#118 refactored RTU unit types

This commit is contained in:
Mikayla Fischler
2023-02-21 12:27:16 -05:00
parent 7247d8a828
commit 424097973d
15 changed files with 146 additions and 169 deletions

View File

@@ -3,13 +3,10 @@
--
local log = require("scada-common.log")
local types = require("scada-common.types")
---@class comms
local comms = {}
local rtu_t = types.rtu_t
local insert = table.insert
local max_distance = nil
@@ -80,17 +77,6 @@ local DEVICE_TYPE = {
CRDN = 3 -- coordinator device type for establish
}
---@enum RTU_UNIT_TYPE
local RTU_UNIT_TYPE = {
REDSTONE = 0, -- redstone I/O
BOILER_VALVE = 1, -- boiler mekanism 10.1+
TURBINE_VALVE = 2, -- turbine, mekanism 10.1+
IMATRIX = 3, -- induction matrix
SPS = 4, -- SPS
SNA = 5, -- SNA
ENV_DETECTOR = 6 -- environment detector
}
---@enum PLC_AUTO_ACK
local PLC_AUTO_ACK = {
FAIL = 0, -- failed to set burn rate/burn rate invalid
@@ -129,7 +115,6 @@ comms.CAPI_TYPE = CAPI_TYPE
comms.ESTABLISH_ACK = ESTABLISH_ACK
comms.DEVICE_TYPE = DEVICE_TYPE
comms.RTU_UNIT_TYPE = RTU_UNIT_TYPE
comms.PLC_AUTO_ACK = PLC_AUTO_ACK
@@ -719,52 +704,4 @@ function comms.capi_packet()
return public
end
-- convert rtu_t to RTU unit type
---@nodiscard
---@param type rtu_t
---@return RTU_UNIT_TYPE|nil
function comms.rtu_t_to_unit_type(type)
if type == rtu_t.redstone then
return RTU_UNIT_TYPE.REDSTONE
elseif type == rtu_t.boiler_valve then
return RTU_UNIT_TYPE.BOILER_VALVE
elseif type == rtu_t.turbine_valve then
return RTU_UNIT_TYPE.TURBINE_VALVE
elseif type == rtu_t.induction_matrix then
return RTU_UNIT_TYPE.IMATRIX
elseif type == rtu_t.sps then
return RTU_UNIT_TYPE.SPS
elseif type == rtu_t.sna then
return RTU_UNIT_TYPE.SNA
elseif type == rtu_t.env_detector then
return RTU_UNIT_TYPE.ENV_DETECTOR
end
return nil
end
-- convert RTU unit type to rtu_t
---@nodiscard
---@param utype RTU_UNIT_TYPE
---@return rtu_t|nil
function comms.advert_type_to_rtu_t(utype)
if utype == RTU_UNIT_TYPE.REDSTONE then
return rtu_t.redstone
elseif utype == RTU_UNIT_TYPE.BOILER_VALVE then
return rtu_t.boiler_valve
elseif utype == RTU_UNIT_TYPE.TURBINE_VALVE then
return rtu_t.turbine_valve
elseif utype == RTU_UNIT_TYPE.IMATRIX then
return rtu_t.induction_matrix
elseif utype == RTU_UNIT_TYPE.SPS then
return rtu_t.sps
elseif utype == RTU_UNIT_TYPE.SNA then
return rtu_t.sna
elseif utype == RTU_UNIT_TYPE.ENV_DETECTOR then
return rtu_t.env_detector
end
return nil
end
return comms

View File

@@ -70,6 +70,48 @@ function types.new_zero_coordinate() return { x = 0, y = 0, z = 0 } end
-- ENUMERATION TYPES --
--#region
---@enum RTU_UNIT_TYPE
types.RTU_UNIT_TYPE = {
VIRTUAL = 0, -- virtual device
REDSTONE = 1, -- redstone I/O
BOILER_VALVE = 2, -- boiler mekanism 10.1+
TURBINE_VALVE = 3, -- turbine, mekanism 10.1+
IMATRIX = 4, -- induction matrix
SPS = 5, -- SPS
SNA = 6, -- SNA
ENV_DETECTOR = 7 -- environment detector
}
types.RTU_UNIT_NAMES = {
"redstone",
"boiler_valve",
"turbine_valve",
"induction_matrix",
"sps",
"sna",
"environment_detector"
}
-- safe conversion of RTU UNIT TYPE to string
---@nodiscard
---@param utype RTU_UNIT_TYPE
---@return string
function types.rtu_type_to_string(utype)
if utype == types.RTU_UNIT_TYPE.VIRTUAL then
return "virtual"
elseif utype == types.RTU_UNIT_TYPE.REDSTONE or
utype == types.RTU_UNIT_TYPE.BOILER_VALVE or
utype == types.RTU_UNIT_TYPE.TURBINE_VALVE or
utype == types.RTU_UNIT_TYPE.IMATRIX or
utype == types.RTU_UNIT_TYPE.SPS or
utype == types.RTU_UNIT_TYPE.SNA or
utype == types.RTU_UNIT_TYPE.ENV_DETECTOR then
return types.RTU_UNIT_NAMES[utype]
else
return ""
end
end
---@enum TRI_FAIL
types.TRI_FAIL = {
OK = 0,
@@ -215,17 +257,6 @@ types.FLUID = {
SUPERHEATED_SODIUM = "mekanism:superheated_sodium"
}
---@alias rtu_t string
types.rtu_t = {
redstone = "redstone",
boiler_valve = "boiler_valve",
turbine_valve = "turbine_valve",
induction_matrix = "induction_matrix",
sps = "sps",
sna = "sna",
env_detector = "environment_detector"
}
---@alias rps_trip_cause
---| "ok"
---| "dmg_crit"