mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#70 validate RTU advertisements on the supervisor
This commit is contained in:
parent
0bc0decbf2
commit
ebcc911b81
@ -102,8 +102,29 @@ function rtu.new_session(id, in_queue, out_queue, advertisement)
|
||||
|
||||
local u_type = unit_advert.type
|
||||
|
||||
-- create unit by type
|
||||
-- validate unit advertisement
|
||||
|
||||
local advert_validator = util.new_validator()
|
||||
advert_validator.assert_type_int(unit_advert.index)
|
||||
advert_validator.assert_type_int(unit_advert.reactor)
|
||||
|
||||
if u_type == RTU_UNIT_TYPES.REDSTONE then
|
||||
advert_validator.assert_type_table(unit_advert.rsio)
|
||||
end
|
||||
|
||||
if advert_validator.valid() then
|
||||
advert_validator.assert_min(unit_advert.index, 1)
|
||||
advert_validator.assert_min(unit_advert.reactor, 1)
|
||||
if not advert_validator.valid() then u_type = false end
|
||||
else
|
||||
u_type = false
|
||||
end
|
||||
|
||||
-- create unit by type
|
||||
|
||||
if u_type == false then
|
||||
-- validation fail
|
||||
elseif u_type == RTU_UNIT_TYPES.REDSTONE then
|
||||
-- redstone
|
||||
unit, rs_in_q = svrs_redstone.new(self.id, i, unit_advert, self.out_q)
|
||||
elseif u_type == RTU_UNIT_TYPES.BOILER then
|
||||
|
@ -90,25 +90,31 @@ function redstone.new(session_id, unit_id, advert, out_queue)
|
||||
-- setup I/O
|
||||
for i = 1, #advert.rsio do
|
||||
local channel = advert.rsio[i]
|
||||
local mode = rsio.get_io_mode(channel)
|
||||
|
||||
if mode == IO_MODE.DIGITAL_IN then
|
||||
self.has_di = true
|
||||
table.insert(self.io_list.digital_in, channel)
|
||||
elseif mode == IO_MODE.DIGITAL_OUT then
|
||||
table.insert(self.io_list.digital_out, channel)
|
||||
elseif mode == IO_MODE.ANALOG_IN then
|
||||
self.has_ai = true
|
||||
table.insert(self.io_list.analog_in, channel)
|
||||
elseif mode == IO_MODE.ANALOG_OUT then
|
||||
table.insert(self.io_list.analog_out, channel)
|
||||
if rsio.is_valid_channel(channel) then
|
||||
local mode = rsio.get_io_mode(channel)
|
||||
|
||||
if mode == IO_MODE.DIGITAL_IN then
|
||||
self.has_di = true
|
||||
table.insert(self.io_list.digital_in, channel)
|
||||
elseif mode == IO_MODE.DIGITAL_OUT then
|
||||
table.insert(self.io_list.digital_out, channel)
|
||||
elseif mode == IO_MODE.ANALOG_IN then
|
||||
self.has_ai = true
|
||||
table.insert(self.io_list.analog_in, channel)
|
||||
elseif mode == IO_MODE.ANALOG_OUT then
|
||||
table.insert(self.io_list.analog_out, channel)
|
||||
else
|
||||
-- should be unreachable code, we already validated channels
|
||||
log.error(util.c(log_tag, "failed to identify advertisement channel IO mode (", channel, ")"), true)
|
||||
return nil
|
||||
end
|
||||
|
||||
self.db[channel] = IO_LVL.LOW
|
||||
else
|
||||
-- should be unreachable code, we already validated channels
|
||||
log.error(util.c(log_tag, "failed to identify advertisement channel IO mode (", channel, ")"), true)
|
||||
log.error(util.c(log_tag, "invalid advertisement channel (", channel, ")"), true)
|
||||
return nil
|
||||
end
|
||||
|
||||
self.db[channel] = IO_LVL.LOW
|
||||
end
|
||||
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
@ -13,7 +13,7 @@ local svsessions = require("supervisor.session.svsessions")
|
||||
local config = require("supervisor.config")
|
||||
local supervisor = require("supervisor.supervisor")
|
||||
|
||||
local SUPERVISOR_VERSION = "beta-v0.4.13"
|
||||
local SUPERVISOR_VERSION = "beta-v0.4.14"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
|
Loading…
Reference in New Issue
Block a user