Skip to content

Commit

Permalink
fix neey protocol to deal with extra response data
Browse files Browse the repository at this point in the history
  • Loading branch information
jblance authored Jan 15, 2025
1 parent 8242c57 commit 823d1f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions powermon/protocols/neey.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@
{"index": "battery_type", "description": "battery_type", "reading_type": ReadingType.MESSAGE, "response_type": ResponseType.STRING},
],
"test_responses": [
b'U\xaa\x11\x01\x04\x00d\x00\x10\n\xd7\xa3;\x00\x00\x80@\x00\x00 @\x01\x01\x02\x18\x01\x00\x00ff&@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb7\xff'
b'U\xaa\x11\x01\x04\x00d\x00\x10\n\xd7\xa3;\x00\x00\x80@\x00\x00 @\x01\x01\x02\x18\x01\x00\x00ff&@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb7\xff',
b"U\xaa\x11\x01\x04\x00d\x00\x10\n\xd7\xa3;\x00\x00\x80@\x00\x00 @\x00\x01\x02,\x01\x00\x00ff&@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xffU\xaa\x11\x01\x02\x00,\x01:\x80\x18V@\x93\xa6\\@t\xbf[@W\xfbX@\xac\x85[@\x80\x18V@\x87CV@\xf3\'\\@\t\x91Z@\xb6\xafV@}LY@\xc7XY@\x18\x84X@\xd7\xf5Z@i\xa4[@\xc3\x12]@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xee\x971>b9;>m\x852>\xb5\xf00>\x14R0>\xd1s3>\x86d5>\xdb\xaf7>f\xf7:>,\xa8@>\xb3)@>\x86\xcd=>\xf2W8>\xd3~3>\x19c1>^\xfe.>\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa\xb9YB\xaa\xb9Y@`H\xdf=\x0f\x05\x0f\x04\x00\x00\x00\x00H\xe1\xf0AH\xe1\xf0A\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|!\xcf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00+\xff",
],
},
}
Expand Down Expand Up @@ -649,8 +650,12 @@ def check_crc(self, response: str, command_definition: CommandDefinition = None)
def trim_response(self, response: str, command_definition: CommandDefinition = None) -> str:
""" Remove extra characters from response """
log.debug("response: %s", response)
last_frame = response.rfind(b'U\xaa')
return response[last_frame:]
if response.count(b'U\xaa') > 1:
command_bytes = cs.Int16ul.build(int(command_definition.command_code))
for frame in response.split(b'U\xaa'):
if frame[2:4] == command_bytes:
return b'U\xaa' + frame
return response

def split_response(self, response: str, command_definition: CommandDefinition = None) -> list:
""" split response into individual items, return as ordered list or list of tuples """
Expand Down
3 changes: 2 additions & 1 deletion tests/config/ble_neey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ device:
port:
type: test
protocol: NEEY
response_number: 1

commands:
- command: factory_defaults
- command: settings
outputs:
- type: screen
format:
Expand Down

0 comments on commit 823d1f1

Please sign in to comment.