Merge branch 'devel' into 225-consolidate-network-channels

This commit is contained in:
Mikayla Fischler
2023-06-05 01:18:13 -04:00
95 changed files with 2338 additions and 847 deletions

View File

@@ -2,6 +2,8 @@
-- Publisher-Subscriber Interconnect Layer
--
local util = require("scada-common.util")
local psil = {}
-- instantiate a new PSI layer
@@ -36,6 +38,15 @@ function psil.create()
table.insert(self.ic[key].subscribers, { notify = func })
end
-- unsubscribe a function from a given key
---@param key string data key
---@param func function function to unsubscribe
function public.unsubscribe(key, func)
if self.ic[key] ~= nil then
util.filter_table(self.ic[key].subscribers, function (s) return s.notify ~= func end)
end
end
-- publish data to a given key, passing it to all subscribers if it has changed
---@param key string data key
---@param value any data value
@@ -64,6 +75,9 @@ function psil.create()
end
end
-- clear the contents of the interconnect
function public.purge() self.ic = nil end
return public
end

View File

@@ -5,14 +5,14 @@
local log = require("scada-common.log")
local util = require("scada-common.util")
local tcallbackdsp = {}
local tcd = {}
local registry = {}
-- request a function to be called after the specified time
---@param time number seconds
---@param f function callback function
function tcallbackdsp.dispatch(time, f)
function tcd.dispatch(time, f)
local timer = util.start_timer(time)
registry[timer] = {
callback = f,
@@ -24,7 +24,7 @@ end
-- request a function to be called after the specified time, aborting any registered instances of that function reference
---@param time number seconds
---@param f function callback function
function tcallbackdsp.dispatch_unique(time, f)
function tcd.dispatch_unique(time, f)
-- cancel if already registered
for timer, entry in pairs(registry) do
if entry.callback == f then
@@ -47,7 +47,7 @@ end
-- abort a requested callback
---@param f function callback function
function tcallbackdsp.abort(f)
function tcd.abort(f)
for timer, entry in pairs(registry) do
if entry.callback == f then
-- cancel event and remove from registry (even if it fires it won't call)
@@ -59,7 +59,7 @@ end
-- lookup a timer event and execute the callback if found
---@param event integer timer event timer ID
function tcallbackdsp.handle(event)
function tcd.handle(event)
if registry[event] ~= nil then
local callback = registry[event].callback
-- clear first so that dispatch_unique call from inside callback won't throw a debug message
@@ -70,7 +70,7 @@ end
-- identify any overdo callbacks<br>
-- prints to log debug output
function tcallbackdsp.diagnostics()
function tcd.diagnostics()
for timer, entry in pairs(registry) do
if entry.expiry < util.time_s() then
local overtime = util.time_s() - entry.expiry
@@ -82,4 +82,4 @@ function tcallbackdsp.diagnostics()
end
end
return tcallbackdsp
return tcd

View File

@@ -39,6 +39,10 @@ function types.new_radiation_reading(r, u) return { radiation = r, unit = u } en
---@return radiation_reading
function types.new_zero_radiation_reading() return { radiation = 0, unit = "nSv" } end
---@class coordinate_2d
---@field x integer
---@field y integer
---@class coordinate
---@field x integer
---@field y integer