diff --git a/rtu/databus.lua b/rtu/databus.lua index 4fe183a..0d086f4 100644 --- a/rtu/databus.lua +++ b/rtu/databus.lua @@ -10,15 +10,15 @@ local databus = {} -- databus PSIL databus.ps = psil.create() ----@enum RTU_UNIT_HW_STATE -local RTU_UNIT_HW_STATE = { +---@enum RTU_HW_STATE +local RTU_HW_STATE = { OFFLINE = 1, FAULTED = 2, UNFORMED = 3, OK = 4 } -databus.RTU_UNIT_HW_STATE = RTU_UNIT_HW_STATE +databus.RTU_HW_STATE = RTU_HW_STATE -- call to toggle heartbeat signal function databus.heartbeat() databus.ps.toggle("heartbeat") end @@ -52,7 +52,7 @@ end -- transmit unit hardware status across the bus ---@param uid integer unit ID ----@param status RTU_UNIT_HW_STATE +---@param status RTU_HW_STATE function databus.tx_unit_hw_status(uid, status) databus.ps.publish("unit_hw_" .. uid, status) end diff --git a/rtu/startup.lua b/rtu/startup.lua index 6d670c6..7a30f42 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -31,10 +31,10 @@ local sna_rtu = require("rtu.dev.sna_rtu") local sps_rtu = require("rtu.dev.sps_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu") -local RTU_VERSION = "v1.10.8" +local RTU_VERSION = "v1.10.9" local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE -local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE +local RTU_HW_STATE = databus.RTU_HW_STATE local println = util.println local println_ts = util.println_ts @@ -229,19 +229,19 @@ local function main() for for_reactor, def in pairs(rs_rtus) do ---@class rtu_registry_entry local unit = { - uid = 0, ---@type integer - name = "redstone_io", ---@type string - type = RTU_UNIT_TYPE.REDSTONE, ---@type RTU_UNIT_TYPE - index = false, ---@type integer|false - reactor = for_reactor, ---@type integer - device = def.capabilities, ---@type IO_PORT[] use device field for redstone ports - is_multiblock = false, ---@type boolean - formed = nil, ---@type boolean|nil - hw_state = RTU_UNIT_HW_STATE.OK, ---@type RTU_UNIT_HW_STATE - rtu = def.rtu, ---@type rtu_device|rtu_rs_device + uid = 0, ---@type integer + name = "redstone_io", ---@type string + type = RTU_UNIT_TYPE.REDSTONE, ---@type RTU_UNIT_TYPE + index = false, ---@type integer|false + reactor = for_reactor, ---@type integer + device = def.capabilities, ---@type IO_PORT[] use device field for redstone ports + is_multiblock = false, ---@type boolean + formed = nil, ---@type boolean|nil + hw_state = RTU_HW_STATE.OK, ---@type RTU_HW_STATE + rtu = def.rtu, ---@type rtu_device|rtu_rs_device modbus_io = modbus.new(def.rtu, false), - pkt_queue = nil, ---@type mqueue|nil - thread = nil ---@type parallel_thread|nil + pkt_queue = nil, ---@type mqueue|nil + thread = nil ---@type parallel_thread|nil } table.insert(units, unit) @@ -442,19 +442,19 @@ local function main() ---@class rtu_registry_entry local rtu_unit = { - uid = 0, ---@type integer - name = name, ---@type string - type = rtu_type, ---@type RTU_UNIT_TYPE - index = index or false, ---@type integer|false - reactor = for_reactor, ---@type integer - device = device, ---@type table peripheral reference - is_multiblock = is_multiblock, ---@type boolean - formed = formed, ---@type boolean|nil - hw_state = RTU_UNIT_HW_STATE.OFFLINE, ---@type RTU_UNIT_HW_STATE - rtu = rtu_iface, ---@type rtu_device|rtu_rs_device + uid = 0, ---@type integer + name = name, ---@type string + type = rtu_type, ---@type RTU_UNIT_TYPE + index = index or false, ---@type integer|false + reactor = for_reactor, ---@type integer + device = device, ---@type table peripheral reference + is_multiblock = is_multiblock, ---@type boolean + formed = formed, ---@type boolean|nil + hw_state = RTU_HW_STATE.OFFLINE, ---@type RTU_HW_STATE + rtu = rtu_iface, ---@type rtu_device|rtu_rs_device modbus_io = modbus.new(rtu_iface, true), - pkt_queue = mqueue.new(), ---@type mqueue|nil - thread = nil ---@type parallel_thread|nil + pkt_queue = mqueue.new(), ---@type mqueue|nil + thread = nil ---@type parallel_thread|nil } rtu_unit.thread = threads.thread__unit_comms(__shared_memory, rtu_unit) @@ -473,14 +473,14 @@ local function main() -- determine hardware status if rtu_unit.type == RTU_UNIT_TYPE.VIRTUAL then - rtu_unit.hw_state = RTU_UNIT_HW_STATE.OFFLINE + rtu_unit.hw_state = RTU_HW_STATE.OFFLINE else if rtu_unit.is_multiblock then - rtu_unit.hw_state = util.trinary(rtu_unit.formed == true, RTU_UNIT_HW_STATE.OK, RTU_UNIT_HW_STATE.UNFORMED) + rtu_unit.hw_state = util.trinary(rtu_unit.formed == true, RTU_HW_STATE.OK, RTU_HW_STATE.UNFORMED) elseif faulted then - rtu_unit.hw_state = RTU_UNIT_HW_STATE.FAULTED + rtu_unit.hw_state = RTU_HW_STATE.FAULTED else - rtu_unit.hw_state = RTU_UNIT_HW_STATE.OK + rtu_unit.hw_state = RTU_HW_STATE.OK end end diff --git a/rtu/threads.lua b/rtu/threads.lua index 0c940c4..5cb1e02 100644 --- a/rtu/threads.lua +++ b/rtu/threads.lua @@ -23,7 +23,7 @@ local core = require("graphics.core") local threads = {} local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE -local UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE +local RTU_HW_STATE = databus.RTU_HW_STATE local MAIN_CLOCK = 0.5 -- (2Hz, 10 ticks) local COMMS_SLEEP = 100 -- (100ms, 2 ticks) @@ -106,7 +106,7 @@ local function handle_unit_mount(smem, println_ts, iface, type, device, unit) -- if disconnected on startup, config wouldn't have been validated -- checking now that it has connected; the config isn't valid, so don't connect it if invalid then - unit.hw_state = UNIT_HW_STATE.OFFLINE + unit.hw_state = RTU_HW_STATE.OFFLINE databus.tx_unit_hw_status(unit.uid, unit.hw_state) return end @@ -138,16 +138,16 @@ local function handle_unit_mount(smem, println_ts, iface, type, device, unit) end if unit.is_multiblock then - unit.hw_state = UNIT_HW_STATE.UNFORMED + unit.hw_state = RTU_HW_STATE.UNFORMED if unit.formed == false then log.info(util.c("assuming ", unit.name, " is not formed due to PPM faults while initializing")) end elseif faulted then - unit.hw_state = UNIT_HW_STATE.FAULTED + unit.hw_state = RTU_HW_STATE.FAULTED elseif not unknown then - unit.hw_state = UNIT_HW_STATE.OK + unit.hw_state = RTU_HW_STATE.OK else - unit.hw_state = UNIT_HW_STATE.OFFLINE + unit.hw_state = RTU_HW_STATE.OFFLINE end databus.tx_unit_hw_status(unit.uid, unit.hw_state) @@ -285,7 +285,7 @@ function threads.thread__main(smem) println_ts(util.c("lost the ", type_name, " on interface ", unit.name)) log.warning(util.c("lost the ", type_name, " unit peripheral on interface ", unit.name)) - unit.hw_state = UNIT_HW_STATE.OFFLINE + unit.hw_state = RTU_HW_STATE.OFFLINE databus.tx_unit_hw_status(unit.uid, unit.hw_state) break end @@ -523,13 +523,13 @@ function threads.thread__unit_comms(smem, unit) if unit.formed == nil then unit.formed = is_formed - if is_formed then unit.hw_state = UNIT_HW_STATE.OK end + if is_formed then unit.hw_state = RTU_HW_STATE.OK end elseif not unit.formed then - unit.hw_state = UNIT_HW_STATE.UNFORMED + unit.hw_state = RTU_HW_STATE.UNFORMED end if (is_formed == true) and not unit.formed then - unit.hw_state = UNIT_HW_STATE.OK + unit.hw_state = RTU_HW_STATE.OK log.info(util.c(detail_name, " is now formed")) rtu_comms.send_remounted(unit.uid) elseif (is_formed == false) and unit.formed then @@ -541,9 +541,9 @@ function threads.thread__unit_comms(smem, unit) -- check hardware status if unit.device.__p_is_healthy() then - if unit.hw_state == UNIT_HW_STATE.FAULTED then unit.hw_state = UNIT_HW_STATE.OK end + if unit.hw_state == RTU_HW_STATE.FAULTED then unit.hw_state = RTU_HW_STATE.OK end else - if unit.hw_state == UNIT_HW_STATE.OK then unit.hw_state = UNIT_HW_STATE.FAULTED end + if unit.hw_state == RTU_HW_STATE.OK then unit.hw_state = RTU_HW_STATE.FAULTED end end -- update hw status