📄 config.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// File Name:
// config.c
// Abstract:
// realize the functions
//
// Author:
// ZHU AN
// Revision History:
// 15/12/2006 17:35:10 AM ZHU AN Created
/////////////////////////////////////////////////////////////////////////////
#include "Config.h"
#include "MonitorBlueSoleil.h"
BOOL g_bFlag = TRUE;
HANDLE g_hForceExit = NULL;
COM_IO g_comIoList[MAX_IO_THREAD]={0};
DEVICE_INFO g_DeviceInfo[MAX_CONNECT_COUNT] = {0};;
HANDLE g_hSocket = NULL;
BOOL g_bclient = TRUE;
INT32 g_iSocketPort = 0;
CHAR g_sSocketAddress[IP_LEN]={0};
INT32 g_iMonitorType = DETECT_BY_API;
BOOL g_bAsynchronous = TRUE;
INT32 g_iInquireLen = 0;
INT32 g_iInquireMode = INQUIRY_GENERAL_MODE;
INT32 g_iSpecificService = CLS_SERIAL_PORT;
HANDLE g_hDetectThread = NULL;
HANDLE g_hBlueSoleilStarted = NULL;
HANDLE g_hBlueSoleilStopping = NULL;
BOOL ReadConfigurationFile(VOID)
{
CHAR szTmp[MAX_PATHLEN]={0};
GetCurrentDirectory(256, szTmp);
strcat(szTmp,"\\spp.ini");
//self role
g_bclient = (BOOL)GetPrivateProfileInt("SPP_COM_PORT", "DO Client IO", 0, szTmp);
g_iSocketPort = GetPrivateProfileInt("REMOTE_ADDRESS", "Socket Port", 0, szTmp);
g_iMonitorType = GetPrivateProfileInt("MONITOR_BSOL", "Monitor Type", DETECT_BY_API, szTmp);
g_bAsynchronous = GetPrivateProfileInt("BT_INQUIRY_DEVICE", "bAsynchronous", 1, szTmp);
g_iInquireLen = GetPrivateProfileInt("BT_INQUIRY_DEVICE", "Inquiry Length", 0, szTmp);
g_iInquireMode = GetPrivateProfileInt("BT_INQUIRY_DEVICE", "Inquiry Mode", INQUIRY_GENERAL_MODE, szTmp);
g_iSpecificService = GetPrivateProfileInt("BT_BROWSE_SERVICE", "Specific Service Class", CLS_SERIAL_PORT, szTmp);
return TRUE;
}
VOID PrintError(CHAR* lpszAPI,DWORD dwError)
{
printf(lpszAPI);
printf(" returned %d: ",dwError);
switch(dwError){
case BTSTATUS_SUCCESS:
printf("Succeeded.\n");
break;
case BTSTATUS_FAIL:
printf("General failed!\n");
break;
case BTSTATUS_SYSTEM_ERROR:
printf("System error occured!\n");
break;
case BTSTATUS_BT_NOT_READY:
printf("Bluetooth is not ready.\n");
break;
case BTSTATUS_ALREADY_PAIRED:
printf("BlueSoleil is already paired with the device.\n");
break;
case BTSTATUS_AUTHENTICATE_FAILED:
printf("Authentication failed!\n");
break;
case BTSTATUS_BT_BUSY:
printf("Bluetooth is busy with browsing services or connecting to a device.\n");
break;
case BTSTATUS_CONNECTION_EXIST:
printf("The connection to the service is already established.\n");
break;
case BTSTATUS_CONNECTION_NOT_EXIST:
printf("The connection does not exist or is released.\n");
break;
case BTSTATUS_PARAMETER_ERROR:
printf("Parameter error!\n");
break;
case BTSTATUS_SERVICE_NOT_EXIST:
printf("Service does not exist.\n");
break;
default:
printf("Unknown error.\n");
}
}
DWORD Help_InputAddr(CHAR temp_addr[], UCHAR bdAddr[6])
{
CHAR cmp_temp[2]={0};
UCHAR buffer[6] = {0};
for(INT32 i = 1; i < 13; i++)
{
if((temp_addr[i-1]>='0' && temp_addr[i-1]<='9') ||
(temp_addr[i-1]>='A' && temp_addr[i-1] <= 'F') ||
(temp_addr[i-1]>='a' && temp_addr[i-1] <= 'f'))
{
if(i%2 == 1)
{
if(temp_addr[i-1]>='0' && temp_addr[i-1]<='9')
cmp_temp[0] = temp_addr[i-1] - '0';
else if(temp_addr[i-1]>='A' && temp_addr[i-1]<='F')
cmp_temp[0] = temp_addr[i-1] - 'A' + 10;
else if(temp_addr[i-1]>='a' && temp_addr[i-1]<='f')
cmp_temp[0] = temp_addr[i-1] - 'a' + 10;
}
else if(i%2 == 0)
{
if(temp_addr[i-1]>='0' && temp_addr[i-1]<='9')
cmp_temp[1] = temp_addr[i-1] - '0';
else if(temp_addr[i-1]>='A' && temp_addr[i-1]<='F')
cmp_temp[1] = temp_addr[i-1] - 'A' + 10;
else if(temp_addr[i-1]>='a' && temp_addr[i-1]<='f')
cmp_temp[1] = temp_addr[i-1] - 'a' + 10;
buffer[6- i/2] = cmp_temp[0]*16 + cmp_temp[1];
}
}
else
{
printf("Invalid Address, Please input again!\n");
return BTSTATUS_FAIL;
}
}
memcpy(bdAddr, buffer, 6);
return BTSTATUS_SUCCESS;
}
BOOL ConfigConnectSppParam(BYTE* pParam, DWORD* pParamLen)
{
PSPP_CLIENT_PARAM pSppParam = (PSPP_CLIENT_PARAM)pParam;
memset(pSppParam, 0, sizeof(SPP_CLIENT_PARAM));
pSppParam->dwSize = sizeof(SPP_CLIENT_PARAM);
if(pParamLen)
*pParamLen = sizeof(SPP_CLIENT_PARAM);
return TRUE;
}
BOOL ConfigConnectParams(WORD wSvcCls, BYTE* pParam, DWORD* pParamLen)
{
BOOL bRet;
switch(wSvcCls)
{
case CLS_SERIAL_PORT:
bRet = ConfigConnectSppParam(pParam, pParamLen);
break;
case CLS_PAN_NAP:
bRet = ConfigConnectSppParam(pParam, pParamLen);
break;
default:
if(pParamLen)
*pParamLen = 0;
bRet = TRUE;
break;
}
return bRet;
}
VOID ShowDeviceInfo(VOID)
{
printf("Devices List\n");
for (INT32 i = 0; 0 != g_DeviceInfo[i].DeviceInfo.dwSize; i++)
{
printf("Device No.%d\n Device Address: %02X:%02X:%02X:%02X:%02X:%02X\n",
i,
g_DeviceInfo[i].DeviceInfo.address[5],
g_DeviceInfo[i].DeviceInfo.address[4],
g_DeviceInfo[i].DeviceInfo.address[3],
g_DeviceInfo[i].DeviceInfo.address[2],
g_DeviceInfo[i].DeviceInfo.address[1],
g_DeviceInfo[i].DeviceInfo.address[0]);
printf(" Device Name: %s\n", g_DeviceInfo[i].DeviceInfo.szName);
if(g_DeviceInfo[i].DeviceInfo.bPaired)
printf(" Device Is Paired: Yes\n");
else
printf(" Device Is Paired: No\n");
printf("\n");
}
}
VOID ShowService(UINT32 index)
{
printf("# Svc ID Svc Handle Svc Name\n");
for(UINT32 i = 0; i < g_DeviceInfo[index].iServiceNum; i++)
{
printf("#%d 0x%x %d %s\n", i,
g_DeviceInfo[index].pServiceInfo[i].wServiceClassUuid16,
g_DeviceInfo[index].pServiceInfo[i].dwServiceHandle,
g_DeviceInfo[index].pServiceInfo[i].szServiceName);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -