コード例 #1
0
ファイル: gsm.c プロジェクト: WindWiz/windnode
static bool wait_gsm_status(int s)
{
	int status;
	int attempt;

	attempt = 0;
	while (attempt < 10) {
		status = gsm_status(f_gsm);

		if (status == s)
			return true;

		switch (status) {
		case 0:
			printf("%s: gsm not registered, idle\n", __func__);
			break;
		case 1:
			printf("%s: gsm registered\n", __func__);
			break;

		case 2:
			printf("%s: not registered, searching\n", __func__);
			break;
		case 3:
			printf("%s: not registered, denied\n", __func__);
			break;
		case 4:
			printf("%s: not registered, unknown\n", __func__);
			break;
		case 5:
			printf("%s: not registered, roaming\n", __func__);
			break;
		}

		usleep(1000000);
		attempt++;
	}
	return false;
}
コード例 #2
0
ファイル: gsm.c プロジェクト: derkling/adcontrol
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();
}