#136 send rps trip cause with status, moved rps is_tripped to rps status from main status, increased plc status send rate to 2 Hz

This commit is contained in:
Mikayla Fischler 2022-12-07 12:59:21 -05:00
parent 52603e3579
commit 2a99d1d385
5 changed files with 33 additions and 31 deletions

View File

@ -315,6 +315,7 @@ function plc.rps_init(reactor, is_formed)
status = rps_status_t.automatic
else
self.tripped = false
self.trip_cause = rps_status_t.ok
end
-- if a new trip occured...
@ -339,7 +340,10 @@ function plc.rps_init(reactor, is_formed)
end
function public.status() return self.state end
function public.is_tripped() return self.tripped end
function public.get_trip_cause() return self.trip_cause end
function public.is_active() return self.reactor_enabled end
function public.is_formed() return self.formed end
function public.is_force_disabled() return self.force_disabled end
@ -623,7 +627,6 @@ function plc.comms(id, version, modem, local_port, server_port, reactor, rps, co
local sys_status = {
util.time(), -- timestamp
(not self.scrammed), -- requested control state
rps.is_tripped(), -- rps_tripped
no_reactor, -- no reactor peripheral connected
formed, -- reactor formed
heating_rate, -- heating rate
@ -641,7 +644,7 @@ function plc.comms(id, version, modem, local_port, server_port, reactor, rps, co
-- send reactor protection system status
function public.send_rps_status()
if self.linked then
_send(RPLC_TYPES.RPS_STATUS, rps.status())
_send(RPLC_TYPES.RPS_STATUS, { rps.is_tripped(), rps.get_trip_cause(), table.unpack(rps.status()) })
end
end

View File

@ -14,7 +14,7 @@ local config = require("reactor-plc.config")
local plc = require("reactor-plc.plc")
local threads = require("reactor-plc.threads")
local R_PLC_VERSION = "beta-v0.9.8"
local R_PLC_VERSION = "beta-v0.9.9"
local print = util.print
local println = util.println

View File

@ -10,7 +10,7 @@ local println = util.println
local print_ts = util.print_ts
local println_ts = util.println_ts
local MAIN_CLOCK = 1 -- (1Hz, 20 ticks)
local MAIN_CLOCK = 0.5 -- (2Hz, 10 ticks)
local RPS_SLEEP = 250 -- (250ms, 5 ticks)
local COMMS_SLEEP = 150 -- (150ms, 3 ticks)
local SP_CTRL_SLEEP = 250 -- (250ms, 5 ticks)
@ -37,9 +37,9 @@ function threads.thread__main(smem, init)
function public.exec()
log.debug("main thread init, clock inactive")
-- send status updates at 1Hz (every 20 server ticks) (every loop tick)
-- send link requests at 0.5Hz (every 40 server ticks) (every 4 loop ticks)
local LINK_TICKS = 4
-- send status updates at 2Hz (every 10 server ticks) (every loop tick)
-- send link requests at 0.5Hz (every 40 server ticks) (every 8 loop ticks)
local LINK_TICKS = 8
local ticks_to_update = 0
local loop_clock = util.new_clock(MAIN_CLOCK)

View File

@ -161,18 +161,20 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
-- copy in the RPS status
---@param rps_status table
local function _copy_rps_status(rps_status)
self.sDB.rps_status.dmg_crit = rps_status[1]
self.sDB.rps_status.high_temp = rps_status[2]
self.sDB.rps_status.no_cool = rps_status[3]
self.sDB.rps_status.ex_waste = rps_status[4]
self.sDB.rps_status.ex_hcool = rps_status[5]
self.sDB.rps_status.no_fuel = rps_status[6]
self.sDB.rps_status.fault = rps_status[7]
self.sDB.rps_status.timeout = rps_status[8]
self.sDB.rps_status.manual = rps_status[9]
self.sDB.rps_status.automatic = rps_status[10]
self.sDB.rps_status.sys_fail = rps_status[11]
self.sDB.rps_status.force_dis = rps_status[12]
self.sDB.rps_tripped = rps_status[1]
self.sDB.rps_trip_cause = rps_status[2]
self.sDB.rps_status.dmg_crit = rps_status[3]
self.sDB.rps_status.high_temp = rps_status[4]
self.sDB.rps_status.no_cool = rps_status[5]
self.sDB.rps_status.ex_waste = rps_status[6]
self.sDB.rps_status.ex_hcool = rps_status[7]
self.sDB.rps_status.no_fuel = rps_status[8]
self.sDB.rps_status.fault = rps_status[9]
self.sDB.rps_status.timeout = rps_status[10]
self.sDB.rps_status.manual = rps_status[11]
self.sDB.rps_status.automatic = rps_status[12]
self.sDB.rps_status.sys_fail = rps_status[13]
self.sDB.rps_status.force_dis = rps_status[14]
end
-- copy in the reactor status
@ -299,19 +301,18 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
-- handle packet by type
if pkt.type == RPLC_TYPES.STATUS then
-- status packet received, update data
if pkt.length >= 5 then
if pkt.length >= 4 then
self.sDB.last_status_update = pkt.data[1]
self.sDB.control_state = pkt.data[2]
self.sDB.rps_tripped = pkt.data[3]
self.sDB.no_reactor = pkt.data[4]
self.sDB.formed = pkt.data[5]
self.sDB.no_reactor = pkt.data[3]
self.sDB.formed = pkt.data[4]
if not self.sDB.no_reactor and self.sDB.formed then
self.sDB.mek_status.heating_rate = pkt.data[6] or 0.0
self.sDB.mek_status.heating_rate = pkt.data[5] or 0.0
-- attempt to read mek_data table
if pkt.data[7] ~= nil then
local status = pcall(_copy_status, pkt.data[7])
if pkt.data[6] ~= nil then
local status = pcall(_copy_status, pkt.data[6])
if status then
-- copied in status data OK
self.received_status_cache = true
@ -396,7 +397,7 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
end
elseif pkt.type == RPLC_TYPES.RPS_STATUS then
-- RPS status packet received, copy data
if pkt.length == 12 then
if pkt.length == 14 then
local status = pcall(_copy_rps_status, pkt.data)
if status then
-- copied in RPS status data OK
@ -410,9 +411,7 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
elseif pkt.type == RPLC_TYPES.RPS_ALARM then
-- RPS alarm
if pkt.length == 13 then
self.sDB.rps_tripped = true
self.sDB.rps_trip_cause = pkt.data[1]
local status = pcall(_copy_rps_status, { table.unpack(pkt.data, 2, pkt.length) })
local status = pcall(_copy_rps_status, { true, table.unpack(pkt.data) })
if status then
-- copied in RPS status data OK
else

View File

@ -14,7 +14,7 @@ local svsessions = require("supervisor.session.svsessions")
local config = require("supervisor.config")
local supervisor = require("supervisor.supervisor")
local SUPERVISOR_VERSION = "beta-v0.8.4"
local SUPERVISOR_VERSION = "beta-v0.8.5"
local print = util.print
local println = util.println