#399 unit waste data updating

This commit is contained in:
Mikayla Fischler 2024-11-17 18:22:40 -05:00
parent 3e1f567c0f
commit 8fad94c4c6
8 changed files with 97 additions and 12 deletions

View File

@ -174,6 +174,7 @@ function iocontrol.init(conf, comms, temp_scale, energy_scale)
waste_mode = types.WASTE_MODE.MANUAL_PLUTONIUM, waste_mode = types.WASTE_MODE.MANUAL_PLUTONIUM,
waste_product = types.WASTE_PRODUCT.PLUTONIUM, waste_product = types.WASTE_PRODUCT.PLUTONIUM,
waste_stats = { 0, 0, 0 }, -- plutonium, polonium, po pellets
last_rate_change_ms = 0, last_rate_change_ms = 0,
turbine_flow_stable = false, turbine_flow_stable = false,
@ -1192,6 +1193,7 @@ function iocontrol.update_unit_statuses(statuses)
local u_spent_rate = waste_rate local u_spent_rate = waste_rate
local u_pu_rate = util.trinary(is_pu, waste_rate, 0.0) local u_pu_rate = util.trinary(is_pu, waste_rate, 0.0)
local u_po_rate = unit.sna_out_rate local u_po_rate = unit.sna_out_rate
local u_po_pl_rate = 0
unit.unit_ps.publish("pu_rate", u_pu_rate) unit.unit_ps.publish("pu_rate", u_pu_rate)
unit.unit_ps.publish("po_rate", u_po_rate) unit.unit_ps.publish("po_rate", u_po_rate)
@ -1202,6 +1204,7 @@ function iocontrol.update_unit_statuses(statuses)
u_spent_rate = u_po_rate u_spent_rate = u_po_rate
unit.unit_ps.publish("po_pl_rate", u_po_rate) unit.unit_ps.publish("po_pl_rate", u_po_rate)
unit.unit_ps.publish("po_am_rate", 0) unit.unit_ps.publish("po_am_rate", 0)
u_po_pl_rate = u_po_rate
po_pl_rate = po_pl_rate + u_po_rate po_pl_rate = po_pl_rate + u_po_rate
elseif unit.waste_product == types.WASTE_PRODUCT.ANTI_MATTER then elseif unit.waste_product == types.WASTE_PRODUCT.ANTI_MATTER then
u_spent_rate = 0 u_spent_rate = 0
@ -1213,6 +1216,8 @@ function iocontrol.update_unit_statuses(statuses)
unit.unit_ps.publish("po_am_rate", 0) unit.unit_ps.publish("po_am_rate", 0)
end end
unit.waste_stats = { u_pu_rate, u_po_rate, u_po_pl_rate }
unit.unit_ps.publish("ws_rate", u_spent_rate) unit.unit_ps.publish("ws_rate", u_spent_rate)
pu_rate = pu_rate + u_pu_rate pu_rate = pu_rate + u_pu_rate

View File

@ -339,6 +339,31 @@ function pocket.new_session(id, s_addr, i_seq_num, in_queue, out_queue, timeout)
{ proc.mode, proc.burn_target, proc.charge_target, proc.gen_target } { proc.mode, proc.burn_target, proc.charge_target, proc.gen_target }
} }
_send(CRDN_TYPE.API_GET_PROC, data)
elseif pkt.type == CRDN_TYPE.API_GET_WASTE then
local data = {}
-- local fac = db.facility
-- local proc = process.get_control_states().process
-- unit data
for i = 1, #db.units do
local u = db.units[i]
data[i] = {
u.waste_mode,
u.waste_product,
u.num_snas,
u.sna_peak_rate,
u.sna_max_rate,
u.sna_out_rate,
u.waste_stats
}
end
-- facility data
data[#db.units + 1] = {}
_send(CRDN_TYPE.API_GET_PROC, data) _send(CRDN_TYPE.API_GET_PROC, data)
else else
log.debug(log_tag .. "handler received unsupported CRDN packet type " .. pkt.type) log.debug(log_tag .. "handler received unsupported CRDN packet type " .. pkt.type)

View File

@ -19,7 +19,7 @@ local renderer = require("coordinator.renderer")
local sounder = require("coordinator.sounder") local sounder = require("coordinator.sounder")
local threads = require("coordinator.threads") local threads = require("coordinator.threads")
local COORDINATOR_VERSION = "v1.5.15" local COORDINATOR_VERSION = "v1.5.16"
local CHUNK_LOAD_DELAY_S = 30.0 local CHUNK_LOAD_DELAY_S = 30.0

View File

@ -94,7 +94,8 @@ function iocontrol.init_core(pkt_comms, nav, cfg)
io.api = { io.api = {
get_unit = function (unit) comms.api__get_unit(unit) end, get_unit = function (unit) comms.api__get_unit(unit) end,
get_ctrl = function () comms.api__get_control() end, get_ctrl = function () comms.api__get_control() end,
get_proc = function () comms.api__get_process() end get_proc = function () comms.api__get_process() end,
get_waste = function () comms.api__get_waste() end
} }
end end
@ -217,6 +218,7 @@ function iocontrol.init_fac(conf)
last_rate_change_ms = 0, last_rate_change_ms = 0,
turbine_flow_stable = false, turbine_flow_stable = false,
waste_stats = { 0, 0, 0 }, -- plutonium, polonium, po pellets
-- auto control group -- auto control group
a_group = types.AUTO_GROUP.MANUAL, a_group = types.AUTO_GROUP.MANUAL,
@ -920,6 +922,37 @@ function iocontrol.record_process_data(data)
fac.ps.publish("process_gen_target", f_data[5][4]) fac.ps.publish("process_gen_target", f_data[5][4])
end 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
end
-- get the IO controller database -- get the IO controller database
function iocontrol.get_db() return io end function iocontrol.get_db() return io end

View File

@ -567,6 +567,11 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
if self.api.linked then _send_api(CRDN_TYPE.API_GET_PROC, {}) end if self.api.linked then _send_api(CRDN_TYPE.API_GET_PROC, {}) end
end end
-- coordinator get waste app data
function public.api__get_waste()
if self.api.linked then _send_api(CRDN_TYPE.API_GET_WASTE, {}) end
end
-- send a facility command -- send a facility command
---@param cmd FAC_COMMAND command ---@param cmd FAC_COMMAND command
---@param option any? optional option options for the optional options (like waste mode) ---@param option any? optional option options for the optional options (like waste mode)
@ -735,6 +740,10 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
if _check_length(packet, #iocontrol.get_db().units + 1) then if _check_length(packet, #iocontrol.get_db().units + 1) then
iocontrol.record_process_data(packet.data) iocontrol.record_process_data(packet.data)
end 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)
end
else _fail_type(packet) end else _fail_type(packet) end
else else
log.debug("discarding coordinator SCADA_CRDN packet before linked") log.debug("discarding coordinator SCADA_CRDN packet before linked")

View File

@ -87,7 +87,7 @@ local function new_view(root)
-- refresh data callback, every 500ms it will re-send the query -- refresh data callback, every 500ms it will re-send the query
local function update() local function update()
if util.time_ms() - last_update >= 500 then if util.time_ms() - last_update >= 500 then
-- db.api.get_waste() db.api.get_waste()
last_update = util.time_ms() last_update = util.time_ms()
end end
end end
@ -109,11 +109,11 @@ local function new_view(root)
TextBox{parent=u_div,y=1,text="Reactor Unit #"..i,alignment=ALIGN.CENTER} TextBox{parent=u_div,y=1,text="Reactor Unit #"..i,alignment=ALIGN.CENTER}
local u_status = StateIndicator{parent=u_div,x=16,y=3,states=style.waste.states_abbrv,value=1,min_width=6} local waste_prod = StateIndicator{parent=u_div,x=16,y=3,states=style.waste.states_abbrv,value=1,min_width=6}
local waste_mode = RadioButton{parent=u_div,y=3,options=style.waste.unit_opts,callback=function()end,radio_colors=cpair(colors.lightGray,colors.gray),select_color=colors.white}
-- u_status.register(f_ps, "current_waste_product", u_status.update) waste_prod.register(u_ps, "U_WasteProduct", waste_prod.update)
waste_mode.register(u_ps, "U_WasteMode", waste_mode.update)
local waste_prod = RadioButton{parent=u_div,y=3,options=style.waste.unit_opts,callback=function()end,radio_colors=cpair(colors.lightGray,colors.gray),select_color=colors.white}
TextBox{parent=u_div,y=8,text="Plutonium (Pellets)",fg_bg=style.label} TextBox{parent=u_div,y=8,text="Plutonium (Pellets)",fg_bg=style.label}
local pu = DataIndicator{parent=u_div,label="",format="%16.3f",value=0,unit="mB/t",lu_colors=lu_col,width=21,fg_bg=text_fg} local pu = DataIndicator{parent=u_div,label="",format="%16.3f",value=0,unit="mB/t",lu_colors=lu_col,width=21,fg_bg=text_fg}
@ -122,6 +122,10 @@ local function new_view(root)
TextBox{parent=u_div,y=14,text="Polonium (Pellets)",fg_bg=style.label} TextBox{parent=u_div,y=14,text="Polonium (Pellets)",fg_bg=style.label}
local popl = DataIndicator{parent=u_div,label="",format="%16.3f",value=0,unit="mB/t",lu_colors=lu_col,width=21,fg_bg=text_fg} local popl = DataIndicator{parent=u_div,label="",format="%16.3f",value=0,unit="mB/t",lu_colors=lu_col,width=21,fg_bg=text_fg}
pu.register(u_ps, "pu_rate", pu.update)
po.register(u_ps, "po_rate", po.update)
popl.register(u_ps, "po_pl_rate", popl.update)
local sna_div = Div{parent=u_pane,x=2,width=page_div.get_width()-2} local sna_div = Div{parent=u_pane,x=2,width=page_div.get_width()-2}
table.insert(panes, sna_div) table.insert(panes, sna_div)
@ -146,6 +150,14 @@ local function new_view(root)
TextBox{parent=sna_div,y=13,text="Current Rate\n In\n Out",fg_bg=style.label} TextBox{parent=sna_div,y=13,text="Current Rate\n In\n Out",fg_bg=style.label}
local cur_i = DataIndicator{parent=sna_div,x=6,y=14,label="",format="%11.2f",value=0,unit="mB/t",lu_colors=lu_col,width=17,fg_bg=text_fg} local cur_i = DataIndicator{parent=sna_div,x=6,y=14,label="",format="%11.2f",value=0,unit="mB/t",lu_colors=lu_col,width=17,fg_bg=text_fg}
local cur_o = DataIndicator{parent=sna_div,x=6,label="",format="%11.2f",value=0,unit="mB/t",lu_colors=lu_col,width=17,fg_bg=text_fg} local cur_o = DataIndicator{parent=sna_div,x=6,label="",format="%11.2f",value=0,unit="mB/t",lu_colors=lu_col,width=17,fg_bg=text_fg}
count.register(u_ps, "sna_count", count.update)
peak_i.register(u_ps, "sna_peak_rate", function (x) peak_i.update(x * 10) end)
peak_o.register(u_ps, "sna_peak_rate", peak_o.update)
max_i.register(u_ps, "sna_max_rate", function (x) max_i.update(x * 10) end)
max_o.register(u_ps, "sna_max_rate", max_o.update)
cur_i.register(u_ps, "sna_out_rate", function (x) cur_i.update(x * 10) end)
cur_o.register(u_ps, "sna_out_rate", cur_o.update)
end end
--#endregion --#endregion

View File

@ -17,8 +17,8 @@ local max_distance = nil
local comms = {} local comms = {}
-- protocol/data versions (protocol/data independent changes tracked by util.lua version) -- protocol/data versions (protocol/data independent changes tracked by util.lua version)
comms.version = "3.0.1" comms.version = "3.0.2"
comms.api_version = "0.0.6" comms.api_version = "0.0.7"
---@enum PROTOCOL ---@enum PROTOCOL
local PROTOCOL = { local PROTOCOL = {
@ -68,8 +68,9 @@ local CRDN_TYPE = {
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_FAC = 7, -- API: get all the facility data
API_GET_UNIT = 8, -- API: get reactor unit data API_GET_UNIT = 8, -- API: get reactor unit data
API_GET_CTRL = 9, -- API: get data used for the control app API_GET_CTRL = 9, -- API: get data for the control app
API_GET_PROC = 10 -- API: get data used for the process app API_GET_PROC = 10, -- API: get data for the process app
API_GET_WASTE = 11 -- API: get data for the waste app
} }
---@enum ESTABLISH_ACK ---@enum ESTABLISH_ACK

View File

@ -22,7 +22,7 @@ local supervisor = require("supervisor.supervisor")
local svsessions = require("supervisor.session.svsessions") local svsessions = require("supervisor.session.svsessions")
local SUPERVISOR_VERSION = "v1.5.15" local SUPERVISOR_VERSION = "v1.5.16"
local println = util.println local println = util.println
local println_ts = util.println_ts local println_ts = util.println_ts