New smartmeter
This commit is contained in:
@@ -8,14 +8,14 @@ class ConfirmingSyncPatternState < StatePattern::State
|
||||
while (idx < bytes.length && idx < sync_length && bytes[idx] == Synchronizer::SYNC_PATTERN[idx]) do idx = idx+1 end
|
||||
|
||||
if (idx == sync_length)
|
||||
#p "Sync pattern confirmed"
|
||||
p "Sync pattern confirmed"
|
||||
transition_to(InSyncState)
|
||||
else
|
||||
#p "Back to SearchingForSync state. idx = #{idx}."
|
||||
p "Back to SearchingForSync state. idx = #{idx}."
|
||||
transition_to(SearchingForSyncState)
|
||||
end
|
||||
|
||||
# return the rest
|
||||
return bytes[idx+1..-1] || ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ require "socket"
|
||||
|
||||
class InSyncState < StatePattern::State
|
||||
|
||||
END_OF_FRAME = "!\n"
|
||||
END_OF_FRAME = "!****\n"
|
||||
|
||||
# def initialize(stateful, previous_state)
|
||||
# # open socket to EmonHub
|
||||
@@ -42,7 +42,8 @@ class InSyncState < StatePattern::State
|
||||
private
|
||||
def new_frame_starts(bytes,idx,sync_pattern_length)
|
||||
#return bytes[idx..idx+sync_pattern_length-1].eql?(Synchronizer::SYNC_PATTERN)
|
||||
return bytes[idx..idx+sync_pattern_length-1].eql?(END_OF_FRAME)
|
||||
#return bytes[idx..idx+sync_pattern_length-1].eql?(END_OF_FRAME)
|
||||
return bytes[idx].eql?(END_OF_FRAME[0])
|
||||
end
|
||||
|
||||
def handle_frame(frame_lines)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
class Synchronizer
|
||||
include StatePattern
|
||||
|
||||
SYNC_PATTERN = "\n/ISk5\\2ME382-1003\n\n"
|
||||
SYNC_PATTERN = "/CTA5ZIV\-METER\n\n"
|
||||
#SYNC_PATTERN = "\n/ISk5\\2ME382-1003\n\n"
|
||||
|
||||
set_initial_state ::SearchingForSyncState
|
||||
|
||||
|
||||
@@ -3,14 +3,21 @@ UNKNOWN_READING = { :total_kwh_consumed_high => nil, :total_kwh_consumed_low =>
|
||||
|
||||
|
||||
class Reading < ActiveRecord::Base
|
||||
|
||||
|
||||
# Round up with 1 (default) decimals
|
||||
def round_up(number, decimals = 1)
|
||||
factor = 10 ** decimals
|
||||
(number * factor).ceil / factor.to_f
|
||||
end
|
||||
|
||||
|
||||
def eql_reading?(reading)
|
||||
self.total_kwh_consumed_high == reading.total_kwh_consumed_high &&
|
||||
self.total_kwh_consumed_low == reading.total_kwh_consumed_low &&
|
||||
self.total_kwh_produced_high == reading.total_kwh_produced_high &&
|
||||
self.total_kwh_produced_low == reading.total_kwh_produced_low &&
|
||||
self.current_kw_consumed == reading.current_kw_consumed &&
|
||||
self.current_kw_produced == reading.current_kw_produced &&
|
||||
round_up(self.current_kw_consumed) == round_up(reading.current_kw_consumed) &&
|
||||
round_up(self.current_kw_produced) == round_up(reading.current_kw_produced) &&
|
||||
self.total_m3_gas_consumed == reading.total_m3_gas_consumed &&
|
||||
self.high_tarif == reading.high_tarif
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user