#64 supervisor code cleanup
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
local comms = require("scada-common.comms")
|
||||
local log = require("scada-common.log")
|
||||
local log = require("scada-common.log")
|
||||
local types = require("scada-common.types")
|
||||
|
||||
local unit_session = require("supervisor.session.rtu.unit_session")
|
||||
@@ -29,7 +29,7 @@ local PERIODICS = {
|
||||
---@param unit_id integer
|
||||
---@param advert rtu_advertisement
|
||||
---@param out_queue mqueue
|
||||
emachine.new = function (session_id, unit_id, advert, out_queue)
|
||||
function emachine.new(session_id, unit_id, advert, out_queue)
|
||||
-- type check
|
||||
if advert.type ~= RTU_UNIT_TYPES.EMACHINE then
|
||||
log.error("attempt to instantiate emachine RTU for type '" .. advert.type .. "'. this is a bug.")
|
||||
@@ -63,13 +63,13 @@ emachine.new = function (session_id, unit_id, advert, out_queue)
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
||||
-- query the build of the device
|
||||
local _request_build = function ()
|
||||
local function _request_build()
|
||||
-- read input register 1 (start = 1, count = 1)
|
||||
self.session.send_request(TXN_TYPES.BUILD, MODBUS_FCODE.READ_INPUT_REGS, { 1, 1 })
|
||||
end
|
||||
|
||||
-- query the state of the energy storage
|
||||
local _request_storage = function ()
|
||||
local function _request_storage()
|
||||
-- read input registers 2 through 4 (start = 2, count = 3)
|
||||
self.session.send_request(TXN_TYPES.STORAGE, MODBUS_FCODE.READ_INPUT_REGS, { 2, 3 })
|
||||
end
|
||||
@@ -78,7 +78,7 @@ emachine.new = function (session_id, unit_id, advert, out_queue)
|
||||
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
public.handle_packet = function (m_pkt)
|
||||
function public.handle_packet(m_pkt)
|
||||
local txn_type = self.session.try_resolve(m_pkt.txn_id)
|
||||
if txn_type == false then
|
||||
-- nothing to do
|
||||
@@ -107,7 +107,7 @@ emachine.new = function (session_id, unit_id, advert, out_queue)
|
||||
|
||||
-- update this runner
|
||||
---@param time_now integer milliseconds
|
||||
public.update = function (time_now)
|
||||
function public.update(time_now)
|
||||
if not self.has_build and self.periodics.next_build_req <= time_now then
|
||||
_request_build()
|
||||
self.periodics.next_build_req = time_now + PERIODICS.BUILD
|
||||
@@ -120,7 +120,7 @@ emachine.new = function (session_id, unit_id, advert, out_queue)
|
||||
end
|
||||
|
||||
-- get the unit session database
|
||||
public.get_db = function () return self.db end
|
||||
function public.get_db() return self.db end
|
||||
|
||||
return public
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user