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 comms = require("scada-common.comms")
|
||||||
local ppm = require("scada-common.ppm")
|
local ppm = require("scada-common.ppm")
|
||||||
|
local types = require("scada-common.types")
|
||||||
|
|
||||||
local modbus = require("modbus")
|
local modbus = require("modbus")
|
||||||
|
|
||||||
local rtu = {}
|
local rtu = {}
|
||||||
|
|
||||||
|
local rtu_t = types.rtu_t
|
||||||
|
|
||||||
local PROTOCOLS = comms.PROTOCOLS
|
local PROTOCOLS = comms.PROTOCOLS
|
||||||
local SCADA_MGMT_TYPES = comms.SCADA_MGMT_TYPES
|
local SCADA_MGMT_TYPES = comms.SCADA_MGMT_TYPES
|
||||||
local RTU_ADVERT_TYPES = comms.RTU_ADVERT_TYPES
|
local RTU_ADVERT_TYPES = comms.RTU_ADVERT_TYPES
|
||||||
@ -281,33 +284,22 @@ rtu.comms = function (modem, local_port, server_port)
|
|||||||
local advertisement = {}
|
local advertisement = {}
|
||||||
|
|
||||||
for i = 1, #units do
|
for i = 1, #units do
|
||||||
local type = nil
|
local unit = units[i]
|
||||||
|
local type = comms.rtu_t_to_advert_type(unit.type)
|
||||||
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
|
|
||||||
|
|
||||||
if type ~= nil then
|
if type ~= nil then
|
||||||
if type == RTU_ADVERT_TYPES.REDSTONE then
|
if type == RTU_ADVERT_TYPES.REDSTONE then
|
||||||
insert(advertisement, {
|
insert(advertisement, {
|
||||||
unit = i,
|
|
||||||
type = type,
|
type = type,
|
||||||
index = units[i].index,
|
index = unit.index,
|
||||||
reactor = units[i].for_reactor,
|
reactor = unit.for_reactor,
|
||||||
rsio = units[i].device
|
rsio = unit.device
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
insert(advertisement, {
|
insert(advertisement, {
|
||||||
unit = i,
|
|
||||||
type = type,
|
type = type,
|
||||||
index = units[i].index,
|
index = unit.index,
|
||||||
reactor = units[i].for_reactor,
|
reactor = unit.for_reactor,
|
||||||
rsio = nil
|
rsio = nil
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
-- Communications
|
-- Communications
|
||||||
--
|
--
|
||||||
|
|
||||||
|
local types = require("scada-common.types")
|
||||||
|
|
||||||
local comms = {}
|
local comms = {}
|
||||||
|
|
||||||
|
local rtu_t = types.rtu_t
|
||||||
local insert = table.insert
|
local insert = table.insert
|
||||||
|
|
||||||
local PROTOCOLS = {
|
local PROTOCOLS = {
|
||||||
@ -42,10 +45,13 @@ local SCADA_MGMT_TYPES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local RTU_ADVERT_TYPES = {
|
local RTU_ADVERT_TYPES = {
|
||||||
BOILER = 0, -- boiler
|
REDSTONE = 0, -- redstone I/O
|
||||||
TURBINE = 1, -- turbine
|
BOILER = 1, -- boiler
|
||||||
IMATRIX = 2, -- induction matrix
|
BOILER_VALVE = 2, -- boiler mekanism 10.1+
|
||||||
REDSTONE = 3 -- redstone I/O
|
TURBINE = 3, -- turbine
|
||||||
|
TURBINE_VALVE = 4, -- turbine, mekanism 10.1+
|
||||||
|
EMACHINE = 5, -- energy machine
|
||||||
|
IMATRIX = 6 -- induction matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
comms.PROTOCOLS = PROTOCOLS
|
comms.PROTOCOLS = PROTOCOLS
|
||||||
@ -544,4 +550,46 @@ comms.capi_packet = function ()
|
|||||||
}
|
}
|
||||||
end
|
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
|
return comms
|
||||||
|
Loading…
x
Reference in New Issue
Block a user