Example #1
0
bool momo_register_and_start_reporting()
{
  bool success = true;
  if ( gsm_on() )
  {
    //if ( !current_momo_state.registered ) { //For now, always re-register
      if ( attempt_registration() )
      {
        success = true;
      } else {
        success = false;
      }
    //}
    gsm_off();
  }

  if (success) {
    rtcc_datetime zero_time = {0,0,0,0,0,0,0,0};
    rtcc_set_time( &zero_time );
    start_report_scheduling();
  }

  return success;
}
Example #2
0
static int8_t gsmAutobaud(void)
{
	char buff[8];
	int8_t try;
	int8_t resp;

	// A HEX string such as “00 49 49 49 49 FF FF FF FF” will be sent out
	// through serial port at the baud rate of 115200 immediately after
	// SIM900 is powered on.

	// Send AT command for autobaud
	gsmDebug("Autobauding...\n");

	for(try=3; try; try--) {
		_gsmWriteLine("AT");
		_gsmRead(buff, 8);
		if (buff[0] == '0') {
			gsmDebug("DONE\n");
			// The GSM has been already configured:
			// return error to avoid re-configuration
			return ERROR;
		}
		resp = _gsmReadResult();
		if (resp == OK) {
			gsmDebug("DONE\n");
			return resp;
		}
		gsmDebug("FAILED\n");
	}
	return ERROR;
}
#else
# define gsmAutobaud() OK
#endif

static int8_t gsmConfigure(void)
{
	char buff[8];
	int8_t resp;

	// Load configuration
	_gsmWriteLine("ATE0");
	_gsmRead(buff, 8);
	resp = _gsmReadResult();
	if (resp != OK) {
		return resp;
	}

	// Configure TA Response Format
	_gsmWriteLine("ATV0");
	resp = _gsmReadResult();
	if (resp != OK) {
		return resp;
	}

	return OK;
}

int8_t gsmPowerOn(void)
{
	int8_t result;

	// TODO: check if the modem is already on
	// either using the STATUS line or by sending an AT command
	if (gsm_status()) {
#if 0
		// Modem already ON... checking AT command
		_gsmWriteLine("AT");
		result = _gsmReadResult();
		if (result == OK)
			return result;
		// Not responding to AT comand... shut-down
		gsm_powerOff();
		DELAY(10000);
#endif
		// Resetting the modem
		LOG_INFO("GSM: Resetting...\n");
		gsm_reset();
	} else {
		LOG_INFO("GSM: Powering-on...\n");
		gsm_on();
	}

	// When DCE powers on with the autobauding enabled, it is recommended
	// to wait 2 to 3 seconds before sending the first AT character.
	LOG_INFO("Wait (20s) for network attachment\n");
	DELAY(20000);

	result = gsmAutobaud();
	if (result != OK)
		return result;

	result = gsmConfigure();
	return result;
}

void gsmPowerOff(void)
{
	LOG_INFO("GSM: Powering-off...\n");
	gsm_off();
	LED_GSM_OFF();
}