-
Notifications
You must be signed in to change notification settings - Fork 2
/
TASS_usb.ino
394 lines (354 loc) · 9.64 KB
/
TASS_usb.ino
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
387
388
389
390
391
392
393
394
/* TASS - USB
*
* USB Serial Functions
*
* Author: Matthew J. Wolf <matthew.wolf.hpsdr@speciosus.net>
* Date: 18-NOV-2018
*
* - Version 0.7-n4mtt
* = Added functions
* -= usb_display_info()
* -= info_usb_board()
* -= info_usb_relay()
*
* - Original author is John Ackermann, N8UR
*
* Copyright (c) 2016 John Ackermann
* Copyright (c) 2018 Matthew J. Wolf
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
void usb_setup() {
// initialize serial:
Serial.begin(115200);
// splash
Serial.println();
Serial.println("TAPR TASS Control Software");
Serial.println(version);
Serial.println("Copyright 2020 John Ackermann N8UR");
Serial.println("Copyright 2018 Matthew J Wolf N4MTT");
Serial.println("Licensed under MIT license");
#ifdef SHOW_INFO_USB
usb_display_info(NUM_TASS_BOARDS_DISPLAY);
#else
Serial.println("");
#endif
} // usb_setup()
boolean get_usb_data() {
if ( getSerialString() ) {
board = toupper(dataBuffer[1]);
relay = atoi(&dataBuffer[2]);
cmd = toupper(dataBuffer[3]);
execute = 1;
// first param is board, A - D
if (!(board >= 'A' && board <= 'D')) {execute = 0;} // board check
// second is relay, 0 through 8
if (!(relay >= 0 && relay <= 8)) {execute = 0;} // relay check
// third is command -- H, S, or U
if (!((cmd == 'H') || (cmd == 'S') || (cmd == 'U') || (cmd == 'I'))) {execute = 0;} // cmd check
} //call getSerialString
return execute;
} //get_usb_data
boolean getSerialString(){
static byte dataBufferIndex = 0;
boolean storeString;
while(Serial.available()>0){
char incomingbyte = Serial.read();
if(incomingbyte==startChar){
dataBufferIndex = 0; //Initialize our dataBufferIndex variable
storeString = true;
}
if(storeString){
// Abort if index outside buffer size
if(dataBufferIndex==DATABUFFERSIZE){
dataBufferIndex = 0;
break;
}
if(incomingbyte==endChar){
dataBuffer[dataBufferIndex] = 0; //null terminate the C string
//Data string is complete.
storeString = false;
return true;
}
else{
dataBuffer[dataBufferIndex++] = incomingbyte;
dataBuffer[dataBufferIndex] = 0; //null terminate the C string
}
}
else{
}
}
//All data read; no valid string
return false;
}
void usb_print_status(){
Serial.println("");
Serial.print ("Board: ");
Serial.print (board);
Serial.print (" relay: ");
Serial.print (relay);
Serial.print (" command: ");
Serial.print (cmd);
if ((cmd == 'U') && (relay == 0)) { Serial.print(" -- Clear All"); }
Serial.println();
#ifdef SHOW_INFO_USB
usb_display_info(NUM_TASS_BOARDS_DISPLAY);
#endif
#ifdef SHOW_MASKS
usb_display_masks();
Serial.println();
#endif
} // usb_print_status()
// Display status of relays
void usb_display_info(int board_num) {
int i = -1;
Serial.println();
Serial.println("--- Relay State ---");
Serial.println(" * :Hold enabled");
if (board_num > 0) {
#ifdef A_DOUBLE_POLE
Serial.print("Board A:");
#ifdef SPLIT
Serial.print(" (K9 SPLIT)");
#endif
Serial.println(" (Double Pole)");
// Top relay of double pole
for ( i=0; i < 4; i++ ) {
Serial.print((i+1),DEC);
Serial.print(":");
if ( digitalRead(A_1 + i) ) {
Serial.print("ON");
if ( get_bit_mask_state(i, H_mask_A) == 1) {
Serial.print("*");
}
else {
Serial.print(" ");
}
}
else {
Serial.print("OFF");
}
Serial.print(" ");
}
Serial.println();
// Bottom relay of double pole
for ( i=0; i < 4; i++ ) {
Serial.print((i+5),DEC);
Serial.print(":");
if ( digitalRead(A_1 + (i+4)) ) {
Serial.print("ON");
if ( get_bit_mask_state((i+4), H_mask_A) == 1) {
Serial.print("*");
}
else {
Serial.print(" ");
}
}
else {
Serial.print("OFF");
}
Serial.print(" ");
}
Serial.println();
#else
Serial.print("Board A:");
#ifdef SPLIT
Serial.print(" (K9 SPLIT)");
#endif
Serial.println();
for ( i=0; i < 8; i++ ) {
Serial.print((i+1),DEC);
Serial.print(":");
if ( digitalRead(A_1 + i) ) {
Serial.print("ON");
if ( get_bit_mask_state(i, H_mask_A) == 1) {
Serial.print("*");
}
else {
Serial.print(" ");
}
}
else {
Serial.print("OFF");
}
Serial.print(" ");
}
#endif
Serial.println();
}
if (board_num > 1) {
Serial.print("Board B:");
#ifdef SPLIT
Serial.print(" (K9 SPLIT)");
#endif
#ifdef A_B_COMBINE
Serial.print(" (A and B Combined)");
#endif
Serial.println();
for ( i=0; i < 8; i++ ) {
Serial.print((i+1),DEC);
Serial.print(":");
if ( digitalRead(B_1 + i) ) {
Serial.print("ON");
if ( get_bit_mask_state(i, H_mask_B) == 1) {
Serial.print("*");
}
else {
Serial.print(" ");
}
}
else {
Serial.print("OFF");
}
Serial.print(" ");
}
Serial.println();
}
if (board_num > 2) {
Serial.print("Board C:");
#ifdef SPLIT
Serial.print(" (K9 SPLIT)");
#endif
Serial.println();
for ( i=0; i < 8; i++ ) {
Serial.print((i+1),DEC);
Serial.print(":");
if ( digitalRead(C_1 + i) ) {
Serial.print("ON");
if ( get_bit_mask_state(i, H_mask_C) == 1) {
Serial.print("*");
}
else {
Serial.print(" ");
}
}
else {
Serial.print("OFF");
}
Serial.print(" ");
}
Serial.println();
}
if (board_num > 3) {
Serial.print("Board D:");
#ifdef SPLIT
Serial.print(" (K9 SPLIT)");
#endif
Serial.println();
for ( i=0; i < 8; i++ ) {
Serial.print((i+1),DEC);
Serial.print(":");
if ( digitalRead(D_1 + i) ) {
Serial.print("ON");
if ( get_bit_mask_state(i, H_mask_D) == 1) {
Serial.print("*");
}
else {
Serial.print(" ");
}
}
else {
Serial.print("OFF");
}
Serial.print(" ");
}
Serial.println();
}
}
void usb_display_masks() {
Serial.println();
Serial.print("S Masks: ");
usb_printBits(S_mask_A);
Serial.print(" ");
usb_printBits(S_mask_B);
Serial.print(" ");
usb_printBits(S_mask_C);
Serial.print(" ");
usb_printBits(S_mask_D);
Serial.println();
Serial.print("H Masks: ");
usb_printBits(H_mask_A);
Serial.print(" ");
usb_printBits(H_mask_B);
Serial.print(" ");
usb_printBits(H_mask_C);
Serial.print(" ");
usb_printBits(H_mask_D);
Serial.println();
Serial.print("Write Masks: ");
usb_printBits(cmd_mask_A);
Serial.print(" ");
usb_printBits(cmd_mask_B);
Serial.print(" ");
usb_printBits(cmd_mask_C);
Serial.print(" ");
usb_printBits(cmd_mask_D);
Serial.println();
} // display_masks()
void usb_printBits(byte myByte){
for (byte mask = 0x80; mask; mask >>= 1){
if (mask & myByte)
Serial.print('1');
else
Serial.print('0');
}
} // usb_printBits()
void info_usb_board(int board,int first_dpin,int h_mask){
int x = -1;
Serial.print("i,");
Serial.write(board);
Serial.print(",");
for ( x=0; x < 8; x++ ) {
if ( digitalRead(first_dpin + x) ) {
if ( get_bit_mask_state(x, h_mask) == 1) {
Serial.print("h");
}
else {
Serial.print("s");
}
}
else {
Serial.print("0");
}
if ( x < 7) {
Serial.print(",");
}
}
Serial.print("\n");
}
void info_usb_relay(int board, int relay,int first_dpin,int h_mask){
Serial.print("i,");
Serial.write(board);
Serial.print(",");
Serial.print(relay);
Serial.print(",");
if ( digitalRead(first_dpin + (relay-1)) ) {
if ( get_bit_mask_state((relay-1), h_mask) == 1) {
Serial.print("h");
}
else {
Serial.print("s");
}
}
else {
Serial.print("0");
}
Serial.print("\n");
}