----------------------------------------------------------------------------- Read data from the serial port -----------------------------------------------------------------------------
| 1735 | // Read data from the serial port |
| 1736 | //----------------------------------------------------------------------------- |
| 1737 | bool Driver::ReadMsg |
| 1738 | ( |
| 1739 | ) |
| 1740 | { |
| 1741 | uint8 buffer[1024]; |
| 1742 | |
| 1743 | memset(buffer, 0, sizeof(uint8)* 1024); |
| 1744 | |
| 1745 | if( !m_controller->Read( buffer, 1 ) ) |
| 1746 | { |
| 1747 | // Nothing to read |
| 1748 | return false; |
| 1749 | } |
| 1750 | |
| 1751 | switch( buffer[0] ) |
| 1752 | { |
| 1753 | case SOF: |
| 1754 | { |
| 1755 | m_SOFCnt++; |
| 1756 | if( m_waitingForAck ) |
| 1757 | { |
| 1758 | // This can happen on any normal network when a transmission overlaps an unexpected |
| 1759 | // reception and the data in the buffer doesn't contain the ACK. The controller will |
| 1760 | // notice and send us a CAN to retransmit. |
| 1761 | Log::Write( LogLevel_Detail, "Unsolicited message received while waiting for ACK." ); |
| 1762 | m_ACKWaiting++; |
| 1763 | } |
| 1764 | |
| 1765 | // Read the length byte. Keep trying until we get it. |
| 1766 | m_controller->SetSignalThreshold( 1 ); |
| 1767 | int32 response = Wait::Single( m_controller, 50 ); |
| 1768 | if( response < 0 ) |
| 1769 | { |
| 1770 | Log::Write( LogLevel_Warning, "WARNING: 50ms passed without finding the length byte...aborting frame read"); |
| 1771 | m_readAborts++; |
| 1772 | break; |
| 1773 | } |
| 1774 | |
| 1775 | m_controller->Read( &buffer[1], 1 ); |
| 1776 | m_controller->SetSignalThreshold( buffer[1] ); |
| 1777 | if( Wait::Single( m_controller, 500 ) < 0 ) |
| 1778 | { |
| 1779 | Log::Write( LogLevel_Warning, "WARNING: 500ms passed without reading the rest of the frame...aborting frame read" ); |
| 1780 | m_readAborts++; |
| 1781 | m_controller->SetSignalThreshold( 1 ); |
| 1782 | break; |
| 1783 | } |
| 1784 | |
| 1785 | m_controller->Read( &buffer[2], buffer[1] ); |
| 1786 | m_controller->SetSignalThreshold( 1 ); |
| 1787 | |
| 1788 | uint32 length = buffer[1] + 2; |
| 1789 | |
| 1790 | // Log the data |
| 1791 | string str = ""; |
| 1792 | for( uint32 i=0; i<length; ++i ) |
| 1793 | { |
| 1794 | if( i ) |