mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-09 16:21:13 +00:00
more debug
This commit is contained in:
1 parent
185ee01ca0
commit
6499d97709
1 file changed
+15
-9
@@ -12,6 +12,7 @@ require "stdlib" .include { "seq", "list" }
|
|||||||
require "posix"
|
require "posix"
|
||||||
require "socket"
|
require "socket"
|
||||||
require "Class"
|
require "Class"
|
||||||
|
require "trace"
|
||||||
local NIL = Class.NIL
|
local NIL = Class.NIL
|
||||||
local list = _G.list
|
local list = _G.list
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ local DutyCycle = Class(nil, "DutyCycle", {
|
|||||||
|
|
||||||
function DutyCycle.new(class, port, pfx)
|
function DutyCycle.new(class, port, pfx)
|
||||||
local now = getMsecs()
|
local now = getMsecs()
|
||||||
return class:_new { mPort = port, mPrefix = pfx , mTail = tnew{}, mLastLog = now }
|
return class:_new():_merge { mPort = port, mPrefix = pfx , mTail = tnew{}, mLastLog = now }
|
||||||
end
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -45,7 +46,7 @@ function DutyCycle:add(str)
|
|||||||
local start = now - math.floor(self.mInterval * 1000)
|
local start = now - math.floor(self.mInterval * 1000)
|
||||||
local tail = self.mTail
|
local tail = self.mTail
|
||||||
while #tail > 0 and tail[#tail].t < start do tail:remove() end
|
while #tail > 0 and tail[#tail].t < start do tail:remove() end
|
||||||
self.mTail:insert(1, {t = now, s = str:sub(1,5), l = #str})
|
self.mTail:insert(1, {t = now, s = str:sub(1,6), l = #str})
|
||||||
|
|
||||||
if self.mLastLog < start then
|
if self.mLastLog < start then
|
||||||
local sum, sums = 0, {}
|
local sum, sums = 0, {}
|
||||||
@@ -55,7 +56,7 @@ function DutyCycle:add(str)
|
|||||||
end
|
end
|
||||||
local names = List(seq.all_keys(sums)):sort()
|
local names = List(seq.all_keys(sums)):sort()
|
||||||
log.notice(("PORT:%-12s %s:%3d%% %3d %s"):_(self.mPort.mName, self.mPrefix,
|
log.notice(("PORT:%-12s %s:%3d%% %3d %s"):_(self.mPort.mName, self.mPrefix,
|
||||||
idiv(self.mPort.mSpeed * 10, sum), sum,
|
idiv(sum * 1000, self.mPort.mSpeed), sum,
|
||||||
List(seq.map(|n|("%s:%d"):_(n, sums[n]), list.iter(names))):concat(",")))
|
List(seq.map(|n|("%s:%d"):_(n, sums[n]), list.iter(names))):concat(",")))
|
||||||
self.mLastLog = now
|
self.mLastLog = now
|
||||||
end
|
end
|
||||||
@@ -134,8 +135,8 @@ end
|
|||||||
---
|
---
|
||||||
-- Startup system interaction
|
-- Startup system interaction
|
||||||
function NmeaNode:start(str)
|
function NmeaNode:start(str)
|
||||||
for _,s in ipairs(self.mInputs or {}) do
|
for ix,s in ipairs(self.mInputs or {}) do
|
||||||
assert(nodes[s], ("No input: %s"):_(s)):addSink(self)
|
assert(nodes[s], ("No input: %s"):_(s)):addSink(self, ix)
|
||||||
end
|
end
|
||||||
if not self.mPortNo then return end
|
if not self.mPortNo then return end
|
||||||
|
|
||||||
@@ -188,7 +189,7 @@ end
|
|||||||
-- Startup system interaction
|
-- Startup system interaction
|
||||||
function NmeaOutput:start(str)
|
function NmeaOutput:start(str)
|
||||||
NmeaOutput:getSuper().start(self, str)
|
NmeaOutput:getSuper().start(self, str)
|
||||||
self:addSink(nodes[self.mOutput])
|
self:addSink(nodes[self.mOutput], 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
@@ -299,7 +300,7 @@ end
|
|||||||
-- Data forwarding
|
-- Data forwarding
|
||||||
function NmeaPort:processInput(str)
|
function NmeaPort:processInput(str)
|
||||||
self.mDutyOut:add(str)
|
self.mDutyOut:add(str)
|
||||||
log.notice(||("OUTP:%-12s W: %t"):_(self.mName, str))
|
log.debug(||("OUTP:%-12s W: %t"):_(self.mName, str))
|
||||||
posix.write(self.mSerialPort:getfd(), str.."\r\n")
|
posix.write(self.mSerialPort:getfd(), str.."\r\n")
|
||||||
-- if self.mLineBuffer then sysmon:addOut(self, str:sub(1,6)) end
|
-- if self.mLineBuffer then sysmon:addOut(self, str:sub(1,6)) end
|
||||||
end
|
end
|
||||||
@@ -382,7 +383,7 @@ end
|
|||||||
function NmeaFilter:passItOn(str, ix)
|
function NmeaFilter:passItOn(str, ix)
|
||||||
if self.mPrioTout then
|
if self.mPrioTout then
|
||||||
local now = getMsecs()
|
local now = getMsecs()
|
||||||
local stmt = str:sub(1,5)
|
local stmt = str:sub(1,6)
|
||||||
local old = self.mPrioList[stmt]
|
local old = self.mPrioList[stmt]
|
||||||
if old and (now - old.timeStamp) < self.mPrioTout and old.prio < ix then
|
if old and (now - old.timeStamp) < self.mPrioTout and old.prio < ix then
|
||||||
log.debug(||("TREJ:%-12s READ: %t"):_(self.mName, str))
|
log.debug(||("TREJ:%-12s READ: %t"):_(self.mName, str))
|
||||||
@@ -565,6 +566,7 @@ local function runGC()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function main(args)
|
local function main(args)
|
||||||
|
--trace.on()
|
||||||
local conf = getConf() or testConf or sampleConf
|
local conf = getConf() or testConf or sampleConf
|
||||||
configure(conf)
|
configure(conf)
|
||||||
startMonitor(117)
|
startMonitor(117)
|
||||||
@@ -573,7 +575,11 @@ local function main(args)
|
|||||||
if not log.debug() and args[1] and args[1] == "trace" then
|
if not log.debug() and args[1] and args[1] == "trace" then
|
||||||
local traceLog = log.create("nmeamux-trace.log", 0, false, 8000)
|
local traceLog = log.create("nmeamux-trace.log", 0, false, 8000)
|
||||||
log.debugonly = function() end
|
log.debugonly = function() end
|
||||||
log.debug = function(str) if not str then return false end return traceLog:log(str) end
|
log.debug = function(str)
|
||||||
|
if not str then return false end
|
||||||
|
if type(str) == "function" then str = str() end
|
||||||
|
return traceLog:log(str)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
log.debugonly = log.debug
|
log.debugonly = log.debug
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user