#93, #94, unit commands and range/type checks on unit IDs on PLC/RTU connections

This commit is contained in:
Mikayla Fischler
2022-10-06 13:54:52 -04:00
parent c02479b52e
commit 62ac993dae
8 changed files with 155 additions and 79 deletions

View File

@@ -198,19 +198,25 @@ function supervisor.comms(version, num_reactors, cooling_conf, modem, dev_listen
if packet.type == RPLC_TYPES.LINK_REQ then
if packet.length == 2 then
-- this is a linking request
local plc_id = svsessions.establish_plc_session(l_port, r_port, packet.data[1], packet.data[2])
if plc_id == false then
-- reactor already has a PLC assigned
log.debug(util.c("PLC_LNK: assignment collision with reactor ", packet.data[1]))
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.COLLISION })
if type(packet.data[1]) == "number" and type(packet.data[2]) == "string" then
local plc_id = svsessions.establish_plc_session(l_port, r_port, packet.data[1], packet.data[2])
if plc_id == false then
-- reactor already has a PLC assigned
log.debug(util.c("PLC_LNK: assignment collision with reactor ", packet.data[1]))
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.COLLISION })
else
-- got an ID; assigned to a reactor successfully
println(util.c("connected to reactor ", packet.data[1], " PLC (", packet.data[2], ") [:", r_port, "]"))
log.debug("PLC_LNK: allowed for device at " .. r_port)
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.ALLOW })
end
else
-- got an ID; assigned to a reactor successfully
println(util.c("connected to reactor ", packet.data[1], " PLC (", packet.data[2], ") [:", r_port, "]"))
log.debug("PLC_LNK: allowed for device at " .. r_port)
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.ALLOW })
log.debug("PLC_LNK: bad parameter types")
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.DENY })
end
else
log.debug("PLC_LNK: new linking packet length mismatch")
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.DENY })
end
else
-- force a re-link
@@ -267,7 +273,7 @@ function supervisor.comms(version, num_reactors, cooling_conf, modem, dev_listen
elseif packet.type == SCADA_CRDN_TYPES.ESTABLISH then
if packet.length == 1 then
-- this is an attempt to establish a new session
println(util.c("connected to coordinator [:", r_port, "]"))
println(util.c("connected to coordinator (", packet.data[1], ") [:", r_port, "]"))
svsessions.establish_coord_session(l_port, r_port, packet.data[1])