📄 callback.cpp
字号:
#include "CallBack.h"
#include "Config.h"
#include "Comport.h"
VOID Connection_CallBack(WORD wServiceClass, BYTE* lpBdAddr, UCHAR ucStatus, DWORD dwConnetionHandle)
{
switch(ucStatus)
{
case STATUS_INCOMING_CONNECT:
printf("Incoming Connection Connect Indication!\n");
break;
case STATUS_INCOMING_DISCONNECT:
printf("Incoming Connection Disconnect Indication!\n");
break;
case STATUS_OUTGOING_CONNECT:
printf("Outgoing Connection Connect Indication!\n");
break;
case STATUS_OUTGOING_DISCONNECT:
printf("Outgoing Connection Disconnect Indication!\n");
break;
}
printf("Remote Address: %02X:%02X:%02X:%02X:%02X:%02X\n",
lpBdAddr[5],
lpBdAddr[4],
lpBdAddr[3],
lpBdAddr[2],
lpBdAddr[1],
lpBdAddr[0]);
printf("Service Class: %d\n", wServiceClass);
printf("Connection Handle: %d\n", dwConnetionHandle);
if(wServiceClass==CLS_SERIAL_PORT)//SPP
{
if(ucStatus == STATUS_INCOMING_CONNECT)
{
BOOL bIsOutGoing;
SPP_CONNECT_INFO sppConnInfo ={0};
DWORD dwLen = sizeof(SPP_CONNECT_INFO);
BYTE bdAddr[6]={0};
WORD wClass;
if(BT_GetConnectInfo(dwConnetionHandle, &bIsOutGoing, &wClass,
bdAddr,&dwLen,(BYTE*)&sppConnInfo) == BTSTATUS_SUCCESS)
{
printf("Com Port = %d\n",sppConnInfo.ucComPort);
printf("Remote Address: %02X:%02X:%02X:%02X:%02X:%02X\n",
bdAddr[5],
bdAddr[4],
bdAddr[3],
bdAddr[2],
bdAddr[1],
bdAddr[0]);
//If incoming spp connected, get the COM port and start IO
if(ucStatus == STATUS_INCOMING_CONNECT)
{
if(g_bclient)
StartIoOnComport(dwConnetionHandle, sppConnInfo.ucComPort, TRUE);
else
StartIoOnComport(dwConnetionHandle, sppConnInfo.ucComPort, FALSE);
}
}
else
printf("Fail to get com port\n",sppConnInfo.ucComPort);
}
else if(ucStatus == STATUS_INCOMING_DISCONNECT || ucStatus == STATUS_OUTGOING_DISCONNECT)
{
//If spp disconnected, stop IO on the COM port
StopIoOnComport(dwConnetionHandle);
}
}
else if (wServiceClass == CLS_PAN_GN)//PAN
{
if(ucStatus == STATUS_OUTGOING_CONNECT)
{
BOOL bIsOutGoing;
BYTE connInfo[MAX_BUFLEN] = {0};
DWORD dwLen = sizeof(SPP_CONNECT_INFO);
BYTE bdAddr[6]={0};
WORD wClass;
if(BT_GetConnectInfo(dwConnetionHandle, &bIsOutGoing, &wClass,
bdAddr,&dwLen, connInfo) == BTSTATUS_SUCCESS)
{
}
else
printf("Fail to get PAN IP\n");
}
else if(ucStatus == STATUS_INCOMING_DISCONNECT || ucStatus == STATUS_OUTGOING_DISCONNECT)
{
//If spp disconnected, stop IO on the COM port
//StopIoOnSocket(dwConnetionHandle);
}
}
}
VOID Error_CallBack(DWORD dwErrorCode)
{
printf("Error Code:%x\n", dwErrorCode);
// g_dwLastError = dwErrorCode;
}
VOID BTStatus_CallBack(UCHAR ucStatus)
{
if(ucStatus == STATUS_BLUETOOTH_STARTED)
{
g_bFlag = TRUE;
printf("Bluetooth is started\n");
}
else if(ucStatus == STATUS_BLUETOOTH_STOPED)
{
g_bFlag = FALSE;
printf("Bluetooth is stoped\n");
}
else
{
g_bFlag = FALSE;
printf("Invalid parameter in Bluetooth ind\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -