Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
support Armac O/850E/PSW #2153 #2154
support Armac O/850E/PSW #2153 #2154
Changes from 6 commits
11c298b
4cca5d7
7a490af
fdf5471
8de5371
596ba3a
8a8bb7d
dc3299e
66ff781
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
+1
along 0x3f instead of 0x0f is pretty much the only change I'm not certain won't affect all other versions.We'd need to just test it on hardware I guess. Or create a database of recorded communications and do a regression testing on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the
+1
is for ensuring a zero-byte in the end (of buffer to be provided big enough by the caller).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking a bit more about this, it may be prudent to check that
buflen > read_size
in advance: if the caller's buffer is too small to fit even the first read eventually (ifusb_interrupt_read()
would return the full requestedread_size
and not fewer bytes for some reason), this is more of a programmer error toupsdebugx()
as such than a device/protocol error. I think it can help long-term troubleshooting as this code evolves.Then there's a chance that we expect to read say 64 bytes (due to
if use_interrupt ...
above) but only get say 6 in reality (guessing here, no idea if this reality is possible - WDYT?), and the caller's buffer is big enough for 6 but not for 64. With current while-clause, we would not even bother trying a query. Is this a correct thing to do?Just trying to think of things that could go wrong, so might brainstorm up some garbage ideas here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand it right we already have this check - we won't enter loop at all in that case
while (bufpos + read_size + 1 < buflen)
. And bellow the loop we emit the error for this specific caseupsdebugx(2, "Protocol error, too much data read.");
. It still had hardcoded read_size that was fixed via 66ff781At least in my case I do always get 64 bytes from
usb_interrupt_read
. From them we have only 47 meaningful bytes that will be copied tobuf
. This is handled viabytes_available = (unsigned char)tmpbuf[0] & 0x3f;
. In theory this function could be changed to work when caller's buffer would be less than 64 bytes. But then we are risking that all data we read from interrupt won't fit tobuf
. I'm not sure which way is better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we loop here (in current code and the earlier one), would it be less misleading to return not the latest
ret
(if positive, just too short presumably), but a count of successfully read bytes e.g.bufpos + ret
? Ifret
is negative (for error), probably pass it through as is and disregard any earlier success? Or returnbufpos
anyway, if positive?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Fixed via dc3299e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vytautassurvila @blaa : any particular preference for
bufpos
vs.bufpos + ret
in this case?Generally I think we can fall into this situation if the device has less info to send than exactly the
read_size
. Like, it has 8 bytes for some message and we read in 6-byte chunks, so our buffer getsret=6
in one cycle andret=2
in the other quite validly - and ifret
is always non-negative, we can tell the caller that we have collected 8 bytes.But this is a general train of thought, you may be better aware about what does and does not happen in these particular interactions :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken here we just received data to
tmpbuf
. It will be copied tobuf
only at line 2107. I guess idea is to copy data tobuf
only when some validation is performed on data we received.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, good catch you too :")
So if we abort here,
buf
has only receivedbufpos
finished bytes indeed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose, here and elsewhere we declare that correct reads always return exactly
read_size
and may not be shorter, to the best of our practical knowledge at this time at least?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can speak only about my UPS -
usb_interrupt_read
andread_size
always match. Within those 64 bytes not all bytes are meaningful - that is determined by bit masking first byte.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for the insights. LGTM I guess. The caller's buffer is large enough for the tested devices, I suppose?