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

Simplified UART has wrong byte format: int8 instead of uint8 #1366

Closed
antonvh opened this issue Jan 3, 2024 · 1 comment
Closed

Simplified UART has wrong byte format: int8 instead of uint8 #1366

antonvh opened this issue Jan 3, 2024 · 1 comment
Assignees
Labels
bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)

Comments

@antonvh
Copy link

antonvh commented Jan 3, 2024

After this commit, PUPDevice.write(1, (-127, -128, -126, -1, 127, 128, 129, 130) ) results in 7F, 7F, 81, FF, 7F, 7F, 7F

pybricks/pybricks-micropython@1ae92c3

So signed bytes become unsigned, every out-of-range number becomes 7F, and the number 128 is unreachable.

The code should probably have uint8 everywhere.

@laurensvalk laurensvalk transferred this issue from pybricks/pybricks-micropython Jan 3, 2024
@laurensvalk laurensvalk self-assigned this Jan 3, 2024
@laurensvalk laurensvalk added bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) labels Jan 3, 2024
@antonvh
Copy link
Author

antonvh commented Jan 16, 2024

Expected results for PUPDevice.write(1, (-129, -128, -127, -1, 127, 128, 129, 130) ) Two options.

  1. preferably uint8, this leads to the least byte conversion. The protocol here only mentions bytes, no int8: https://github.com/pybricks/technical-info/blob/master/uart-protocol.md
    ('0x00', '0x00', '0x00', '0x00', '0x7f', '0x80', '0x81', '0x82')

  2. alternatively int8, as is. BUT with (a) -128 reachable, (b) clamping down for numbers below -128, so -129 becomes -128 (0x80) and (c) raw bytes writing option.
    ['0x80', '0x80', '0x82', '0xff', '0x7f', '0x7f', '0x7f', '0x7f']

raw bytes:
PUPDevice.write(1, b'\x00\x01\x02' )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)
Projects
None yet
Development

No branches or pull requests

2 participants