?? sdkfunc.cpp
字號(hào):
/************************************************************************************
// Sample code for calling IVT BlueSoleil APIs
Copyright (c) 2004 -2005 , IVT Corporation. All rights reserved.
*******************************************************************************************/
#include "main.h"
#include "SdkFunc.h"
#include "HelpFunc.h"
#include <stdio.h>
#include "menu.h"
#include "ComPort.h"
#include "ConnectCheck.h"
GENERAL_CONNECT_INFO g_connList[MAX_CONNECT_COUNT] = {0};
GENERAL_SERVICE_INFO g_svcList[MAX_SERVICE_COUNT]={0};
SPPEX_INFO g_sppexSvr[MAX_SPPEX]={0};
DWORD g_dwLastError;
BOOL SDK_Init()
{
DWORD dwBtVersion;
if(!BT_InitializeLibrary()){
printf("BT_InitializeLibrary() failed!\n");
return FALSE;
}
dwBtVersion = BT_GetVersion();
printf("BlueSoleil API version: %d.%d\n",LOBYTE(LOWORD(dwBtVersion)),HIBYTE(LOWORD(dwBtVersion)));
BT_GetBtSpecVersion(&dwBtVersion);
printf("Compliant BT Spec version: %d.%d\n",LOBYTE(LOWORD(dwBtVersion)),HIBYTE(LOWORD(dwBtVersion)));
ChangeMenu2(MENU_STANDBY);
ShowMenu();
return TRUE;
}
void SDK_Done()
{
BT_UninitializeLibrary();
ChangeMenu2(MENU_IDLE);
}
void SDK_BtPair()
{
BLUETOOTH_DEVICE_INFO devInfo={0};
devInfo.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);
memcpy(devInfo.address,g_targetBdAddr,6);
char lpPinCode[MAX_PIN_CODE_LENGTH]={0};
WORD wPinCodeLen = 0;
GetPrivateProfileString("BT_PAIR_DEVICE", "Pin Code", NULL, lpPinCode, MAX_PIN_CODE_LENGTH, g_szIniPath);
wPinCodeLen = strlen(lpPinCode);
int bKeepOldKeyOnFail;
bKeepOldKeyOnFail=GetPrivateProfileInt("BT_PAIR_DEVICE", "KeepOldKeyOnFail", 0, g_szIniPath);
int bShowPincode;
bShowPincode=GetPrivateProfileInt("BT_PAIR_DEVICE", "ShowPincode", 0, g_szIniPath);
DWORD dwResult;
dwResult=BT_PairDevice(&devInfo, wPinCodeLen, ((wPinCodeLen == 0) ? NULL : (UCHAR*)lpPinCode),bKeepOldKeyOnFail,bShowPincode);
PrintError("BT_PairDevice",dwResult);
}
void SDK_BtUnpair()
{
DWORD dwResult;
dwResult = BT_UnpairDevice(g_targetBdAddr);
PrintError("BT_UnpairDevice",dwResult);
}
void SDK_BtInquiry()
{
UCHAR ucInqMode = INQUIRY_GENERAL_MODE,
ucInqLen = 15;
BLUETOOTH_DEVICE_INFO lpDevsList[MAX_SERVICE_COUNT] = {0};
DWORD DevsListLen = sizeof(BLUETOOTH_DEVICE_INFO) * MAX_SERVICE_COUNT;
char temp[MAX_PATH]={0};
if(GetPrivateProfileString("BT_INQUIRY_DEVICE", "Inquiry Mode", NULL, temp, MAX_PATH, g_szIniPath)==0){
printf("Get Inquiry Mode Failed!\n");
return;
}
ucInqMode = atoi(temp);
//Get Inquiry Length 0x00-0xFF
if(GetPrivateProfileString("BT_INQUIRY_DEVICE", "Inquiry Length", NULL, temp, MAX_PATH, g_szIniPath)==0){
printf("Get Inquiry Mode Failed!\n");
return;
}
ucInqLen = atoi(temp);
if(ucInqLen<=0){
printf("Get Inquiry Mode Failed!\n");
return;
}
BOOL bAsynchronous = GetPrivateProfileInt("BT_INQUIRY_DEVICE", "bAsynchronous",1, g_szIniPath);
DWORD dwResult;
if(bAsynchronous)
DevsListLen = 0;
dwResult = BT_InquireDevices(ucInqMode, ucInqLen, &DevsListLen, lpDevsList);
PrintError("BT_InquireDevices",dwResult);
if(!bAsynchronous && dwResult == BTSTATUS_SUCCESS){
printf("Devices List\n");
DWORD i, offset;
offset = sizeof(BLUETOOTH_DEVICE_INFO);
BLUETOOTH_DEVICE_INFO *pDevice;
for(i=0; i<((DevsListLen)/sizeof(BLUETOOTH_DEVICE_INFO)); i++){
pDevice=(BLUETOOTH_DEVICE_INFO*)((UCHAR*)lpDevsList+i*offset);
printf("Device No.%d\n Device Address: %02X:%02X:%02X:%02X:%02X:%02X\n",
i,
pDevice->address[5],
pDevice->address[4],
pDevice->address[3],
pDevice->address[2],
pDevice->address[1],
pDevice->address[0]);
DWORD dwMask = 0;
BLUETOOTH_DEVICE_INFO_EX devInfo = {0};
memcpy(&devInfo.address, pDevice->address, DEVICE_ADDRESS_LENGTH);
devInfo.dwSize = sizeof(BLUETOOTH_DEVICE_INFO_EX);
devInfo.szName[0]='\0';
dwMask = MASK_DEVICE_NAME;
DWORD dwResult;
dwResult = BT_SetRemoteDeviceInfo(dwMask, &devInfo);
PrintError("BT_SetRemoteDeviceInfo",dwResult);
dwResult = BT_GetRemoteDeviceInfo(dwMask, &devInfo);
PrintError("BT_GetRemoteDeviceInfo",dwResult);
printf(" Device Name: %s\n", devInfo.szName);
PrintDeviceClassInfo(pDevice->classOfDevice);
if(pDevice->bPaired)
printf(" Device Is Paired: Yes\n");
else
printf(" Device Is Paired: No\n");
}
}
}
void SDK_BtBrowseServices()
{
BLUETOOTH_DEVICE_INFO devInfo={0};
devInfo.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);
memcpy(devInfo.address,g_targetBdAddr,6);
GENERAL_SERVICE_INFO pClsidList[MAX_SERVICE_COUNT]={0};
DWORD ClsidListLen = MAX_SERVICE_COUNT*sizeof(GENERAL_SERVICE_INFO);
BOOL bBrowseAllService = TRUE;
//Clear the g_device_service_info
memset((void*)g_svcList, 0, MAX_SERVICE_COUNT*sizeof(GENERAL_SERVICE_INFO));
char temp[MAX_PATH]={0};
//Get Browse All Services
if(GetPrivateProfileString("BT_BROWSE_SERVICE", "Browse All Services", NULL, temp, MAX_PATH, g_szIniPath)==0){
printf("Get Browse All Services Failed!\n");
return;
}
strcpy(temp, strupr(temp));
if(strcmp(temp, "TRUE") == 0)
bBrowseAllService = TRUE;
else if(strcmp(temp, "FALSE") == 0)
bBrowseAllService = FALSE;
else{
printf("Invalid Browse All Service!\n");
return;
}
if(!bBrowseAllService){
if(GetPrivateProfileString("BT_BROWSE_SERVICE", "Specific Service Class", NULL, temp, MAX_PATH, g_szIniPath)==0){
printf("Get Specific Service Class Failed!\n");
return;
}
if((pClsidList[0].wServiceClassUuid16 = atoi(temp)) == 0){
printf("Invalid Specific Service Class!\n");
return;
}
}
DWORD dwReusult;
dwReusult = BT_BrowseServices(&devInfo, bBrowseAllService, &ClsidListLen, pClsidList);
PrintError("BT_BrowseServices",dwReusult);
if(dwReusult ==BTSTATUS_SUCCESS) {
printf("Device Address: %02X:%02X:%02X:%02X:%02X:%02X \n",
g_targetBdAddr[5],
g_targetBdAddr[4],
g_targetBdAddr[3],
g_targetBdAddr[2],
g_targetBdAddr[1],
g_targetBdAddr[0]);
printf("# Svc ID Svc Handle Svc Name\n");
for(DWORD i=0; i<ClsidListLen/sizeof(GENERAL_SERVICE_INFO);i++){
printf("#%d 0x%x %d %s\n", i, pClsidList[i].wServiceClassUuid16, pClsidList[i].dwServiceHandle,pClsidList[i].szServiceName);
g_svcList[i].wServiceClassUuid16 = pClsidList[i].wServiceClassUuid16;
g_svcList[i].dwServiceHandle = pClsidList[i].dwServiceHandle;
g_svcList[i].dwSize = pClsidList[i].dwSize;
}
}
}
void PostConnect(DWORD dwHanlde, WORD wSvcId, BYTE* pParam)
{
switch(wSvcId)
{
case CLS_SERIAL_PORT:
{
//Start IO on the COM port
int bDClientIO = GetPrivateProfileInt("SPP_COM_PORT", "DO Client IO", 0,g_szIniPath);
if(bDClientIO)
StartIoOnComport(dwHanlde,((PSPP_CLIENT_PARAM)pParam)->ucComPort, TRUE);
}
break;
case CLS_HEADSET:
case CLS_HANDSFREE:
{
}
break;
default:;
}
}
void SDK_BtConnectService()
{
SDK_BtBrowseServices();
printf("Please input the number of the service. (-1 to return)\n");
int nInput;
scanf("%d",&nInput);
if(nInput == -1 )
return;
if(nInput > MAX_SERVICE_COUNT || nInput<0 || g_svcList[nInput].wServiceClassUuid16 ==0){
printf("Invalid item.\n");
}
BLUETOOTH_DEVICE_INFO devInfo={0};
devInfo.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);
memcpy(devInfo.address, g_targetBdAddr, 6);
BYTE abyConnParam[512];
DWORD dwParamLen = 512;
if(!ConfigConnectParams(g_svcList[nInput].wServiceClassUuid16,abyConnParam,&dwParamLen)){
printf("Failed to config parameters.\n");
return;
}
DWORD dwResult;
DWORD dwHandle;
dwResult = BT_ConnectService(&devInfo, &g_svcList[nInput], dwParamLen==0 ? NULL : abyConnParam, &dwHandle);
PrintError("BT_ConnectService",dwResult);
if(dwResult == BTSTATUS_SUCCESS){
PostConnect(dwHandle, g_svcList[nInput].wServiceClassUuid16,abyConnParam);
}
}
void SDK_BtDisConnectService()
{
SDK_EnumConnections();
printf("Please input the number of the connection. (-1 to return)\nBSOL_CLIENT>");
int nInput;
scanf("%d",&nInput);
if(nInput == -1 )
return;
if(nInput > MAX_CONNECT_COUNT || nInput<0 || g_connList[nInput].dwHandle ==0){
printf("Invalid input.\n");
return;
}
DWORD dwResult = BT_DisconnectService(g_connList[nInput].dwHandle);
PrintError("BT_DisconnectService",dwResult);
if(dwResult == BTSTATUS_SUCCESS){
memset(&g_connList[nInput], 0 , sizeof(GENERAL_CONNECT_INFO));
}
}
void SDK_BtGetRemoteInfo()
{
DWORD dwMask = 0;
BLUETOOTH_DEVICE_INFO_EX devInfo={0};
devInfo.dwSize = sizeof(BLUETOOTH_DEVICE_INFO_EX);
memcpy(devInfo.address, g_targetBdAddr, 6);
char temp[MAX_PATH];
if(GetPrivateProfileString("GET_REMOTE_DEVICE_INFO", "Mask", NULL, temp, MAX_PATH, g_szIniPath)==0){
printf("Get Mask Failed!\n");
return;
}
if((dwMask = atoi(temp)) == 0){
printf("Invalid Parameters: 'Mask'\n");
return;
}
//dwMask = 0x0000ffff;
DWORD dwResult = BT_GetRemoteDeviceInfo(dwMask, &devInfo);
PrintError("BT_GetRemoteDeviceInfo",dwResult);
if(dwResult != BTSTATUS_SUCCESS){
return;
}
printf("Device Name: %s\nDevice class: %02X %02X %02X\n",
devInfo.szName,
devInfo.classOfDevice[0],
devInfo.classOfDevice[1],
devInfo.classOfDevice[2]);
if(devInfo.bConnected)
printf("Device Connection Status: YES\n");
else
printf("Device Connection Status: NO\n");
if(devInfo.bPaired)
printf("Device Paired Status: YES\n");
else
printf("Device Paired Status: NO\n");
printf("\n");
printf("Device Clock Offset: %d\n", devInfo.wClockOffset);
printf("Device LPM version: %d\n", devInfo.ucLmpVersion);
printf("Device Manufacture: %d\n", devInfo.wManuName);
printf("Device Sub LMP version: %d\n", devInfo.wLmpSubversion);
printf("Device dwDataRecvBytes: %d\n", devInfo.dwDataRecvBytes);
printf("Device dwDataSentBytes: %d\n", devInfo.dwDataSentBytes);
printf("Device Signal Strength: %d\n", devInfo.cSignalStrength);
}
void SDK_BtSetRemoteInfo()
{
DWORD dwMask = 0;
BLUETOOTH_DEVICE_INFO_EX devInfo = {0};
devInfo.dwSize = sizeof(BLUETOOTH_DEVICE_INFO_EX);
memcpy(devInfo.address, g_targetBdAddr, 6);
char temp[MAX_PATH];
//Get Mask
if(GetPrivateProfileString("SET_REMOTE_DEVICE_INFO", "Mask", NULL, temp, MAX_PATH, g_szIniPath)==0) {
printf("Get Mask Failed!\n");
return;
}
if((dwMask = atoi(temp)) == 0){
printf("Invalid Parameters: 'Mask'\n");
return;
}
//Get Name
if(GetPrivateProfileString("SET_REMOTE_DEVICE_INFO", "Name", "", devInfo.szName, MAX_DEVICE_NAME_LENGTH, g_szIniPath)==0){
}
//Get Device Class
if(GetPrivateProfileString("SET_REMOTE_DEVICE_INFO", "Device Class", NULL, temp, MAX_PATH, g_szIniPath)==0){
printf("Get Device Class Failed!\n");
return;
}
if(Help_InputDeviceClass(temp, devInfo.classOfDevice) == BTSTATUS_FAIL){
printf("Invalid Device Class!\n");
return;
}
//Get Clock Offset
if(GetPrivateProfileString("SET_REMOTE_DEVICE_INFO", "Clock Offset", NULL, temp, MAX_PATH, g_szIniPath)==0) {
printf("Get Link Key Failed!\n");
return;
}
devInfo.wClockOffset = atoi(temp);
DWORD dwResult;
dwResult = BT_SetRemoteDeviceInfo(dwMask, &devInfo);
PrintError("BT_SetRemoteDeviceInfo",dwResult);
}
void SDK_BtGetLocalInfo()
{
DWORD dwMask = 0;
BLUETOOTH_DEVICE_INFO_EX devInfo = {0};
devInfo.dwSize = sizeof(BLUETOOTH_DEVICE_INFO_EX);
memcpy(devInfo.address, g_targetBdAddr, 6);
char temp[MAX_PATH];
//Get Mask
if(GetPrivateProfileString("GET_LOCAL_DEVICE_INFO", "Mask", NULL, temp, MAX_PATH, g_szIniPath)==0){
printf("Get Mask Failed!\n");
return;
}
if((dwMask = atoi(temp)) == 0){
printf("Invalid Parameters: 'Mask'\n");
return;
}
memcpy(devInfo.address, g_targetBdAddr, 6);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -