#95 added boiler/turbine RTUs to supervisor, tons of RTU/MODBUS related bugfixes, adjusted annunciator conditions
This commit is contained in:
@@ -108,7 +108,7 @@ function boiler.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.BUILD then
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local comms = require("scada-common.comms")
|
||||
local log = require("scada-common.log")
|
||||
local types = require("scada-common.types")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local unit_session = require("supervisor.session.rtu.unit_session")
|
||||
|
||||
@@ -60,8 +61,8 @@ function boilerv.new(session_id, unit_id, advert, out_queue)
|
||||
length = 0,
|
||||
width = 0,
|
||||
height = 0,
|
||||
min_pos = 0,
|
||||
max_pos = 0,
|
||||
min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
|
||||
max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
|
||||
boil_cap = 0.0,
|
||||
steam_cap = 0,
|
||||
water_cap = 0,
|
||||
@@ -76,16 +77,16 @@ function boilerv.new(session_id, unit_id, advert, out_queue)
|
||||
boil_rate = 0.0
|
||||
},
|
||||
tanks = {
|
||||
steam = {}, ---@type tank_fluid
|
||||
steam = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid
|
||||
steam_need = 0,
|
||||
steam_fill = 0.0,
|
||||
water = {}, ---@type tank_fluid
|
||||
water = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid
|
||||
water_need = 0,
|
||||
water_fill = 0.0,
|
||||
hcool = {}, ---@type tank_fluid
|
||||
hcool = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid
|
||||
hcool_need = 0,
|
||||
hcool_fill = 0.0,
|
||||
ccool = {}, ---@type tank_fluid
|
||||
ccool = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid
|
||||
ccool_need = 0,
|
||||
ccool_fill = 0.0
|
||||
}
|
||||
@@ -105,19 +106,19 @@ function boilerv.new(session_id, unit_id, advert, out_queue)
|
||||
-- query the build of the device
|
||||
local function _request_build()
|
||||
-- read input registers 1 through 13 (start = 1, count = 13)
|
||||
self.session.send_request(TXN_TYPES.BUILD, MODBUS_FCODE.READ_INPUT_REGS, { 1, 7 })
|
||||
self.session.send_request(TXN_TYPES.BUILD, MODBUS_FCODE.READ_INPUT_REGS, { 1, 13 })
|
||||
end
|
||||
|
||||
-- query the state of the device
|
||||
local function _request_state()
|
||||
-- read input registers 14 through 16 (start = 14, count = 2)
|
||||
-- read input registers 14 through 15 (start = 14, count = 2)
|
||||
self.session.send_request(TXN_TYPES.STATE, MODBUS_FCODE.READ_INPUT_REGS, { 14, 2 })
|
||||
end
|
||||
|
||||
-- query the tanks of the device
|
||||
local function _request_tanks()
|
||||
-- read input registers 17 through 29 (start = 17, count = 12)
|
||||
self.session.send_request(TXN_TYPES.TANKS, MODBUS_FCODE.READ_INPUT_REGS, { 17, 12 })
|
||||
-- read input registers 16 through 27 (start = 16, count = 12)
|
||||
self.session.send_request(TXN_TYPES.TANKS, MODBUS_FCODE.READ_INPUT_REGS, { 16, 12 })
|
||||
end
|
||||
|
||||
-- PUBLIC FUNCTIONS --
|
||||
@@ -125,7 +126,7 @@ function boilerv.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.FORMED then
|
||||
|
||||
@@ -79,7 +79,7 @@ function emachine.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.BUILD then
|
||||
|
||||
@@ -62,7 +62,7 @@ function envd.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.RAD then
|
||||
|
||||
@@ -112,7 +112,7 @@ function imatrix.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.FORMED then
|
||||
|
||||
@@ -144,7 +144,7 @@ function redstone.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.DI_READ then
|
||||
|
||||
@@ -97,7 +97,7 @@ function sna.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.BUILD then
|
||||
|
||||
@@ -117,7 +117,7 @@ function sps.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.FORMED then
|
||||
|
||||
@@ -104,7 +104,7 @@ function turbine.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.BUILD then
|
||||
|
||||
@@ -70,6 +70,7 @@ function turbinev.new(session_id, unit_id, advert, out_queue)
|
||||
in_q = mqueue.new(),
|
||||
has_build = false,
|
||||
periodics = {
|
||||
next_formed_req = 0,
|
||||
next_build_req = 0,
|
||||
next_state_req = 0,
|
||||
next_tanks_req = 0
|
||||
@@ -81,8 +82,8 @@ function turbinev.new(session_id, unit_id, advert, out_queue)
|
||||
length = 0,
|
||||
width = 0,
|
||||
height = 0,
|
||||
min_pos = 0,
|
||||
max_pos = 0,
|
||||
min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
|
||||
max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
|
||||
blades = 0,
|
||||
coils = 0,
|
||||
vents = 0,
|
||||
@@ -101,7 +102,7 @@ function turbinev.new(session_id, unit_id, advert, out_queue)
|
||||
dumping_mode = DUMPING_MODE.IDLE ---@type DUMPING_MODE
|
||||
},
|
||||
tanks = {
|
||||
steam = 0,
|
||||
steam = { type = "mekanism:empty_gas", amount = 0 }, ---@type tank_fluid
|
||||
steam_need = 0,
|
||||
steam_fill = 0.0,
|
||||
energy = 0,
|
||||
@@ -163,9 +164,17 @@ function turbinev.new(session_id, unit_id, advert, out_queue)
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
local txn_type = self.session.try_resolve(m_pkt)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
elseif txn_type == TXN_TYPES.FORMED then
|
||||
-- formed response
|
||||
-- load in data if correct length
|
||||
if m_pkt.length == 1 then
|
||||
self.db.formed = m_pkt.data[1]
|
||||
else
|
||||
log.debug(log_tag .. "MODBUS transaction reply length mismatch (" .. TXN_TAGS[txn_type] .. ")")
|
||||
end
|
||||
elseif txn_type == TXN_TYPES.BUILD then
|
||||
-- build response
|
||||
if m_pkt.length == 15 then
|
||||
|
||||
@@ -19,6 +19,7 @@ function txnctrl.new()
|
||||
local public = {}
|
||||
|
||||
local insert = table.insert
|
||||
local remove = table.remove
|
||||
|
||||
-- get the length of the transaction list
|
||||
function public.length()
|
||||
@@ -55,8 +56,9 @@ function txnctrl.new()
|
||||
|
||||
for i = 1, public.length() do
|
||||
if self.list[i].txn_id == txn_id then
|
||||
txn_type = self.list[i].txn_type
|
||||
self.list[i] = nil
|
||||
local entry = remove(self.list, i)
|
||||
txn_type = entry.txn_type
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local comms = require("scada-common.comms")
|
||||
local log = require("scada-common.log")
|
||||
local types = require("scada-common.types")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local txnctrl = require("supervisor.session.rtu.txnctrl")
|
||||
|
||||
@@ -57,7 +58,7 @@ function unit_session.new(unit_id, advert, out_queue, log_tag, txn_tags)
|
||||
if m_pkt.scada_frame.protocol() == PROTOCOLS.MODBUS_TCP then
|
||||
if m_pkt.unit_id == self.unit_id then
|
||||
local txn_type = self.transaction_controller.resolve(m_pkt.txn_id)
|
||||
local txn_tag = " (" .. self.txn_tags[txn_type] .. ")"
|
||||
local txn_tag = " (" .. util.strval(self.txn_tags[txn_type]) .. ")"
|
||||
|
||||
if bit.band(m_pkt.func_code, MODBUS_FCODE.ERROR_FLAG) ~= 0 then
|
||||
-- transaction incomplete or failed
|
||||
|
||||
Reference in New Issue
Block a user