A parsing routine would understand the incoming message format, take the message apart to access its individual components, and send/distribute the components.
Here is a routine I use to receive Serial:
void fReceiveSerial_LIDAR( void * parameters )
{
bool BeginSentence = false;
char OneChar;
char *str;
str = (char *)ps_calloc(300, sizeof(char) ); // put str buffer into PSRAM
// log_i("Free PSRAM before String: %d", ESP.getFreePsram());
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 * ) &str );
xEventGroupSetBits( eg, evtParseLIDAR_ReceivedSerial );
//
}
BeginSentence = false;
break;
}
strncat( str, &OneChar, 1 );
}
else
{
if ( OneChar == '<' )
{
strcpy( str, ""); // clear string buffer
BeginSentence = true; // found beginning of sentence
}
}
} // while ( LIDARSerial.available() )
} //if ( LIDARSerial.available() >= 1 )
xSemaphoreGive( sema_ReceiveSerial_LIDAR );
// log_i( "fReceiveSerial_LIDAR " );
// log_i(uxTaskGetStackHighWaterMark( NULL ));
}
free(str);
vTaskDelete( NULL );
} //void fParseSerial( void * parameters )
The routine is only concerned with the processing of the received data and passing that data onto a parsing routine.
Here is the parsing routine:
void fParseLIDAR_ReceivedSerial ( void * parameters )
{
// distribute received LIDAR info
String sTmp = "";
sTmp.reserve ( 20 );
String sMessage = "";
sMessage.reserve ( StringBufferSize300 );
for ( ;; )
{
EventBits_t xbit = xEventGroupWaitBits (eg, evtParseLIDAR_ReceivedSerial, pdTRUE, pdTRUE, portMAX_DELAY) ;
xQueueReceive ( xQ_LIDAR_Display_INFO, &sMessage, QueueReceiveDelayTime );
int commaIndex = sMessage.indexOf(',');
sTmp.concat ( sMessage.substring(0, commaIndex) );
sMessage.remove( 0, (commaIndex + 1) ); // chop off begining of message
if ( sTmp == "!" )
{
xSemaphoreGive ( sema_LIDAR_OK );
// Display info from LIDAR
sLIDAR_Display_Info = sMessage;
}
if ( sTmp == "$" )
{
xEventGroupSetBits( eg1, evtResetWatchDogVariables );
}
if ( sTmp == "#")
{
xSemaphoreTake( sema_LIDAR_Alarm, xSemaphoreTicksToWait );
sLIDAR_Alarm_info = sMessage;
xSemaphoreGive( sema_LIDAR_Alarm );
xEventGroupSetBits( eg, evtfLIDAR_Alarm );
}
sTmp = "";
sMessage = "";
xSemaphoreGive( sema_ParseLIDAR_ReceivedSerial );
}
vTaskDelete( NULL );
} // void fParseReceivedSerial ( void * parameters )
The parsing routine is only concerned with deconstructing the received message and passing the deconstructed message to the various other concerned tasks.
What you may find useful is to load up into the IDE a library for a I2C device, there by looking into the .cpp file you can see how I2C is parsed and, perhaps, apply what is learned to your project.