[fluksod] fix bug in pulse logic
This commit is contained in:
parent
8b7cc4510a
commit
b69a4d5bdd
|
@ -82,7 +82,9 @@ function dispatch(wan_child, lan_child)
|
||||||
end
|
end
|
||||||
|
|
||||||
for line in delta.fdout:linesource() do
|
for line in delta.fdout:linesource() do
|
||||||
|
if DEBUG then
|
||||||
print(line)
|
print(line)
|
||||||
|
end
|
||||||
|
|
||||||
local timestamp, data = line:match('^(%d+)%s+([%d%s]+)$')
|
local timestamp, data = line:match('^(%d+)%s+([%d%s]+)$')
|
||||||
timestamp = tonumber(timestamp)
|
timestamp = tonumber(timestamp)
|
||||||
|
@ -106,7 +108,7 @@ function dispatch(wan_child, lan_child)
|
||||||
coroutine.resume(lan_child, sensor_id, timestamp, extra)
|
coroutine.resume(lan_child, sensor_id, timestamp, extra)
|
||||||
|
|
||||||
elseif sensor_type == 'pulse' then
|
elseif sensor_type == 'pulse' then
|
||||||
coroutine.resume(lan_child, sensor_id, timestamp, nil, counter, extra)
|
coroutine.resume(lan_child, sensor_id, timestamp, false, counter, extra)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- check in the e branch whether the counter has increased, if not then discard
|
-- check in the e branch whether the counter has increased, if not then discard
|
||||||
|
@ -199,9 +201,10 @@ function lan_buffer(child)
|
||||||
|
|
||||||
if timestamp > TIMESTAMP_MIN and timestamp > (previous[sensor_id].timestamp or 0) then
|
if timestamp > TIMESTAMP_MIN and timestamp > (previous[sensor_id].timestamp or 0) then
|
||||||
if not power then -- we're dealing pulse message so first calculate power
|
if not power then -- we're dealing pulse message so first calculate power
|
||||||
if previous[sensor_id].msec and msec > prev[sensor_id].msec then
|
if previous[sensor_id].msec and msec > previous[sensor_id].msec then
|
||||||
power = math.floor(diff(previous[sensor_id].counter, counter) /
|
power = math.floor(diff(previous[sensor_id].counter, counter) /
|
||||||
diff(previous[sensor_id].msec, msec) * 3.6 * 10^6 + 0.5)
|
diff(previous[sensor_id].msec, msec) * 3.6 * 10^6 + 0.5)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if msec decreased, just update the value in the table
|
-- if msec decreased, just update the value in the table
|
||||||
|
@ -210,9 +213,11 @@ function lan_buffer(child)
|
||||||
previous[sensor_id].counter = counter
|
previous[sensor_id].counter = counter
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if power then
|
||||||
measurements:add(sensor_id, timestamp, power)
|
measurements:add(sensor_id, timestamp, power)
|
||||||
previous[sensor_id].timestamp = timestamp
|
previous[sensor_id].timestamp = timestamp
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if next(measurements) then --checking whether table is not empty
|
if next(measurements) then --checking whether table is not empty
|
||||||
coroutine.resume(child, measurements)
|
coroutine.resume(child, measurements)
|
||||||
|
|
Loading…
Reference in New Issue