/usr/share/doc/libcomedi-dev/demo/common.c is in libcomedi-dev 0.10.2-4build7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | /*
* This is a little helper function to parse options that
* are common to most of the examples.
*/
#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>
#include <stdlib.h>
#include "examples.h"
static char * const default_filename = "/dev/comedi0";
void init_parsed_options(struct parsed_options *options)
{
memset(options, 0, sizeof(struct parsed_options));
options->filename = default_filename;
options->aref = AREF_GROUND;
options->n_chan = 4;
options->n_scan = 1000;
options->freq = 1000.0;
options->physical = 0;
options->value = 0.;
}
int parse_options(struct parsed_options *options, int argc, char *argv[])
{
int c;
while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:n:N:F:pvdgom"))) {
switch (c) {
case 'f':
options->filename = optarg;
break;
case 's':
options->subdevice = strtoul(optarg, NULL, 0);
break;
case 'c':
options->channel = strtoul(optarg, NULL, 0);
break;
case 'a':
options->aref = strtoul(optarg, NULL, 0);
break;
case 'r':
options->range = strtoul(optarg, NULL, 0);
break;
case 'n':
options->n_chan = strtoul(optarg, NULL, 0);
break;
case 'N':
options->n_scan = strtoul(optarg, NULL, 0);
break;
case 'F':
options->freq = strtod(optarg, NULL);
break;
case 'p':
options->physical = 1;
break;
case 'v':
++options->verbose;
break;
case 'd':
options->aref = AREF_DIFF;
break;
case 'g':
options->aref = AREF_GROUND;
break;
case 'o':
options->aref = AREF_OTHER;
break;
case 'm':
options->aref = AREF_COMMON;
break;
default:
printf("bad option\n");
exit(1);
}
}
if(optind < argc) {
/* data value */
options->value = strtod(argv[optind++], NULL);
}
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|");
#ifdef TRIG_OTHER
if(src&TRIG_OTHER)strcat(buf, "other|");
#endif
if(strlen(buf)==0){
sprintf(buf,"unknown(0x%08x)",src);
}else{
buf[strlen(buf)-1]=0;
}
return buf;
}
void dump_cmd(FILE *out,comedi_cmd *cmd)
{
char buf[100];
fprintf(out,"subdevice: %d\n",
cmd->subdev);
fprintf(out,"start: %-8s %d\n",
cmd_src(cmd->start_src,buf),
cmd->start_arg);
fprintf(out,"scan_begin: %-8s %d\n",
cmd_src(cmd->scan_begin_src,buf),
cmd->scan_begin_arg);
fprintf(out,"convert: %-8s %d\n",
cmd_src(cmd->convert_src,buf),
cmd->convert_arg);
fprintf(out,"scan_end: %-8s %d\n",
cmd_src(cmd->scan_end_src,buf),
cmd->scan_end_arg);
fprintf(out,"stop: %-8s %d\n",
cmd_src(cmd->stop_src,buf),
cmd->stop_arg);
}
|