2023-04-08 20:49:54 +00:00
|
|
|
--
|
2023-04-09 01:35:44 +00:00
|
|
|
-- Data Bus - Central Communication Linking for PLC Front Panel
|
2023-04-08 20:49:54 +00:00
|
|
|
--
|
|
|
|
|
2023-04-09 01:35:44 +00:00
|
|
|
local log = require("scada-common.log")
|
2023-04-08 20:49:54 +00:00
|
|
|
local psil = require("scada-common.psil")
|
|
|
|
local util = require("scada-common.util")
|
|
|
|
|
|
|
|
local databus = {}
|
|
|
|
|
2023-05-13 13:43:42 +00:00
|
|
|
-- databus PSIL
|
|
|
|
databus.ps = psil.create()
|
|
|
|
|
2023-04-09 01:35:44 +00:00
|
|
|
local dbus_iface = {
|
|
|
|
rps_scram = function () log.debug("DBUS: unset rps_scram() called") end,
|
|
|
|
rps_reset = function () log.debug("DBUS: unset rps_reset() called") end
|
|
|
|
}
|
2023-04-08 20:49:54 +00:00
|
|
|
|
|
|
|
-- call to toggle heartbeat signal
|
2023-05-13 13:43:42 +00:00
|
|
|
function databus.heartbeat() databus.ps.toggle("heartbeat") end
|
2023-04-09 01:35:44 +00:00
|
|
|
|
|
|
|
-- 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
|
2023-04-08 20:49:54 +00:00
|
|
|
end
|
|
|
|
|
2023-04-09 01:35:44 +00:00
|
|
|
-- 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
|
|
|
|
|
2023-04-08 20:49:54 +00:00
|
|
|
-- 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)
|
2023-05-13 13:43:42 +00:00
|
|
|
databus.ps.publish("version", plc_v)
|
|
|
|
databus.ps.publish("comms_version", comms_v)
|
2023-04-08 20:49:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- transmit unit ID across the bus
|
|
|
|
---@param id integer unit ID
|
|
|
|
function databus.tx_id(id)
|
2023-05-13 13:43:42 +00:00
|
|
|
databus.ps.publish("unit_id", id)
|
2023-04-08 20:49:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- transmit hardware status across the bus
|
|
|
|
---@param plc_state plc_state
|
|
|
|
function databus.tx_hw_status(plc_state)
|
2023-05-13 13:43:42 +00:00
|
|
|
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)
|
2023-04-08 20:49:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- transmit thread (routine) statuses
|
|
|
|
---@param thread string thread name
|
|
|
|
---@param ok boolean thread state
|
|
|
|
function databus.tx_rt_status(thread, ok)
|
2023-05-13 13:43:42 +00:00
|
|
|
databus.ps.publish(util.c("routine__", thread), ok)
|
2023-04-08 20:49:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- transmit supervisor link state across the bus
|
|
|
|
---@param state integer
|
|
|
|
function databus.tx_link_state(state)
|
2023-05-13 13:43:42 +00:00
|
|
|
databus.ps.publish("link_state", state)
|
2023-04-08 20:49:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- transmit reactor enable state across the bus
|
|
|
|
---@param active boolean reactor active
|
|
|
|
function databus.tx_reactor_state(active)
|
2023-05-13 13:43:42 +00:00
|
|
|
databus.ps.publish("reactor_active", active)
|
2023-04-08 20:49:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- transmit RPS data across the bus
|
|
|
|
---@param tripped boolean RPS tripped
|
|
|
|
---@param status table RPS status
|
2023-04-18 15:28:46 +00:00
|
|
|
---@param emer_cool_active boolean RPS activated the emergency coolant
|
|
|
|
function databus.tx_rps(tripped, status, emer_cool_active)
|
2023-05-13 13:43:42 +00:00
|
|
|
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)
|
2023-04-08 20:49:54 +00:00
|
|
|
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)
|
2023-05-13 13:43:42 +00:00
|
|
|
databus.ps.subscribe(field, func)
|
2023-04-08 20:49:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return databus
|