ACQ2XX_API
acq196_api_test.cpp
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file api_test.cpp                                                         */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2008 Peter Milne, D-TACQ Solutions Ltd
00005  *                      <Peter dot Milne at D hyphen TACQ dot com>
00006 
00007  This program is free software; you can redistribute it and/or modify
00008  it under the terms of Version 2 of the GNU General Public License
00009  as published by the Free Software Foundation;
00010 
00011  This program is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with this program; if not, write to the Free Software
00018  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
00019 /* ------------------------------------------------------------------------- */
00020 
00021 /** @file acq196_api_test.cpp start and monitor continuous capture using API.
00022 - exercise the methods of Acq2xx, first by setting properties,
00023 - then run a continuous capture.
00024 - <ctrlC> will abort the program, sending a setAbort to target
00025  *
00026 <pre>
00027   opts:
00028 Usage: acq196_api_test [OPTION...]
00029   -f, --device=STRING
00030   -b, --board=STRING
00031   -s, --shell=STRING
00032   -v, --verbose=INT
00033   --version
00034   -T, --trigger
00035   --trigger-type=STRING
00036   -t, --timeout=INT         timeout in seconds
00037   --iclock=INT              internal clock in Hz
00038 
00039 Help options:
00040   -?, --help                Show this help message
00041   --device                  Example: ip-address eg 192.168.0.123, localhost:10010
00042   --usage                   Display brief usage message
00043   -T : use hard trigger 
00044   --trigger-type lemo-master : set.route in lemo out fpga pxi : chassis master
00045   --trigger-type pxi-slave   : set.route in pxi out fpga      : chassis slave
00046                                default: front panel lemo-standalone
00047 </pre>
00048  */
00049 
00050 #include <popt.h>
00051 
00052 #include <signal.h>
00053 
00054 #include "local.h"
00055 #include "acq2xx_api.h"
00056 #include "acq_transport.h"
00057 
00058 int acq200_debug;
00059 int timeout;
00060 char* device;
00061 int do_shell;
00062 
00063 #define RETERR(cmd) if (STATUS_ERR(rc = cmd)) {         \
00064         err("failed: \"%s\" code:%d", #cmd, rc);        \
00065         return rc;      \
00066 }
00067 
00068 
00069 #define POST 1024000
00070 
00071 
00072 const char *trigger_type = "lemo-standalone";
00073 
00074 static int interrupted;
00075 
00076 void sigintHandler(int signum)
00077 {
00078         interrupted = 1;
00079 }
00080 
00081 static void installSignalHandler(void)
00082 {
00083         struct sigaction sa;
00084         memset(&sa, 0, sizeof(sa));
00085         sa.sa_handler = sigintHandler;
00086         if (sigaction(SIGINT, &sa, NULL)) perror("sigaction");
00087 }
00088 
00089 static int iclock = 10000;
00090 
00091 int main(int argc, const char* argv[])
00092 {
00093         struct poptOption opt_table[] = {
00094                 { "device",     'f', POPT_ARG_STRING, &device,          'f' },
00095                 { "board",      'b', POPT_ARG_STRING, &device,          'b' },
00096                 { "shell",      's', POPT_ARG_STRING, &device,          's' },
00097                 { "verbose",    'v', POPT_ARG_INT,    &acq200_debug,    0   },
00098                 { "version",    0,   POPT_ARG_NONE,   0,                'V' },
00099                 { "trigger",    'T', POPT_ARG_NONE,   0,                'T' },
00100                 { "trigger-type", 0, POPT_ARG_STRING, &trigger_type,    0 },
00101                 { "timeout",    't', POPT_ARG_INT,    &timeout,         't',
00102                           "timeout in seconds"},
00103                 { "iclock",     0,   POPT_ARG_INT,    &iclock,          0,
00104                   "internal clock in Hz" },
00105                 POPT_AUTOHELP
00106                 POPT_TABLEEND           
00107         };
00108         int rc;
00109         poptContext opt_context = 
00110                 poptGetContext(argv[0], argc, argv, opt_table, 0);
00111         int soft_trigger = 1;
00112 
00113         while ( (rc = poptGetNextOpt(opt_context)) > 0 ){
00114                 switch(rc){
00115                 case 's':
00116                         do_shell = 1;
00117                         break;  
00118                 case 'T':
00119                         soft_trigger = 0;
00120                         break;
00121                 }
00122         }       
00123 
00124         if (device == 0){
00125                 err("usage api_test -f DEVICE command ...");
00126                 return -1;
00127         }
00128 
00129         installSignalHandler();
00130         
00131         Transport *t = Transport::getTransport(device); 
00132         Acq2xx card(t);
00133         int channels;
00134 
00135         printf("Test starts here:");
00136 
00137         printf("getAvailableChannels\n");
00138         RETERR(card.getAvailableChannels(channels));
00139         printf("getAvailableChannels: %d\n", channels);
00140 
00141 
00142         printf("setInternalClock(%d)\n", iclock);
00143         RETERR(card.setInternalClock(iclock));  
00144         iclock = -1234;
00145         RETERR(card.getInternalClock(iclock));
00146         printf("getInternalClock value %d\n", iclock);
00147 
00148         printf("setChannelMask\n");
00149         char* channelMask = new char[96];
00150         int ch;
00151         for (ch = 1; ch <= 96; ++ch){
00152                 channelMask[ch-1] = '1';
00153         }
00154         channelMask[ch-1] = '\0';
00155 
00156         RETERR(card.selectChannels(channelMask));
00157 
00158         RETERR(card.getSelectedChannels(channelMask, &channels));
00159         printf("getChannelMask %s number of channels %d\n", 
00160                         channelMask, channels);
00161 
00162 
00163         RETERR(card.setPrePostMode(10000,10000, DI_NONE));
00164 
00165         RETERR(card.setArm());
00166         
00167         enum STATE s;
00168         int post;
00169         do {
00170                 sleep(1);
00171                 if (interrupted){
00172                         printf("Quit on SIGINT\n");
00173                         RETERR(card.setAbort());        
00174                 }
00175                 RETERR(card.getState(s));
00176                 RETERR(card.getNumSamples(&post));
00177                 printf("getState:%s total:%d\n", toString(s), post);
00178         } while(s != ST_STOP);
00179 
00180         
00181         delete [] channelMask;
00182         return 0;
00183 }