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

refactor(ot3_state_manager): Rework messages #430

Merged

Conversation

DerekMaggio
Copy link
Contributor

@DerekMaggio DerekMaggio commented Aug 5, 2022

Overview

Each message is now mapped to an int value instead using arbitrary string parsing

Related Docs

Changelog

  • Remove to_message method from all Message classes
  • Changed format of messages. All message are now 4 bytes long and have the following format: <message-id><message-content> where the length of message-id is a single byte and the length of message-content is 3 bytes.
  • Replace to_message method and parse_message function with Message ABC.
    • Each concrete concrete class of Message is required to implement a build and to_bytes message
  • The _parse_message method looks at the message-id byte and based off of the value passes message-content to the build method of the appropriate concrete implementation of Message
  • Remove hashing of message value as response. Instead just return bytes value.
  • Update tests accordingly

Review Requests

None

Risk

None

@DerekMaggio DerekMaggio changed the title refactor: Rework messages refactor(ot3_state_manager): Rework messages Aug 5, 2022
@DerekMaggio DerekMaggio self-assigned this Aug 5, 2022
@DerekMaggio DerekMaggio marked this pull request as ready for review August 5, 2022 15:07
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to change the way we handle the byte strings here, but this is definitely on the right track

ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
@DerekMaggio
Copy link
Contributor Author

@sfoster1 is the format string <H correct? Do we actually want it to be Big Endian?

int_val = 0xFF00
print(struct.pack(">H", int_val))
print(struct.pack("<H", int_val))
>>> b'\xff\x00'
>>> b'\x00\xff'

With the way we have been talking about the messages, we want the message to be formatted like the first print statement (Little Endian)

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're almost there but there's a couple subtle changes we should make.

ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
@DerekMaggio
Copy link
Contributor Author

@sfoster1 I feel like I should pull the parse method out of the Message class and make it a pure function.
I don't think that the concrete implementations of the Message class should have access to the parse function since the parse function has a larger scope than the concrete class should have.

What do you think?

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much much better structurally but there's some things to fix up.

ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/messages.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/util.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/util.py Outdated Show resolved Hide resolved
ot3_state_manager/ot3_state_manager/util.py Outdated Show resolved Hide resolved
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - last review was supposed to be this status

@DerekMaggio DerekMaggio force-pushed the RET-1104-rework-ot3-state-manager-communication-layer branch from 5e9d5bd to 0839532 Compare August 9, 2022 19:06
P_L_AXIS = 0x0005, OT3Axis.P_L
P_R_AXIS = 0x0006, OT3Axis.P_R
G_AXIS = 0x0007, OT3Axis.G
Q_AXIS = 0x0008, OT3Axis.Q
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does Q axis represent here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my understanding, the Q axis is the high-throughput pipette axis.
https://github.com/Opentrons/opentrons/blob/edge/api/src/opentrons/hardware_control/types.py#L128

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Definitely the right way to do it, very solid

@DerekMaggio DerekMaggio merged commit c771b1f into main Aug 9, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants