#23 device version reporting

This commit is contained in:
Mikayla Fischler 2022-05-19 10:21:04 -04:00
parent dd553125d6
commit 6a168c884d
7 changed files with 37 additions and 21 deletions

View File

@ -278,15 +278,17 @@ end
-- Reactor PLC Communications
---@param id integer
---@param version string
---@param modem table
---@param local_port integer
---@param server_port integer
---@param reactor table
---@param rps rps
---@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 = {
id = id,
version = version,
seq_num = 0,
r_seq_num = nil,
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
public.send_link_req = function ()
_send(RPLC_TYPES.LINK_REQ, { self.id })
_send(RPLC_TYPES.LINK_REQ, { self.id, self.version })
end
-- send live status information

View File

@ -13,7 +13,7 @@ local config = require("reactor-plc.config")
local plc = require("reactor-plc.plc")
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 println = util.println
@ -117,7 +117,8 @@ local init = function ()
log.debug("init> conn watchdog started")
-- 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")
else
println("boot> starting in offline mode");

View File

@ -161,12 +161,14 @@ rtu.init_unit = function ()
end
-- RTU Communications
---@param version string
---@param modem table
---@param local_port integer
---@param server_port integer
---@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 = {
version = version,
seq_num = 0,
r_seq_num = nil,
txn_id = 0,
@ -249,7 +251,7 @@ rtu.comms = function (modem, local_port, server_port, conn_watchdog)
-- send capability advertisement
---@param units table
public.send_advertisement = function (units)
local advertisement = {}
local advertisement = { self.version }
for i = 1, #units do
local unit = units[i] --@type rtu_unit_registry_entry

View File

@ -24,7 +24,7 @@ local imatrix_rtu = require("rtu.dev.imatrix_rtu")
local turbine_rtu = require("rtu.dev.turbine_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
@ -264,7 +264,7 @@ smem_sys.conn_watchdog = util.new_watchdog(5)
log.debug("boot> conn watchdog started")
-- 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")
-- init threads

View File

@ -196,13 +196,15 @@ end
---@param local_port integer
---@param remote_port integer
---@param for_reactor integer
---@param version string
---@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
---@class plc_session_struct
local plc_s = {
open = true,
reactor = for_reactor,
version = version,
l_port = local_port,
r_port = remote_port,
in_queue = mqueue.new(),
@ -231,9 +233,13 @@ end
---@param advertisement table
---@return integer session_id
svsessions.establish_rtu_session = function (local_port, remote_port, advertisement)
-- pull version from advertisement
local version = table.remove(advertisement, 1)
---@class rtu_session_struct
local rtu_s = {
open = true,
version = version,
l_port = local_port,
r_port = remote_port,
in_queue = mqueue.new(),

View File

@ -38,7 +38,7 @@ if modem == nil then
end
-- 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)
local MAIN_CLOCK = 0.15

View File

@ -20,12 +20,14 @@ local print_ts = util.print_ts
local println_ts = util.println_ts
-- supervisory controller communications
---@param version string
---@param num_reactors integer
---@param modem table
---@param dev_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 = {
version = version,
num_reactors = num_reactors,
modem = modem,
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?
if packet.type == RPLC_TYPES.LINK_REQ then
if packet.length == 1 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])
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("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("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)
_send_plc_linking(next_seq_id, r_port, { RPLC_LINKING.ALLOW })
end
@ -210,18 +212,21 @@ supervisor.comms = function (num_reactors, modem, dev_listen, coord_listen)
if session ~= nil then
-- pass the packet onto the session handler
session.in_queue.push_packet(packet)
else
-- is this an RTU advertisement?
if packet.type == SCADA_MGMT_TYPES.RTU_ADVERT then
local rtu_id = svsessions.establish_rtu_session(l_port, r_port, packet.data)
elseif packet.type == SCADA_MGMT_TYPES.RTU_ADVERT then
if packet.length >= 1 then
-- this is an RTU advertisement for a new session
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)
_send_remote_linked(packet.scada_frame.seq_num() + 1, r_port)
else
-- any other packet should be session related, discard it
log.debug("discarding SCADA_MGMT packet without a known session")
log.debug("RTU_ADVERT: advertisement packet empty")
end
else
-- any other packet should be session related, discard it
log.debug("discarding SCADA_MGMT packet without a known session")
end
else
log.debug("illegal packet type " .. protocol .. " on device listening channel")