added lots of more information
This commit is contained in:
parent
14152fb380
commit
5e8a77d52b
1 changed files with 156 additions and 8 deletions
164
demo/info.c
164
demo/info.c
|
@ -10,6 +10,8 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
void get_command_stuff(comedi_t *it,int s);
|
||||
|
||||
void help(void)
|
||||
{
|
||||
fprintf(stderr,"info </dev/comediN>\n");
|
||||
|
@ -62,22 +64,41 @@ int main(int argc,char *argv[])
|
|||
printf("subdevice %d:\n",i);
|
||||
type=comedi_get_subdevice_type(it,i);
|
||||
printf(" type: %d (%s)\n",type,subdevice_types[type]);
|
||||
if(type==COMEDI_SUBD_UNUSED)
|
||||
continue;
|
||||
n_chans=comedi_get_n_channels(it,i);
|
||||
printf(" number of channels: %d\n",n_chans);
|
||||
printf(" max data value: %d\n",comedi_get_maxdata(it,i,0));
|
||||
n_ranges=comedi_get_n_ranges(it,i,0);
|
||||
printf(" number of ranges: %d\n",n_ranges);
|
||||
if(!comedi_maxdata_is_chan_specific(it,i)){
|
||||
printf(" max data value: %d\n",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(" ranges:\n");
|
||||
for(chan=0;chan<n_chans;chan++){
|
||||
printf(" chan%d:",chan);
|
||||
//printf(" (0x%08x)",comedi_get_rangetype(it,i,chan));
|
||||
if(!comedi_range_is_chan_specific(it,i)){
|
||||
n_ranges=comedi_get_n_ranges(it,i,0);
|
||||
printf(" all chans:");
|
||||
for(j=0;j<n_ranges;j++){
|
||||
rng=comedi_get_range(it,i,chan,j);
|
||||
//printf(" %p",rng);
|
||||
rng=comedi_get_range(it,i,0,j);
|
||||
printf(" [%g,%g]",rng->min,rng->max);
|
||||
}
|
||||
printf("\n");
|
||||
}else{
|
||||
for(chan=0;chan<n_chans;chan++){
|
||||
n_ranges=comedi_get_n_ranges(it,i,chan);
|
||||
printf(" chan%d:",chan);
|
||||
for(j=0;j<n_ranges;j++){
|
||||
rng=comedi_get_range(it,i,chan,j);
|
||||
printf(" [%g,%g]",rng->min,rng->max);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf(" command:\n");
|
||||
get_command_stuff(it,i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -95,3 +116,130 @@ char *tobinary(char *s,int bits,int n)
|
|||
return s;
|
||||
}
|
||||
|
||||
char *cmd_src(int src,char *buf)
|
||||
{
|
||||
buf[0]=0;
|
||||
|
||||
if(src&TRIG_NONE)strcat(buf,"none|");
|
||||
if(src&TRIG_NOW)strcat(buf,"now|");
|
||||
if(src&TRIG_FOLLOW)strcat(buf,"follow|");
|
||||
if(src&TRIG_TIME)strcat(buf,"time|");
|
||||
if(src&TRIG_TIMER)strcat(buf,"timer|");
|
||||
if(src&TRIG_COUNT)strcat(buf,"count|");
|
||||
if(src&TRIG_EXT)strcat(buf,"ext|");
|
||||
if(src&TRIG_INT)strcat(buf,"int|");
|
||||
|
||||
if(strlen(buf)==0){
|
||||
sprintf(buf,"unknown(0x%02x)",src);
|
||||
}else{
|
||||
buf[strlen(buf)-1]=0;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void probe_max_1chan(comedi_t *it,int s);
|
||||
|
||||
int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd)
|
||||
{
|
||||
memset(cmd,0,sizeof(*cmd));
|
||||
|
||||
cmd->subdev = s;
|
||||
|
||||
cmd->flags = 0;
|
||||
|
||||
cmd->start_src = TRIG_ANY;
|
||||
cmd->scan_begin_src = TRIG_ANY;
|
||||
cmd->convert_src = TRIG_ANY;
|
||||
cmd->scan_end_src = TRIG_ANY;
|
||||
cmd->stop_src = TRIG_ANY;
|
||||
|
||||
return comedi_command_test(it,cmd);
|
||||
}
|
||||
|
||||
|
||||
int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
comedi_get_cmd_src_mask(it,s,cmd);
|
||||
|
||||
cmd->chanlist_len = 1;
|
||||
|
||||
cmd->scan_end_src = TRIG_COUNT;
|
||||
cmd->scan_end_arg = 1;
|
||||
|
||||
if(cmd->convert_src&TRIG_TIMER){
|
||||
if(cmd->scan_begin_src&TRIG_FOLLOW){
|
||||
cmd->convert_src = TRIG_TIMER;
|
||||
cmd->scan_begin_src = TRIG_FOLLOW;
|
||||
}else{
|
||||
cmd->convert_src = TRIG_TIMER;
|
||||
cmd->scan_begin_src = TRIG_TIMER;
|
||||
}
|
||||
}else{
|
||||
printf("can't do timed?!?\n");
|
||||
return;
|
||||
}
|
||||
if(cmd->stop_src&TRIG_COUNT){
|
||||
cmd->stop_src=TRIG_COUNT;
|
||||
cmd->stop_arg=2;
|
||||
}else if(cmd->stop_src&TRIG_NONE){
|
||||
cmd->stop_src=TRIG_NONE;
|
||||
cmd->stop_arg=0;
|
||||
}else{
|
||||
printf("can't find a good stop_src\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret=comedi_command_test(it,cmd);
|
||||
if(ret==3){
|
||||
/* good */
|
||||
ret=comedi_command_test(it,cmd);
|
||||
}
|
||||
if(ret==4 || ret==0){
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void get_command_stuff(comedi_t *it,int s)
|
||||
{
|
||||
comedi_cmd cmd;
|
||||
char buf[100];
|
||||
|
||||
if(comedi_get_cmd_src_mask(it,s,&cmd)<0){
|
||||
printf(" not supported\n");
|
||||
}else{
|
||||
printf(" start: %s\n",cmd_src(cmd.start_src,buf));
|
||||
printf(" scan_begin: %s\n",cmd_src(cmd.scan_begin_src,buf));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void probe_max_1chan(comedi_t *it,int s)
|
||||
{
|
||||
comedi_cmd cmd;
|
||||
char buf[100];
|
||||
|
||||
printf(" command fast 1chan:\n");
|
||||
if(comedi_get_cmd_fast_1chan(it,s,&cmd)<0){
|
||||
printf(" not supported\n");
|
||||
}else{
|
||||
printf(" start: %s %d\n",
|
||||
cmd_src(cmd.start_src,buf),cmd.start_arg);
|
||||
printf(" scan_begin: %s %d\n",
|
||||
cmd_src(cmd.scan_begin_src,buf),cmd.scan_begin_arg);
|
||||
printf(" convert: %s %d\n",
|
||||
cmd_src(cmd.convert_src,buf),cmd.convert_arg);
|
||||
printf(" scan_end: %s %d\n",
|
||||
cmd_src(cmd.scan_end_src,buf),cmd.scan_end_arg);
|
||||
printf(" stop: %s %d\n",
|
||||
cmd_src(cmd.stop_src,buf),cmd.stop_arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue