Good way to count incoming serial data from sim 900A

Hellow

We are interfacing SIM 900A module with Arduino-UNO.

We are able to detect the incoming call ring on serial monitor. But we want to count the no. of rings and then depending on ring count we are controlling LEDs

For example if ring count is 3 then ON one LED on pin 4 and if ring count is 5 then ON LED on pin 2

we are trying this with following code but not gatting desired output. give your suggestions

#include <SoftwareSerial.h>
SoftwareSerial GPRS(7, 8); // RX, TX
int i=0;
enum _parseState {
  PS_DETECT_CALL_TYPE,     // IN THIS WE ARE DETECTING SMS THPE WHETHER ITS IS CMTI OR CMG
};

byte state = PS_DETECT_CALL_TYPE;    //DETECT TYPE OF MSG

char buffer[80];      //BUFFER LENGTH 
byte pos = 0;         // START STRING BUFFER FROM0
char flag=0;
//int lastReceivedSMSId = 0;    //LAST RECIEVE SMS ID EQUAL TO 0
boolean validSender = false;

void resetBuffer() {
  memset(buffer, 0, sizeof(buffer));
  pos = 0;
}

void setup()
{
  GPRS.begin(9600);
  Serial.begin(9600);

  // Set as appropriate for your case
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  digitalWrite(2, HIGH);
  digitalWrite(4, HIGH);

  for (int i = 1; i <= 10; i++) {       //CHANGES FROM 15 TO 10 FOR LOOP TO DELETE FIRST 10 SMS TO MAKE ROOM FOR NEW SMS
    GPRS.print("AT+CMGD=");     // DELETS SMS
    GPRS.println(i);
    delay(200);

    // Not really necessary but prevents the serial monitor from dropping any input
    while(GPRS.available()) 
      Serial.write(GPRS.read());
  }
}

void loop()
{
  while(GPRS.available()) {
    parseATText(GPRS.read());
  }


}

void parseATText(byte b) {

  buffer[pos++] = b;

  if ( pos >= sizeof(buffer) )
    resetBuffer(); // just to be safe

  
      if ( b == '\n' )
        resetBuffer();
      else {        
        if ( pos == 4 && strcmp(buffer, "RING") == 0 ) {

            i++;
            resetBuffer();
  /*   if (GPRS.available()!=0)
       {
         flag=1;
        }*/
            
              if ( pos == 2 && strcmp(buffer, "NO") == 0 ) {
                   if (i==3)
                    {
                      digitalWrite(4, HIGH);
                      digitalWrite(2, LOW);
                      }
                      
                    if (i==5)
                    {
                      digitalWrite(2, HIGH);
                      digitalWrite(4, LOW);
                      }
                   i=0;
               }
             /// state = PS_DETECT_CALL_TYPE;
             
           }

       
        //}
   // }
  }
}
void resetBuffer() {
  memset(buffer, 0, sizeof(buffer));
  pos = 0;
}

If one stop sign is good, 80 must be better, huh? I don't think so.

I strongly suggest that you get your delete key fixed, and delete the commented out, useless code. There is no reason to expect us to wade past all that crap.

Using Tools + Auto Format, so it doesn't look like your code was typed by a drunken monkey would be good, too.

You have code to recognize when the data coming in contains "RING". What's so hard about incrementing a variable when that happens?

When do you reset the variable?