Compare commits
3 Commits
635-optimi
...
643-multi-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
983724f45f | ||
|
|
d43112bdeb | ||
|
|
4dabc3f0aa |
@@ -327,10 +327,10 @@ function facility.receive_sv(side, sender, reply_to, message, distance)
|
||||
local s_pkt = self.nic.receive(side, sender, reply_to, message, distance)
|
||||
|
||||
if s_pkt and s_pkt.protocol() == PROTOCOL.SCADA_MGMT then
|
||||
local pkt = comms.mgmt_packet().decode(s_pkt)
|
||||
if pkt then
|
||||
local mgmt_pkt = comms.mgmt_packet()
|
||||
if mgmt_pkt.decode(s_pkt) then
|
||||
tcd.abort(handle_timeout)
|
||||
handle_packet(pkt)
|
||||
handle_packet(mgmt_pkt.get())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -374,10 +374,18 @@ function coordinator.comms(version, nic, wl_nic, sv_watchdog)
|
||||
local pkt = nil
|
||||
|
||||
if s_pkt then
|
||||
-- get as SCADA management packet
|
||||
if s_pkt.protocol() == PROTOCOL.SCADA_MGMT then
|
||||
pkt = comms.mgmt_packet().decode(s_pkt)
|
||||
local mgmt_pkt = comms.mgmt_packet()
|
||||
if mgmt_pkt.decode(s_pkt) then
|
||||
pkt = mgmt_pkt.get()
|
||||
end
|
||||
-- get as coordinator packet
|
||||
elseif s_pkt.protocol() == PROTOCOL.SCADA_CRDN then
|
||||
pkt = comms.crdn_packet().decode(s_pkt)
|
||||
local crdn_pkt = comms.crdn_packet()
|
||||
if crdn_pkt.decode(s_pkt) then
|
||||
pkt = crdn_pkt.get()
|
||||
end
|
||||
else
|
||||
log.debug("attempted parse of illegal packet type " .. s_pkt.protocol(), true)
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ local renderer = require("coordinator.renderer")
|
||||
local sounder = require("coordinator.sounder")
|
||||
local threads = require("coordinator.threads")
|
||||
|
||||
local COORDINATOR_VERSION = "v1.7.1"
|
||||
local COORDINATOR_VERSION = "v1.7.0"
|
||||
|
||||
local CHUNK_LOAD_DELAY_S = 30.0
|
||||
|
||||
|
||||
@@ -626,13 +626,21 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
|
||||
---@return mgmt_frame|crdn_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
|
||||
|
||||
if s_pkt then
|
||||
-- get as SCADA management packet
|
||||
if s_pkt.protocol() == PROTOCOL.SCADA_MGMT then
|
||||
pkt = comms.mgmt_packet().decode(s_pkt)
|
||||
local mgmt_pkt = comms.mgmt_packet()
|
||||
if mgmt_pkt.decode(s_pkt) then
|
||||
pkt = mgmt_pkt.get()
|
||||
end
|
||||
-- get as coordinator packet
|
||||
elseif s_pkt.protocol() == PROTOCOL.SCADA_CRDN then
|
||||
pkt = comms.crdn_packet().decode(s_pkt)
|
||||
local crdn_pkt = comms.crdn_packet()
|
||||
if crdn_pkt.decode(s_pkt) then
|
||||
pkt = crdn_pkt.get()
|
||||
end
|
||||
else
|
||||
log.debug("attempted parse of illegal packet type " .. s_pkt.protocol(), true)
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ local pocket = require("pocket.pocket")
|
||||
local renderer = require("pocket.renderer")
|
||||
local threads = require("pocket.threads")
|
||||
|
||||
local POCKET_VERSION = "v1.0.5"
|
||||
local POCKET_VERSION = "v1.0.4"
|
||||
|
||||
local println = util.println
|
||||
local println_ts = util.println_ts
|
||||
|
||||
@@ -515,12 +515,13 @@ doc("fp_crd_rtt", "RTT", "Each connection has a round trip time, or RTT. Since t
|
||||
list(DOC_LIST_TYPE.BULLET, { "green: <=1000ms", "yellow: <=1500ms ", "red: >1500ms" })
|
||||
sect("CRD Tab")
|
||||
text("This tab includes information about the Coordinator, partially covered by 'Common Items'.")
|
||||
doc("fp_crd_spkr", "SPEAKER", "This indicates if the speaker is connected.")
|
||||
doc("fp_crd_rt_main", "RT MAIN", "This indicates that the device's main loop co-routine is running.")
|
||||
doc("fp_crd_rt_render", "RT RENDER", "This indicates that the Coordinator graphics renderer co-routine is running.")
|
||||
doc("fp_crd_mon_main", "MAIN MONITOR", "The connection status of the main display monitor.")
|
||||
doc("fp_crd_mon_flow", "FLOW MONITOR", "The connection status of the coolant and waste flow display monitor.")
|
||||
doc("fp_crd_mon_unit", "UNIT X MONITOR", "The connection status of the monitor associated with a given unit.")
|
||||
doc("fp_crd_spkr", "SPEAKER", "This indicates if the speaker is connected.")
|
||||
list(DOC_LIST_TYPE.LED, { "Disconnected", "Display View Unloaded", "Display View Loaded" }, { colors.gray, colors.red, colors.green })
|
||||
doc("fp_crd_mon_main", "MAIN DISPLAY", "The connection status of the main display monitor.")
|
||||
doc("fp_crd_mon_flow", "FLOW DISPLAY", "The connection status of the coolant and waste flow display monitor.")
|
||||
doc("fp_crd_mon_unit", "UNIT X DISPLAY", "The connection status of the monitor associated with a given unit.")
|
||||
sect("API Tab")
|
||||
text("This tab lists connected pocket computers. Refer to the Supervisor PKT tab documentation for details on fields.")
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ local network = require("scada-common.network")
|
||||
local ppm = require("scada-common.ppm")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local databus = require("reactor-plc.databus")
|
||||
|
||||
local println = util.println
|
||||
|
||||
---@class plc_backplane
|
||||
@@ -118,6 +120,16 @@ function backplane.init(config, __shared_memory)
|
||||
plc_state.reactor_formed = false
|
||||
end
|
||||
end
|
||||
|
||||
-- detect and warn about multiple reactors
|
||||
if #ppm.get_all_devices("fissionReactorLogicAdapter") > 1 then
|
||||
println("startup> !! DANGER !! more than one reactor was detected! do not share reactor connections between multiple PLCs! they may not all be protected and used as configured")
|
||||
|
||||
log.warning("BKPLN: !! DANGER !! more than one reactor was detected on startup!")
|
||||
log.warning("BKPLN: do NOT share reactor connections between multiple PLCs! they may not all be protected and used as configured")
|
||||
|
||||
databus.tx_multi_reactor(true)
|
||||
end
|
||||
end
|
||||
|
||||
-- get the active NIC
|
||||
@@ -139,7 +151,15 @@ function backplane.attach(iface, type, device, print_no_fp)
|
||||
local sys = _bp.smem.plc_sys
|
||||
|
||||
if type ~= nil and device ~= nil then
|
||||
if state.no_reactor and (type == "fissionReactorLogicAdapter") then
|
||||
if type == "fissionReactorLogicAdapter" then
|
||||
if not state.no_reactor then
|
||||
log.warning("BKPLN: !! DANGER !! an additional reactor (" .. iface .. ") was connected and will not be used!")
|
||||
log.warning("BKPLN: do NOT share reactor connections between multiple PLCs! they may not all be protected and used as configured")
|
||||
|
||||
databus.tx_multi_reactor(true)
|
||||
return
|
||||
end
|
||||
|
||||
-- reconnected reactor
|
||||
log.info("BKPLN: REACTOR LINK_UP " .. iface)
|
||||
|
||||
@@ -250,6 +270,17 @@ function backplane.detach(iface, type, device, print_no_fp)
|
||||
|
||||
state.no_reactor = true
|
||||
state.degraded = true
|
||||
|
||||
-- clear this tentatively, so then if there is >1, that will be reported in backplane.attach in the following if statement
|
||||
databus.tx_multi_reactor(false)
|
||||
|
||||
-- try to find another reactor (this should not work unless multiple were incorrectly connected)
|
||||
local reactor, r_iface = ppm.get_fission_reactor()
|
||||
if reactor and r_iface then
|
||||
log.info("BKPLN: found another fission reactor logic adapter")
|
||||
|
||||
backplane.attach(r_iface, type, reactor, print_no_fp)
|
||||
end
|
||||
elseif _bp.smem.networked and type == "modem" then
|
||||
---@cast device Modem
|
||||
|
||||
|
||||
@@ -141,6 +141,7 @@ local function self_check()
|
||||
self.self_check_msg("> check fission reactor formed...")
|
||||
-- this consumes events, but that is fine here
|
||||
self.self_check_msg(nil, reactor and reactor.isFormed(), "ensure the fission reactor multiblock is formed")
|
||||
self.self_check_msg("> check for no more than one reactor...", #ppm.get_all_devices("fissionReactorLogicAdapter") <= 1, "there MUST be no more than one reactor connected, as a PLC uses the first one it finds, which may not always be the same one")
|
||||
|
||||
self.self_check_msg("> check configuration...", valid_cfg, "go through Configure System and apply settings to set any missing settings and repair any corrupted ones")
|
||||
|
||||
@@ -249,10 +250,10 @@ function check.receive_sv(side, sender, reply_to, message, distance)
|
||||
local s_pkt = self.nic.receive(side, sender, reply_to, message, distance)
|
||||
|
||||
if s_pkt and s_pkt.protocol() == PROTOCOL.SCADA_MGMT then
|
||||
local pkt = comms.mgmt_packet().decode(s_pkt)
|
||||
if pkt then
|
||||
local mgmt_pkt = comms.mgmt_packet()
|
||||
if mgmt_pkt.decode(s_pkt) then
|
||||
tcd.abort(handle_timeout)
|
||||
handle_packet(pkt)
|
||||
handle_packet(mgmt_pkt.get())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,6 +56,12 @@ function databus.tx_hw_status(plc_state)
|
||||
databus.ps.publish("has_wl_modem", plc_state.wl_modem)
|
||||
end
|
||||
|
||||
-- transmiti f the reactor dangerously has multiple fission reactor logic adapters
|
||||
---@param multi boolean has multiple reactors
|
||||
function databus.tx_multi_reactor(multi)
|
||||
databus.ps.publish("has_multi_reactor", multi)
|
||||
end
|
||||
|
||||
-- transmit thread (routine) statuses
|
||||
---@param thread string thread name
|
||||
---@param ok boolean thread state
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
-- Reactor PLC Front Panel GUI
|
||||
--
|
||||
|
||||
local tcd = require("scada-common.tcd")
|
||||
local types = require("scada-common.types")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
@@ -161,6 +162,34 @@ local function init(panel, config)
|
||||
TextBox{parent=hw_labels,text="NT v"..databus.ps.get("comms_version"),fg_bg=s_hi_box}
|
||||
TextBox{parent=hw_labels,text="SN "..comp_id.."-PLC",fg_bg=s_hi_box}
|
||||
|
||||
-- warning about multiple reactors connected
|
||||
|
||||
local warn_strings = { "!! DANGER !!\n>1 REACTOR\nLOGIC ADAPTER", "REMOVE\nALL BUT ONE\nLOGIC ADAPTER" }
|
||||
local multi_warn = TextBox{parent=status,text=warn_strings[1],width=status.get_width()-2,alignment=ALIGN.CENTER,fg_bg=cpair(colors.yellow,colors.red),hidden=true}
|
||||
|
||||
local warn_toggle = true
|
||||
local function flash_warn()
|
||||
multi_warn.recolor(util.trinary(warn_toggle, colors.black, colors.yellow))
|
||||
multi_warn.set_value(util.trinary(warn_toggle, warn_strings[2], warn_strings[1]))
|
||||
warn_toggle = not warn_toggle
|
||||
|
||||
if databus.ps.get("has_multi_reactor") then tcd.dispatch_unique(2, flash_warn) end
|
||||
end
|
||||
|
||||
multi_warn.register(databus.ps, "has_multi_reactor", function (v)
|
||||
if v then
|
||||
multi_warn.show(true)
|
||||
|
||||
warn_toggle = false
|
||||
flash_warn()
|
||||
|
||||
tcd.dispatch_unique(2, flash_warn)
|
||||
else
|
||||
tcd.abort(flash_warn)
|
||||
multi_warn.hide(true)
|
||||
end
|
||||
end)
|
||||
|
||||
--
|
||||
-- rps list
|
||||
--
|
||||
|
||||
@@ -923,10 +923,14 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
|
||||
local pkt = nil
|
||||
|
||||
if s_pkt then
|
||||
-- get as RPLC packet
|
||||
if s_pkt.protocol() == PROTOCOL.RPLC then
|
||||
pkt = comms.rplc_packet().decode(s_pkt)
|
||||
local rplc_pkt = comms.rplc_packet()
|
||||
if rplc_pkt.decode(s_pkt) then pkt = rplc_pkt.get() end
|
||||
-- get as SCADA management packet
|
||||
elseif s_pkt.protocol() == PROTOCOL.SCADA_MGMT then
|
||||
pkt = comms.mgmt_packet().decode(s_pkt)
|
||||
local mgmt_pkt = comms.mgmt_packet()
|
||||
if mgmt_pkt.decode(s_pkt) then pkt = mgmt_pkt.get() end
|
||||
else
|
||||
log.debug("unsupported packet type " .. s_pkt.protocol(), true)
|
||||
end
|
||||
|
||||
@@ -326,10 +326,10 @@ function check.receive_sv(side, sender, reply_to, message, distance)
|
||||
local s_pkt = self.nic.receive(side, sender, reply_to, message, distance)
|
||||
|
||||
if s_pkt and s_pkt.protocol() == PROTOCOL.SCADA_MGMT then
|
||||
local pkt = comms.mgmt_packet().decode(s_pkt)
|
||||
if pkt then
|
||||
local mgmt_pkt = comms.mgmt_packet()
|
||||
if mgmt_pkt.decode(s_pkt) then
|
||||
tcd.abort(handle_timeout)
|
||||
handle_packet(pkt)
|
||||
handle_packet(mgmt_pkt.get())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
12
rtu/rtu.lua
12
rtu/rtu.lua
@@ -425,10 +425,18 @@ function rtu.comms(version, nic, conn_watchdog)
|
||||
local pkt = nil
|
||||
|
||||
if s_pkt then
|
||||
-- get as MODBUS TCP packet
|
||||
if s_pkt.protocol() == PROTOCOL.MODBUS_TCP then
|
||||
pkt = comms.modbus_packet().decode(s_pkt)
|
||||
local m_pkt = comms.modbus_packet()
|
||||
if m_pkt.decode(s_pkt) then
|
||||
pkt = m_pkt.get()
|
||||
end
|
||||
-- get as SCADA management packet
|
||||
elseif s_pkt.protocol() == PROTOCOL.SCADA_MGMT then
|
||||
pkt = comms.mgmt_packet().decode(s_pkt)
|
||||
local mgmt_pkt = comms.mgmt_packet()
|
||||
if mgmt_pkt.decode(s_pkt) then
|
||||
pkt = mgmt_pkt.get()
|
||||
end
|
||||
else
|
||||
log.debug("illegal packet type " .. s_pkt.protocol(), true)
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ local rtu = require("rtu.rtu")
|
||||
local threads = require("rtu.threads")
|
||||
local uinit = require("rtu.uinit")
|
||||
|
||||
local RTU_VERSION = "v1.13.1"
|
||||
local RTU_VERSION = "v1.13.0"
|
||||
|
||||
local println = util.println
|
||||
local println_ts = util.println_ts
|
||||
|
||||
@@ -414,7 +414,6 @@ function comms.modbus_packet()
|
||||
---@param unit_id integer
|
||||
---@param func_code MODBUS_FCODE
|
||||
---@param data table
|
||||
---@return boolean success
|
||||
function public.make(txn_id, unit_id, func_code, data)
|
||||
if type(data) == "table" then
|
||||
self.txn_id = txn_id
|
||||
@@ -426,33 +425,37 @@ function comms.modbus_packet()
|
||||
-- populate raw array
|
||||
self.raw = { self.txn_id, self.unit_id, self.func_code }
|
||||
for i = 1, self.length do insert(self.raw, data[i]) end
|
||||
|
||||
return true
|
||||
else
|
||||
log.error("COMMS: modbus_packet.make(): data not a table")
|
||||
end
|
||||
|
||||
log.error("COMMS: modbus_packet.make(): data not a table")
|
||||
return false
|
||||
end
|
||||
|
||||
-- decode a MODBUS packet from a SCADA frame
|
||||
---@param frame scada_packet
|
||||
---@return modbus_frame|nil frame the decoded frame, if valid
|
||||
---@return boolean success
|
||||
function public.decode(frame)
|
||||
if frame then
|
||||
self.frame = frame
|
||||
|
||||
if frame.protocol() == PROTOCOL.MODBUS_TCP then
|
||||
if frame.length() >= 3 then
|
||||
local size_ok = frame.length() >= 3
|
||||
|
||||
if size_ok then
|
||||
local data = frame.data()
|
||||
|
||||
if public.make(data[1], data[2], data[3], { table.unpack(data, 4, #data) }) then
|
||||
return public.get()
|
||||
end
|
||||
public.make(data[1], data[2], data[3], { table.unpack(data, 4, #data) })
|
||||
end
|
||||
else log.debug("COMMS: attempted MODBUS_TCP parse of incorrect protocol " .. frame.protocol(), true) end
|
||||
else log.debug("COMMS: nil frame encountered", true) end
|
||||
|
||||
return nil
|
||||
local valid = type(self.txn_id) == "number" and type(self.unit_id) == "number" and type(self.func_code) == "number"
|
||||
|
||||
return size_ok and valid
|
||||
else
|
||||
log.debug("COMMS: attempted MODBUS_TCP parse of incorrect protocol " .. frame.protocol(), true)
|
||||
return false
|
||||
end
|
||||
else
|
||||
log.debug("COMMS: nil frame encountered", true)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- get raw to send
|
||||
@@ -497,7 +500,6 @@ function comms.rplc_packet()
|
||||
---@param id integer
|
||||
---@param packet_type RPLC_TYPE
|
||||
---@param data table
|
||||
---@return boolean success
|
||||
function public.make(id, packet_type, data)
|
||||
if type(data) == "table" then
|
||||
-- packet accessor properties
|
||||
@@ -509,33 +511,37 @@ function comms.rplc_packet()
|
||||
-- populate raw array
|
||||
self.raw = { self.id, self.type }
|
||||
for i = 1, #data do insert(self.raw, data[i]) end
|
||||
|
||||
return true
|
||||
else
|
||||
log.error("COMMS: rplc_packet.make(): data not a table")
|
||||
end
|
||||
|
||||
log.error("COMMS: rplc_packet.make(): data not a table")
|
||||
return false
|
||||
end
|
||||
|
||||
-- decode an RPLC packet from a SCADA frame
|
||||
---@param frame scada_packet
|
||||
---@return rplc_frame|nil frame the decoded frame, if valid
|
||||
---@return boolean success
|
||||
function public.decode(frame)
|
||||
if frame then
|
||||
self.frame = frame
|
||||
|
||||
if frame.protocol() == PROTOCOL.RPLC then
|
||||
if frame.length() >= 2 then
|
||||
local ok = frame.length() >= 2
|
||||
|
||||
if ok then
|
||||
local data = frame.data()
|
||||
|
||||
if public.make(data[1], data[2], { table.unpack(data, 3, #data) }) and (type(self.id) == "number") then
|
||||
return public.get()
|
||||
end
|
||||
public.make(data[1], data[2], { table.unpack(data, 3, #data) })
|
||||
end
|
||||
else log.debug("COMMS: attempted RPLC parse of incorrect protocol " .. frame.protocol(), true) end
|
||||
else log.debug("COMMS: nil frame encountered", true) end
|
||||
|
||||
return nil
|
||||
ok = ok and type(self.id) == "number"
|
||||
|
||||
return ok
|
||||
else
|
||||
log.debug("COMMS: attempted RPLC parse of incorrect protocol " .. frame.protocol(), true)
|
||||
return false
|
||||
end
|
||||
else
|
||||
log.debug("COMMS: nil frame encountered", true)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- get raw to send
|
||||
@@ -577,7 +583,6 @@ function comms.mgmt_packet()
|
||||
-- make a SCADA management packet
|
||||
---@param packet_type MGMT_TYPE
|
||||
---@param data table
|
||||
---@return boolean success
|
||||
function public.make(packet_type, data)
|
||||
if type(data) == "table" then
|
||||
-- packet accessor properties
|
||||
@@ -588,33 +593,35 @@ function comms.mgmt_packet()
|
||||
-- populate raw array
|
||||
self.raw = { self.type }
|
||||
for i = 1, #data do insert(self.raw, data[i]) end
|
||||
|
||||
return true
|
||||
else
|
||||
log.error("COMMS: mgmt_packet.make(): data not a table")
|
||||
end
|
||||
|
||||
log.error("COMMS: mgmt_packet.make(): data not a table")
|
||||
return false
|
||||
end
|
||||
|
||||
-- decode a SCADA management packet from a SCADA frame
|
||||
---@param frame scada_packet
|
||||
---@return mgmt_frame|nil frame the decoded frame, if valid
|
||||
---@return boolean success
|
||||
function public.decode(frame)
|
||||
if frame then
|
||||
self.frame = frame
|
||||
|
||||
if frame.protocol() == PROTOCOL.SCADA_MGMT then
|
||||
if frame.length() >= 1 then
|
||||
local ok = frame.length() >= 1
|
||||
|
||||
if ok then
|
||||
local data = frame.data()
|
||||
|
||||
if public.make(data[1], { table.unpack(data, 2, #data) }) then
|
||||
return public.get()
|
||||
end
|
||||
public.make(data[1], { table.unpack(data, 2, #data) })
|
||||
end
|
||||
else log.debug("COMMS: attempted SCADA_MGMT parse of incorrect protocol " .. frame.protocol(), true) end
|
||||
else log.debug("COMMS: nil frame encountered", true) end
|
||||
|
||||
return nil
|
||||
return ok
|
||||
else
|
||||
log.debug("COMMS: attempted SCADA_MGMT parse of incorrect protocol " .. frame.protocol(), true)
|
||||
return false
|
||||
end
|
||||
else
|
||||
log.debug("COMMS: nil frame encountered", true)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- get raw to send
|
||||
@@ -655,7 +662,6 @@ function comms.crdn_packet()
|
||||
-- make a coordinator packet
|
||||
---@param packet_type CRDN_TYPE
|
||||
---@param data table
|
||||
---@return boolean success
|
||||
function public.make(packet_type, data)
|
||||
if type(data) == "table" then
|
||||
-- packet accessor properties
|
||||
@@ -666,33 +672,35 @@ function comms.crdn_packet()
|
||||
-- populate raw array
|
||||
self.raw = { self.type }
|
||||
for i = 1, #data do insert(self.raw, data[i]) end
|
||||
|
||||
return true
|
||||
else
|
||||
log.error("COMMS: crdn_packet.make(): data not a table")
|
||||
end
|
||||
|
||||
log.error("COMMS: crdn_packet.make(): data not a table")
|
||||
return false
|
||||
end
|
||||
|
||||
-- decode a coordinator packet from a SCADA frame
|
||||
---@param frame scada_packet
|
||||
---@return crdn_frame|nil frame the decoded frame, if valid
|
||||
---@return boolean success
|
||||
function public.decode(frame)
|
||||
if frame then
|
||||
self.frame = frame
|
||||
|
||||
if frame.protocol() == PROTOCOL.SCADA_CRDN then
|
||||
if frame.length() >= 1 then
|
||||
local ok = frame.length() >= 1
|
||||
|
||||
if ok then
|
||||
local data = frame.data()
|
||||
|
||||
if public.make(data[1], { table.unpack(data, 2, #data) }) then
|
||||
return public.get()
|
||||
end
|
||||
public.make(data[1], { table.unpack(data, 2, #data) })
|
||||
end
|
||||
else log.debug("COMMS: attempted SCADA_CRDN parse of incorrect protocol " .. frame.protocol(), true) end
|
||||
else log.debug("COMMS: nil frame encountered", true) end
|
||||
|
||||
return nil
|
||||
return ok
|
||||
else
|
||||
log.debug("COMMS: attempted SCADA_CRDN parse of incorrect protocol " .. frame.protocol(), true)
|
||||
return false
|
||||
end
|
||||
else
|
||||
log.debug("COMMS: nil frame encountered", true)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- get raw to send
|
||||
|
||||
@@ -425,26 +425,27 @@ end
|
||||
|
||||
-- get a mounted peripheral by type (if multiple, returns the first)
|
||||
---@nodiscard
|
||||
---@param name string type name
|
||||
---@return table|nil device function table
|
||||
function ppm.get_device(name)
|
||||
local device = nil
|
||||
---@param type string type name
|
||||
---@return table|nil device, string|nil iface device and interface
|
||||
function ppm.get_device(type)
|
||||
local device, d_iface = nil, nil
|
||||
|
||||
for _, data in pairs(_ppm.mounts) do
|
||||
if data.type == name then
|
||||
for iface, data in pairs(_ppm.mounts) do
|
||||
if data.type == type then
|
||||
device = data.dev
|
||||
d_iface = iface
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return device
|
||||
return device, d_iface
|
||||
end
|
||||
|
||||
-- SPECIFIC DEVICE ACCESSORS --
|
||||
|
||||
-- get the fission reactor (if multiple, returns the first)
|
||||
---@nodiscard
|
||||
---@return table|nil reactor function table
|
||||
---@return table|nil reactor, string|nil iface reactor and interface
|
||||
function ppm.get_fission_reactor() return ppm.get_device("fissionReactorLogicAdapter") end
|
||||
|
||||
-- get a modem by name
|
||||
@@ -470,8 +471,8 @@ function ppm.get_wireless_modem()
|
||||
|
||||
for iface, device in pairs(_ppm.mounts) do
|
||||
if device.type == "modem" and (emulated_env or device.dev.isWireless()) then
|
||||
w_iface = iface
|
||||
w_modem = device.dev
|
||||
w_iface = iface
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ local supervisor = require("supervisor.supervisor")
|
||||
|
||||
local svsessions = require("supervisor.session.svsessions")
|
||||
|
||||
local SUPERVISOR_VERSION = "v1.8.1"
|
||||
local SUPERVISOR_VERSION = "v1.8.0"
|
||||
|
||||
local println = util.println
|
||||
local println_ts = util.println_ts
|
||||
|
||||
@@ -413,14 +413,22 @@ function supervisor.comms(_version, fp_ok, facility)
|
||||
end
|
||||
|
||||
if s_pkt then
|
||||
-- get as MODBUS TCP packet
|
||||
if s_pkt.protocol() == PROTOCOL.MODBUS_TCP then
|
||||
pkt = comms.modbus_packet().decode(s_pkt)
|
||||
local m_pkt = comms.modbus_packet()
|
||||
if m_pkt.decode(s_pkt) then pkt = m_pkt.get() end
|
||||
-- get as RPLC packet
|
||||
elseif s_pkt.protocol() == PROTOCOL.RPLC then
|
||||
pkt = comms.rplc_packet().decode(s_pkt)
|
||||
local rplc_pkt = comms.rplc_packet()
|
||||
if rplc_pkt.decode(s_pkt) then pkt = rplc_pkt.get() end
|
||||
-- get as SCADA management packet
|
||||
elseif s_pkt.protocol() == PROTOCOL.SCADA_MGMT then
|
||||
pkt = comms.mgmt_packet().decode(s_pkt)
|
||||
local mgmt_pkt = comms.mgmt_packet()
|
||||
if mgmt_pkt.decode(s_pkt) then pkt = mgmt_pkt.get() end
|
||||
-- get as coordinator packet
|
||||
elseif s_pkt.protocol() == PROTOCOL.SCADA_CRDN then
|
||||
pkt = comms.crdn_packet().decode(s_pkt)
|
||||
local crdn_pkt = comms.crdn_packet()
|
||||
if crdn_pkt.decode(s_pkt) then pkt = crdn_pkt.get() end
|
||||
else
|
||||
log.debug("parse_packet(" .. side .. "): attempted parse of illegal packet type " .. s_pkt.protocol(), true)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user