Skip to content
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixed rxClient function for modular use
  • Loading branch information
upadhyaydhruv committed Feb 4, 2022
commit 5de8de916d48e52de07aa3ed81a63be17285984a
8 changes: 2 additions & 6 deletions libs/can/src/CANInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ void CANInterface::rxPostman(void) {
void CANInterface::rxClient(void) {
while (true) {
Copy link
Member

Choose a reason for hiding this comment

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

should no longer be while true if its a 1ms periodic function

CANMsg *mail = nullptr;

// Wait for a message to arrive
do {
mail = m_rxMailbox.try_get(); // using try_get() because try_get_for() was crashing
ThisThread::sleep_for(1ms); // TODO: Check for object in mailbox every ms
} while (mail == nullptr);
// Check if a message has arrived:
mail = m_rxMailbox.try_get();

MBED_ASSERT(mail != nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

I agree with the above logic change on lines 58 and 59, but now it results in try_get sometimes returning nullptr if the mailbox is empty. should change this assert to maybe a debug print and early return(or just an if block to block execution of rest of this function. personally, i prefer single return statements from functions in fw code)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would the MBED_ASSERT not account for that?

Copy link
Member

Choose a reason for hiding this comment

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

MBED_ASSERT would actually break the program, I agree that we should remove it and just wrap the logic in an if block


Expand Down