微 网 高 通

P7. 电磁波唤醒节点
来源: | 作者:微网高通 | 发布时间: 2025-06-12 | 25 次浏览 | 分享到:
      // The detailed error code: Invalid CRC32
      if ( report.m_iQError & WIMINET_IO_REPORT_ER_CRCODE )
      {
         printf( "[Invalid CRC32]" );
      }
     
      // The end of this line
      printf( "rnrn" );
      // The error code
      return report.m_iQError;
   }
   // The unknown error code
   return 0X80;
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
   char iRetVal;
   char iAutoMode;
   char iTRequest;
   char iShiftBMP;
   unsigned char   iErrorA;
   unsigned char   iErrorB;
   unsigned long   dwChar;
   unsigned long   dwFile;
   unsigned long   dwThis;
   unsigned long   dwSize;
   unsigned long   dwIndex;
   unsigned short iObject;
   ULARGE_INTEGER qwTimerA;
   ULARGE_INTEGER qwTimerB;
   unsigned short pObject[] = { 0X34F1 };   //0X0930   0X5028
 
   // COM port interface
   //iRetVal = OpenWiMinetShell( "COM6",115200, 0X01 );
   // Ethernet interface
   //iRetVal = OpenWiMinetShell( "192.168.0.240",12580, 0X01 );
   // Ethernet interface
   iRetVal = OpenWiMinetShell( "192.168.1.240",12580, 0X01 );
 
   // Validate the shell open interface
   if ( !iRetVal )
   {
      printf( "Open shell failed!rn" );
      return 0X00;
   }
   // The default Tx status report
   SetTxStateReport( 0X00, 0X01 );
 
   // The Tx performance
   SetTxPerformance( 0X00, 0X05 );
   // The notice for user input
   printf( "Please select '0'-'9' for file, 'q' or 'Q' to exit!rnrn" );
   // Auto mode or step mode
   iAutoMode = 0X00;
   // The initial request status
   iTRequest = 0X00;
   // The BMP status
   iShiftBMP = 0X00;
   // The main service
   while ( 0X01 )
   {
      // Release the processor control
      Sleep( 0X01 );
     
      // Check the keyboard input
      if ( _kbhit() )
      {
         // Get the input character
         dwChar = _getch();
       
         // Check if time to exit this process
         if ( ( dwChar == 'q' ) || ( dwChar == 'Q' ) )
         {
            break;
         }
         else if ( ( dwChar == 't' ) || ( dwChar == 'T' ) )
         {
            iAutoMode = 0X01;
            printf( "CMD:Auto Modern" );
            continue;
         }
         else if ( ( dwChar == 'm' ) || ( dwChar == 'M' ) )
         {
            iAutoMode = 0X00;
            printf( "CMD:Manual Modern" );
            continue;
         }
         else if ( ( dwChar == 'y' ) || ( dwChar == 'Y' ) )
         {
            iShiftBMP = 0X01;
            printf( "CMD:Dynamic BMPrn" );
            continue;
         }
         else if ( ( dwChar == 's' ) || ( dwChar == 'S' ) )
         {
            iShiftBMP = 0X00;
            printf( "CMD:Static BMPrn" );
            continue;
         }
       
         // Translate the input character
         dwFile = Translate_Output_File_Number( dwChar );
       
         // The request conunter
         dwIndex = 0X00;
       
         // Start the new request
         iTRequest = 0X01;
         // Get the start timer
         GetSystemTimeAsFileTime( ( LPFILETIME )&qwTimerA );
       
         // Cut off the initial timer
         qwTimerA.QuadPart -= ( TIME_OUT_TIMER * X64_SEC_TIMER_CONST );
      }
      // Check if there is a new request
      if ( !iTRequest )
      {
         continue;
      }
     
      // Get the output file name
      if ( !Validate_Output_File_Number( dwFile ) )
      {
         // The error message
         printf( "Invalid File Numberrn" );
       
         // Clear the request
         iTRequest = 0X00;
         continue;
      }
      // Get current timer
      GetSystemTimeAsFileTime( ( LPFILETIME )&qwTimerB );
      // Check if in auto mode
      if ( iAutoMode )
      {
         // Get the offset value
         qwTimerB.QuadPart -= qwTimerA.QuadPart;
         // Convert 100ns to miliseconds, then seconds
         qwTimerB.QuadPart /= X64_SEC_TIMER_CONST;
         // Validate the timeout timer
         if ( qwTimerB.QuadPart < TIME_OUT_TIMER )
         {
            continue;
         }
      }
     
      // Wait for the Tx Ready
      Wait_Tx_Active_Ready();
      // The counter of the object
      dwSize = sizeof( pObject ) / sizeof( pObject[0X00] );
      // The object index value
      iObject = pObject[dwIndex % dwSize];
     
      // Set the Wakeup Request: Parameter-4=iAck
      // 0X00: Dont Send Report
      // 0X01: Need Send Report
      //
      // ++++++ IMPORTANT NOTES ++++++
      // (1) if iACK=0, then client will never send out the UDP report
      // (2) if iACK=0, then Print_WiMinet_BATVol will encounter time out error
      //
      SetWakeupRequest( 0X00, iObject, 5000, 0X01, NULL, 0X00 );
      // The file index
      dwThis = dwFile;
      // Check if in auto mode and dynamic BMP
      if ( iShiftBMP && iAutoMode )
      {
         dwThis += dwIndex;
      }
           
      // Send File to Remote Client
      iRetVal = Tx_Message_To_Client( iObject, dwThis );
      // Validate the Operation Result
      if ( !iRetVal )
      {
         // Clear the request
         iTRequest = 0X00;
         continue;
      }
      // The request counter
      dwIndex++;
      // Print the Tx Task status
      Print_Tx_Task_Status( dwIndex );
     
      // The wiminet notice
      iErrorA = Print_WiMinet_Notice();
      // The client voltage
      iErrorB = Print_WiMinet_BATVol();
      // Check if there are errors
      if ( iErrorA || iErrorB )
      {
         // Clear the auto mode
         iAutoMode = 0X00;
         // Report the error status
         printf( "Error:A=0X%02X,B=0X%02Xrn", iErrorA, iErrorB );
      }
     
      // Check if in auto mode
      if ( !iAutoMode )
      {
         // Clear the request
         iTRequest = 0X00;
         continue;
      }
      // Update the start timer