diff --git a/scada-common/comms.lua b/scada-common/comms.lua index 4bf8262..1e3373f 100644 --- a/scada-common/comms.lua +++ b/scada-common/comms.lua @@ -16,8 +16,8 @@ local max_distance = nil ---@class comms local comms = {} --- protocol version (non-protocol changes tracked by util.lua version) -comms.version = "2.4.0" +-- protocol/data version (protocol/data independent changes tracked by util.lua version) +comms.version = "2.4.1" ---@enum PROTOCOL local PROTOCOL = { diff --git a/scada-common/rsio.lua b/scada-common/rsio.lua index 13a6d6a..4d98c2f 100644 --- a/scada-common/rsio.lua +++ b/scada-common/rsio.lua @@ -7,9 +7,7 @@ local util = require("scada-common.util") ---@class rsio local rsio = {} ----------------------- --- RS I/O CONSTANTS -- ----------------------- +--#region RS I/O Constants ---@enum IO_LVL I/O logic level local IO_LVL = { @@ -53,30 +51,31 @@ local IO_PORT = { -- facility F_ALARM = 7, -- active high, facility-wide alarm (any high priority unit alarm) + F_ALARM_ANY = 8, -- active high, any alarm regardless of priority -- waste - WASTE_PU = 8, -- active low, waste -> plutonium -> pellets route - WASTE_PO = 9, -- active low, waste -> polonium route - WASTE_POPL = 10, -- active low, polonium -> pellets route - WASTE_AM = 11, -- active low, polonium -> anti-matter route + WASTE_PU = 9, -- active low, waste -> plutonium -> pellets route + WASTE_PO = 10, -- active low, waste -> polonium route + WASTE_POPL = 11, -- active low, polonium -> pellets route + WASTE_AM = 12, -- active low, polonium -> anti-matter route -- reactor - R_ACTIVE = 12, -- active high, if the reactor is active - R_AUTO_CTRL = 13, -- active high, if the reactor burn rate is automatic - R_SCRAMMED = 14, -- active high, if the reactor is scrammed - R_AUTO_SCRAM = 15, -- active high, if the reactor was automatically scrammed - R_HIGH_DMG = 16, -- active high, if the reactor damage is high - R_HIGH_TEMP = 17, -- active high, if the reactor is at a high temperature - R_LOW_COOLANT = 18, -- active high, if the reactor has very low coolant - R_EXCESS_HC = 19, -- active high, if the reactor has excess heated coolant - R_EXCESS_WS = 20, -- active high, if the reactor has excess waste - R_INSUFF_FUEL = 21, -- active high, if the reactor has insufficent fuel - R_PLC_FAULT = 22, -- active high, if the reactor PLC reports a device access fault - R_PLC_TIMEOUT = 23, -- active high, if the reactor PLC has not been heard from + R_ACTIVE = 13, -- active high, reactor is active + R_AUTO_CTRL = 14, -- active high, reactor burn rate is automatic + R_SCRAMMED = 15, -- active high, reactor is scrammed + R_AUTO_SCRAM = 16, -- active high, reactor was automatically scrammed + R_HIGH_DMG = 17, -- active high, reactor damage is high + R_HIGH_TEMP = 18, -- active high, reactor is at a high temperature + R_LOW_COOLANT = 19, -- active high, reactor has very low coolant + R_EXCESS_HC = 20, -- active high, reactor has excess heated coolant + R_EXCESS_WS = 21, -- active high, reactor has excess waste + R_INSUFF_FUEL = 22, -- active high, reactor has insufficent fuel + R_PLC_FAULT = 23, -- active high, reactor PLC reports a device access fault + R_PLC_TIMEOUT = 24, -- active high, reactor PLC has not been heard from -- unit outputs - U_ALARM = 24, -- active high, unit alarm - U_EMER_COOL = 25 -- active low, emergency coolant control + U_ALARM = 25, -- active high, unit alarm + U_EMER_COOL = 26 -- active low, emergency coolant control } rsio.IO_LVL = IO_LVL @@ -84,9 +83,9 @@ rsio.IO_DIR = IO_DIR rsio.IO_MODE = IO_MODE rsio.IO = IO_PORT ------------------------ --- UTILITY FUNCTIONS -- ------------------------ +--#endregion + +--#region Utility Functions -- port to string ---@nodiscard @@ -100,6 +99,7 @@ function rsio.to_string(port) "R_ENABLE", "U_ACK", "F_ALARM", + "F_ALARM_ANY", "WASTE_PU", "WASTE_PO", "WASTE_POPL", @@ -153,6 +153,8 @@ local RS_DIO_MAP = { -- F_ALARM { _in = _I_ACTIVE_HIGH, _out = _O_ACTIVE_HIGH, mode = IO_DIR.OUT }, + -- F_ALARM_ANY + { _in = _I_ACTIVE_HIGH, _out = _O_ACTIVE_HIGH, mode = IO_DIR.OUT }, -- WASTE_PU { _in = _I_ACTIVE_LOW, _out = _O_ACTIVE_LOW, mode = IO_DIR.OUT }, @@ -207,6 +209,7 @@ function rsio.get_io_mode(port) IO_MODE.DIGITAL_IN, -- R_ENABLE IO_MODE.DIGITAL_IN, -- U_ACK IO_MODE.DIGITAL_OUT, -- F_ALARM + IO_MODE.DIGITAL_OUT, -- F_ALARM_ANY IO_MODE.DIGITAL_OUT, -- WASTE_PU IO_MODE.DIGITAL_OUT, -- WASTE_PO IO_MODE.DIGITAL_OUT, -- WASTE_POPL @@ -234,9 +237,9 @@ function rsio.get_io_mode(port) end end --------------------- --- GENERIC CHECKS -- --------------------- +--#endregion + +--#region Generic Checks local RS_SIDES = rs.getSides() @@ -269,9 +272,9 @@ function rsio.is_color(color) return util.is_int(color) and (color > 0) and (_B_AND(color, (color - 1)) == 0) end ------------------ --- DIGITAL I/O -- ------------------ +--#endregion + +--#region Digital I/O -- get digital I/O level reading from a redstone boolean input value ---@nodiscard @@ -285,9 +288,7 @@ end ---@nodiscard ---@param level IO_LVL logic level ---@return boolean -function rsio.digital_write(level) - return level == IO_LVL.HIGH -end +function rsio.digital_write(level) return level == IO_LVL.HIGH end -- returns the level corresponding to active ---@nodiscard @@ -317,9 +318,9 @@ function rsio.digital_is_active(port, level) end end ----------------- --- ANALOG I/O -- ----------------- +--#endregion + +--#region Analog I/O -- read an analog value scaled from min to max ---@nodiscard @@ -343,4 +344,6 @@ function rsio.analog_write(value, min, max) return math.floor(scaled_value * 15) end +--#endregion + return rsio diff --git a/scada-common/util.lua b/scada-common/util.lua index a1a1b4a..637d92a 100644 --- a/scada-common/util.lua +++ b/scada-common/util.lua @@ -8,7 +8,7 @@ local cc_strings = require("cc.strings") local util = {} -- scada-common version -util.version = "1.1.2" +util.version = "1.1.3" -- ENVIRONMENT CONSTANTS -- diff --git a/supervisor/facility.lua b/supervisor/facility.lua index 30bcd68..708522f 100644 --- a/supervisor/facility.lua +++ b/supervisor/facility.lua @@ -746,18 +746,21 @@ function facility.new(num_reactors, cooling_conf) -- handle facility ack if self.io_ctl.digital_read(IO.F_ACK) then public.ack_all() end - -- update facility alarm output (check if emergency+ alarms are active) - local has_alarm = false + -- update facility alarm outputs + local has_prio_alarm, has_any_alarm = false, false for i = 1, #self.units do - local u = self.units[i] ---@type reactor_unit + local u = self.units[i] ---@type reactor_unit if u.has_alarm_min_prio(PRIO.EMERGENCY) then - has_alarm = true + has_prio_alarm, has_any_alarm = true, true break + elseif u.has_alarm_min_prio(PRIO.TIMELY) then + has_any_alarm = true end end - self.io_ctl.digital_write(IO.F_ALARM, has_alarm) + self.io_ctl.digital_write(IO.F_ALARM, has_prio_alarm) + self.io_ctl.digital_write(IO.F_ALARM_ANY, has_any_alarm) end ---------------- diff --git a/supervisor/startup.lua b/supervisor/startup.lua index 76fd746..fda0dc4 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -21,7 +21,7 @@ local supervisor = require("supervisor.supervisor") local svsessions = require("supervisor.session.svsessions") -local SUPERVISOR_VERSION = "v1.0.6" +local SUPERVISOR_VERSION = "v1.0.7" local println = util.println local println_ts = util.println_ts