RTU print fixes, config fixes, comms init fixes and moved modem open

This commit is contained in:
Mikayla Fischler
2022-04-11 11:08:46 -04:00
parent 28b1c03e03
commit 203d868aeb
3 changed files with 30 additions and 19 deletions

View File

@ -1,7 +1,10 @@
-- #REQUIRES rsio.lua -- #REQUIRES rsio.lua
SCADA_SERVER = 16000 -- port to send packets TO server
SERVER_PORT = 16000
-- port to listen to incoming packets FROM server
LISTEN_PORT = 15001
-- RTU peripheral devices (named: side/network device name)
RTU_DEVICES = { RTU_DEVICES = {
{ {
name = "boiler_0", name = "boiler_0",
@ -14,7 +17,7 @@ RTU_DEVICES = {
for_reactor = 1 for_reactor = 1
} }
} }
-- RTU redstone interface definitions
RTU_REDSTONE = { RTU_REDSTONE = {
{ {
for_reactor = 1, for_reactor = 1,

View File

@ -98,6 +98,11 @@ function rtu_comms(modem, local_port, server_port)
l_port = local_port l_port = local_port
} }
-- open modem
if not self.modem.isOpen(self.l_port) then
self.modem.open(self.l_port)
end
-- PRIVATE FUNCTIONS -- -- PRIVATE FUNCTIONS --
local _send = function (protocol, msg) local _send = function (protocol, msg)

View File

@ -17,7 +17,15 @@ os.loadAPI("dev/turbine.lua")
local RTU_VERSION = "alpha-v0.1.0" local RTU_VERSION = "alpha-v0.1.0"
local print = util.print
local println = util.println
local print_ts = util.print_ts local print_ts = util.print_ts
local println_ts = util.println_ts
log._info("========================================")
log._info("BOOTING rtu.startup " .. RTU_VERSION)
log._info("========================================")
println(">> RTU " .. RTU_VERSION .. " <<")
---------------------------------------- ----------------------------------------
-- startup -- startup
@ -37,12 +45,7 @@ if modem == nil then
return return
end end
-- start comms local rtu_comms = rtu.rtu_comms(modem, config.LISTEN_PORT, config.SERVER_PORT)
if not modem.isOpen(config.LISTEN_PORT) then
modem.open(config.LISTEN_PORT)
end
local rtu_comms = rtu.rtu_comms(config.REACTOR_ID, modem, config.LISTEN_PORT, config.SERVER_PORT, reactor)
---------------------------------------- ----------------------------------------
-- determine configuration -- determine configuration
@ -69,8 +72,8 @@ for reactor_idx = 1, #RTU_REDSTONE do
end end
if ~valid then if ~valid then
local message = "invalid redstone configuration at index " .. i local message = "init> invalid redstone definition at index " .. i
print_ts(message .. "\n") println_ts(message)
log._warning(message) log._warning(message)
else else
-- link redstone in RTU -- link redstone in RTU
@ -85,13 +88,13 @@ for reactor_idx = 1, #RTU_REDSTONE do
rs_rtu.link_ao(config.channel, config.side) rs_rtu.link_ao(config.channel, config.side)
else else
-- should be unreachable code, we already validated channels -- should be unreachable code, we already validated channels
log._error("fell through if chain attempting to identify IO mode", true) log._error("init> fell through if chain attempting to identify IO mode", true)
break break
end end
table.insert(capabilities, config.channel) table.insert(capabilities, config.channel)
log._debug("startup> linked redstone " .. #capabilities .. ": " .. rsio.to_string(config.channel) .. " (" .. config.side .. log._debug("init> linked redstone " .. #capabilities .. ": " .. rsio.to_string(config.channel) .. " (" .. config.side ..
") for reactor " .. RTU_REDSTONE[reactor_idx].for_reactor) ") for reactor " .. RTU_REDSTONE[reactor_idx].for_reactor)
end end
end end
@ -112,8 +115,8 @@ for i = 1, #RTU_DEVICES do
local device = ppm.get_periph(RTU_DEVICES[i].name) local device = ppm.get_periph(RTU_DEVICES[i].name)
if device == nil then if device == nil then
local message = "'" .. RTU_DEVICES[i].name .. "' not found" local message = "init> '" .. RTU_DEVICES[i].name .. "' not found"
print_ts(message .. "\n") println_ts(message)
log._warning(message) log._warning(message)
else else
local type = ppm.get_type(RTU_DEVICES[i].name) local type = ppm.get_type(RTU_DEVICES[i].name)
@ -133,8 +136,8 @@ for i = 1, #RTU_DEVICES do
rtu_type = "imatrix" rtu_type = "imatrix"
rtu_iface = imatrix_rtu(device) rtu_iface = imatrix_rtu(device)
else else
local message = "device '" .. RTU_DEVICES[i].name .. "' is not a known type (" .. type .. ")" local message = "init> device '" .. RTU_DEVICES[i].name .. "' is not a known type (" .. type .. ")"
print_ts(message .. "\n") println_ts(message)
log._warning(message) log._warning(message)
end end
@ -149,7 +152,7 @@ for i = 1, #RTU_DEVICES do
modbus_io = modbus_init(rtu_iface) modbus_io = modbus_init(rtu_iface)
}) })
log._debug("startup> initialized RTU unit #" .. #units .. ": " .. RTU_DEVICES[i].name .. " (" .. rtu_type .. ") [" .. log._debug("init> initialized RTU unit #" .. #units .. ": " .. RTU_DEVICES[i].name .. " (" .. rtu_type .. ") [" ..
RTU_DEVICES[i].index .. "] for reactor " .. RTU_DEVICES[i].for_reactor) RTU_DEVICES[i].index .. "] for reactor " .. RTU_DEVICES[i].for_reactor)
end end
end end
@ -188,7 +191,7 @@ while true do
-- if linked, stop sending advertisements -- if linked, stop sending advertisements
linked = link_ref.linked linked = link_ref.linked
elseif event == "terminate" then elseif event == "terminate" then
print_ts("Exiting...\n") println_ts("exiting...")
return return
end end
end end