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

Add Cyphal/serial #128

Merged
merged 6 commits into from
Jun 3, 2023
Merged

Add Cyphal/serial #128

merged 6 commits into from
Jun 3, 2023

Conversation

pavel-kirienko
Copy link
Member

Closes #99

@maksimdrachov
Copy link
Member

maksimdrachov commented May 12, 2023

Trying to test the example you gave here: https://github.com/maksimdrachov/test-serial-pr

Coming up with some inconsistency, the output of running this script:

serial_frame:  SerialFrame(priority=NOMINAL, transfer_id=0, index=0, end_of_transfer=True, payload=303132333435363738, source_node_id=1234, destination_node_id=1, data_specifier=MessageDataSpecifier(subject_id=1234), user_data=0)
memoryview_output:  b'\x00\x06\x01\x04\xd2\x04\x01\x03\xd2\x04\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x02\x80\x01\x0c\xbd\x88012345678\x00'
(starting delimiter) memoryview_bytes[0]:  b'\x00'
(COBS overhead byte) memoryview_bytes[1]:  b'\x06'
(header) memoryview_bytes[2:2+24]: 
b'\x01'
b'\x04'
b'\xd2'
b'\x04'
b'\x01'
b'\x03'
b'\xd2'
b'\x04'
b'\x01'
b'\x01'
b'\x01'
b'\x01'
b'\x01'
b'\x01'
b'\x01'
b'\x01'
b'\x01'
b'\x01'
b'\x02'
b'\x80'
b'\x01'
b'\x0c'
b'\xbd'
b'\x88'
(payload) memoryview_bytes[27:27+11]: 
b'1'
b'2'
b'3'
b'4'
b'5'
b'6'
b'7'
b'8'
b'\x00'
COBS-encoded transfer-CRC b''
Traceback (most recent call last):
  File "/Users/maksimdrachov/test-serial-pr/test-serial-pr.py", line 72, in <module>
    "(ending delimiter) memoryview_bytes[44]: ", memoryview_bytes[44].to_bytes(1, "big")
                                                 ~~~~~~~~~~~~~~~~^^^^
IndexError: index out of range

Is it because pycyphal/serial hasn't been updated yet to reflect this new part? (No issue for this can be found tho)

Note: I think you forgot to mention which destination_node_id is used?

@pavel-kirienko
Copy link
Member Author

There might be an off-by-one error in your snippet. You can try and cross-validate it using these instructions:

% $ ncat --broker --listen -p 50905 -vv
%
% $ nc localhost 50905 | xxd -g1
%
% $ export UAVCAN__SERIAL__IFACE='socket://127.0.0.1:50905'
% $ export UAVCAN__NODE__ID=1234
% $ y pub -N1 1234:uavcan.primitive.string '"012345678"'

@maksimdrachov
Copy link
Member

If it's not using pycyphal I'm not interested.

@maksimdrachov
Copy link
Member

Using Yakut:

image

image

Seems to aling.

@maksimdrachov
Copy link
Member

Second example, using yakut:

image

image

Doing something wrong here?

@pavel-kirienko
Copy link
Member Author

pavel-kirienko commented May 12, 2023 via email

@maksimdrachov
Copy link
Member

After re-sending the same empty message:

image

@pavel-kirienko
Copy link
Member Author

The pointed-to element corresponds to the source node-ID, which is 1234 = 0x04d2.

@maksimdrachov
Copy link
Member

image

@pavel-kirienko
Copy link
Member Author

Ah, good catch! I changed the source node-ID to 4321 but failed to reflect this in the text. Fix incoming.

@maksimdrachov
Copy link
Member

Ah, good catch! I changed the source node-ID to 4321 but failed to reflect this in the text. Fix incoming.

image

@maksimdrachov
Copy link
Member

maksimdrachov commented May 12, 2023

The ones marked in purple are also different from the text:

image

Looks like the first 2 need to be switched around?

Using this:

image

@pavel-kirienko
Copy link
Member Author

If you could just push a commit updating the examples that would be dandy

@maksimdrachov
Copy link
Member

maksimdrachov commented May 12, 2023

Ok!

That's assuming the yakut one is correct? (It's using pycyphal under the hood?)

I still wanna try with strictly pycyphal.

@pavel-kirienko
Copy link
Member Author

Yes, Yakut uses PyCyphal under the hood.

@maksimdrachov
Copy link
Member

maksimdrachov commented May 12, 2023

I think there's some issue with the current implementation of pycyphal. Resulting in a different result between yakut (which is using an older version) and pycyphal.

See unit test in version 1.8:

https://github.com/OpenCyphal/pycyphal/blob/d2a7eb923bd8cbeb941e9032494ade48e755654e/pycyphal/transport/serial/_frame.py#L199-L237

And compare with unit test in the latest version:

https://github.com/OpenCyphal/pycyphal/blob/4f56e6518194268c7a6ae6c4b232e5a7aead7005/pycyphal/transport/serial/_frame.py#L230-L268

I have updated the script here and even the length of the resulting frame is shorter (36 vs 42)

@maksimdrachov
Copy link
Member

image image

@maksimdrachov
Copy link
Member

Ok, I have taken a look at how the pub functionality is implemented in yakut.

It calls send() on SerialOutputSession (which makes sense).

Now in pycyphal/serial, there seem to be 2 different implementations of send, which was what caused my initial confusion (see send_tranfer() in SerialTransport).

Two methods next to each other:

image

I checked in UDPTransport and it doesn't have any methods related to sending. Can you comment on this?

@pavel-kirienko
Copy link
Member Author

Two methods next to each other:

They look okay to me.

I checked in UDPTransport and it doesn't have any methods related to sending. Can you comment on this?

This is because in Cyphal/UDP, sending is done via sessions by writing directly to the socket.

@maksimdrachov
Copy link
Member

Ok, we can discuss it next time we meet. I'm still a bit confused.

maksimdrachov
maksimdrachov previously approved these changes May 14, 2023
Copy link
Member

@thirtytwobits thirtytwobits left a comment

Choose a reason for hiding this comment

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

image

@pavel-kirienko pavel-kirienko merged commit e7155a4 into master Jun 3, 2023
@pavel-kirienko pavel-kirienko deleted the dev branch June 3, 2023 11:01
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.

Specify Cyphal/serial
3 participants