[Xenomai-git] Jorge Ramirez-Ortiz : utils/analogy: make cmd_read single threaded

2014-08-08 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: f08ad773edcf1ed9b444326fa3494ad595837341
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=f08ad773edcf1ed9b444326fa3494ad595837341

Author: Jorge Ramirez-Ortiz 
Date:   Tue Jul 15 14:26:58 2014 -0400

utils/analogy: make cmd_read single threaded

---

 utils/analogy/cmd_read.c |  262 --
 1 file changed, 92 insertions(+), 170 deletions(-)

diff --git a/utils/analogy/cmd_read.c b/utils/analogy/cmd_read.c
index c114331..ab0c14e 100644
--- a/utils/analogy/cmd_read.c
+++ b/utils/analogy/cmd_read.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -32,7 +33,7 @@
 #include 
 
 typedef int (*dump_function_t) (a4l_desc_t *, a4l_cmd_t*, unsigned char *, 
int);
-static pthread_t thread;
+
 struct arguments {
int argc;
char **argv;
@@ -55,14 +56,9 @@ static int real_time = 0;
 static int use_mmap = 0;
 static int verbose = 0;
 
-#define ERR(fmt, args ...) fprintf(stderr, fmt, ##args)
-#define OUT(fmt, args ...) fprintf(stdout, fmt, ##args)
-#define DBG(fmt, args...)  \
-do {   \
-   if (verbose)\
-  printf(fmt, ##args); \
-   } while (0)
-
+#define exit_err(fmt, args ...) error(1,0, fmt "\n", ##args)
+#define output(fmt, args ...) fprintf(stdout, fmt "\n", ##args)
+#define debug(fmt, args...)  if (verbose &&  printf(fmt "\n", ##args))
 
 /* The command to send by default */
 a4l_cmd_t cmd = {
@@ -98,20 +94,20 @@ struct option cmd_read_opts[] = {
 
 static void do_print_usage(void)
 {
-   OUT("usage:\tcmd_read [OPTS]\n");
-   OUT("\tOPTS:\t -v, --verbose: verbose output\n");
-   OUT("\t\t -r, --real-time: enable real-time acquisition mode\n");
-   OUT("\t\t -d, --device: device filename (analogy0, analogy1, ...)\n");
-   OUT("\t\t -s, --subdevice: subdevice index\n");
-   OUT("\t\t -S, --scan-count: count of scan to perform\n");
-   OUT("\t\t -c, --channels: channels to use (ex.: -c 0,1)\n");
-   OUT("\t\t -m, --mmap: mmap the buffer\n");
-   OUT("\t\t -w, --raw: dump data in raw format\n");
-   OUT("\t\t -k, --wake-count: space available before waking up the 
process\n");
-   OUT("\t\t -h, --help: print this help\n");
+   output("usage:\tcmd_read [OPTS]");
+   output("\tOPTS:\t -v, --verbose: verbose output");
+   output("\t\t -r, --real-time: enable real-time acquisition mode");
+   output("\t\t -d, --device: device filename (analogy0, analogy1, ...)");
+   output("\t\t -s, --subdevice: subdevice index");
+   output("\t\t -S, --scan-count: count of scan to perform");
+   output("\t\t -c, --channels: channels to use (ex.: -c 0,1)");
+   output("\t\t -m, --mmap: mmap the buffer");
+   output("\t\t -w, --raw: dump data in raw format");
+   output("\t\t -k, --wake-count: space available before waking up the 
process");
+   output("\t\t -h, --help: output this help");
 }
 
-static int dump_raw(a4l_desc_t *dsc, a4l_cmd_t *cmd, unsigned char *buf, int 
size)
+static inline int dump_raw(a4l_desc_t *dsc, a4l_cmd_t *cmd, unsigned char 
*buf, int size)
 {
return fwrite(buf, size, 1, stdout);
 }
@@ -127,17 +123,12 @@ static int dump_text(a4l_desc_t *dsc, a4l_cmd_t *cmd, 
unsigned char *buf, int si
int width;
 
err = a4l_get_chinfo(dsc, cmd->idx_subd, cmd->chan_descs[i], 
&chans[i]);
-   if (err < 0) {
-   ERR("cmd_read: a4l_get_chinfo failed (ret=%d)\n", err);
-   goto out;
-   }
+   if (err < 0)
+   exit_err("a4l_get_chinfo failed (ret=%d)", err);
 
width = a4l_sizeof_chan(chans[i]);
-   if (width < 0) {
-   ERR("cmd_read: incoherent info for channel %d\n", 
cmd->chan_descs[i]);
-   err = width;
-   goto out;
-   }
+   if (width < 0)
+   exit_err("incoherent info for channel %d", 
cmd->chan_descs[i]);
 
switch (width) {
case 1:
@@ -159,14 +150,14 @@ static int dump_text(a4l_desc_t *dsc, a4l_cmd_t *cmd, 
unsigned char *buf, int si
if (err < 0)
goto out;
 
-   OUT(fmts[cur_chan], value);
+   fprintf(stdout, fmts[cur_chan], value);
 
/* We assume a4l_sizeof_chan() cannot return because we already
 * called it on the very same channel descriptor */
tmp_size += a4l_sizeof_chan(chans[cur_chan]);
 
if (++cur_chan == cmd->nb_chan) {
-   OUT("\n");
+   fprintf(stdout, "\n");
cur_chan = 0;

[Xenomai-git] Jorge Ramirez-Ortiz : utils/analogy: make cmd_read single threaded

2014-08-08 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: add52ab2cd54d8da4599dcd0136e59db38f741c3
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=add52ab2cd54d8da4599dcd0136e59db38f741c3

Author: Jorge Ramirez-Ortiz 
Date:   Tue Jul 15 14:26:58 2014 -0400

utils/analogy: make cmd_read single threaded

---

 utils/analogy/cmd_read.c |  262 --
 1 file changed, 92 insertions(+), 170 deletions(-)

diff --git a/utils/analogy/cmd_read.c b/utils/analogy/cmd_read.c
index c114331..ab0c14e 100644
--- a/utils/analogy/cmd_read.c
+++ b/utils/analogy/cmd_read.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -32,7 +33,7 @@
 #include 
 
 typedef int (*dump_function_t) (a4l_desc_t *, a4l_cmd_t*, unsigned char *, 
int);
-static pthread_t thread;
+
 struct arguments {
int argc;
char **argv;
@@ -55,14 +56,9 @@ static int real_time = 0;
 static int use_mmap = 0;
 static int verbose = 0;
 
-#define ERR(fmt, args ...) fprintf(stderr, fmt, ##args)
-#define OUT(fmt, args ...) fprintf(stdout, fmt, ##args)
-#define DBG(fmt, args...)  \
-do {   \
-   if (verbose)\
-  printf(fmt, ##args); \
-   } while (0)
-
+#define exit_err(fmt, args ...) error(1,0, fmt "\n", ##args)
+#define output(fmt, args ...) fprintf(stdout, fmt "\n", ##args)
+#define debug(fmt, args...)  if (verbose &&  printf(fmt "\n", ##args))
 
 /* The command to send by default */
 a4l_cmd_t cmd = {
@@ -98,20 +94,20 @@ struct option cmd_read_opts[] = {
 
 static void do_print_usage(void)
 {
-   OUT("usage:\tcmd_read [OPTS]\n");
-   OUT("\tOPTS:\t -v, --verbose: verbose output\n");
-   OUT("\t\t -r, --real-time: enable real-time acquisition mode\n");
-   OUT("\t\t -d, --device: device filename (analogy0, analogy1, ...)\n");
-   OUT("\t\t -s, --subdevice: subdevice index\n");
-   OUT("\t\t -S, --scan-count: count of scan to perform\n");
-   OUT("\t\t -c, --channels: channels to use (ex.: -c 0,1)\n");
-   OUT("\t\t -m, --mmap: mmap the buffer\n");
-   OUT("\t\t -w, --raw: dump data in raw format\n");
-   OUT("\t\t -k, --wake-count: space available before waking up the 
process\n");
-   OUT("\t\t -h, --help: print this help\n");
+   output("usage:\tcmd_read [OPTS]");
+   output("\tOPTS:\t -v, --verbose: verbose output");
+   output("\t\t -r, --real-time: enable real-time acquisition mode");
+   output("\t\t -d, --device: device filename (analogy0, analogy1, ...)");
+   output("\t\t -s, --subdevice: subdevice index");
+   output("\t\t -S, --scan-count: count of scan to perform");
+   output("\t\t -c, --channels: channels to use (ex.: -c 0,1)");
+   output("\t\t -m, --mmap: mmap the buffer");
+   output("\t\t -w, --raw: dump data in raw format");
+   output("\t\t -k, --wake-count: space available before waking up the 
process");
+   output("\t\t -h, --help: output this help");
 }
 
-static int dump_raw(a4l_desc_t *dsc, a4l_cmd_t *cmd, unsigned char *buf, int 
size)
+static inline int dump_raw(a4l_desc_t *dsc, a4l_cmd_t *cmd, unsigned char 
*buf, int size)
 {
return fwrite(buf, size, 1, stdout);
 }
@@ -127,17 +123,12 @@ static int dump_text(a4l_desc_t *dsc, a4l_cmd_t *cmd, 
unsigned char *buf, int si
int width;
 
err = a4l_get_chinfo(dsc, cmd->idx_subd, cmd->chan_descs[i], 
&chans[i]);
-   if (err < 0) {
-   ERR("cmd_read: a4l_get_chinfo failed (ret=%d)\n", err);
-   goto out;
-   }
+   if (err < 0)
+   exit_err("a4l_get_chinfo failed (ret=%d)", err);
 
width = a4l_sizeof_chan(chans[i]);
-   if (width < 0) {
-   ERR("cmd_read: incoherent info for channel %d\n", 
cmd->chan_descs[i]);
-   err = width;
-   goto out;
-   }
+   if (width < 0)
+   exit_err("incoherent info for channel %d", 
cmd->chan_descs[i]);
 
switch (width) {
case 1:
@@ -159,14 +150,14 @@ static int dump_text(a4l_desc_t *dsc, a4l_cmd_t *cmd, 
unsigned char *buf, int si
if (err < 0)
goto out;
 
-   OUT(fmts[cur_chan], value);
+   fprintf(stdout, fmts[cur_chan], value);
 
/* We assume a4l_sizeof_chan() cannot return because we already
 * called it on the very same channel descriptor */
tmp_size += a4l_sizeof_chan(chans[cur_chan]);
 
if (++cur_chan == cmd->nb_chan) {
-   OUT("\n");
+   fprintf(stdout, "\n");
cur_chan = 0;