-
Notifications
You must be signed in to change notification settings - Fork 0
/
TINTRFAC.C
386 lines (272 loc) · 8.67 KB
/
TINTRFAC.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#include "TEKDECL.H"
#include "decl.h"
#include <string.h>
#define DEBUG 1
#define IN_BUFFER 1050
//#define STR_BUFFER 100
extern int bd; //defined in main scope.c file
extern char cont[];// = "\x3F\x5F\x40\x21\x0";
extern char scopt[];//= "\x3F\x5F\x41\x20\x0";
char data_buffer[IN_BUFFER+1]; //make it just a little bigger than required for some protection
//*************************************************************************************
//*
//* displayedChannels checks to determine which channels are displayed on the scope
//*
//* Receives a pointer to an array large enough to hold NUMCHANNELS bytes
// Returns: VOID, but fills the array with a 1 if the channel is displayed
//* or a zero if not displayed
//*
//*
//*************************************************************************************
void displayedChannels(uint8_t *list)
{
uint8_t channel;
//Check main waveforms CH1, CH2, ADD, MULT
//Check saved waveforms REF1, REF2, REF3, REF4
for (channel=0; channel <NUMCHANNELS; channel++)
{
if (CheckChannel(channel)) list[channel]=1;
else list[channel]=0;
}
}
//********************************************************************************
//*
//* Check Generic Channel if displayed
//* Receives: channel name
//* Returns: 1 if the channel is displayed, zero if not displayed
//*
//********************************************************************************
uint8_t CheckChannel(uint8_t channel) {
uint8_t len;
uint16_t recv;
// Tell the client to LISTEN for incoming data
// printf("cont pointer is: %p",cont);
// printf("cont = <%s>\r\n",cont);
ibcmd(bd,cont,strlen(cont)); //console talks, device listens
// Send the client the commands
strcpy(data_buffer,"PATH OFF");
ibwrt(bd,data_buffer,8);
// Assemble the request
switch (channel) {
case CH1:
strcpy(data_buffer,"VMO? CH1");
len = 8;
break;
case CH2:
strcpy(data_buffer,"VMO? CH2");
len = 8;
break;
case ADD:
strcpy(data_buffer,"VMO? ADD");
len = 8;
break;
case MULT:
strcpy(data_buffer,"VMO? MUL");
len = 8;
break;
case REF1:
strcpy(data_buffer,"REFDISP? REF1");
len = 13;
break;
case REF2:
strcpy(data_buffer,"REFDISP? REF2");
len = 13;
break;
case REF3:
strcpy(data_buffer,"REFDISP? REF3");
len = 13;
break;
case REF4:
strcpy(data_buffer,"REFDISP? REF4");
len = 13;
break;
}
//tell the scope what to send
ibwrt(bd, data_buffer, strlen(data_buffer));
//Tell the scope to start talking
ibcmd(bd, scopt, strlen(scopt));
//read data from bus
ibrd(bd, data_buffer, 1050);
// printf("Data length read: %d\r\n", ibcnt);
// printf(" channel: %d is <%s>", channel,data_buffer);
//if (recv ==0) Serial.println (F("Errored out"));
if ((data_buffer[0] == 'O') && (data_buffer[1] == 'N'))
{
//The channel is displayed.
//Now get its data.
//Serial.print(F("channel "));
//Serial.print((uint8_t)channel,DEC);
// Serial.println(F(" is displayed"));
return 1;
}
else {
//Serial.print(F("channel "));
//Serial.print((uint8_t)channel,DEC);
//Serial.println(F(" is NOT displayed"));
}
return 0;
}
//********************************************************************************
//*
//* Read Waveform Preamble
//* Sends commands to obtain the preamble, then parse out the extraneous characters
//* Receives: channel name
//* Returns: VOID, but the preamble text is in the data buffer
//*
//********************************************************************************
void ReadWfmPre(uint8_t channel)
{
uint16_t recv;
uint8_t len;
// Tell the client to LISTEN for incoming data
ibcmd(bd, cont, strlen(cont));
// send standard setup instructions
strcpy(data_buffer, "PATH OFF;DAT ENC:RPB");
ibwrt(bd, data_buffer, strlen(data_buffer));
//set data source and initiate the send of the waveform preamble
switch (channel) {
case CH1:
strcpy(data_buffer,"DAT SOU:CH1;WFM?");
len = 16;
break;
case CH2:
strcpy(data_buffer,"DAT SOU:CH2;WFM?");
len = 16;
break;
case ADD:
strcpy(data_buffer,"DAT SOU:ADD;WFM?");
len = 16;
break;
case MULT:
strcpy(data_buffer,"DAT SOU:MUL;WFM?");
len = 16;
break;
case REF1:
strcpy(data_buffer,"DAT SOU:REF1;WFM?");
len = 17;
break;
case REF2:
strcpy(data_buffer,"DAT SOU:REF2;WFM?");
len = 17;
break;
case REF3:
strcpy(data_buffer,"DAT SOU:REF3;WFM?");
len = 17;
break;
case REF4:
strcpy(data_buffer,"DAT SOU:REF4;WFM?");
len = 17;
break;
//default:
//errorFunction();
}
ibwrt(bd, data_buffer, len);
//Tell the client to start talking
ibcmd(bd, scopt, strlen(scopt));
//read string from the scope
ibrd(bd, data_buffer, 1050);
if (ibcnt != 0) //parse the data IF data was received
{
ParseWFM();
//Serial.write(data_buffer);
//Serial.println();
}
}
//********************************************************************************
//*
//* Read Curve
//* Sends commands to obtain the curve data, then parse out the extraneous characters
//* Receives: channel name
//* Returns: VOID, but the data is in the data buffer
//*
//********************************************************************************
void ReadCurve(uint8_t channel)
{
// uint16_t recv;
uint8_t len;
// Tell the client to LISTEN for incoming data
ibcmd(bd, cont, strlen(cont));
// send standard setup instructions
strcpy(data_buffer, "PATH OFF;DAT ENC:RPB");
ibwrt(bd, data_buffer, strlen(data_buffer));
switch (channel) {
case CH1:
strcpy(data_buffer, "DAT SOU:CH1;CURV?");
break;
case CH2:
strcpy(data_buffer, "DAT SOU:CH2;CURV?");
break;
case ADD:
strcpy(data_buffer, "DAT SOU:ADD;CURV?");
break;
case MULT:
strcpy(data_buffer, "DAT SOU:MUL;CURV?");
break;
case REF1:
strcpy(data_buffer, "DAT SOU:REF1;CURV?");
break;
case REF2:
strcpy(data_buffer, "DAT SOU:REF2;CURV?");
break;
case REF3:
strcpy(data_buffer, "DAT SOU:REF3;CURV?");
break;
case REF4:
strcpy(data_buffer, "DAT SOU:REF4;CURV?");
break;
default:
printf("invalid channel selection\r\n");
}
ibwrt(bd, data_buffer, strlen(data_buffer));
//Tell the client to start talking
ibcmd(bd, scopt, strlen(scopt));
//recv = Read_Data(); //read string from bus
ibrd(bd, data_buffer, 1050);
if (ibcnt != 0)
{
//Serial.print(F("Data received: "));
//Serial.print(recv);
//Serial.println(F("bytes"));
//now do something with the data
ParseData();
//now send the data the the flash drive
}
}
//******************************************************************************
//*
//* Parse WFMPre
//*
//******************************************************************************
uint8_t ParseWFM(void)
{
//find the text within quotes in the WFM string
//and move it to the beginning and null terminate it
uint16_t pos1, pos2;
uint16_t x, index;
char *ptr;
ptr = (char *)strchr(data_buffer,'"');
pos1 = (uint16_t) (ptr-data_buffer);
//Serial.println(pos1);
ptr = (char*)strchr(&data_buffer[pos1+1],'"');
pos2 = (uint16_t) (ptr-data_buffer);
for (x = pos1+1, index = 0; x < pos2; x++, index++) data_buffer[index] = data_buffer[x];
data_buffer[index] = 0; //null terminate the new string
return (uint8_t) index+1;
}
//******************************************************************************
//*
//* Parse Data
//*
//******************************************************************************
void ParseData(void)
{
//The data has 3 bytes of a header in the beginning
//And one byte of a checksum at the end
//So, move the data forward by 3 bytes to eliminate the header
//The header is one byte of a special character, then 2 bytes of the data size in case it matters
//The starting point is byte 3 and the number of bytes to move is 1024
//TODO: Use memmove()? movemem()?
uint16_t x, index;
for (x = 0, index = 3; x < 1024; x++, index++) data_buffer[x] = data_buffer[index];
//data_buffer[1024] = 0; //put a null at the end just to show where the end is.
}