SIM908IDE100/SIM900.cpp
byte GSM::CheckRegistration(void)
{
  byte status;
  byte ret_val = REG_NOT_REGISTERED;

  if (CLS_FREE != GetCommLineStatus()) return (REG_COMM_LINE_BUSY);
  SetCommLineStatus(CLS_ATCMD);
  _cell.println("AT+CREG?");
  // 5 sec. for initial comm tmout
  // 50 msec. for inter character timeout
  status = WaitResp(5000, 50); 

  if (status == RX_FINISHED) {
    // something was received but what was received?
    // ---------------------------------------------
    if(IsStringReceived("+CREG: 0,1") 
      || IsStringReceived("+CREG: 0,5")) {
      // it means module is registered
      // ----------------------------
      module_status |= STATUS_REGISTERED;
    
    
      // in case GSM module is registered first time after reset
      // sets flag STATUS_INITIALIZED
      // it is used for sending some init commands which 
      // must be sent only after registration
      // --------------------------------------------
      if (!IsInitialized()) {
        module_status |= STATUS_INITIALIZED;
        SetCommLineStatus(CLS_FREE);
        InitParam(PARAM_SET_1);
      }
      ret_val = REG_REGISTERED;      
    }
    else {
      // NOT registered
      // --------------
      module_status &= ~STATUS_REGISTERED;
      ret_val = REG_NOT_REGISTERED;
    }
  }
  else {
    // nothing was received
    // --------------------
    ret_val = REG_NO_RESPONSE;
  }
  SetCommLineStatus(CLS_FREE);
 

  return (ret_val);
}
/**********************************************************
Method checks if the GSM module is registered in the GSM net
- this method communicates directly with the GSM module
  in contrast to the method IsRegistered() which reads the
  flag from the module_status (this flag is set inside this method)

- must be called regularly - from 1sec. to cca. 10 sec.

return values: 
      REG_NOT_REGISTERED  - not registered
      REG_REGISTERED      - GSM module is registered
      REG_NO_RESPONSE     - GSM doesn't response
      REG_COMM_LINE_BUSY  - comm line between GSM module and Arduino is not free
                            for communication
**********************************************************/
Method checks if the GSM module is registered in the GSM net
this method communicates directly with the GSM module
in contrast to the method IsRegistered() which reads the
flag from the module_status (this flag is set inside this method)

must be called regularly - from 1sec. to cca.

return values:
REG_NOT_REGISTERED  - not registered
REG_REGISTERED      - GSM module is registered
REG_NO_RESPONSE     - GSM doesn't response
REG_COMM_LINE_BUSY  - comm line between GSM module and Arduino is not free
for communication
Method checks if the GSM module is registered in the GSM net this method communicates directly with the GSM module in contrast to the method IsRegistered () which reads the flag from the module_status ( this flag is set inside this method ) must be called regularly - from 1sec . to cca . return values : REG_NOT_REGISTERED - not registered REG_REGISTERED - GSM module is registered REG_NO_RESPONSE - GSM doesn ' t response REG_COMM_LINE_BUSY - comm line between GSM module and Arduino is not free for communication
byte GSM::CheckRegistration(void)
{
  byte status;
  byte ret_val = REG_NOT_REGISTERED;
  if (CLS_FREE != GetCommLineStatus()) return (REG_COMM_LINE_BUSY);
  SetCommLineStatus(CLS_ATCMD);
  _cell.println("AT+CREG?");
  status = WaitResp(5000, 50); 
  if (status == RX_FINISHED) {
    if(IsStringReceived("+CREG: 0,1") 
      || IsStringReceived("+CREG: 0,5")) {
      module_status |= STATUS_REGISTERED;
      ----------------
      if (!IsInitialized()) {
        module_status |= STATUS_INITIALIZED;
        SetCommLineStatus(CLS_FREE);
        InitParam(PARAM_SET_1);
      }
      ret_val = REG_REGISTERED;      
    }
    else {
      module_status &= ~STATUS_REGISTERED;
      ret_val = REG_NOT_REGISTERED;
    }
  }
  else {
    ------
    ret_val = REG_NO_RESPONSE;
  }
  SetCommLineStatus(CLS_FREE);
  return (ret_val);
}
byte GSM :: CheckRegistration ( void ) { byte status ; byte ret_val = REG_NOT_REGISTERED ; if ( CLS_FREE != GetCommLineStatus ( ) ) return ( REG_COMM_LINE_BUSY ) ; SetCommLineStatus ( CLS_ATCMD ) ; _cell . println ( " " ) ; status = WaitResp ( 5000 , 50 ) ; if ( status == RX_FINISHED ) { if ( IsStringReceived ( " " ) || IsStringReceived ( " " ) ) { module_status |= STATUS_REGISTERED ; if ( ! IsInitialized ( ) ) { module_status |= STATUS_INITIALIZED ; SetCommLineStatus ( CLS_FREE ) ; InitParam ( PARAM_SET_1 ) ; } ret_val = REG_REGISTERED ; } else { module_status &= ~ STATUS_REGISTERED ; ret_val = REG_NOT_REGISTERED ; } } else { ret_val = REG_NO_RESPONSE ; } SetCommLineStatus ( CLS_FREE ) ; return ( ret_val ) ; }
Method checks if the GSM module is registered in the GSM net
this method communicates directly with the GSM module
in contrast to the method IsRegistered() which reads the
flag from the module_status (this flag is set inside this method)
Method checks if the GSM module is registered in the GSM net this method communicates directly with the GSM module in contrast to the method IsRegistered () which reads the flag from the module_status ( this flag is set inside this method )
// 5 sec. for initial comm tmout // 50 msec. for inter character timeout // something was received but what was received? // --------------------------------------------- // it means module is registered // ---------------------------- // in case GSM module is registered first time after reset // sets flag STATUS_INITIALIZED // it is used for sending some init commands which  // must be sent only after registration // -------------------------------------------- // NOT registered // -------------- // nothing was received // --------------------