Is the serial data in an ad hoc format or in a sentence format?
ad hoc format 2 3 4 5 6 43 2 6 8 5 3 2 4 6 7 8 98 7 65 4 3 32 45 5
sentence format
<1,2,3,4,5,6,7,8,9>
As maybe seen in the ad hoc format the data is just a random format. No telling where one data part is over the other data parts.
As may be seen, in the sentence format the data has a beginning sentence marker, delimited data parts, and an ending sentence marker.
<!,1,2,3,4,5,6,7,8,9>
<@,1,2,3,4,5,6,7,8,9>
<#,1,2,3,4,5,6,7,8,9>
As, also may be seen a data identifier can be placed in the sentence when different data are being sent like temperature or Linear regression data.
Also with the sentence format the code can be wrote that waits on the sentence begin marker to collect the data and a sentence end marker to send the data to a parser.
void fReceiveSerial_LIDAR( void * parameters )
{
bool BeginSentence = false;
sSerial.reserve ( StringBufferSize300 );
char OneChar;
for ( ;; )
{
EventBits_t xbit = xEventGroupWaitBits (eg, evtReceiveSerial_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY);
if ( LIDARSerial.available() >= 1 )
{
while ( LIDARSerial.available() )
{
OneChar = LIDARSerial.read();
if ( BeginSentence )
{
if ( OneChar == ‘>’)
{
if ( xSemaphoreTake( sema_ParseLIDAR_ReceivedSerial, xSemaphoreTicksToWait10 ) == pdTRUE )
{
xQueueOverwrite( xQ_LIDAR_Display_INFO, ( void * ) &sSerial );
xEventGroupSetBits( eg, evtParseLIDAR_ReceivedSerial );
//
}
BeginSentence = false;
break;
}
sSerial.concat ( OneChar );
}
else
{
if ( OneChar == ‘<’ )
{
sSerial = “”; // clear string buffer
BeginSentence = true; // found begining of sentence
}
}
} // while ( LIDARSerial.available() )
} //if ( LIDARSerial.available() >= 1 )
xSemaphoreGive( sema_ReceiveSerial_LIDAR );
}
vTaskDelete( NULL );
} //void fReceiveSerial_LIDAR( void * parameters )
One might be able to discern the use of serial data used in sentence structure from the above code.