-
Notifications
You must be signed in to change notification settings - Fork 0
/
HostInterface.c
1649 lines (1385 loc) · 36.2 KB
/
HostInterface.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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ARDOP TNC Host Interface
//
#include "ARDOPC.h"
BOOL blnHostRDY = FALSE;
extern int intFECFramesSent;
void SendData();
BOOL CheckForDisconnect();
int Encode4FSKControl(UCHAR bytFrameType, UCHAR bytSessionID, UCHAR * bytreturn);
int ComputeInterFrameInterval(int intRequestedIntervalMS);
HANDLE OpenCOMPort(VOID * pPort, int speed, BOOL SetDTR, BOOL SetRTS, BOOL Quiet, int Stopbits);
BOOL WriteCOMBlock(HANDLE fd, char * Block, int BytesToWrite);
void SetupGPIOPTT();
VOID ConvertCallstoAX25();
int GetEEPROM(int Reg);
void SaveEEPROM(int reg, int val);
void Break();
extern BOOL NeedID; // SENDID Command Flag
extern BOOL NeedConReq; // ARQCALL Command Flag
extern BOOL NeedPing;
extern BOOL PingCount;
extern char ConnectToCall[16];
extern enum _ARQBandwidth CallBandwidth;
extern int PORTT1; // L2 TIMEOUT
extern int PORTN2; // RETRIES
#define L2TICK 10 // Timer called every 1/10 sec
int SerialMode = 0;
extern BOOL NeedTwoToneTest;
extern unsigned int lastRTCTick;// Make sure this is set to ticks mod 1000 so RTC incrememtns at mS 0
extern unsigned int RTC; // set to seconds since 01.01.2000 by DATE and TIME Commands (Dragon log time epoch)
#ifndef WIN32
#define strtok_s strtok_r
#define _strupr strupr
char * strupr(char* s)
{
char* p = s;
if (s == 0)
return 0;
while (*p = toupper( *p )) p++;
return s;
}
int _memicmp(unsigned char *a, unsigned char *b, int n)
{
if (n)
{
while (n && toupper(*a) == toupper(*b))
n--, a++, b++;
if (n)
return toupper(*a) - toupper(*b);
}
return 0;
}
#endif
extern int dttTimeoutTrip;
#define BREAK 0x23
extern UCHAR bytSessionID;
// Subroutine to add data to outbound queue (bytDataToSend)
void AddDataToDataToSend(UCHAR * bytNewData, int Len)
{
char HostCmd[32];
if (Len == 0)
return;
if ((bytDataToSendLength + Len) >= DATABUFFERSIZE)
return; // Flow control has failed
GetSemaphore();
memcpy(&bytDataToSend[bytDataToSendLength], bytNewData, Len);
bytDataToSendLength += Len;
if (bytDataToSendLength > DATABUFFERSIZE)
return;
FreeSemaphore();
SetLED(TRAFFICLED, TRUE);
sprintf(HostCmd, "BUFFER %d", bytDataToSendLength);
QueueCommandToHost(HostCmd);
}
char strFault[100] = "";
VOID DoTrueFalseCmd(char * strCMD, char * ptrParams, BOOL * Value)
{
char cmdReply[128];
if (ptrParams == NULL)
{
sprintf(cmdReply, "%s %s", strCMD, (*Value) ? "TRUE": "FALSE");
SendReplyToHost(cmdReply);
return;
}
if (strcmp(ptrParams, "TRUE") == 0)
*Value = TRUE;
else if (strcmp(ptrParams, "FALSE") == 0)
*Value = FALSE;
else
{
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
return;
}
sprintf(cmdReply, "%s now %s", strCMD, (*Value) ? "TRUE": "FALSE");
SendReplyToHost(cmdReply);
return;
}
// Subroutine for processing a command from Host
void ProcessCommandFromHost(char * strCMD)
{
char * ptrParams;
char cmdCopy[80] = "";
char strFault[100] = "";
char cmdReply[1024];
strFault[0] = 0;
strCMD[79] = 0; // in case cmd handler gets garbage
memcpy(cmdCopy, strCMD, 79); // save before we split it up
_strupr(strCMD);
if (CommandTrace) WriteDebugLog(LOGDEBUG, "[Command Trace FROM host: %s", strCMD);
ptrParams = strlop(strCMD, ' ');
if (strcmp(strCMD, "ABORT") == 0 || strcmp(strCMD, "DD") == 0)
{
Abort();
SendReplyToHost("ABORT");
goto cmddone;
}
if (strcmp(strCMD, "ARQBW") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "ARQBW %s", ARQBandwidths[ARQBandwidth]);
SendReplyToHost(cmdReply);
goto cmddone;
}
else
{
for (i = 0; i < 8; i++)
{
if (strcmp(ptrParams, ARQBandwidths[i]) == 0)
break;
}
if (i == 8)
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
else
{
ARQBandwidth = i;
sprintf(cmdReply, "ARQBW now %s", ARQBandwidths[ARQBandwidth]);
SendReplyToHost(cmdReply);
}
}
goto cmddone;
}
if (strcmp(strCMD, "ARQCALL") == 0)
{
char * strCallParam = NULL;
if (ptrParams)
strCallParam = strlop(ptrParams, ' ');
if (strCallParam)
{
if ((strcmp(ptrParams, "CQ") == 0) || CheckValidCallsignSyntax(ptrParams))
{
int param = atoi(strCallParam);
if (param > 1 && param < 16)
{
if (Callsign[0] == 0)
{
sprintf(strFault, "MYCALL not Set");
goto cmddone;
}
if (ProtocolMode == ARQ)
{
ARQConReqRepeats = param;
NeedConReq = TRUE;
strcpy(ConnectToCall, ptrParams);
SendReplyToHost(cmdCopy);
goto cmddone;
}
sprintf(strFault, "Not from mode FEC");
goto cmddone;
}
}
}
sprintf(strFault, "Syntax Err: %s", cmdCopy);
goto cmddone;
}
if (strcmp(strCMD, "ARQTIMEOUT") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %d", strCMD, ARQTimeout);
SendReplyToHost(cmdReply);
goto cmddone;
}
else
{
i = atoi(ptrParams);
if (i > 29 && i < 241)
{
ARQTimeout = i;
sprintf(cmdReply, "%s now %d", strCMD, ARQTimeout);
SendReplyToHost(cmdReply);
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
if (strcmp(strCMD, "AUTOBREAK") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &AutoBreak);
goto cmddone;
}
if (strcmp(strCMD, "BREAK") == 0)
{
Break();
goto cmddone;
}
if (strcmp(strCMD, "BUFFER") == 0)
{
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %d", strCMD, bytDataToSendLength);
SendReplyToHost(cmdReply);
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
goto cmddone;
}
if (strcmp(strCMD, "BUSYBLOCK") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &BusyBlock);
goto cmddone;
}
if (strcmp(strCMD, "BUSYDET") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %d", strCMD, BusyDet);
SendReplyToHost(cmdReply);
}
else
{
i = atoi(ptrParams);
if (i >= 0 && i <= 10)
{
BusyDet = i;
sprintf(cmdReply, "%s now %d", strCMD, BusyDet);
SendReplyToHost(cmdReply);
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
if (strcmp(strCMD, "CALLBW") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "CALLBW %s", ARQBandwidths[CallBandwidth]);
SendReplyToHost(cmdReply);
goto cmddone;
}
else
{
for (i = 0; i < 9; i++)
{
if (strcmp(ptrParams, ARQBandwidths[i]) == 0)
break;
}
if (i == 9)
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
else
{
CallBandwidth = i;
sprintf(cmdReply, "CALLBW now %s", ARQBandwidths[CallBandwidth]);
SendReplyToHost(cmdReply);
}
}
goto cmddone;
}
if (strcmp(strCMD, "CAPTURE") == 0)
{
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %s", strCMD, CaptureDevice);
SendReplyToHost(cmdReply);
}
else
{
// Can't change on Teensy
#ifndef Teensy
strcpy(CaptureDevice, ptrParams);
#endif
sprintf(cmdReply, "%s now %s", strCMD, CaptureDevice);
SendReplyToHost(cmdReply);
}
goto cmddone;
}
if (strcmp(strCMD, "CAPTUREDEVICES") == 0)
{
sprintf(cmdReply, "%s %s", strCMD, CaptureDevices);
SendReplyToHost(cmdReply);
goto cmddone;
}
if (strcmp(strCMD, "CL") == 0) // For PTC Emulator
{
ClearDataToSend();
goto cmddone;
}
if (strcmp(strCMD, "CLOSE") == 0)
{
blnClosing = TRUE;
goto cmddone;
}
if (strcmp(strCMD, "CMDTRACE") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &CommandTrace);
goto cmddone;
}
if (strcmp(strCMD, "CODEC") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &blnCodecStarted);
if (strcmp(ptrParams, "TRUE") == 0)
StartCodec(strFault);
else if (strcmp(ptrParams, "FALSE") == 0)
StopCodec(strFault);
goto cmddone;
}
if (strcmp(strCMD, "CONSOLELOG") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %d", strCMD, ConsoleLogLevel);
SendReplyToHost(cmdReply);
}
else
{
i = atoi(ptrParams);
if (i >= LOGEMERGENCY && i <= LOGDEBUG)
{
ConsoleLogLevel = i;
sprintf(cmdReply, "%s now %d", strCMD, ConsoleLogLevel);
SendReplyToHost(cmdReply);
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
if (strcmp(strCMD, "CWID") == 0)
{
if (ptrParams == NULL)
{
if (wantCWID)
if (CWOnOff)
sprintf(cmdReply, "CWID ONOFF");
else
sprintf(cmdReply, "CWID TRUE");
else
sprintf(cmdReply, "CWID FALSE");
SendReplyToHost(cmdReply);
goto cmddone;
}
if (strcmp(ptrParams, "TRUE") == 0)
{
wantCWID = TRUE;
CWOnOff = FALSE;
}
else
if (strcmp(ptrParams, "FALSE") == 0)
wantCWID = FALSE;
else
if (strcmp(ptrParams, "ONOFF") == 0)
{
wantCWID = TRUE;
CWOnOff = TRUE;
}
else
{
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
goto cmddone;
}
if (wantCWID)
if (CWOnOff)
sprintf(cmdReply, "CWID now ONOFF");
else
sprintf(cmdReply, "CWID now TRUE");
else
sprintf(cmdReply, "CWID now FALSE");
SendReplyToHost(cmdReply);
goto cmddone;
}
if (strcmp(strCMD, "DATATOSEND") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %d", strCMD, bytDataToSendLength);
SendReplyToHost(cmdReply);
goto cmddone;
}
else
{
i = atoi(ptrParams);
if (i == 0)
{
bytDataToSendLength = 0;
sprintf(cmdReply, "%s now %d", strCMD, bytDataToSendLength);
SendReplyToHost(cmdReply);
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
if (strcmp(strCMD, "DATETIME") == 0)
{
#ifndef TEENSY
sprintf(strFault, "DATETIME not supported on this platform");
#else
// Set RTC to Date (DD MM YY HH MM SS format)
struct tm tm;
int n;
if (ptrParams == NULL || strlen(ptrParams) != 17)
{
sprintf(strFault, "Syntax Err: %s", cmdCopy);
goto cmddone;
}
n = sscanf(ptrParams, "%d %d %d %d %d %d",
&tm.tm_mday, &tm.tm_mon, &tm.tm_year,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec);
if (n != 6)
{
sprintf(strFault, "Syntax Err: %s", cmdCopy);
goto cmddone;
}
tm.tm_year += 100;
tm.tm_mon--;
RTC = mktime(&tm);
sprintf(cmdReply, "RTC set");
RTC -= 946684800; // Adjust to start from 1/1/2000
SendReplyToHost(cmdReply);
#endif
goto cmddone;
}
if (strcmp(strCMD, "DEBUGLOG") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &DebugLog);
goto cmddone;
}
if (strcmp(strCMD, "DISCONNECT") == 0)
{
if (ProtocolState == IDLE || ProtocolState == IRS || ProtocolState == ISS || ProtocolState == IRStoISS)
{
blnARQDisconnect = TRUE;
SendReplyToHost("DISCONNECT NOW TRUE");
}
else
SendReplyToHost("DISCONNECT IGNORED");
goto cmddone;
}
if (strcmp(strCMD, "DRIVELEVEL") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %d", strCMD, DriveLevel);
SendReplyToHost(cmdReply);
goto cmddone;
}
else
{
i = atoi(ptrParams);
if (i >= 0 && i <= 100)
{
DriveLevel = i;
sprintf(cmdReply, "%s now %d", strCMD, DriveLevel);
SendReplyToHost(cmdReply);
goto cmddone;
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
#ifdef TEENSY
if (strcmp(strCMD, "EEPROM") == 0)
{
if (ptrParams)
{
char * ptr, * context;
int Reg = 0, Val = 0;
ptr = strtok_s(ptrParams, ", ", &context);
if (ptr)
{
Reg = atoi(ptr);
ptr = strtok_s(NULL, ", ", &context);
if (ptr)
{
Val = atoi(ptr);
}
}
if (Reg == 0 || Reg == 12 || Reg > 14 || ptr == 0)
{
// Bad command
sprintf(strFault, "Syntax Err: %s", cmdCopy);
goto cmddone;
}
SaveEEPROM(Reg, Val);
}
// Display EEPROM Settings
sprintf(cmdReply, "01 TXDelay - Zero means use ADC %3d\n", GetEEPROM(1));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "02 Persistance %3d\n", GetEEPROM(2));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "03 Slottime (in 10 mS) %3d\n", GetEEPROM(3));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "04 TXTail %3d\n", GetEEPROM(4));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "05 Full Duplex - Not used %3d\n", GetEEPROM(5));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "06 Our Channel (Hex) %02x\n", GetEEPROM(6));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "07 I2C Address (0 = async) Hex %02x\n", GetEEPROM(7));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "08 Mode Speed %4d\n", GetEEPROM(8) * 100);
SendReplyToHost(cmdReply);
sprintf(cmdReply, "09 RX Level (Config) %3d\n", GetEEPROM(9));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "10 TX Level %3d\n", GetEEPROM(10));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "11 RX Level (Actual) %3d\n", GetEEPROM(11));
SendReplyToHost(cmdReply);
sprintf(cmdReply, "13 Centre Freq %4d\n", GetEEPROM(13) * 10);
SendReplyToHost(cmdReply);
sprintf(cmdReply, "14 TNC Mode %c\n", GetEEPROM(14));
SendReplyToHost(cmdReply);
goto cmddone;
}
#endif
if (strcmp(strCMD, "ENABLEPINGACK") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &EnablePingAck);
goto cmddone;
}
if (strcmp(strCMD, "FECID") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &FECId);
goto cmddone;
}
if (strcmp(strCMD, "FASTSTART") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &fastStart);
goto cmddone;
}
if (strcmp(strCMD, "FECMODE") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %s", strCMD, strFECMode);
SendReplyToHost(cmdReply);
}
else
{
for (i = 0; i < strAllDataModesLen; i++)
{
if (strcmp(ptrParams, strAllDataModes[i]) == 0)
{
strcpy(strFECMode, ptrParams);
intFECFramesSent = 0; // Force mode to be reevaluated
sprintf(cmdReply, "%s now %s", strCMD, strFECMode);
SendReplyToHost(cmdReply);
goto cmddone;
}
}
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
if (strcmp(strCMD, "FECREPEATS") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %d", strCMD, FECRepeats);
SendReplyToHost(cmdReply);
}
else
{
i = atoi(ptrParams);
if (i >= 0 && i <= 5)
{
FECRepeats = i;
sprintf(cmdReply, "%s now %d", strCMD, FECRepeats);
SendReplyToHost(cmdReply);
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
if (strcmp(strCMD, "FECSEND") == 0)
{
if (ptrParams == 0)
{
sprintf(strFault, "Syntax Err: %s", strCMD);
goto cmddone;
}
if (strcmp(ptrParams, "TRUE") == 0)
{
WriteDebugLog(LOGDEBUG, "FECRepeats %d", FECRepeats);
StartFEC(NULL, 0, strFECMode, FECRepeats, FECId);
SendReplyToHost("FECSEND now TRUE");
}
else if (strcmp(ptrParams, "FALSE") == 0)
{
blnAbort = TRUE;
SendReplyToHost("FECSEND now FALSE");
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
goto cmddone;
}
if (strcmp(strCMD, "FSKONLY") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &FSKOnly);
goto cmddone;
}
if (strcmp(strCMD, "GRIDSQUARE") == 0)
{
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %s", strCMD, GridSquare);
SendReplyToHost(cmdReply);
}
else
if (CheckGSSyntax(ptrParams))
{
strcpy(GridSquare, ptrParams);
sprintf(cmdReply, "%s now %s", strCMD, GridSquare);
SendReplyToHost(cmdReply);
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
goto cmddone;
}
if (strcmp(strCMD, "INITIALIZE") == 0)
{
blnInitializing = TRUE;
ClearDataToSend();
blnHostRDY = TRUE;
blnInitializing = FALSE;
SendReplyToHost("INITIALIZE");
goto cmddone;
}
if (strcmp(strCMD, "LEADER") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %d", strCMD, LeaderLength);
SendReplyToHost(cmdReply);
}
else
{
i = atoi(ptrParams);
if (i >= 120 && i <= 2500)
{
LeaderLength = (i + 9) /10;
LeaderLength *= 10; // round to 10 mS
sprintf(cmdReply, "%s now %d", strCMD, LeaderLength);
SendReplyToHost(cmdReply);
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
if (strcmp(strCMD, "LISTEN") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &blnListen);
if (blnListen)
ClearBusy();
goto cmddone;
}
if (strcmp(strCMD, "LOGLEVEL") == 0)
{
int i;
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %d", strCMD, FileLogLevel);
SendReplyToHost(cmdReply);
}
else
{
i = atoi(ptrParams);
if (i >= LOGEMERGENCY && i <= LOGDEBUG)
{
FileLogLevel = i;
sprintf(cmdReply, "%s now %d", strCMD, FileLogLevel);
SendReplyToHost(cmdReply);
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
if (strcmp(strCMD, "MONITOR") == 0)
{
DoTrueFalseCmd(strCMD, ptrParams, &Monitor);
goto cmddone;
}
if (strcmp(strCMD, "MYAUX") == 0)
{
int i, len;
char * ptr, * context;
if (ptrParams == 0)
{
len = sprintf(cmdReply, "%s", "MYAUX ");
for (i = 0; i < AuxCallsLength; i++)
{
len += sprintf(&cmdReply[len], "%s,", AuxCalls[i]);
}
cmdReply[len - 1] = 0; // remove trailing space or ,
SendReplyToHost(cmdReply);
goto cmddone;
}
ptr = strtok_s(ptrParams, ", ", &context);
AuxCallsLength = 0;
while (ptr && AuxCallsLength < 10)
{
if (CheckValidCallsignSyntax(ptr))
strcpy(AuxCalls[AuxCallsLength++], ptr);
ptr = strtok_s(NULL, ", ", &context);
}
len = sprintf(cmdReply, "%s", "MYAUX now ");
for (i = 0; i < AuxCallsLength; i++)
{
len += sprintf(&cmdReply[len], "%s,", AuxCalls[i]);
}
cmdReply[len - 1] = 0; // remove trailing space or ,
SendReplyToHost(cmdReply);
ConvertCallstoAX25();
goto cmddone;
}
if (strcmp(strCMD, "MYCALL") == 0)
{
if (ptrParams == 0)
{
sprintf(cmdReply, "%s %s", strCMD, Callsign);
SendReplyToHost(cmdReply);
}
else
{
if (CheckValidCallsignSyntax(ptrParams))
{
strcpy(Callsign, ptrParams);
sprintf(cmdReply, "%s now %s", strCMD, Callsign);
SendReplyToHost(cmdReply);
ConvertCallstoAX25();
}
else
sprintf(strFault, "Syntax Err: %s %s", strCMD, ptrParams);
}
goto cmddone;
}
// if (strcmp(strCMD, "NEGOTIATEBW") == 0)
// {
// DoTrueFalseCmd(strCMD, ptrParams, &NegotiateBW);
// goto cmddone;
// }
if (strcmp(strCMD, "PING") == 0)
{
if (ptrParams)
{
char * countp = strlop(ptrParams, ' ');
int count = 0;
if (countp)
count = atoi(countp);
if (CheckValidCallsignSyntax(ptrParams) && count > 0 && count < 16)
{
if (ProtocolState != DISC)
{
sprintf(strFault, "No PING from state %s", ARDOPStates[ProtocolState]);
goto cmddone;
}
else
{
SendReplyToHost(cmdCopy); // echo command back to host.
strcpy(ConnectToCall, _strupr(ptrParams));
PingCount = count;
NeedPing = TRUE; // request ping grom background
goto cmddone;
}
}
}
sprintf(strFault, "Syntax Err: %s", cmdCopy);
goto cmddone;
}
if (strcmp(strCMD, "PAC") == 0)
{
// Packet Mode Subcommands
//extern int pktNumCar;
//extern int pktDataLen;
//extern int pktRSLen;
//extern char pktMod[4][8];
//extern int pktMode;
if (ptrParams)
{
char * PacVal = strlop(ptrParams, ' ');
if (strcmp(ptrParams, "MODE") == 0)
{
int i;
if (PacVal == NULL)
{
sprintf(cmdReply, "PAC MODE %s", &pktMod[initMode][0]);
SendReplyToHost(cmdReply);
goto cmddone;
}
for (i = 0; i < pktModeLen; i++)
{
if (strcmp(PacVal, &pktMod[i][0]) == 0)
{
initMode = i;
sprintf(cmdReply, "PAC MODE now %s", PacVal);
SendReplyToHost(cmdReply);
goto cmddone;
}
}
sprintf(strFault, "Syntax Err: PAC MODE %s", PacVal);
goto cmddone;
}
if (strcmp(ptrParams, "RETRIES") == 0)
{
int i;
if (PacVal == NULL)
{
sprintf(cmdReply, "PAC RETRIES %d", PORTN2);