shared global types

This commit is contained in:
Mikayla Fischler 2022-05-03 10:44:18 -04:00
parent 62b4b63f4a
commit c76200b0e3
4 changed files with 41 additions and 14 deletions

View File

@ -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 {

View File

@ -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")

View File

@ -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 .. ")"

20
scada-common/types.lua Normal file
View File

@ -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"
}