#182 added scram/reset buttons to PLC front panel

This commit is contained in:
Mikayla Fischler 2023-04-08 21:35:44 -04:00
parent 6bd7dd0271
commit 27a697c27e
7 changed files with 73 additions and 37 deletions

View File

@ -1,84 +1,101 @@
--
-- Data Bus - Central Communication Linking for PLC PSIL
-- Data Bus - Central Communication Linking for PLC Front Panel
--
local log = require("scada-common.log")
local psil = require("scada-common.psil")
local util = require("scada-common.util")
local databus = {}
local 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()
ps.toggle("heartbeat")
function databus.heartbeat() dbus_iface.ps.toggle("heartbeat") end
-- link RPS command functions
---@param scram function reactor SCRAM function
---@param reset function RPS reset function
function databus.link_rps(scram, reset)
dbus_iface.rps_scram = scram
dbus_iface.rps_reset = reset
end
-- transmit a command to the RPS to SCRAM
function databus.rps_scram() dbus_iface.rps_scram() end
-- transmit a command to the RPS to reset
function databus.rps_reset() dbus_iface.rps_reset() end
-- transmit firmware versions across the bus
---@param plc_v string PLC version
---@param comms_v string comms version
function databus.tx_versions(plc_v, comms_v)
ps.publish("version", plc_v)
ps.publish("comms_version", comms_v)
dbus_iface.ps.publish("version", plc_v)
dbus_iface.ps.publish("comms_version", comms_v)
end
-- transmit unit ID across the bus
---@param id integer unit ID
function databus.tx_id(id)
ps.publish("unit_id", id)
dbus_iface.ps.publish("unit_id", id)
end
-- transmit hardware status across the bus
---@param plc_state plc_state
function databus.tx_hw_status(plc_state)
ps.publish("reactor_dev_state", util.trinary(plc_state.no_reactor, 1, util.trinary(plc_state.reactor_formed, 3, 2)))
ps.publish("has_modem", not plc_state.no_modem)
ps.publish("degraded", plc_state.degraded)
ps.publish("init_ok", plc_state.init_ok)
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)
end
-- transmit thread (routine) statuses
---@param thread string thread name
---@param ok boolean thread state
function databus.tx_rt_status(thread, ok)
ps.publish(util.c("routine__", thread), ok)
dbus_iface.ps.publish(util.c("routine__", thread), ok)
end
-- transmit supervisor link state across the bus
---@param state integer
function databus.tx_link_state(state)
ps.publish("link_state", state)
dbus_iface.ps.publish("link_state", state)
end
-- transmit reactor enable state across the bus
---@param active boolean reactor active
function databus.tx_reactor_state(active)
ps.publish("reactor_active", active)
dbus_iface.ps.publish("reactor_active", active)
end
-- transmit RPS data across the bus
---@param tripped boolean RPS tripped
---@param status table RPS status
function databus.tx_rps(tripped, status)
ps.publish("rps_scram", tripped)
ps.publish("rps_damage", status[1])
ps.publish("rps_high_temp", status[2])
ps.publish("rps_low_ccool", status[3])
ps.publish("rps_high_waste", status[4])
ps.publish("rps_high_hcool", status[5])
ps.publish("rps_no_fuel", status[6])
ps.publish("rps_fault", status[7])
ps.publish("rps_timeout", status[8])
ps.publish("rps_manual", status[9])
ps.publish("rps_automatic", status[10])
ps.publish("rps_sysfail", status[11])
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])
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)
ps.subscribe(field, func)
dbus_iface.ps.subscribe(field, func)
end
return databus

View File

@ -16,6 +16,8 @@ local Div = require("graphics.elements.div")
local Rectangle = require("graphics.elements.rectangle")
local TextBox = require("graphics.elements.textbox")
local PushButton = require("graphics.elements.controls.push_button")
local LED = require("graphics.elements.indicators.led")
local LEDPair = require("graphics.elements.indicators.ledpair")
local RGBLED = require("graphics.elements.indicators.ledrgb")
@ -65,11 +67,18 @@ local function init(monitor)
databus.rx_field("routine__comms_rx", rt_cmrx.update)
databus.rx_field("routine__spctl", rt_sctl.update)
local status = Div{parent=panel,width=16,height=4,x=18,y=3}
local status = Div{parent=panel,width=19,height=18,x=17,y=3}
local active = LED{parent=status,label="RCT ACTIVE",colors=cpair(colors.green,colors.green_off)}
local scram = LED{parent=status,label="RPS TRIP",colors=cpair(colors.red,colors.red_off),flash=true,period=flasher.PERIOD.BLINK_250_MS}
system.line_break()
local active = LED{parent=status,x=2,width=12,label="RCT ACTIVE",colors=cpair(colors.green,colors.green_off)}
local status_trip_rct = Rectangle{parent=status,width=20,height=3,x=1,y=2,border=border(1,colors.lightGray,true),even_inner=true,fg_bg=cpair(colors.black,colors.ivory)}
local status_trip = Div{parent=status_trip_rct,width=18,height=1,fg_bg=cpair(colors.black,colors.lightGray)}
local scram = LED{parent=status_trip,width=10,label="RPS TRIP",colors=cpair(colors.red,colors.red_off),flash=true,period=flasher.PERIOD.BLINK_250_MS}
local controls_rct = Rectangle{parent=status,width=17,height=3,x=1,y=5,border=border(1,colors.white,true),even_inner=true,fg_bg=cpair(colors.black,colors.ivory)}
local controls = Div{parent=controls_rct,width=15,height=1,fg_bg=cpair(colors.black,colors.white)}
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)

View File

@ -13,6 +13,7 @@ local cpair = core.graphics.cpair
-- remap global colors
colors.ivory = colors.pink
colors.red_off = colors.brown
colors.yellow_off = colors.magenta
colors.green_off = colors.lime
style.root = cpair(colors.black, colors.ivory)
@ -29,9 +30,9 @@ style.colors = {
{ c = colors.blue, hex = 0x0096ff },
{ c = colors.purple, hex = 0xb156ee },
{ c = colors.pink, hex = 0xdcd9ca }, -- IVORY
{ c = colors.magenta, hex = 0xf9488a },
{ c = colors.magenta, hex = 0x85862c }, -- YELLOW OFF
-- { c = colors.white, hex = 0xdcd9ca },
{ c = colors.lightGray, hex = 0x999f9b },
{ c = colors.lightGray, hex = 0xb1b8b3 },
{ c = colors.gray, hex = 0x575757 },
-- { c = colors.black, hex = 0x191919 },
{ c = colors.brown, hex = 0x672223 } -- RED OFF

View File

@ -396,6 +396,9 @@ function plc.rps_init(reactor, is_formed)
end
end
-- link functions with databus
databus.link_rps(public.trip_manual, public.reset)
return public
end

View File

@ -67,9 +67,9 @@ end
function renderer.ui_ready() return ui.view ~= nil end
-- handle a touch event
---@param event monitor_touch
function renderer.handle_touch(event)
ui.view.handle_touch(event)
---@param event mouse_interaction
function renderer.handle_mouse(event)
ui.view.handle_mouse(event)
end
return renderer

View File

@ -17,7 +17,7 @@ local plc = require("reactor-plc.plc")
local renderer = require("reactor-plc.renderer")
local threads = require("reactor-plc.threads")
local R_PLC_VERSION = "v1.1.2"
local R_PLC_VERSION = "v1.1.3"
local print = util.print
local println = util.println

View File

@ -5,6 +5,9 @@ local tcallbackdsp = require("scada-common.tcallbackdsp")
local util = require("scada-common.util")
local databus = require("reactor-plc.databus")
local renderer = require("reactor-plc.renderer")
local core = require("graphics.core")
local threads = {}
@ -255,6 +258,9 @@ function threads.thread__main(smem, init)
-- update indicators
databus.tx_hw_status(plc_state)
elseif event == "mouse_click" then
-- handle a monitor touch event
renderer.handle_mouse(core.events.click(param1, param2, param3))
elseif event == "clock_start" then
-- start loop clock
loop_clock.start()