微 网 高 通

测试例程:全局消息钩子
来源: | 作者:微网高通 | 发布时间: 2025-08-30 | 3 次浏览 | 分享到:

测试例程:全局消息钩子

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "API-WiMinet.h"
int main( int argc, char* argv[] )
{
   char buffer[0X80];
   unsigned char index;
   unsigned char iSize;
   unsigned char iShell[0X10];
   unsigned long dwTotal;
   unsigned short iSource;
   WiMinet_DIReport_SDK * pReport;
   // Clear all the shell
   memset( iShell, 0X00, sizeof( iShell ) );
 
   // The 1st shell interface
   iShell[0X00] = OpenWiMinetShell( "COM4",115200UL, 0X01 );
   // The 1st shell interface
   //iShell[0X01] = OpenWiMinetShell( "COM10",115200UL, 0X01 );
 
   // The 1st shell interface
   //iShell[0X00] = OpenWiMinetShell( "192.168.0.240",12580, 0X01 );
   // The 2nd shell interface
   iShell[0X01] = OpenWiMinetShell( "192.168.0.241",12580, 0X01 );
   // Enable the hook service
   EnableGlobalHook( 0XFF );
   // Validate the shell open interface
   if ( !iShell[0X00] && !iShell[0X01] )
   {
      printf( "Open shell failed!\r\n" );
      return 0X00;
   }
   // The total size
   dwTotal = 0X00UL;
   // Get the user input key
   while ( !_kbhit() )
   {
      // Release the processor control
      Sleep( 0X01 );
     
      // Get the hooked message
      iSize = GetHookRxMessage( &iSource, buffer, sizeof( buffer ) );
      // Validate the packet size
      if ( !iSize )
      {
         continue;
      }
      // Update the total size
      dwTotal += iSize;
     
      // The source address
      printf( "\r\nSource=0X%04X\r\n", iSource );
     
      // Report the message: contents    
      printf( "Content[%d/%lu]=", iSize, dwTotal );
     
      // The byte contents of the input buffer
      for ( index = 0X00; index < iSize; index++ )
      {
         printf( "%02X ", (unsigned char)buffer[index] );
      }
      // The end of this line
      printf( "\r\n" );
      // The pointer to the object
      pReport = ( WiMinet_DIReport_SDK * )buffer;
      // The member contents
      printf( "Members:\r\n" );
      printf( "   [0] Battery=%.3f(V)\r\n", pReport->m_nPacket.m_nReport.m_iBATVol * 0.001f );
      printf( "   [1] Channel=%d\r\n", pReport->m_nPacket.m_nReport.m_iChannel );
      printf( "   [2] IReport=%d\r\n", pReport->m_nPacket.m_nReport.m_iUserDI );
      printf( "   [3] EventID=0X%02X\r\n", pReport->m_nPacket.m_nReport.m_iQEvent );
      printf( "   [4] DIState=0X%02X\r\n", pReport->m_nPacket.m_nReport.m_iStatus );
      printf( "   [5] Counter=0X%lX\r\n", pReport->m_nPacket.m_nReport.m_dwSerial );
      printf( "   [6] NETAddr=0X%04X\r\n", pReport->m_nPacket.m_nReport.m_iX16NET );
      printf( "   [7] Chipset=%lX\r\n", pReport->m_nPacket.m_nReport.m_iRFChip );
      printf( "   [8] Rx-RSSI=%d(dBm)\r\n", pReport->m_nPacket.m_nReport.m_iRxRSSI );    
      printf( "   [9] Tx-RSSI=%d(dBm)\r\n", pReport->m_nPacket.m_nReport.m_iTxRSSI );
      printf( "   [9] Tx-RSSI=%d(dBm)\r\n", pReport->m_nPacket.m_nReport.m_iTxRSSI );
      // The X64MAC address of the server
      printf( "   [A] MACAddr=0X" );
     
      // The size of the X64MAC address
      iSize = sizeof( pReport->m_nPacket.m_pX64MAC );
      // Get the item counter
iSize /= sizeof( pReport->m_nPacket.m_pX64MAC[0X00] );
// The X64MAC address
      for ( index = 0X00; index < iSize; index++ )
      {
         printf( "%02X", pReport->m_nPacket.m_pX64MAC[index] );
      }
      printf( "\r\n" );
      // The shell of the server
      printf( "   [B] IOShell=%lu\r\n", pReport->m_dwShell );
      // The device name of the server
      printf( "   [C] DevName=%s\r\n", pReport->m_pDevice );
   }
   // Stop the shell
   StopWiMinetShell( 0X00 );
   // Exit this main program
   return 0X01;
}