Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 #include <string.h>
00041 #include <stdio.h>
00042 #include <getopt.h>
00043 #include <stdbool.h>
00044 #include <string>
00045 
00046 #include  <wgtest_status_indicator/delcom_usb_light.h>
00047 
00048 using namespace wgtest_status_indicator;
00049 
00050 std::string boolToString(bool val)
00051 {
00052   return val ? "True" : "False";
00053 }
00054 
00055 int main (int argc, char **argv)
00056 {
00057     
00058     static int orange_flag;
00059     static int get_flag;
00060     static int green_flag;
00061     static int help_flag;
00062     static int off_flag;
00063     static int red_flag;
00064 
00065     int c;
00066     while (1) 
00067     {
00068       static struct option long_options[] = {
00069         
00070         {"orange",  no_argument,  &orange_flag,  1},
00071         {"get",   no_argument,  &get_flag,   1},
00072         {"green", no_argument,  &green_flag, 1},
00073         {"help",  no_argument,  &help_flag,  1},
00074         {"off",   no_argument,  &off_flag,   1},
00075         {"red",   no_argument,  &red_flag,   1},
00076       };
00077       
00078       int option_index = 0;
00079       c = getopt_long(argc, argv, "", long_options, &option_index);
00080       
00081       if (c == -1)
00082         break;
00083       
00084       switch (c) 
00085       {
00086       case 0:
00087         if (long_options[option_index].flag != 0)
00088           break;
00089       }
00090     }
00091     
00092     
00093     if ((! orange_flag && ! red_flag && ! green_flag && ! off_flag && ! get_flag)
00094         || help_flag) 
00095     {
00096       printf(
00097              "Usage: %s [ --orange | --red | --green | --off | --get ]\n",
00098              argv[0]
00099              );
00100       
00101       exit(1);
00102     }
00103     
00104     DelcomUSBLight *light = new DelcomUSBLight;
00105     if (!light->isOpen())
00106     {
00107       fprintf(stderr, "Unable to open USB light!");
00108       return 1;
00109     }
00110     
00111     
00112     USBLightCommand cmd;
00113 
00114     if (get_flag)
00115     {
00116       
00117       if (!light->getStatus(cmd))
00118         return 1;
00119 
00120       if (cmd.off)
00121         fprintf(stdout, "Light status: OFF\n");
00122       else
00123       {
00124         fprintf(stdout, "Green: %s. Orange: %s. Red: %s.\n", 
00125                 boolToString(cmd.green).c_str(),
00126                 boolToString(cmd.orange).c_str(), 
00127                 boolToString(cmd.red).c_str());
00128       }
00129     }
00130     else
00131     {
00132       
00133       cmd.green = green_flag;
00134       cmd.orange = orange_flag;
00135       cmd.off = off_flag;
00136       cmd.red = red_flag;
00137       
00138       if (!light->sendCommand(cmd))
00139         return 1;
00140     }
00141 
00142     return 0;
00143 }