From: Ian Abbott Date: Wed, 5 Nov 2008 11:40:42 +0000 (+0000) Subject: Handle COMEDI_SUBD_PWM and check for future unknown subdevice types. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0038ed146700f267d9f983ae94068df826bdd1e5;p=comedilib.git Handle COMEDI_SUBD_PWM and check for future unknown subdevice types. --- diff --git a/demo/info.c b/demo/info.c index 2ad0a95..ff38880 100644 --- a/demo/info.c +++ b/demo/info.c @@ -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,6 +46,7 @@ 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; @@ -69,7 +71,12 @@ int main(int argc,char *argv[]) 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]); + 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); diff --git a/testing/info.c b/testing/info.c index 66ea9aa..e1bc197 100644 --- a/testing/info.c +++ b/testing/info.c @@ -13,7 +13,7 @@ #include "comedi_test.h" -static char *subdevice_types[]={ +static const char * const subdevice_types[]={ "unused", "analog input", "analog output", @@ -25,7 +25,8 @@ static char *subdevice_types[]={ "memory", "calibration", "processor", - "serial" + "serial", + "pwm" }; @@ -33,6 +34,7 @@ int test_info(void) { int j; int type; + const char *type_str; int chan,n_chans; int n_ranges; comedi_range *rng; @@ -40,7 +42,12 @@ int test_info(void) printf("rev 1\n"); type = comedi_get_subdevice_type(device,subdevice); - printf("I: subdevice type: %d (%s)\n",type,subdevice_types[type]); + if(type < (int)(sizeof(subdevice_types) / sizeof(subdevice_types[0]))) { + type_str = subdevice_types[type]; + }else{ + type_str = "UNKNOWN"; + } + printf("I: subdevice type: %d (%s)\n",type,type_str); if(type==COMEDI_SUBD_UNUSED) return 0; n_chans=comedi_get_n_channels(device,subdevice);