Ejemplo n.º 1
0
// Update the CSQ signal level indicator
static void updateCSQ(void) {
	uint8_t csq, level;

	// Prevently switch-off all CSQ LEDs
	LED_GSM_OFF();

	// Checking for network availability
	if (!gsmRegistered()) {
		// Forcing GMS reset
		gsmPowerOn();
	}

	// Update the signal level
	gsmUpdateCSQ();
	csq = gsmCSQ();
	DB(LOG_INFO("GSM CSQ [%hu]\r\n", csq));
	if (csq == 99)
		return;

	// Set the CSQ ledbar according to the CSQ signal level
	level = 0;
	if (csq > 2)
		level = 1;
	if (csq > 16)
		level = 2;
	if (csq > 24)
		level = 3;
	LED_GSM_CSQ(level);

	// TODO if not network attached: force network scanning and attaching
}
Ejemplo n.º 2
0
void NORETURN gsmTesting(Serial *port) {

	gsmInit(port);
	gsmPowerOn();
	gsmSMSConf(0);

	//gsmUpdateConf();
	//DELAY(1000);

	//DELAY(5000);
	//gsmSMSSend("+393473153808", "Test message from RFN");
	while (1) {
		gsmUpdateCSQ();
		DELAY(5000);
		//gsmSMSSend("+393473153808", "Test message from RFN");
		//gsmSMSSend("+393357963938", "Test message from RFN");
		//DELAY(10000);
	}

//  Prova invio messaggio molto lungo, che impiega tutti i 160 caratteri a
//	disposizione per un singolo SMS. Vediamo se i buffer disponibili sono
//	sufficienti.  Ciao


	for(uint8_t i=1; i<100; i++) {

		LOG_INFO("Iteration %d/100\n", i);

		gsmSMSList();
		DELAY(1000);

		//gsmSMSLast(&msg);
		for (uint8_t j=1; j<10; j++) {
			gsmSMSByIndex(&msg,j);
			DELAY(500);
		}

		gsmSMSDelRead();

		if (!(i%3))
			gsmSMSSend("+393357963938", "Test message from RFN");

		DELAY(10000);
	}

	DELAY(15000);
	gsmPowerOff();
}
Ejemplo n.º 3
0
int8_t controlNotifyBySMS(const char *dest, const char *buff) { 
	int8_t result;
	uint8_t try;
	uint8_t timeout;

	LOG_INFO("Notify by SMS\nDest: %s\nText: %s\r\n", dest, buff);

	// Checking for Network availability
	try = 0; timeout = 10;
	result = gsmRegisterNetwork();
	while (result != OK) {
		LOG_WARN("Network not available\r\n");
		if (try % timeout) {
			LOG_WARN("Trying again in 60s\r\n");
			DELAY(60000);
		} else {
			// Resetting modem once every (10*timeout) mins
			gsmPowerOn();
			timeout += 10;
			if (timeout >= 250)
				timeout = 10;
		}
		result = gsmRegisterNetwork();
		try++;
	}
	
	// Checking for signal quality
	try = 0; timeout = 20;
	result = gsmUpdateCSQ();
	while (result != OK ||
			gsmCSQ() == 99 || gsmCSQ() == 0) {
		LOG_WARN("Low network signal [%d]\r\n", gsmCSQ());
		if (try % timeout) {
			LOG_WARN("Trying again in 60s\r\n");
			DELAY(60000);
		} else {
			// Resetting modem once every (20*timeout) mins
			gsmPowerOn();
			timeout += 20;
			if (timeout >= 240)
				timeout = 20;
		}
		result = gsmRegisterNetwork();
		try++;
	}

	// Trying to send the SMS
	result = 0;
	GSM(result = gsmSMSSend(dest, buff));
	return result;
}
void smsSplitAndParse(char const *from, char *sms) {
	char *cmd = sms;
	char *cmdEnd = sms;

	// Reset response buffer
	cmdBuff[0] = '\0';

	while (*cmdEnd) {
		
		// Find command separator, or end of SMS
		for ( ; (*cmdEnd && *cmdEnd != ';'); ++cmdEnd)
			;// nop
		
		// 
		if (*cmdEnd == ';') {
			*cmdEnd = '\0';
		}

		// lowercase current command
		for (char *p = cmd; *p != ' ' && *p; ++p) {
			if (*p >= 'A' && *p <= 'Z')
				*p += 'a'-'A';
		}

		//DB2(LOG_INFO("CMD: %s\r\n", cmd));

		// Parse current command
		command_parse(&dbg_port.fd, cmd);

		// Go on with next command
		*cmdEnd = ';';
		for ( ; *cmdEnd; ++cmdEnd) {
			if ((*cmdEnd != ';') && (*cmdEnd != ' '))
				break;
		}
		cmd = cmdEnd;

	}

	// If a non empty buffer has been setup: send it as response
	if (cmdBuff[0] == '\0')
		return;

	controlNotifyBySMS(from, cmdBuff);

	// Wait for SMS being delivered
	DELAY(10000);

}
Ejemplo n.º 4
0
/*
* Task running
*/
void gsmTask(void const *arg){
	
	int i;
	unsigned int reloadcnt = 0;
	int flag = 0;
	int cnt = 0;
	int gps_fail = 0;
	
	osDelay(3000);
	//osSignalWait (0x01, osWaitForever);
	
	while(1){
		if (reloadcnt > 3 ){
			reloadcnt = 0;
			osDelay(1000);
			gsmPowerOff();
			flag = 6;
			//osSignalWait (0x01, osWaitForever);
		}
		
			//gsmPowerOff();

	gsmPowerOn();
		reloadcnt++;
	
	if ( gsmInitModem() == AT_OK ){
		osDelay(1000);
		if ( gsmInitGPRS() == AT_STATE_IP_STATUS ){
			while(1){
			osDelay(100);
			if ( gsmConnect(GSM_SERVER_IP,GSM_SERVER_PORT) == AT_STATE_IP_CONNECT ){
				  osDelay(100);
				#ifdef WIALON_TRACKER	
					if ( wialonLogin (GSM_SERVER_IMEI, GSM_SERVER_PASSWORD ) == WN_LOGIN ){
				#endif
						
				
						flag = gsmSendStatus( flag );
						if ( flag < 0 ) break;
						
						flag = gsmWork( flag );
						if ( flag < 0 ) break;

#ifdef WIALON_TRACKER						
						 
						if ( flag == 8 ) gps_fail++;	else { gps_fail = 0; cnt++; }		//No GPS? add that
						if (cnt > 100 ) {flag = 4; cnt = 0;}	//Some message 100point
						if (cnt == 0 && flag == 1 ) flag = 5;	//No GPS	
						if (gps_fail > 50 ) flag = 7;						
						
#endif
								
			//		}		
#ifdef WIALON_TRACKER	
					flag = 2;
				}
#endif
			}
		}
		}
	}
	flag = 3;
	//gsm[254] = 0;
	}
	
	
}