Skip to content

Commit

Permalink
Apply minor delay to read thread, improve style
Browse files Browse the repository at this point in the history
Fixes #191.
  • Loading branch information
PeterBowman committed Sep 4, 2018
1 parent 39f4c69 commit b73c378
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions libraries/YarpPlugins/CanBusControlboard/ThreadImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include "CanBusControlboard.hpp"

#include <limits>

#include <yarp/os/Time.h>

// ------------------ Thread Related -----------------------------------------

void roboticslab::CanBusControlboard::run()
Expand All @@ -10,6 +14,8 @@ void roboticslab::CanBusControlboard::run()

while ( ! this->isStopping() )
{
yarp::os::Time::delay(std::numeric_limits<double>::min());

unsigned int read;

//-- Blocks with timeout until one message arrives, returns false on errors.
Expand All @@ -22,20 +28,20 @@ void roboticslab::CanBusControlboard::run()
int canId = msg.getId() & 0x7F;

//-- Commenting next line as way too verbose, happens all the time.
//CD_DEBUG("Read ok. %s\n", msgToStr(&buffer).c_str());
//CD_DEBUG("Read ok. %s\n", msgToStr(msg).c_str());

std::map< int, int >::iterator idxFromCanIdFound = idxFromCanId.find(canId);

if( idxFromCanIdFound == idxFromCanId.end() ) //-- Can ID not found
{
//-- Intercept 700h 0 msg that just indicates presence.
if( (msg.getId()-canId) == 0x700 )
if( msg.getId() - canId == 0x700 )
{
CD_SUCCESS("Device indicating presence. %s\n",msgToStr(msg).c_str());
CD_SUCCESS("Device indicating presence. %s\n", msgToStr(msg).c_str());
continue;
}

//CD_ERROR("Read CAN message from unknown device!!! %s\n", msgToStr(&buffer).c_str()); // --Commented this line to avoid filling the screen with error messages
//CD_ERROR("Read CAN message from unknown device!!! %s\n", msgToStr(msg).c_str()); // --Commented this line to avoid filling the screen with error messages
continue;
}

Expand All @@ -45,8 +51,6 @@ void roboticslab::CanBusControlboard::run()
} //-- ends: while ( ! this->isStopping() ).

CD_INFO("Stopping CanBusControlboard reading thread run.\n");

return;
}

// -----------------------------------------------------------------------------

0 comments on commit b73c378

Please sign in to comment.