Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected payload passed to decode_message of core/protocol.py #9

Open
liquidg3 opened this issue Jun 1, 2023 · 1 comment
Open

Comments

@liquidg3
Copy link

liquidg3 commented Jun 1, 2023

status_info is NaN, throwing errors to log.

It seems to happen often when the battery is below 30% (solid amber battery indicator).

Added a log to decode_message at line 662 to print packets.
Added a log to SummaryDataMessageV3.__init at line 508 to print the parsed value set to status_info.

Any pointers on how to approach this?

2023-06-01 12:21:38,271 INFO: incoming summary data packet [111, 231, 7, 6, 1, 73, 14, 166, 2, 3, 66, 0, 110, 0, 70, 0, 1, 0, 7, 0, 10, 236, 53, 40, 25, 220, 0, 100, 128, 0, 97, 68, 0, 0, 254, 0, 12, 114, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 50, 0, 64, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 22, 0]


2023-06-01 12:21:38,271 INFO: status_info (nan)


2023-06-01 12:21:38,271 ERROR: Message with id 43 was corrupted: unsupported operand type(s) for &: 'float' and 'int'
Traceback (most recent call last):
  File "C:\Users\suppo\install\App-Zephyr\core\protocol.py", line 725, in decode_bytestream
    msg = decode_message(msgid, payload, fin)
  File "C:\Users\suppo\install\App-Zephyr\core\protocol.py", line 651, in decode_message
    return SummaryDataMessageV3(msgid, payload, fin)
  File "C:\Users\suppo\install\App-Zephyr\core\protocol.py", line 495, in __init__
    self._decode_status_info(status_info)
  File "C:\Users\suppo\install\App-Zephyr\core\protocol.py", line 396, in _decode_status_info
    self.device_worn_confidence = 1 - (status_info & 3)/3
TypeError: unsupported operand type(s) for &: 'float' and 'int'
@chkothe
Copy link
Member

chkothe commented Jun 1, 2023

Hey, this should be fairly straightforward to fix - the issue is that status_info is being set to nan (to signify an invalid value), which is a float. However, float's don't support integer ops like &.

So the fix there should be to condition this on whether status_info is nan. As in device_worn_confidence = 0 if math.isnan(status_info) else 1 - (status_info & 3)/3 -- however, I think there are several more places where this can occur when status_info is invalid, and I don't have a Zephyr at hand at this time to clean these issues out and re-test the result. If you can catch some of those and can confirm that the app survives status_info becoming nan, a small pull request would be appreciated! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants