Example #1
0
void radio_hangup()
{
	radio_cmd("at+chld=1\r\n", 10);
	radio_cmd("at+xctms=0\r\n", 10);
	audiohw_switch_normal_call(FALSE);
	speaker_setup();
}
Example #2
0
int radio_register(int timeout)
{
	char buf[256];

	// enable auto registration
	radio_cmd("at+cops=0\r\n", 10);

	uint64_t startTime = timer_get_system_microtime();
	while(TRUE)
	{
		if(has_elapsed(startTime,  timeout * 1000))
			return -1;

		char* pos;
		radio_write("at+cops?\r\n");
		radio_read(buf, sizeof(buf));

		pos = buf;
		while(memcmp(pos, "+COPS: ", sizeof("+COPS: ") - 1) != 0)
			++pos;

		if(pos[7] != '0' || pos[8] != ',')
		{
			radio_cmd("at+cops=0\r\n", 10);
			continue;
		}

		char* name = &pos[12];
		char* lastQuote = name;
		while(*lastQuote != '\"')
			++lastQuote;
		*lastQuote = '\0';

		bufferPrintf("radio: Registered with %s\r\n", name);
		return 0;
	}
}
Example #3
0
void app_tick(void)
{
	uint8_t ch,data;
	uint8_t page,seg;
	uint16_t c,d;

	if (cons_getch(&ch)) {
		switch (ch) {
			case 'e':
				while (!cons_getch(&page));
				cmd[0]=4;
				cmd[1]=0xFE;
				cmd[2]=1;
				cmd[3]=page&0x1F;
				cmd[4]=0;
				if (radio_cmd()) goto ack;
				break;

			case 'p':
				while (!cons_getch(&page));
				cmd[0]=4;
				cmd[1]=0xFE;
				cmd[2]=2;
				cmd[3]=page&0x1F;
				cmd[4]=0;
				if (radio_cmd()) goto ack;
				break;

			case 'r':
				while (!cons_getch(&page));
				for (seg=0;seg<16;seg++) {
					cmd[0]=4;
					cmd[1]=0xFE;
					cmd[2]=3;
					cmd[3]=page&0x1F;
					cmd[4]=seg&0x0F;
					if (!radio_cmd()) break;
				}
				for (c=0;c<1024;c++) {
					cons_putc(rambuf[c]);
    					//cons_puthex8(rambuf[c]);
				}
				goto ack;
				break;

			case 'l':
				for (c=0;c<1024;c++) {
					while (!cons_getch(&data));
					rambuf[c]=data;
					//cons_puthex8(data);
				}
				c=0;
				for (seg=0;seg<16;seg++) {
					cmd[0]=68;
					cmd[1]=0xFE;
					cmd[2]=4;
					cmd[3]=0;
					cmd[4]=seg&0x0F;
					for (d=5;d<69;d++) {
						cmd[d]=rambuf[c++];
					}
					if (!radio_cmd()) break;
				}
				goto ack;
				break;
			case 'j':
				cmd[0]=2;
				cmd[1]=0xFE;
				cmd[2]=5;
				if (radio_cmd()) goto ack;
				break;

			case 0:
				cmd[0]=4;
				cmd[1]=0xFE;
				cmd[2]=0;
				cmd[3]=0;
				cmd[4]=0;
				radio_cmd();
				break;

ack:
				cons_putc(0);
				//cons_puts("ACK\r\n");
		}
	}
}
Example #4
0
void speaker_vol(int vol)
{
	char buf[100];
	sprintf(buf, "at+xdrv=0,1,%d,0\r\n", vol);
	radio_cmd(buf, 10);
}
Example #5
0
void radio_call(const char* number)
{
	char buf[256];

	bufferPrintf("radio: Setting up audio\r\n");

	audiohw_switch_normal_call(TRUE);

#ifdef CONFIG_3G
	radio_cmd("at+xdrv=0,8,0,0\r\n", 10);
#else
	radio_cmd("at+xdrv=0,4\r\n", 10);
	radio_cmd("at+xdrv=0,20,0\r\n", 10);
#endif

	// mute everything?
	radio_cmd("at+xdrv=0,1,0,0\r\n", 10);
	radio_cmd("at+xdrv=0,1,0,1\r\n", 10);
	radio_cmd("at+xdrv=0,1,0,2\r\n", 10);
	radio_cmd("at+xdrv=0,1,0,6\r\n", 10);

	// I really don't know
	radio_cmd("at+xdrv=0,24,1,1\r\n", 10);

	// note this is different from before
	radio_cmd("at+xdrv=0,0,1,1\r\n", 10);

	// microphone volume?
	radio_cmd("at+xdrv=0,1,100,1\r\n", 10);

	loudspeaker_vol(40);

#ifdef CONFIG_3G
	radio_cmd("at+xdrv=0,8,1,0\r\n", 10);
#endif

	speaker_vol(68);

	// clock
	// In general, lower is slower and higher is faster, but at some point it loops around.
	// This may mean the value is a bitset, e.g., at+xdrv=0,2,2,29 will set it to half speed
	radio_cmd("at+xdrv=0,2,2,10\r\n", 10);

	// channels?
	radio_cmd("at+xdrv=0,9,2\r\n", 10);

	// enable i2s?
	radio_cmd("at+xdrv=0,20,1\r\n", 10);

	// unmute?
	radio_cmd("at+xdrv=0,3,0\r\n", 10);

	// get notifications
	radio_cmd("at+xcallstat=1\r\n", 10);

	bufferPrintf("radio: Dialing\r\n");

	sprintf(buf, "atd%s;\r\n", number);

	radio_cmd(buf, 10);
	radio_cmd("at+cmut=0\r\n", 10);

#ifndef CONFIG_3G
	radio_cmd("at+xdrv=4,0,0,0,0,0\r\n", 10);

	speaker_vol(68);

	radio_cmd("at+xdrv=4,0,0,0,0,0\r\n", 10);
#endif

	// we now need to wait for +XCALLSTAT to indicate 0 or active status. This code is less
	// complex than it seems. The whole point is just to wait until we have a line that says
	// +XCALLSTAT: *,0. That's it.
	while(TRUE)
	{
		buf[0] = '\0';

		radio_read(buf, sizeof(buf));

		char* pos = buf;
		int len = strlen(buf);
		int callstat = -1;

		while(len >= (sizeof("+XCALLSTAT: ") - 1))
		{

			while(((int)(pos - buf)) <= (len - sizeof("+XCALLSTAT: ") + 1) && memcmp(pos, "+XCALLSTAT: ", sizeof("+XCALLSTAT: ") - 1) != 0)
				++pos;

			if(memcmp(pos, "+XCALLSTAT: ", sizeof("+XCALLSTAT: ") - 1) != 0)
				break;

			while(*pos != ',')
				++pos;

			++pos;

			if(*pos == '0')
			{
				bufferPrintf("radio: Call answered\r\n");
				callstat = 0;
				break;
			}

			++pos;
		}

		if(callstat == 0)
			break;
	}

#ifndef CONFIG_3G
	// do the rest
	radio_cmd("at+xdrv=4,0,0,0,0,0\r\n", 10);
#endif

	// why the same thing again?
	radio_cmd("at+xdrv=0,4\r\n", 10);
	radio_cmd("at+xdrv=0,20,0\r\n", 10);

	radio_cmd("at+xcallstat=0\r\n", 10);
}
Example #6
0
int speaker_setup()
{
	// something set at the very beginning
	radio_cmd("at+xdrv=0,41,25\r\n", 10);

#ifdef CONFIG_IPHONE
	bufferPrintf("radio: enabling internal speaker\r\n");

	// mute everything?
	radio_cmd("at+xdrv=0,1,0,0\r\n", 10);
	radio_cmd("at+xdrv=0,1,0,1\r\n", 10);
	radio_cmd("at+xdrv=0,1,0,2\r\n", 10);
	radio_cmd("at+xdrv=0,1,0,6\r\n", 10);

	// I really don't know
	radio_cmd("at+xdrv=0,24,1,1\r\n", 10);
	radio_cmd("at+xdrv=0,0,2,2\r\n", 10);

	loudspeaker_vol(100);
	speaker_vol(68);

	// clock
	// In general, lower is slower and higher is faster, but at some point it loops around.
	// This may mean the value is a bitset, e.g., at+xdrv=0,2,2,29 will set it to half speed
	radio_cmd("at+xdrv=0,2,2,10\r\n", 10);

	// channels?
	radio_cmd("at+xdrv=0,9,2\r\n", 10);

	// enable i2s?
	radio_cmd("at+xdrv=0,20,1\r\n", 10);

	// unmute?
	radio_cmd("at+xdrv=0,3,0\r\n", 10);

	bufferPrintf("radio: internal speaker enabled\r\n");
#endif
	return 0;
}
Example #7
0
int radio_wait_for_ok(int tries)
{
	return radio_cmd("at\r\n", tries);
}