mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
RTU linking and requesting advertisement
This commit is contained in:
@ -179,11 +179,15 @@ while true do
|
|||||||
end
|
end
|
||||||
elseif event == "modem_message" then
|
elseif event == "modem_message" then
|
||||||
-- got a packet
|
-- got a packet
|
||||||
|
local link_ref = { linked = linked }
|
||||||
local packet = rtu_comms.parse_packet(p1, p2, p3, p4, p5)
|
local packet = rtu_comms.parse_packet(p1, p2, p3, p4, p5)
|
||||||
rtu_comms.handle_packet(packet)
|
|
||||||
|
|
||||||
|
rtu_comms.handle_packet(packet, units, link_ref)
|
||||||
|
|
||||||
|
-- if linked, stop sending advertisements
|
||||||
|
linked = link_ref.linked
|
||||||
elseif event == "terminate" then
|
elseif event == "terminate" then
|
||||||
|
print_ts("Exiting...\n")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,8 +34,9 @@ RPLC_LINKING = {
|
|||||||
SCADA_MGMT_TYPES = {
|
SCADA_MGMT_TYPES = {
|
||||||
PING = 0, -- generic ping
|
PING = 0, -- generic ping
|
||||||
SV_HEARTBEAT = 1, -- supervisor heartbeat
|
SV_HEARTBEAT = 1, -- supervisor heartbeat
|
||||||
RTU_HEARTBEAT = 2, -- RTU heartbeat
|
REMOTE_LINKED = 2, -- remote device linked
|
||||||
RTU_ADVERT = 3 -- RTU capability advertisement
|
RTU_ADVERT = 3, -- RTU capability advertisement
|
||||||
|
RTU_HEARTBEAT = 4, -- RTU heartbeat
|
||||||
}
|
}
|
||||||
|
|
||||||
RTU_ADVERT_TYPES = {
|
RTU_ADVERT_TYPES = {
|
||||||
@ -203,7 +204,7 @@ function rtu_comms(modem, local_port, server_port)
|
|||||||
return pkt
|
return pkt
|
||||||
end
|
end
|
||||||
|
|
||||||
local handle_packet = function(packet, units)
|
local handle_packet = function(packet, units, ref)
|
||||||
if packet ~= nil then
|
if packet ~= nil then
|
||||||
local protocol = packet.scada_frame.protocol()
|
local protocol = packet.scada_frame.protocol()
|
||||||
|
|
||||||
@ -222,6 +223,16 @@ function rtu_comms(modem, local_port, server_port)
|
|||||||
end
|
end
|
||||||
elseif protocol == PROTOCOLS.SCADA_MGMT then
|
elseif protocol == PROTOCOLS.SCADA_MGMT then
|
||||||
-- SCADA management packet
|
-- SCADA management packet
|
||||||
|
if packet.type == SCADA_MGMT_TYPES.REMOTE_LINKED then
|
||||||
|
-- acknowledgement
|
||||||
|
ref.linked = true
|
||||||
|
elseif packet.type == SCADA_MGMT_TYPES.RTU_ADVERT then
|
||||||
|
-- request for capabilities again
|
||||||
|
send_advertisement(units)
|
||||||
|
else
|
||||||
|
-- not supported
|
||||||
|
log._warning("RTU got unexpected SCADA message type " .. packet.type, true)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
-- should be unreachable assuming packet is from parse_packet()
|
-- should be unreachable assuming packet is from parse_packet()
|
||||||
log._error("Illegal packet type " .. protocol, true)
|
log._error("Illegal packet type " .. protocol, true)
|
||||||
|
Reference in New Issue
Block a user