⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 BlueTooth SDK Source Code! I hope that everybody like it.
💻 C
📖 第 1 页 / 共 2 页
字号:
		printf(">> HF initiated voice recognition deactivation request!\nHF_TESTER>");
		break;
	case HF_DIAL_IND: /*HF initiated phone number dial*/
		printf("\n>> ATCMD RX: (ATD)\n");
		printf(">> HF initiated dial indication!\n");
	    memcpy(buf, param, param_len);
	    buf[param_len] = 0;
	    printf(">> The phone number is %s.\nHF_TESTER>", buf);
		break;
	case HF_MEM_DIAL_IND: /*HF initiated memory dial*/
		printf("\n>> ATCMD RX: (ATD>)\n");
		printf(">> HF initiated memory dial indication!\n");
		memcpy(buf, param, param_len);
		buf[param_len] = 0;
		printf(">> The memory location is %s.\nHF_TESTER>", buf);
		break;
	case HF_LASTNUM_REDIAL_IND: /*HF initiated last number redial*/
		printf("\n>> ATCMD RX: (BLDN)\n");
		printf(">> HF initiated last number redial indication!\nHF_TESTER>");
		break;
	case HF_DTMF_IND: /*HF transmitted DTMF code*/
		printf("\n>> ATCMD RX: (AT+VTS=...)\n");
		printf(">> HF initiated DTMF indication!\n");
		printf(">> The DTMF code received is %c.\nHF_TESTER>", *param);
		break;
	case VOICE_TAG_PHONE_NUM_REQ: /*HF initiated voice tag phone number request*/
		printf("\n>> ATCMD RX: (AT+BINP=1)\n");
		printf(">> HF initiated voice tag phone number indication!\nHF_TESTER>");
		break;
	case NREC_DISENABLE_IND: /*HF request AG to disenable NREC function*/
		printf("\n>> ATCMD RX: (AT+NREC=0)\n");
		printf(">> HF initiated NREC disenable indication!\nHF_TESTER>");
		break;
	case HF_AVAILABLE_IND: /*The connection with HF has been established*/
		printf("\n>> Available service in remote device is %s", (*param == '1') ? "Headset" : "Hands-Free");
		printf("\n>> Service Level Connection is established!\nHF_TESTER>");
		break;
	case HF_UNAVAILABLE_IND: /*The connection with HF has been released*/
		printf("\n>> Service Level Connection is released!\nHF_TESTER>");
		break;
	case AUDIO_CONN_ESTABLISHED_IND: /*The SCO connection with HF has been established*/
		printf("\n>> Audio Connection is established!\nHF_TESTER>");
		break;
	case AUDIO_CONN_RELEASED_IND: /*The SCO connection with HF has been released*/
		printf("\n>> Audio Connection is released!\nHF_TESTER>");
		break;
	case SPKVOL_CHANGED_IND: /*HF speaker volumer change indication*/
		printf("\n>> ATCMD RX: (AT+VGS=...)\n");
		printf(">> Speaker Volume of HF device is changed!\n");
		printf(">> Speaker Volume of HF device is changed to %d.\nHF_TESTER>", *param);
		break;
	case EXTEND_CMD_IND: /*HF transmitted extended AT Command*/
		printf("\n>> ATCMD RX: Extended AT Command\n");
	    memcpy(extend_cmd, param, param_len);
	    extend_cmd[param_len] = 0;
	    printf("\n>> The Extended AT Command is: %s.\nHF_TESTER>", extend_cmd);
		HFT_SendExtendATCmd("\r\nERROR\r\n");
		break;
	case PCM_DATA_SEND_COMPLETE_IND: /*PCM data has been sent to HF*/
		memcpy(&trans_bytes, param, sizeof(DWORD));
		printf("\n>> %ld bytes have been sent to Hands-Free device!\nHF_TESTER>", trans_bytes);
		break;
	case PCM_DATA_SAVE_COMPLETE_IND: /*PCM data from HF device has been saved to the specific buffer*/
		memcpy(&trans_bytes, param, sizeof(DWORD));
		g_pcm_buffer_size = trans_bytes;
		printf("\n>> %ld bytes have been saved to PCM data buffer!\nHF_TESTER>", trans_bytes);
		break;
	default:
		break;
	}
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
	This function is the pair event processing callback function registered to 
	hf tester library.
Arguments:
	bd_addr[IN]		Bluetooth BaseBand Address of the under tested Hands-Free device.
	event[IN]		event code.
	param[IN]       parameter for the event
Return Value:
	None.
---------------------------------------------------------------------------*/
static void APP_PairCbk(UCHAR *bd_addr, UCHAR event, const UCHAR *param)
{
    switch (event) {
	case PIN_CODE_REQ_IND: /*PIN code request indication*/
		{
    	    UCHAR pin_code[5];
	        printf("\n>> PIN Code Request Indication!\nHF_TESTER>");
			/*get the PIN code from configuration file, it is "0000" for Sony Ericsson Hands-Free*/
	        GetPrivateProfileString("HANDS-FREE", "PinCode", "", pin_code, MAX_PIN_CODE_LEN, g_init_file);
			/*send the PIN code*/
	        HFT_SendPinCode(bd_addr, pin_code);
		    
		}
		break;
	case LINK_KEY_REQ_IND: /*Link Key reqeust indication*/
		{
	        UCHAR tempstr[35];
            UCHAR temp[2];
	        UCHAR i;
	        UCHAR link_key[MAX_LINK_KEY_LEN];
	        UCHAR bd[BD_ADDR_LEN];
    
	        printf("\n>> Link Key Request Indication!\nHF_TESTER>");
			/*get the previous paired device's bd_addr from configuration file*/
	        GetBDAddr(bd);
	        /*if the remote bd_addr is not equal to the previous paired device's bd_addr, reject the link key request*/
	        if (memcmp(bd_addr, bd, BD_ADDR_LEN)) {  
		        HFT_RejectLinkKeyReq(bd_addr);
		        return;
	        }
			/*
			retrieve the link key for the Hands-Free device to be paired with from configuration file, 
			which is saved to the configuration file when LINK_KEY_NOTIF_IND event is received.
			*/
	        GetPrivateProfileString("HANDS-FREE", "LinkKey", "", tempstr, 35, g_init_file);
            for (i=0; i<16; i++) {
                temp[0] = tempstr[2 * i];
                temp[1] = tempstr[2 * i + 1];
                link_key[i] = ((temp[0]>='0' && temp[0]<='9') ? temp[0]-'0' : temp[0]-'A'+10) * 16 + ((temp[1]>='0' && temp[1]<='9') ? temp[1]-'0' : temp[1]-'A'+10);
	        }
			/*send the link key*/
            HFT_SendLinkKey(bd_addr, link_key);
		}
		break;
	case LINK_KEY_NOTIF_IND:  /*Link Key notification indication: pair succeed!*/
		{
	        int i, j = 0;
	        char buffer[50];
            
	        printf("\n>> Link Key Notification Indication!\nHF_TESTER>");
	        sprintf(buffer,"%02X:%02X:%02X:%02X:%02X:%02X", bd_addr[5], bd_addr[4], bd_addr[3], bd_addr[2],	bd_addr[1], bd_addr[0]);
			/*save the Baseband address of the paired Hands-Free device to the configuration file*/
	        WritePrivateProfileString("HANDS-FREE", "BDAddress", buffer, g_init_file);
	        for (i = 0; i < 16; i++)
		        j += sprintf( buffer + j, "%02X", param[i]);
			/*save the Link Key for the paired Hands-Free device to the configuration file*/
	        WritePrivateProfileString("HANDS-FREE", "LinkKey", buffer, g_init_file);
		}
		break;
	default:
		break;
	}
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
	This function is called to get one Bluetooth Baseband Address from paired 
	Hands-Free devices.
	The bd_addr is retrieved from the HF Tester configuration file.
	For this implementation, only one paired bd_addr would be saved to the 
	configuration file, therefore, only the last paired bd_addr would be returned.
	If more paired bd_addr required to be saved, the implementation could be 
	modified, and in this situation, which paired bd_addr would be returned 
	by the function GetBDAddr is implementation dependent.
Arguments:
	bd_addr[IN]		Bluetooth BaseBand Address of the paired Hands-Free device.
Return Value:
	None.
---------------------------------------------------------------------------*/
static void GetBDAddr(UCHAR *bd_addr) 
{
	int i;
	char tempstr[35], temp[2];
	
	GetPrivateProfileString("HANDS-FREE", "BDAddress", "", tempstr, 32, g_init_file);
	if (strcmp(tempstr, "")==0 ) {
		memset(bd_addr, 0, BD_ADDR_LEN);
	}
	else { 
		for (i = 0; i < 20; i++)
			if('a'<tempstr[i] && tempstr[i]<'z')
				tempstr[i] = _toupper(tempstr[i]);
		for ( i=0; i<6; i++ ) {
			temp[0] = tempstr[3 * i];
			temp[1] = tempstr[3 * i + 1];
			bd_addr[5 - i] = ((temp[0]>='0' && temp[0]<='9') ? temp[0]-'0' : temp[0]-'A'+10) * 16 + ((temp[1]>='0' && temp[1]<='9') ? temp[1]-'0' : temp[1]-'A'+10);
		}
	}
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
	This function is used to list inquired Hands-Free device.
Arguments:
	dev_num[IN]		Number of the inquired Hands-Free devices.
	dev_list[IN]    List of the inquired Hands-Free devices.
Return Value:
	The index of the user selected Hands-Free device.
---------------------------------------------------------------------------*/
static DWORD ShowFindDevInfo(DWORD dev_num, struct DEVICE_INFO *dev_list)
{
	DWORD i = 0;
	DWORD j = 0;
	char quote = 32;
	DWORD idx = 0;

	printf("\n++++++++++++++++++++++     total  %d  Devices  Found     +++++++++++++++++++++++\n", dev_num);
	printf("number  device name %21hc device address %5hc", quote, quote);
	for(i = 0; i < dev_num; i ++) {
		printf("\n  %d%5hc", i + 1, quote);
		printf("%-34hs", (dev_list + i)->dev_name);
		for(j = 5; j > 0; j --)
			printf("%02X:",(dev_list + i)->bd_addr[j]);
		printf("%02X%3hc", (dev_list + i)->bd_addr[0], quote);
	}
	printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
	do {
    	printf("Enter the number of the device, enter 0 to quit: ");
		idx = 0;
		scanf("%d", &idx);
	} while (idx < 0 || idx > dev_num);
	return idx;
}

/*parse user input command, it is just used for demo!*/
UCHAR ParseCmd(UCHAR* cmd)
{
	UCHAR *p1=cmd, *p2, tmp;

	g_argc=0;
	for (;*p1!='\0';) {
		if (*p1==' '||*p1=='\t') {
			p1++;
			continue;
		}
		for (p2=p1;*p2!='\0';p2++) {
			if (*p2==' '||*p2=='\t') {
				break;
			}
		}
		tmp=*p2;
		*p2='\0';
		if (p1!=p2) {
			strcpy(g_argv[g_argc], p1); 
			g_argc++;
		}
		if (tmp=='\0') {
			break;
		}
		p1=p2; p1++;
	}
	if (g_argc==0) {		
		return -1;
	}
	return 0;
}

/*demo menu*/
static void DemoMenu()
{
    printf("\n***************** IVT Hands-Free Tester Demo Menu********************\n");
	printf("<1> to Inquire and Pair nearby Hands-Free devices.\n");
	printf("<2> to Connect with HF device.\n");
    printf("<3> to Establish SCO Connection with HF device.\n");
	printf("<4> to Release SCO Connection with HF device.\n");
    printf("<5> to Disconnect with HF device.\n");
    printf("<6> to Reset Hands-Free Tester.\n");
    printf("<7 + AT Command> to Send Extended AT Command.\n");
	printf("<a> to Start save PCM data.\n");
	printf("<b> to Stop save PCM data.\n");
	printf("<c> to Start send specific PCM data to Hands-Free device.\n");
	printf("<d> to Start send saved PCM data to Hands-Free device.\n");
	printf("<e> to Stop send PCM data to Hands-Free device.\n");
	printf("<f> to Get current saved PCM data size.\n");
	printf("<g + block size> to Read PCM data from PCM data buffer.\n");
	printf("<0> to Quit the application\n");
    printf("**********************************************************************\n");
	printf("HF_TESTER>");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -