mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
added time functions to util, also task_wait
This commit is contained in:
parent
1744527a41
commit
c46a7b2486
@ -1,5 +1,6 @@
|
||||
-- #REQUIRES comms.lua
|
||||
-- #REQUIRES ppm.lua
|
||||
-- #REQUIRES util.lua
|
||||
|
||||
local PROTOCOLS = comms.PROTOCOLS
|
||||
local RPLC_TYPES = comms.RPLC_TYPES
|
||||
@ -272,7 +273,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
|
||||
-- keep alive ack
|
||||
local _send_keep_alive_ack = function (srv_time)
|
||||
_send(RPLC_TYPES.KEEP_ALIVE, { srv_time, os.epoch() })
|
||||
_send(RPLC_TYPES.KEEP_ALIVE, { srv_time, util.time() })
|
||||
end
|
||||
|
||||
-- general ack
|
||||
@ -369,7 +370,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
if packet.type == RPLC_TYPES.KEEP_ALIVE then
|
||||
-- keep alive request received, echo back
|
||||
local timestamp = packet.data[1]
|
||||
local trip_time = os.epoch() - timestamp
|
||||
local trip_time = util.time() - timestamp
|
||||
|
||||
if trip_time < 0 then
|
||||
log._warning("PLC KEEP_ALIVE trip time less than 0 (" .. trip_time .. ")")
|
||||
@ -494,7 +495,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
end
|
||||
|
||||
local sys_status = {
|
||||
os.epoch(),
|
||||
util.time(),
|
||||
(not self.scrammed),
|
||||
overridden,
|
||||
degraded,
|
||||
|
@ -1,3 +1,5 @@
|
||||
-- #REQUIRES util.lua
|
||||
|
||||
SEVERITY = {
|
||||
INFO = 0, -- basic info message
|
||||
WARNING = 1, -- warning about some abnormal state
|
||||
@ -9,7 +11,7 @@ SEVERITY = {
|
||||
|
||||
function scada_alarm(severity, device, message)
|
||||
local self = {
|
||||
time = os.epoch(),
|
||||
time = util.time(),
|
||||
ts_string = os.date("[%H:%M:%S]"),
|
||||
severity = severity,
|
||||
device = device,
|
||||
|
@ -1,3 +1,5 @@
|
||||
-- PRINT --
|
||||
|
||||
-- we are overwriting 'print' so save it first
|
||||
local _print = print
|
||||
|
||||
@ -21,6 +23,28 @@ function println_ts(message)
|
||||
_print(os.date("[%H:%M:%S] ") .. message)
|
||||
end
|
||||
|
||||
-- TIME --
|
||||
|
||||
function time_ms()
|
||||
return os.epoch('local')
|
||||
end
|
||||
|
||||
function time_s()
|
||||
return os.epoch('local') / 1000
|
||||
end
|
||||
|
||||
function time()
|
||||
return time_ms()
|
||||
end
|
||||
|
||||
-- PARALLELIZATION --
|
||||
|
||||
-- block waiting for parallel call
|
||||
function task_wait(f)
|
||||
parallel.waitForAll(f)
|
||||
end
|
||||
|
||||
-- WATCHDOG --
|
||||
|
||||
-- ComputerCraft OS Timer based Watchdog
|
||||
-- triggers a timer event if not fed within 'timeout' seconds
|
||||
|
@ -185,7 +185,7 @@ function new_session(id, for_reactor, in_queue, out_queue)
|
||||
if rplc_pkt.length == 2 then
|
||||
local srv_start = rplc_pkt.data[1]
|
||||
local plc_send = rplc_pkt.data[2]
|
||||
local srv_now = os.epoch()
|
||||
local srv_now = util.time()
|
||||
self.last_rtt = srv_now - srv_start
|
||||
|
||||
if self.last_rtt < 0 then
|
||||
@ -351,7 +351,7 @@ function new_session(id, for_reactor, in_queue, out_queue)
|
||||
self.periodics.keep_alive = self.periodics.keep_alive + elapsed
|
||||
|
||||
if self.periodics.keep_alive >= PERIODICS.KEEP_ALIVE then
|
||||
_send(RPLC_TYPES.KEEP_ALIVE, { os.epoch() })
|
||||
_send(RPLC_TYPES.KEEP_ALIVE, { util.time() })
|
||||
self.periodics.keep_alive = 0
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user