arduino mega + GPRS + xbee + easyvr shield

first of all, im not good in english so bare with me.
I am working on home automation project. I’m using arduino mega 2560 + GPRS + xbee + easyvr shield. I want all the data to be transfered from arduino mega 2560 + GPRS + xbee + easyvr shield to another arduino. I used a different serials for each shield to avoid conflicts when sending data.

But the problem is that the program is only listening to one serial at a time; It is only to easyVR. I want the program to stop listening to easyVR when a sms was received.

GPRS shield = serial2
xbee shield = serial1
easyVR = serial

i put,

if(Serial2.available()>0)

but the program still don’t recognized my sms.

#include <SoftwareSerial.h>
#include "Arduino.h"
#if !defined(SERIAL_PORT_MONITOR)
#error "Arduino version not supported. Please update your IDE to the latest version."
#endif

#if defined(SERIAL_PORT_USBVIRTUAL)
  // Shield Jumper on HW (for Leonardo and Due)
  #define port SERIAL_PORT_HARDWARE
  #define pcSerial SERIAL_PORT_USBVIRTUAL
#else
  // Shield Jumper on SW (using pins 12/13 or 8/9 as RX/TX)
  #include "SoftwareSerial.h"
  SoftwareSerial port(12, 13);
  #define pcSerial SERIAL_PORT_MONITOR
#endif

#include "EasyVR.h"

EasyVR easyvr(port);

//Groups and Commands
enum Groups
{
  GROUP_0  = 0,
  GROUP_1  = 1,
};

enum Group0 
{
  G0_UTECH = 0,
};

enum Group1 
{
  G1_ALO = 0,
  G1_LIGHTS_OFF = 1,
  G1_DIM_LIGHTS = 2,
  G1_OUTLETS_ON = 3,
  G1_TURN_OFF_OUTLETS = 4,
  G1_TVO = 5,
  G1_TFT = 6,
  G1_TV_VOL_UP = 7,
  G1_DECREASE_VOL = 8,
  G1_ILIMINATE = 9,
};


int8_t group, idx;
String SmsStorePos = String("");
String msg = String("");
String snTmp = String("");
String snFull = String("");
int SmsContentFlag = 0;

void setup()
{
  // setup PC serial port
  pcSerial.begin(9600);
  Serial2.begin(9600);               // the GPRS baud rate   
  Serial1.begin(9600);

  // bridge mode?
  int mode = easyvr.bridgeRequested(pcSerial);
  switch (mode)
  {
  case EasyVR::BRIDGE_NONE:
    // setup EasyVR serial port
    port.begin(9600);
    // run normally
    pcSerial.println(F("---"));
    pcSerial.println(F("Bridge not started!"));
    break;
    
  case EasyVR::BRIDGE_NORMAL:
    // setup EasyVR serial port (low speed)
    port.begin(9600);
    // soft-connect the two serial ports (PC and EasyVR)
    easyvr.bridgeLoop(pcSerial);
    // resume normally if aborted
    pcSerial.println(F("---"));
    pcSerial.println(F("Bridge connection aborted!"));
    break;
    
  case EasyVR::BRIDGE_BOOT:
    // setup EasyVR serial port (high speed)
    port.begin(115200);
    // soft-connect the two serial ports (PC and EasyVR)
    easyvr.bridgeLoop(pcSerial);
    // resume normally if aborted
    pcSerial.println(F("---"));
    pcSerial.println(F("Bridge connection aborted!"));
    break;
  }

  while (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    delay(1000);
  }

  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");
  easyvr.setTimeout(5);
  easyvr.setLanguage(0);

  group = EasyVR::TRIGGER; //<-- start group (customize)
}



void loop()
{  char SerialInByte;

   if(Serial2.available()>0)
    {    
        char SerialInByte;
        SerialInByte = (unsigned char)Serial2.read();
        

       
        if( SerialInByte == 13 ){ProcessGprsMsg();
         }
         if( SerialInByte == 10 ){
         }
         else {
           msg += String(SerialInByte);
         }
     } 
     else{
  easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)

  Serial.print("Say a command in Group ");
  Serial.println(group);
  easyvr.recognizeCommand(group);

  do
  {   if(Serial2.available()>0)
    {    
        char SerialInByte;
        SerialInByte = (unsigned char)Serial2.read();
        

       
        if( SerialInByte == 13 ){ProcessGprsMsg();
         }
         if( SerialInByte == 10 ){
         }
         else {
           msg += String(SerialInByte);
         }
     }
    // can do some processing while waiting for a spoken command
  }
  while (!easyvr.hasFinished());
  
  easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

  idx = easyvr.getWord();
  if (idx >= 0)
  {
    // built-in trigger (ROBOT)
    // group = GROUP_X; <-- jump to another group X
    return;
  }
  idx = easyvr.getCommand();
  if (idx >= 0)
  {
    // print debug message
    uint8_t train = 0;
    char name[32];
    Serial.print("Command: ");
    Serial.print(idx);
    if (easyvr.dumpCommand(group, idx, name, train))
    {
      Serial.print(" = ");
      Serial.println(name);
    }
    else
      Serial.println();
    easyvr.playSound(0, EasyVR::VOL_FULL);
    // perform some action
    action();
  }
  else // errors or timeout
  {
    if (easyvr.isTimeout())
      Serial.println("Timed out, try again...");
    int16_t err = easyvr.getError();
    if (err >= 0)
    {
      Serial.print("Error ");
      Serial.println(err, HEX);
    }
  }
   
}}

void action()
{
    switch (group)
    {
    case GROUP_0:
      switch (idx)
      {
      case G0_UTECH:
      group = GROUP_1;
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    case GROUP_1:
      switch (idx)
      {
      case G1_ALO:
       Serial1.write(">LoA");
        break;
      case G1_LIGHTS_OFF:
       Serial1.write(">LfA");
        break;
      case G1_DIM_LIGHTS:
       Serial1.write(">Ld1");
        break;
      case G1_OUTLETS_ON:
       Serial1.write(">OoA");
        break;
      case G1_TURN_OFF_OUTLETS:
       Serial1.write(">OfA");
        break;
      case G1_TVO:
       Serial1.write(">4vZ");
        break;
      case G1_TFT:
       Serial1.write(">4vF");
        break;
      case G1_TV_VOL_UP:
       Serial1.write(">4vU");
        break;
      case G1_DECREASE_VOL:
       Serial1.write(">4vD");
        break;
      case G1_ILIMINATE:
      Serial1.write(">Ime");
        break;
      }
      break;
    }
}
void ProcessSms( String sms ){
  sms.toLowerCase();

   if( sms.indexOf("on") >= 0 ){
    Serial1.write(">LoA");
    return;
  }
  if( sms.indexOf("off") >= 0 ){
    Serial1.write(">LfA");
    return;
  } 
  if( sms.indexOf("dim") >= 0 ){
    Serial1.write(">Ld1");
    return;
  } else {
    Serial2.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
    delay(1000);
    Serial2.print("AT+CMGS=\"");
    Serial2.print(snFull);
    Serial2.print("\"\r");
    delay(1000);
    Serial2.print("Unknown Command: ");
    Serial2.print(sms);
    Serial2.print("\r");
    delay(1000);
    Serial2.write(0x1A);  //Equivalent to sending Ctrl+Z     
    return;
  }
}
void GprsTextModeSMS(){
  Serial2.println( "AT+CMGF=1" );
}

void GprsReadSmsStore( String SmsStorePos ){
  Serial2.print( "AT+CMGR=" );
  Serial2.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
  msg = "";
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {

  if( msg.indexOf( "Call Ready" ) >= 0 ){
     //Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
     GprsTextModeSMS();
  }

  // EN: unsolicited message received when getting a SMS message
  if( msg.indexOf( "+CMTI" ) >= 0 ){
     int iPos = msg.indexOf( "," );
     SmsStorePos = msg.substring( iPos+1 );
   //  Serial.print( "SMS stored at " );
     Serial2.println( SmsStorePos );

     // EN: Ask to read the SMS store
     GprsReadSmsStore( SmsStorePos );
  }

  // EN: SMS store readed through UART (result of GprsReadSmsStore request)  
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // get number of sender
    int snPos = msg.indexOf("+1");
    snTmp = msg.substring(snPos+1);
    snFull = "";
    for (int i = 0; i < 11; i++){
      snFull += snTmp[i];    
    }
    Serial2.println(snFull);

    SmsContentFlag = 1;
    ClearGprsMsg();
    return;
  }
ProcessSms( msg );
    delSMS();
  snFull = "";}
   else if (SmsContentFlag == 1 & snFull != "18768621111")
   {
    Serial2.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
    delay(1000);
    Serial2.print("AT+CMGS=\"");
    Serial2.print(snFull);
    Serial2.print("\"\r");
    delay(1000);
    Serial2.print("Unauthorized Number!");
    delay(1000);
    Serial2.write(0x1A);  //Equivalent to sending Ctrl+Z
    snFull="";    
    return;
  
  }

  ClearGprsMsg();
  // EN: Always clear the flag
  SmsContentFlag = 0; 
}
void delSMS() {
  Serial2.print("AT+CMGD=");
  Serial2.println(SmsStorePos);
}