コード例 #1
0
ファイル: SIM908a.c プロジェクト: wetnt/Arduino_public
void loop()
{

        if(started)
        {
        
                check_gps();
                Check_SMS();
        
        }





}
コード例 #2
0
ファイル: gsmControl.cpp プロジェクト: popai/gsmControl
void loop()
{
// The loop function is called in an endless loop
	int id = 0;
	//int error = 0;			//error from function
	byte i = 0;
	if (delEEPROM)
		return;

	if (config)
	{
		if (Serial.available() > 0)
		{
			while (Serial.available() > 0)
			{
				sms_rx[i] = (Serial.read()); //read data
				i++;
			}
			sms_rx[i - 1] = 0;

			delay(5);
			//Serial.println(sms_rx);
			if (strstr_P(sms_rx, PSTR("citeste")) != 0)
			{
				for (int i = 0; i <= 512; i += 18)
					ReadEprom(sms_rx, i);
			}
			else if (strlen(sms_rx) != 0)
				if (!CfgCmd(sms_rx))
					Serial.println("ERROR");
			*sms_rx = 0x00;
		}

		else
		{
			id = Check_SMS();
			if (id == GETSMS_AUTH_SMS || id == GETSMS_NOT_AUTH_SMS)
				Config(number, sms_rx);
			*sms_rx = 0x00;
			id = 0;
		}
		//test SIM900 module up
		if (AT_RESP_OK == gsm.SendATCmdWaitResp("AT", 500, 100, "OK", 5))
			PORTB &= ~(1 << PINB5);			//ERROR LED off
		else PORTB |= (1 << PINB5);			//ERROR LED on

		//XXX feeding the dog
		wdt_reset();
	}
	else
	{
		VerificIN();
		id = Check_SMS();
		//Serial.println(id);
		if (id == GETSMS_AUTH_SMS)
			Comand(number, sms_rx);
		else if (id == GETSMS_NOT_AUTH_SMS)
		{
			//Check if receive a pas
			char buffer[64];
			ReadEprom(buffer, 18 * 24);
			if (strcmp(buffer, sms_rx) == 0)
			{
				//write number on sim
				uint8_t nr_pfonnr = 1;	//hold number of phone number on sim
				char tmpnr[20];
				for (byte i = 1; i < 7; i++)
				{
					if (1 == gsm.GetPhoneNumber(i, tmpnr))
						++nr_pfonnr;	//Find number in specified position
					else
						break;
				}

				if (nr_pfonnr < 7) //max 6 number
				{
					if (gsm.WritePhoneNumber(nr_pfonnr, number) != 0)
					{
#ifndef DEBUG_GSMRX
						sprintf_P(buffer, PSTR("%s writed at position %d"),
								number, nr_pfonnr);
						Serial.println(buffer);
#endif
						//++nr_pfonnr;
						strcpy_P(buffer, PSTR("Acceptat"));
						gsm.SendSMS(number, buffer);

					}
					else
					{
						strcpy_P(buffer, PSTR("ERROR"));
						Serial.println(buffer);
						gsm.SendSMS(number, buffer);
					}
				}
				else
				{
					strcpy_P(buffer, PSTR("Nu slot"));
					gsm.SendSMS(number, buffer);
				}
			}
		}
		*number = 0x00;
		*sms_rx = 0x00;
		id = 0;

	}
	//XXX feeding the dog
	wdt_reset();

	//test SIM900 module up
	if (AT_RESP_OK == gsm.SendATCmdWaitResp("AT", 500, 100, "OK", 5))
		PORTB &= ~(1 << PINB5);			//ERROR LED off
	else PORTB |= (1 << PINB5);			//ERROR LED on

	delay(50);
}