From e953fb0245903a92bef7c2d1fcff18be1bfd01d1 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Thu, 22 Apr 2010 16:35:46 +0200 Subject: [PATCH] give each sensor its own timestamp_prev to prevent starvation of second sensor in case of pwr messages --- openwrt/package/flukso/src/flukso.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openwrt/package/flukso/src/flukso.lua b/openwrt/package/flukso/src/flukso.lua index 93bc20b..339ac1c 100755 --- a/openwrt/package/flukso/src/flukso.lua +++ b/openwrt/package/flukso/src/flukso.lua @@ -78,14 +78,16 @@ function buffer(child, interval) return coroutine.create(function(meter, timestamp, value) local measurements = data.new() local threshold = timestamp + interval - local old_timestamp = 0 + local timestamp_prev = {} while true do - if meter ~= nil and timestamp > math.max(1234567890, old_timestamp) then measurements:add(meter, timestamp, value) end + if meter ~= nil and timestamp > math.max(1234567890, timestamp_prev[meter] or 0) then + measurements:add(meter, timestamp, value) + end if timestamp > threshold and next(measurements) then --checking whether table is not empty coroutine.resume(child, measurements) threshold = timestamp + interval - old_timestamp = timestamp + timestamp_prev[meter] = timestamp end meter, timestamp, value = coroutine.yield() end