more debug

This commit is contained in:
madsenco
2011-03-24 07:08:41 +01:00
parent 185ee01ca0
commit 6499d97709
+15 -9
View File
@@ -12,6 +12,7 @@ require "stdlib" .include { "seq", "list" }
require "posix"
require "socket"
require "Class"
require "trace"
local NIL = Class.NIL
local list = _G.list
@@ -35,7 +36,7 @@ local DutyCycle = Class(nil, "DutyCycle", {
function DutyCycle.new(class, port, pfx)
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
---
@@ -45,7 +46,7 @@ function DutyCycle:add(str)
local start = now - math.floor(self.mInterval * 1000)
local tail = self.mTail
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
local sum, sums = 0, {}
@@ -55,7 +56,7 @@ function DutyCycle:add(str)
end
local names = List(seq.all_keys(sums)):sort()
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(",")))
self.mLastLog = now
end
@@ -134,8 +135,8 @@ end
---
-- Startup system interaction
function NmeaNode:start(str)
for _,s in ipairs(self.mInputs or {}) do
assert(nodes[s], ("No input: %s"):_(s)):addSink(self)
for ix,s in ipairs(self.mInputs or {}) do
assert(nodes[s], ("No input: %s"):_(s)):addSink(self, ix)
end
if not self.mPortNo then return end
@@ -188,7 +189,7 @@ end
-- Startup system interaction
function NmeaOutput:start(str)
NmeaOutput:getSuper().start(self, str)
self:addSink(nodes[self.mOutput])
self:addSink(nodes[self.mOutput], 1)
end
--------------------------------------------------------------------
@@ -299,7 +300,7 @@ end
-- Data forwarding
function NmeaPort:processInput(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")
-- if self.mLineBuffer then sysmon:addOut(self, str:sub(1,6)) end
end
@@ -382,7 +383,7 @@ end
function NmeaFilter:passItOn(str, ix)
if self.mPrioTout then
local now = getMsecs()
local stmt = str:sub(1,5)
local stmt = str:sub(1,6)
local old = self.mPrioList[stmt]
if old and (now - old.timeStamp) < self.mPrioTout and old.prio < ix then
log.debug(||("TREJ:%-12s READ: %t"):_(self.mName, str))
@@ -565,6 +566,7 @@ local function runGC()
end
local function main(args)
--trace.on()
local conf = getConf() or testConf or sampleConf
configure(conf)
startMonitor(117)
@@ -573,7 +575,11 @@ local function main(args)
if not log.debug() and args[1] and args[1] == "trace" then
local traceLog = log.create("nmeamux-trace.log", 0, false, 8000)
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
log.debugonly = log.debug
end