First parsing of frame

This commit is contained in:
Aart van Halteren
2013-06-26 17:46:21 -04:00
parent 6443d70bcf
commit bdcf92211f
4 changed files with 28 additions and 4 deletions

View File

@@ -20,8 +20,9 @@ class InSyncState < StatePattern::State
if new_frame_starts(bytes,idx,sync_pattern_length)
p "------ FRAME -----"
frame_lines = frame.split("\n")
p frame_lines # should call to higher level
p frame_lines
p "##################"
handle_frame(frame_lines)
return bytes[idx+sync_pattern_length..-1]
else
return nil
@@ -34,4 +35,25 @@ class InSyncState < StatePattern::State
#return bytes[idx..idx+sync_pattern_length-1].eql?(Synchronizer::SYNC_PATTERN)
return bytes[idx..idx+sync_pattern_length-1].eql?(END_OF_FRAME)
end
def handle_frame(frame_lines)
frame_lines.each {| line|
if line.match(/1.8.1/)
total_kwh_consumed_high = line.split(/1-0:1.8.1\(|\*kWh\)/).join.to_f
p "Total kwh consumed (high): #{total_kwh_consumed_high}."
end
if line.match(/1.8.2/)
total_kwh_consumed_high = line.split(/1-0:1.8.2\(|\*kWh\)/).join.to_f
p "Total kwh consumed (low): #{total_kwh_consumed_high}."
end
if line.match(/2.8.1/)
total_kwh_produced_high = line.split(/1-0:2.8.1\(|\*kWh\)/).join.to_f
p "Total kwh consumed (high): #{total_kwh_produced_high}."
end
if line.match(/2.8.2/)
total_kwh_produced_low = line.split(/1-0:2.8.2\(|\*kWh\)/).join.to_f
p "Total kwh consumed (low): #{total_kwh_produced_low}."
end
}
end
end