diff --git a/coordinator/coordinator.lua b/coordinator/coordinator.lua index 59661da..53fda6f 100644 --- a/coordinator/coordinator.lua +++ b/coordinator/coordinator.lua @@ -390,13 +390,10 @@ function coordinator.comms(version, nic, crd_channel, svr_channel, pkt_channel, ---@param distance integer ---@return mgmt_frame|crdn_frame|capi_frame|nil packet function public.parse_packet(side, sender, reply_to, message, distance) + local s_pkt = nic.receive(side, sender, reply_to, message, distance) local pkt = nil - local s_pkt = comms.scada_packet() - -- parse packet as generic SCADA packet - s_pkt.receive(side, sender, reply_to, message, distance) - - if s_pkt.is_valid() then + if s_pkt then -- get as SCADA management packet if s_pkt.protocol() == PROTOCOL.SCADA_MGMT then local mgmt_pkt = comms.mgmt_packet() diff --git a/pocket/pocket.lua b/pocket/pocket.lua index c0b5f77..b0432cf 100644 --- a/pocket/pocket.lua +++ b/pocket/pocket.lua @@ -178,13 +178,10 @@ function pocket.comms(version, nic, pkt_channel, svr_channel, crd_channel, range ---@param distance integer ---@return mgmt_frame|capi_frame|nil packet function public.parse_packet(side, sender, reply_to, message, distance) + local s_pkt = nic.receive(side, sender, reply_to, message, distance) local pkt = nil - local s_pkt = comms.scada_packet() - -- parse packet as generic SCADA packet - s_pkt.receive(side, sender, reply_to, message, distance) - - if s_pkt.is_valid() then + if s_pkt then -- get as SCADA management packet if s_pkt.protocol() == PROTOCOL.SCADA_MGMT then local mgmt_pkt = comms.mgmt_packet() diff --git a/reactor-plc/plc.lua b/reactor-plc/plc.lua index d2991ae..2bba4ee 100644 --- a/reactor-plc/plc.lua +++ b/reactor-plc/plc.lua @@ -732,10 +732,10 @@ function plc.comms(id, version, nic, plc_channel, svr_channel, range, reactor, r ---@param distance integer ---@return rplc_frame|mgmt_frame|nil packet function public.parse_packet(side, sender, reply_to, message, distance) - local pkt = nil local s_pkt = nic.receive(side, sender, reply_to, message, distance) + local pkt = nil - if s_pkt and s_pkt.is_valid() then + if s_pkt then -- get as RPLC packet if s_pkt.protocol() == PROTOCOL.RPLC then local rplc_pkt = comms.rplc_packet() diff --git a/scada-common/network.lua b/scada-common/network.lua index fbc4750..3469413 100644 --- a/scada-common/network.lua +++ b/scada-common/network.lua @@ -73,7 +73,7 @@ end ---@param modem table modem to use function network.nic(modem) local self = { - connected = (modem ~= nil), + connected = true, channels = {} } @@ -92,6 +92,10 @@ function network.nic(modem) ---@field callRemote function local public = {} + -- check if this NIC has a connected modem + ---@nodiscard + function public.connected() return self.connected end + -- connect to a modem peripheral ---@param reconnected_modem table function public.connect(reconnected_modem) @@ -112,18 +116,17 @@ function network.nic(modem) -- flag this NIC as no longer having a connected modem (usually do to peripheral disconnect) function public.disconnect() self.connected = false end - -- check if this NIC has a connected modem - ---@nodiscard - function public.connected() return self.connected end - -- check if a peripheral is this modem ---@nodiscard ---@param device table function public.is_modem(device) return device == modem end - -- wrap modem functions, then create custom transmit + -- wrap modem functions, then create custom functions public.connect(modem) + -- open a channel on the modem
+ -- if disconnected *after* opening, previousy opened channels will be re-opened on reconnection + ---@param channel integer function public.open(channel) if self.connected then modem.open(channel) @@ -142,6 +145,8 @@ function network.nic(modem) end end + -- close a channel on the modem + ---@param channel integer function public.close(channel) if self.connected then modem.close(channel) @@ -154,6 +159,7 @@ function network.nic(modem) end end + -- close all channels on the modem function public.closeAll() if self.connected then modem.closeAll()