#100 work in progress on command acks for reactive buttons

This commit is contained in:
Mikayla Fischler
2022-10-20 12:22:03 -04:00
parent bfa87815fa
commit ab757e14a7
8 changed files with 118 additions and 52 deletions

View File

@@ -182,26 +182,29 @@ function coordinator.new_session(id, in_queue, out_queue, facility_units)
elseif pkt.type == SCADA_CRDN_TYPES.COMMAND_UNIT then
if pkt.length >= 2 then
-- get command and unit id
local uid = pkt.data[1]
local cmd = pkt.data[2]
local cmd = pkt.data[1]
local uid = pkt.data[2]
-- pkt.data[3] will be nil except for some commands
local data = { uid, pkt.data[3] }
-- continue if valid unit id
if util.is_int(uid) and uid > 0 and uid <= #self.units then
if cmd == CRDN_COMMANDS.START then
self.out_q.push_data(SV_Q_DATA.START, uid)
self.out_q.push_data(SV_Q_DATA.START, data)
elseif cmd == CRDN_COMMANDS.SCRAM then
self.out_q.push_data(SV_Q_DATA.SCRAM, uid)
self.out_q.push_data(SV_Q_DATA.SCRAM, data)
elseif cmd == CRDN_COMMANDS.RESET_RPS then
self.out_q.push_data(SV_Q_DATA.RESET_RPS, uid)
self.out_q.push_data(SV_Q_DATA.RESET_RPS, data)
elseif cmd == CRDN_COMMANDS.SET_BURN then
if pkt.length == 3 then
self.out_q.push_data(SV_Q_DATA.SET_BURN, { uid, pkt.data[3] })
self.out_q.push_data(SV_Q_DATA.SET_BURN, data)
else
log.debug(log_header .. "CRDN command unit burn rate missing option")
end
elseif cmd == CRDN_COMMANDS.SET_WASTE then
if pkt.length == 3 then
self.out_q.push_data(SV_Q_DATA.SET_WASTE, { uid, pkt.data[3] })
self.out_q.push_data(SV_Q_DATA.SET_WASTE, data)
else
log.debug(log_header .. "CRDN command unit set waste missing option")
end

View File

@@ -11,6 +11,8 @@ local PROTOCOLS = comms.PROTOCOLS
local RPLC_TYPES = comms.RPLC_TYPES
local SCADA_MGMT_TYPES = comms.SCADA_MGMT_TYPES
local CRDN_COMMANDS = comms.CRDN_COMMANDS
local print = util.print
local println = util.println
local print_ts = util.print_ts
@@ -336,6 +338,13 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
elseif ack == false then
log.debug(log_header .. "burn rate update failed!")
end
-- send acknowledgement to coordinator
self.out_q.push_data(svqtypes.SV_Q_DATA.CRDN_ACK, {
unit = self.for_reactor,
cmd = CRDN_COMMANDS.SET_BURN,
ack = ack
})
elseif pkt.type == RPLC_TYPES.RPS_ENABLE then
-- enable acknowledgement
local ack = _get_ack(pkt)
@@ -345,6 +354,13 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
elseif ack == false then
log.debug(log_header .. "enable failed!")
end
-- send acknowledgement to coordinator
self.out_q.push_data(svqtypes.SV_Q_DATA.CRDN_ACK, {
unit = self.for_reactor,
cmd = CRDN_COMMANDS.START,
ack = ack
})
elseif pkt.type == RPLC_TYPES.RPS_SCRAM then
-- SCRAM acknowledgement
local ack = _get_ack(pkt)
@@ -354,6 +370,13 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
elseif ack == false then
log.debug(log_header .. "SCRAM failed!")
end
-- send acknowledgement to coordinator
self.out_q.push_data(svqtypes.SV_Q_DATA.CRDN_ACK, {
unit = self.for_reactor,
cmd = CRDN_COMMANDS.SCRAM,
ack = ack
})
elseif pkt.type == RPLC_TYPES.RPS_STATUS then
-- RPS status packet received, copy data
if pkt.length == 9 then
@@ -392,6 +415,13 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
elseif ack == false then
log.debug(log_header .. "RPS reset failed")
end
-- send acknowledgement to coordinator
self.out_q.push_data(svqtypes.SV_Q_DATA.CRDN_ACK, {
unit = self.for_reactor,
cmd = CRDN_COMMANDS.RESET_RPS,
ack = ack
})
else
log.debug(log_header .. "handler received unsupported RPLC packet type " .. pkt.type)
end

View File

@@ -9,7 +9,9 @@ local SV_Q_DATA = {
SCRAM = 2,
RESET_RPS = 3,
SET_BURN = 4,
SET_WASTE = 5
SET_WASTE = 5,
__END_PLC_CMDS__ = 6,
CRDN_ACK = 7
}
svqtypes.SV_Q_CMDS = SV_Q_CMDS

View File

@@ -70,25 +70,30 @@ local function _sv_handle_outq(session)
elseif msg.qtype == mqueue.TYPE.DATA then
-- instruction/notification with body
local cmd = msg.message ---@type queue_data
local plc_s = nil
if type(cmd.val) == "table" then
plc_s = svsessions.get_reactor_session(cmd.val[1])
elseif type(cmd.val) == "number" then
plc_s = svsessions.get_reactor_session(cmd.val)
end
if cmd.key < SV_Q_DATA.__END_PLC_CMDS__ then
-- PLC commands from coordinator
local crdn_sid = session.instance.get_id()
local plc_s = svsessions.get_reactor_session(cmd.val[1])
if plc_s ~= nil then
if cmd.key == SV_Q_DATA.START then
plc_s.in_queue.push_command(PLC_S_CMDS.ENABLE)
elseif cmd.key == SV_Q_DATA.SCRAM then
plc_s.in_queue.push_command(PLC_S_CMDS.SCRAM)
elseif cmd.key == SV_Q_DATA.RESET_RPS then
plc_s.in_queue.push_command(PLC_S_CMDS.RPS_RESET)
elseif cmd.key == SV_Q_DATA.SET_BURN and type(cmd.val) == "table" and #cmd.val == 2 then
plc_s.in_queue.push_data(PLC_S_DATA.BURN_RATE, cmd.val[2])
elseif cmd.key == SV_Q_DATA.SET_WASTE and type(cmd.val) == "table" and #cmd.val == 2 then
---@todo set waste
if plc_s ~= nil then
if cmd.key == SV_Q_DATA.START then
plc_s.in_queue.push_command(PLC_S_CMDS.ENABLE)
elseif cmd.key == SV_Q_DATA.SCRAM then
plc_s.in_queue.push_command(PLC_S_CMDS.SCRAM)
elseif cmd.key == SV_Q_DATA.RESET_RPS then
plc_s.in_queue.push_command(PLC_S_CMDS.RPS_RESET)
elseif cmd.key == SV_Q_DATA.SET_BURN and type(cmd.val) == "table" and #cmd.val == 2 then
plc_s.in_queue.push_data(PLC_S_DATA.BURN_RATE, cmd.val[2])
elseif cmd.key == SV_Q_DATA.SET_WASTE and type(cmd.val) == "table" and #cmd.val == 2 then
---@todo set waste
else
log.debug(util.c("unknown PLC SV queue command ", cmd.key))
end
end
else
if cmd.key == SV_Q_DATA.CRDN_ACK then
---@todo ack to be sent to coordinator
end
end
end
@@ -279,7 +284,7 @@ function svsessions.establish_plc_session(local_port, remote_port, for_reactor,
r_port = remote_port,
in_queue = mqueue.new(),
out_queue = mqueue.new(),
instance = nil
instance = nil ---@type plc_session
}
plc_s.instance = plc.new_session(self.next_plc_id, for_reactor, plc_s.in_queue, plc_s.out_queue)
@@ -317,7 +322,7 @@ function svsessions.establish_rtu_session(local_port, remote_port, advertisement
r_port = remote_port,
in_queue = mqueue.new(),
out_queue = mqueue.new(),
instance = nil
instance = nil ---@type rtu_session
}
rtu_s.instance = rtu.new_session(self.next_rtu_id, rtu_s.in_queue, rtu_s.out_queue, advertisement, self.facility_units)
@@ -346,7 +351,7 @@ function svsessions.establish_coord_session(local_port, remote_port, version)
r_port = remote_port,
in_queue = mqueue.new(),
out_queue = mqueue.new(),
instance = nil
instance = nil ---@type coord_session
}
coord_s.instance = coordinator.new_session(self.next_coord_id, coord_s.in_queue, coord_s.out_queue, self.facility_units)