#8 RTU session for emachine and turbine, RTU session creation, adjusted sequence number logic in svsessions

This commit is contained in:
Mikayla Fischler
2022-05-13 09:45:11 -04:00
parent 635e7b7f59
commit fc39588b2e
7 changed files with 525 additions and 66 deletions

View File

@@ -1,7 +1,6 @@
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")
@@ -25,16 +24,17 @@ local PERIODICS = {
}
-- create a new boiler rtu session runner
---@param session_id integer
---@param advert rtu_advertisement
---@param out_queue mqueue
boiler.new = function (advert, out_queue)
boiler.new = function (session_id, advert, out_queue)
-- type check
if advert.type ~= rtu_t.boiler then
log.error("attempt to instantiate boiler RTU for non boiler type '" .. advert.type .. "'. this is a bug.")
log.error("attempt to instantiate boiler RTU for type '" .. advert.type .. "'. this is a bug.")
return nil
end
local log_tag = "session.rtu.boiler(" .. advert.index .. "): "
local log_tag = "session.rtu(" .. session_id .. ").boiler(" .. advert.index .. "): "
local self = {
uid = advert.index,
@@ -69,52 +69,46 @@ boiler.new = function (advert, out_queue)
water = 0,
water_need = 0,
water_fill = 0.0,
hcool = 0,
hcool = {}, ---@type tank_fluid
hcool_need = 0,
hcool_fill = 0.0,
ccool = 0,
ccool = {}, ---@type tank_fluid
ccool_need = 0,
ccool_fill = 0.0
}
}
}
---@class rtu_session__boiler
---@class rtu_session_unit
local public = {}
-- PRIVATE FUNCTIONS --
-- query the build of the device
local _request_build = function ()
local _send_request = function (txn_type, f_code, register_range)
local m_pkt = comms.modbus_packet()
local txn_id = self.transaction_controller.create(TXN_TYPES.BUILD)
local txn_id = self.transaction_controller.create(txn_type)
-- read input registers 1 through 7 (start = 1, count = 7)
m_pkt.make(txn_id, self.uid, MODBUS_FCODE.READ_INPUT_REGS, { 1, 7 })
m_pkt.make(txn_id, self.uid, f_code, register_range)
self.out_q.push_packet(m_pkt)
end
-- query the build of the device
local _request_build = function ()
-- read input registers 1 through 7 (start = 1, count = 7)
_send_request(TXN_TYPES.BUILD, MODBUS_FCODE.READ_INPUT_REGS, { 1, 7 })
end
-- query the state of the device
local _request_state = function ()
local m_pkt = comms.modbus_packet()
local txn_id = self.transaction_controller.create(TXN_TYPES.STATE)
-- read input registers 8 through 9 (start = 8, count = 2)
m_pkt.make(txn_id, self.uid, MODBUS_FCODE.READ_INPUT_REGS, { 8, 2 })
self.out_q.push_packet(m_pkt)
_send_request(TXN_TYPES.STATE, MODBUS_FCODE.READ_INPUT_REGS, { 8, 2 })
end
-- query the tanks of the device
local _request_tanks = function ()
local m_pkt = comms.modbus_packet()
local txn_id = self.transaction_controller.create(TXN_TYPES.TANKS)
-- read input registers 10 through 21 (start = 10, count = 12)
m_pkt.make(txn_id, self.uid, MODBUS_FCODE.READ_INPUT_REGS, { 10, 12 })
self.out_q.push_packet(m_pkt)
_send_request(TXN_TYPES.TANKS, MODBUS_FCODE.READ_INPUT_REGS, { 10, 12 })
end
-- PUBLIC FUNCTIONS --