New smartmeter

This commit is contained in:
2025-07-16 15:20:39 +02:00
parent abe9328460
commit 40d4956be3
7 changed files with 22 additions and 14 deletions

View File

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

View File

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

View File

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