scope fixes, load comms api, debug prints

This commit is contained in:
Mikayla Fischler 2022-04-18 09:35:08 -04:00
parent 7d9a664d38
commit 377cf8e6fc
3 changed files with 17 additions and 7 deletions

View File

@ -2,6 +2,10 @@
-- #REQUIRES modbus.lua -- #REQUIRES modbus.lua
-- #REQUIRES ppm.lua -- #REQUIRES ppm.lua
local PROTOCOLS = comms.PROTOCOLS
local SCADA_MGMT_TYPES = comms.SCADA_MGMT_TYPES
local RTU_ADVERT_TYPES = comms.RTU_ADVERT_TYPES
function rtu_init() function rtu_init()
local self = { local self = {
discrete_inputs = {}, discrete_inputs = {},
@ -130,7 +134,7 @@ function rtu_comms(modem, local_port, server_port)
-- PRIVATE FUNCTIONS -- -- PRIVATE FUNCTIONS --
local _send = function (protocol, msg) local _send = function (protocol, msg)
local packet = scada_packet() local packet = comms.scada_packet()
packet.make(self.seq_num, protocol, msg) packet.make(self.seq_num, protocol, msg)
self.modem.transmit(self.s_port, self.l_port, packet.raw()) self.modem.transmit(self.s_port, self.l_port, packet.raw())
self.seq_num = self.seq_num + 1 self.seq_num = self.seq_num + 1
@ -141,7 +145,7 @@ function rtu_comms(modem, local_port, server_port)
-- parse a MODBUS/SCADA packet -- parse a MODBUS/SCADA packet
local parse_packet = function(side, sender, reply_to, message, distance) local parse_packet = function(side, sender, reply_to, message, distance)
local pkt = nil local pkt = nil
local s_pkt = scada_packet() local s_pkt = comms.scada_packet()
-- parse packet as generic SCADA packet -- parse packet as generic SCADA packet
s_pkt.recieve(side, sender, reply_to, message, distance) s_pkt.recieve(side, sender, reply_to, message, distance)
@ -149,13 +153,13 @@ function rtu_comms(modem, local_port, server_port)
if s_pkt.is_valid() then if s_pkt.is_valid() then
-- get as MODBUS TCP packet -- get as MODBUS TCP packet
if s_pkt.protocol() == PROTOCOLS.MODBUS_TCP then if s_pkt.protocol() == PROTOCOLS.MODBUS_TCP then
local m_pkt = modbus_packet() local m_pkt = modbus.packet()
if m_pkt.decode(s_pkt) then if m_pkt.decode(s_pkt) then
pkt = m_pkt.get() pkt = m_pkt.get()
end end
-- get as SCADA management packet -- get as SCADA management packet
elseif s_pkt.protocol() == PROTOCOLS.SCADA_MGMT then elseif s_pkt.protocol() == PROTOCOLS.SCADA_MGMT then
local mgmt_pkt = mgmt_packet() local mgmt_pkt = comms.mgmt_packet()
if mgmt_pkt.decode(s_pkt) then if mgmt_pkt.decode(s_pkt) then
pkt = mgmt_packet.get() pkt = mgmt_packet.get()
end end

View File

@ -5,6 +5,7 @@
os.loadAPI("scada-common/log.lua") os.loadAPI("scada-common/log.lua")
os.loadAPI("scada-common/util.lua") os.loadAPI("scada-common/util.lua")
os.loadAPI("scada-common/ppm.lua") os.loadAPI("scada-common/ppm.lua")
os.loadAPI("scada-common/comms.lua")
os.loadAPI("scada-common/modbus.lua") os.loadAPI("scada-common/modbus.lua")
os.loadAPI("scada-common/rsio.lua") os.loadAPI("scada-common/rsio.lua")
@ -16,7 +17,7 @@ os.loadAPI("dev/boiler.lua")
os.loadAPI("dev/imatrix.lua") os.loadAPI("dev/imatrix.lua")
os.loadAPI("dev/turbine.lua") os.loadAPI("dev/turbine.lua")
local RTU_VERSION = "alpha-v0.1.1" local RTU_VERSION = "alpha-v0.1.2"
local print = util.print local print = util.print
local println = util.println local println = util.println
@ -67,6 +68,8 @@ for reactor_idx = 1, #rtu_redstone do
local capabilities = {} local capabilities = {}
log._debug("init> starting redstone RTU I/O linking for reactor " .. rtu_redstone[reactor_idx].for_reactor .. "...")
for i = 1, #io_table do for i = 1, #io_table do
local valid = false local valid = false
local config = io_table[i] local config = io_table[i]
@ -81,7 +84,8 @@ for reactor_idx = 1, #rtu_redstone do
end end
if not valid then if not valid then
local message = "init> invalid redstone definition at index " .. i local message = "init> invalid redstone definition at index " .. i .. " in definition block #" .. reactor_idx ..
" (for reactor " .. rtu_redstone[reactor_idx].for_reactor .. ")"
println_ts(message) println_ts(message)
log._warning(message) log._warning(message)
else else
@ -117,6 +121,8 @@ for reactor_idx = 1, #rtu_redstone do
rtu = rs_rtu, rtu = rs_rtu,
modbus_io = modbus.new(rs_rtu) modbus_io = modbus.new(rs_rtu)
}) })
log._debug("init> initialized RTU unit #" .. #units .. ": redstone_io (redstone) [1] for reactor " .. rtu_redstone[reactor_idx].for_reactor)
end end
-- mounted peripherals -- mounted peripherals

View File

@ -264,7 +264,7 @@ function new(rtu_dev)
} }
end end
function modbus_packet() function packet()
local self = { local self = {
frame = nil, frame = nil,
txn_id = txn_id, txn_id = txn_id,