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

📄 hcievent.cpp

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

//--------------------------------------------------------------- %FILH_BEG% --
//
//  Project:		$$ProjectName
//
//  File name:		HCIEvent.h
//  Author:			
//  Description:	  
//
//  Revision History:
//  $Log: $
//
//  Rev 1.00  15 July 2000 Initial release
//    
//
//  Copyright (c) TelenComm Corporation  2000   -   All rights reserved    
//--------------------------------------------------------------- %FILH_END% 
//------------------------------------------------------------------------------
//
//  Includes
//
//------------------------------------------------------------------------------
#include "..\..\..\stdafx.h"
#include "..\..\..\BTHost.h"
#include "process.h"

#include "..\Inc\HCIEventProc.h"
#include "..\Inc\HCIEventPacket.h"
#include "..\Inc\HCIEventTable.h"

//------------------------------------------------------------------------------
//
//  Code
//
//------------------------------------------------------------------------------
CHCIEventProcessor::CHCIEventProcessor(void)

{
  if(!ValidateHCIEventTable())
  {
    printf("Function DB or Table is corrupted");
    abort();
  }
}
bool CHCIEventProcessor::ValidateHCIEventTable(void)
{
#ifdef BT_DEBUG
  int i;
  uint8 PrevOpCode;

  assert(s_NoOfEvents > 0);

  PrevOpCode = m_HCIEventTable[0].OpCode;
  for (i = 1; i < (int)s_NoOfEvents; i++)
  {
    assert(m_HCIEventTable[i].OpCode > PrevOpCode);
    assert(m_HCIEventTable[i].EventFunction != NULL);
    assert(m_HCIEventTable[i].SpecSection != NULL);
    assert(m_HCIEventTable[i].Name != NULL);

    PrevOpCode = m_HCIEventTable[i].OpCode;
  }


#endif BT_DEBUG
  return true;
}

//------------------------------------------------------------------------------

void CHCIEventProcessor::PrintHCIEventTable()
{

  int i;

  printf("\n");
  printf("m_HCIEventTable\n");
  printf("===============\n\n");

  for (i = 0; i < (int)s_NoOfEvents; i++)
  {
    printf("Entry[%0i] -----------\n");
    printf("----------------------\n");
    printf("OpCode:               %x\n", m_HCIEventTable[i].OpCode);
    printf("ParameterTotalLength: %x\n", m_HCIEventTable[i].ParameterTotalLength);
    printf("EventFunction:      %x\n", m_HCIEventTable[i].EventFunction);
    printf("SpecSection:          %s\n", m_HCIEventTable[i].SpecSection);
    printf("Name:                 %s\n", m_HCIEventTable[i].Name);
  }
  printf("----------------------\n\n");
}

//------------------------------------------------------------------------------

int CHCIEventProcessor::FindHCIEventType(uint8 OpCode)
{
  int Lower,Upper,Current;
  int FindIdx = -1;
  Lower = 0;
  Upper = s_NoOfEvents - 1;
  int MaxIdx = Upper;

  // DebugInformation Event Doesn't Follow the Table Index
  if(OpCode != 0xEF && (OpCode>Upper || OpCode<= Lower))	// OpCode = 0xEF For DebugInformation
  {
	  FindIdx = -1;
	  TRACE("E001/ FindHCIEventType(): Wrong code in Event packet");
	  //MessageBox(NULL,"Wrong code in Event packet","Error",MB_OK|MB_ICONWARNING);
  }
  else
  {

    FOR_LOOP(i,0,1000) // to avoid infinite loop
    {
      Current = (Upper + Lower) / 2;

      if (m_HCIEventTable[Current].OpCode > OpCode)
      {
        Upper = Current
          ;
      }
      else if (m_HCIEventTable[Current].OpCode < OpCode)
      {
        Lower = Current+1;
      }
      else
      {
        FindIdx = Current;
        break;
      }

      if (Upper == Lower)
      {
        if(OpCode == m_HCIEventTable[MaxIdx].OpCode)
        {
          FindIdx = MaxIdx;
        }
        else
        {
		  TRACE("E002/FindHCIEventType(): Wrong code in Event packet");
          //MessageBox(NULL,"Wrong code in Event packet","Error",MB_OK|MB_ICONWARNING);
        }
        break; // not found
      }
    }
  }
  return FindIdx;
}

//------------------------------------------------------------------------------

CHCIEventProcessor::tEventParseStatus CHCIEventProcessor::ParseHCIEvent(CHCI_EventPacket& HCI_EventPacket)
{
 
  int Index;
  
  if ( (Index = FindHCIEventType(HCI_EventPacket.GetOpCode()) )!= -1 )
  {
    tHCIEventTableItem* pEvTableItem = &m_HCIEventTable[Index];
    // Does function require a specific parameter length

    if ((pEvTableItem->ParameterTotalLength != NO_PAR) &&
        (pEvTableItem->ParameterTotalLength !=  
         HCI_EventPacket.GetParmLen()))
    {
      // Wrong parameter total length, send error meesage
      if ((pEvTableItem->ParameterTotalLength <  
           HCI_EventPacket.GetParmLen()))
      {
        FOR_LOOP(i,0,s_NoOfOCFWithVariableParams)
        {
          if(m_ListOfOCFWithVariableParams[i] == pEvTableItem->OpCode)
          {
            pEvTableItem->EventFunction(HCI_EventPacket);
            return ePARSING_OK;
          }
        }
      }
	  TRACE("E001/ParseHCIEvent(): Wrong parameter size in Event packet");
      //MessageBox(NULL,"Wrong parameter size in Event packet","Error",MB_OK|MB_ICONWARNING);
      return ePARAMETER_SIZE_MISMATCH;
    }
    else
    {
        // aCTIVATE  HCI Event Function

        pEvTableItem->EventFunction(HCI_EventPacket);
        return ePARSING_OK;
    }
  }
  // Event not found in database, send unknown Event
  TRACE("E002/ParseHCIEvent(): Unknown Event");
  //MessageBox(NULL,"unknown Event","Error",MB_OK|MB_ICONWARNING);
  return eUNKNOWN_EVENT;
}



//------------------------------------------------------------------------------
//  End of  HCIEvent.cpp

⌨️ 快捷键说明

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