#51 usage of nic.receive and some cleanup

This commit is contained in:
Mikayla Fischler 2023-06-23 14:12:41 -04:00
parent ffac6996ed
commit 9073009eb0
4 changed files with 18 additions and 18 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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<br>
-- 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()