From c76200b0e3a3ef821451e788e32b35a0264fd635 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Tue, 3 May 2022 10:44:18 -0400 Subject: [PATCH] shared global types --- reactor-plc/plc.lua | 23 +++++++++++++---------- reactor-plc/startup.lua | 1 + rtu/startup.lua | 11 +++++++---- scada-common/types.lua | 20 ++++++++++++++++++++ 4 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 scada-common/types.lua diff --git a/reactor-plc/plc.lua b/reactor-plc/plc.lua index a1e5225..cccced9 100644 --- a/reactor-plc/plc.lua +++ b/reactor-plc/plc.lua @@ -1,7 +1,10 @@ +-- #REQUIRES types.lua -- #REQUIRES comms.lua -- #REQUIRES ppm.lua -- #REQUIRES util.lua +local iss_status_t = types.iss_status_t + local PROTOCOLS = comms.PROTOCOLS local RPLC_TYPES = comms.RPLC_TYPES local RPLC_LINKING = comms.RPLC_LINKING @@ -113,7 +116,7 @@ function iss_init(reactor) -- check all safety conditions local check = function () - local status = "ok" + local status = iss_status_t.ok local was_tripped = self.tripped -- update cache @@ -132,32 +135,32 @@ function iss_init(reactor) status = self.trip_cause elseif self.cache[1] then log._warning("ISS: damage critical!") - status = "dmg_crit" + status = iss_status_t.dmg_crit elseif self.cache[4] then log._warning("ISS: high temperature!") - status = "high_temp" + status = iss_status_t.high_temp elseif self.cache[2] then log._warning("ISS: heated coolant backup!") - status = "heated_coolant_backup" + status = iss_status_t.ex_hcoolant elseif self.cache[6] then log._warning("ISS: no coolant!") - status = "no_coolant" + status = iss_status_t.no_coolant elseif self.cache[3] then log._warning("ISS: full waste!") - status = "full_waste" + status = iss_status_t.ex_waste elseif self.cache[5] then log._warning("ISS: no fuel!") - status = "no_fuel" + status = iss_status_t.no_fuel elseif self.cache[7] then log._warning("ISS: supervisor connection timeout!") - status = "timeout" + status = iss_status_t.timeout else self.tripped = false end -- if a new trip occured... local first_trip = false - if not was_tripped and status ~= "ok" then + if not was_tripped and status ~= iss_status_t.ok then log._warning("ISS: reactor SCRAM") first_trip = true @@ -181,7 +184,7 @@ function iss_init(reactor) local reset = function () self.timed_out = false self.tripped = false - self.trip_cause = "" + self.trip_cause = iss_status_t.ok end return { diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index cd68962..5c9df15 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -3,6 +3,7 @@ -- os.loadAPI("scada-common/log.lua") +os.loadAPI("scada-common/types.lua") os.loadAPI("scada-common/util.lua") os.loadAPI("scada-common/ppm.lua") os.loadAPI("scada-common/comms.lua") diff --git a/rtu/startup.lua b/rtu/startup.lua index 20177e6..72d1b7e 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -3,6 +3,7 @@ -- os.loadAPI("scada-common/log.lua") +os.loadAPI("scada-common/types.lua") os.loadAPI("scada-common/util.lua") os.loadAPI("scada-common/ppm.lua") os.loadAPI("scada-common/comms.lua") @@ -21,6 +22,8 @@ os.loadAPI("dev/turbine_rtu.lua") local RTU_VERSION = "alpha-v0.4.11" +local rtu_t = types.rtu_t + local print = util.print local println = util.println local print_ts = util.print_ts @@ -139,7 +142,7 @@ for reactor_idx = 1, #rtu_redstone do table.insert(units, { name = "redstone_io", - type = "redstone", + type = rtu_t.redstone, index = 1, reactor = rtu_redstone[reactor_idx].for_reactor, device = capabilities, -- use device field for redstone channels @@ -168,15 +171,15 @@ for i = 1, #rtu_devices do if type == "boiler" then -- boiler multiblock - rtu_type = "boiler" + rtu_type = rtu_t.boiler rtu_iface = boiler_rtu.new(device) elseif type == "turbine" then -- turbine multiblock - rtu_type = "turbine" + rtu_type = rtu_t.turbine rtu_iface = turbine_rtu.new(device) elseif type == "mekanismMachine" then -- assumed to be an induction matrix multiblock - rtu_type = "imatrix" + rtu_type = rtu_t.induction_matrix rtu_iface = imatrix_rtu.new(device) else local message = "init> device '" .. rtu_devices[i].name .. "' is not a known type (" .. type .. ")" diff --git a/scada-common/types.lua b/scada-common/types.lua new file mode 100644 index 0000000..072cd9a --- /dev/null +++ b/scada-common/types.lua @@ -0,0 +1,20 @@ +-- Global Types + +rtu_t = { + redstone = "redstone", + boiler = "boiler", + turbine = "turbine", + energy_machine = "emachine", + induction_matrix = "imatrix" +} + +iss_status_t = { + ok = "ok", + dmg_crit = "dmg_crit", + ex_hcoolant = "heated_coolant_backup", + ex_waste = "full_waste", + high_temp = "high_temp", + no_fuel = "no_fuel", + no_coolant = "no_coolant", + timeout = "timeout" +}