Separeted commands

hi guys, when i was working on ST7789 output, i notice commands using substring isnt that good, ex:"cmd 000 000 000 000", is somewone know a way to make better command system that works like (cmd 0,0,0,0)

If all you mean is to replace spaces as delimiters with commas, I ask why?

What was the problem with the code that you tried where spaces were expected in between?

a7

it seems to i cant find something like this. the code is use on command with 000s part is just regular string.substring's

I don't know if you mean a TFT LCD display. Your question is not in any context.

Perhaps this article will be of interest:

It gets into how to send multiple pieces of data separated by. Whatever.

a7

OHHHH I GOT IT, THERE WAS SPLIT THAT ON VB .NET, but i cant find on the arduino.cc

here is how I split a comma delimited string.

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 );
    //        Serial.println ( sMessage );
    int commaIndex = sMessage.indexOf(',');
    sTmp.concat ( sMessage.substring(0, commaIndex) );
    sMessage.remove( 0, (commaIndex + 1) ); // chop off begining of message
    //    Serial.println ( sTmp );
    if ( sTmp == "!" )
    {
      xSemaphoreGive ( sema_LIDAR_OK );
      //  Display info from LIDAR
      sLIDAR_Display_Info = sMessage;
    }
    if ( sTmp == "$" )
    {
      xEventGroupSetBits( eg1, evtResetWatchDogVariables );
    }
    if ( sTmp == "#")
    {
      // Serial.println ( "#" );
      xSemaphoreTake( sema_LIDAR_Alarm, xSemaphoreTicksToWait );
      sLIDAR_Alarm_info = sMessage;
      xSemaphoreGive( sema_LIDAR_Alarm );
      xEventGroupSetBits( eg, evtfLIDAR_Alarm );
    }
    //    Serial.println ( "parse serial ok" );
    sTmp = "";
    sMessage = "";
    xSemaphoreGive( sema_ParseLIDAR_ReceivedSerial );
    //    Serial.print( "fParseReceivedSerial " );
    //    Serial.print(uxTaskGetStackHighWaterMark( NULL ));
    //    Serial.println();
    //    Serial.flush();
  }
  vTaskDelete( NULL );
} // void fParseReceivedSerial ( void * parameters )

is it saving them on an array of strings

No.

so how im gonna get "all" of those string's

you can write code to save them to an array?

In the case for the code posted in post#6 I receive the String on Serial like this.

void fReceiveSerial_LIDAR( void * parameters  )
{
  char OneChar;
  char *str;
  str = (char *)ps_calloc(300, sizeof(char) ); // put str buffer into PSRAM
  bool BeginSentence = false;
  sSerial.reserve ( StringBufferSize300 );
  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  )

After receipt of a complete String, the String is sent over to the parser xQueueOverwrite( xQ_LIDAR_Display_INFO, ( void * ) &sSerial ); where the parser receives the String with xQueueReceive ( xQ_LIDAR_Display_INFO, &sMessage, QueueReceiveDelayTime );

i found the code just i needed on forum in How to split a string with space and store the items in array?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.