mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#53 RTU redstone parse checks
This commit is contained in:
parent
790571b6fc
commit
62d5490dc8
128
rtu/startup.lua
128
rtu/startup.lua
@ -103,64 +103,88 @@ for entry_idx = 1, #rtu_redstone do
|
|||||||
|
|
||||||
log.debug("init> starting redstone RTU I/O linking for reactor " .. io_reactor .. "...")
|
log.debug("init> starting redstone RTU I/O linking for reactor " .. io_reactor .. "...")
|
||||||
|
|
||||||
for i = 1, #io_table do
|
local continue = true
|
||||||
local valid = false
|
|
||||||
local conf = io_table[i]
|
|
||||||
|
|
||||||
-- verify configuration
|
for i = 1, #units do
|
||||||
if rsio.is_valid_channel(conf.channel) and rsio.is_valid_side(conf.side) then
|
local unit = units[i] ---@type rtu_unit_registry_entry
|
||||||
if conf.bundled_color then
|
if unit.reactor == io_reactor and unit.type == rtu_t.redstone then
|
||||||
valid = rsio.is_color(conf.bundled_color)
|
-- duplicate entry
|
||||||
else
|
log.warning("init> skipping definition block #" .. entry_idx .. " for reactor " .. io_reactor .. " with already defined redstone I/O")
|
||||||
valid = true
|
continue = false
|
||||||
end
|
break
|
||||||
end
|
|
||||||
|
|
||||||
if not valid then
|
|
||||||
local message = "init> invalid redstone definition at index " .. i .. " in definition block #" .. entry_idx ..
|
|
||||||
" (for reactor " .. io_reactor .. ")"
|
|
||||||
println_ts(message)
|
|
||||||
log.warning(message)
|
|
||||||
else
|
|
||||||
-- link redstone in RTU
|
|
||||||
local mode = rsio.get_io_mode(conf.channel)
|
|
||||||
if mode == rsio.IO_MODE.DIGITAL_IN then
|
|
||||||
rs_rtu.link_di(conf.side, conf.bundled_color)
|
|
||||||
elseif mode == rsio.IO_MODE.DIGITAL_OUT then
|
|
||||||
rs_rtu.link_do(conf.channel, conf.side, conf.bundled_color)
|
|
||||||
elseif mode == rsio.IO_MODE.ANALOG_IN then
|
|
||||||
rs_rtu.link_ai(conf.side)
|
|
||||||
elseif mode == rsio.IO_MODE.ANALOG_OUT then
|
|
||||||
rs_rtu.link_ao(conf.side)
|
|
||||||
else
|
|
||||||
-- should be unreachable code, we already validated channels
|
|
||||||
log.error("init> fell through if chain attempting to identify IO mode", true)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(capabilities, conf.channel)
|
|
||||||
|
|
||||||
log.debug("init> linked redstone " .. #capabilities .. ": " .. rsio.to_string(conf.channel) .. " (" .. conf.side ..
|
|
||||||
") for reactor " .. io_reactor)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@class rtu_unit_registry_entry
|
if continue then
|
||||||
local unit = {
|
for i = 1, #io_table do
|
||||||
name = "redstone_io",
|
local valid = false
|
||||||
type = rtu_t.redstone,
|
local conf = io_table[i]
|
||||||
index = entry_idx,
|
|
||||||
reactor = io_reactor,
|
|
||||||
device = capabilities, -- use device field for redstone channels
|
|
||||||
rtu = rs_rtu,
|
|
||||||
modbus_io = modbus.new(rs_rtu, false),
|
|
||||||
pkt_queue = nil,
|
|
||||||
thread = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
table.insert(units, unit)
|
-- verify configuration
|
||||||
|
if rsio.is_valid_channel(conf.channel) and rsio.is_valid_side(conf.side) then
|
||||||
|
if conf.bundled_color then
|
||||||
|
valid = rsio.is_color(conf.bundled_color)
|
||||||
|
else
|
||||||
|
valid = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
log.debug("init> initialized RTU unit #" .. #units .. ": redstone_io (redstone) [1] for reactor " .. io_reactor)
|
if not valid then
|
||||||
|
local message = "init> invalid redstone definition at index " .. i .. " in definition block #" .. entry_idx ..
|
||||||
|
" (for reactor " .. io_reactor .. ")"
|
||||||
|
println_ts(message)
|
||||||
|
log.warning(message)
|
||||||
|
else
|
||||||
|
-- link redstone in RTU
|
||||||
|
local mode = rsio.get_io_mode(conf.channel)
|
||||||
|
if mode == rsio.IO_MODE.DIGITAL_IN then
|
||||||
|
-- can't have duplicate inputs
|
||||||
|
if util.table_contains(capabilities, conf.channel) then
|
||||||
|
log.warning("init> skipping duplicate input for channel " .. rsio.to_string(conf.channel) .. " on side " .. conf.side)
|
||||||
|
else
|
||||||
|
rs_rtu.link_di(conf.side, conf.bundled_color)
|
||||||
|
end
|
||||||
|
elseif mode == rsio.IO_MODE.DIGITAL_OUT then
|
||||||
|
rs_rtu.link_do(conf.channel, conf.side, conf.bundled_color)
|
||||||
|
elseif mode == rsio.IO_MODE.ANALOG_IN then
|
||||||
|
-- can't have duplicate inputs
|
||||||
|
if util.table_contains(capabilities, conf.channel) then
|
||||||
|
log.warning("init> skipping duplicate input for channel " .. rsio.to_string(conf.channel) .. " on side " .. conf.side)
|
||||||
|
else
|
||||||
|
rs_rtu.link_ai(conf.side)
|
||||||
|
end
|
||||||
|
elseif mode == rsio.IO_MODE.ANALOG_OUT then
|
||||||
|
rs_rtu.link_ao(conf.side)
|
||||||
|
else
|
||||||
|
-- should be unreachable code, we already validated channels
|
||||||
|
log.error("init> fell through if chain attempting to identify IO mode", true)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(capabilities, conf.channel)
|
||||||
|
|
||||||
|
log.debug("init> linked redstone " .. #capabilities .. ": " .. rsio.to_string(conf.channel) .. " (" .. conf.side ..
|
||||||
|
") for reactor " .. io_reactor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@class rtu_unit_registry_entry
|
||||||
|
local unit = {
|
||||||
|
name = "redstone_io",
|
||||||
|
type = rtu_t.redstone,
|
||||||
|
index = entry_idx,
|
||||||
|
reactor = io_reactor,
|
||||||
|
device = capabilities, -- use device field for redstone channels
|
||||||
|
rtu = rs_rtu,
|
||||||
|
modbus_io = modbus.new(rs_rtu, false),
|
||||||
|
pkt_queue = nil,
|
||||||
|
thread = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
table.insert(units, unit)
|
||||||
|
|
||||||
|
log.debug("init> initialized RTU unit #" .. #units .. ": redstone_io (redstone) [1] for reactor " .. io_reactor)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- mounted peripherals
|
-- mounted peripherals
|
||||||
|
@ -107,6 +107,17 @@ util.filter_table = function (t, f, on_delete)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- check if a table contains the provided element
|
||||||
|
---@param t table table to check
|
||||||
|
---@param element any element to check for
|
||||||
|
util.table_contains = function (t, element)
|
||||||
|
for i = 1, #t do
|
||||||
|
if t[i] == element then return true end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
-- MEKANISM POWER --
|
-- MEKANISM POWER --
|
||||||
|
|
||||||
-- function kFE(fe) return fe / 1000 end
|
-- function kFE(fe) return fe / 1000 end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user