#32 new threaded PLC code

This commit is contained in:
Mikayla Fischler
2022-04-27 12:21:10 -04:00
parent f7f723829c
commit 68011d6734
7 changed files with 210 additions and 132 deletions

59
scada-common/mqueue.lua Normal file
View File

@@ -0,0 +1,59 @@
--
-- Message Queue
--
TYPE = {
COMMAND = 0,
DATA = 1,
PACKET = 2
}
function new()
local queue = {}
local length = function ()
return #queue
end
local empty = function ()
return #queue == 0
end
local ready = function ()
return #queue > 0
end
local _push = function (qtype, message)
table.insert(queue, { qtype = qtype, message = message })
end
local push_command = function (message)
_push(TYPE.COMMAND, message)
end
local push_data = function (message)
_push(TYPE.DATA, message)
end
local push_packet = function (message)
_push(TYPE.PACKET, message)
end
local pop = function ()
if #queue > 0 then
return table.remove(queue)
else
return nil
end
end
return {
length = length,
empty = empty,
ready = ready,
push_packet = push_packet,
push_data = push_data,
push_command = push_command,
pop = pop
}
end

View File

@@ -39,9 +39,10 @@ end
-- PARALLELIZATION --
-- block waiting for parallel call
function async_wait(f)
parallel.waitForAll(f)
-- no-op to provide a brief pause (and a yield)
-- EVENT_CONSUMER: this function consumes events
function nop()
sleep(0.05)
end
-- WATCHDOG --