-
Notifications
You must be signed in to change notification settings - Fork 0
/
ARDOPC.c.bak
3215 lines (2489 loc) · 84.4 KB
/
ARDOPC.c.bak
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
// ARDOPC.cpp : Defines the entry point for the console application.
//
#ifdef WIN32
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_32BIT_TIME_T
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
#else
#include <unistd.h>
#define SOCKET int
#define closesocket close
#endif
#include "ARDOPC.h"
#include "getopt.h"
void CompressCallsign(char * Callsign, UCHAR * Compressed);
void CompressGridSquare(char * Square, UCHAR * Compressed);
void ASCIIto6Bit(char * Padded, UCHAR * Compressed);
void GetTwoToneLeaderWithSync(int intSymLen);
void SendID(BOOL blnEnableCWID);
void PollReceivedSamples();
void CheckTimers();
BOOL GetNextARQFrame();
BOOL TCPHostInit();
BOOL SerialHostInit();
BOOL KISSInit();
void SerialHostPoll();
void TCPHostPoll();
BOOL MainPoll();
VOID PacketStartTX();
void PlatformSleep();
BOOL BusyDetect2(float * dblMag, int intStart, int intStop);
BOOL IsPingToMe(char * strCallsign);
void LookforPacket(float * dblMag, float dblMagAvg, int count, float * real, float * imag);
void PktARDOPStartTX();
// Config parameters
char GridSquare[9] = "";
char Callsign[10] = "";
BOOL wantCWID = FALSE;
BOOL CWOnOff = FALSE;
BOOL NeedID = FALSE; // SENDID Command Flag
BOOL NeedCWID = FALSE; // SENDCWID Command Flag
BOOL NeedConReq = FALSE; // ARQCALL Command Flag
BOOL NeedPing = FALSE; // PING Command Flag
BOOL NeedTwoToneTest = FALSE;
enum _ARQBandwidth CallBandwidth = UNDEFINED;
BOOL UseKISS = TRUE; // Enable Packet (KISS) interface
int PingCount;
BOOL blnPINGrepeating = False;
BOOL blnFramePending = False; // Cancels last repeat
int intPINGRepeats = 0;
#ifdef TEENSY
int WaterfallActive = 0; // Waterfall display off
int SpectrumActive = 0; // Spectrum display off
#else
int WaterfallActive = 1; // Waterfall display on
int SpectrumActive = 0; // Spectrum display off
#endif
char ConnectToCall[16] = "";
#ifdef TEENSY
int LeaderLength = 500;
#else
int LeaderLength = 240;
#endif
int TrailerLength = 0;
unsigned int ARQTimeout = 120;
int TuningRange = 100;
int TXLevel = 300; // 300 mV p-p Used on Teensy
int RXLevel = 0; // Configured Level - zero means auto tune
int autoRXLevel = 1500; // calculated level
int ARQConReqRepeats = 5;
BOOL DebugLog = TRUE;
BOOL CommandTrace = TRUE;
int DriveLevel = 100;
char strFECMode[16] = "4FSK.500.100";
int FECRepeats = 0;
BOOL FECId = FALSE;
int Squelch = 5;
int BusyDet = 5;
enum _ARQBandwidth ARQBandwidth = B2000MAX;
char HostPort[80] = "";
int port = 8515;
int pktport = 0;
BOOL RadioControl = FALSE;
BOOL SlowCPU = FALSE;
BOOL AccumulateStats = TRUE;
BOOL Use600Modes = FALSE;
BOOL FSKOnly = FALSE;
BOOL fastStart = TRUE;
BOOL ConsoleLogLevel = LOGDEBUG;
BOOL FileLogLevel = LOGDEBUG;
BOOL EnablePingAck = TRUE;
BOOL gotGPIO = FALSE;
BOOL useGPIO = FALSE;
int pttGPIOPin = -1;
BOOL pttGPIOInvert = FALSE;
HANDLE hCATDevice = 0;
char CATPort[80] = ""; // Port for CAT.
int CATBAUD = 19200;
int EnableHostCATRX = FALSE; // Set when host sends RADIOHEX command
HANDLE hPTTDevice = 0;
char PTTPort[80] = ""; // Port for Hardware PTT - may be same as control port.
int PTTBAUD = 19200;
UCHAR PTTOnCmd[64];
UCHAR PTTOnCmdLen = 0;
UCHAR PTTOffCmd[64];
UCHAR PTTOffCmdLen = 0;
int PTTMode = PTTRTS; // PTT Control Flags.
// Stats
// Public Structure QualityStats
int int4FSKQuality;
int int4FSKQualityCnts;
int int8FSKQuality;
int int8FSKQualityCnts;
int int16FSKQuality;
int int16FSKQualityCnts;
int intFSKSymbolsDecoded;
int intPSKQuality[2];
int intPSKQualityCnts[2];
int intPSKSymbolsDecoded;
int intQAMQuality;
int intQAMQualityCnts;
int intQAMSymbolsDecoded;
int intGoodQAMSummationDecodes;
char stcLastPingstrSender[10];
char stcLastPingstrTarget[10];
int stcLastPingintRcvdSN;
int stcLastPingintQuality;
time_t stcLastPingdttTimeReceived;
BOOL blnInitializing = FALSE;
BOOL blnLastPTT = FALSE;
BOOL PlayComplete = FALSE;
BOOL blnBusyStatus;
BOOL newStatus;
unsigned int tmrSendTimeout;
int intCalcLeader; // the computed leader to use based on the reported Leader Length
int intRmtLeaderMeasure = 0;
int dttCodecStarted;
enum _ReceiveState State;
enum _ARDOPState ProtocolState;
const char ARDOPStates[8][9] = {"OFFLINE", "DISC", "ISS", "IRS", "IDLE", "IRStoISS", "FECSEND", "FECRCV"};
struct SEM Semaphore = {0, 0, 0, 0};
BOOL SoundIsPlaying = FALSE;
BOOL Capturing = TRUE;
int DecodeCompleteTime;
BOOL blnAbort = FALSE;
int intRepeatCount;
BOOL blnARQDisconnect = FALSE;
int dttLastPINGSent;
enum _ProtocolMode ProtocolMode = FEC;
extern BOOL blnEnbARQRpt;
extern BOOL blnDISCRepeating;
extern char strRemoteCallsign[10];
extern char strLocalCallsign[10];
extern char strFinalIDCallsign[10];
extern int dttTimeoutTrip;
extern unsigned int dttLastFECIDSent;
extern int intFrameRepeatInterval;
extern BOOL blnPending;
extern unsigned int tmrIRSPendingTimeout;
extern unsigned int tmrFinalID;
extern unsigned int tmrPollOBQueue;
int Encode4FSKControl(UCHAR bytFrameType, UCHAR bytSessionID, UCHAR * bytreturn);
void SendPING(char * strMycall, char * strTargetCall, int intRpt);
int intRepeatCnt;
extern SOCKET TCPControlSock, TCPDataSock, PktSock;
BOOL blnClosing = FALSE;
BOOL blnCodecStarted = FALSE;
unsigned int dttNextPlay = 0;
const UCHAR bytValidFrameTypesALL[]=
{0, 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,
35, 36, 41, 44, 45,
46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, PINGACK, PING,
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49, // 40 - 4F
0x4A,0x4B,0x4C,0x4D,
0x50,0x51,0x52,0x53,0x54,0x55, // 50 - 5F
0x60,0x61,0x62,0x63,0x64,0x65, // 60 - 6F
0x70,0x71,0x72,0x73,0x74,0x75,0x7A,0x7B,0x7C,0x7D, // 70 - 7F
PktFrameHeader, 208, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
124, 125, 208, 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};
const UCHAR bytValidFrameTypesISS[]= // ACKs, NAKs, END, DISC, BREAK
{
//NAK
0, 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,
// BREAK, DISC, or END
BREAK, DISCFRAME, END, ConRejBusy, ConRejBW,
// Con req and Con ACK
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
//ACK
PktFrameHeader, 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};
const UCHAR * bytValidFrameTypes;
int bytValidFrameTypesLengthISS = sizeof(bytValidFrameTypesISS);
int bytValidFrameTypesLengthALL = sizeof(bytValidFrameTypesALL);
int bytValidFrameTypesLength;
/*
const UCHAR isValidFrame[256]=
{
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 00 - 0F ACK and NAK
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 10 - 1F
0,0,0,1,1,0,0,0,0,1,0,0,1,1,1,0, // BREAK=23, IDLE=24, DISC=29, END=2C, ConRejBusy=2D, ConRejBW=2E
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, // 30 - 3F (3d PING Ack 3E Ping
1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, // 40 - 4F
1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0, // 50 - 5F
1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0, // 60 - 6F
1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0, // 70 - 7F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 80 - 8F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 90 - 9F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // A0 - AF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // B0 - BF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // C0 - CF
// experimental SOUNDINGs D0
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // D0 - DF
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // e0 - eF ACK and NAK
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 // f0 - ff
};
*/
BOOL blnTimeoutTriggered = FALSE;
// We can't keep the audio samples for retry, but we can keep the
// encoded data
unsigned char bytEncodedBytes[1800] =""; // I think the biggest is 600 bd 768 + overhead
int EncLen;
extern UCHAR bytSessionID;
int intLastRcvdFrameQuality;
int intAmp = 26000; // Selected to have some margin in calculations with 16 bit values (< 32767) this must apply to all filters as well.
const char strAllDataModes[18][15] =
{"4FSK.200.50S", "4PSK.200.100S",
"4PSK.200.100", "8PSK.200.100", "16QAM.200.100",
"4FSK.500.100S", "4FSK.500.100",
"4PSK.500.100", "8PSK.500.100", "16QAM.500.100",
"4PSK.1000.100", "8PSK.1000.100", "16QAM.1000.100",
"4PSK.2000.100", "8PSK.2000.100", "16QAM.2000.100",
"4FSK.2000.600", "4FSK.2000.600S"};
int strAllDataModesLen = 18;
// Frame Speed By Type (from Rick's spreadsheet)
const short Rate[256] =
{
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00 - 0F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 10 - 1F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 20 - 2F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 30 - 3F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 40 - 4F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 50 - 5F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 60 - 6F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 70 - 7F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 80 - 8F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 90 - 9F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // a0 - AF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // b0 - BF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // c0 - CF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // d0 - DF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // e0 - EF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // f0 - FF
const short FrameSize[256] =
{
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00 - 0F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 10 - 1F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 20 - 2F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 30 - 3F
64,64,16,16,108,108,128,128,16,16,64,64,32,32,0,0, // 40 - 4F
128,128,216,216,256,256,0,0,0,0,0,0,0,0,0,0, // 50 - 5F
256,256,432,432,512,512,0,0,0,0,0,0,0,0,0,0, // 60 - 6F
512,512,864,864,1024,1024,0,0,0,0,600,600,200,200,0,0, // 70 - 7F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 80 - 8F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 90 - 9F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // a0 - AF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // b0 - BF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // c0 - CF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // d0 - DF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // e0 - EF
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // f0 - FF
const char strFrameType[256][18] = {
"DataNAK", // Range 0x00 to 0x1F includes 5 bits for quality 1 Car, 200Hz,4FSK
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","",
//Short Control Frames 1 Car, 200Hz,4FSK ' Reassigned May 22, 2015 for maximum "distance"
"BREAK", "IDLE", "",
"", "", "",
"DISC", "", "",
"END",
"ConRejBusy",
"ConRejBW",
"",
//Special frames 1 Car, 200Hz,4FSK 0x30 +
"IDFrame",
"ConReq200M",
"ConReq500M",
"ConReq1000M",
"ConReq2000M",
"ConReq200F",
"ConReq500F",
"ConReq1000F",
"ConReq2000F",
"ConAck200",
"ConAck500",
"ConAck1000",
"ConAck2000",
"PingAck",
"Ping",
"",
// 200 Hz Bandwidth Data
// 1 Car PSK Data Modes 200 HzBW 100 baud
"4PSK.200.100.E", // 0x40
"4PSK.200.100.O",
"4PSK.200.100S.E",
"4PSK.200.100S.O",
"8PSK.200.100.E",
"8PSK.200.100.O",
// 1 Car 16QAM Data mode 200 Hz BW, 100 baud
"16QAM.200.100.E", // 46
"16QAM.200.100.O", // 47
// 1 Car 4FSK Data mode 200 HzBW, 50 baud
//"4FSK.200.50.E",
//"4FSK.200.50.O",
"4FSK.200.50S.E", // 48
"4FSK.200.50S.O",
"4FSK.500.100.E",
"4FSK.500.100.O",
"4FSK.500.100S.E",
"4FSK.500.100S.O",
"",//"8FSK.200.25.E",
"",//"8FSK.200.25.O",
//' 2 Car PSK Data Modes 100 baud
"4PSK.500.100.E", // 50
"4PSK.500.100.O",
"8PSK.500.100.E",
"8PSK.500.100.O",
// 2 Car Data modes 16 QAM baud
"16QAM.500.100.E", //54
"16QAM.500.100.O",
"", "", // 56, 57 were 500 167 modes
// 1 Car 16FSK mode 25 baud
// "16FSK.500.25.E", // 58
// "16FSK.500.25.O",
// "16FSK.500.25S.E",
// "16FSK.500.25S.O",
"","","","", // 58 -5B
"","","","", // 5C-5F
//1 Khz Bandwidth Data Modes
// 4 Car 100 baud PSK
"4PSK.1000.100.E", //60
"4PSK.1000.100.O",
"8PSK.1000.100.E",
"8PSK.1000.100.O",
// 4 car 167 baud PSK
"16QAM.1000.100.E",
"16QAM.1000.100.O",
"",
"",
// 2 Car 4FSK 100 baud
"", //68
"","","","","","","",
// 2Khz Bandwidth Data Modes
// 8 Car 100 baud PSK
"4PSK.2000.100.E", //70
"4PSK.2000.100.O",
"8PSK.2000.100.E",
"8PSK.2000.100.O",
// 8 Car 167 baud PSK
"16QAM.2000.100.E",
"16QAM.2000.100.O", // 75
"","","","", // 79=79
// 1 Car 4FSK 600 baud (FM only)
"4FSK.2000.600.E", // Experimental //7A
"4FSK.2000.600.O", // Experimental
"4FSK.2000.600S.E", // Experimental
"4FSK.2000.600S.O", // Experimental //7D
"","", // 7e-7f
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"PktHddr","PktData","","","","","","","","","","","","","","", //C0
//Frame Types 0xA0 to 0xDF reserved for experimentation
"SOUND2K" //D0
"","","","","","","","","","","","","","","","",
//Data ACK 1 Car, 200Hz,4FSK
"DataACK" // Range 0xE0 to 0xFF includes 5 bits for quality
};
const char shortFrameType[256][12] = {
"DataNAK", // Range 0x00 to 0x1F includes 5 bits for quality 1 Car, 200Hz,4F
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","",
//Short Control Frames 1 Car, 200Hz,4F ' Reassigned May 22, 2015 for maximum "distance"
"BREAK", "IDLE", "",
"", "", "",
"DISC", "", "",
"END",
"ConRejBusy",
"ConRejBW",
"",
//Special frames 1 Car, 200Hz,4F 0x30 +
"IDFrame",
"ConReq200M",
"ConReq500M",
"ConReq1KM",
"ConReq2KM",
"ConReq200F",
"ConReq500F",
"ConReq1KF",
"ConReq2KF",
"ConAck200",
"ConAck500",
"ConAck1K",
"ConAck2K",
// Types 0x3D to 0x3F reserved
"PingAck","Ping","",
// 200 Hz Bandwidth Data
// 1 Car P Data Modes 200 HzBW 100 baud
"4P.200.100", // 0x40
"4P.200.100",
"4P.200.100S",
"4P.200.100S",
"8P.200.100",
"8P.200.100",
// 1 Car 16QAM Data mode 200 Hz BW, 100 baud
"16Q.200.100", // 46
"16Q.200.100", // 47
"4F.200.50S", // 48
"4F.200.50S",
"4F.500.100",
"4F.500.100",
"4F.500.100S",
"4F.500.100S",
"",
"",
//' 2 Car P Data Modes 100 baud
"4P.500.100", // 50
"4P.500.100",
"8P.500.100",
"8P.500.100",
// 2 Car Data modes 16 Q baud
"16Q.500.100", //54
"16Q.500.100",
"", "", // 56, 57 were 500 167 modes
"", // 58
"",
"",
"",
"", // 5C
"", // 5D
"","", // 5E/F
//1 Khz Bandwidth Data Modes
// 4 Car 100 baud P
"4P.1K.100", //60
"4P.1K.100",
"8P.1K.100",
"8P.1K.100",
// 4 car 167 baud P
"16Q.1K.100",
"16Q.1K.100",
"8",
"8",
// 2 Car 4F 100 baud
"", //68
"","","","","","","",
// 2Khz Bandwidth Data Modes
// 8 Car 100 baud P
"4P.2K.100", //70
"4P.2K.100",
"8P.2K.100",
"8P.2K.100",
// 8 Car 167 baud P
"16Q.2K.100",
"16Q.2K.100",
"",
"",
// 4 Car 4F 100 baud
"",
"",
// 1 Car 4F 600 baud (FM only)
"4F.2K.600", // Experimental
"4F.2K.600", // Experimental
"4F.2K.600S", // Experimental
"4F.2K.600S", // Experimental //7d
"","", // 7e-7f
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","",
"PktHDDR","PktData","","","","","","","","","","","","","","", //C0
//Frame Types 0xA0 to 0xDF reserved for experimentation
"SOUND2K" //D0
"","","","","","","","","","","","","","","","",
//Data ACK 1 Car, 200Hz,4F
"DataACK" // Range 0xE0 to 0xFF includes 5 bits for quality
};
char * strlop(char * buf, char delim)
{
// Terminate buf at delim, and return rest of string
char * ptr = strchr(buf, delim);
if (ptr == NULL) return NULL;
*(ptr)++=0;
return ptr;
}
#ifdef WIN32
float round(float x)
{
return floorf(x + 0.5f);
}
#endif
void GetSemaphore()
{
}
void FreeSemaphore()
{
}
BOOL CheckValidCallsignSyntax(char * strCallsign)
{
// Function for checking valid call sign syntax
char * Dash = strchr(strCallsign, '-');
int callLen = strlen(strCallsign);
char * ptr = strCallsign;
int SSID;
if (Dash)
{
callLen = Dash - strCallsign;
SSID = atoi(Dash + 1);
if (SSID > 15)
return FALSE;
if (strlen(Dash + 1) > 2)
return FALSE;
if (!isalnum(*(Dash + 1)))
return FALSE;
}
if (callLen > 7 || callLen < 3)
return FALSE;
while (callLen--)
{
if (!isalnum(*(ptr++)))
return FALSE;
}
return TRUE;
}
// Function to check for proper syntax of a 4, 6 or 8 character GS
BOOL CheckGSSyntax(char * GS)
{
int Len = strlen(GS);
if (!(Len == 4 || Len == 6 || Len == 8))
return FALSE;
if (!isalpha(GS[0]) || !isalpha(GS[1]))
return FALSE;
if (!isdigit(GS[2]) || !isdigit(GS[3]))
return FALSE;
if (Len == 4)
return TRUE;
if (!isalpha(GS[4]) || !isalpha(GS[5]))
return FALSE;
if (Len == 6)
return TRUE;
if (!isdigit(GS[6]) || !isdigit(GS[7]))
return FALSE;
return TRUE;
}
// Function polled by Main polling loop to see if time to play next wave stream
BOOL GetNextFrame()
{
// returning TRUE sets frame pending in Main
if (ProtocolMode == FEC || ProtocolState == FECSend)
{
if (ProtocolState == FECSend || ProtocolState == FECRcv || ProtocolState == DISC)
return GetNextFECFrame();
else
return FALSE;
}
if (ProtocolMode == ARQ)
// if (ARQState == None)
// return FALSE;
// else
return GetNextARQFrame();
return FALSE;
}
#ifdef WIN32
extern LARGE_INTEGER Frequency;
extern LARGE_INTEGER StartTicks;
extern LARGE_INTEGER NewTicks;
#endif
extern int NErrors;
void testRS()
{
// feed random data into RS to check robustness
BOOL blnRSOK, FrameOK;
char bytRawData[256];
int DataLen = 128;
int intRSLen = 64;
int i;
for (i = 0; i < DataLen; i++)
{
bytRawData[i] = rand() % 256;
}
FrameOK = RSDecode(bytRawData, DataLen, intRSLen, &blnRSOK);
}
void ardopmain()
{
blnTimeoutTriggered = FALSE;
SetARDOPProtocolState(DISC);
InitSound();
if (SerialMode)
SerialHostInit();
else
TCPHostInit();
if (UseKISS)
{
KISSInit();
#ifdef USE_SOUNDMODEM
afskInit();
#endif
}
// while (1)
// testRS();
tmrPollOBQueue = Now + 10000;
ProtocolMode = ARQ;
while(!blnClosing)
{
PollReceivedSamples();
CheckTimers();
if (SerialMode)
SerialHostPoll();
else
TCPHostPoll();
MainPoll();
PlatformSleep();
}
if (!SerialMode)
{
closesocket(TCPControlSock);
closesocket(TCPDataSock);
closesocket(PktSock);
}
return;
}
void SendCWID(char * Callsign, BOOL x)
{
}
// Subroutine to generate 1 symbol of leader
// returns pointer to Frame Type Name
const char * Name(UCHAR bytID)
{
if (bytID < 0x20)
return strFrameType[0];
else if (bytID >= 0xE0)
return strFrameType[0xE0];
else
return strFrameType[bytID];
}
// returns pointer to Frame Type Name
const char * shortName(UCHAR bytID)
{
if (bytID < 0x20)
return shortFrameType[0];
else if (bytID >= 0xE0)
return shortFrameType[0xE0];
else
return shortFrameType[bytID];
}
// Function to look up frame info from bytFrameType
BOOL FrameInfo(UCHAR bytFrameType, int * blnOdd, int * intNumCar, char * strMod,
int * intBaud, int * intDataLen, int * intRSLen, UCHAR * bytQualThres, char * strType)
{
//Used to "lookup" all parameters by frame Type.
// returns TRUE if all fields updated otherwise FALSE (improper bytFrameType)
// 1 Carrier 4FSK control frames
if ((bytFrameType >= 0 && bytFrameType <= 0x1F) || bytFrameType >= 0xE0)
{
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 0;
*intRSLen = 0;
strcpy(strMod, "4FSK");
*intBaud = 50;
*bytQualThres = 40;
}
else
{
switch(bytFrameType)
{
case 0x23:
case 0x24:
case 0x29:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 0;
*intRSLen = 0;
strcpy(strMod, "4FSK");
*intBaud = 50;
*bytQualThres = 60;
break;
case 0x2C:
case 0x2D:
case 0x2E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 0;
*intRSLen = 0;
strcpy(strMod, "4FSK");
*intBaud = 50;
*bytQualThres = 60;
break;
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x3E: // Ping
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 12;
*intRSLen = 4; // changed 0.8.0
strcpy(strMod, "4FSK");
*intBaud = 50;
*bytQualThres = 50;
break;
case 0x39:
case 0x3A:
case 0x3B:
case 0x3C:
case 0x3D:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 3;
*intRSLen = 0;
strcpy(strMod, "4FSK");
*intBaud = 50;
*bytQualThres = 50;
break;
case 0xe0:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 0;
*intRSLen = 0;
strcpy(strMod, "4FSK");
*intBaud = 50;
*bytQualThres = 60;
break;
// 1 Carrier Data modes
// 100 baud PSK (200 baud not compatible with 200 Hz bandwidth) (Note 1 carrier modes Qual Threshold reduced to 30 (was 50) for testing April 20, 2015
case 0x40:
case 0x41:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 64;
*intRSLen = 32;
strcpy(strMod, "4PSK");
*intBaud = 100;
*bytQualThres = 30;
break;
case 0x42:
case 0x43:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 16;
*intRSLen = 8;
strcpy(strMod, "4PSK");
*intBaud = 100;
*bytQualThres = 30;
break;
case 0x44:
case 0x45:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 108;
*intRSLen = 36;
strcpy(strMod, "8PSK");
*intBaud = 100;
*bytQualThres = 30;
break;
case 0x46:
case 0x47:
// 100 baud 16QAM
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 128;
*intRSLen = 64;
strcpy(strMod, "16QAM");
*intBaud = 100;
*bytQualThres = 30;
break;
case 0x48:
case 0x49:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 16;
*intRSLen = 4;
strcpy(strMod, "4FSK");
*intBaud = 50;
*bytQualThres = 30;
break;
case 0x4A:
case 0x4B:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 64;
*intRSLen = 16;
strcpy(strMod, "4FSK");
*intBaud = 100;
*bytQualThres = 30;