source: ETALON/CLIO/savedata/old-savedata.c @ 756

Last change on this file since 756 was 756, checked in by delerue, 6 years ago

Importing savedata

File size: 4.2 KB
Line 
1// $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/18AI32SSC1M/savedata/savedata.c $
2// $Rev: 35161 $
3// $Date: 2016-06-06 16:28:07 -0500 (Mon, 06 Jun 2016) $
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// #defines *******************************************************************
16
17#define _1M             (1024L * 1024L)
18
19
20
21// variables *******************************************************************
22
23static  u32     _buffer[_1M];
24
25
26
27//*****************************************************************************
28static int _channels(int fd, s32* chans)
29{
30        s32             active  = -1;
31        char    buf[64];
32        int             errs    = 0;
33        s32             first   = -1;
34        s32             last    = -1;
35        s32             single  = -1;
36
37        gsc_label("Input Channels");
38
39        active  = -1;
40        errs    += ai32ssc1m_dsl_ioctl(fd, AI32SSC1M_IOCTL_CHAN_ACTIVE, &active );
41        errs    += ai32ssc1m_dsl_ioctl(fd, AI32SSC1M_IOCTL_CHAN_FIRST,  &first  );
42        errs    += ai32ssc1m_dsl_ioctl(fd, AI32SSC1M_IOCTL_CHAN_LAST,   &last   );
43        errs    += ai32ssc1m_dsl_ioctl(fd, AI32SSC1M_IOCTL_CHAN_SINGLE, &single );
44
45        if (errs == 0)
46        {
47                switch (active)
48                {
49                        default:
50
51                                errs++;
52                                printf("FAIL <---  (invalid ACTIVE selection: %ld)\n", (long) active);
53                                break;
54
55                        case AI32SSC1M_CHAN_ACTIVE_SINGLE:
56
57                                chans[0]        = 1;
58                                sprintf(buf, "# %ld", (long) single);
59                                break;
60
61                        case AI32SSC1M_CHAN_ACTIVE_0_1:
62
63                                chans[0]        = 2;
64                                strcpy(buf, "#s 0-1");
65                                break;
66
67                        case AI32SSC1M_CHAN_ACTIVE_0_3:
68
69                                chans[0]        = 4;
70                                strcpy(buf, "#s 0-3");
71                                break;
72
73                        case AI32SSC1M_CHAN_ACTIVE_0_7:
74
75                                chans[0]        = 8;
76                                strcpy(buf, "#s 0-7");
77                                break;
78
79                        case AI32SSC1M_CHAN_ACTIVE_0_15:
80
81                                chans[0]        = 16;
82                                strcpy(buf, "#s 0-15");
83                                break;
84
85                        case AI32SSC1M_CHAN_ACTIVE_0_31:
86
87                                chans[0]        = 32;
88                                strcpy(buf, "#s 0-31");
89                                break;
90
91                        case AI32SSC1M_CHAN_ACTIVE_RANGE:
92
93                                chans[0]        = last - first + 1;
94
95                                if (first == last)
96                                        sprintf(buf, "# %ld", (long) first);
97                                else
98                                        sprintf(buf, "#s %ld-%ld", (long) first, (long) last);
99
100                                break;
101                }
102
103                if (errs == 0)
104                {
105                        printf( "%ld Channel%s  (%s)\n",
106                                        (long) chans[0],
107                                        (chans[0] == 1) ? "" : "s",
108                                        buf);
109                }
110        }
111
112        return(errs);
113}
114
115
116
117//*****************************************************************************
118static int _read_data(int fd)
119{
120        int             errs;
121        long    get             = sizeof(_buffer) / 4;
122        int             got;
123
124        gsc_label("Reading");
125        got     = ai32ssc1m_dsl_read(fd, _buffer, get);
126
127        if (got < 0)
128        {
129                errs    = 1;
130        }
131        else if (got != get)
132        {
133                errs    = 1;
134                printf( "FAIL <---  (got %ld samples, requested %ld)\n",
135                                (long) got,
136                                (long) get);
137        }
138        else
139        {
140                errs    = 0;
141                printf( "PASS  (%ld samples)\n",
142                                (long) get);
143        }
144
145        return(errs);
146}
147
148
149
150//*****************************************************************************
151static int _save_data(int fd, int chan, int errs)
152{
153        FILE*           file;
154        int                     i;
155        long            l;
156        const char*     name    = "data.txt";
157        long            samples = sizeof(_buffer) / 4;
158
159        gsc_label("Saving");
160
161        for (;;)
162        {
163                if (errs)
164                {
165                        printf("SKIPPED  (errors)\n");
166                        errs    = 0;
167                        break;
168                }
169
170                file    = fopen(name, "w+b");
171
172                if (file == NULL)
173                {
174                        printf("FAIL <---  (unable to create %s)\n", name);
175                        errs    = 1;
176                        break;
177                }
178
179                for (l = 0; l < samples; l++)
180                {
181                        if ((l) && (_buffer[l] & 0x80000000))
182                        {
183                                i       = fprintf(file, "\r\n");
184
185                                if (i != 2)
186                                {
187                                        printf("FAIL <---  (fprintf() failure to %s)\n", name);;
188                                        errs    = 1;
189                                        break;
190                                }
191                        }
192
193                        i       = fprintf(file, "  %08lX", (long) _buffer[l]);
194
195                        if (i != 10)
196                        {
197                                printf("FAIL <---  (fprintf() failure to %s)\n", name);
198                                errs    = 1;
199                                break;
200                        }
201                }
202
203                fclose(file);
204
205                if (errs == 0)
206                        printf("PASS  (%s)\n", name);
207
208                break;
209        }
210
211        return(errs);
212}
213
214
215
216//*****************************************************************************
217int save_data(int fd, s32 io_mode)
218{
219        s32     chans   = 32;
220        int     errs    = 0;
221
222        gsc_label("Capture & Save");
223        printf("\n");
224        gsc_label_level_inc();
225
226        errs    += ai32ssc1m_config_ai(fd, -1, 1440);
227        errs    += ai32ssc1m_rx_io_mode(fd, -1, io_mode, NULL);
228        errs    += _channels(fd, &chans);
229        errs    += ai32ssc1m_ain_buf_clear(fd, -1);
230        errs    += _read_data(fd);
231        errs    += ai32ssc1m_ain_buf_overflow(fd, -1, -1, NULL);
232        errs    += ai32ssc1m_ain_buf_underflow(fd, -1, -1, NULL);
233        errs    += _save_data(fd, chans, errs);
234
235        gsc_label_level_dec();
236        return(errs);
237}
238
239
240
Note: See TracBrowser for help on using the repository browser.