mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
85 lines
2.4 KiB
Lua
85 lines
2.4 KiB
Lua
--
|
|
-- Data Bus - Central Communication Linking for PLC PSIL
|
|
--
|
|
|
|
local psil = require("scada-common.psil")
|
|
local util = require("scada-common.util")
|
|
|
|
local databus = {}
|
|
|
|
local ps = psil.create()
|
|
|
|
-- call to toggle heartbeat signal
|
|
function databus.heartbeat()
|
|
ps.toggle("heartbeat")
|
|
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)
|
|
end
|
|
|
|
-- transmit unit ID across the bus
|
|
---@param id integer unit ID
|
|
function databus.tx_id(id)
|
|
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)
|
|
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)
|
|
end
|
|
|
|
-- transmit supervisor link state across the bus
|
|
---@param state integer
|
|
function databus.tx_link_state(state)
|
|
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)
|
|
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])
|
|
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)
|
|
end
|
|
|
|
return databus
|