Merge branch 'devel' into 488-accelerate-hmac-computation

This commit is contained in:
Mikayla Fischler 2024-06-29 12:51:52 -04:00
commit 8dedb092e7
3 changed files with 119 additions and 117 deletions

View File

@ -523,7 +523,10 @@ function iocontrol.record_unit_data(data)
reactor_state = 6 -- SCRAM reactor_state = 6 -- SCRAM
rps_status = 2 rps_status = 2
end end
else rps_status = 4 end else
rps_status = 4
reactor_state = 4
end
-- update reactor/control status -- update reactor/control status
if unit.reactor_data.mek_status.status then if unit.reactor_data.mek_status.status then

View File

@ -570,33 +570,17 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
self.seq_num = self.seq_num + 1 self.seq_num = self.seq_num + 1
end end
-- variable reactor status information, excluding heating rate -- dynamic reactor status information, excluding heating rate
---@return table data_table, boolean faulted ---@return table data_table, boolean faulted
local function _reactor_status() local function _get_reactor_status()
local fuel = nil local fuel = nil
local waste = nil local waste = nil
local coolant = nil local coolant = nil
local hcoolant = nil local hcoolant = nil
local data_table = { local data_table = {}
false, -- getStatus
0, -- getBurnRate reactor.__p_disable_afc()
0, -- getActualBurnRate
0, -- getTemperature
0, -- getDamagePercent
0, -- getBoilEfficiency
0, -- getEnvironmentalLoss
0, -- fuel_amnt
0, -- getFuelFilledPercentage
0, -- waste_amnt
0, -- getWasteFilledPercentage
"", -- coolant_name
0, -- coolant_amnt
0, -- getCoolantFilledPercentage
"", -- hcoolant_name
0, -- hcoolant_amnt
0 -- getHeatedCoolantFilledPercentage
}
local tasks = { local tasks = {
function () data_table[1] = reactor.getStatus() end, function () data_table[1] = reactor.getStatus() end,
@ -636,30 +620,32 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
data_table[16] = hcoolant.amount data_table[16] = hcoolant.amount
end end
reactor.__p_enable_afc()
return data_table, reactor.__p_is_faulted() return data_table, reactor.__p_is_faulted()
end end
-- update the status cache if changed -- update the status cache if changed
---@return boolean changed ---@return boolean changed
local function _update_status_cache() local function _update_status_cache()
local status, faulted = _reactor_status() local status, faulted = _get_reactor_status()
local changed = false local changed = false
if self.status_cache ~= nil then if not faulted then
if not faulted then if self.status_cache ~= nil then
for i = 1, #status do for i = 1, #status do
if status[i] ~= self.status_cache[i] then if status[i] ~= self.status_cache[i] then
changed = true changed = true
break break
end end
end end
else
changed = true
end end
else
changed = true
end
if changed and not faulted then if changed then
self.status_cache = status self.status_cache = status
end
end end
return changed return changed
@ -678,9 +664,11 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
_send(msg_type, { status }) _send(msg_type, { status })
end end
-- send structure properties (these should not change, server will cache these) -- send static structure properties, cached by server
local function _send_struct() local function _send_struct()
local mek_data = { false, 0, 0, 0, types.new_zero_coordinate(), types.new_zero_coordinate(), 0, 0, 0, 0, 0, 0, 0, 0 } local mek_data = {}
reactor.__p_disable_afc()
local tasks = { local tasks = {
function () mek_data[1] = reactor.getLength() end, function () mek_data[1] = reactor.getLength() end,
@ -704,6 +692,8 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
_send(RPLC_TYPE.MEK_STRUCT, mek_data) _send(RPLC_TYPE.MEK_STRUCT, mek_data)
self.resend_build = false self.resend_build = false
end end
reactor.__p_enable_afc()
end end
-- PUBLIC FUNCTIONS -- -- PUBLIC FUNCTIONS --

View File

@ -190,71 +190,111 @@ function plc.new_session(id, s_addr, i_seq_num, reactor_id, in_queue, out_queue,
-- copy in the RPS status -- copy in the RPS status
---@param rps_status table ---@param rps_status table
local function _copy_rps_status(rps_status) local function _copy_rps_status(rps_status)
self.sDB.rps_tripped = rps_status[1] local rps = self.sDB.rps_status
self.sDB.rps_trip_cause = rps_status[2]
self.sDB.rps_status.high_dmg = rps_status[3] self.sDB.rps_tripped = rps_status[1]
self.sDB.rps_status.high_temp = rps_status[4] self.sDB.rps_trip_cause = rps_status[2]
self.sDB.rps_status.low_cool = rps_status[5]
self.sDB.rps_status.ex_waste = rps_status[6] rps.high_dmg = rps_status[3]
self.sDB.rps_status.ex_hcool = rps_status[7] rps.high_temp = rps_status[4]
self.sDB.rps_status.no_fuel = rps_status[8] rps.low_cool = rps_status[5]
self.sDB.rps_status.fault = rps_status[9] rps.ex_waste = rps_status[6]
self.sDB.rps_status.timeout = rps_status[10] rps.ex_hcool = rps_status[7]
self.sDB.rps_status.manual = rps_status[11] rps.no_fuel = rps_status[8]
self.sDB.rps_status.automatic = rps_status[12] rps.fault = rps_status[9]
self.sDB.rps_status.sys_fail = rps_status[13] rps.timeout = rps_status[10]
self.sDB.rps_status.force_dis = rps_status[14] rps.manual = rps_status[11]
rps.automatic = rps_status[12]
rps.sys_fail = rps_status[13]
rps.force_dis = rps_status[14]
end end
-- copy in the reactor status -- copy in the reactor status
---@param mek_data table ---@param mek_data table
local function _copy_status(mek_data) local function _copy_status(mek_data)
local stat = self.sDB.mek_status
local struct = self.sDB.mek_struct
-- copy status information -- copy status information
self.sDB.mek_status.status = mek_data[1] stat.status = mek_data[1]
self.sDB.mek_status.burn_rate = mek_data[2] stat.burn_rate = mek_data[2]
self.sDB.mek_status.act_burn_rate = mek_data[3] stat.act_burn_rate = mek_data[3]
self.sDB.mek_status.temp = mek_data[4] stat.temp = mek_data[4]
self.sDB.mek_status.damage = mek_data[5] stat.damage = mek_data[5]
self.sDB.mek_status.boil_eff = mek_data[6] stat.boil_eff = mek_data[6]
self.sDB.mek_status.env_loss = mek_data[7] stat.env_loss = mek_data[7]
-- copy container information -- copy container information
self.sDB.mek_status.fuel = mek_data[8] stat.fuel = mek_data[8]
self.sDB.mek_status.fuel_fill = mek_data[9] stat.fuel_fill = mek_data[9]
self.sDB.mek_status.waste = mek_data[10] stat.waste = mek_data[10]
self.sDB.mek_status.waste_fill = mek_data[11] stat.waste_fill = mek_data[11]
self.sDB.mek_status.ccool_type = mek_data[12] stat.ccool_type = mek_data[12]
self.sDB.mek_status.ccool_amnt = mek_data[13] stat.ccool_amnt = mek_data[13]
self.sDB.mek_status.ccool_fill = mek_data[14] stat.ccool_fill = mek_data[14]
self.sDB.mek_status.hcool_type = mek_data[15] stat.hcool_type = mek_data[15]
self.sDB.mek_status.hcool_amnt = mek_data[16] stat.hcool_amnt = mek_data[16]
self.sDB.mek_status.hcool_fill = mek_data[17] stat.hcool_fill = mek_data[17]
-- update computable fields if we have our structure -- update computable fields if we have our structure
if self.received_struct then if self.received_struct then
self.sDB.mek_status.fuel_need = self.sDB.mek_struct.fuel_cap - self.sDB.mek_status.fuel_fill stat.fuel_need = struct.fuel_cap - stat.fuel_fill
self.sDB.mek_status.waste_need = self.sDB.mek_struct.waste_cap - self.sDB.mek_status.waste_fill stat.waste_need = struct.waste_cap - stat.waste_fill
self.sDB.mek_status.cool_need = self.sDB.mek_struct.ccool_cap - self.sDB.mek_status.ccool_fill stat.cool_need = struct.ccool_cap - stat.ccool_fill
self.sDB.mek_status.hcool_need = self.sDB.mek_struct.hcool_cap - self.sDB.mek_status.hcool_fill stat.hcool_need = struct.hcool_cap - stat.hcool_fill
end end
end end
-- copy in the reactor structure -- copy in the reactor structure
---@param mek_data table ---@param mek_data table
local function _copy_struct(mek_data) local function _copy_struct(mek_data)
self.sDB.mek_struct.length = mek_data[1] local struct = self.sDB.mek_struct
self.sDB.mek_struct.width = mek_data[2]
self.sDB.mek_struct.height = mek_data[3] struct.length = mek_data[1]
self.sDB.mek_struct.min_pos = mek_data[4] struct.width = mek_data[2]
self.sDB.mek_struct.max_pos = mek_data[5] struct.height = mek_data[3]
self.sDB.mek_struct.heat_cap = mek_data[6] struct.min_pos = mek_data[4]
self.sDB.mek_struct.fuel_asm = mek_data[7] struct.max_pos = mek_data[5]
self.sDB.mek_struct.fuel_sa = mek_data[8] struct.heat_cap = mek_data[6]
self.sDB.mek_struct.fuel_cap = mek_data[9] struct.fuel_asm = mek_data[7]
self.sDB.mek_struct.waste_cap = mek_data[10] struct.fuel_sa = mek_data[8]
self.sDB.mek_struct.ccool_cap = mek_data[11] struct.fuel_cap = mek_data[9]
self.sDB.mek_struct.hcool_cap = mek_data[12] struct.waste_cap = mek_data[10]
self.sDB.mek_struct.max_burn = mek_data[13] struct.ccool_cap = mek_data[11]
struct.hcool_cap = mek_data[12]
struct.max_burn = mek_data[13]
end
-- handle a reactor status packet
---@param pkt rplc_frame
local function _handle_status(pkt)
local valid = (type(pkt.data[1]) == "number") and (type(pkt.data[2]) == "boolean") and
(type(pkt.data[3]) == "boolean") and (type(pkt.data[4]) == "boolean") and
(type(pkt.data[5]) == "number")
if valid then
self.sDB.last_status_update = pkt.data[1]
self.sDB.control_state = pkt.data[2]
self.sDB.no_reactor = pkt.data[3]
self.sDB.formed = pkt.data[4]
self.sDB.auto_ack_token = pkt.data[5]
if (not self.sDB.no_reactor) and self.sDB.formed and (type(pkt.data[6]) == "number") then
self.sDB.mek_status.heating_rate = pkt.data[6] or 0.0
-- attempt to read mek_data table
if type(pkt.data[7]) == "table" then
if #pkt.data[7] == 17 then
_copy_status(pkt.data[7])
self.received_status_cache = true
else
log.error(log_header .. "RPLC status packet reactor data length mismatch")
end
end
end
else
log.debug(log_header .. "RPLC status packet invalid")
end
end end
-- mark this PLC session as closed, stop watchdog -- mark this PLC session as closed, stop watchdog
@ -332,48 +372,17 @@ function plc.new_session(id, s_addr, i_seq_num, reactor_id, in_queue, out_queue,
if pkt.type == RPLC_TYPE.STATUS then if pkt.type == RPLC_TYPE.STATUS then
-- status packet received, update data -- status packet received, update data
if pkt.length >= 5 then if pkt.length >= 5 then
if (type(pkt.data[1]) == "number") and (type(pkt.data[2]) == "boolean") and (type(pkt.data[3]) == "boolean") and _handle_status(pkt)
(type(pkt.data[4]) == "boolean") and (type(pkt.data[5]) == "number") then
self.sDB.last_status_update = pkt.data[1]
self.sDB.control_state = pkt.data[2]
self.sDB.no_reactor = pkt.data[3]
self.sDB.formed = pkt.data[4]
self.sDB.auto_ack_token = pkt.data[5]
if (not self.sDB.no_reactor) and self.sDB.formed and (type(pkt.data[6]) == "number") then
self.sDB.mek_status.heating_rate = pkt.data[6] or 0.0
-- attempt to read mek_data table
if type(pkt.data[7]) == "table" then
local status = pcall(_copy_status, pkt.data[7])
if status then
-- copied in status data OK
self.received_status_cache = true
else
-- error copying status data
log.error(log_header .. "failed to parse status packet data")
end
end
end
else
log.debug(log_header .. "RPLC status packet invalid")
end
else else
log.debug(log_header .. "RPLC status packet length mismatch") log.debug(log_header .. "RPLC status packet length mismatch")
end end
elseif pkt.type == RPLC_TYPE.MEK_STRUCT then elseif pkt.type == RPLC_TYPE.MEK_STRUCT then
-- received reactor structure, record it -- received reactor structure, record it
if pkt.length == 14 then if pkt.length == 13 then
local status = pcall(_copy_struct, pkt.data) _copy_struct(pkt.data)
if status then _compute_op_temps()
-- copied in structure data OK self.received_struct = true
_compute_op_temps() out_queue.push_data(svqtypes.SV_Q_DATA.PLC_BUILD_CHANGED, reactor_id)
self.received_struct = true
out_queue.push_data(svqtypes.SV_Q_DATA.PLC_BUILD_CHANGED, reactor_id)
else
-- error copying structure data
log.error(log_header .. "failed to parse struct packet data")
end
else else
log.debug(log_header .. "RPLC struct packet length mismatch") log.debug(log_header .. "RPLC struct packet length mismatch")
end end