Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 211 → Rev 213

/common/BioloidPacket.cpp
43,12 → 43,26
*/
 
BioloidPacket::BioloidPacket()
: m_state( BioloidPacket::STATE_IDLE )
: m_state( BioloidPacket::STATE_IDLE ),
m_param( NULL ),
m_maxParam( 0 )
{
}
 
//***************************************************************************
/**
* Constructor where storage for parameter data is specified.
*/
 
BioloidPacket::BioloidPacket( void *data, uint8_t maxData )
: m_state( BioloidPacket::STATE_IDLE ),
m_param( static_cast< uint8_t * >( data )),
m_maxParam( maxData )
{
}
 
//***************************************************************************
/**
* Destructor
*
* virtual
67,9 → 81,10
* virtual
*/
 
void BioloidPacket::ProcessChar( uint8_t ch )
Bioloid::Error BioloidPacket::ProcessChar( uint8_t ch )
{
State nextState = m_state;
State nextState = m_state;
Bioloid::Error err = Bioloid::ERROR_NOT_DONE;
 
switch ( nextState )
{
136,14 → 151,23
{
if (( m_paramIdx + 2 ) >= m_length )
{
Bioloid::Error err = Bioloid::ERROR_NONE;
 
// ch is the Checksum
 
m_checksum = ~m_checksum;
 
if ( m_checksum != ch )
if ( m_checksum == ch )
{
if ( m_paramIdx <= m_maxParam )
{
err = Bioloid::ERROR_NONE;
}
else
{
err = Bioloid::ERROR_TOO_MUCH_DATA;
}
}
else
{
// CRC failed
 
err = Bioloid::ERROR_CHECKSUM;
150,15 → 174,13
LogError( "Rcvd Checksum: 0x%02x Expecting: 0x%02x\n",
ch, m_checksum );
}
 
PacketReceived( err );
nextState = STATE_IDLE;
break;
}
 
if ( m_paramIdx < sizeof( m_param ))
m_checksum += ch;
if ( m_paramIdx < m_maxParam )
{
m_checksum += ch;
m_param[ m_paramIdx ] = ch;
}
m_paramIdx++;
167,5 → 189,7
}
 
m_state = nextState;
 
return err;
}