source: ETALON/DAQ/main.c

Last change on this file was 4, checked in by delerue, 11 years ago

Added DAQ software (version without trigger)

File size: 5.9 KB
Line 
1// $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/18AI32SSC1M/savedata/main.c $
2// $Rev: 16253 $
3// $Date: 2012-05-10 15:10:31 -0500 (Thu, 10 May 2012) $
4
5#include <ctype.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <time.h>
10
11#include "main.h"
12
13
14
15// variables    ***************************************************************
16
17static  int             _continuous             = 0;
18static  int             _ignore_errors  = 0;
19static  int             _index                  = 0;
20static  __s32   _io_mode                = GSC_IO_MODE_DMA;
21static  long    _minute_limit   = 0;
22static  int             _test_limit             = -1;
23
24
25
26/******************************************************************************
27*
28*       Function:       _parse_args
29*
30*       Purpose:
31*
32*               Parse the command line arguments.
33*
34*       Arguments:
35*
36*               argc    The number of command line arguments given.
37*
38*               argv    The list of command line arguments given.
39*
40*       Returned:
41*
42*               >= 0    The number of errors encounterred.
43*
44******************************************************************************/
45
46static int _parse_args(int argc, char** argv)
47{
48        char    c;
49        int             errs    = 0;
50        int             i;
51        int             j;
52        int             k;
53
54        printf("USAGE: savedata <-c> <-C> <-dma> <-dmdma> <-m#> <-n#> <-pio> <index>\n");
55        printf("   -c      Continue testing until an error occurs.\n");
56        printf("   -C      Continue testing even if errors occur.\n");
57        printf("   -dma    Use standard DMA for data transfer. This is the default.\n");
58        printf("   -dmama  Use Deman Mode DMA for data transfer.\n");
59        printf("   -m#     Run for at most # minutes (a decimal number).\n");
60        printf("   -n#     Repeat test at most # times (a decimal number).\n");
61        printf("   -pio    Use PIO for data transfer.\n");
62        printf("   index   The index of the board to access.\n");
63        printf(" NOTE: Hit Ctrl-C to abort continuous testing.\n");
64
65        for (i = 1; i < argc; i++)
66        {
67                if (strcmp(argv[i], "-c") == 0)
68                {
69                        _continuous             = 1;
70                        _ignore_errors  = 0;
71                        continue;
72                }
73
74                if (strcmp(argv[i], "-C") == 0)
75                {
76                        _continuous             = 1;
77                        _ignore_errors  = 1;
78                        continue;
79                }
80
81                if (strcmp(argv[i], "-dma") == 0)
82                {
83                        _io_mode        = GSC_IO_MODE_DMA;
84                        continue;
85                }
86
87                if (strcmp(argv[i], "-dmdma") == 0)
88                {
89                        _io_mode        = GSC_IO_MODE_DMA;
90                        continue;
91                }
92
93                if (strcmp(argv[i], "-pio") == 0)
94                {
95                        _io_mode        = GSC_IO_MODE_PIO;
96                        continue;
97                }
98
99                if ((argv[i][0] == '-') && (argv[i][1] == 'm') && (argv[i][2]))
100                {
101                        j       = sscanf(&argv[i][2], "%d%c", &k, &c);
102
103                        if ((j == 1) && (k > 0))
104                        {
105                                _minute_limit   = k;
106                                continue;
107                        }
108
109                        errs    = 1;
110                        printf("ERROR: invalid argument: %s\n", argv[i]);
111                        break;
112                }
113
114                if ((argv[i][0] == '-') && (argv[i][1] == 'n') && (argv[i][2]))
115                {
116                        j       = sscanf(&argv[i][2], "%d%c", &k, &c);
117
118                        if ((j == 1) && (k > 0))
119                        {
120                                _test_limit     = k;
121                                continue;
122                        }
123
124                        errs    = 1;
125                        printf("ERROR: invalid argument: %s\n", argv[i]);
126                        break;
127                }
128
129                j       = sscanf(argv[i], "%d%c", &k, &c);
130
131                if ((j == 1) && (k >= 0))
132                {
133                        _index  = k;
134                        continue;
135                }
136                else
137                {
138                        errs    = 1;
139                        printf("ERROR: invalid board selection: %s\n", argv[i]);
140                        break;
141                }
142        }
143
144        return(errs);
145}
146
147
148
149/******************************************************************************
150*
151*       Function:       _perform_tests
152*
153*       Purpose:
154*
155*               Perform the appropriate testing.
156*
157*       Arguments:
158*
159*               fd              The handle for the board to access.
160*
161*       Returned:
162*
163*               >= 0    The number of errors encounterred.
164*
165******************************************************************************/
166
167static int _perform_tests(int fd)
168{
169        int                     errs    = 0;
170        const char*     psz;
171        struct tm*      stm;
172        time_t          tt;
173
174        time(&tt);
175        stm     = localtime(&tt);
176        psz     = asctime(stm);
177        gsc_label("Performing Operation");
178        printf("%s", psz);
179
180        errs    += gsc_id_driver(AI32SSC1M_BASE_NAME);
181        errs    += ai32ssc1m_id_board(fd, -1, NULL);
182
183        errs    += save_data(fd, _io_mode);
184
185        return(errs);
186}
187
188
189
190/******************************************************************************
191*
192*       Function:       main
193*
194*       Purpose:
195*
196*               Control the overall flow of the application.
197*
198*       Arguments:
199*
200*               argc                    The number of command line arguments.
201*
202*               argv                    The list of command line arguments.
203*
204*       Returned:
205*
206*               EXIT_SUCCESS    We tested a device.
207*               EXIT_FAILURE    We didn't test a device.
208*
209******************************************************************************/
210
211int main(int argc, char *argv[])
212{
213        int             errs;
214        time_t  exec            = time(NULL);
215        long    failures        = 0;
216        int             fd                      = 0;
217        long    hours;
218        long    mins;
219        time_t  now;
220        long    passes          = 0;
221        int             qty;
222        int             ret                     = EXIT_FAILURE;
223        long    secs;
224        time_t  t_limit;
225        time_t  test;
226        long    tests           = 0;
227
228        gsc_label_init(28);
229
230        for (;;)
231        {
232                test    = time(NULL);
233                printf("savedata - Capture and Save Data to Disk (Version %s)\n", VERSION);
234                errs    = _parse_args(argc, argv);
235
236                if (errs)
237                        break;
238
239                gsc_id_host();
240                t_limit = exec + (_minute_limit * 60);
241                qty             = gsc_count_boards(AI32SSC1M_BASE_NAME);
242                errs    = gsc_select_1_board(qty, &_index);
243
244                if ((qty <= 0) || (errs))
245                        break;
246
247                gsc_label("Accessing Board Index");
248                printf("%d\n", _index);
249                fd      = gsc_dev_open(_index, AI32SSC1M_BASE_NAME);
250
251                if (fd == -1)
252                {
253                        errs    = 1;
254                        printf( "ERROR: Unable to access device %d.", _index);
255                }
256
257                if (errs == 0)
258                {
259                        ret             = EXIT_SUCCESS;
260                        errs    = _perform_tests(fd);
261                }
262
263                gsc_dev_close(_index, fd);
264
265                now     = time(NULL);
266                tests++;
267
268                if (errs)
269                {
270                        failures++;
271                        printf( "\nRESULTS: FAIL <---  (%d error%s)",
272                                        errs,
273                                        (errs == 1) ? "" : "s");
274                }
275                else
276                {
277                        passes++;
278                        printf("\nRESULTS: PASS");
279                }
280
281                secs    = now - test;
282                hours   = secs / 3600;
283                secs    = secs % 3600;
284                mins    = secs / 60;
285                secs    = secs % 60;
286                printf(" (duration %ld:%ld:%02ld)\n", hours, mins, secs);
287
288                secs    = now - exec;
289                hours   = secs / 3600;
290                secs    = secs % 3600;
291                mins    = secs / 60;
292                secs    = secs % 60;
293                printf( "SUMMARY: tests %ld, pass %ld, fail %ld"
294                                " (duration %ld:%ld:%02ld)\n\n",
295                                tests,
296                                passes,
297                                failures,
298                                hours,
299                                mins,
300                                secs);
301
302                if ((_test_limit > 0) && (_test_limit <= tests))
303                        break;
304
305                if (_continuous == 0)
306                        break;
307
308                if ((_ignore_errors == 0) && (errs))
309                        break;
310
311                if ((_minute_limit) && (now >= t_limit))
312                        break;
313        }
314
315        return(ret);
316}
317
318
319
Note: See TracBrowser for help on using the repository browser.