mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
check for table type before checking length, added power conversion/formatting helpers
This commit is contained in:
parent
50be7f9ca2
commit
4f7775ccb6
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -12,6 +12,7 @@
|
||||
"settings",
|
||||
"window",
|
||||
"read",
|
||||
"periphemu"
|
||||
"periphemu",
|
||||
"mekanismEnergyHelper"
|
||||
]
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ local config = require("coordinator.config")
|
||||
local coordinator = require("coordinator.coordinator")
|
||||
local renderer = require("coordinator.renderer")
|
||||
|
||||
local COORDINATOR_VERSION = "alpha-v0.4.14"
|
||||
local COORDINATOR_VERSION = "alpha-v0.4.15"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
|
@ -1,4 +1,5 @@
|
||||
local core = require("graphics.core")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local style = require("coordinator.ui.style")
|
||||
|
||||
@ -22,11 +23,11 @@ local function new_view(root, x, y, ps)
|
||||
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 prod_rate = DataIndicator{parent=turbine,x=5,y=3,lu_colors=lu_col,label="",unit="FE",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("computed_status", status.update)
|
||||
ps.subscribe("prod_rate", prod_rate.update)
|
||||
ps.subscribe("prod_rate", function (val) prod_rate.update(util.joules_to_fe(val)) end)
|
||||
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}
|
||||
|
@ -13,7 +13,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.8.4"
|
||||
local R_PLC_VERSION = "beta-v0.8.5"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
|
@ -24,7 +24,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
|
||||
local sps_rtu = require("rtu.dev.sps_rtu")
|
||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||
|
||||
local RTU_VERSION = "beta-v0.8.1"
|
||||
local RTU_VERSION = "beta-v0.8.2"
|
||||
|
||||
local rtu_t = types.rtu_t
|
||||
|
||||
|
@ -143,8 +143,12 @@ function comms.scada_packet()
|
||||
if #self.raw >= 3 then
|
||||
self.seq_num = self.raw[1]
|
||||
self.protocol = self.raw[2]
|
||||
self.length = #self.raw[3]
|
||||
self.payload = self.raw[3]
|
||||
|
||||
-- element 3 must be a table
|
||||
if type(self.raw[3]) == "table" then
|
||||
self.length = #self.raw[3]
|
||||
self.payload = self.raw[3]
|
||||
end
|
||||
end
|
||||
|
||||
self.valid = type(self.seq_num) == "number" and
|
||||
|
@ -273,34 +273,37 @@ end
|
||||
|
||||
-- MEKANISM POWER --
|
||||
|
||||
-- function util.kFE(fe) return fe / 1000.0 end
|
||||
-- function util.MFE(fe) return fe / 1000000.0 end
|
||||
-- function util.GFE(fe) return fe / 1000000000.0 end
|
||||
-- function util.TFE(fe) return fe / 1000000000000.0 end
|
||||
-- convert Joules to FE
|
||||
---@param J number Joules
|
||||
---@return number FE Forge Energy
|
||||
function util.joules_to_fe(J) return mekanismEnergyHelper.joulesToFE(J) end
|
||||
|
||||
-- -- FLOATING POINT PRINTS --
|
||||
-- convert FE to Joules
|
||||
---@param FE number Forge Energy
|
||||
---@return number J Joules
|
||||
function util.fe_to_joules(FE) return mekanismEnergyHelper.feToJoules(FE) end
|
||||
|
||||
-- local function fractional_1s(number)
|
||||
-- return number == math.round(number)
|
||||
-- end
|
||||
local function kFE(fe) return fe / 1000.0 end
|
||||
local function MFE(fe) return fe / 1000000.0 end
|
||||
local function GFE(fe) return fe / 1000000000.0 end
|
||||
local function TFE(fe) return fe / 1000000000000.0 end
|
||||
|
||||
-- local function fractional_10ths(number)
|
||||
-- number = number * 10
|
||||
-- return number == math.round(number)
|
||||
-- end
|
||||
|
||||
-- local function fractional_100ths(number)
|
||||
-- number = number * 100
|
||||
-- return number == math.round(number)
|
||||
-- end
|
||||
|
||||
-- function util.power_format(fe)
|
||||
-- if fe < 1000 then
|
||||
-- return string.format("%.2f FE", fe)
|
||||
-- elseif fe < 1000000 then
|
||||
-- return string.format("%.3f kFE", kFE(fe))
|
||||
-- end
|
||||
-- end
|
||||
-- format a power value into XXX.XX UNIT format (FE, kFE, MFE, GFE, TFE)
|
||||
---@param fe number forge energy value
|
||||
---@return string str formatted string
|
||||
function util.power_format(fe)
|
||||
if fe < 1000 then
|
||||
return string.format("%.2f FE", fe)
|
||||
elseif fe < 1000000 then
|
||||
return string.format("%.2f kFE", kFE(fe))
|
||||
elseif fe < 1000000000 then
|
||||
return string.format("%.2f MFE", MFE(fe))
|
||||
elseif fe < 1000000000000 then
|
||||
return string.format("%.2f GFE", GFE(fe))
|
||||
else
|
||||
return string.format("%.2f TFE", TFE(fe))
|
||||
end
|
||||
end
|
||||
|
||||
-- WATCHDOG --
|
||||
|
||||
|
@ -13,7 +13,7 @@ local svsessions = require("supervisor.session.svsessions")
|
||||
local config = require("supervisor.config")
|
||||
local supervisor = require("supervisor.supervisor")
|
||||
|
||||
local SUPERVISOR_VERSION = "beta-v0.5.13"
|
||||
local SUPERVISOR_VERSION = "beta-v0.5.14"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
|
Loading…
Reference in New Issue
Block a user