-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
Difficulty with packet descriptor #157
Comments
Did you ever figure this out? I think I'm seeing a related problem. I too expect the response evaluator to return with a progressively growing buffer, which is collecting data as it is coming in from the serial port. Instead, with each call of the evaluator, I'm getting only partial data. My However, my response evaluator is invoked multiple times with the following byte counts (associated with each Data = 1 bytes Data = 1 bytes Data = 1 bytes Data = 1 bytes Data = 1 bytes Data = 1 bytes Data = 1 bytes Data = 1 bytes Data = 1 bytes This continues all the way up to 31, one byte shy of the entire response length. You may also notice the progressing pattern in the byte counts. I did not notice this until just now. It is a definite clue to what is going on in the logic that invokes the response evaluator. It may be that I need to re-read the documentation but this is not the kind of behavior that is intuitive for an API like this. |
I should probably clarify the documentation around this. The behavior you're seeing is correct (minus not seeing all 32 bytes). The response evaluator is called repeatedly with progressively bigger chunks of the received data working backward. I agree this can be a bit confusing when you first encounter it, and I might design the API differently were I designing it today. But there is a good reason for it, as this approach is very robust in the face of occasional garbage data or incomplete packets, as well as fully supporting multiple (even overlapping) packet listeners being installed at the same time. Anyway, it means that your response evaluator should check for both the beginning and end of the packet you're expecting (and/or the overall length, a matching checksum, etc., as is appropriate for your packet format). It should disqualify packets as efficiently as possible. And this API isn't necessarily a great choice if your packet format isn't very structured, ie. it's hard to write general purpose "is this a valid packet?" code. That said, I'm concerned that you're only seeing 31/32 bytes. You should see all 32. @StateMachineJunkie feel free to email me privately if you want me to help you dig in a bit more. |
Hi. I'm trying to parse packets that can either be one of four 1-byte packets, or a variable-length packet. That is, a byte at the start of a packet of 0x06 (ACK), 0x15 (NAK), 0x16 (SYN), or 0x18 (CAN) constitutes a complete message. A starting byte of 0x01 (SOF) means at least four more bytes are coming.
When I send a request, I get back an ACK byte, followed by a SOF frame. If my request was bad, I just get back a NAK byte.
The full set of bytes I get from the other end looks like this:
What that dump shows is the ACK, followed by a SOF frame of 18 bytes: SOF (0x01), length (0x10), type (0x01), some string data, 0x00, 0x01, and a checksum of 0x5D. Because I never ACK the response, it's repeated, so the 0x93 above is followed by 0x01, 0x10, 0x01, 0x15.
My packet descriptor evaluator looks like this. Unfortunately, it never makes it to the the checksum validation. Instead, it seems to decide the length is 0x93, which suggests to me the packet parser is calling my function after skipping some bytes. I would have thought it would keep sending me the same buffer, with new bytes appended to the end, so I could keep reevaluating them until I got a good packet.
The text was updated successfully, but these errors were encountered: