comedilib/demo/main.c

125 lines
2.1 KiB
C
Raw Normal View History

2000-02-02 05:14:23 +00:00
/*
2000-10-19 06:28:27 +00:00
* This is a little helper function to parse options that
* are common to most of the examples.
2000-02-02 05:14:23 +00:00
*/
#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include <malloc.h>
#include <string.h>
2000-10-19 06:28:27 +00:00
#include "examples.h"
2000-02-02 05:14:23 +00:00
char *filename="/dev/comedi0";
int verbose_flag;
int value;
int subdevice;
int channel;
int aref;
int range;
int parse_options(int argc, char *argv[])
{
int c;
2000-05-27 00:55:34 +00:00
while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:vdgom"))) {
2000-02-02 05:14:23 +00:00
switch (c) {
case 'f':
2000-05-27 00:55:34 +00:00
filename = optarg;
2000-02-02 05:14:23 +00:00
break;
case 's':
2000-05-27 00:55:34 +00:00
sscanf(optarg,"%d",&subdevice);
2000-02-02 05:14:23 +00:00
break;
case 'c':
2000-05-27 00:55:34 +00:00
sscanf(optarg,"%d",&channel);
2000-02-02 05:14:23 +00:00
break;
case 'a':
2000-05-27 00:55:34 +00:00
sscanf(optarg,"%d",&aref);
2000-02-02 05:14:23 +00:00
break;
case 'r':
2000-05-27 00:55:34 +00:00
sscanf(optarg,"%d",&range);
2000-02-02 05:14:23 +00:00
break;
case 'v':
verbose_flag = 1;
break;
case 'd':
aref=AREF_DIFF;
break;
case 'g':
aref=AREF_GROUND;
break;
case 'o':
aref=AREF_OTHER;
break;
case 'm':
aref=AREF_COMMON;
break;
default:
printf("bad option\n");
exit(1);
}
}
2000-05-27 00:55:34 +00:00
if(optind < argc) {
/* data value */
sscanf(argv[optind++],"%d",&value);
}
2000-02-02 05:14:23 +00:00
return argc;
}
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;
}
2000-02-02 05:14:23 +00:00
return buf;
}
void dump_cmd(comedi_cmd *cmd)
{
char buf[100];
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);
}
2000-02-02 05:14:23 +00:00