mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
cleanup of rtu comms
This commit is contained in:
parent
96e535fdc4
commit
469ee29b5a
28
rtu/rtu.lua
28
rtu/rtu.lua
@ -1,10 +1,13 @@
|
||||
local comms = require("scada-common.comms")
|
||||
local ppm = require("scada-common.ppm")
|
||||
local types = require("scada-common.types")
|
||||
|
||||
local modbus = require("modbus")
|
||||
|
||||
local rtu = {}
|
||||
|
||||
local rtu_t = types.rtu_t
|
||||
|
||||
local PROTOCOLS = comms.PROTOCOLS
|
||||
local SCADA_MGMT_TYPES = comms.SCADA_MGMT_TYPES
|
||||
local RTU_ADVERT_TYPES = comms.RTU_ADVERT_TYPES
|
||||
@ -281,33 +284,22 @@ rtu.comms = function (modem, local_port, server_port)
|
||||
local advertisement = {}
|
||||
|
||||
for i = 1, #units do
|
||||
local type = nil
|
||||
|
||||
if units[i].type == "boiler" then
|
||||
type = RTU_ADVERT_TYPES.BOILER
|
||||
elseif units[i].type == "turbine" then
|
||||
type = RTU_ADVERT_TYPES.TURBINE
|
||||
elseif units[i].type == "imatrix" then
|
||||
type = RTU_ADVERT_TYPES.IMATRIX
|
||||
elseif units[i].type == "redstone" then
|
||||
type = RTU_ADVERT_TYPES.REDSTONE
|
||||
end
|
||||
local unit = units[i]
|
||||
local type = comms.rtu_t_to_advert_type(unit.type)
|
||||
|
||||
if type ~= nil then
|
||||
if type == RTU_ADVERT_TYPES.REDSTONE then
|
||||
insert(advertisement, {
|
||||
unit = i,
|
||||
type = type,
|
||||
index = units[i].index,
|
||||
reactor = units[i].for_reactor,
|
||||
rsio = units[i].device
|
||||
index = unit.index,
|
||||
reactor = unit.for_reactor,
|
||||
rsio = unit.device
|
||||
})
|
||||
else
|
||||
insert(advertisement, {
|
||||
unit = i,
|
||||
type = type,
|
||||
index = units[i].index,
|
||||
reactor = units[i].for_reactor,
|
||||
index = unit.index,
|
||||
reactor = unit.for_reactor,
|
||||
rsio = nil
|
||||
})
|
||||
end
|
||||
|
@ -2,8 +2,11 @@
|
||||
-- Communications
|
||||
--
|
||||
|
||||
local types = require("scada-common.types")
|
||||
|
||||
local comms = {}
|
||||
|
||||
local rtu_t = types.rtu_t
|
||||
local insert = table.insert
|
||||
|
||||
local PROTOCOLS = {
|
||||
@ -42,10 +45,13 @@ local SCADA_MGMT_TYPES = {
|
||||
}
|
||||
|
||||
local RTU_ADVERT_TYPES = {
|
||||
BOILER = 0, -- boiler
|
||||
TURBINE = 1, -- turbine
|
||||
IMATRIX = 2, -- induction matrix
|
||||
REDSTONE = 3 -- redstone I/O
|
||||
REDSTONE = 0, -- redstone I/O
|
||||
BOILER = 1, -- boiler
|
||||
BOILER_VALVE = 2, -- boiler mekanism 10.1+
|
||||
TURBINE = 3, -- turbine
|
||||
TURBINE_VALVE = 4, -- turbine, mekanism 10.1+
|
||||
EMACHINE = 5, -- energy machine
|
||||
IMATRIX = 6 -- induction matrix
|
||||
}
|
||||
|
||||
comms.PROTOCOLS = PROTOCOLS
|
||||
@ -544,4 +550,46 @@ comms.capi_packet = function ()
|
||||
}
|
||||
end
|
||||
|
||||
-- convert rtu_t to RTU advertisement type
|
||||
comms.rtu_t_to_advert_type = function (type)
|
||||
if type == rtu_t.redstone then
|
||||
return RTU_ADVERT_TYPES.REDSTONE
|
||||
elseif type == rtu_t.boiler then
|
||||
return RTU_ADVERT_TYPES.BOILER
|
||||
elseif type == rtu_t.boiler_valve then
|
||||
return RTU_ADVERT_TYPES.BOILER_VALVE
|
||||
elseif type == rtu_t.turbine then
|
||||
return RTU_ADVERT_TYPES.TURBINE
|
||||
elseif type == rtu_t.turbine_valve then
|
||||
return RTU_ADVERT_TYPES.TURBINE_VALVE
|
||||
elseif type == rtu_t.energy_machine then
|
||||
return RTU_ADVERT_TYPES.EMACHINE
|
||||
elseif type == rtu_t.induction_matrix then
|
||||
return RTU_ADVERT_TYPES.IMATRIX
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
-- convert RTU advertisement type to rtu_t
|
||||
comms.advert_type_to_rtu_t = function (atype)
|
||||
if atype == RTU_ADVERT_TYPES.REDSTONE then
|
||||
return rtu_t.redstone
|
||||
elseif atype == RTU_ADVERT_TYPES.BOILER then
|
||||
return rtu_t.boiler
|
||||
elseif atype == RTU_ADVERT_TYPES.BOILER_VALVE then
|
||||
return rtu_t.boiler_valve
|
||||
elseif atype == RTU_ADVERT_TYPES.TURBINE then
|
||||
return rtu_t.turbine
|
||||
elseif atype == RTU_ADVERT_TYPES.TURBINE_VALVE then
|
||||
return rtu_t.turbine_valve
|
||||
elseif atype == RTU_ADVERT_TYPES.EMACHINE then
|
||||
return rtu_t.energy_machine
|
||||
elseif atype == RTU_ADVERT_TYPES.IMATRIX then
|
||||
return rtu_t.induction_matrix
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
return comms
|
||||
|
Loading…
Reference in New Issue
Block a user