diff --git a/pocket/iocontrol.lua b/pocket/iocontrol.lua index 0a3af09..cb27059 100644 --- a/pocket/iocontrol.lua +++ b/pocket/iocontrol.lua @@ -2,11 +2,11 @@ -- I/O Control for Pocket Integration with Supervisor & Coordinator -- -local const = require("scada-common.constants") local psil = require("scada-common.psil") local types = require("scada-common.types") local util = require("scada-common.util") +local iorx = require("pocket.iorx") local process = require("pocket.process") local ALARM = types.ALARM @@ -50,6 +50,8 @@ function iocontrol.init_core(pkt_comms, nav, cfg) comms = pkt_comms config = cfg + iocontrol.rx = iorx(io) + io.nav = nav ---@class pocket_ioctl_diag @@ -347,642 +349,6 @@ function iocontrol.report_crd_tt(trip_time) io.ps.publish("crd_conn_quality", state) end --- populate facility data from API_GET_FAC ----@param data table ----@return boolean valid -function iocontrol.record_facility_data(data) - local valid = true - - local fac = io.facility - - fac.all_sys_ok = data[1] - fac.rtu_count = data[2] - fac.radiation = data[3] - - -- auto control - if type(data[4]) == "table" and #data[4] == 4 then - fac.auto_ready = data[4][1] - fac.auto_active = data[4][2] - fac.auto_ramping = data[4][3] - fac.auto_saturated = data[4][4] - end - - -- waste - if type(data[5]) == "table" and #data[5] == 2 then - fac.auto_current_waste_product = data[5][1] - fac.auto_pu_fallback_active = data[5][2] - end - - fac.num_tanks = data[6] - fac.has_imatrix = data[7] - fac.has_sps = data[8] - - return valid -end - -local function tripped(state) return state == ALARM_STATE.TRIPPED or state == ALARM_STATE.ACKED end - -local function _record_multiblock_status(faulted, data, ps) - ps.publish("formed", data.formed) - ps.publish("faulted", faulted) - - for key, val in pairs(data.state) do ps.publish(key, val) end - for key, val in pairs(data.tanks) do ps.publish(key, val) end -end - --- update unit status data from API_GET_UNIT ----@param data table -function iocontrol.record_unit_data(data) - local unit = io.units[data[1]] - - unit.connected = data[2] - unit.rtu_hw = data[3] - unit.a_group = data[4] - unit.alarms = data[5] - - unit.unit_ps.publish("auto_group_id", unit.a_group) - unit.unit_ps.publish("auto_group", types.AUTO_GROUP_NAMES[unit.a_group + 1]) - - --#region Annunciator - - unit.annunciator = data[6] - - local rcs_disconn, rcs_warn, rcs_hazard = false, false, false - - for key, val in pairs(unit.annunciator) do - if key == "BoilerOnline" or key == "TurbineOnline" then - local every = true - - -- split up online arrays - for id = 1, #val do - every = every and val[id] - - if key == "BoilerOnline" then - unit.boiler_ps_tbl[id].publish(key, val[id]) - else - unit.turbine_ps_tbl[id].publish(key, val[id]) - end - end - - if not every then rcs_disconn = true end - - unit.unit_ps.publish("U_" .. key, every) - elseif key == "HeatingRateLow" or key == "WaterLevelLow" then - -- split up array for all boilers - local any = false - for id = 1, #val do - any = any or val[id] - unit.boiler_ps_tbl[id].publish(key, val[id]) - end - - if key == "HeatingRateLow" and any then - rcs_warn = true - elseif key == "WaterLevelLow" and any then - rcs_hazard = true - end - - unit.unit_ps.publish("U_" .. key, any) - elseif key == "SteamDumpOpen" or key == "TurbineOverSpeed" or key == "GeneratorTrip" or key == "TurbineTrip" then - -- split up array for all turbines - local any = false - for id = 1, #val do - any = any or val[id] - unit.turbine_ps_tbl[id].publish(key, val[id]) - end - - if key == "GeneratorTrip" and any then - rcs_warn = true - elseif (key == "TurbineOverSpeed" or key == "TurbineTrip") and any then - rcs_hazard = true - end - - unit.unit_ps.publish("U_" .. key, any) - else - -- non-table fields - unit.unit_ps.publish(key, val) - end - end - - local anc = unit.annunciator - rcs_hazard = rcs_hazard or anc.RCPTrip - rcs_warn = rcs_warn or anc.RCSFlowLow or anc.CoolantLevelLow or anc.RCSFault or anc.MaxWaterReturnFeed or - anc.CoolantFeedMismatch or anc.BoilRateMismatch or anc.SteamFeedMismatch - - local rcs_status = 4 - if rcs_hazard then - rcs_status = 2 - elseif rcs_warn then - rcs_status = 3 - elseif rcs_disconn then - rcs_status = 1 - end - - unit.unit_ps.publish("U_RCS", rcs_status) - - --#endregion - - --#region Reactor Data - - unit.reactor_data = data[7] - - local control_status = 1 - local reactor_status = 1 - local reactor_state = 1 - local rps_status = 1 - - if unit.connected then - -- update RPS status - if unit.reactor_data.rps_tripped then - control_status = 2 - - if unit.reactor_data.rps_trip_cause == "manual" then - reactor_state = 4 -- disabled - rps_status = 3 - else - reactor_state = 6 -- SCRAM - rps_status = 2 - end - else - rps_status = 4 - reactor_state = 4 - end - - -- update reactor/control status - if unit.reactor_data.mek_status.status then - reactor_status = 4 - reactor_state = 5 -- running - control_status = util.trinary(unit.annunciator.AutoControl, 4, 3) - else - if unit.reactor_data.no_reactor then - reactor_status = 2 - reactor_state = 3 -- faulted - elseif not unit.reactor_data.formed then - reactor_status = 3 - reactor_state = 2 -- not formed - elseif unit.reactor_data.rps_status.force_dis then - reactor_status = 3 - reactor_state = 7 -- force disabled - else - reactor_status = 4 - end - end - - for key, val in pairs(unit.reactor_data) do - if key ~= "rps_status" and key ~= "mek_struct" and key ~= "mek_status" then - unit.unit_ps.publish(key, val) - end - end - - for key, val in pairs(unit.reactor_data.rps_status) do - unit.unit_ps.publish(key, val) - end - - for key, val in pairs(unit.reactor_data.mek_struct) do - unit.unit_ps.publish(key, val) - end - - for key, val in pairs(unit.reactor_data.mek_status) do - unit.unit_ps.publish(key, val) - end - end - - unit.unit_ps.publish("U_ControlStatus", control_status) - unit.unit_ps.publish("U_ReactorStatus", reactor_status) - unit.unit_ps.publish("U_ReactorStateStatus", reactor_state) - unit.unit_ps.publish("U_RPS", rps_status) - - --#endregion - - --#region RTU Devices - - unit.boiler_data_tbl = data[8] - - for id = 1, #unit.boiler_data_tbl do - local boiler = unit.boiler_data_tbl[id] - local ps = unit.boiler_ps_tbl[id] - - local boiler_status = 1 - local computed_status = 1 - - if unit.rtu_hw.boilers[id].connected then - if unit.rtu_hw.boilers[id].faulted then - boiler_status = 3 - computed_status = 3 - elseif boiler.formed then - boiler_status = 4 - - if boiler.state.boil_rate > 0 then - computed_status = 5 - else - computed_status = 4 - end - else - boiler_status = 2 - computed_status = 2 - end - - _record_multiblock_status(unit.rtu_hw.boilers[id].faulted, boiler, ps) - end - - ps.publish("BoilerStatus", boiler_status) - ps.publish("BoilerStateStatus", computed_status) - end - - unit.turbine_data_tbl = data[9] - - for id = 1, #unit.turbine_data_tbl do - local turbine = unit.turbine_data_tbl[id] - local ps = unit.turbine_ps_tbl[id] - - local turbine_status = 1 - local computed_status = 1 - - if unit.rtu_hw.turbines[id].connected then - if unit.rtu_hw.turbines[id].faulted then - turbine_status = 3 - computed_status = 3 - elseif turbine.formed then - turbine_status = 4 - - if turbine.tanks.energy_fill >= 0.99 then - computed_status = 6 - elseif turbine.state.flow_rate < 100 then - computed_status = 4 - else - computed_status = 5 - end - else - turbine_status = 2 - computed_status = 2 - end - - _record_multiblock_status(unit.rtu_hw.turbines[id].faulted, turbine, ps) - end - - ps.publish("TurbineStatus", turbine_status) - ps.publish("TurbineStateStatus", computed_status) - end - - unit.tank_data_tbl = data[10] - - unit.last_rate_change_ms = data[11] - unit.turbine_flow_stable = data[12] - - --#endregion - - --#region Status Information Display - - local ecam = {} -- aviation reference :) - - -- local function red(text) return { text = text, color = colors.red } end - local function white(text) return { text = text, color = colors.white } end - local function blue(text) return { text = text, color = colors.blue } end - - -- if unit.reactor_data.rps_status then - -- for k, v in pairs(unit.alarms) do - -- unit.alarms[k] = ALARM_STATE.TRIPPED - -- end - -- end - - if tripped(unit.alarms[ALARM.ContainmentBreach]) then - local items = { white("REACTOR MELTDOWN"), blue("DON HAZMAT SUIT") } - table.insert(ecam, { color = colors.red, text = "CONTAINMENT BREACH", help = "ContainmentBreach", items = items }) - end - - if tripped(unit.alarms[ALARM.ContainmentRadiation]) then - local items = { - white("RADIATION DETECTED"), - blue("DON HAZMAT SUIT"), - blue("RESOLVE LEAK"), - blue("AWAIT SAFE LEVELS") - } - - table.insert(ecam, { color = colors.red, text = "RADIATION LEAK", help = "ContainmentRadiation", items = items }) - end - - if tripped(unit.alarms[ALARM.CriticalDamage]) then - local items = { white("MELTDOWN IMMINENT"), blue("EVACUATE") } - table.insert(ecam, { color = colors.red, text = "RCT DAMAGE CRITICAL", help = "CriticalDamage", items = items }) - end - - if tripped(unit.alarms[ALARM.ReactorLost]) then - local items = { white("REACTOR OFF-LINE"), blue("CHECK PLC") } - table.insert(ecam, { color = colors.red, text = "REACTOR CONN LOST", help = "ReactorLost", items = items }) - end - - if tripped(unit.alarms[ALARM.ReactorDamage]) then - local items = { white("REACTOR DAMAGED"), blue("CHECK RCS"), blue("AWAIT DMG REDUCED") } - table.insert(ecam, { color = colors.red, text = "REACTOR DAMAGE", help = "ReactorDamage", items = items }) - end - - if tripped(unit.alarms[ALARM.ReactorOverTemp]) then - local items = { white("DAMAGING TEMP"), blue("CHECK RCS"), blue("AWAIT COOLDOWN") } - table.insert(ecam, { color = colors.red, text = "REACTOR OVER TEMP", help = "ReactorOverTemp", items = items }) - end - - if tripped(unit.alarms[ALARM.ReactorHighTemp]) then - local items = { white("OVER EXPECTED TEMP"), blue("CHECK RCS") } - table.insert(ecam, { color = colors.yellow, text = "REACTOR HIGH TEMP", help = "ReactorHighTemp", items = items}) - end - - if tripped(unit.alarms[ALARM.ReactorWasteLeak]) then - local items = { white("AT WASTE CAPACITY"), blue("CHECK WASTE OUTPUT"), blue("KEEP RCT DISABLED") } - table.insert(ecam, { color = colors.red, text = "REACTOR WASTE LEAK", help = "ReactorWasteLeak", items = items}) - end - - if tripped(unit.alarms[ALARM.ReactorHighWaste]) then - local items = { blue("CHECK WASTE OUTPUT") } - table.insert(ecam, { color = colors.yellow, text = "REACTOR WASTE HIGH", help = "ReactorHighWaste", items = items}) - end - - if tripped(unit.alarms[ALARM.RPSTransient]) then - local items = {} - local stat = unit.reactor_data.rps_status - - -- for k, _ in pairs(stat) do stat[k] = true end - - local function insert(cond, key, text, color) if cond[key] then table.insert(items, { text = text, help = key, color = color }) end end - - table.insert(items, white("REACTOR SCRAMMED")) - insert(stat, "high_dmg", "HIGH DAMAGE", colors.red) - insert(stat, "high_temp", "HIGH TEMPERATURE", colors.red) - insert(stat, "low_cool", "CRIT LOW COOLANT") - insert(stat, "ex_waste", "EXCESS WASTE") - insert(stat, "ex_hcool", "EXCESS HEATED COOL") - insert(stat, "no_fuel", "NO FUEL") - insert(stat, "fault", "HARDWARE FAULT") - insert(stat, "timeout", "SUPERVISOR DISCONN") - insert(stat, "manual", "MANUAL SCRAM", colors.white) - insert(stat, "automatic", "AUTOMATIC SCRAM") - insert(stat, "sys_fail", "NOT FORMED", colors.red) - insert(stat, "force_dis", "FORCE DISABLED", colors.red) - table.insert(items, blue("RESOLVE PROBLEM")) - table.insert(items, blue("RESET RPS")) - - table.insert(ecam, { color = colors.yellow, text = "RPS TRANSIENT", help = "RPSTransient", items = items}) - end - - if tripped(unit.alarms[ALARM.RCSTransient]) then - local items = {} - local annunc = unit.annunciator - - -- for k, v in pairs(annunc) do - -- if type(v) == "boolean" then annunc[k] = true end - -- if type(v) == "table" then - -- for a, _ in pairs(v) do - -- v[a] = true - -- end - -- end - -- end - - local function insert(cond, key, text, color) - if cond == true or (type(cond) == "table" and cond[key]) then table.insert(items, { text = text, help = key, color = color }) end - end - - table.insert(items, white("COOLANT PROBLEM")) - - insert(annunc, "RCPTrip", "RCP TRIP", colors.red) - insert(annunc, "CoolantLevelLow", "LOW COOLANT") - - if unit.num_boilers == 0 then - if (util.time_ms() - unit.last_rate_change_ms) > const.FLOW_STABILITY_DELAY_MS then - insert(annunc, "BoilRateMismatch", "BOIL RATE MISMATCH") - end - - if unit.turbine_flow_stable then - insert(annunc, "RCSFlowLow", "RCS FLOW LOW") - insert(annunc, "CoolantFeedMismatch", "COOL FEED MISMATCH") - insert(annunc, "SteamFeedMismatch", "STM FEED MISMATCH") - end - else - if (util.time_ms() - unit.last_rate_change_ms) > const.FLOW_STABILITY_DELAY_MS then - insert(annunc, "RCSFlowLow", "RCS FLOW LOW") - insert(annunc, "BoilRateMismatch", "BOIL RATE MISMATCH") - insert(annunc, "CoolantFeedMismatch", "COOL FEED MISMATCH") - end - - if unit.turbine_flow_stable then - insert(annunc, "SteamFeedMismatch", "STM FEED MISMATCH") - end - end - - insert(annunc, "MaxWaterReturnFeed", "MAX WTR RTRN FEED") - - for k, v in ipairs(annunc.WaterLevelLow) do insert(v, "WaterLevelLow", "BOILER " .. k .. " WTR LOW", colors.red) end - for k, v in ipairs(annunc.HeatingRateLow) do insert(v, "HeatingRateLow", "BOILER " .. k .. " HEAT RATE") end - for k, v in ipairs(annunc.TurbineOverSpeed) do insert(v, "TurbineOverSpeed", "TURBINE " .. k .. " OVERSPD", colors.red) end - for k, v in ipairs(annunc.GeneratorTrip) do insert(v, "GeneratorTrip", "TURBINE " .. k .. " GEN TRIP") end - - table.insert(items, blue("CHECK COOLING SYS")) - - table.insert(ecam, { color = colors.yellow, text = "RCS TRANSIENT", help = "RCSTransient", items = items}) - end - - if tripped(unit.alarms[ALARM.TurbineTrip]) then - local items = {} - - for k, v in ipairs(unit.annunciator.TurbineTrip) do - if v then table.insert(items, { text = "TURBINE " .. k .. " TRIP", help = "TurbineTrip" }) end - end - - table.insert(items, blue("CHECK ENERGY OUT")) - table.insert(ecam, { color = colors.red, text = "TURBINE TRIP", help = "TurbineTripAlarm", items = items}) - end - - if not (tripped(unit.alarms[ALARM.ReactorLost]) or unit.connected) then - local items = { blue("CHECK PLC") } - table.insert(ecam, { color = colors.yellow, text = "REACTOR OFF-LINE", items = items }) - end - - for k, v in ipairs(unit.annunciator.BoilerOnline) do - if not v then - local items = { blue("CHECK RTU") } - table.insert(ecam, { color = colors.yellow, text = "BOILER " .. k .. " OFF-LINE", items = items}) - end - end - - for k, v in ipairs(unit.annunciator.TurbineOnline) do - if not v then - local items = { blue("CHECK RTU") } - table.insert(ecam, { color = colors.yellow, text = "TURBINE " .. k .. " OFF-LINE", items = items}) - end - end - - -- if no alarms, put some basic status messages in - if #ecam == 0 then - table.insert(ecam, { color = colors.green, text = "REACTOR " .. util.trinary(unit.reactor_data.mek_status.status, "NOMINAL", "IDLE"), items = {}}) - - local plural = util.trinary(unit.num_turbines > 1, "S", "") - table.insert(ecam, { color = colors.green, text = "TURBINE" .. plural .. util.trinary(unit.turbine_flow_stable, " STABLE", " STABILIZING"), items = {}}) - end - - unit.unit_ps.publish("U_ECAM", textutils.serialize(ecam)) - - --#endregion -end - --- update control app with unit data from API_GET_CTRL ----@param data table -function iocontrol.record_control_data(data) - for u_id = 1, #data do - local unit = io.units[u_id] - local u_data = data[u_id] - - unit.connected = u_data[1] - - unit.reactor_data.rps_tripped = u_data[2] - unit.unit_ps.publish("rps_tripped", u_data[2]) - unit.reactor_data.mek_status.status = u_data[3] - unit.unit_ps.publish("status", u_data[3]) - unit.reactor_data.mek_status.temp = u_data[4] - unit.unit_ps.publish("temp", u_data[4]) - unit.reactor_data.mek_status.burn_rate = u_data[5] - unit.unit_ps.publish("burn_rate", u_data[5]) - unit.reactor_data.mek_status.act_burn_rate = u_data[6] - unit.unit_ps.publish("act_burn_rate", u_data[6]) - unit.reactor_data.mek_struct.max_burn = u_data[7] - unit.unit_ps.publish("max_burn", u_data[7]) - - unit.annunciator.AutoControl = u_data[8] - unit.unit_ps.publish("AutoControl", u_data[8]) - - unit.a_group = u_data[9] - unit.unit_ps.publish("auto_group_id", unit.a_group) - unit.unit_ps.publish("auto_group", types.AUTO_GROUP_NAMES[unit.a_group + 1]) - - local control_status = 1 - - if unit.connected then - if unit.reactor_data.rps_tripped then - control_status = 2 - end - - if unit.reactor_data.mek_status.status then - control_status = util.trinary(unit.annunciator.AutoControl, 4, 3) - end - end - - unit.unit_ps.publish("U_ControlStatus", control_status) - end -end - --- update process app with unit data from API_GET_PROC ----@param data table -function iocontrol.record_process_data(data) - -- get unit data - for u_id = 1, #io.units do - local unit = io.units[u_id] - local u_data = data[u_id] - - unit.reactor_data.mek_status.status = u_data[1] - unit.reactor_data.mek_struct.max_burn = u_data[2] - unit.annunciator.AutoControl = u_data[6] - unit.a_group = u_data[7] - - unit.unit_ps.publish("status", u_data[1]) - unit.unit_ps.publish("max_burn", u_data[2]) - unit.unit_ps.publish("burn_limit", u_data[3]) - unit.unit_ps.publish("U_AutoReady", u_data[4]) - unit.unit_ps.publish("U_AutoDegraded", u_data[5]) - unit.unit_ps.publish("AutoControl", u_data[6]) - unit.unit_ps.publish("auto_group_id", unit.a_group) - unit.unit_ps.publish("auto_group", types.AUTO_GROUP_NAMES[unit.a_group + 1]) - end - - -- get facility data - local fac = io.facility - local f_data = data[#io.units + 1] - - fac.status_lines = f_data[1] - - fac.auto_ready = f_data[2][1] - fac.auto_active = f_data[2][2] - fac.auto_ramping = f_data[2][3] - fac.auto_saturated = f_data[2][4] - - fac.auto_scram = f_data[3] - fac.ascram_status = f_data[4] - - fac.ps.publish("status_line_1", fac.status_lines[1]) - fac.ps.publish("status_line_2", fac.status_lines[2]) - - fac.ps.publish("auto_ready", fac.auto_ready) - fac.ps.publish("auto_active", fac.auto_active) - fac.ps.publish("auto_ramping", fac.auto_ramping) - fac.ps.publish("auto_saturated", fac.auto_saturated) - - fac.ps.publish("auto_scram", fac.auto_scram) - fac.ps.publish("as_matrix_fault", fac.ascram_status.matrix_fault) - fac.ps.publish("as_matrix_fill", fac.ascram_status.matrix_fill) - fac.ps.publish("as_crit_alarm", fac.ascram_status.crit_alarm) - fac.ps.publish("as_radiation", fac.ascram_status.radiation) - fac.ps.publish("as_gen_fault", fac.ascram_status.gen_fault) - - fac.ps.publish("process_mode", f_data[5][1]) - fac.ps.publish("process_burn_target", f_data[5][2]) - fac.ps.publish("process_charge_target", f_data[5][3]) - fac.ps.publish("process_gen_target", f_data[5][4]) -end - --- update waste app with unit data from API_GET_WASTE ----@param data table -function iocontrol.record_waste_data(data) - -- get unit data - for u_id = 1, #io.units do - local unit = io.units[u_id] - local u_data = data[u_id] - - unit.waste_mode = u_data[1] - unit.waste_product = u_data[2] - unit.num_snas = u_data[3] - unit.sna_peak_rate = u_data[4] - unit.sna_max_rate = u_data[5] - unit.sna_out_rate = u_data[6] - unit.waste_stats = u_data[7] - - unit.unit_ps.publish("U_AutoWaste", unit.waste_mode == types.WASTE_MODE.AUTO) - unit.unit_ps.publish("U_WasteMode", unit.waste_mode) - unit.unit_ps.publish("U_WasteProduct", unit.waste_product) - - unit.unit_ps.publish("sna_count", unit.num_snas) - unit.unit_ps.publish("sna_peak_rate", unit.sna_peak_rate) - unit.unit_ps.publish("sna_max_rate", unit.sna_max_rate) - unit.unit_ps.publish("sna_out_rate", unit.sna_out_rate) - - unit.unit_ps.publish("pu_rate", unit.waste_stats[1]) - unit.unit_ps.publish("po_rate", unit.waste_stats[2]) - unit.unit_ps.publish("po_pl_rate", unit.waste_stats[3]) - end - - -- get facility data - local fac = io.facility - local f_data = data[#io.units + 1] - - fac.auto_current_waste_product = f_data[1] - fac.auto_pu_fallback_active = f_data[2] - fac.auto_sps_disabled = f_data[3] - - fac.ps.publish("current_waste_product", fac.auto_current_waste_product) - fac.ps.publish("pu_fallback_active", fac.auto_pu_fallback_active) - fac.ps.publish("sps_disabled_low_power", fac.auto_sps_disabled) - - fac.ps.publish("process_waste_product", f_data[4]) - fac.ps.publish("process_pu_fallback", f_data[5]) - fac.ps.publish("process_sps_low_power", f_data[6]) - - fac.waste_stats = f_data[7] - - fac.ps.publish("burn_sum", fac.waste_stats[1]) - fac.ps.publish("pu_rate", fac.waste_stats[2]) - fac.ps.publish("po_rate", fac.waste_stats[3]) - fac.ps.publish("po_pl_rate", fac.waste_stats[4]) - fac.ps.publish("po_am_rate", fac.waste_stats[5]) - fac.ps.publish("spent_waste_rate", fac.waste_stats[6]) - - fac.ps.publish("sps_computed_status", f_data[8]) - fac.ps.publish("sps_process_rate", f_data[9]) -end - -- get the IO controller database function iocontrol.get_db() return io end diff --git a/pocket/iorx.lua b/pocket/iorx.lua new file mode 100644 index 0000000..522c14f --- /dev/null +++ b/pocket/iorx.lua @@ -0,0 +1,654 @@ +-- +-- I/O Control's Data Receive (Rx) Handlers +-- + +local const = require("scada-common.constants") +local types = require("scada-common.types") +local util = require("scada-common.util") + +local ALARM = types.ALARM +local ALARM_STATE = types.ALARM_STATE + +local io ---@type pocket_ioctl +local iorx = {} ---@class iorx + +-- populate facility data from API_GET_FAC +---@param data table +---@return boolean valid +function iorx.record_facility_data(data) + local valid = true + + local fac = io.facility + + fac.all_sys_ok = data[1] + fac.rtu_count = data[2] + fac.radiation = data[3] + + -- auto control + if type(data[4]) == "table" and #data[4] == 4 then + fac.auto_ready = data[4][1] + fac.auto_active = data[4][2] + fac.auto_ramping = data[4][3] + fac.auto_saturated = data[4][4] + end + + -- waste + if type(data[5]) == "table" and #data[5] == 2 then + fac.auto_current_waste_product = data[5][1] + fac.auto_pu_fallback_active = data[5][2] + end + + fac.num_tanks = data[6] + fac.has_imatrix = data[7] + fac.has_sps = data[8] + + return valid +end + +local function tripped(state) return state == ALARM_STATE.TRIPPED or state == ALARM_STATE.ACKED end + +local function _record_multiblock_status(faulted, data, ps) + ps.publish("formed", data.formed) + ps.publish("faulted", faulted) + + for key, val in pairs(data.state) do ps.publish(key, val) end + for key, val in pairs(data.tanks) do ps.publish(key, val) end +end + +-- update unit status data from API_GET_UNIT +---@param data table +function iorx.record_unit_data(data) + local unit = io.units[data[1]] + + unit.connected = data[2] + unit.rtu_hw = data[3] + unit.a_group = data[4] + unit.alarms = data[5] + + unit.unit_ps.publish("auto_group_id", unit.a_group) + unit.unit_ps.publish("auto_group", types.AUTO_GROUP_NAMES[unit.a_group + 1]) + + --#region Annunciator + + unit.annunciator = data[6] + + local rcs_disconn, rcs_warn, rcs_hazard = false, false, false + + for key, val in pairs(unit.annunciator) do + if key == "BoilerOnline" or key == "TurbineOnline" then + local every = true + + -- split up online arrays + for id = 1, #val do + every = every and val[id] + + if key == "BoilerOnline" then + unit.boiler_ps_tbl[id].publish(key, val[id]) + else + unit.turbine_ps_tbl[id].publish(key, val[id]) + end + end + + if not every then rcs_disconn = true end + + unit.unit_ps.publish("U_" .. key, every) + elseif key == "HeatingRateLow" or key == "WaterLevelLow" then + -- split up array for all boilers + local any = false + for id = 1, #val do + any = any or val[id] + unit.boiler_ps_tbl[id].publish(key, val[id]) + end + + if key == "HeatingRateLow" and any then + rcs_warn = true + elseif key == "WaterLevelLow" and any then + rcs_hazard = true + end + + unit.unit_ps.publish("U_" .. key, any) + elseif key == "SteamDumpOpen" or key == "TurbineOverSpeed" or key == "GeneratorTrip" or key == "TurbineTrip" then + -- split up array for all turbines + local any = false + for id = 1, #val do + any = any or val[id] + unit.turbine_ps_tbl[id].publish(key, val[id]) + end + + if key == "GeneratorTrip" and any then + rcs_warn = true + elseif (key == "TurbineOverSpeed" or key == "TurbineTrip") and any then + rcs_hazard = true + end + + unit.unit_ps.publish("U_" .. key, any) + else + -- non-table fields + unit.unit_ps.publish(key, val) + end + end + + local anc = unit.annunciator + rcs_hazard = rcs_hazard or anc.RCPTrip + rcs_warn = rcs_warn or anc.RCSFlowLow or anc.CoolantLevelLow or anc.RCSFault or anc.MaxWaterReturnFeed or + anc.CoolantFeedMismatch or anc.BoilRateMismatch or anc.SteamFeedMismatch + + local rcs_status = 4 + if rcs_hazard then + rcs_status = 2 + elseif rcs_warn then + rcs_status = 3 + elseif rcs_disconn then + rcs_status = 1 + end + + unit.unit_ps.publish("U_RCS", rcs_status) + + --#endregion + + --#region Reactor Data + + unit.reactor_data = data[7] + + local control_status = 1 + local reactor_status = 1 + local reactor_state = 1 + local rps_status = 1 + + if unit.connected then + -- update RPS status + if unit.reactor_data.rps_tripped then + control_status = 2 + + if unit.reactor_data.rps_trip_cause == "manual" then + reactor_state = 4 -- disabled + rps_status = 3 + else + reactor_state = 6 -- SCRAM + rps_status = 2 + end + else + rps_status = 4 + reactor_state = 4 + end + + -- update reactor/control status + if unit.reactor_data.mek_status.status then + reactor_status = 4 + reactor_state = 5 -- running + control_status = util.trinary(unit.annunciator.AutoControl, 4, 3) + else + if unit.reactor_data.no_reactor then + reactor_status = 2 + reactor_state = 3 -- faulted + elseif not unit.reactor_data.formed then + reactor_status = 3 + reactor_state = 2 -- not formed + elseif unit.reactor_data.rps_status.force_dis then + reactor_status = 3 + reactor_state = 7 -- force disabled + else + reactor_status = 4 + end + end + + for key, val in pairs(unit.reactor_data) do + if key ~= "rps_status" and key ~= "mek_struct" and key ~= "mek_status" then + unit.unit_ps.publish(key, val) + end + end + + for key, val in pairs(unit.reactor_data.rps_status) do + unit.unit_ps.publish(key, val) + end + + for key, val in pairs(unit.reactor_data.mek_struct) do + unit.unit_ps.publish(key, val) + end + + for key, val in pairs(unit.reactor_data.mek_status) do + unit.unit_ps.publish(key, val) + end + end + + unit.unit_ps.publish("U_ControlStatus", control_status) + unit.unit_ps.publish("U_ReactorStatus", reactor_status) + unit.unit_ps.publish("U_ReactorStateStatus", reactor_state) + unit.unit_ps.publish("U_RPS", rps_status) + + --#endregion + + --#region RTU Devices + + unit.boiler_data_tbl = data[8] + + for id = 1, #unit.boiler_data_tbl do + local boiler = unit.boiler_data_tbl[id] + local ps = unit.boiler_ps_tbl[id] + + local boiler_status = 1 + local computed_status = 1 + + if unit.rtu_hw.boilers[id].connected then + if unit.rtu_hw.boilers[id].faulted then + boiler_status = 3 + computed_status = 3 + elseif boiler.formed then + boiler_status = 4 + + if boiler.state.boil_rate > 0 then + computed_status = 5 + else + computed_status = 4 + end + else + boiler_status = 2 + computed_status = 2 + end + + _record_multiblock_status(unit.rtu_hw.boilers[id].faulted, boiler, ps) + end + + ps.publish("BoilerStatus", boiler_status) + ps.publish("BoilerStateStatus", computed_status) + end + + unit.turbine_data_tbl = data[9] + + for id = 1, #unit.turbine_data_tbl do + local turbine = unit.turbine_data_tbl[id] + local ps = unit.turbine_ps_tbl[id] + + local turbine_status = 1 + local computed_status = 1 + + if unit.rtu_hw.turbines[id].connected then + if unit.rtu_hw.turbines[id].faulted then + turbine_status = 3 + computed_status = 3 + elseif turbine.formed then + turbine_status = 4 + + if turbine.tanks.energy_fill >= 0.99 then + computed_status = 6 + elseif turbine.state.flow_rate < 100 then + computed_status = 4 + else + computed_status = 5 + end + else + turbine_status = 2 + computed_status = 2 + end + + _record_multiblock_status(unit.rtu_hw.turbines[id].faulted, turbine, ps) + end + + ps.publish("TurbineStatus", turbine_status) + ps.publish("TurbineStateStatus", computed_status) + end + + unit.tank_data_tbl = data[10] + + unit.last_rate_change_ms = data[11] + unit.turbine_flow_stable = data[12] + + --#endregion + + --#region Status Information Display + + local ecam = {} -- aviation reference :) + + -- local function red(text) return { text = text, color = colors.red } end + local function white(text) return { text = text, color = colors.white } end + local function blue(text) return { text = text, color = colors.blue } end + + -- if unit.reactor_data.rps_status then + -- for k, v in pairs(unit.alarms) do + -- unit.alarms[k] = ALARM_STATE.TRIPPED + -- end + -- end + + if tripped(unit.alarms[ALARM.ContainmentBreach]) then + local items = { white("REACTOR MELTDOWN"), blue("DON HAZMAT SUIT") } + table.insert(ecam, { color = colors.red, text = "CONTAINMENT BREACH", help = "ContainmentBreach", items = items }) + end + + if tripped(unit.alarms[ALARM.ContainmentRadiation]) then + local items = { + white("RADIATION DETECTED"), + blue("DON HAZMAT SUIT"), + blue("RESOLVE LEAK"), + blue("AWAIT SAFE LEVELS") + } + + table.insert(ecam, { color = colors.red, text = "RADIATION LEAK", help = "ContainmentRadiation", items = items }) + end + + if tripped(unit.alarms[ALARM.CriticalDamage]) then + local items = { white("MELTDOWN IMMINENT"), blue("EVACUATE") } + table.insert(ecam, { color = colors.red, text = "RCT DAMAGE CRITICAL", help = "CriticalDamage", items = items }) + end + + if tripped(unit.alarms[ALARM.ReactorLost]) then + local items = { white("REACTOR OFF-LINE"), blue("CHECK PLC") } + table.insert(ecam, { color = colors.red, text = "REACTOR CONN LOST", help = "ReactorLost", items = items }) + end + + if tripped(unit.alarms[ALARM.ReactorDamage]) then + local items = { white("REACTOR DAMAGED"), blue("CHECK RCS"), blue("AWAIT DMG REDUCED") } + table.insert(ecam, { color = colors.red, text = "REACTOR DAMAGE", help = "ReactorDamage", items = items }) + end + + if tripped(unit.alarms[ALARM.ReactorOverTemp]) then + local items = { white("DAMAGING TEMP"), blue("CHECK RCS"), blue("AWAIT COOLDOWN") } + table.insert(ecam, { color = colors.red, text = "REACTOR OVER TEMP", help = "ReactorOverTemp", items = items }) + end + + if tripped(unit.alarms[ALARM.ReactorHighTemp]) then + local items = { white("OVER EXPECTED TEMP"), blue("CHECK RCS") } + table.insert(ecam, { color = colors.yellow, text = "REACTOR HIGH TEMP", help = "ReactorHighTemp", items = items}) + end + + if tripped(unit.alarms[ALARM.ReactorWasteLeak]) then + local items = { white("AT WASTE CAPACITY"), blue("CHECK WASTE OUTPUT"), blue("KEEP RCT DISABLED") } + table.insert(ecam, { color = colors.red, text = "REACTOR WASTE LEAK", help = "ReactorWasteLeak", items = items}) + end + + if tripped(unit.alarms[ALARM.ReactorHighWaste]) then + local items = { blue("CHECK WASTE OUTPUT") } + table.insert(ecam, { color = colors.yellow, text = "REACTOR WASTE HIGH", help = "ReactorHighWaste", items = items}) + end + + if tripped(unit.alarms[ALARM.RPSTransient]) then + local items = {} + local stat = unit.reactor_data.rps_status + + -- for k, _ in pairs(stat) do stat[k] = true end + + local function insert(cond, key, text, color) if cond[key] then table.insert(items, { text = text, help = key, color = color }) end end + + table.insert(items, white("REACTOR SCRAMMED")) + insert(stat, "high_dmg", "HIGH DAMAGE", colors.red) + insert(stat, "high_temp", "HIGH TEMPERATURE", colors.red) + insert(stat, "low_cool", "CRIT LOW COOLANT") + insert(stat, "ex_waste", "EXCESS WASTE") + insert(stat, "ex_hcool", "EXCESS HEATED COOL") + insert(stat, "no_fuel", "NO FUEL") + insert(stat, "fault", "HARDWARE FAULT") + insert(stat, "timeout", "SUPERVISOR DISCONN") + insert(stat, "manual", "MANUAL SCRAM", colors.white) + insert(stat, "automatic", "AUTOMATIC SCRAM") + insert(stat, "sys_fail", "NOT FORMED", colors.red) + insert(stat, "force_dis", "FORCE DISABLED", colors.red) + table.insert(items, blue("RESOLVE PROBLEM")) + table.insert(items, blue("RESET RPS")) + + table.insert(ecam, { color = colors.yellow, text = "RPS TRANSIENT", help = "RPSTransient", items = items}) + end + + if tripped(unit.alarms[ALARM.RCSTransient]) then + local items = {} + local annunc = unit.annunciator + + -- for k, v in pairs(annunc) do + -- if type(v) == "boolean" then annunc[k] = true end + -- if type(v) == "table" then + -- for a, _ in pairs(v) do + -- v[a] = true + -- end + -- end + -- end + + local function insert(cond, key, text, color) + if cond == true or (type(cond) == "table" and cond[key]) then table.insert(items, { text = text, help = key, color = color }) end + end + + table.insert(items, white("COOLANT PROBLEM")) + + insert(annunc, "RCPTrip", "RCP TRIP", colors.red) + insert(annunc, "CoolantLevelLow", "LOW COOLANT") + + if unit.num_boilers == 0 then + if (util.time_ms() - unit.last_rate_change_ms) > const.FLOW_STABILITY_DELAY_MS then + insert(annunc, "BoilRateMismatch", "BOIL RATE MISMATCH") + end + + if unit.turbine_flow_stable then + insert(annunc, "RCSFlowLow", "RCS FLOW LOW") + insert(annunc, "CoolantFeedMismatch", "COOL FEED MISMATCH") + insert(annunc, "SteamFeedMismatch", "STM FEED MISMATCH") + end + else + if (util.time_ms() - unit.last_rate_change_ms) > const.FLOW_STABILITY_DELAY_MS then + insert(annunc, "RCSFlowLow", "RCS FLOW LOW") + insert(annunc, "BoilRateMismatch", "BOIL RATE MISMATCH") + insert(annunc, "CoolantFeedMismatch", "COOL FEED MISMATCH") + end + + if unit.turbine_flow_stable then + insert(annunc, "SteamFeedMismatch", "STM FEED MISMATCH") + end + end + + insert(annunc, "MaxWaterReturnFeed", "MAX WTR RTRN FEED") + + for k, v in ipairs(annunc.WaterLevelLow) do insert(v, "WaterLevelLow", "BOILER " .. k .. " WTR LOW", colors.red) end + for k, v in ipairs(annunc.HeatingRateLow) do insert(v, "HeatingRateLow", "BOILER " .. k .. " HEAT RATE") end + for k, v in ipairs(annunc.TurbineOverSpeed) do insert(v, "TurbineOverSpeed", "TURBINE " .. k .. " OVERSPD", colors.red) end + for k, v in ipairs(annunc.GeneratorTrip) do insert(v, "GeneratorTrip", "TURBINE " .. k .. " GEN TRIP") end + + table.insert(items, blue("CHECK COOLING SYS")) + + table.insert(ecam, { color = colors.yellow, text = "RCS TRANSIENT", help = "RCSTransient", items = items}) + end + + if tripped(unit.alarms[ALARM.TurbineTrip]) then + local items = {} + + for k, v in ipairs(unit.annunciator.TurbineTrip) do + if v then table.insert(items, { text = "TURBINE " .. k .. " TRIP", help = "TurbineTrip" }) end + end + + table.insert(items, blue("CHECK ENERGY OUT")) + table.insert(ecam, { color = colors.red, text = "TURBINE TRIP", help = "TurbineTripAlarm", items = items}) + end + + if not (tripped(unit.alarms[ALARM.ReactorLost]) or unit.connected) then + local items = { blue("CHECK PLC") } + table.insert(ecam, { color = colors.yellow, text = "REACTOR OFF-LINE", items = items }) + end + + for k, v in ipairs(unit.annunciator.BoilerOnline) do + if not v then + local items = { blue("CHECK RTU") } + table.insert(ecam, { color = colors.yellow, text = "BOILER " .. k .. " OFF-LINE", items = items}) + end + end + + for k, v in ipairs(unit.annunciator.TurbineOnline) do + if not v then + local items = { blue("CHECK RTU") } + table.insert(ecam, { color = colors.yellow, text = "TURBINE " .. k .. " OFF-LINE", items = items}) + end + end + + -- if no alarms, put some basic status messages in + if #ecam == 0 then + table.insert(ecam, { color = colors.green, text = "REACTOR " .. util.trinary(unit.reactor_data.mek_status.status, "NOMINAL", "IDLE"), items = {}}) + + local plural = util.trinary(unit.num_turbines > 1, "S", "") + table.insert(ecam, { color = colors.green, text = "TURBINE" .. plural .. util.trinary(unit.turbine_flow_stable, " STABLE", " STABILIZING"), items = {}}) + end + + unit.unit_ps.publish("U_ECAM", textutils.serialize(ecam)) + + --#endregion +end + +-- update control app with unit data from API_GET_CTRL +---@param data table +function iorx.record_control_data(data) + for u_id = 1, #data do + local unit = io.units[u_id] + local u_data = data[u_id] + + unit.connected = u_data[1] + + unit.reactor_data.rps_tripped = u_data[2] + unit.unit_ps.publish("rps_tripped", u_data[2]) + unit.reactor_data.mek_status.status = u_data[3] + unit.unit_ps.publish("status", u_data[3]) + unit.reactor_data.mek_status.temp = u_data[4] + unit.unit_ps.publish("temp", u_data[4]) + unit.reactor_data.mek_status.burn_rate = u_data[5] + unit.unit_ps.publish("burn_rate", u_data[5]) + unit.reactor_data.mek_status.act_burn_rate = u_data[6] + unit.unit_ps.publish("act_burn_rate", u_data[6]) + unit.reactor_data.mek_struct.max_burn = u_data[7] + unit.unit_ps.publish("max_burn", u_data[7]) + + unit.annunciator.AutoControl = u_data[8] + unit.unit_ps.publish("AutoControl", u_data[8]) + + unit.a_group = u_data[9] + unit.unit_ps.publish("auto_group_id", unit.a_group) + unit.unit_ps.publish("auto_group", types.AUTO_GROUP_NAMES[unit.a_group + 1]) + + local control_status = 1 + + if unit.connected then + if unit.reactor_data.rps_tripped then + control_status = 2 + end + + if unit.reactor_data.mek_status.status then + control_status = util.trinary(unit.annunciator.AutoControl, 4, 3) + end + end + + unit.unit_ps.publish("U_ControlStatus", control_status) + end +end + +-- update process app with unit data from API_GET_PROC +---@param data table +function iorx.record_process_data(data) + -- get unit data + for u_id = 1, #io.units do + local unit = io.units[u_id] + local u_data = data[u_id] + + unit.reactor_data.mek_status.status = u_data[1] + unit.reactor_data.mek_struct.max_burn = u_data[2] + unit.annunciator.AutoControl = u_data[6] + unit.a_group = u_data[7] + + unit.unit_ps.publish("status", u_data[1]) + unit.unit_ps.publish("max_burn", u_data[2]) + unit.unit_ps.publish("burn_limit", u_data[3]) + unit.unit_ps.publish("U_AutoReady", u_data[4]) + unit.unit_ps.publish("U_AutoDegraded", u_data[5]) + unit.unit_ps.publish("AutoControl", u_data[6]) + unit.unit_ps.publish("auto_group_id", unit.a_group) + unit.unit_ps.publish("auto_group", types.AUTO_GROUP_NAMES[unit.a_group + 1]) + end + + -- get facility data + local fac = io.facility + local f_data = data[#io.units + 1] + + fac.status_lines = f_data[1] + + fac.auto_ready = f_data[2][1] + fac.auto_active = f_data[2][2] + fac.auto_ramping = f_data[2][3] + fac.auto_saturated = f_data[2][4] + + fac.auto_scram = f_data[3] + fac.ascram_status = f_data[4] + + fac.ps.publish("status_line_1", fac.status_lines[1]) + fac.ps.publish("status_line_2", fac.status_lines[2]) + + fac.ps.publish("auto_ready", fac.auto_ready) + fac.ps.publish("auto_active", fac.auto_active) + fac.ps.publish("auto_ramping", fac.auto_ramping) + fac.ps.publish("auto_saturated", fac.auto_saturated) + + fac.ps.publish("auto_scram", fac.auto_scram) + fac.ps.publish("as_matrix_fault", fac.ascram_status.matrix_fault) + fac.ps.publish("as_matrix_fill", fac.ascram_status.matrix_fill) + fac.ps.publish("as_crit_alarm", fac.ascram_status.crit_alarm) + fac.ps.publish("as_radiation", fac.ascram_status.radiation) + fac.ps.publish("as_gen_fault", fac.ascram_status.gen_fault) + + fac.ps.publish("process_mode", f_data[5][1]) + fac.ps.publish("process_burn_target", f_data[5][2]) + fac.ps.publish("process_charge_target", f_data[5][3]) + fac.ps.publish("process_gen_target", f_data[5][4]) +end + +-- update waste app with unit data from API_GET_WASTE +---@param data table +function iorx.record_waste_data(data) + -- get unit data + for u_id = 1, #io.units do + local unit = io.units[u_id] + local u_data = data[u_id] + + unit.waste_mode = u_data[1] + unit.waste_product = u_data[2] + unit.num_snas = u_data[3] + unit.sna_peak_rate = u_data[4] + unit.sna_max_rate = u_data[5] + unit.sna_out_rate = u_data[6] + unit.waste_stats = u_data[7] + + unit.unit_ps.publish("U_AutoWaste", unit.waste_mode == types.WASTE_MODE.AUTO) + unit.unit_ps.publish("U_WasteMode", unit.waste_mode) + unit.unit_ps.publish("U_WasteProduct", unit.waste_product) + + unit.unit_ps.publish("sna_count", unit.num_snas) + unit.unit_ps.publish("sna_peak_rate", unit.sna_peak_rate) + unit.unit_ps.publish("sna_max_rate", unit.sna_max_rate) + unit.unit_ps.publish("sna_out_rate", unit.sna_out_rate) + + unit.unit_ps.publish("pu_rate", unit.waste_stats[1]) + unit.unit_ps.publish("po_rate", unit.waste_stats[2]) + unit.unit_ps.publish("po_pl_rate", unit.waste_stats[3]) + end + + -- get facility data + local fac = io.facility + local f_data = data[#io.units + 1] + + fac.auto_current_waste_product = f_data[1] + fac.auto_pu_fallback_active = f_data[2] + fac.auto_sps_disabled = f_data[3] + + fac.ps.publish("current_waste_product", fac.auto_current_waste_product) + fac.ps.publish("pu_fallback_active", fac.auto_pu_fallback_active) + fac.ps.publish("sps_disabled_low_power", fac.auto_sps_disabled) + + fac.ps.publish("process_waste_product", f_data[4]) + fac.ps.publish("process_pu_fallback", f_data[5]) + fac.ps.publish("process_sps_low_power", f_data[6]) + + fac.waste_stats = f_data[7] + + fac.ps.publish("burn_sum", fac.waste_stats[1]) + fac.ps.publish("pu_rate", fac.waste_stats[2]) + fac.ps.publish("po_rate", fac.waste_stats[3]) + fac.ps.publish("po_pl_rate", fac.waste_stats[4]) + fac.ps.publish("po_am_rate", fac.waste_stats[5]) + fac.ps.publish("spent_waste_rate", fac.waste_stats[6]) + + fac.ps.publish("sps_computed_status", f_data[8]) + fac.ps.publish("sps_process_rate", f_data[9]) +end + +return function (io_obj) + io = io_obj + return iorx +end diff --git a/pocket/pocket.lua b/pocket/pocket.lua index 461f57a..ccd3762 100644 --- a/pocket/pocket.lua +++ b/pocket/pocket.lua @@ -726,23 +726,23 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav) end elseif packet.type == CRDN_TYPE.API_GET_FAC then if _check_length(packet, 11) then - iocontrol.record_facility_data(packet.data) + iocontrol.rx.record_facility_data(packet.data) end elseif packet.type == CRDN_TYPE.API_GET_UNIT then if _check_length(packet, 12) and type(packet.data[1]) == "number" and iocontrol.get_db().units[packet.data[1]] then - iocontrol.record_unit_data(packet.data) + iocontrol.rx.record_unit_data(packet.data) end elseif packet.type == CRDN_TYPE.API_GET_CTRL then if _check_length(packet, #iocontrol.get_db().units) then - iocontrol.record_control_data(packet.data) + iocontrol.rx.record_control_data(packet.data) end elseif packet.type == CRDN_TYPE.API_GET_PROC then if _check_length(packet, #iocontrol.get_db().units + 1) then - iocontrol.record_process_data(packet.data) + iocontrol.rx.record_process_data(packet.data) end elseif packet.type == CRDN_TYPE.API_GET_WASTE then if _check_length(packet, #iocontrol.get_db().units + 1) then - iocontrol.record_waste_data(packet.data) + iocontrol.rx.record_waste_data(packet.data) end else _fail_type(packet) end else diff --git a/pocket/startup.lua b/pocket/startup.lua index 0eea7b0..0058904 100644 --- a/pocket/startup.lua +++ b/pocket/startup.lua @@ -20,7 +20,7 @@ local pocket = require("pocket.pocket") local renderer = require("pocket.renderer") local threads = require("pocket.threads") -local POCKET_VERSION = "v0.12.10-alpha" +local POCKET_VERSION = "v0.12.11-alpha" local println = util.println local println_ts = util.println_ts diff --git a/pocket/ui/apps/unit.lua b/pocket/ui/apps/unit.lua index bc34d5f..30823d6 100644 --- a/pocket/ui/apps/unit.lua +++ b/pocket/ui/apps/unit.lua @@ -9,6 +9,7 @@ local pocket = require("pocket.pocket") local style = require("pocket.ui.style") +local dyn_tank = require("pocket.ui.pages.dynamic_tank") local boiler = require("pocket.ui.pages.unit_boiler") local reactor = require("pocket.ui.pages.unit_reactor") local turbine = require("pocket.ui.pages.unit_turbine") @@ -92,6 +93,10 @@ local function new_view(root) table.insert(list, { label = "T-" .. i, color = core.cpair(colors.black, colors.lightGray), callback = nav_links[id].turbine[i] }) end + if #unit.tank_data_tbl > 0 then + table.insert(list, { label = "DYN", color = core.cpair(colors.black, colors.lightGray), callback = nav_links[id].d_tank }) + end + app.set_sidebar(list) end @@ -363,6 +368,15 @@ local function new_view(root) --#endregion + --#region Dynamic Tank Tab + + if #unit.tank_data_tbl > 0 then + local tank_pane = Div{parent=page_div} + nav_links[i].d_tank = dyn_tank(app, u_page, panes, tank_pane, 1, unit.tank_ps_tbl[1], update) + end + + --#endregion + util.nop() end diff --git a/pocket/ui/pages/dynamic_tank.lua b/pocket/ui/pages/dynamic_tank.lua new file mode 100644 index 0000000..bb3cc01 --- /dev/null +++ b/pocket/ui/pages/dynamic_tank.lua @@ -0,0 +1,48 @@ +local util = require("scada-common.util") + +local iocontrol = require("pocket.iocontrol") + +local style = require("pocket.ui.style") + +local core = require("graphics.core") + +local Div = require("graphics.elements.Div") +local TextBox = require("graphics.elements.TextBox") + +local PushButton = require("graphics.elements.controls.PushButton") + +local DataIndicator = require("graphics.elements.indicators.DataIndicator") +local IconIndicator = require("graphics.elements.indicators.IconIndicator") +local StateIndicator = require("graphics.elements.indicators.StateIndicator") +local VerticalBar = require("graphics.elements.indicators.VerticalBar") + +local ALIGN = core.ALIGN +local cpair = core.cpair + +local label = style.label +local lu_col = style.label_unit_pair +local text_fg = style.text_fg +local tri_ind_s = style.icon_states.tri_ind_s +local red_ind_s = style.icon_states.red_ind_s +local yel_ind_s = style.icon_states.yel_ind_s + +-- create a dynamic tank view for the unit or facility app +---@param app pocket_app +---@param page nav_tree_page +---@param panes Div[] +---@param tank_pane Div +---@param ps psil +---@param update function +return function (app, page, panes, tank_pane, u_id, ps, update) + local db = iocontrol.get_db() + + local tank_div = Div{parent=tank_pane,x=2,width=tank_pane.get_width()-2} + table.insert(panes, tank_div) + + local tank_page = app.new_page(page, #panes) + tank_page.tasks = { update } + + TextBox{parent=tank_div,y=1,text="Dyn Tank",width=9} + local status = StateIndicator{parent=tank_div,x=10,y=1,states=style.dtank.states,value=1,min_width=12} + status.register(ps, "DynamicTankStateStatus", status.update) +end diff --git a/pocket/ui/style.lua b/pocket/ui/style.lua index aba5d19..400fbc2 100644 --- a/pocket/ui/style.lua +++ b/pocket/ui/style.lua @@ -184,6 +184,36 @@ style.turbine = { } } +style.dtank = { + -- dynamic tank states + states = { + { + color = cpair(colors.black, colors.yellow), + text = "OFF-LINE" + }, + { + color = cpair(colors.black, colors.orange), + text = "NOT FORMED" + }, + { + color = cpair(colors.black, colors.orange), + text = "RTU FAULT" + }, + { + color = cpair(colors.black, colors.green), + text = "ONLINE" + }, + { + color = cpair(colors.black, colors.yellow), + text = "LOW FILL" + }, + { + color = cpair(colors.black, colors.green), + text = "FILLED" + } + } +} + style.imatrix = { -- induction matrix states states = { @@ -210,7 +240,7 @@ style.imatrix = { { color = cpair(colors.black, colors.yellow), text = "HIGH CHARGE" - }, + } } }