#include <Arduino.h>


#include <Arduino.h>

#define debugger

#define DEBUG 1

#if DEBUG == 1
  #define debug(x) Serial.print(x)
  #define debugln(x) Serial.println(x)
#else
#define debug(x)
#define debugln(x)  
#endif

  char serialIn[100]; //Captures initial delimited input
  char pairs[100];
  char call[10][15];
  char action[10][15];

  char plusNumber[2];
  static bool readingSerial = false;

void ReadSerial() {
  // To Clear the incoming: clearbuffer
      readingSerial = true;
      //debugln("Reading Serial");
      char userInput[75] = "";
      char clrbfr[] = "clearbuffer";
      char resetesp[] = "resetesp";
      int commasFound[10];
      int colNum[5] = {};
      char* colonIndex;
    
  //userInput[sizeof(userInput)] = "set:[function:1,delay:2,millis:10]";
    
    while(Serial.available() > 0) {
      //debugln("Serial Available");
      
      size_t numChars = Serial.readBytesUntil('\n', userInput, sizeof(userInput) - 1);
        userInput[numChars] = '\0'; 
      printf("You entered: %s\n", userInput);
    
      // To Clear the incoming: clearbuffer
        if (strncmp(clrbfr, &userInput[0], int(11)) == 0) {
          Serial.println("Clearing Input Buffer");
          //debugln(" ");
              memset(userInput,0,sizeof(userInput));
        //memset(userInput,0,sizeof(userInput));
          //debugln(" ");
          //debugln("Buffer Cleared!");
      }
//    
    else if(strcmp(resetesp, userInput) == 0) {
        debugln("Reseting ESP cpu");
        //debugln(" ");
        esp_cpu_reset(0);
        debugln("Resetting ESP APP");
        //debugln(" ");
        esp_cpu_reset(1);
        debugln("ESP CPU and APP have been reset!");
        //debugln(" ");
      }
      int inSize = strlen(userInput);
      printf("Length of User Input =  %i\n", inSize);

     
     colonIndex = strstr(userInput, ":");
     printf("' : ' Index = %s\n", colonIndex);
    }

    if(strncmp(&colonIndex[1], "[", int(1)) == 0)  {
      colNum[0] = strlen(colonIndex);
      printf("Size of : + ->  %i\n", colNum[0]);
    }
   }
  




void setup() {
  Serial.begin(115200);
  delay(100);

    }

void loop() {
  delay(10); // this speeds up the simulation

  if(Serial.available() > 0) {
    //debugln("reading serial in loop");
    ReadSerial();
    }
  }