openwrt: support pls xxx:yyy:zzz type messages with zzz = 32-bit millisec counter on the AVR

This commit is contained in:
Bart Van Der Meerssche 2010-09-05 00:42:33 +02:00
parent 431fefa5f2
commit 8f4e7a17a2
1 changed files with 28 additions and 16 deletions

View File

@ -41,42 +41,54 @@ local param = {xmlrpcaddress = 'http://logger.flukso.net/xmlrpc',
function dispatch(e_child, p_child, device, pwrenable) function dispatch(e_child, p_child, device, pwrenable)
return coroutine.create(function() return coroutine.create(function()
local function flash() -- flash the power led for 50ms
os.execute('gpioctl clear 4 > /dev/null')
socket.select(nil, nil, 0.05)
os.execute('gpioctl set 4 > /dev/null')
end
-- open the connection to the syslog deamon, specifying our identity -- open the connection to the syslog deamon, specifying our identity
posix.openlog('flukso') posix.openlog('flukso')
posix.syslog(30, 'starting the flukso deamon') posix.syslog(30, 'starting the flukso deamon')
posix.syslog(30, 'listening for pulses on '..device..'...') posix.syslog(30, 'listening for pulses on '..device..'...')
pattern = '^(%l+)%s(%x+):(%d+):?(%d*)$'
for line in io.lines(device) do for line in io.lines(device) do
if line:sub(1, 3) == 'pls' and line:len() == 47 and line:find(':') == 37 then -- user data + additional data integrity checks command, meter, value, millis = line:match(pattern)
length = line:len()
if command == 'pls' and (length == 47 or length == 58) then -- user data
flash()
posix.syslog(30, 'received pulse from ' .. device .. ': ' .. line:sub(5)) posix.syslog(30, 'received pulse from ' .. device .. ': ' .. line:sub(5))
-- flash the power led for 50ms coroutine.resume(e_child, meter, os.time(), tonumber(value))
os.execute('gpioctl clear 4 > /dev/null')
socket.select(nil, nil, 0.05)
os.execute('gpioctl set 4 > /dev/null')
local meter, value = line:sub(5, 36), tonumber(line:sub(38)) -- pls includes a msec timestamp so report to p_child as well
coroutine.resume(e_child, meter, os.time(), value) if length == 58 then
coroutine.resume(p_child, meter, os.time(), nil, tonumber(millis))
end
elseif line:sub(1, 3) == 'pwr' and line:len() == 47 and line:find(':') == 37 then -- user data + additional data integrity checks elseif command == 'pwr' and length == 47 then -- user data
local meter, value = line:sub(5, 36), tonumber(line:sub(38))
if pwrenable then coroutine.resume(p_child, meter, os.time(), value) end if pwrenable then coroutine.resume(p_child, meter, os.time(), value) end
elseif line:sub(1, 3) == 'msg' then -- control data elseif command == 'msg' then -- control data
posix.syslog(31, 'received message from ' .. device .. ': ' .. line:sub(5)) posix.syslog(31, 'received message from ' .. device .. ': ' .. line:sub(5))
else else -- error
posix.syslog(27, 'input error on ' .. device .. ': ' .. line) posix.syslog(27, 'input error on ' .. device .. ': ' .. line)
end end
end end
posix.syslog(30, 'closing down the flukso deamon') posix.syslog(30, 'closing down the flukso deamon')
os.exit() os.exit(1)
end) end)
end end
-- TODO: adapt for millis input
function buffer(child, interval) function buffer(child, interval)
return coroutine.create(function(meter, timestamp, value) return coroutine.create(function(meter, timestamp, value, millis)
local measurements = data.new() local measurements = data.new()
local threshold = timestamp + interval local threshold = timestamp + interval
local timestamp_prev = {} local timestamp_prev = {}