From 8ebdf2686bfd2eaea5b4db59c6d1b04ea98079b1 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Tue, 14 Feb 2023 15:15:34 -0500 Subject: [PATCH] #118 created constructors for basic types --- coordinator/iocontrol.lua | 4 ++-- coordinator/startup.lua | 2 +- scada-common/types.lua | 35 +++++++++++++++++++++++++++-- supervisor/session/plc.lua | 5 +++-- supervisor/session/rtu/boilerv.lua | 12 +++++----- supervisor/session/rtu/envd.lua | 2 +- supervisor/session/rtu/imatrix.lua | 4 ++-- supervisor/session/rtu/sna.lua | 4 ++-- supervisor/session/rtu/sps.lua | 8 +++---- supervisor/session/rtu/turbinev.lua | 6 ++--- supervisor/startup.lua | 2 +- 11 files changed, 58 insertions(+), 26 deletions(-) diff --git a/coordinator/iocontrol.lua b/coordinator/iocontrol.lua index 77b878e..af27ab5 100644 --- a/coordinator/iocontrol.lua +++ b/coordinator/iocontrol.lua @@ -31,7 +31,7 @@ function iocontrol.init(conf, comms) auto_saturated = false, auto_scram = false, - radiation = { radiation = 0, unit = "nSv" }, ---@type radiation_reading + radiation = types.new_zero_radiation_reading(), num_units = conf.num_units, ---@type integer @@ -73,7 +73,7 @@ function iocontrol.init(conf, comms) control_state = false, burn_rate_cmd = 0.0, waste_control = 0, - radiation = { radiation = 0, unit = "nSv" }, ---@type radiation_reading + radiation = types.new_zero_radiation_reading(), a_group = 0, -- auto control group diff --git a/coordinator/startup.lua b/coordinator/startup.lua index e7ed010..73df848 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -19,7 +19,7 @@ local iocontrol = require("coordinator.iocontrol") local renderer = require("coordinator.renderer") local sounder = require("coordinator.sounder") -local COORDINATOR_VERSION = "beta-v0.9.10" +local COORDINATOR_VERSION = "beta-v0.9.11" local print = util.print local println = util.println diff --git a/scada-common/types.lua b/scada-common/types.lua index 31ef14b..41946eb 100644 --- a/scada-common/types.lua +++ b/scada-common/types.lua @@ -11,15 +11,46 @@ local types = {} ---@field name string ---@field amount integer +-- create a new tank fluid +---@param n string name +---@param a integer amount +---@return radiation_reading +function types.new_tank_fluid(n, a) return { name = n, amount = a } end + +-- create a new empty tank fluid +---@return tank_fluid +function types.new_empty_gas() return { type = "mekanism:empty_gas", amount = 0 } end + ---@class radiation_reading ---@field radiation number ---@field unit string +-- create a new radiation reading +---@param r number radiaiton level +---@param u string radiation unit +---@return radiation_reading +function types.new_radiation_reading(r, u) return { radiation = r, unit = u } end + +-- create a new zeroed radiation reading +---@return radiation_reading +function types.new_zero_radiation_reading() return { radiation = 0, unit = "nSv" } end + ---@class coordinate ---@field x integer ---@field y integer ---@field z integer +-- create a new coordinate +---@param x integer +---@param y integer +---@param z integer +---@return coordinate +function types.new_coordinate(x, y, z) return { x = x, y = y, z = z } end + +-- create a new zero coordinate +---@return coordinate +function types.new_zero_coordinate() return { x = 0, y = 0, z = 0 } end + ---@class rtu_advertisement ---@field type integer ---@field index integer @@ -47,7 +78,7 @@ types.PROCESS = { CHARGE = 3, GEN_RATE = 4, MATRIX_FAULT_IDLE = 5, - UNIT_ALARM_IDLE = 6, + SYSTEM_ALARM_IDLE = 6, GEN_RATE_FAULT_IDLE = 7 } @@ -58,7 +89,7 @@ types.PROCESS_NAMES = { "CHARGE", "GEN_RATE", "MATRIX_FAULT_IDLE", - "UNIT_ALARM_IDLE", + "SYSTEM_ALARM_IDLE", "GEN_RATE_FAULT_IDLE" } diff --git a/supervisor/session/plc.lua b/supervisor/session/plc.lua index 4d29c3c..f78c6e6 100644 --- a/supervisor/session/plc.lua +++ b/supervisor/session/plc.lua @@ -1,6 +1,7 @@ local comms = require("scada-common.comms") local log = require("scada-common.log") local mqueue = require("scada-common.mqueue") +local types = require("scada-common.types") local util = require("scada-common.util") local svqtypes = require("supervisor.session.svqtypes") @@ -149,8 +150,8 @@ function plc.new_session(id, for_reactor, in_queue, out_queue, timeout) length = 0, width = 0, height = 0, - min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate - max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate + min_pos = types.new_zero_coordinate(), + max_pos = types.new_zero_coordinate(), heat_cap = 0, fuel_asm = 0, fuel_sa = 0, diff --git a/supervisor/session/rtu/boilerv.lua b/supervisor/session/rtu/boilerv.lua index fe61372..2f3b5b5 100644 --- a/supervisor/session/rtu/boilerv.lua +++ b/supervisor/session/rtu/boilerv.lua @@ -62,8 +62,8 @@ function boilerv.new(session_id, unit_id, advert, out_queue) length = 0, width = 0, height = 0, - min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate - max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate + min_pos = types.new_zero_coordinate(), + max_pos = types.new_zero_coordinate(), boil_cap = 0.0, steam_cap = 0, water_cap = 0, @@ -80,16 +80,16 @@ function boilerv.new(session_id, unit_id, advert, out_queue) }, tanks = { last_update = 0, - steam = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid + steam = types.new_empty_gas(), steam_need = 0, steam_fill = 0.0, - water = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid + water = types.new_empty_gas(), water_need = 0, water_fill = 0.0, - hcool = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid + hcool = types.new_empty_gas(), hcool_need = 0, hcool_fill = 0.0, - ccool = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid + ccool = types.new_empty_gas(), ccool_need = 0, ccool_fill = 0.0 } diff --git a/supervisor/session/rtu/envd.lua b/supervisor/session/rtu/envd.lua index 7fb7c26..bc65476 100644 --- a/supervisor/session/rtu/envd.lua +++ b/supervisor/session/rtu/envd.lua @@ -44,7 +44,7 @@ function envd.new(session_id, unit_id, advert, out_queue) ---@class envd_session_db db = { last_update = 0, - radiation = { radiation = 0, unit = "nSv" }, ---@type radiation_reading + radiation = types.new_zero_radiation_reading(), radiation_raw = 0 } } diff --git a/supervisor/session/rtu/imatrix.lua b/supervisor/session/rtu/imatrix.lua index 00e14f7..3ab5d4a 100644 --- a/supervisor/session/rtu/imatrix.lua +++ b/supervisor/session/rtu/imatrix.lua @@ -62,8 +62,8 @@ function imatrix.new(session_id, unit_id, advert, out_queue) length = 0, width = 0, height = 0, - min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate - max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate + min_pos = types.new_zero_coordinate(), + max_pos = types.new_zero_coordinate(), max_energy = 0, transfer_cap = 0, cells = 0, diff --git a/supervisor/session/rtu/sna.lua b/supervisor/session/rtu/sna.lua index 40014d3..cd3415f 100644 --- a/supervisor/session/rtu/sna.lua +++ b/supervisor/session/rtu/sna.lua @@ -64,10 +64,10 @@ function sna.new(session_id, unit_id, advert, out_queue) }, tanks = { last_update = 0, - input = {}, ---@type tank_fluid + input = types.new_empty_gas(), input_need = 0, input_fill = 0.0, - output = {}, ---@type tank_fluid + output = types.new_empty_gas(), output_need = 0, output_fill = 0.0 } diff --git a/supervisor/session/rtu/sps.lua b/supervisor/session/rtu/sps.lua index 4cd7fb1..3a6f4c3 100644 --- a/supervisor/session/rtu/sps.lua +++ b/supervisor/session/rtu/sps.lua @@ -62,8 +62,8 @@ function sps.new(session_id, unit_id, advert, out_queue) length = 0, width = 0, height = 0, - min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate - max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate + min_pos = types.new_zero_coordinate(), + max_pos = types.new_zero_coordinate(), coils = 0, input_cap = 0, output_cap = 0, @@ -75,10 +75,10 @@ function sps.new(session_id, unit_id, advert, out_queue) }, tanks = { last_update = 0, - input = {}, ---@type tank_fluid + input = types.new_empty_gas(), input_need = 0, input_fill = 0.0, - output = {}, ---@type tank_fluid + output = types.new_empty_gas(), output_need = 0, output_fill = 0.0, energy = 0, diff --git a/supervisor/session/rtu/turbinev.lua b/supervisor/session/rtu/turbinev.lua index 5662b70..0ac793a 100644 --- a/supervisor/session/rtu/turbinev.lua +++ b/supervisor/session/rtu/turbinev.lua @@ -74,8 +74,8 @@ function turbinev.new(session_id, unit_id, advert, out_queue) length = 0, width = 0, height = 0, - min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate - max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate + min_pos = types.new_zero_coordinate(), + max_pos = types.new_zero_coordinate(), blades = 0, coils = 0, vents = 0, @@ -96,7 +96,7 @@ function turbinev.new(session_id, unit_id, advert, out_queue) }, tanks = { last_update = 0, - steam = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid + steam = types.new_empty_gas(), steam_need = 0, steam_fill = 0.0, energy = 0, diff --git a/supervisor/startup.lua b/supervisor/startup.lua index 4ff3169..164624d 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -14,7 +14,7 @@ local svsessions = require("supervisor.session.svsessions") local config = require("supervisor.config") local supervisor = require("supervisor.supervisor") -local SUPERVISOR_VERSION = "beta-v0.11.5" +local SUPERVISOR_VERSION = "beta-v0.11.6" local print = util.print local println = util.println