微 网 高 通

测试例程:休眠节点的LED控制
来源: | 作者:微网高通 | 发布时间: 2025-08-30 | 3 次浏览 | 分享到:

测试例程:休眠节点的LED控制

#include <stdio.h>
#include <conio.h>
#include "API-WiMinet.h"
#define WIMINET_EWOR_CMD0()                     printf( "  [0] Open LED0\r\n" )
#define WIMINET_EWOR_CMD1()                     printf( "  [1] Stop LED0\r\n" )
#define WIMINET_EWOR_CMD2()                     printf( "  [2] Open LED1\r\n" )
#define WIMINET_EWOR_CMD3()                     printf( "  [3] Stop LED1\r\n" )
#define WIMINET_EWOR_CMD4()                     printf( "  [4] Open LED0 + LED1\r\n" )
#define WIMINET_EWOR_CMD5()                     printf( "  [5] Stop LED0 + LED1\r\n" )
#define WIMINET_EWOR_CMD6()                     printf( "  [6] Ctrl LED0=0,LED1=1\r\n" )
#define WIMINET_EWOR_CMD7()                     printf( "  [7] Ctrl LED0=1,LED1=0\r\n" )
int main( int argc, char* argv[] )
{
   char iRetVal;
   unsigned char iChar;
   unsigned short iTimer;
   unsigned short iObject;
 
   // COM port interface
   iRetVal = OpenWiMinetShell( "COM6",115200, 0X01 );
   // Ethernet interface
   //iRetVal = OpenWiMinetShell( "192.168.0.240",12580, 0X01 );
   // Validate the shell open interface
   if ( !iRetVal )
   {
      printf( "Open shell failed!\r\n" );
      return 0X00;
   }
   // The notice header
   printf( "\r\nPlease select your option:\r\n" );
   // The command menu
   WIMINET_EWOR_CMD0();
   WIMINET_EWOR_CMD1();
   WIMINET_EWOR_CMD2();
   WIMINET_EWOR_CMD3();
   WIMINET_EWOR_CMD4();
   WIMINET_EWOR_CMD5();
   WIMINET_EWOR_CMD6();
   WIMINET_EWOR_CMD7();
   // The unit is mini-second(ms)
   iTimer = 5000;
   // The object address
   iObject = 0X805D;
 
   // The wakeup exit information
   while ( !_kbhit() )
   {
      // The task interval
      Sleep( 1000 );
      // Get the input character
      iChar = _getch();
      // The exit input
      if ( ( iChar == 'q' ) || ( iChar == 'Q' ) )
      {
         printf( "\r\n" );
         break;
      }
      // The input key value
      printf( "\r\nThe Input Key is %c\r\n", iChar );
      // The command processor
      switch ( iChar )
      {
      case '0':
         {
            // The command notice message
            WIMINET_EWOR_CMD0();
           
            // Channel-0 = Open
            Set_eWakeUp_Open( 0X00, iObject, 0X00, iTimer );
         }
         break;
      case '1':
         {
            // The command notice message
            WIMINET_EWOR_CMD1();
           
            // Channel-0 = Stop
            Set_eWakeUp_Stop( 0X00, iObject, 0X00 );
         }
         break;
       
      case '2':
         {
            // The command notice message
            WIMINET_EWOR_CMD2();
           
            // Channel-1 = Open
            Set_eWakeUp_Open( 0X00, iObject, 0X01, iTimer );
         }
         break;
      case '3':
         {
            // The command notice message
            WIMINET_EWOR_CMD3();
           
            // Channel-1 = Stop
            Set_eWakeUp_Stop( 0X00, iObject, 0X01 );
         }
         break;
       
      case '4':
         {
            // The command notice message
            WIMINET_EWOR_CMD4();
           
            // Channel-0/1 = Open
            Set_eWakeUp_Ctrl( 0X00, iObject, 0X03, 0X03, iTimer );
         }
         break;
       
      case '5':
         {
            // The command notice message
            WIMINET_EWOR_CMD5();
           
            // Channel-0/1 = Stop
            Set_eWakeUp_Ctrl( 0X00, iObject, 0X03, 0X00, iTimer );
         }
         break;
       
      case '6':
         {
            // The command notice message
            WIMINET_EWOR_CMD6();
           
            // Channel-0 = Stop
            // Channel-1 = Open
            Set_eWakeUp_Ctrl( 0X00, iObject, 0X03, 0X02, iTimer );
         }
         break;
       
      case '7':
         {
            // The command notice message
            WIMINET_EWOR_CMD7();
           
            // Channel-0 = Open
            // Channel-1 = Stop
            Set_eWakeUp_Ctrl( 0X00, iObject, 0X03, 0X01, iTimer );
         }
         break;
       
      default:
         {
            printf( "Invalid command!\r\n" );
         }
         break;        
      }
   }
 
   // Stop the shell
   StopWiMinetShell( 0X00 );
 
   // Exit this main program
   return 0X01;
}