added cmd related functions
authorDavid Schleef <ds@schleef.org>
Mon, 28 May 2001 02:36:03 +0000 (02:36 +0000)
committerDavid Schleef <ds@schleef.org>
Mon, 28 May 2001 02:36:03 +0000 (02:36 +0000)
lib/cmd.c [new file with mode: 0644]

diff --git a/lib/cmd.c b/lib/cmd.c
new file mode 100644 (file)
index 0000000..82fbe9a
--- /dev/null
+++ b/lib/cmd.c
@@ -0,0 +1,90 @@
+
+#include <stdio.h>
+#include <comedilib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <getopt.h>
+#include <ctype.h>
+#include <math.h>
+#include <sys/time.h>
+#include <string.h>
+
+
+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_generic_timed(comedi_t *it,unsigned int s,comedi_cmd *cmd)
+{
+       int ret;
+
+       ret = comedi_get_cmd_src_mask(it,s,cmd);
+       if(ret<0)return ret;
+
+       if(cmd->start_src&TRIG_NOW){
+               cmd->start_src=TRIG_NOW;
+               cmd->start_arg=0;
+       }else if(cmd->start_src&TRIG_FOLLOW){
+               cmd->start_src=TRIG_FOLLOW;
+               cmd->start_arg=0;
+       }
+               /* hmmm... don't know what to do */
+               return -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 -1;
+       }
+
+       cmd->scan_end_src = TRIG_COUNT;
+       cmd->scan_end_arg = 1;
+
+       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 -1;
+       }
+
+       cmd->chanlist_len = 1;
+
+       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;
+}
+