mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#23 device version reporting
This commit is contained in:
parent
dd553125d6
commit
6a168c884d
@ -278,15 +278,17 @@ end
|
|||||||
|
|
||||||
-- Reactor PLC Communications
|
-- Reactor PLC Communications
|
||||||
---@param id integer
|
---@param id integer
|
||||||
|
---@param version string
|
||||||
---@param modem table
|
---@param modem table
|
||||||
---@param local_port integer
|
---@param local_port integer
|
||||||
---@param server_port integer
|
---@param server_port integer
|
||||||
---@param reactor table
|
---@param reactor table
|
||||||
---@param rps rps
|
---@param rps rps
|
||||||
---@param conn_watchdog watchdog
|
---@param conn_watchdog watchdog
|
||||||
plc.comms = function (id, modem, local_port, server_port, reactor, rps, conn_watchdog)
|
plc.comms = function (id, version, modem, local_port, server_port, reactor, rps, conn_watchdog)
|
||||||
local self = {
|
local self = {
|
||||||
id = id,
|
id = id,
|
||||||
|
version = version,
|
||||||
seq_num = 0,
|
seq_num = 0,
|
||||||
r_seq_num = nil,
|
r_seq_num = nil,
|
||||||
modem = modem,
|
modem = modem,
|
||||||
@ -499,7 +501,7 @@ plc.comms = function (id, modem, local_port, server_port, reactor, rps, conn_wat
|
|||||||
|
|
||||||
-- attempt to establish link with supervisor
|
-- attempt to establish link with supervisor
|
||||||
public.send_link_req = function ()
|
public.send_link_req = function ()
|
||||||
_send(RPLC_TYPES.LINK_REQ, { self.id })
|
_send(RPLC_TYPES.LINK_REQ, { self.id, self.version })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- send live status information
|
-- send live status information
|
||||||
|
@ -13,7 +13,7 @@ local config = require("reactor-plc.config")
|
|||||||
local plc = require("reactor-plc.plc")
|
local plc = require("reactor-plc.plc")
|
||||||
local threads = require("reactor-plc.threads")
|
local threads = require("reactor-plc.threads")
|
||||||
|
|
||||||
local R_PLC_VERSION = "alpha-v0.6.7"
|
local R_PLC_VERSION = "alpha-v0.6.8"
|
||||||
|
|
||||||
local print = util.print
|
local print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
@ -117,7 +117,8 @@ local init = function ()
|
|||||||
log.debug("init> conn watchdog started")
|
log.debug("init> conn watchdog started")
|
||||||
|
|
||||||
-- start comms
|
-- start comms
|
||||||
smem_sys.plc_comms = plc.comms(config.REACTOR_ID, smem_dev.modem, config.LISTEN_PORT, config.SERVER_PORT, smem_dev.reactor, smem_sys.rps, smem_sys.conn_watchdog)
|
smem_sys.plc_comms = plc.comms(config.REACTOR_ID, R_PLC_VERSION, smem_dev.modem, config.LISTEN_PORT, config.SERVER_PORT,
|
||||||
|
smem_dev.reactor, smem_sys.rps, smem_sys.conn_watchdog)
|
||||||
log.debug("init> comms init")
|
log.debug("init> comms init")
|
||||||
else
|
else
|
||||||
println("boot> starting in offline mode");
|
println("boot> starting in offline mode");
|
||||||
|
@ -161,12 +161,14 @@ rtu.init_unit = function ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- RTU Communications
|
-- RTU Communications
|
||||||
|
---@param version string
|
||||||
---@param modem table
|
---@param modem table
|
||||||
---@param local_port integer
|
---@param local_port integer
|
||||||
---@param server_port integer
|
---@param server_port integer
|
||||||
---@param conn_watchdog watchdog
|
---@param conn_watchdog watchdog
|
||||||
rtu.comms = function (modem, local_port, server_port, conn_watchdog)
|
rtu.comms = function (version, modem, local_port, server_port, conn_watchdog)
|
||||||
local self = {
|
local self = {
|
||||||
|
version = version,
|
||||||
seq_num = 0,
|
seq_num = 0,
|
||||||
r_seq_num = nil,
|
r_seq_num = nil,
|
||||||
txn_id = 0,
|
txn_id = 0,
|
||||||
@ -249,7 +251,7 @@ rtu.comms = function (modem, local_port, server_port, conn_watchdog)
|
|||||||
-- send capability advertisement
|
-- send capability advertisement
|
||||||
---@param units table
|
---@param units table
|
||||||
public.send_advertisement = function (units)
|
public.send_advertisement = function (units)
|
||||||
local advertisement = {}
|
local advertisement = { self.version }
|
||||||
|
|
||||||
for i = 1, #units do
|
for i = 1, #units do
|
||||||
local unit = units[i] --@type rtu_unit_registry_entry
|
local unit = units[i] --@type rtu_unit_registry_entry
|
||||||
|
@ -24,7 +24,7 @@ local imatrix_rtu = require("rtu.dev.imatrix_rtu")
|
|||||||
local turbine_rtu = require("rtu.dev.turbine_rtu")
|
local turbine_rtu = require("rtu.dev.turbine_rtu")
|
||||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||||
|
|
||||||
local RTU_VERSION = "alpha-v0.6.6"
|
local RTU_VERSION = "alpha-v0.6.7"
|
||||||
|
|
||||||
local rtu_t = types.rtu_t
|
local rtu_t = types.rtu_t
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ smem_sys.conn_watchdog = util.new_watchdog(5)
|
|||||||
log.debug("boot> conn watchdog started")
|
log.debug("boot> conn watchdog started")
|
||||||
|
|
||||||
-- setup comms
|
-- setup comms
|
||||||
smem_sys.rtu_comms = rtu.comms(smem_dev.modem, config.LISTEN_PORT, config.SERVER_PORT, smem_sys.conn_watchdog)
|
smem_sys.rtu_comms = rtu.comms(RTU_VERSION, smem_dev.modem, config.LISTEN_PORT, config.SERVER_PORT, smem_sys.conn_watchdog)
|
||||||
log.debug("boot> comms init")
|
log.debug("boot> comms init")
|
||||||
|
|
||||||
-- init threads
|
-- init threads
|
||||||
|
@ -196,13 +196,15 @@ end
|
|||||||
---@param local_port integer
|
---@param local_port integer
|
||||||
---@param remote_port integer
|
---@param remote_port integer
|
||||||
---@param for_reactor integer
|
---@param for_reactor integer
|
||||||
|
---@param version string
|
||||||
---@return integer|false session_id
|
---@return integer|false session_id
|
||||||
svsessions.establish_plc_session = function (local_port, remote_port, for_reactor)
|
svsessions.establish_plc_session = function (local_port, remote_port, for_reactor, version)
|
||||||
if svsessions.get_reactor_session(for_reactor) == nil then
|
if svsessions.get_reactor_session(for_reactor) == nil then
|
||||||
---@class plc_session_struct
|
---@class plc_session_struct
|
||||||
local plc_s = {
|
local plc_s = {
|
||||||
open = true,
|
open = true,
|
||||||
reactor = for_reactor,
|
reactor = for_reactor,
|
||||||
|
version = version,
|
||||||
l_port = local_port,
|
l_port = local_port,
|
||||||
r_port = remote_port,
|
r_port = remote_port,
|
||||||
in_queue = mqueue.new(),
|
in_queue = mqueue.new(),
|
||||||
@ -231,9 +233,13 @@ end
|
|||||||
---@param advertisement table
|
---@param advertisement table
|
||||||
---@return integer session_id
|
---@return integer session_id
|
||||||
svsessions.establish_rtu_session = function (local_port, remote_port, advertisement)
|
svsessions.establish_rtu_session = function (local_port, remote_port, advertisement)
|
||||||
|
-- pull version from advertisement
|
||||||
|
local version = table.remove(advertisement, 1)
|
||||||
|
|
||||||
---@class rtu_session_struct
|
---@class rtu_session_struct
|
||||||
local rtu_s = {
|
local rtu_s = {
|
||||||
open = true,
|
open = true,
|
||||||
|
version = version,
|
||||||
l_port = local_port,
|
l_port = local_port,
|
||||||
r_port = remote_port,
|
r_port = remote_port,
|
||||||
in_queue = mqueue.new(),
|
in_queue = mqueue.new(),
|
||||||
|
@ -38,7 +38,7 @@ if modem == nil then
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- start comms, open all channels
|
-- start comms, open all channels
|
||||||
local superv_comms = supervisor.comms(config.NUM_REACTORS, modem, config.SCADA_DEV_LISTEN, config.SCADA_SV_LISTEN)
|
local superv_comms = supervisor.comms(SUPERVISOR_VERSION, config.NUM_REACTORS, modem, config.SCADA_DEV_LISTEN, config.SCADA_SV_LISTEN)
|
||||||
|
|
||||||
-- base loop clock (6.67Hz, 3 ticks)
|
-- base loop clock (6.67Hz, 3 ticks)
|
||||||
local MAIN_CLOCK = 0.15
|
local MAIN_CLOCK = 0.15
|
||||||
|
@ -20,12 +20,14 @@ local print_ts = util.print_ts
|
|||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
|
|
||||||
-- supervisory controller communications
|
-- supervisory controller communications
|
||||||
|
---@param version string
|
||||||
---@param num_reactors integer
|
---@param num_reactors integer
|
||||||
---@param modem table
|
---@param modem table
|
||||||
---@param dev_listen integer
|
---@param dev_listen integer
|
||||||
---@param coord_listen integer
|
---@param coord_listen integer
|
||||||
supervisor.comms = function (num_reactors, modem, dev_listen, coord_listen)
|
supervisor.comms = function (version, num_reactors, modem, dev_listen, coord_listen)
|
||||||
local self = {
|
local self = {
|
||||||
|
version = version,
|
||||||
num_reactors = num_reactors,
|
num_reactors = num_reactors,
|
||||||
modem = modem,
|
modem = modem,
|
||||||
dev_listen = dev_listen,
|
dev_listen = dev_listen,
|
||||||
@ -180,16 +182,16 @@ supervisor.comms = function (num_reactors, modem, dev_listen, coord_listen)
|
|||||||
|
|
||||||
-- unknown session, is this a linking request?
|
-- unknown session, is this a linking request?
|
||||||
if packet.type == RPLC_TYPES.LINK_REQ then
|
if packet.type == RPLC_TYPES.LINK_REQ then
|
||||||
if packet.length == 1 then
|
if packet.length == 2 then
|
||||||
-- this is a linking request
|
-- this is a linking request
|
||||||
local plc_id = svsessions.establish_plc_session(l_port, r_port, packet.data[1])
|
local plc_id = svsessions.establish_plc_session(l_port, r_port, packet.data[1], packet.data[2])
|
||||||
if plc_id == false then
|
if plc_id == false then
|
||||||
-- reactor already has a PLC assigned
|
-- reactor already has a PLC assigned
|
||||||
log.debug("PLC_LNK: assignment collision with reactor " .. packet.data[1])
|
log.debug("PLC_LNK: assignment collision with reactor " .. packet.data[1])
|
||||||
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.COLLISION })
|
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.COLLISION })
|
||||||
else
|
else
|
||||||
-- got an ID; assigned to a reactor successfully
|
-- got an ID; assigned to a reactor successfully
|
||||||
println("connected to reactor " .. packet.data[1] .. " PLC (port " .. r_port .. ")")
|
println("connected to reactor " .. packet.data[1] .. " PLC v " .. packet.data[2] .. " (port " .. r_port .. ")")
|
||||||
log.debug("PLC_LNK: allowed for device at " .. r_port)
|
log.debug("PLC_LNK: allowed for device at " .. r_port)
|
||||||
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.ALLOW })
|
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.ALLOW })
|
||||||
end
|
end
|
||||||
@ -210,19 +212,22 @@ supervisor.comms = function (num_reactors, modem, dev_listen, coord_listen)
|
|||||||
if session ~= nil then
|
if session ~= nil then
|
||||||
-- pass the packet onto the session handler
|
-- pass the packet onto the session handler
|
||||||
session.in_queue.push_packet(packet)
|
session.in_queue.push_packet(packet)
|
||||||
else
|
elseif packet.type == SCADA_MGMT_TYPES.RTU_ADVERT then
|
||||||
-- is this an RTU advertisement?
|
if packet.length >= 1 then
|
||||||
if packet.type == SCADA_MGMT_TYPES.RTU_ADVERT then
|
-- this is an RTU advertisement for a new session
|
||||||
local rtu_id = svsessions.establish_rtu_session(l_port, r_port, packet.data)
|
println("connected to RTU v " .. packet.data[1] .. " (port " .. r_port .. ")")
|
||||||
|
|
||||||
|
svsessions.establish_rtu_session(l_port, r_port, packet.data)
|
||||||
|
|
||||||
println("connected to RTU (port " .. r_port .. ")")
|
|
||||||
log.debug("RTU_ADVERT: linked " .. r_port)
|
log.debug("RTU_ADVERT: linked " .. r_port)
|
||||||
_send_remote_linked(packet.scada_frame.seq_num() + 1, r_port)
|
_send_remote_linked(packet.scada_frame.seq_num() + 1, r_port)
|
||||||
|
else
|
||||||
|
log.debug("RTU_ADVERT: advertisement packet empty")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
-- any other packet should be session related, discard it
|
-- any other packet should be session related, discard it
|
||||||
log.debug("discarding SCADA_MGMT packet without a known session")
|
log.debug("discarding SCADA_MGMT packet without a known session")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
else
|
else
|
||||||
log.debug("illegal packet type " .. protocol .. " on device listening channel")
|
log.debug("illegal packet type " .. protocol .. " on device listening channel")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user