mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#229 PLC changes for UI element register change
This commit is contained in:
parent
b2115fd077
commit
e763af9981
@ -8,14 +8,16 @@ local util = require("scada-common.util")
|
||||
|
||||
local databus = {}
|
||||
|
||||
-- databus PSIL
|
||||
databus.ps = psil.create()
|
||||
|
||||
local dbus_iface = {
|
||||
ps = psil.create(),
|
||||
rps_scram = function () log.debug("DBUS: unset rps_scram() called") end,
|
||||
rps_reset = function () log.debug("DBUS: unset rps_reset() called") end
|
||||
}
|
||||
|
||||
-- call to toggle heartbeat signal
|
||||
function databus.heartbeat() dbus_iface.ps.toggle("heartbeat") end
|
||||
function databus.heartbeat() databus.ps.toggle("heartbeat") end
|
||||
|
||||
-- link RPS command functions
|
||||
---@param scram function reactor SCRAM function
|
||||
@ -35,42 +37,42 @@ function databus.rps_reset() dbus_iface.rps_reset() end
|
||||
---@param plc_v string PLC version
|
||||
---@param comms_v string comms version
|
||||
function databus.tx_versions(plc_v, comms_v)
|
||||
dbus_iface.ps.publish("version", plc_v)
|
||||
dbus_iface.ps.publish("comms_version", comms_v)
|
||||
databus.ps.publish("version", plc_v)
|
||||
databus.ps.publish("comms_version", comms_v)
|
||||
end
|
||||
|
||||
-- transmit unit ID across the bus
|
||||
---@param id integer unit ID
|
||||
function databus.tx_id(id)
|
||||
dbus_iface.ps.publish("unit_id", id)
|
||||
databus.ps.publish("unit_id", id)
|
||||
end
|
||||
|
||||
-- transmit hardware status across the bus
|
||||
---@param plc_state plc_state
|
||||
function databus.tx_hw_status(plc_state)
|
||||
dbus_iface.ps.publish("reactor_dev_state", util.trinary(plc_state.no_reactor, 1, util.trinary(plc_state.reactor_formed, 3, 2)))
|
||||
dbus_iface.ps.publish("has_modem", not plc_state.no_modem)
|
||||
dbus_iface.ps.publish("degraded", plc_state.degraded)
|
||||
dbus_iface.ps.publish("init_ok", plc_state.init_ok)
|
||||
databus.ps.publish("reactor_dev_state", util.trinary(plc_state.no_reactor, 1, util.trinary(plc_state.reactor_formed, 3, 2)))
|
||||
databus.ps.publish("has_modem", not plc_state.no_modem)
|
||||
databus.ps.publish("degraded", plc_state.degraded)
|
||||
databus.ps.publish("init_ok", plc_state.init_ok)
|
||||
end
|
||||
|
||||
-- transmit thread (routine) statuses
|
||||
---@param thread string thread name
|
||||
---@param ok boolean thread state
|
||||
function databus.tx_rt_status(thread, ok)
|
||||
dbus_iface.ps.publish(util.c("routine__", thread), ok)
|
||||
databus.ps.publish(util.c("routine__", thread), ok)
|
||||
end
|
||||
|
||||
-- transmit supervisor link state across the bus
|
||||
---@param state integer
|
||||
function databus.tx_link_state(state)
|
||||
dbus_iface.ps.publish("link_state", state)
|
||||
databus.ps.publish("link_state", state)
|
||||
end
|
||||
|
||||
-- transmit reactor enable state across the bus
|
||||
---@param active boolean reactor active
|
||||
function databus.tx_reactor_state(active)
|
||||
dbus_iface.ps.publish("reactor_active", active)
|
||||
databus.ps.publish("reactor_active", active)
|
||||
end
|
||||
|
||||
-- transmit RPS data across the bus
|
||||
@ -78,26 +80,26 @@ end
|
||||
---@param status table RPS status
|
||||
---@param emer_cool_active boolean RPS activated the emergency coolant
|
||||
function databus.tx_rps(tripped, status, emer_cool_active)
|
||||
dbus_iface.ps.publish("rps_scram", tripped)
|
||||
dbus_iface.ps.publish("rps_damage", status[1])
|
||||
dbus_iface.ps.publish("rps_high_temp", status[2])
|
||||
dbus_iface.ps.publish("rps_low_ccool", status[3])
|
||||
dbus_iface.ps.publish("rps_high_waste", status[4])
|
||||
dbus_iface.ps.publish("rps_high_hcool", status[5])
|
||||
dbus_iface.ps.publish("rps_no_fuel", status[6])
|
||||
dbus_iface.ps.publish("rps_fault", status[7])
|
||||
dbus_iface.ps.publish("rps_timeout", status[8])
|
||||
dbus_iface.ps.publish("rps_manual", status[9])
|
||||
dbus_iface.ps.publish("rps_automatic", status[10])
|
||||
dbus_iface.ps.publish("rps_sysfail", status[11])
|
||||
dbus_iface.ps.publish("emer_cool", emer_cool_active)
|
||||
databus.ps.publish("rps_scram", tripped)
|
||||
databus.ps.publish("rps_damage", status[1])
|
||||
databus.ps.publish("rps_high_temp", status[2])
|
||||
databus.ps.publish("rps_low_ccool", status[3])
|
||||
databus.ps.publish("rps_high_waste", status[4])
|
||||
databus.ps.publish("rps_high_hcool", status[5])
|
||||
databus.ps.publish("rps_no_fuel", status[6])
|
||||
databus.ps.publish("rps_fault", status[7])
|
||||
databus.ps.publish("rps_timeout", status[8])
|
||||
databus.ps.publish("rps_manual", status[9])
|
||||
databus.ps.publish("rps_automatic", status[10])
|
||||
databus.ps.publish("rps_sysfail", status[11])
|
||||
databus.ps.publish("emer_cool", emer_cool_active)
|
||||
end
|
||||
|
||||
-- link a function to receive data from the bus
|
||||
---@param field string field name
|
||||
---@param func function function to link
|
||||
function databus.rx_field(field, func)
|
||||
dbus_iface.ps.subscribe(field, func)
|
||||
databus.ps.subscribe(field, func)
|
||||
end
|
||||
|
||||
return databus
|
||||
|
@ -31,7 +31,7 @@ local border = core.border
|
||||
---@param panel graphics_element main displaybox
|
||||
local function init(panel)
|
||||
local header = TextBox{parent=panel,y=1,text="REACTOR PLC - UNIT ?",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header}
|
||||
databus.rx_field("unit_id", function (id) header.set_value(util.c("REACTOR PLC - UNIT ", id)) end)
|
||||
header.register(databus.ps, "unit_id", function (id) header.set_value(util.c("REACTOR PLC - UNIT ", id)) end)
|
||||
|
||||
--
|
||||
-- system indicators
|
||||
@ -43,8 +43,8 @@ local function init(panel)
|
||||
local heartbeat = LED{parent=system,label="HEARTBEAT",colors=cpair(colors.green,colors.green_off)}
|
||||
system.line_break()
|
||||
|
||||
databus.rx_field("init_ok", init_ok.update)
|
||||
databus.rx_field("heartbeat", heartbeat.update)
|
||||
init_ok.register(databus.ps, "init_ok", init_ok.update)
|
||||
heartbeat.register(databus.ps, "heartbeat", heartbeat.update)
|
||||
|
||||
local reactor = LEDPair{parent=system,label="REACTOR",off=colors.red,c1=colors.yellow,c2=colors.green}
|
||||
local modem = LED{parent=system,label="MODEM",colors=cpair(colors.green,colors.green_off)}
|
||||
@ -52,9 +52,9 @@ local function init(panel)
|
||||
network.update(5)
|
||||
system.line_break()
|
||||
|
||||
databus.rx_field("reactor_dev_state", reactor.update)
|
||||
databus.rx_field("has_modem", modem.update)
|
||||
databus.rx_field("link_state", network.update)
|
||||
reactor.register(databus.ps, "reactor_dev_state", reactor.update)
|
||||
modem.register(databus.ps, "has_modem", modem.update)
|
||||
network.register(databus.ps, "link_state", network.update)
|
||||
|
||||
local rt_main = LED{parent=system,label="RT MAIN",colors=cpair(colors.green,colors.green_off)}
|
||||
local rt_rps = LED{parent=system,label="RT RPS",colors=cpair(colors.green,colors.green_off)}
|
||||
@ -63,11 +63,11 @@ local function init(panel)
|
||||
local rt_sctl = LED{parent=system,label="RT SPCTL",colors=cpair(colors.green,colors.green_off)}
|
||||
system.line_break()
|
||||
|
||||
databus.rx_field("routine__main", rt_main.update)
|
||||
databus.rx_field("routine__rps", rt_rps.update)
|
||||
databus.rx_field("routine__comms_tx", rt_cmtx.update)
|
||||
databus.rx_field("routine__comms_rx", rt_cmrx.update)
|
||||
databus.rx_field("routine__spctl", rt_sctl.update)
|
||||
rt_main.register(databus.ps, "routine__main", rt_main.update)
|
||||
rt_rps.register(databus.ps, "routine__rps", rt_rps.update)
|
||||
rt_cmtx.register(databus.ps, "routine__comms_tx", rt_cmtx.update)
|
||||
rt_cmrx.register(databus.ps, "routine__comms_rx", rt_cmrx.update)
|
||||
rt_sctl.register(databus.ps, "routine__spctl", rt_sctl.update)
|
||||
|
||||
--
|
||||
-- status & controls
|
||||
@ -80,7 +80,7 @@ local function init(panel)
|
||||
-- only show emergency coolant LED if emergency coolant is configured for this device
|
||||
if type(config.EMERGENCY_COOL) == "table" then
|
||||
local emer_cool = LED{parent=status,x=2,width=14,label="EMER COOLANT",colors=cpair(colors.yellow,colors.yellow_off)}
|
||||
databus.rx_field("emer_cool", emer_cool.update)
|
||||
emer_cool.register(databus.ps, "emer_cool", emer_cool.update)
|
||||
end
|
||||
|
||||
local status_trip_rct = Rectangle{parent=status,width=20,height=3,x=1,border=border(1,colors.lightGray,true),even_inner=true,fg_bg=cpair(colors.black,colors.ivory)}
|
||||
@ -92,8 +92,8 @@ local function init(panel)
|
||||
PushButton{parent=controls,x=1,y=1,min_width=7,text="SCRAM",callback=databus.rps_scram,fg_bg=cpair(colors.black,colors.red),active_fg_bg=cpair(colors.black,colors.red_off)}
|
||||
PushButton{parent=controls,x=9,y=1,min_width=7,text="RESET",callback=databus.rps_reset,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=cpair(colors.black,colors.yellow_off)}
|
||||
|
||||
databus.rx_field("reactor_active", active.update)
|
||||
databus.rx_field("rps_scram", scram.update)
|
||||
active.register(databus.ps, "reactor_active", active.update)
|
||||
scram.register(databus.ps, "rps_scram", scram.update)
|
||||
|
||||
--
|
||||
-- about footer
|
||||
@ -103,8 +103,8 @@ local function init(panel)
|
||||
local fw_v = TextBox{parent=about,x=2,y=1,text="FW: v00.00.00",alignment=TEXT_ALIGN.LEFT,height=1}
|
||||
local comms_v = TextBox{parent=about,x=17,y=1,text="NT: v00.00.00",alignment=TEXT_ALIGN.LEFT,height=1}
|
||||
|
||||
databus.rx_field("version", function (version) fw_v.set_value(util.c("FW: ", version)) end)
|
||||
databus.rx_field("comms_version", function (version) comms_v.set_value(util.c("NT: v", version)) end)
|
||||
fw_v.register(databus.ps, "version", function (version) fw_v.set_value(util.c("FW: ", version)) end)
|
||||
comms_v.register(databus.ps, "comms_version", function (version) comms_v.set_value(util.c("NT: v", version)) end)
|
||||
|
||||
--
|
||||
-- rps list
|
||||
@ -126,17 +126,17 @@ local function init(panel)
|
||||
local rps_ccl = LED{parent=rps,label="LO CCOOLANT",colors=cpair(colors.red,colors.red_off)}
|
||||
local rps_hcl = LED{parent=rps,label="HI HCOOLANT",colors=cpair(colors.red,colors.red_off)}
|
||||
|
||||
databus.rx_field("rps_manual", rps_man.update)
|
||||
databus.rx_field("rps_automatic", rps_auto.update)
|
||||
databus.rx_field("rps_timeout", rps_tmo.update)
|
||||
databus.rx_field("rps_fault", rps_flt.update)
|
||||
databus.rx_field("rps_sysfail", rps_fail.update)
|
||||
databus.rx_field("rps_damage", rps_dmg.update)
|
||||
databus.rx_field("rps_high_temp", rps_tmp.update)
|
||||
databus.rx_field("rps_no_fuel", rps_nof.update)
|
||||
databus.rx_field("rps_high_waste", rps_wst.update)
|
||||
databus.rx_field("rps_low_ccool", rps_ccl.update)
|
||||
databus.rx_field("rps_high_hcool", rps_hcl.update)
|
||||
rps_man.register(databus.ps, "rps_manual", rps_man.update)
|
||||
rps_auto.register(databus.ps, "rps_automatic", rps_auto.update)
|
||||
rps_tmo.register(databus.ps, "rps_timeout", rps_tmo.update)
|
||||
rps_flt.register(databus.ps, "rps_fault", rps_flt.update)
|
||||
rps_fail.register(databus.ps, "rps_sysfail", rps_fail.update)
|
||||
rps_dmg.register(databus.ps, "rps_damage", rps_dmg.update)
|
||||
rps_tmp.register(databus.ps, "rps_high_temp", rps_tmp.update)
|
||||
rps_nof.register(databus.ps, "rps_no_fuel", rps_nof.update)
|
||||
rps_wst.register(databus.ps, "rps_high_waste", rps_wst.update)
|
||||
rps_ccl.register(databus.ps, "rps_low_ccool", rps_ccl.update)
|
||||
rps_hcl.register(databus.ps, "rps_high_hcool", rps_hcl.update)
|
||||
end
|
||||
|
||||
return init
|
||||
|
@ -44,10 +44,8 @@ function renderer.close_ui()
|
||||
-- stop blinking indicators
|
||||
flasher.clear()
|
||||
|
||||
-- hide to stop animation callbacks
|
||||
ui.display.hide()
|
||||
|
||||
-- clear root UI elements
|
||||
-- delete element tree
|
||||
ui.display.delete()
|
||||
ui.display = nil
|
||||
|
||||
-- restore colors
|
||||
|
@ -18,7 +18,7 @@ local plc = require("reactor-plc.plc")
|
||||
local renderer = require("reactor-plc.renderer")
|
||||
local threads = require("reactor-plc.threads")
|
||||
|
||||
local R_PLC_VERSION = "v1.2.0"
|
||||
local R_PLC_VERSION = "v1.3.0"
|
||||
|
||||
local println = util.println
|
||||
local println_ts = util.println_ts
|
||||
|
Loading…
Reference in New Issue
Block a user