refactored RTU_UNIT_HW_STATE to RTU_HW_STATE
This commit is contained in:
parent
0bf7b8204d
commit
c3ccd051dc
@ -10,15 +10,15 @@ local databus = {}
|
|||||||
-- databus PSIL
|
-- databus PSIL
|
||||||
databus.ps = psil.create()
|
databus.ps = psil.create()
|
||||||
|
|
||||||
---@enum RTU_UNIT_HW_STATE
|
---@enum RTU_HW_STATE
|
||||||
local RTU_UNIT_HW_STATE = {
|
local RTU_HW_STATE = {
|
||||||
OFFLINE = 1,
|
OFFLINE = 1,
|
||||||
FAULTED = 2,
|
FAULTED = 2,
|
||||||
UNFORMED = 3,
|
UNFORMED = 3,
|
||||||
OK = 4
|
OK = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
databus.RTU_UNIT_HW_STATE = RTU_UNIT_HW_STATE
|
databus.RTU_HW_STATE = RTU_HW_STATE
|
||||||
|
|
||||||
-- call to toggle heartbeat signal
|
-- call to toggle heartbeat signal
|
||||||
function databus.heartbeat() databus.ps.toggle("heartbeat") end
|
function databus.heartbeat() databus.ps.toggle("heartbeat") end
|
||||||
@ -52,7 +52,7 @@ end
|
|||||||
|
|
||||||
-- transmit unit hardware status across the bus
|
-- transmit unit hardware status across the bus
|
||||||
---@param uid integer unit ID
|
---@param uid integer unit ID
|
||||||
---@param status RTU_UNIT_HW_STATE
|
---@param status RTU_HW_STATE
|
||||||
function databus.tx_unit_hw_status(uid, status)
|
function databus.tx_unit_hw_status(uid, status)
|
||||||
databus.ps.publish("unit_hw_" .. uid, status)
|
databus.ps.publish("unit_hw_" .. uid, status)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,10 +31,10 @@ local sna_rtu = require("rtu.dev.sna_rtu")
|
|||||||
local sps_rtu = require("rtu.dev.sps_rtu")
|
local sps_rtu = require("rtu.dev.sps_rtu")
|
||||||
local turbinev_rtu = require("rtu.dev.turbinev_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_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 = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
@ -229,19 +229,19 @@ local function main()
|
|||||||
for for_reactor, def in pairs(rs_rtus) do
|
for for_reactor, def in pairs(rs_rtus) do
|
||||||
---@class rtu_registry_entry
|
---@class rtu_registry_entry
|
||||||
local unit = {
|
local unit = {
|
||||||
uid = 0, ---@type integer
|
uid = 0, ---@type integer
|
||||||
name = "redstone_io", ---@type string
|
name = "redstone_io", ---@type string
|
||||||
type = RTU_UNIT_TYPE.REDSTONE, ---@type RTU_UNIT_TYPE
|
type = RTU_UNIT_TYPE.REDSTONE, ---@type RTU_UNIT_TYPE
|
||||||
index = false, ---@type integer|false
|
index = false, ---@type integer|false
|
||||||
reactor = for_reactor, ---@type integer
|
reactor = for_reactor, ---@type integer
|
||||||
device = def.capabilities, ---@type IO_PORT[] use device field for redstone ports
|
device = def.capabilities, ---@type IO_PORT[] use device field for redstone ports
|
||||||
is_multiblock = false, ---@type boolean
|
is_multiblock = false, ---@type boolean
|
||||||
formed = nil, ---@type boolean|nil
|
formed = nil, ---@type boolean|nil
|
||||||
hw_state = RTU_UNIT_HW_STATE.OK, ---@type RTU_UNIT_HW_STATE
|
hw_state = RTU_HW_STATE.OK, ---@type RTU_HW_STATE
|
||||||
rtu = def.rtu, ---@type rtu_device|rtu_rs_device
|
rtu = def.rtu, ---@type rtu_device|rtu_rs_device
|
||||||
modbus_io = modbus.new(def.rtu, false),
|
modbus_io = modbus.new(def.rtu, false),
|
||||||
pkt_queue = nil, ---@type mqueue|nil
|
pkt_queue = nil, ---@type mqueue|nil
|
||||||
thread = nil ---@type parallel_thread|nil
|
thread = nil ---@type parallel_thread|nil
|
||||||
}
|
}
|
||||||
|
|
||||||
table.insert(units, unit)
|
table.insert(units, unit)
|
||||||
@ -442,19 +442,19 @@ local function main()
|
|||||||
|
|
||||||
---@class rtu_registry_entry
|
---@class rtu_registry_entry
|
||||||
local rtu_unit = {
|
local rtu_unit = {
|
||||||
uid = 0, ---@type integer
|
uid = 0, ---@type integer
|
||||||
name = name, ---@type string
|
name = name, ---@type string
|
||||||
type = rtu_type, ---@type RTU_UNIT_TYPE
|
type = rtu_type, ---@type RTU_UNIT_TYPE
|
||||||
index = index or false, ---@type integer|false
|
index = index or false, ---@type integer|false
|
||||||
reactor = for_reactor, ---@type integer
|
reactor = for_reactor, ---@type integer
|
||||||
device = device, ---@type table peripheral reference
|
device = device, ---@type table peripheral reference
|
||||||
is_multiblock = is_multiblock, ---@type boolean
|
is_multiblock = is_multiblock, ---@type boolean
|
||||||
formed = formed, ---@type boolean|nil
|
formed = formed, ---@type boolean|nil
|
||||||
hw_state = RTU_UNIT_HW_STATE.OFFLINE, ---@type RTU_UNIT_HW_STATE
|
hw_state = RTU_HW_STATE.OFFLINE, ---@type RTU_HW_STATE
|
||||||
rtu = rtu_iface, ---@type rtu_device|rtu_rs_device
|
rtu = rtu_iface, ---@type rtu_device|rtu_rs_device
|
||||||
modbus_io = modbus.new(rtu_iface, true),
|
modbus_io = modbus.new(rtu_iface, true),
|
||||||
pkt_queue = mqueue.new(), ---@type mqueue|nil
|
pkt_queue = mqueue.new(), ---@type mqueue|nil
|
||||||
thread = nil ---@type parallel_thread|nil
|
thread = nil ---@type parallel_thread|nil
|
||||||
}
|
}
|
||||||
|
|
||||||
rtu_unit.thread = threads.thread__unit_comms(__shared_memory, rtu_unit)
|
rtu_unit.thread = threads.thread__unit_comms(__shared_memory, rtu_unit)
|
||||||
@ -473,14 +473,14 @@ local function main()
|
|||||||
|
|
||||||
-- determine hardware status
|
-- determine hardware status
|
||||||
if rtu_unit.type == RTU_UNIT_TYPE.VIRTUAL then
|
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
|
else
|
||||||
if rtu_unit.is_multiblock then
|
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
|
elseif faulted then
|
||||||
rtu_unit.hw_state = RTU_UNIT_HW_STATE.FAULTED
|
rtu_unit.hw_state = RTU_HW_STATE.FAULTED
|
||||||
else
|
else
|
||||||
rtu_unit.hw_state = RTU_UNIT_HW_STATE.OK
|
rtu_unit.hw_state = RTU_HW_STATE.OK
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ local core = require("graphics.core")
|
|||||||
local threads = {}
|
local threads = {}
|
||||||
|
|
||||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
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 MAIN_CLOCK = 0.5 -- (2Hz, 10 ticks)
|
||||||
local COMMS_SLEEP = 100 -- (100ms, 2 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
|
-- 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
|
-- checking now that it has connected; the config isn't valid, so don't connect it
|
||||||
if invalid then
|
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)
|
databus.tx_unit_hw_status(unit.uid, unit.hw_state)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -138,16 +138,16 @@ local function handle_unit_mount(smem, println_ts, iface, type, device, unit)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if unit.is_multiblock then
|
if unit.is_multiblock then
|
||||||
unit.hw_state = UNIT_HW_STATE.UNFORMED
|
unit.hw_state = RTU_HW_STATE.UNFORMED
|
||||||
if unit.formed == false then
|
if unit.formed == false then
|
||||||
log.info(util.c("assuming ", unit.name, " is not formed due to PPM faults while initializing"))
|
log.info(util.c("assuming ", unit.name, " is not formed due to PPM faults while initializing"))
|
||||||
end
|
end
|
||||||
elseif faulted then
|
elseif faulted then
|
||||||
unit.hw_state = UNIT_HW_STATE.FAULTED
|
unit.hw_state = RTU_HW_STATE.FAULTED
|
||||||
elseif not unknown then
|
elseif not unknown then
|
||||||
unit.hw_state = UNIT_HW_STATE.OK
|
unit.hw_state = RTU_HW_STATE.OK
|
||||||
else
|
else
|
||||||
unit.hw_state = UNIT_HW_STATE.OFFLINE
|
unit.hw_state = RTU_HW_STATE.OFFLINE
|
||||||
end
|
end
|
||||||
|
|
||||||
databus.tx_unit_hw_status(unit.uid, unit.hw_state)
|
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))
|
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))
|
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)
|
databus.tx_unit_hw_status(unit.uid, unit.hw_state)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -523,13 +523,13 @@ function threads.thread__unit_comms(smem, unit)
|
|||||||
|
|
||||||
if unit.formed == nil then
|
if unit.formed == nil then
|
||||||
unit.formed = is_formed
|
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
|
elseif not unit.formed then
|
||||||
unit.hw_state = UNIT_HW_STATE.UNFORMED
|
unit.hw_state = RTU_HW_STATE.UNFORMED
|
||||||
end
|
end
|
||||||
|
|
||||||
if (is_formed == true) and not unit.formed then
|
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"))
|
log.info(util.c(detail_name, " is now formed"))
|
||||||
rtu_comms.send_remounted(unit.uid)
|
rtu_comms.send_remounted(unit.uid)
|
||||||
elseif (is_formed == false) and unit.formed then
|
elseif (is_formed == false) and unit.formed then
|
||||||
@ -541,9 +541,9 @@ function threads.thread__unit_comms(smem, unit)
|
|||||||
|
|
||||||
-- check hardware status
|
-- check hardware status
|
||||||
if unit.device.__p_is_healthy() then
|
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
|
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
|
end
|
||||||
|
|
||||||
-- update hw status
|
-- update hw status
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user