Changed the name of verbose_flag; Added a few more flags in main.c
This commit is contained in:
parent
68e8bf7b0d
commit
31b3e7ed7f
15 changed files with 73 additions and 54 deletions
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
|
||||
CFLAGS += -I ../include -I . -O2 -Wall -Wstrict-prototypes
|
||||
CFLAGS += -I ../include -I . -O2 -Wall -Wstrict-prototypes -g
|
||||
#CFLAGS += -I ../include -I . -Wall -Wstrict-prototypes -g
|
||||
LDFLAGS = -L../lib/ -lcomedi -lm
|
||||
|
||||
|
|
23
demo/README
23
demo/README
|
@ -110,14 +110,17 @@ Many of these demos are linked with the file main.c, which parses
|
|||
command line options. Some options don't make sense with all programs.
|
||||
The options are:
|
||||
|
||||
-a <aref> use analog reference <aref> (default: 0 == ground)
|
||||
-c <chan> use channel <chan> (default: 0)
|
||||
-s <subd> use subdevice <subd> (default: 0)
|
||||
-r <index> use voltage range <index> (default: 0)
|
||||
-f <file> use device file <file> (default: /dev/comedi0)
|
||||
-v verbose
|
||||
-d set analog reference to differential
|
||||
-g set analog reference to ground
|
||||
-o set analog reference to other
|
||||
-m set analog reference to common
|
||||
-a <aref> use analog reference <aref> (default: 0 == ground)
|
||||
-c <chan> use channel <chan> (default: 0)
|
||||
-s <subd> use subdevice <subd> (default: 0)
|
||||
-r <index> use voltage range <index> (default: 0)
|
||||
-f <file> use device file <file> (default: /dev/comedi0)
|
||||
-n <value> use <value> for the number of channels in a scan
|
||||
-N <value> use <value> for the number of scans
|
||||
-F <freq> use <freq> as the scan frequency
|
||||
-v verbose
|
||||
-d set analog reference to differential
|
||||
-g set analog reference to ground
|
||||
-o set analog reference to other
|
||||
-m set analog reference to common
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
data = value;
|
||||
if(verbose_flag){
|
||||
if(verbose){
|
||||
printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
|
||||
data,filename,subdevice,channel,range,aref);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef _EXAMPLES_H
|
||||
#define _EXAMPLES_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* Definitions of some of the common code.
|
||||
*/
|
||||
|
@ -15,10 +17,14 @@ extern int subdevice;
|
|||
extern int channel;
|
||||
extern int aref;
|
||||
extern int range;
|
||||
extern int verbose;
|
||||
extern int n_chan;
|
||||
extern int n_scan;
|
||||
extern double freq;
|
||||
|
||||
int parse_options(int argc, char *argv[]);
|
||||
char *cmd_src(int src,char *buf);
|
||||
void dump_cmd(comedi_cmd *cmd);
|
||||
void dump_cmd(FILE *file,comedi_cmd *cmd);
|
||||
|
||||
|
||||
#define sec_to_nsec(x) ((x)*1000000000)
|
||||
|
|
|
@ -37,7 +37,7 @@ int main(int argc, char *argv[])
|
|||
exit(0);
|
||||
}
|
||||
|
||||
if(verbose_flag){
|
||||
if(verbose){
|
||||
printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
|
||||
filename,subdevice,channel,range,aref);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ int main(int argc, char *argv[])
|
|||
exit(0);
|
||||
}
|
||||
|
||||
if(verbose_flag){
|
||||
if(verbose){
|
||||
printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
|
||||
filename,subdevice,channel,range,aref);
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret=comedi_command_test(dev,cmd);
|
||||
|
||||
|
@ -190,7 +190,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret=comedi_command(dev,cmd);
|
||||
|
||||
|
|
54
demo/main.c
54
demo/main.c
|
@ -12,17 +12,21 @@
|
|||
#include <ctype.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "examples.h"
|
||||
|
||||
|
||||
char *filename="/dev/comedi0";
|
||||
int verbose_flag;
|
||||
int verbose;
|
||||
|
||||
int value=0;
|
||||
int subdevice=0;
|
||||
int channel=0;
|
||||
int aref=0;
|
||||
int aref=AREF_GROUND;
|
||||
int range=0;
|
||||
int n_chan=4;
|
||||
int n_scan=1000;
|
||||
double freq=1000.0;
|
||||
|
||||
|
||||
int parse_options(int argc, char *argv[])
|
||||
|
@ -30,37 +34,46 @@ int parse_options(int argc, char *argv[])
|
|||
int c;
|
||||
|
||||
|
||||
while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:vdgom"))) {
|
||||
while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:n:N:F:vdgom"))) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
filename = optarg;
|
||||
break;
|
||||
case 's':
|
||||
sscanf(optarg,"%d",&subdevice);
|
||||
subdevice = strtoul(optarg,NULL,0);
|
||||
break;
|
||||
case 'c':
|
||||
sscanf(optarg,"%d",&channel);
|
||||
channel = strtoul(optarg,NULL,0);
|
||||
break;
|
||||
case 'a':
|
||||
sscanf(optarg,"%d",&aref);
|
||||
aref = strtoul(optarg,NULL,0);
|
||||
break;
|
||||
case 'r':
|
||||
sscanf(optarg,"%d",&range);
|
||||
range = strtoul(optarg,NULL,0);
|
||||
break;
|
||||
case 'n':
|
||||
n_chan = strtoul(optarg,NULL,0);
|
||||
break;
|
||||
case 'N':
|
||||
n_scan = strtoul(optarg,NULL,0);
|
||||
break;
|
||||
case 'F':
|
||||
freq = strtoul(optarg,NULL,0);
|
||||
break;
|
||||
case 'v':
|
||||
verbose_flag = 1;
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'd':
|
||||
aref=AREF_DIFF;
|
||||
aref = AREF_DIFF;
|
||||
break;
|
||||
case 'g':
|
||||
aref=AREF_GROUND;
|
||||
aref = AREF_GROUND;
|
||||
break;
|
||||
case 'o':
|
||||
aref=AREF_OTHER;
|
||||
aref = AREF_OTHER;
|
||||
break;
|
||||
case 'm':
|
||||
aref=AREF_COMMON;
|
||||
aref = AREF_COMMON;
|
||||
break;
|
||||
default:
|
||||
printf("bad option\n");
|
||||
|
@ -87,9 +100,12 @@ char *cmd_src(int src,char *buf)
|
|||
if(src&TRIG_COUNT)strcat(buf, "count|");
|
||||
if(src&TRIG_EXT)strcat(buf, "ext|");
|
||||
if(src&TRIG_INT)strcat(buf, "int|");
|
||||
#ifdef TRIG_OTHER
|
||||
if(src&TRIG_OTHER)strcat(buf, "other|");
|
||||
#endif
|
||||
|
||||
if(strlen(buf)==0){
|
||||
sprintf(buf,"unknown(0x%02x)",src);
|
||||
sprintf(buf,"unknown(0x%08x)",src);
|
||||
}else{
|
||||
buf[strlen(buf)-1]=0;
|
||||
}
|
||||
|
@ -97,27 +113,27 @@ char *cmd_src(int src,char *buf)
|
|||
return buf;
|
||||
}
|
||||
|
||||
void dump_cmd(comedi_cmd *cmd)
|
||||
void dump_cmd(FILE *out,comedi_cmd *cmd)
|
||||
{
|
||||
char buf[100];
|
||||
|
||||
printf("start: %s %d\n",
|
||||
fprintf(out,"start: %-8s %d\n",
|
||||
cmd_src(cmd->start_src,buf),
|
||||
cmd->start_arg);
|
||||
|
||||
printf("scan_begin: %s %d\n",
|
||||
fprintf(out,"scan_begin: %-8s %d\n",
|
||||
cmd_src(cmd->scan_begin_src,buf),
|
||||
cmd->scan_begin_arg);
|
||||
|
||||
printf("convert: %s %d\n",
|
||||
fprintf(out,"convert: %-8s %d\n",
|
||||
cmd_src(cmd->convert_src,buf),
|
||||
cmd->convert_arg);
|
||||
|
||||
printf("scan_end: %s %d\n",
|
||||
fprintf(out,"scan_end: %-8s %d\n",
|
||||
cmd_src(cmd->scan_end_src,buf),
|
||||
cmd->scan_end_arg);
|
||||
|
||||
printf("stop: %s %d\n",
|
||||
fprintf(out,"stop: %-8s %d\n",
|
||||
cmd_src(cmd->stop_src,buf),
|
||||
cmd->stop_arg);
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
#define N_SCANS 10
|
||||
#define N_CHANS 16
|
||||
|
||||
double freq = 1000;
|
||||
|
||||
#define BUFSZ 1000
|
||||
char buf[BUFSZ];
|
||||
|
||||
|
@ -80,7 +78,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret = comedi_command_test(dev,cmd);
|
||||
|
||||
|
@ -91,7 +89,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret = comedi_command(dev,cmd);
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
data = value;
|
||||
if(verbose_flag){
|
||||
if(verbose){
|
||||
printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
|
||||
data,filename,subdevice,channel,range,aref);
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
#define N_SCANS 10
|
||||
#define N_CHANS 16
|
||||
|
||||
double freq = 1000;
|
||||
|
||||
#define BUFSZ 1000
|
||||
sampl_t buf[BUFSZ];
|
||||
|
||||
|
@ -99,7 +97,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret=comedi_command_test(dev,cmd);
|
||||
|
||||
|
@ -110,7 +108,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret=comedi_command(dev,cmd);
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
cmd->chanlist = chanlist;
|
||||
cmd->chanlist_len = n_chans;
|
||||
|
@ -111,7 +111,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
cmd->chanlist = chanlist;
|
||||
cmd->chanlist_len = n_chans;
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
#define N_SCANS 10
|
||||
#define N_CHANS 16
|
||||
|
||||
double freq = 1000;
|
||||
|
||||
#define BUFSZ 1000
|
||||
sampl_t buf[BUFSZ];
|
||||
|
||||
|
@ -94,7 +92,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret=comedi_command_test(dev,cmd);
|
||||
|
||||
|
@ -105,7 +103,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret=comedi_command(dev,cmd);
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret=comedi_command_test(dev,cmd);
|
||||
|
||||
|
@ -153,7 +153,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd)
|
|||
return;
|
||||
}
|
||||
|
||||
dump_cmd(cmd);
|
||||
dump_cmd(stdout,cmd);
|
||||
|
||||
ret=comedi_command(dev,cmd);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ int main(int argc, char *argv[])
|
|||
exit(0);
|
||||
}
|
||||
|
||||
if(verbose_flag){
|
||||
if(verbose){
|
||||
printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
|
||||
filename,subdevice,channel,range,aref);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue