微 网 高 通

P7. 电磁波唤醒节点
来源: | 作者:微网高通 | 发布时间: 2025-06-12 | 23 次浏览 | 分享到:
 
   // The initial time counter
   dwTimerA = GetTickCount();
 
   // The default Tx progress
   iProgress = 0XFF;
 
   // Query the TxStatus
   while ( 0X01 )
   {
      // Release the control of the processor
      Sleep( 0X01 );
           
      // Query the Tx status
      QueryTxMsgStatus( 0X00, ( char * )&iStatus );
     
      // Check if end of the Tx procedure
      if ( iStatus & TXD_TASK_STATUS_REPORTTABLE )
      {
         break;
      }
     
      // Compare the progress value
      if ( iStatus == iProgress )
      {
         continue;
      }
     
      // Current time counter
      dwTimerB = GetTickCount();
     
      // The offset timer
      dwTimerX = dwTimerB - dwTimerA;
     
      // Update the progress value
      iProgress = iStatus;
     
      // Current Tx progress
      printf( "%9lu ms --> %d%%rn", dwTimerX, iStatus );
   }
   // The seconds timer
   fTimer = 0.001f * GetTickCount();
 
   // Query the Tx timer
   GetTxMessageTime( 0X00, &dwTimerX );
 
   // The task completed status
   switch ( iStatus )
   {
   case TXD_TASK_STATUS_END_SUCCESS:
      {
         printf(
            "rn[%.3f]+%lu Tx Completed Successfully,Time=%lu(ms)rnrn",
            fTimer,
            dwIndex,
            dwTimerX );
      }
      break;
     
   case TXD_TASK_STATUS_END_FAILURE:
      {
         printf(
            "rn[%.3f]+%lu Tx Completed With Error,Time=%lu(ms)rnrn",
            fTimer,
            dwIndex,
            dwTimerX );
      }
      break;
     
   case TXD_TASK_STATUS_END_NOCRC32:
      {
         printf(
            "rn[%.3f]+%lu Tx Completed Without CRC32,Time=%lu(ms)rnrn",
            fTimer,
            dwIndex,
            dwTimerX );
      }
      break;
     
   default:
      {
         printf(
            "rn[%.3f]+%lu Tx Completed With Unknown Error,Time=%lu(ms)rnrn",
            fTimer,
            dwIndex,
            dwTimerX );
      }
      break;
   }
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
char Tx_Message_To_Client( unsigned short iObject, unsigned long dwFile )
{
   char * pBuffer;
   FILE * pFile;
   unsigned long dwSize;
   // The total file size
   dwSize = sizeof( pOutputFileName ) / sizeof( pOutputFileName[0X00] );
   // Regulate the index value
   dwFile %= dwSize;
   // Open the file
   pFile = fopen( pOutputFileName[dwFile], "rb" );
 
   // Validate the file pointer
   if ( !pFile )
   {
      printf( "Failed To Open File!rn" );
      return 0X00;
   }
 
   // Seek to the file end
   fseek( pFile, 0X00, SEEK_END );
 
   // The file size
   dwSize = ftell( pFile );
 
   // Seek to the file head
   fseek( pFile, 0X00, SEEK_SET );
 
   // allocate the buffer
   pBuffer = ( char * )malloc( dwSize );
 
   // Read this file contents
   fread( pBuffer, 0X01, dwSize, pFile );
 
   // Close this file
   fclose( pFile );
   // Set the message format
   // Parameter-1: Shell Number
   // Parameter-2: Media Type
   //              0X00 = Common Data
   //              0X01 = Firmware
   //
   // Parameter-3: Compress Mode
   //              0X00 = None Compress
   //              0X01 = Compress Mode
   SetMessageFormat( 0X00, 0X00, 0X01 );
   // The task status
   printf( "[WiMinet TxSize=%lu]:Object=0X%04Xrn", dwSize, iObject );
 
   // Send message via TCP on all nodes
   SendHiQoSMessage( 0X00, iObject, pBuffer, dwSize );
   // Send message via UDP on the end node, TCP on other nodes
   //SendMxQoSMessage( 0X00, iObject, pBuffer, dwSize );   
   // Send message via UDP on all nodes
   //SendNoQoSMessage( 0X00, iObject, pBuffer, dwSize );
   // delete this buffer
   free( pBuffer );
   // The operation status
   return 0X01;
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
unsigned char Print_WiMinet_Notice( void )
{
   char buffer[0XFF];
   unsigned char iExit;
   unsigned char iSize;
   unsigned char iError;
   unsigned char iEvent;
   unsigned char iRetVal;
   unsigned short iObject;
   ULARGE_INTEGER qwTimerA;
   ULARGE_INTEGER qwTimerB;
   WiMinet_TxReport * pTxReport;
 
   // The exit condition
   iExit = 0X00;
   // The error code
   iError = 0X00;
 
   // Update the start timer
   GetSystemTimeAsFileTime( ( LPFILETIME )&qwTimerA );                           
   // Wait some timer
   while ( iExit != 0X03 )
   {
      // Update the start timer
      GetSystemTimeAsFileTime( ( LPFILETIME )&qwTimerB );
      // Get the offset value
      qwTimerB.QuadPart -= qwTimerA.QuadPart;
      // Check the time out value
      if ( qwTimerB.QuadPart >= 0X02UL * X64_SEC_TIMER_CONST )
      {
         // Convert to mini-second timer
         qwTimerB.QuadPart /= X64_MIS_TIMER_CONST;
         // The error status
         printf( "rn[WiMinet Notice=%I64u]:Time Out Errorrn", qwTimerB.QuadPart );
         return 0XFF;
      }
      // The max buffer size
      iSize = sizeof( buffer );
     
      // Get the wiminet notice
      iRetVal = GetWiMinetNotice( 0X00, &iEvent, &iObject, buffer, &iSize );
     
      // Check the status
      if ( !iRetVal )
      {
         continue;
      }
      // Convert to mini-second timer
      qwTimerB.QuadPart /= X64_MIS_TIMER_CONST;
     
      // The notice header
      printf( "rn[WiMinet Notice=%I64u]:rn", qwTimerB.QuadPart );
     
      // The event of the object
      switch ( iEvent )
      {
      case WIMINET_EVENT_COMMUTE_END:
         {
            iExit |= 0X02;
            printf( "   [1] Event=Commute Successrn" );
            printf( "   [2] Object=0X%04Xrn", iObject );
            // The TxReport status
            pTxReport = ( WiMinet_TxReport * )buffer;
            // The report status
            printf( "   [3] Size=%d Bytesrn", iSize );
            printf( "   [4] Error=0X%02X", pTxReport->m_iQError );
            // The detailed error code: No Header
            if ( pTxReport->m_iQError & WIMINET_IO_REPORT_NO_HEADER )
            {
               printf( "[No Header]" );
            }
           
            // The detailed error code: Invalid Size
            if ( pTxReport->m_iQError & WIMINET_IO_REPORT_ER_AMOUNT )
            {