mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#78 removed redundant device index from boiler/turbine ps keys
This commit is contained in:
parent
b53d2d6694
commit
c2ac7fc973
@ -399,7 +399,7 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
|
||||
end
|
||||
elseif packet.type == SCADA_CRDN_TYPES.STRUCT_BUILDS then
|
||||
-- record builds
|
||||
if iocontrol.populate_builds(packet.data) then
|
||||
if iocontrol.record_builds(packet.data) then
|
||||
-- acknowledge receipt of builds
|
||||
_send_sv(PROTOCOLS.SCADA_CRDN, SCADA_CRDN_TYPES.STRUCT_BUILDS, {})
|
||||
else
|
||||
|
@ -60,7 +60,7 @@ end
|
||||
-- populate structure builds
|
||||
---@param builds table
|
||||
---@return boolean valid
|
||||
function iocontrol.populate_builds(builds)
|
||||
function iocontrol.record_builds(builds)
|
||||
if #builds ~= #io.units then
|
||||
log.error("number of provided unit builds does not match expected number of units")
|
||||
return false
|
||||
@ -84,10 +84,8 @@ function iocontrol.populate_builds(builds)
|
||||
|
||||
unit.boiler_ps_tbl[id].publish("formed", boiler[2])
|
||||
|
||||
local key_prefix = "unit_" .. i .. "_boiler_" .. id .. "_"
|
||||
|
||||
for key, val in pairs(unit.boiler_data_tbl[id].build) do
|
||||
unit.boiler_ps_tbl[id].publish(key_prefix .. key, val)
|
||||
unit.boiler_ps_tbl[id].publish(key, val)
|
||||
end
|
||||
end
|
||||
|
||||
@ -100,10 +98,8 @@ function iocontrol.populate_builds(builds)
|
||||
|
||||
unit.turbine_ps_tbl[id].publish("formed", turbine[2])
|
||||
|
||||
local key_prefix = "unit_" .. i .. "_turbine_" .. id .. "_"
|
||||
|
||||
for key, val in pairs(unit.turbine_data_tbl[id].build) do
|
||||
unit.turbine_ps_tbl[id].publish(key_prefix .. key, val)
|
||||
unit.turbine_ps_tbl[id].publish(key, val)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -129,11 +125,8 @@ function iocontrol.update_statuses(statuses)
|
||||
local reactor_status = status[1]
|
||||
|
||||
if #reactor_status == 0 then
|
||||
unit.reactor_ps.publish("online", false)
|
||||
unit.reactor_ps.publish("computed_status", 1) -- disconnected
|
||||
else
|
||||
unit.reactor_ps.publish("online", true)
|
||||
|
||||
local mek_status = reactor_status[1]
|
||||
local rps_status = reactor_status[2]
|
||||
local gen_status = reactor_status[3]
|
||||
@ -181,16 +174,31 @@ function iocontrol.update_statuses(statuses)
|
||||
|
||||
for key, val in pairs(annunciator) do
|
||||
if key == "TurbineTrip" then
|
||||
-- split up turbine trip table for all turbines and a general OR combination
|
||||
local trips = val
|
||||
local any = false
|
||||
|
||||
for x = 1, #trips do
|
||||
any = any or trips[x]
|
||||
unit.turbine_ps_tbl[x].publish(x .. "_TurbineTrip", trips[x])
|
||||
for id = 1, #trips do
|
||||
any = any or trips[id]
|
||||
unit.turbine_ps_tbl[id].publish(key, trips[id])
|
||||
end
|
||||
|
||||
unit.reactor_ps.publish("TurbineTrip", any)
|
||||
elseif key == "BoilerOnline" or key == "HeatingRateLow" then
|
||||
-- split up array for all boilers
|
||||
for id = 1, #val do
|
||||
unit.boiler_ps_tbl[id].publish(key, val[id])
|
||||
end
|
||||
elseif key == "TurbineOnline" or key == "SteamDumpOpen" or key == "TurbineOverSpeed" then
|
||||
-- split up array for all turbines
|
||||
for id = 1, #val do
|
||||
unit.turbine_ps_tbl[id].publish(key, val[id])
|
||||
end
|
||||
elseif type(val) == "table" then
|
||||
-- we missed one of the tables?
|
||||
log.error("unrecognized table found in annunciator list, this is a bug", true)
|
||||
else
|
||||
-- non-table fields
|
||||
unit.reactor_ps.publish(key, val)
|
||||
end
|
||||
end
|
||||
@ -204,33 +212,28 @@ function iocontrol.update_statuses(statuses)
|
||||
for id = 1, #unit.boiler_data_tbl do
|
||||
if rtu_statuses.boilers[i] == nil then
|
||||
-- disconnected
|
||||
unit.boiler_ps_tbl[id].publish(id .. "_online", false)
|
||||
unit.boiler_ps_tbl[id].publish(id .. "_computed_status", 1)
|
||||
unit.boiler_ps_tbl[id].publish("computed_status", 1)
|
||||
end
|
||||
end
|
||||
|
||||
for id, boiler in pairs(rtu_statuses.boilers) do
|
||||
unit.boiler_ps_tbl[id].publish(id .. "_online", true)
|
||||
|
||||
unit.boiler_data_tbl[id].state = boiler[1] ---@type table
|
||||
unit.boiler_data_tbl[id].tanks = boiler[2] ---@type table
|
||||
|
||||
local key_prefix = id .. "_"
|
||||
|
||||
local data = unit.boiler_data_tbl[id] ---@type boiler_session_db|boilerv_session_db
|
||||
|
||||
if data.state.boil_rate > 0 then
|
||||
unit.boiler_ps_tbl[id].publish(id .. "_computed_status", 3) -- active
|
||||
unit.boiler_ps_tbl[id].publish("computed_status", 3) -- active
|
||||
else
|
||||
unit.boiler_ps_tbl[id].publish(id .. "_computed_status", 2) -- idle
|
||||
unit.boiler_ps_tbl[id].publish("computed_status", 2) -- idle
|
||||
end
|
||||
|
||||
for key, val in pairs(unit.boiler_data_tbl[id].state) do
|
||||
unit.boiler_ps_tbl[id].publish(key_prefix .. key, val)
|
||||
unit.boiler_ps_tbl[id].publish(key, val)
|
||||
end
|
||||
|
||||
for key, val in pairs(unit.boiler_data_tbl[id].tanks) do
|
||||
unit.boiler_ps_tbl[id].publish(key_prefix .. key, val)
|
||||
unit.boiler_ps_tbl[id].publish(key, val)
|
||||
end
|
||||
end
|
||||
|
||||
@ -239,35 +242,30 @@ function iocontrol.update_statuses(statuses)
|
||||
for id = 1, #unit.turbine_ps_tbl do
|
||||
if rtu_statuses.turbines[i] == nil then
|
||||
-- disconnected
|
||||
unit.turbine_ps_tbl[id].publish(id .. "_online", false)
|
||||
unit.turbine_ps_tbl[id].publish(id .. "_computed_status", 1)
|
||||
unit.turbine_ps_tbl[id].publish("computed_status", 1)
|
||||
end
|
||||
end
|
||||
|
||||
for id, turbine in pairs(rtu_statuses.turbines) do
|
||||
unit.turbine_ps_tbl[id].publish(id .. "_online", true)
|
||||
|
||||
unit.turbine_data_tbl[id].state = turbine[1] ---@type table
|
||||
unit.turbine_data_tbl[id].tanks = turbine[2] ---@type table
|
||||
|
||||
local key_prefix = id .. "_"
|
||||
|
||||
local data = unit.turbine_data_tbl[id] ---@type turbine_session_db|turbinev_session_db
|
||||
|
||||
if data.tanks.steam_fill >= 0.99 then
|
||||
unit.turbine_ps_tbl[id].publish(id .. "_computed_status", 4) -- trip
|
||||
unit.turbine_ps_tbl[id].publish("computed_status", 4) -- trip
|
||||
elseif data.state.flow_rate < 100 then
|
||||
unit.turbine_ps_tbl[id].publish(id .. "_computed_status", 2) -- idle
|
||||
unit.turbine_ps_tbl[id].publish("computed_status", 2) -- idle
|
||||
else
|
||||
unit.turbine_ps_tbl[id].publish(id .. "_computed_status", 3) -- active
|
||||
unit.turbine_ps_tbl[id].publish("computed_status", 3) -- active
|
||||
end
|
||||
|
||||
for key, val in pairs(unit.turbine_data_tbl[id].state) do
|
||||
unit.turbine_ps_tbl[id].publish(key_prefix .. key, val)
|
||||
unit.turbine_ps_tbl[id].publish(key, val)
|
||||
end
|
||||
|
||||
for key, val in pairs(unit.turbine_data_tbl[id].tanks) do
|
||||
unit.turbine_ps_tbl[id].publish(key_prefix .. key, val)
|
||||
unit.turbine_ps_tbl[id].publish(key, val)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,8 +8,6 @@ local Rectangle = require("graphics.elements.rectangle")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
local VerticalBar = require("graphics.elements.indicators.vbar")
|
||||
|
||||
local TEXT_ALIGN = core.graphics.TEXT_ALIGN
|
||||
|
||||
local cpair = core.graphics.cpair
|
||||
local border = core.graphics.border
|
||||
|
||||
@ -17,11 +15,8 @@ local border = core.graphics.border
|
||||
---@param root graphics_element parent
|
||||
---@param x integer top left x
|
||||
---@param y integer top left y
|
||||
---@param id integer device index
|
||||
---@param ps psil ps interface
|
||||
local function new_view(root, x, y, id, ps)
|
||||
local tag = id .. "_"
|
||||
|
||||
local function new_view(root, x, y, ps)
|
||||
local boiler = Rectangle{parent=root,border=border(1, colors.gray, true),width=31,height=7,x=x,y=y}
|
||||
|
||||
local text_fg_bg = cpair(colors.black, colors.lightGray)
|
||||
@ -31,9 +26,9 @@ local function new_view(root, x, y, id, ps)
|
||||
local temp = DataIndicator{parent=boiler,x=5,y=3,lu_colors=lu_col,label="Temp:",unit="K",format="%10.2f",value=0,width=22,fg_bg=text_fg_bg}
|
||||
local boil_r = DataIndicator{parent=boiler,x=5,y=4,lu_colors=lu_col,label="Boil:",unit="mB/t",format="%10.0f",value=0,commas=true,width=22,fg_bg=text_fg_bg}
|
||||
|
||||
ps.subscribe(tag .. "computed_status", status.update)
|
||||
ps.subscribe(tag .. "temperature", temp.update)
|
||||
ps.subscribe(tag .. "boil_rate", boil_r.update)
|
||||
ps.subscribe("computed_status", status.update)
|
||||
ps.subscribe("temperature", temp.update)
|
||||
ps.subscribe("boil_rate", boil_r.update)
|
||||
|
||||
TextBox{parent=boiler,text="H",x=2,y=5,height=1,width=1,fg_bg=text_fg_bg}
|
||||
TextBox{parent=boiler,text="W",x=3,y=5,height=1,width=1,fg_bg=text_fg_bg}
|
||||
@ -45,10 +40,10 @@ local function new_view(root, x, y, id, ps)
|
||||
local steam = VerticalBar{parent=boiler,x=27,y=1,fg_bg=cpair(colors.white,colors.gray),height=4,width=1}
|
||||
local ccool = VerticalBar{parent=boiler,x=28,y=1,fg_bg=cpair(colors.lightBlue,colors.gray),height=4,width=1}
|
||||
|
||||
ps.subscribe(tag .. "hcool_fill", hcool.update)
|
||||
ps.subscribe(tag .. "water_fill", water.update)
|
||||
ps.subscribe(tag .. "steam_fill", steam.update)
|
||||
ps.subscribe(tag .. "ccool_fill", ccool.update)
|
||||
ps.subscribe("hcool_fill", hcool.update)
|
||||
ps.subscribe("water_fill", water.update)
|
||||
ps.subscribe("steam_fill", steam.update)
|
||||
ps.subscribe("ccool_fill", ccool.update)
|
||||
end
|
||||
|
||||
return new_view
|
||||
|
@ -5,11 +5,8 @@ local style = require("coordinator.ui.style")
|
||||
local DataIndicator = require("graphics.elements.indicators.data")
|
||||
local StateIndicator = require("graphics.elements.indicators.state")
|
||||
local Rectangle = require("graphics.elements.rectangle")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
local VerticalBar = require("graphics.elements.indicators.vbar")
|
||||
|
||||
local TEXT_ALIGN = core.graphics.TEXT_ALIGN
|
||||
|
||||
local cpair = core.graphics.cpair
|
||||
local border = core.graphics.border
|
||||
|
||||
@ -17,27 +14,24 @@ local border = core.graphics.border
|
||||
---@param root graphics_element parent
|
||||
---@param x integer top left x
|
||||
---@param y integer top left y
|
||||
---@param id integer device index
|
||||
---@param ps psil ps interface
|
||||
local function new_view(root, x, y, id, ps)
|
||||
local tag = id .. "_"
|
||||
|
||||
local function new_view(root, x, y, ps)
|
||||
local turbine = Rectangle{parent=root,border=border(1, colors.gray, true),width=23,height=7,x=x,y=y}
|
||||
|
||||
local text_fg_bg = cpair(colors.black, colors.lightGray)
|
||||
local lu_col = cpair(colors.gray, colors.gray)
|
||||
|
||||
local status = StateIndicator{parent=turbine,x=8,y=1,states=style.turbine.states,value=1,min_width=10}
|
||||
local prod_rate = DataIndicator{parent=turbine,x=5,y=3,lu_colors=lu_col,label="",unit="MFE",format="%10.2f",value=0,width=16,fg_bg=text_fg_bg}
|
||||
local flow_rate = DataIndicator{parent=turbine,x=5,y=4,lu_colors=lu_col,label="",unit="mB/t",format="%10.0f",value=0,commas=true,width=16,fg_bg=text_fg_bg}
|
||||
local status = StateIndicator{parent=turbine,x=8,y=1,states=style.turbine.states,value=1,min_width=10}
|
||||
local prod_rate = DataIndicator{parent=turbine,x=5,y=3,lu_colors=lu_col,label="",unit="MFE",format="%10.2f",value=0,width=16,fg_bg=text_fg_bg}
|
||||
local flow_rate = DataIndicator{parent=turbine,x=5,y=4,lu_colors=lu_col,label="",unit="mB/t",format="%10.0f",value=0,commas=true,width=16,fg_bg=text_fg_bg}
|
||||
|
||||
ps.subscribe(tag .. "computed_status", status.update)
|
||||
ps.subscribe(tag .. "prod_rate", prod_rate.update)
|
||||
ps.subscribe(tag .. "flow_rate", flow_rate.update)
|
||||
ps.subscribe("computed_status", status.update)
|
||||
ps.subscribe("prod_rate", prod_rate.update)
|
||||
ps.subscribe("flow_rate", flow_rate.update)
|
||||
|
||||
local steam = VerticalBar{parent=turbine,x=2,y=1,fg_bg=cpair(colors.white,colors.gray),height=5,width=2}
|
||||
|
||||
ps.subscribe(tag .. "steam_fill", steam.update)
|
||||
ps.subscribe("steam_fill", steam.update)
|
||||
end
|
||||
|
||||
return new_view
|
||||
|
@ -74,8 +74,8 @@ local function make(parent, x, y, unit)
|
||||
-- BOILERS --
|
||||
-------------
|
||||
|
||||
if num_boilers >= 1 then boiler_view(root, 16, 11, 1, unit.boiler_ps_tbl[1]) end
|
||||
if num_boilers >= 2 then boiler_view(root, 16, 19, 2, unit.boiler_ps_tbl[2]) end
|
||||
if num_boilers >= 1 then boiler_view(root, 16, 11, unit.boiler_ps_tbl[1]) end
|
||||
if num_boilers >= 2 then boiler_view(root, 16, 19, unit.boiler_ps_tbl[2]) end
|
||||
|
||||
--------------
|
||||
-- TURBINES --
|
||||
@ -85,17 +85,17 @@ local function make(parent, x, y, unit)
|
||||
local no_boilers = num_boilers == 0
|
||||
|
||||
if (num_turbines >= 3) or no_boilers or (num_boilers == 1 and num_turbines >= 2) then
|
||||
turbine_view(root, 58, 3, t_idx, unit.turbine_ps_tbl[t_idx])
|
||||
turbine_view(root, 58, 3, unit.turbine_ps_tbl[t_idx])
|
||||
t_idx = t_idx + 1
|
||||
end
|
||||
|
||||
if (num_turbines >= 1 and not no_boilers) or num_turbines >= 2 then
|
||||
turbine_view(root, 58, 11, t_idx, unit.turbine_ps_tbl[t_idx])
|
||||
turbine_view(root, 58, 11, unit.turbine_ps_tbl[t_idx])
|
||||
t_idx = t_idx + 1
|
||||
end
|
||||
|
||||
if (num_turbines >= 2 and num_boilers >= 2) or num_turbines >= 3 then
|
||||
turbine_view(root, 58, 19, t_idx, unit.turbine_ps_tbl[t_idx])
|
||||
turbine_view(root, 58, 19, unit.turbine_ps_tbl[t_idx])
|
||||
end
|
||||
|
||||
local steam_pipes_b = {}
|
||||
|
Loading…
Reference in New Issue
Block a user