-
Notifications
You must be signed in to change notification settings - Fork 53
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
fix(hesai_hw_interface): add error handling #131
fix(hesai_hw_interface): add error handling #131
Conversation
* check PTC command error codes, throw exception if necessary * perform size checks before parsing responses * emit errors on too-large payload size
(I still have to test this on real sensors) |
Test PandarXT32The driver works with an actual sensor. Pointcloud looks normal.
|
The actual parsing is the same in this PR as it was before. However, OT128 (and to some extent AT128, possibly others) have slightly different struct definitions from e.g. XT32. As it was not an issue until now, I opted to print an error that we are parsing the wrong data for some fields, rather than doing a proper refactoring at this point. What has changed however, is that payload size is now checked before parsing into the structs is attempted. |
OT128's TCP API doc lists the I have added Do you think it is best to add an exception |
Indeed, the output had some other errors as well: I forgot to reset the output modifiers ( Output now:
|
e5d0a9c
to
decf1ac
Compare
19e8101
to
4f022cd
Compare
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.
Great work!
PR Type
Related Links
This PR will not fix this issue but at least throw an exception with a detailed error message instead of a segfault, making future similar bugs much easier to spot:
hesai_cmd_response.hpp
struct formats are wrong for some sensors #130Description
This PR introduces error checking and handling in
hesai_hw_interface.cpp
. The following features have been added:std::runtime_error
s in case an error occursThe following other things have changed as a result of the fix:
hesai_cmd_response.hpp
are now parsed viamemcpy
, and useboost::endian
buffers in the sizes specified by the datasheet(s)expected
modeled after C++23 std::expected was added to make error handling code more compactFIXME
s in places that are wrong but not high priority (do not cause crashes etc.)Behavior for TCP commands is now as follows:
std::runtime_error
is thrown with a detailed list of error messagesHesaiPtpConfig
):std::runtime_error
is thrown if the payload is too short tomemcpy
into the structPrintError
ed if the payload is too large. This is done because the first few fields of the struct are typically correct, even if the format of later fields differsReview Procedure
Test TCP with real sensors (at least AT128, OT128 and an older sensor).
Remarks
We should refactor TCP communication in a similar way that was done with mixins in #104. This would make the sensor definition much more readable: one could read the sensor definition alongside the TCP documentation, without boilerplate code. This would provide much better maintainability, and, for new sensors, forces the developer to check every TCP command for changes when implementing.
Pre-Review Checklist for the PR Author
PR Author should check the checkboxes below when creating the PR.
Checklist for the PR Reviewer
Reviewers should check the checkboxes below before approval.
Post-Review Checklist for the PR Author
PR Author should check the checkboxes below before merging.
CI Checks