doc: add missing -lm option to command line for compiling tut1
[comedilib.git] / demo / info.c
index 7e75427c41b646b18eeb6e1f074fab5a032a8958..ff38880f57ba71d0ef6ed323502e15491297e312 100644 (file)
@@ -22,7 +22,7 @@ void help(void)
 
 char *tobinary(char *s,int bits,int n);
 
-char *subdevice_types[]={
+static const char * const subdevice_types[]={
        "unused",
        "analog input",
        "analog output",
@@ -34,7 +34,8 @@ char *subdevice_types[]={
        "memory",
        "calibration",
        "processor",
-       "serial digital I/O"
+       "serial digital I/O",
+       "pwm"
 };
 
 comedi_t *it;
@@ -45,39 +46,50 @@ int main(int argc,char *argv[])
 {
        int i,j;
        int n_subdevices,type;
+       const char *type_str;
        int chan,n_chans;
        int n_ranges;
+       int subdev_flags;
        comedi_range *rng;
-       
-       parse_options(argc,argv);
+       struct parsed_options options;
 
-       it=comedi_open(filename);
+       init_parsed_options(&options);
+       parse_options(&options, argc, argv);
+
+       it = comedi_open(options.filename);
        if(!it){
-               fprintf(stderr,"cannot open %s\n",filename);
-               exit(0);
+               comedi_perror(options.filename);
+               exit(1);
        }
 
        printf("overall info:\n");
-       printf("  version code: 0x%06x\n",comedi_get_version_code(it));
-       printf("  driver name: %s\n",comedi_get_driver_name(it));
-       printf("  board name: %s\n",comedi_get_board_name(it));
-       printf("  number of subdevices: %d\n",n_subdevices=comedi_get_n_subdevices(it));
-       
-       for(i=0;i<n_subdevices;i++){
+       printf("  version code: 0x%06x\n", comedi_get_version_code(it));
+       printf("  driver name: %s\n", comedi_get_driver_name(it));
+       printf("  board name: %s\n", comedi_get_board_name(it));
+       printf("  number of subdevices: %d\n", n_subdevices = comedi_get_n_subdevices(it));
+
+       for(i = 0; i < n_subdevices; i++){
                printf("subdevice %d:\n",i);
-               type=comedi_get_subdevice_type(it,i);
-               printf("  type: %d (%s)\n",type,subdevice_types[type]);
+               type = comedi_get_subdevice_type(it, i);
+               if(type < (int)(sizeof(subdevice_types) / sizeof(subdevice_types[0]))){
+                       type_str = subdevice_types[type];
+               }else{
+                       type_str = "UNKNOWN";
+               }
+               printf("  type: %d (%s)\n",type,type_str);
                if(type==COMEDI_SUBD_UNUSED)
                        continue;
+               subdev_flags = comedi_get_subdevice_flags(it, i);
+               printf("  flags: 0x%08x\n",subdev_flags);
                n_chans=comedi_get_n_channels(it,i);
                printf("  number of channels: %d\n",n_chans);
                if(!comedi_maxdata_is_chan_specific(it,i)){
-                       printf("  max data value: %d\n",comedi_get_maxdata(it,i,0));
+                       printf("  max data value: %lu\n", (unsigned long)comedi_get_maxdata(it,i,0));
                }else{
                        printf("  max data value: (channel specific)\n");
                        for(chan=0;chan<n_chans;chan++){
-                               printf("    chan%d: %d\n",chan,
-                                       comedi_get_maxdata(it,i,chan));
+                               printf("    chan%d: %lu\n",chan,
+                                       (unsigned long)comedi_get_maxdata(it,i,chan));
                        }
                }
                printf("  ranges:\n");
@@ -103,7 +115,7 @@ int main(int argc,char *argv[])
                printf("  command:\n");
                get_command_stuff(it,i);
        }
-       
+
        return 0;
 }
 
@@ -111,11 +123,11 @@ char *tobinary(char *s,int bits,int n)
 {
        int bit=1<<n;
        char *t=s;
-       
+
        for(;bit;bit>>=1)
                *t++=(bits&bit)?'1':'0';
        *t=0;
-       
+
        return s;
 }
 
@@ -134,7 +146,7 @@ void get_command_stuff(comedi_t *it,int s)
                printf("    convert: %s\n",cmd_src(cmd.convert_src,buf));
                printf("    scan_end: %s\n",cmd_src(cmd.scan_end_src,buf));
                printf("    stop: %s\n",cmd_src(cmd.stop_src,buf));
-       
+
                probe_max_1chan(it,s);
        }
 }
@@ -145,7 +157,7 @@ void probe_max_1chan(comedi_t *it,int s)
        char buf[100];
 
        printf("  command fast 1chan:\n");
-       if(comedi_get_cmd_generic_timed(it,s,&cmd,1)<0){
+       if(comedi_get_cmd_generic_timed(it, s, &cmd, 1, 1)<0){
                printf("    not supported\n");
        }else{
                printf("    start: %s %d\n",