コード例 #1
0
void cellular_init()
{
	//configure pins
	DDRB = DDRB | (1 << PORTB1);//make Cell phone ON/OFF output
	DDRB = DDRB & (0 << PORTB2); //set pin 3 "poweron MON" to be input
	
	_delay_ms(500); //wait for these pins to be stable

	if(cellular_isOn())
	{
		ToggleCellModule(); //turn it off then!
		while(cellular_isOn()) //wait for it to turn off
		{
			//maybe add an escape condition
		}
	}
	if(!cellular_isOn()) //it's off i guess
	{
		ToggleCellModule();
		while(!cellular_isOn()) //wait for it to turn on
		{
			//maybe?
		}
	}
	ATsend_no("AT\r"); //get the modules attention.
	_delay_ms(7000);
	ATsend_no("AT\r"); //no really we want your attention.
	_delay_ms(5000);	//we need these delays, because some time during
						//the init process the module will send a MWI
						//and the next command we send will likely fail
						//if it is an AT then everything is fine.
						//however this can only increase our odds...
						//without real parsing we have to do this.
}
コード例 #2
0
int cellular_ON()
{
	if(cellular_isOn())
	{
		//cellular_OFF();
		//cellular_modem_reset();
		//lcd_puts("found to be on\n");
		_delay_ms(2000);
		ATsend_no("AT\r"); //get the modules attention.
		_delay_ms(1000);
		ATsend_no("AT\r");
		_delay_ms(1000);
		ATsend_no("AT#NITZ=1,1\r");
		_delay_ms(1000);
		ATsend_no("AT+CTZU=1,1\r");
		return 0;
	}
	else //if(!cellular_isOn()) //it's off i guess
	{
		//lcd_puts("turn on");
		//ToggleCellModule();
		PORTB = PORTB | (1<<PORTB1);
		_delay_ms(5000);
		PORTB = PORTB & ~(1<<PORTB1);
		_delay_ms(500);
		int count = 0;
		while(!cellular_isOn()&&count<10) //two second time out to turn on to modem rest
		{
			lcd_putc('T');
			_delay_ms(200);
			count++;
		}
		if(count >= 10)
		{
		//	lcd_puts("timeout. reset\n");
			cellular_modem_reset();
			return -1;
		}			
		else
		{
			//lcd_puts("found to be on2\n");
			_delay_ms(2000);
			ATsend_no("AT\r"); //get the modules attention.
			_delay_ms(1000);
			ATsend_no("AT\r");
			_delay_ms(1000);
			//we need these delays, because some time during
			ATsend_no("AT#NITZ=1,1\r");
			_delay_ms(1000);
			ATsend_no("AT+CTZU=1,1\r");
			return 0;
		}			
	}					//the init process the module will send a MWI
			//and the next command we send will likely fail
						//if it is an AT then everything is fine.
						//however this can only increase our odds...
						//without real parsing we have to do this.	
}
コード例 #3
0
int cellular_OFF()
{
	/*if(!cellular_isOn())
	{
		cellular_ON();
		//return -2;
	}*/		
	ATsend_no("AT#SHDN\r");
	_delay_ms(5000);
	//else
	if(cellular_isOn())
	{
		//ToggleCellModule();
		PORTB = PORTB | (1<<PORTB1);
		_delay_ms(5000);
		PORTB = PORTB & ~(1<<PORTB1);
		
		int count = 0;
		while(cellular_isOn() && count < 40)//15 second time out to modem reset
		{
			_delay_ms(375);
			count++;
		}
		if(count >= 40)
		{
			//cellular_modem_reset();
			PORTC = PORTC & (0 << PORTC7); //kill myself
			return -1;//silly...
		}			
		else
		{
			_delay_ms(1500);
			//cellular_ON();
			return 0;
		}			
	}
	else
	{
		PORTC = PORTC & (0 << PORTC7); //kill myself
	}
	
}
コード例 #4
0
int cellular_modem_reset()
{
		PORTB = PORTB | (1<<PORTB3);
		_delay_ms(5000);
		PORTB = PORTB & ~(1<<PORTB3);
		if(cellular_isOn())
		{
			_delay_ms(2000);
			ATsend_no("AT\r");
			return 0;
		}
		else
		{
			_delay_ms(2000);
			return cellular_ON();
		}
}