cc-mek-scada/scada-common/types.lua

444 lines
8.3 KiB
Lua
Raw Normal View History

--
2022-05-03 14:44:18 +00:00
-- Global Types
--
2022-05-03 14:44:18 +00:00
2022-05-10 21:06:27 +00:00
---@class types
local types = {}
-- CLASSES --
2022-05-12 19:37:42 +00:00
---@class tank_fluid
---@field name fluid
---@field amount integer
2022-05-12 19:37:42 +00:00
-- create a new tank fluid
2023-02-21 15:31:05 +00:00
---@nodiscard
---@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
2023-02-21 15:31:05 +00:00
---@nodiscard
---@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
2023-02-21 15:31:05 +00:00
---@nodiscard
---@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
2023-02-21 15:31:05 +00:00
---@nodiscard
---@return radiation_reading
function types.new_zero_radiation_reading() return { radiation = 0, unit = "nSv" } end
---@class coordinate_2d
---@field x integer
---@field y integer
2022-05-12 19:37:42 +00:00
---@class coordinate
---@field x integer
---@field y integer
---@field z integer
-- create a new coordinate
2023-02-21 15:31:05 +00:00
---@nodiscard
---@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
2023-02-21 15:31:05 +00:00
---@nodiscard
---@return coordinate
function types.new_zero_coordinate() return { x = 0, y = 0, z = 0 } end
---@class rtu_advertisement
2023-02-21 16:05:57 +00:00
---@field type RTU_UNIT_TYPE
---@field index integer|false
---@field reactor integer
---@field rsio table|nil
-- ALIASES --
---@alias color integer
2022-05-21 16:24:43 +00:00
-- ENUMERATION TYPES --
2023-02-21 15:31:05 +00:00
--#region
2022-05-21 16:24:43 +00:00
---@enum TEMP_SCALE
types.TEMP_SCALE = {
KELVIN = 1,
CELSIUS = 2,
FAHRENHEIT = 3,
RANKINE = 4
}
types.TEMP_SCALE_NAMES = {
"Kelvin",
"Celsius",
"Fahrenheit",
"Rankine"
}
types.TEMP_SCALE_UNITS = {
"K",
"\xb0C",
"\xb0F",
"\xb0R"
}
2024-07-27 16:34:01 +00:00
---@enum ENERGY_SCALE
types.ENERGY_SCALE = {
JOULES = 1,
FE = 2,
RF = 3
}
types.ENERGY_SCALE_NAMES = {
"Joules (J)",
"Forge Energy (FE)",
"Redstone Flux (RF)"
}
types.ENERGY_SCALE_UNITS = {
"J",
"FE",
"RF"
}
---@enum PANEL_LINK_STATE
types.PANEL_LINK_STATE = {
LINKED = 1,
DENIED = 2,
COLLISION = 3,
BAD_VERSION = 4,
DISCONNECTED = 5
}
2023-02-21 17:27:16 +00:00
---@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+
2023-07-11 21:27:03 +00:00
DYNAMIC_VALVE = 4, -- dynamic tank, mekanism 10.1+
IMATRIX = 5, -- induction matrix
SPS = 6, -- SPS
SNA = 7, -- SNA
ENV_DETECTOR = 8 -- environment detector
2023-02-21 17:27:16 +00:00
}
types.RTU_UNIT_NAMES = {
"redstone",
"boiler_valve",
"turbine_valve",
2023-07-11 21:27:03 +00:00
"dynamic_valve",
2023-02-21 17:27:16 +00:00
"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
2023-07-11 21:27:03 +00:00
utype == types.RTU_UNIT_TYPE.DYNAMIC_VALVE or
2023-02-21 17:27:16 +00:00
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
2023-02-21 15:31:05 +00:00
---@enum TRI_FAIL
2022-05-21 16:24:43 +00:00
types.TRI_FAIL = {
2023-02-21 17:40:34 +00:00
OK = 1,
PARTIAL = 2,
FULL = 3
2022-05-21 16:24:43 +00:00
}
2023-02-21 15:31:05 +00:00
---@enum PROCESS
types.PROCESS = {
2023-02-25 04:59:39 +00:00
INACTIVE = 0,
MAX_BURN = 1,
BURN_RATE = 2,
CHARGE = 3,
GEN_RATE = 4,
MATRIX_FAULT_IDLE = 5,
SYSTEM_ALARM_IDLE = 6,
GEN_RATE_FAULT_IDLE = 7
}
types.PROCESS_NAMES = {
"INACTIVE",
"MAX_BURN",
"BURN_RATE",
"CHARGE",
"GEN_RATE",
"MATRIX_FAULT_IDLE",
"SYSTEM_ALARM_IDLE",
"GEN_RATE_FAULT_IDLE"
}
2023-02-21 15:31:05 +00:00
---@enum WASTE_MODE
types.WASTE_MODE = {
AUTO = 1,
MANUAL_PLUTONIUM = 2,
MANUAL_POLONIUM = 3,
MANUAL_ANTI_MATTER = 4
}
2023-02-21 17:40:34 +00:00
types.WASTE_MODE_NAMES = {
"AUTO",
"MANUAL_PLUTONIUM",
"MANUAL_POLONIUM",
"MANUAL_ANTI_MATTER"
}
---@enum WASTE_PRODUCT
types.WASTE_PRODUCT = {
PLUTONIUM = 1,
POLONIUM = 2,
ANTI_MATTER = 3
}
types.WASTE_PRODUCT_NAMES = {
2023-02-21 17:40:34 +00:00
"PLUTONIUM",
"POLONIUM",
"ANTI_MATTER"
}
2023-02-21 15:31:05 +00:00
---@enum ALARM
types.ALARM = {
ContainmentBreach = 1,
ContainmentRadiation = 2,
ReactorLost = 3,
CriticalDamage = 4,
ReactorDamage = 5,
ReactorOverTemp = 6,
ReactorHighTemp = 7,
ReactorWasteLeak = 8,
ReactorHighWaste = 9,
RPSTransient = 10,
RCSTransient = 11,
TurbineTrip = 12
}
2023-02-21 15:31:05 +00:00
types.ALARM_NAMES = {
"ContainmentBreach",
"ContainmentRadiation",
"ReactorLost",
"CriticalDamage",
"ReactorDamage",
"ReactorOverTemp",
"ReactorHighTemp",
"ReactorWasteLeak",
"ReactorHighWaste",
"RPSTransient",
"RCSTransient",
"TurbineTrip"
}
2023-02-21 15:31:05 +00:00
---@enum ALARM_PRIORITY
types.ALARM_PRIORITY = {
2023-02-21 17:40:34 +00:00
CRITICAL = 1,
EMERGENCY = 2,
URGENT = 3,
TIMELY = 4
}
2023-02-21 15:31:05 +00:00
types.ALARM_PRIORITY_NAMES = {
"CRITICAL",
"EMERGENCY",
"URGENT",
"TIMELY"
}
2023-02-21 15:31:05 +00:00
---@enum ALARM_STATE
types.ALARM_STATE = {
2023-02-21 17:40:34 +00:00
INACTIVE = 1,
TRIPPED = 2,
ACKED = 3,
RING_BACK = 4
}
types.ALARM_STATE_NAMES = {
"INACTIVE",
"TRIPPED",
"ACKED",
"RING_BACK"
}
2023-02-21 15:31:05 +00:00
--#endregion
-- STRING TYPES --
2023-02-21 15:31:05 +00:00
--#region
2022-05-12 19:37:42 +00:00
---@alias side
---|"top"
---|"bottom"
---|"left"
---|"right"
---|"front"
---|"back"
---@alias os_event
---| "alarm"
---| "char"
---| "computer_command"
---| "disk"
---| "disk_eject"
---| "http_check"
---| "http_failure"
---| "http_success"
---| "key"
---| "key_up"
---| "modem_message"
---| "monitor_resize"
---| "monitor_touch"
---| "mouse_click"
---| "mouse_drag"
---| "mouse_scroll"
---| "mouse_up"
2023-09-23 16:53:05 +00:00
---| "double_click" (custom)
---| "paste"
---| "peripheral"
---| "peripheral_detach"
---| "rednet_message"
---| "redstone"
---| "speaker_audio_empty"
---| "task_complete"
---| "term_resize"
---| "terminate"
---| "timer"
---| "turtle_inventory"
---| "websocket_closed"
---| "websocket_failure"
---| "websocket_message"
---| "websocket_success"
2023-09-23 16:53:05 +00:00
---| "clock_start" (custom)
2022-09-03 17:10:09 +00:00
---@alias fluid
---| "mekanism:empty_gas"
---| "minecraft:water"
---| "mekanism:sodium"
---| "mekanism:superheated_sodium"
2023-02-21 16:32:56 +00:00
types.FLUID = {
EMPTY_GAS = "mekanism:empty_gas",
WATER = "minecraft:water",
SODIUM = "mekanism:sodium",
SUPERHEATED_SODIUM = "mekanism:superheated_sodium"
}
2023-02-21 15:31:05 +00:00
---@alias rps_trip_cause
---| "ok"
---| "high_dmg"
2023-02-21 15:31:05 +00:00
---| "high_temp"
---| "low_coolant"
2023-02-21 16:29:04 +00:00
---| "ex_waste"
---| "ex_heated_coolant"
2023-02-21 15:31:05 +00:00
---| "no_fuel"
---| "fault"
---| "timeout"
---| "manual"
---| "automatic"
---| "sys_fail"
---| "force_disabled"
2023-02-21 16:29:04 +00:00
types.RPS_TRIP_CAUSE = {
OK = "ok",
HIGH_DMG = "high_dmg",
2023-02-21 16:29:04 +00:00
HIGH_TEMP = "high_temp",
LOW_COOLANT = "low_coolant",
2023-02-21 16:29:04 +00:00
EX_WASTE = "ex_waste",
EX_HCOOLANT = "ex_heated_coolant",
NO_FUEL = "no_fuel",
FAULT = "fault",
TIMEOUT = "timeout",
MANUAL = "manual",
AUTOMATIC = "automatic",
SYS_FAIL = "sys_fail",
FORCE_DISABLED = "force_disabled"
2022-05-03 14:44:18 +00:00
}
2023-07-11 21:27:03 +00:00
---@alias container_mode
---| "BOTH"
---| "FILL"
---| "EMPTY"
types.CONTAINER_MODE = {
BOTH = "BOTH",
FILL = "FILL",
EMPTY = "EMPTY"
}
2023-02-21 16:30:49 +00:00
---@alias dumping_mode
2023-02-21 15:31:05 +00:00
---| "IDLE"
---| "DUMPING"
---| "DUMPING_EXCESS"
types.DUMPING_MODE = {
IDLE = "IDLE",
DUMPING = "DUMPING",
DUMPING_EXCESS = "DUMPING_EXCESS"
}
2023-02-21 15:31:05 +00:00
--#endregion
2023-02-21 15:31:05 +00:00
-- MODBUS --
--#region
-- MODBUS function codes
---@enum MODBUS_FCODE
types.MODBUS_FCODE = {
READ_COILS = 0x01,
READ_DISCRETE_INPUTS = 0x02,
READ_MUL_HOLD_REGS = 0x03,
READ_INPUT_REGS = 0x04,
WRITE_SINGLE_COIL = 0x05,
WRITE_SINGLE_HOLD_REG = 0x06,
WRITE_MUL_COILS = 0x0F,
WRITE_MUL_HOLD_REGS = 0x10,
ERROR_FLAG = 0x80
}
2023-02-21 15:31:05 +00:00
-- MODBUS exception codes
---@enum MODBUS_EXCODE
types.MODBUS_EXCODE = {
2023-09-03 21:54:39 +00:00
OK = 0x00,
ILLEGAL_FUNCTION = 0x01,
ILLEGAL_DATA_ADDR = 0x02,
ILLEGAL_DATA_VALUE = 0x03,
SERVER_DEVICE_FAIL = 0x04,
ACKNOWLEDGE = 0x05,
SERVER_DEVICE_BUSY = 0x06,
NEG_ACKNOWLEDGE = 0x07,
MEMORY_PARITY_ERROR = 0x08,
GATEWAY_PATH_UNAVAILABLE = 0x0A,
GATEWAY_TARGET_TIMEOUT = 0x0B
}
2023-02-21 15:31:05 +00:00
--#endregion
return types