#51 nic integration with rtu and supervisor
This commit is contained in:
@@ -34,7 +34,7 @@ local SESSION_TYPE = {
|
||||
svsessions.SESSION_TYPE = SESSION_TYPE
|
||||
|
||||
local self = {
|
||||
modem = nil, ---@type table|nil
|
||||
nic = nil, ---@type nic|nil
|
||||
fp_ok = false,
|
||||
num_reactors = 0,
|
||||
facility = nil, ---@type facility|nil
|
||||
@@ -60,7 +60,7 @@ local function _sv_handle_outq(session)
|
||||
if msg ~= nil then
|
||||
if msg.qtype == mqueue.TYPE.PACKET then
|
||||
-- handle a packet to be sent
|
||||
self.modem.transmit(session.r_chan, config.SVR_CHANNEL, msg.message.raw_sendable())
|
||||
self.nic.transmit(session.r_chan, config.SVR_CHANNEL, msg.message)
|
||||
elseif msg.qtype == mqueue.TYPE.COMMAND then
|
||||
-- handle instruction/notification
|
||||
elseif msg.qtype == mqueue.TYPE.DATA then
|
||||
@@ -135,7 +135,7 @@ local function _shutdown(session)
|
||||
while session.out_queue.ready() do
|
||||
local msg = session.out_queue.pop()
|
||||
if msg ~= nil and msg.qtype == mqueue.TYPE.PACKET then
|
||||
self.modem.transmit(session.r_chan, config.SVR_CHANNEL, msg.message.raw_sendable())
|
||||
self.nic.transmit(session.r_chan, config.SVR_CHANNEL, msg.message)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -195,23 +195,17 @@ end
|
||||
-- PUBLIC FUNCTIONS --
|
||||
|
||||
-- initialize svsessions
|
||||
---@param modem table modem device
|
||||
---@param nic nic network interface device
|
||||
---@param fp_ok boolean front panel active
|
||||
---@param num_reactors integer number of reactors
|
||||
---@param cooling_conf table cooling configuration definition
|
||||
function svsessions.init(modem, fp_ok, num_reactors, cooling_conf)
|
||||
self.modem = modem
|
||||
function svsessions.init(nic, fp_ok, num_reactors, cooling_conf)
|
||||
self.nic = nic
|
||||
self.fp_ok = fp_ok
|
||||
self.num_reactors = num_reactors
|
||||
self.facility = facility.new(num_reactors, cooling_conf)
|
||||
end
|
||||
|
||||
-- re-link the modem
|
||||
---@param modem table
|
||||
function svsessions.relink_modem(modem)
|
||||
self.modem = modem
|
||||
end
|
||||
|
||||
-- find an RTU session by the computer ID
|
||||
---@nodiscard
|
||||
---@param source_addr integer
|
||||
|
||||
@@ -7,6 +7,7 @@ require("/initenv").init_env()
|
||||
local crash = require("scada-common.crash")
|
||||
local comms = require("scada-common.comms")
|
||||
local log = require("scada-common.log")
|
||||
local network = require("scada-common.network")
|
||||
local ppm = require("scada-common.ppm")
|
||||
local tcd = require("scada-common.tcd")
|
||||
local util = require("scada-common.util")
|
||||
@@ -20,7 +21,7 @@ local supervisor = require("supervisor.supervisor")
|
||||
|
||||
local svsessions = require("supervisor.session.svsessions")
|
||||
|
||||
local SUPERVISOR_VERSION = "v0.17.10"
|
||||
local SUPERVISOR_VERSION = "v0.18.0"
|
||||
|
||||
local println = util.println
|
||||
local println_ts = util.println_ts
|
||||
@@ -115,8 +116,9 @@ local function main()
|
||||
println_ts = function (_) end
|
||||
end
|
||||
|
||||
-- start comms
|
||||
local superv_comms = supervisor.comms(SUPERVISOR_VERSION, modem, fp_ok)
|
||||
-- create network interface then setup comms
|
||||
local nic = network.nic(modem)
|
||||
local superv_comms = supervisor.comms(SUPERVISOR_VERSION, nic, fp_ok)
|
||||
|
||||
-- base loop clock (6.67Hz, 3 ticks)
|
||||
local MAIN_CLOCK = 0.15
|
||||
@@ -139,9 +141,12 @@ local function main()
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "modem" then
|
||||
-- we only care if this is our wireless modem
|
||||
if device == modem then
|
||||
if nic.is_modem(device) then
|
||||
nic.disconnect()
|
||||
|
||||
println_ts("wireless modem disconnected!")
|
||||
log.warning("comms modem disconnected")
|
||||
|
||||
databus.tx_hw_modem(false)
|
||||
else
|
||||
log.warning("non-comms modem disconnected")
|
||||
@@ -153,10 +158,9 @@ local function main()
|
||||
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "modem" then
|
||||
if device.isWireless() then
|
||||
if device.isWireless() and not nic.connected() then
|
||||
-- reconnected modem
|
||||
modem = device
|
||||
superv_comms.reconnect_modem(modem)
|
||||
nic.connect(device)
|
||||
|
||||
println_ts("wireless modem reconnected.")
|
||||
log.info("comms modem reconnected")
|
||||
|
||||
@@ -16,10 +16,10 @@ local SCADA_MGMT_TYPE = comms.SCADA_MGMT_TYPE
|
||||
-- supervisory controller communications
|
||||
---@nodiscard
|
||||
---@param _version string supervisor version
|
||||
---@param modem table modem device
|
||||
---@param nic nic network interface device
|
||||
---@param fp_ok boolean if the front panel UI is running
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
function supervisor.comms(_version, modem, fp_ok)
|
||||
function supervisor.comms(_version, nic, fp_ok)
|
||||
-- print a log message to the terminal as long as the UI isn't running
|
||||
local function println(message) if not fp_ok then util.println_ts(message) end end
|
||||
|
||||
@@ -43,15 +43,11 @@ function supervisor.comms(_version, modem, fp_ok)
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
||||
-- configure modem channels
|
||||
local function _conf_channels()
|
||||
modem.closeAll()
|
||||
modem.open(svr_channel)
|
||||
end
|
||||
|
||||
_conf_channels()
|
||||
nic.closeAll()
|
||||
nic.open(svr_channel)
|
||||
|
||||
-- pass modem, status, and config data to svsessions
|
||||
svsessions.init(modem, fp_ok, num_reactors, cooling_conf)
|
||||
svsessions.init(nic, fp_ok, num_reactors, cooling_conf)
|
||||
|
||||
-- send an establish request response
|
||||
---@param packet scada_packet
|
||||
@@ -64,7 +60,7 @@ function supervisor.comms(_version, modem, fp_ok)
|
||||
m_pkt.make(SCADA_MGMT_TYPE.ESTABLISH, { ack, data })
|
||||
s_pkt.make(packet.src_addr(), packet.seq_num() + 1, PROTOCOL.SCADA_MGMT, m_pkt.raw_sendable())
|
||||
|
||||
modem.transmit(packet.remote_channel(), svr_channel, s_pkt.raw_sendable())
|
||||
nic.transmit(packet.remote_channel(), svr_channel, s_pkt)
|
||||
self.last_est_acks[packet.src_addr()] = ack
|
||||
end
|
||||
|
||||
@@ -73,14 +69,6 @@ function supervisor.comms(_version, modem, fp_ok)
|
||||
---@class superv_comms
|
||||
local public = {}
|
||||
|
||||
-- reconnect a newly connected modem
|
||||
---@param new_modem table
|
||||
function public.reconnect_modem(new_modem)
|
||||
modem = new_modem
|
||||
svsessions.relink_modem(new_modem)
|
||||
_conf_channels()
|
||||
end
|
||||
|
||||
-- parse a packet
|
||||
---@nodiscard
|
||||
---@param side string
|
||||
|
||||
Reference in New Issue
Block a user