#200 work on pocket comms

This commit is contained in:
Mikayla 2024-03-07 17:27:25 +00:00
parent ce37a672a3
commit f0f2aadf53
3 changed files with 49 additions and 27 deletions

View File

@ -278,20 +278,7 @@ function iocontrol.init(conf, comms, temp_scale)
},
---@type alarms
alarms = {
ALARM_STATE.INACTIVE, -- containment breach
ALARM_STATE.INACTIVE, -- containment radiation
ALARM_STATE.INACTIVE, -- reactor lost
ALARM_STATE.INACTIVE, -- damage critical
ALARM_STATE.INACTIVE, -- reactor taking damage
ALARM_STATE.INACTIVE, -- reactor over temperature
ALARM_STATE.INACTIVE, -- reactor high temperature
ALARM_STATE.INACTIVE, -- waste leak
ALARM_STATE.INACTIVE, -- waste level high
ALARM_STATE.INACTIVE, -- RPS transient
ALARM_STATE.INACTIVE, -- RCS transient
ALARM_STATE.INACTIVE -- turbine trip
},
alarms = { ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE, ALARM_STATE.INACTIVE },
annunciator = {}, ---@type annunciator

View File

@ -8,7 +8,7 @@ local iocontrol = require("coordinator.iocontrol")
local pocket = {}
local PROTOCOL = comms.PROTOCOL
-- local CRDN_TYPE = comms.CRDN_TYPE
local CRDN_TYPE = comms.CRDN_TYPE
local MGMT_TYPE = comms.MGMT_TYPE
-- retry time constants in ms
@ -73,18 +73,18 @@ function pocket.new_session(id, s_addr, in_queue, out_queue, timeout)
end
-- send a CRDN packet
-----@param msg_type CRDN_TYPE
-----@param msg table
-- local function _send(msg_type, msg)
-- local s_pkt = comms.scada_packet()
-- local c_pkt = comms.crdn_packet()
---@param msg_type CRDN_TYPE
---@param msg table
local function _send(msg_type, msg)
local s_pkt = comms.scada_packet()
local c_pkt = comms.crdn_packet()
-- c_pkt.make(msg_type, msg)
-- s_pkt.make(self.seq_num, PROTOCOL.SCADA_CRDN, c_pkt.raw_sendable())
c_pkt.make(msg_type, msg)
s_pkt.make(s_addr, self.seq_num, PROTOCOL.SCADA_CRDN, c_pkt.raw_sendable())
-- out_queue.push_packet(s_pkt)
-- self.seq_num = self.seq_num + 1
-- end
out_queue.push_packet(s_pkt)
self.seq_num = self.seq_num + 1
end
-- send a SCADA management packet
---@param msg_type MGMT_TYPE
@ -120,8 +120,41 @@ function pocket.new_session(id, s_addr, in_queue, out_queue, timeout)
if pkt.scada_frame.protocol() == PROTOCOL.SCADA_CRDN then
---@cast pkt crdn_frame
local db = iocontrol.get_db()
-- handle packet by type
if pkt.type == nil then
if pkt.type == CRDN_TYPE.API_GET_FAC then
local fac = db.facility
---@class api_fac
local data = {
num_units = fac.num_units,
num_tanks = util.table_len(fac.tank_data_tbl),
tank_mode = fac.tank_mode,
tank_defs = fac.tank_defs,
sys_ok = fac.all_sys_ok,
rtu_count = fac.rtu_count,
radiation = fac.radiation,
auto = { fac.auto_ready, fac.auto_active, fac.auto_ramping, fac.auto_saturated },
waste = { fac.auto_current_waste_product, fac.auto_pu_fallback_active },
has_matrix = fac.induction_data_tbl[1] ~= nil,
has_sps = fac.sps_data_tbl[1] ~= nil,
}
_send(CRDN_TYPE.API_GET_FAC, data)
elseif pkt.type == CRDN_TYPE.API_GET_UNITS then
local data = {}
for i = 1, #db.units do
local u = db.units[i] ---@type ioctl_unit
table.insert(data, {
u.unit_id,
u.num_boilers,
u.num_turbines,
u.num_snas,
u.has_tank
})
end
else
log.debug(log_header .. "handler received unsupported CRDN packet type " .. pkt.type)
end

View File

@ -64,7 +64,9 @@ local CRDN_TYPE = {
FAC_CMD = 3, -- faility command
UNIT_BUILDS = 4, -- build of each reactor unit (reactor + RTUs)
UNIT_STATUSES = 5, -- state of each of the reactor units
UNIT_CMD = 6 -- command a reactor unit
UNIT_CMD = 6, -- command a reactor unit
API_GET_FAC = 7, -- API: get all the facility data
API_GET_UNITS = 8 -- API: get all the reactor unit data
}
---@enum ESTABLISH_ACK