base/serial.c
void Asynchronous_ProcessByte(UCHAR ucByte_)
{   
   static UCHAR ucCheckSum = 0;
   static UartRxState eTheState = UART_STATE_WFSYNC;
   static UCHAR ucTheLength = 0;
   static UCHAR ucIndex = 0;
   static UCHAR* pucTheBuffer = NULL;

   switch(eTheState)
   {
      case UART_STATE_WFSYNC:                         // Wiating for SYNC
      {
         if(ucByte_ == MESG_TX_SYNC)                  // Got SYNC
         {
            eTheState = UART_STATE_WFSIZE;            // Move to wiating for size
            ucCheckSum = MESG_TX_SYNC; 
            ucIndex = 0;         
         }
         break;
      }     
      case UART_STATE_WFSIZE:                         // Wiating for size
      {

         if(ucByte_ < SERIAL_QUEUE_BUFFER_LENGTH)     // Make sure size makes sense
         {
            pucTheBuffer = Serial_Get_Rx_Buffer();    // Try to get a buffer from the RX queue

            if(pucTheBuffer)
            {
               pucTheBuffer[ucIndex++] = ucByte_;
               ucCheckSum ^= ucByte_; 
               ucTheLength = ucByte_;                 // Move to waiting for body
               eTheState = UART_STATE_BODY;
            }
            else
            {
               eTheState = UART_STATE_WFSYNC;         // If no buffer in queue, drop this message and reset
               sqRxMessages.bQueueOverflow = TRUE;  //Set overflow flag
            }

         }
         else
         {
            eTheState = UART_STATE_WFSYNC;            // If the size is weird drop message and reset
         }

         break;
      }     
      case UART_STATE_BODY:                           // Waiting for body bytes
      {
         if(pucTheBuffer)
         {
            pucTheBuffer[ucIndex++] = ucByte_;
            ucCheckSum ^= ucByte_; 

            if(ucTheLength == 0)                      // Body will be collected up to checksum
            {
               eTheState = UART_STATE_WFCHKSUM;       // Move to waiting for checksum
            }
            else
            {         
               ucTheLength--;
            }      
         }
         break;
      }       
      case UART_STATE_WFCHKSUM:                       // Waiting for checksum byte
      {

         if( (ucByte_ == ucCheckSum) && !sqRxMessages.bQueueOverflow)                   // If the checksum is good
            Serial_Put_Rx_Buffer();                   // put buffer back in queue

         // Reset the state machine
         ucCheckSum = 0;
         eTheState = UART_STATE_WFSYNC;
         ucTheLength = 0;
         ucIndex = 0;
         pucTheBuffer = NULL;

         break;
      }


      default:                                        // Shouldn't happen
      {
         eTheState = UART_STATE_WFSYNC;
         break;
      }
   }
}
////////////////////////////////////////////////////////////////////////////
// Asynchronous_ProcessByte
//
// Process bytes recieve in the UART interrupt. Once a complete and valid
// ANT message is recieved, it is put into the RX serial queue.
// 
////////////////////////////////////////////////////////////////////////////
Asynchronous_ProcessByte
Process bytes recieve in the UART interrupt. Once a complete and valid
ANT message is recieved, it is put into the RX serial queue.
Asynchronous_ProcessByte Process bytes recieve in the UART interrupt . Once a complete and valid ANT message is recieved it is put into the RX serial queue .
void Asynchronous_ProcessByte(UCHAR ucByte_)
{   
   static UCHAR ucCheckSum = 0;
   static UartRxState eTheState = UART_STATE_WFSYNC;
   static UCHAR ucTheLength = 0;
   static UCHAR ucIndex = 0;
   static UCHAR* pucTheBuffer = NULL;
   switch(eTheState)
   {
      case UART_STATE_WFSYNC:                         
      {
         if(ucByte_ == MESG_TX_SYNC)                  
         {
            eTheState = UART_STATE_WFSIZE;            
            ucCheckSum = MESG_TX_SYNC; 
            ucIndex = 0;         
         }
         break;
      }     
      case UART_STATE_WFSIZE:                         
      {
         if(ucByte_ < SERIAL_QUEUE_BUFFER_LENGTH)     
         {
            pucTheBuffer = Serial_Get_Rx_Buffer();    
            if(pucTheBuffer)
            {
               pucTheBuffer[ucIndex++] = ucByte_;
               ucCheckSum ^= ucByte_; 
               ucTheLength = ucByte_;                 
               eTheState = UART_STATE_BODY;
            }
            else
            {
               eTheState = UART_STATE_WFSYNC;         
               sqRxMessages.bQueueOverflow = TRUE;  
            }
         }
         else
         {
            eTheState = UART_STATE_WFSYNC;            
         }
         break;
      }     
      case UART_STATE_BODY:                           
      {
         if(pucTheBuffer)
         {
            pucTheBuffer[ucIndex++] = ucByte_;
            ucCheckSum ^= ucByte_; 
            if(ucTheLength == 0)                      
            {
               eTheState = UART_STATE_WFCHKSUM;       
            }
            else
            {         
               ucTheLength--;
            }      
         }
         break;
      }       
      case UART_STATE_WFCHKSUM:                       
      {
         if( (ucByte_ == ucCheckSum) && !sqRxMessages.bQueueOverflow)                   
            Serial_Put_Rx_Buffer();                   
         ucCheckSum = 0;
         eTheState = UART_STATE_WFSYNC;
         ucTheLength = 0;
         ucIndex = 0;
         pucTheBuffer = NULL;
         break;
      }
      default:                                        
      {
         eTheState = UART_STATE_WFSYNC;
         break;
      }
   }
}
void Asynchronous_ProcessByte ( UCHAR ucByte_ ) { static UCHAR ucCheckSum = 0 ; static UartRxState eTheState = UART_STATE_WFSYNC ; static UCHAR ucTheLength = 0 ; static UCHAR ucIndex = 0 ; static UCHAR * pucTheBuffer = NULL ; switch ( eTheState ) { case UART_STATE_WFSYNC : { if ( ucByte_ == MESG_TX_SYNC ) { eTheState = UART_STATE_WFSIZE ; ucCheckSum = MESG_TX_SYNC ; ucIndex = 0 ; } break ; } case UART_STATE_WFSIZE : { if ( ucByte_ < SERIAL_QUEUE_BUFFER_LENGTH ) { pucTheBuffer = Serial_Get_Rx_Buffer ( ) ; if ( pucTheBuffer ) { pucTheBuffer [ ucIndex ++ ] = ucByte_ ; ucCheckSum ^= ucByte_ ; ucTheLength = ucByte_ ; eTheState = UART_STATE_BODY ; } else { eTheState = UART_STATE_WFSYNC ; sqRxMessages . bQueueOverflow = TRUE ; } } else { eTheState = UART_STATE_WFSYNC ; } break ; } case UART_STATE_BODY : { if ( pucTheBuffer ) { pucTheBuffer [ ucIndex ++ ] = ucByte_ ; ucCheckSum ^= ucByte_ ; if ( ucTheLength == 0 ) { eTheState = UART_STATE_WFCHKSUM ; } else { ucTheLength -- ; } } break ; } case UART_STATE_WFCHKSUM : { if ( ( ucByte_ == ucCheckSum ) && ! sqRxMessages . bQueueOverflow ) Serial_Put_Rx_Buffer ( ) ; ucCheckSum = 0 ; eTheState = UART_STATE_WFSYNC ; ucTheLength = 0 ; ucIndex = 0 ; pucTheBuffer = NULL ; break ; } default : { eTheState = UART_STATE_WFSYNC ; break ; } } }
Asynchronous_ProcessByte
Process bytes recieve in the UART interrupt.
Asynchronous_ProcessByte Process bytes recieve in the UART interrupt .
// Wiating for SYNC // Got SYNC // Move to wiating for size // Wiating for size // Make sure size makes sense // Try to get a buffer from the RX queue // Move to waiting for body // If no buffer in queue, drop this message and reset //Set overflow flag // If the size is weird drop message and reset // Waiting for body bytes // Body will be collected up to checksum // Move to waiting for checksum // Waiting for checksum byte // If the checksum is good // put buffer back in queue // Reset the state machine // Shouldn't happen