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

📄 hcieventpacketproc.cpp

📁 蓝牙协议HCI层指令发送,主要用于测试HCI以下的代码及RF部分测试.
💻 CPP
📖 第 1 页 / 共 5 页
字号:

uint8    HCI_EventsInterfaceProcFunctions::DisconnectionCompleteEvent(CHCI_EventPacket& rHCI_EventPacket)
{
  CString Temp; int n;
  CString EventCode;
  CString Status;
  CString ConHandle;
  CString Reason;
  CString ParamStr;
  char buf1[10] = {'\0'},buf2[10] = {'\0'},buf3[10] = {'\0'};
  char ErrorDef[40] = {'\0'};

  int ComPortNo = g_odTheBTHostApp.GetCurComPortNo();

  uint8 EventIndex = rHCI_EventPacket.GetOpCode();
  uint8 ParamLength= rHCI_EventPacket.GetParmLen();

  sDisconnectionCompleteEvent* psDisconnectionCompleteEvent = (sDisconnectionCompleteEvent*)rHCI_EventPacket.GetHCI_EventPacketParam();

  Temp.Format ("%.2X", EventIndex ); 
  EventCode.Format    ("\tEvent Code:                  [1]  %s\n", Temp );  
  
  if(psDisconnectionCompleteEvent->Status) {
    g_pChildFrame->ErrorDef((char *)(&psDisconnectionCompleteEvent->Status), ErrorDef); 
 	Temp.Format ("%.2X   - %s", psDisconnectionCompleteEvent->Status, ErrorDef);
  }else
    Temp.Format ("%.2X",psDisconnectionCompleteEvent->Status);  

  
  //BT_itoa(&psDisconnectionCompleteEvent->Status ,1, buf1);
  //Temp.Format ("%s", buf1);   
  Status.Format       ("\tStatus:                      [1]  %s\n", Temp );

  Temp.Format ("%.4X", psDisconnectionCompleteEvent->ConnectionHandle);  n = Temp.GetLength(); 
  ConHandle.Format    ("\tConnectionHandle:            [%d]  %s\n",sizeof(psDisconnectionCompleteEvent->ConnectionHandle), Temp );

  BT_itoa(&psDisconnectionCompleteEvent->tReason ,1, buf3);
  Temp.Format ("%s", buf3);  n = Temp.GetLength(); 
  Reason.Format       ("\tReason:                      [%d]  %s\n",sizeof(psDisconnectionCompleteEvent->tReason), Temp );
 
  ParamStr = EventCode + Status	+ ConHandle	+ Reason ;
  g_pChildFrame->ParamListForOutput(ParamStr);
  return true;
  
}

//  struct sAuthenticationCompleteEvent
//  {
//    uint8				  Status;
//	  tConnectionHandle   ConnectionHandle;
//  };
//
uint8    HCI_EventsInterfaceProcFunctions::AuthenticationCompleteEvent(CHCI_EventPacket& rHCI_EventPacket)
{
  CString Temp; int n;
  CString EventCode;
  CString Status;
  CString ConHandle;
  CString ParamStr;
  char buf1[10] = {'\0'};
  char ErrorDef[40];
  int ComPortNo = g_odTheBTHostApp.GetCurComPortNo();

  uint8 EventIndex = rHCI_EventPacket.GetOpCode();
  uint8 ParamLength= rHCI_EventPacket.GetParmLen();

  sAuthenticationCompleteEvent* psAuthenticationCompleteEvent = (sAuthenticationCompleteEvent*)rHCI_EventPacket.GetHCI_EventPacketParam();

  Temp.Format ("%.2X", EventIndex ); 
  EventCode.Format    ("\tEvent Code:                  [1]  %s\n", Temp );  
  
 if(psAuthenticationCompleteEvent->Status) {
    g_pChildFrame->ErrorDef((char *)(&psAuthenticationCompleteEvent->Status), ErrorDef); 
 	Temp.Format ("%.2X   - %s", psAuthenticationCompleteEvent->Status, ErrorDef);
  }else
    Temp.Format ("%.2X",psAuthenticationCompleteEvent->Status);  

  Status.Format       ("\tStatus:                      [1]  %s\n", Temp );

  Temp.Format ("%-.4X", psAuthenticationCompleteEvent->ConnectionHandle);  n = Temp.GetLength(); 
  ConHandle.Format    ("\tConnectionHandle:            [%d]  %s\n",sizeof(psAuthenticationCompleteEvent->ConnectionHandle), Temp );

 
  ParamStr = EventCode + Status	+ ConHandle	;
  g_pChildFrame->ParamListForOutput(ParamStr);
  return true;
  

}

uint8    HCI_EventsInterfaceProcFunctions::RemoteNameRequestCompleteEvent(CHCI_EventPacket& rHCI_EventPacket)
                                 
{

  int n;
  int RemoteNameSize;
  CString Temp,strTemp;
  CString str;
  CString EventCode;
  CString Status;
  CString BD_ADDR;
  CString Remote_Name;
  CString ParamStr;
  char buf1[20] = {'\0'}, buf2[20] = {'\0'};
  char ErrorDef[40];
  struct psRetParams_tag
  {
    uint8		Status;
    UCHAR   	BD_ADDR[6];
    UCHAR		Remote_Name[REMOTE_NAME_SIZE]; 
  }*psRNRParams;

  psRNRParams = (psRetParams_tag*)rHCI_EventPacket.GetHCI_EventPacketParam();

  uint8 EventIndex = rHCI_EventPacket.GetOpCode();
  uint8 ParamLength= rHCI_EventPacket.GetParmLen();

  Temp.Format ("%.2X", EventIndex ); 
  EventCode.Format     ("\tEvent Code:                  [1]  %s\n", Temp );  


  if(psRNRParams->Status) {
    g_pChildFrame->ErrorDef((char *)(&psRNRParams->Status), ErrorDef); 
 	Temp.Format ("%.2X   - %s", psRNRParams->Status, ErrorDef);
  }else
    Temp.Format ("%.2X",psRNRParams->Status); 


  Status.Format        ("\tStatus:                      [1]  %s\n", Temp ); 
  Temp.Empty();

  BT_itoa(psRNRParams->BD_ADDR ,6, buf1);
  BT_ReverseStr(buf1, buf2);
  Temp.Format ("%s", buf2);   
  BD_ADDR.Format       ("\tBD_ADDR:                     [6]  %s\n", Temp );

  Temp.Empty();
 
  RemoteNameSize = ParamLength - sizeof(psRNRParams->BD_ADDR) - sizeof(psRNRParams->Status);

  //for (int i = 0 ; i < (RemoteNameSize / 35) + 1; i++)
  //{
  //	   strncpy(buf3,psRNRParams->Remote_Name[i], 36) 
  //     Temp.Format ("\t%s",buf3 );
  //}
  
  strTemp.Format("\t%s", psRNRParams->Remote_Name) ;

  Temp.Empty(); Temp = "\t";
  for (int i = 0, j = 0 ; i < RemoteNameSize; i++)
  {
	  if(psRNRParams->Remote_Name[i] != '\0')
	  {
	    str.Format("%X ",  psRNRParams->Remote_Name[i]);
        if( ((j) % 16) == 0)  
          Temp += "\n\t";

        Temp += str ;
		j++;
	  }
	  else
	  {
       if( ((j) % 16) == 0)  
		 Temp += "\n\t";
	   Temp += "00 ";
	   j++;
	  }
  }
  
  if(RemoteNameSize < 248 && (psRNRParams->Remote_Name[RemoteNameSize - 1] != '\0'))
  {
     //int k = Temp.GetLength();
   	 //Temp.SetAt( k,'\0');
 	 AfxMessageBox("\t\tWarning\nRemote Name is Supposed to be Padded by NULL!!",MB_OK);
  }
  n = RemoteNameSize;	 //Temp.GetLength(); 
  //assert(n <= REMOTE_NAME_SIZE);

  Remote_Name.Format   ("\tRemote_Name:                 [%d]  \n\n%s%s\n",n, strTemp, Temp );

  ParamStr = Status + BD_ADDR + Remote_Name; 
			 
  g_pChildFrame->ParamListForOutput(ParamStr);

  if(psRNRParams->Status)
  {
  } 
  return true;
}

uint8    HCI_EventsInterfaceProcFunctions::EncryptionChangeEvent(CHCI_EventPacket& rHCI_EventPacket)
{
  CString Temp; int n;
  CString EventCode;
  CString Status;
  CString ConHandle;
  CString EncryptionEnable;
  CString ParamStr;
  char buf1[15] = {'\0'},buf2[10] = {'\0'},buf3[10] = {'\0'};
  char ErrorDef[40];
  int ComPortNo = g_odTheBTHostApp.GetCurComPortNo();

  uint8 EventIndex = rHCI_EventPacket.GetOpCode();
  uint8 ParamLength= rHCI_EventPacket.GetParmLen();

  sEncryptionChangeEvent* psEncryptionChangeEvent = (sEncryptionChangeEvent*)rHCI_EventPacket.GetHCI_EventPacketParam();

  Temp.Format ("%.2X", EventIndex ); 
  EventCode.Format    ("\tEvent Code:                  [1]  %s\n", Temp );  
  
  if(psEncryptionChangeEvent->Status) {
    g_pChildFrame->ErrorDef((char *)(&psEncryptionChangeEvent->Status), ErrorDef); 
 	Temp.Format ("%.2X   - %s", psEncryptionChangeEvent->Status, ErrorDef);
  }else
    Temp.Format ("%.2X",psEncryptionChangeEvent->Status); 

  Status.Format       ("\tStatus:                      [%d]  %s\n",sizeof(psEncryptionChangeEvent->Status), Temp );

  Temp.Format ("%-.4X", psEncryptionChangeEvent->ConnectionHandle);  n = Temp.GetLength(); 
  ConHandle.Format    ("\tConnectionHandle:            [%d]  %s\n",sizeof(psEncryptionChangeEvent->ConnectionHandle), Temp );

  BT_itoa(&psEncryptionChangeEvent->u8EncryptionEnable ,1, buf3);
  Temp.Format ("%s", buf3);  n = Temp.GetLength(); 
  EncryptionEnable.Format("\tEncryption Enable:           [%d]  %s\n",sizeof(psEncryptionChangeEvent->u8EncryptionEnable), Temp );
 
  ParamStr = EventCode + Status	+ ConHandle	+ EncryptionEnable ;
  g_pChildFrame->ParamListForOutput(ParamStr);
  
  return true; 
}

uint8    HCI_EventsInterfaceProcFunctions::ChangeConnectionLinkKeyCompleteEvent(CHCI_EventPacket& rHCI_EventPacket)
{
  CString Temp; int n;
  CString EventCode;
  CString Status;
  CString ConHandle;
  CString ParamStr;
  char buf1[10] = {'\0'};
  char ErrorDef[40] = {'\0'};
  int ComPortNo = g_odTheBTHostApp.GetCurComPortNo();

  uint8 EventIndex = rHCI_EventPacket.GetOpCode();
  uint8 ParamLength= rHCI_EventPacket.GetParmLen();

  sChangeConnectionLinkKeyCompleteEvent* psChangeConLinkKey = (sChangeConnectionLinkKeyCompleteEvent*)rHCI_EventPacket.GetHCI_EventPacketParam();

  Temp.Format ("%.2X", EventIndex ); 
  EventCode.Format    ("\tEvent Code:                  [1]  %s\n", Temp );  
  
   if(psChangeConLinkKey->Status) {
    g_pChildFrame->ErrorDef((char *)(&psChangeConLinkKey->Status), ErrorDef); 
 	Temp.Format ("%.2X   - %s", psChangeConLinkKey->Status, ErrorDef);
  }else
    Temp.Format ("%.2X",psChangeConLinkKey->Status); 

  Status.Format       ("\tStatus:                      [%d]  %s\n",sizeof(psChangeConLinkKey->Status), Temp );

  Temp.Format ("%-.4X", psChangeConLinkKey->ConnectionHandle);  n = Temp.GetLength(); 
  ConHandle.Format    ("\tConnectionHandle:            [%d]  %s\n",sizeof(psChangeConLinkKey->ConnectionHandle), Temp );

  ParamStr = EventCode + Status	+ ConHandle	;
  g_pChildFrame->ParamListForOutput(ParamStr);
  
  return true; 
}
uint8    HCI_EventsInterfaceProcFunctions::MasterLinkKeyCompleteEvent(CHCI_EventPacket& rHCI_EventPacket)
{

  CString Temp; int n;
  CString EventCode;
  CString Status;
  CString ConHandle;
  CString KeyFlag;
  CString ParamStr;
  char buf1[10] = {'\0'},buf2[10] = {'\0'},buf3[10] = {'\0'};
  char ErrorDef[40] = {'\0'};

  int ComPortNo = g_odTheBTHostApp.GetCurComPortNo();

  uint8 EventIndex = rHCI_EventPacket.GetOpCode();
  uint8 ParamLength= rHCI_EventPacket.GetParmLen();

  sMasterLinkKeyCompleteEvent* psMasterLinkKey = (sMasterLinkKeyCompleteEvent*)rHCI_EventPacket.GetHCI_EventPacketParam();

  Temp.Format ("%.2X", EventIndex ); 
  EventCode.Format    ("\tEvent Code:                  [1]  %s\n", Temp );  
  
  if(psMasterLinkKey->Status) {
    g_pChildFrame->ErrorDef((char *)(&psMasterLinkKey->Status), ErrorDef); 
 	Temp.Format ("%.2X   - %s", psMasterLinkKey->Status, ErrorDef);
  }else
    Temp.Format ("%.2X",psMasterLinkKey->Status); 

  Status.Format       ("\tStatus:                      [%d]  %s\n",sizeof(psMasterLinkKey->Status), Temp );

  Temp.Format ("%-.4X", psMasterLinkKey->ConnectionHandle);  n = Temp.GetLength(); 
  ConHandle.Format    ("\tConnectionHandle:            [%d]  %s\n",sizeof(psMasterLinkKey->ConnectionHandle), Temp );

  BT_itoa(&psMasterLinkKey->u8KeyFlag ,1, buf3);
  Temp.Format ("%s", buf3);  n = Temp.GetLength(); 
  KeyFlag.Format      ("\tKey Flag:                    [%d]  %s\n",sizeof(psMasterLinkKey->u8KeyFlag), Temp );
 
  ParamStr = EventCode + Status	+ ConHandle	+ KeyFlag ;
  g_pChildFrame->ParamListForOutput(ParamStr);
  
  
  return true; 
}
uint8    HCI_EventsInterfaceProcFunctions::ReadRemoteSupportedFeaturesCompleteEvent(CHCI_EventPacket& rHCI_EventPacket)
{
  CString Temp; int n;
  CString EventCode;
  CString Status;
  CString ConHandle;
  CString LMP_Features;	//8 Bytes
  CString ParamStr;
  char buf1[10] = {'\0'},buf2[20] = {'\0'},buf3[25] = {'\0'};
  char ErrorDef[40] = {'\0'};
  int ComPortNo = g_odTheBTHostApp.GetCurComPortNo();

  uint8 EventIndex = rHCI_EventPacket.GetOpCode();
  uint8 ParamLength= rHCI_EventPacket.GetParmLen();

  sReadRemoteSupportedFeaturesCompleteEvent* psReadRemote = (sReadRemoteSupportedFeaturesCompleteEvent*)rHCI_EventPacket.GetHCI_EventPacketParam();

  Temp.Format ("%.2X", EventIndex ); 
  EventCode.Format    ("\tEvent Code:                  [1]  %s\n", Temp );  
  
  if(psReadRemote->Status) {
    g_pChildFrame->ErrorDef((char *)(&psReadRemote->Status), ErrorDef); 
 	Temp.Format ("%.2X   - %s", psReadRemote->Status, ErrorDef);
  }else
    Temp.Format ("%.2X",psReadRemote->Status); 

  Status.Format       ("\tStatus:                      [%d]  %s\n",sizeof(psReadRemote->Status), Temp );
  
  Temp.Format ("%-.4X",psReadRemote->ConnectionHandle );  n = Temp.GetLength(); 
  ConHandle.Format    ("\tConnectionHandle:            [%d]  %s\n",sizeof(psReadRemote->ConnectionHandle), Temp );

  for(int i = 0; i < 25;i++) buf2[i] = '\0';
  BT_itoa(&psReadRemote->sLMP_Features ,8, buf2);
  BT_ReverseStr(buf2, buf3);
  Temp.Format ("%s", buf3);  n = Temp.GetLength(); 
  LMP_Features.Format ("\tLMP_Features:                [%d]  %s\n",sizeof(psReadRemote->sLMP_Features), Temp );
 
  ParamStr = EventCode + Status	+ ConHandle	+ LMP_Features ;
  g_pChildFrame->ParamListForOutput(ParamStr);
  
  
  return true;
}

/*teHCI_EVENT_ERROR_CODE Status,
 tConnectionHandle  ConnectionHandle,

⌨️ 快捷键说明

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