diff --git a/reactor-plc/databus.lua b/reactor-plc/databus.lua index 32d3c9f..52f74ad 100644 --- a/reactor-plc/databus.lua +++ b/reactor-plc/databus.lua @@ -43,7 +43,9 @@ end -- transmit unit ID across the bus ---@param id integer unit ID -function databus.tx_id(id) databus.ps.publish("unit_id", id) end +function databus.tx_id(id) + databus.ps.publish("unit_id", id) +end -- transmit hardware status across the bus ---@param plc_state plc_state @@ -57,15 +59,21 @@ end -- transmit thread (routine) statuses ---@param thread string thread name ---@param ok boolean thread state -function databus.tx_rt_status(thread, ok) databus.ps.publish(util.c("routine__", thread), ok) end +function databus.tx_rt_status(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) databus.ps.publish("link_state", state) end +function databus.tx_link_state(state) + databus.ps.publish("link_state", state) +end -- transmit reactor enable state across the bus ---@param active any reactor active -function databus.tx_reactor_state(active) databus.ps.publish("reactor_active", active == true) end +function databus.tx_reactor_state(active) + databus.ps.publish("reactor_active", active == true) +end -- transmit RPS data across the bus ---@param tripped boolean RPS tripped diff --git a/reactor-plc/panel/front_panel.lua b/reactor-plc/panel/front_panel.lua index b76b3cb..985d00c 100644 --- a/reactor-plc/panel/front_panel.lua +++ b/reactor-plc/panel/front_panel.lua @@ -39,9 +39,7 @@ local ind_red = style.ind_red local function init(panel, config) local s_hi_box = style.theme.highlight_box - local disabled_fg = style.fp.disabled_fg - - local term_w, term_h = term.getSize() + local term_w, _ = term.getSize() local header = TextBox{parent=panel,y=1,text="FISSION REACTOR PLC - UNIT ?",alignment=ALIGN.CENTER,fg_bg=style.theme.header} header.register(databus.ps, "unit_id", function (id) header.set_value(util.c("FISSION REACTOR PLC - UNIT ", id)) end) @@ -64,8 +62,8 @@ local function init(panel, config) if config.Networked then if config.WirelessModem and config.WiredModem then - local wl_modem = LED{parent=system,label="WD MODEM",colors=ind_grn} - local wd_modem = LED{parent=system,label="WL MODEM",colors=ind_grn} + local wd_modem = LED{parent=system,label="WD MODEM",colors=ind_grn} + local wl_modem = LED{parent=system,label="WL MODEM",colors=ind_grn} wd_modem.register(databus.ps, "has_wd_modem", wd_modem.update) wl_modem.register(databus.ps, "has_wl_modem", wl_modem.update) else @@ -159,9 +157,9 @@ local function init(panel, config) ---@diagnostic disable-next-line: undefined-field local comp_id = util.sprintf("%03d", os.getComputerID()) - TextBox{parent=hw_labels,text="FW "..databus.ps.get("version"),fg_bg=s_hi_box} - TextBox{parent=hw_labels,text="COMM v"..databus.ps.get("comms_version"),fg_bg=s_hi_box} - TextBox{parent=hw_labels,text="S/N PLC-"..comp_id,fg_bg=s_hi_box} + TextBox{parent=hw_labels,text="FW "..databus.ps.get("version"),fg_bg=s_hi_box} + TextBox{parent=hw_labels,text="NT v"..databus.ps.get("comms_version"),fg_bg=s_hi_box} + TextBox{parent=hw_labels,text="S/N PLC-"..comp_id,fg_bg=s_hi_box} -- -- rps list diff --git a/rtu/backplane.lua b/rtu/backplane.lua index 63dc14c..4415fe0 100644 --- a/rtu/backplane.lua +++ b/rtu/backplane.lua @@ -49,6 +49,8 @@ function backplane.init(config, __shared_memory) -- set this as active for now _bp.act_nic = wd_nic _bp.wd_nic = wd_nic + + databus.tx_hw_wd_modem(modem ~= nil) end -- init wireless NIC(s) @@ -64,9 +66,9 @@ function backplane.init(config, __shared_memory) end _bp.wl_nic = wl_nic - end - databus.tx_hw_modem(_bp.act_nic.is_connected()) + databus.tx_hw_wl_modem(modem ~= nil) + end -- at least one comms modem is required if not ((_bp.wd_nic and _bp.wd_nic.is_connected()) or (_bp.wl_nic and _bp.wl_nic.is_connected())) then @@ -120,9 +122,13 @@ function backplane.detach(type, device, iface, print_no_fp) if wd_nic and wd_nic.is_modem(device) then wd_nic.disconnect() log.info("BKPLN: WIRED PHY_DOWN " .. iface) + + databus.tx_hw_wd_modem(false) elseif wl_nic and wl_nic.is_modem(device) then wl_nic.disconnect() log.info("BKPLN: WIRELESS PHY_DOWN " .. iface) + + databus.tx_hw_wl_modem(false) end -- we only care if this is our active comms modem @@ -141,13 +147,13 @@ function backplane.detach(type, device, iface, print_no_fp) wl_nic.connect(modem) log.info("BKPLN: WIRELESS PHY_UP " .. m_iface) + + databus.tx_hw_wl_modem(true) elseif wd_nic and wd_nic.is_connected() then _bp.act_nic = _bp.wd_nic comms.switch_nic(_bp.act_nic) log.info("BKPLN: switched comms to wired modem") - else - databus.tx_hw_modem(false) end elseif wl_nic and wl_nic.is_connected() then -- wired active disconnected, wireless available @@ -157,7 +163,6 @@ function backplane.detach(type, device, iface, print_no_fp) log.info("BKPLN: switched comms to wireless modem") else -- wired active disconnected, wireless unavailable - databus.tx_hw_modem(false) end elseif _bp.wl_nic and m_is_wl then -- wireless, but not active @@ -214,7 +219,7 @@ function backplane.attach(type, device, iface, print_no_fp) comms.switch_nic(_bp.act_nic) log.info("BKPLN: switched comms to wired modem (preferred)") - databus.tx_hw_modem(true) + databus.tx_hw_wd_modem(true) end elseif wl_nic and (not wl_nic.is_connected()) and m_is_wl then -- connect this as the wireless NIC @@ -229,7 +234,7 @@ function backplane.attach(type, device, iface, print_no_fp) comms.switch_nic(_bp.act_nic) log.info("BKPLN: switched comms to wireless modem (preferred)") - databus.tx_hw_modem(true) + databus.tx_hw_wl_modem(true) end elseif wl_nic and m_is_wl then -- the wireless NIC already has a modem diff --git a/rtu/databus.lua b/rtu/databus.lua index 50deeb7..aec06ae 100644 --- a/rtu/databus.lua +++ b/rtu/databus.lua @@ -31,10 +31,16 @@ function databus.tx_versions(rtu_v, comms_v) databus.ps.publish("comms_version", comms_v) end --- transmit hardware status for comms modem connection state +-- transmit hardware status for the wireless comms modem connection state ---@param has_modem boolean -function databus.tx_hw_modem(has_modem) - databus.ps.publish("has_modem", has_modem) +function databus.tx_hw_wl_modem(has_modem) + databus.ps.publish("has_wl_modem", has_modem) +end + +-- transmit hardware status for the wired comms modem connection state +---@param has_modem boolean +function databus.tx_hw_wd_modem(has_modem) + databus.ps.publish("has_wd_modem", has_modem) end -- transmit the number of speakers connected diff --git a/rtu/panel/front_panel.lua b/rtu/panel/front_panel.lua index 0b9c2ed..4166783 100644 --- a/rtu/panel/front_panel.lua +++ b/rtu/panel/front_panel.lua @@ -12,6 +12,7 @@ local style = require("rtu.panel.style") local core = require("graphics.core") local Div = require("graphics.elements.Div") +local Rectangle = require("graphics.elements.Rectangle") local TextBox = require("graphics.elements.TextBox") local DataIndicator = require("graphics.elements.indicators.DataIndicator") @@ -25,6 +26,7 @@ local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE local ALIGN = core.ALIGN local cpair = core.cpair +local border = core.border local ind_grn = style.ind_grn @@ -32,8 +34,11 @@ local UNIT_TYPE_LABELS = { "UNKNOWN", "REDSTONE", "BOILER", "TURBINE", "DYNAMIC -- create new front panel view ---@param panel DisplayBox main displaybox +---@param config rtu_config configuraiton ---@param units rtu_registry_entry[] unit list -local function init(panel, units) +local function init(panel, config, units) + local s_hi_box = style.theme.highlight_box + local disabled_fg = style.fp.disabled_fg local term_w, term_h = term.getSize() @@ -53,7 +58,15 @@ local function init(panel, units) heartbeat.register(databus.ps, "heartbeat", heartbeat.update) - local modem = LED{parent=system,label="MODEM",colors=ind_grn} + if config.WirelessModem and config.WiredModem then + local wd_modem = LED{parent=system,label="WD MODEM",colors=ind_grn} + local wl_modem = LED{parent=system,label="WL MODEM",colors=ind_grn} + wd_modem.register(databus.ps, "has_wd_modem", wd_modem.update) + wl_modem.register(databus.ps, "has_wl_modem", wl_modem.update) + else + local modem = LED{parent=system,label="MODEM",colors=ind_grn} + modem.register(databus.ps, util.trinary(config.WirelessModem, "has_wl_modem", "has_wd_modem"), modem.update) + end if not style.colorblind then local network = RGBLED{parent=system,label="NETWORK",colors={colors.green,colors.red,colors.yellow,colors.orange,style.ind_bkg}} @@ -90,8 +103,6 @@ local function init(panel, units) system.line_break() - modem.register(databus.ps, "has_modem", modem.update) - local rt_main = LED{parent=system,label="RT MAIN",colors=ind_grn} local rt_comm = LED{parent=system,label="RT COMMS",colors=ind_grn} system.line_break() @@ -99,25 +110,27 @@ local function init(panel, units) rt_main.register(databus.ps, "routine__main", rt_main.update) rt_comm.register(databus.ps, "routine__comms", rt_comm.update) + -- + -- hardware labeling + -- + + local hw_labels = Rectangle{parent=panel,y=term_h-6,width=15,height=5,border=border(1,s_hi_box.bkg,true),even_inner=true} + ---@diagnostic disable-next-line: undefined-field - local comp_id = util.sprintf("(%d)", os.getComputerID()) - TextBox{parent=system,x=9,y=4,width=6,text=comp_id,fg_bg=disabled_fg} + local comp_id = util.sprintf("%03d", os.getComputerID()) - TextBox{parent=system,y=term_h-5,text="SPEAKERS",width=8,fg_bg=style.fp.text_fg} - local speaker_count = DataIndicator{parent=system,x=10,y=term_h-5,label="",format="%3d",value=0,width=3,fg_bg=style.theme.field_box} + TextBox{parent=hw_labels,text="FW "..databus.ps.get("version"),fg_bg=s_hi_box} + TextBox{parent=hw_labels,text="NT v"..databus.ps.get("comms_version"),fg_bg=s_hi_box} + TextBox{parent=hw_labels,text="S/N RTU-"..comp_id,fg_bg=s_hi_box} + + -- + -- speaker count + -- + + TextBox{parent=panel,x=2,y=term_h-1,text="SPEAKERS",width=8,fg_bg=style.fp.text_fg} + local speaker_count = DataIndicator{parent=panel,x=11,y=term_h-1,label="",format="%3d",value=0,width=3,fg_bg=style.theme.field_box} speaker_count.register(databus.ps, "speaker_count", speaker_count.update) - -- - -- about label - -- - - local about = Div{parent=panel,width=15,height=2,y=term_h-1,fg_bg=disabled_fg} - local fw_v = TextBox{parent=about,text="FW: v00.00.00"} - local comms_v = TextBox{parent=about,text="NT: v00.00.00"} - - 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) - -- -- unit status list -- diff --git a/rtu/renderer.lua b/rtu/renderer.lua index dd86a06..0c8366d 100644 --- a/rtu/renderer.lua +++ b/rtu/renderer.lua @@ -18,16 +18,15 @@ local ui = { } -- try to start the UI +---@param config rtu_config configuration ---@param units rtu_registry_entry[] RTU entries ----@param theme FP_THEME front panel theme ----@param color_mode COLOR_MODE color mode ---@return boolean success, any error_msg -function renderer.try_start_ui(units, theme, color_mode) +function renderer.try_start_ui(config, units) local status, msg = true, nil if ui.display == nil then -- set theme - style.set_theme(theme, color_mode) + style.set_theme(config.FrontPanelTheme, config.ColorMode) -- reset terminal term.setTextColor(colors.white) @@ -41,7 +40,7 @@ function renderer.try_start_ui(units, theme, color_mode) end -- apply color mode - local c_mode_overrides = style.theme.color_modes[color_mode] + local c_mode_overrides = style.theme.color_modes[config.ColorMode] for i = 1, #c_mode_overrides do term.setPaletteColor(c_mode_overrides[i].c, c_mode_overrides[i].hex) end @@ -49,7 +48,7 @@ function renderer.try_start_ui(units, theme, color_mode) -- init front panel view status, msg = pcall(function () ui.display = DisplayBox{window=term.current(),fg_bg=style.fp.root} - panel_view(ui.display, units) + panel_view(ui.display, config, units) end) if status then diff --git a/rtu/startup.lua b/rtu/startup.lua index 26230e1..ad6172a 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -124,7 +124,7 @@ local function main() -- start UI local message - rtu_state.fp_ok, message = renderer.try_start_ui(units, config.FrontPanelTheme, config.ColorMode) + rtu_state.fp_ok, message = renderer.try_start_ui(config, units) if not rtu_state.fp_ok then println_ts(util.c("UI error: ", message)) diff --git a/supervisor/panel/front_panel.lua b/supervisor/panel/front_panel.lua index 9a28db6..b86520b 100644 --- a/supervisor/panel/front_panel.lua +++ b/supervisor/panel/front_panel.lua @@ -65,32 +65,28 @@ local function init(panel, config) heartbeat.register(databus.ps, "heartbeat", heartbeat.update) - if config.WirelessModem then - local wl_modem = LED{parent=system,label="WL MODEM",colors=ind_grn} - system.line_break() - - wl_modem.register(databus.ps, "has_wl_modem", wl_modem.update) - end - - if config.WiredModem then + if config.WirelessModem and config.WiredModem then local wd_modem = LED{parent=system,label="WD MODEM",colors=ind_grn} - system.line_break() - + local wl_modem = LED{parent=system,label="WL MODEM",colors=ind_grn} wd_modem.register(databus.ps, "has_wd_modem", wd_modem.update) + wl_modem.register(databus.ps, "has_wl_modem", wl_modem.update) + else + local modem = LED{parent=system,label="MODEM",colors=ind_grn} + modem.register(databus.ps, util.trinary(config.WirelessModem, "has_wl_modem", "has_wd_modem"), modem.update) end -- -- hardware labeling -- - local hw_labels = Rectangle{parent=main_page,x=2,y=term_h-7,width=17,height=5,border=border(1,s_hi_box.bkg,true),even_inner=true} + local hw_labels = Rectangle{parent=main_page,y=term_h-7,width=15,height=5,border=border(1,s_hi_box.bkg,true),even_inner=true} ---@diagnostic disable-next-line: undefined-field local comp_id = util.sprintf("%03d", os.getComputerID()) - TextBox{parent=hw_labels,text="FW "..databus.ps.get("version"),fg_bg=s_hi_box} - TextBox{parent=hw_labels,text="COMM v"..databus.ps.get("comms_version"),fg_bg=s_hi_box} - TextBox{parent=hw_labels,text="S/N SVR-"..comp_id,fg_bg=s_hi_box} + TextBox{parent=hw_labels,text="FW "..databus.ps.get("version"),fg_bg=s_hi_box} + TextBox{parent=hw_labels,text="NT v"..databus.ps.get("comms_version"),fg_bg=s_hi_box} + TextBox{parent=hw_labels,text="S/N SVR-"..comp_id,fg_bg=s_hi_box} -- -- page handling