Skip to content

Check requested message before trying callbacks #14

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/ODriveCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,17 @@ void ODriveCAN::onReceive(uint32_t id, uint8_t length, const uint8_t* data) {
Serial.print(msg.data[byte_index--], HEX);
Serial.println(F(""));
#endif // DEBUG
// Check that the message is meant for this node.
if (node_id_ != (id >> ODriveCAN::kNodeIdShift))
return;
// If the message is requested, copy it in the request buffer and exit.
if ((id & ODriveCAN::kCmdIdBits) == requested_msg_id_) {
memcpy(buffer_, data, length);
requested_msg_id_ = REQUEST_PENDING;
return;
};
// Check if any of the registered callback handlers apply. Useful for cyclic
// messages.
switch (id & ODriveCAN::kCmdIdBits) {
case Get_Encoder_Estimates_msg_t::cmd_id: {
Get_Encoder_Estimates_msg_t estimates;
Expand Down Expand Up @@ -178,10 +187,6 @@ void ODriveCAN::onReceive(uint32_t id, uint8_t length, const uint8_t* data) {
Serial.print(F("waiting for: 0x"));
Serial.println(requested_msg_id_, HEX);
#endif // DEBUG
if ((id & ODriveCAN::kCmdIdBits) != requested_msg_id_)
return;
memcpy(buffer_, data, length);
requested_msg_id_ = REQUEST_PENDING;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ODriveCAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ODriveCAN {
bool getVersion(Get_Version_msg_t& msg, uint16_t timeout_ms = 10);

/**
* @brief Requests encoder feedback data. May trigger onFeedback callback if it's registered
* @brief Requests encoder feedback data.
*
* This function will block and wait for up to timeout_ms (default 10msec) for ODrive to reply
*/
Expand Down