give each sensor its own timestamp_prev to prevent starvation of second sensor in case of pwr messages

This commit is contained in:
Bart Van Der Meerssche 2010-04-22 16:35:46 +02:00
parent 0f2ad0b693
commit e953fb0245
1 changed files with 5 additions and 3 deletions

View File

@ -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