-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathARDOPC.c
More file actions
1880 lines (1473 loc) · 46.3 KB
/
Copy pathARDOPC.c
File metadata and controls
1880 lines (1473 loc) · 46.3 KB
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
#ifdef WIN32
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
#else
#define SOCKET int
#include <unistd.h>
#define closesocket close
#endif
//#include "Version.h"
#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(int mS);
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] = "No GS ";
char Callsign[10] = "";
BOOL wantCWID = FALSE;
BOOL NeedID = FALSE; // SENDID Command Flag
BOOL NeedCWID = FALSE;
BOOL NeedConReq = FALSE; // ARQCALL Command Flag
BOOL NeedPing = FALSE; // PING Command Flag
BOOL NeedCQ = FALSE; // PING Command Flag
BOOL NeedTwoToneTest = FALSE;
BOOL UseKISS = TRUE; // Enable Packet (KISS) interface
int PingCount;
int CQCount;
BOOL blnPINGrepeating = False;
BOOL blnFramePending = False; // Cancels last repeat
int intPINGRepeats = 0;
char ConnectToCall[16] = "";
#ifdef TEENSY
int LeaderLength = 500;
#else
int LeaderLength = 300;
#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] = "OFDM.500.55";
int FECRepeats = 0;
BOOL FECId = FALSE;
int Squelch = 5;
enum _ARQBandwidth ARQBandwidth = XB500;
BOOL NegotiateBW = TRUE;
char HostPort[80] = "";
int port = 8515;
int pktport = 0;
BOOL RadioControl = FALSE;
BOOL SlowCPU = FALSE;
BOOL AccumulateStats = TRUE;
BOOL Use600Modes = FALSE;
BOOL EnableOFDM = TRUE;
BOOL UseOFDM = TRUE;
BOOL FSKOnly = FALSE;
BOOL fastStart = TRUE;
BOOL ConsoleLogLevel = LOGDEBUG;
BOOL FileLogLevel = LOGDEBUG;
BOOL EnablePingAck = TRUE;
// Stats
// Public Structure QualityStats
int SessBytesSent;
int SessBytesReceived;
int int4FSKQuality;
int int4FSKQualityCnts;
int int8FSKQuality;
int int8FSKQualityCnts;
int int16FSKQuality;
int int16FSKQualityCnts;
int intFSKSymbolsDecoded;
int intPSKQuality[2];
int intPSKQualityCnts[2];
int intOFDMQuality[8];
int intOFDMQualityCnts[8];
int intPSKSymbolsDecoded;
int intOFDMSymbolsDecoded;
int intQAMQuality;
int intQAMQualityCnts;
int intQAMSymbolsDecoded;
int intGoodQAMSummationDecodes;
int intLeaderDetects;
int intLeaderSyncs;
int intAccumLeaderTracking;
float dblFSKTuningSNAvg;
int intGoodFSKFrameTypes;
int intFailedFSKFrameTypes;
int intAccumFSKTracking;
int intFSKSymbolCnt;
int intGoodFSKFrameDataDecodes;
int intFailedFSKFrameDataDecodes;
int intAvgFSKQuality;
int intFrameSyncs;
int intGoodPSKSummationDecodes;
int intGoodFSKSummationDecodes;
int intGoodQAMSummationDecodes;
int intGoodOFDMSummationDecodes;
float dblLeaderSNAvg;
int intAccumPSKLeaderTracking;
float dblAvgPSKRefErr;
int intPSKTrackAttempts;
int intAccumPSKTracking;
int intQAMTrackAttempts;
int intOFDMTrackAttempts;
int intAccumQAMTracking;
int intAccumOFDMTracking;
int intPSKSymbolCnt;
int intQAMSymbolCnt;
int intOFDMSymbolCnt;
int intGoodPSKFrameDataDecodes;
int intFailedPSKFrameDataDecodes;
int intGoodQAMFrameDataDecodes;
int intFailedQAMFrameDataDecodes;
int intAvgPSKQuality;
int intGoodOFDMFrameDataDecodes;
int intFailedOFDMFrameDataDecodes;
int intAvgOFDMQuality;
float dblAvgDecodeDistance;
int intDecodeDistanceCount;
int intShiftUPs;
int intShiftDNs;
unsigned int dttStartSession;
int intLinkTurnovers;
int intEnvelopeCors;
float dblAvgCorMaxToMaxProduct;
int intConReqSN;
int intConReqQuality;
int intTimeouts;
char stcLastPingstrSender[10];
char stcLastPingstrTarget[10];
int stcLastPingintRcvdSN;
int stcLastPingintQuality;
time_t stcLastPingdttTimeReceived;
BOOL blnInitializing = FALSE;
BOOL blnLastPTT = FALSE;
BOOL PlayComplete = FALSE;
BOOL blnBusyStatus = 0;
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"};
const char ARDOPModes[3][6] = {"Undef", "FEC", "ARQ"};
struct SEM Semaphore = {0, 0, 0, 0};
int DecodeCompleteTime;
BOOL blnAbort = FALSE;
int intRepeatCount;
BOOL blnARQDisconnect = FALSE;
int dttLastPINGSent;
enum _ProtocolMode ProtocolMode = FEC;
extern int intTimeouts;
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 BOOL blnPending;
extern unsigned int tmrIRSPendingTimeout;
extern unsigned int tmrFinalID;
extern unsigned int tmrPollOBQueue;
VOID EncodeAndSend4FSKControl(UCHAR bytFrameType, UCHAR bytSessionID, int LeaderLength);
void SendPING(char * strMycall, char * strTargetCall, int intRpt);
void SendCQ(int intRpt);
int intRepeatCnt;
BOOL blnClosing = FALSE;
BOOL blnCodecStarted = FALSE;
unsigned int dttNextPlay = 0;
const UCHAR bytValidFrameTypesALL[]=
{
DataNAK,
DataNAKLoQ,
ConRejBusy,
ConRejBW,
ConAck,
DISCFRAME,
BREAK,
END,
IDLEFRAME,
ConReq200,
ConReq500,
ConReq2500,
OConReq500,
OConReq2500,
IDFRAME,
PINGACK,
PING,
CQ_de,
D4PSK_200_50_E,
D4PSK_200_50_O,
D4PSK_200_100_E,
D4PSK_200_100_O,
D16QAM_200_100_E,
D16QAM_200_100_O,
D4FSK_500_50_E,
D4FSK_500_50_O,
D4PSK_500_50_E,
D4PSK_500_50_O,
D4PSK_500_100_E,
D4PSK_500_100_O,
D16QAMR_500_100_E,
D16QAMR_500_100_O,
D16QAM_500_100_E,
D16QAM_500_100_O,
DOFDM_200_55_E,
DOFDM_200_55_O,
DOFDM_500_55_E,
DOFDM_500_55_O,
D4FSK_1000_50_E,
D4FSK_1000_50_O,
D4PSKR_2500_50_E,
D4PSKR_2500_50_O,
D4PSK_2500_50_E,
D4PSK_2500_50_O,
D4PSK_2500_100_E,
D4PSK_2500_100_O,
D16QAMR_2500_100_E,
D16QAMR_2500_100_O,
D16QAM_2500_100_E,
D16QAM_2500_100_O,
DOFDM_2500_55_E,
DOFDM_2500_55_O,
PktFrameHeader, // Variable length frame Header
PktFrameData, // Variable length frame Data (Virtual Frsme Type)
OFDMACK,
DataACK,
DataACKHiQ};
const UCHAR bytValidFrameTypesISS[]= // ACKs, NAKs, END, DISC, BREAK
{
DataNAK,
DataNAKLoQ,
ConRejBusy,
ConRejBW,
ConAck,
DISCFRAME,
END,
IDFRAME,
PktFrameHeader, // Variable length frame Header
PktFrameData, // Variable length frame Data (Virtual Frsme Type)
OFDMACK,
DataACK,
DataACKHiQ};
const UCHAR * bytValidFrameTypes;
int bytValidFrameTypesLengthISS = sizeof(bytValidFrameTypesISS);
int bytValidFrameTypesLengthALL = sizeof(bytValidFrameTypesALL);
int bytValidFrameTypesLength;
BOOL blnTimeoutTriggered = FALSE;
// We can't keep the audio samples for retry, but we can keep the
// encoded data
unsigned char bytEncodedBytes[4500] =""; // OFDM is big (maybe not 4500)
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][16] =
{"4PSK.200.50", "4PSK.200.100",
"16QAM.200.100", "4FSK.500.50",
"4PSK.500.50", "4PSK.500.100",
"OFDM.200.55", "OFDM.500.55",
"16QAMR.500.100", "16QAM.500.100",
"4FSK.1000.50",
"4PSKR.2500.50", "4PSK.2500.50",
"4PSK.2500.100",
"16QAMR.2500.100", "16QAM.2500.100", "OFDM.2500.55"};
int strAllDataModesLen = 18;
// Frame Speed By Type (from Rick's spreadsheet) Bytes per minute
const short Rate[64] =
{
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00 - 0F
402,402,826,826,1674,1674,0,0,0,0,402,402,857,857,1674,1674, // 10 - 1F
1674,1674,3349,3359,0,0,0,0,857,857,2143,2143,4286,4286,8372,8372, // 20 - 2F
8372,8372,16744,16744,0,0,0,0,0,0,0,0,0,0,0,0, // 30 - 3F
};
const short FrameSize[64] =
{
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00 - 0F
32,32,64,64,120,120,0,0,0,0,32,32,64,64,128,128, // 10 - 1F
120,120,240,240,360,360,720,720,64,64,160,160,320,320,640,640, // 20 - 2F
600,600,1200,1200,680,680,1360,1360,0,0,0,0,0,0,0,0, // 30 - 3F
};
const char strFrameType[64][18] =
{
// Short Control Frames 1 Car, 500Hz,4FSK, 50 baud
"DataNAK", // 0
"DataNAKLoQ",
"ConRejBusy",
"ConRejBW",
"ConAck", // 4
"DISC",
"BREAK",
"END",
"IDLE", // 8
"ConReq200",
"ConReq500",
"ConReq2500",
"IDFrame", // C
"PingAck",
"Ping", // E
"CQ_de", // F
// 200 Hz Bandwidth
// 1 Car modes
"4PSK.200.50.E", // 0x10
"4PSK.200.50.O",
"4PSK.200.100.E",
"4PSK.200.100.O",
"16QAM.200.100.E", // 0x14
"16QAM.200.100.O",
"", "",// 0x16 to 0x17
"OConReq500", "OConReq2500",
// 500 Hz bandwidth Data
// 1 Car 4FSK Data mode 500 Hz, 50 baud tones spaced @ 100 Hz
"4FSK.500.50.E", // 0x1A
"4FSK.500.50.O",
// 2 Car PSK Data Modes
"4PSK.500.50.E",
"4PSK.500.50.O",
"4PSK.500.100.E", // 0x1E
"4PSK.500.100.O",
// 2 Car 16QAM Data Modes 100 baud
"16QAMR.500.100.E", // 0x20
"16QAMR.500.100.O",
// 2 Car 16QAM Data Modes 100 baud
"16QAM.500.100.E", // 0x22
"16QAM.500.100.O",
"OFDM.500.55.E",
"OFDM.500.55.O",
"OFDM.200.55.E",
"OFDM.200.55.O",
// 1 Khz Bandwidth Data Modes
// 4 Car 4FSK Data mode 1000 Hz, 50 baud tones spaced @ 100 Hz
"4FSK.1000.50.E", // 0x28
"4FSK.1000.50.O",
// 2500 dblOffsetHz bandwidth modes
// 10 Car PSK Data Modes 50 baud
"4PSKR.2500.50.E", // 0x2A
"4PSKR.2500.50.O",
"4PSK.2500.50.E",
"4PSK.2500.50.O",
// 10 Car PSK Data Modes 100 baud
"4PSK.2500.100.E", // 0x2E
"4PSK.2500.100.O",
// 10 Car 16QAM Data modes 100 baud
"16QAMR.2500.100.E", // 0x30
"16QAMR.2500.100.O",
"16QAM.2500.100.E", // 0x32
"16QAM.2500.100.O",
"OFDM.2500.55.E",
"OFDM.2500.55.O",
"",
"",
"", "", // 0x38 to 0x39
"PktFrameHeader", //3A
"PktFrameData",
"", // 0x3C
"OFDMACK",
"DataACK", // note special coding to have large distance from NAKs
"DataACKHiQ" // note special coding to have large distance from NAKs
};
const char shortFrameType[64][12] =
{
// Short Control Frames 1 Car, 500Hz,4FSK, 50 baud
// Used on OLED display
"DataNAK", // 0
"DataNAKLoQ",
"ConRejBusy",
"ConRejBW",
"ConAck", // 4
"DISC",
"BREAK",
"END",
"IDLE", // 8
"ConReq200",
"ConReq500",
"ConReq2500",
"IDFrame", // C
"PingAck",
"Ping", // E
"CQ_de", // F
// 200 Hz Bandwidth
// 1 Car modes
"4P.200.50", // 0x10
"4P.200.50",
"4P.200.100",
"4PS.200.100",
"16Q.200.100", // 0x14
"16Q.200.100",
"", "",// 0x16 to 0x17
"OConReq500", "OConReq2500",
// 500 Hz bandwidth Data
// 1 Car 4FSK Data mode 500 Hz, 50 baud tones spaced @ 100 Hz
"4F.500.50", // 0x1A
"4F.500.50",
// 2 Car PSK Data Modes
"4P.500.50",
"4P.500.50",
"4P.500.100", // 0x1E
"4P.500.100",
// 2 Car 16QAM Data Modes 100 baud
"16QR.500.100", // 0x20
"16QR.500.100",
// 2 Car 16QAM Data Modes 100 baud
"16Q.500.100", // 0x22
"16Q.500.100",
"OFDM.500",
"OFDM.500",
"OFDM.200",
"OFDM.200",
// 1 Khz Bandwidth Data Modes
// 4 Car 4FSK Data mode 1000 Hz, 50 baud tones spaced @ 100 Hz
"4F.1K.50", // 0x28
"4F.1K.50",
// 2500 dblOffsetHz bandwidth modes
// 10 Car PSK Data Modes 50 baud
"4PR.2500.50", // 0x2A
"4PR.2500.50",
"4P.2500.50",
"4P.2500.50",
// 10 Car PSK Data Modes 100 baud
"4P.2500.100", // 0x2E
"4P.2500.100",
// 10 Car 16QAM Data modes 100 baud
"QR.2500.100", // 0x30
"QR.2500.100",
"Q.2500.100", // 0x32
"Q.2500.100",
"OFDM.2500",
"OFDM.2500",
"",
"",
"", "", // 0x38 to 0x39
"PktHeader", //3A
"PktData",
"", // 0x3C
"OFDMACK",
"DataACK", // note special coding to have large distance from NAKs
"DataACKHiQ" // note special coding to have large distance from NAKs
};
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
#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 SendCWID(char * Callsign, BOOL x)
{
}
// Subroutine to generate 1 symbol of leader
// returns pointer to Frame Type Name
const char * Name(UCHAR bytID)
{
return strFrameType[bytID];
}
// returns pointer to Frame Type Name
const char * shortName(UCHAR bytID)
{
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
switch(bytFrameType)
{
case DataNAK:
case DataNAKLoQ:
case DataACK:
case DataACKHiQ:
case ConAck:
case ConRejBW:
case ConRejBusy:
case IDLEFRAME:
case DISCFRAME:
case BREAK:
case END:
*blnOdd = 0;
*intNumCar = 1;
*intDataLen = 0;
*intRSLen = 0;
strcpy(strMod, "4FSK");
*intBaud = 50;
break;
case IDFRAME:
case PING:
case CQ_de:
*blnOdd = 0;
*intNumCar = 1;
*intDataLen = 12;
*intRSLen = 4; // changed 0.8.0
strcpy(strMod, "4FSK");
*intBaud = 50;
break;
case PINGACK:
*blnOdd = 0;
*intNumCar = 1;
*intDataLen = 3;
*intRSLen = 0;
strcpy(strMod, "4FSK");
*intBaud = 50;
break;
case ConReq200:
case ConReq500:
case ConReq2500:
case OConReq500:
case OConReq2500:
*blnOdd = 0;
*intNumCar = 1;
*intDataLen = 6;
*intRSLen = 2;
strcpy(strMod, "4FSK");
*intBaud = 50;
break;
case OFDMACK:
*blnOdd = 0;
*intNumCar = 1;
*intDataLen = 6;
*intRSLen = 4;
strcpy(strMod, "4FSK");
*intBaud = 100;
break;
case PktFrameHeader:
// Special Variable Length frame
// This defines the header, 4PSK.500.100. Length is 6 bytes
// Once we have that we receive the rest of the packet in the
// mode defined in the header.
// Header is 4 bits Type 12 Bits Len 2 bytes CRC 2 bytes RS
*blnOdd = 0;
*intNumCar = 1;
*intDataLen = 2;
*intRSLen = 2;
strcpy(strMod, "4FSK");
*intBaud = 100;
break;
case PktFrameData:
// Special Variable Length frame
// This isn't ever transmitted but is used to define the
// current setting for the data frame. Mode and Length
// are variable
*blnOdd = 1;
*intNumCar = pktCarriers[pktMode];
*intDataLen = pktDataLen;
*intRSLen = pktRSLen;
strcpy(strMod, &pktMod[pktMode][0]);
strlop(strMod, '/');
*intBaud = 100;
break;
default:
// Others are Even/Odd Pairs
switch(bytFrameType & 0xFE)
{
case D4PSK_200_50_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 32;
*intRSLen = 8;
strcpy(strMod, "4PSK");
*intBaud = 50;
break;
case D4PSK_200_100_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 64;
*intRSLen = 16;
strcpy(strMod, "4PSK");
*intBaud = 100;
break;
case D16QAM_200_100_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 120;
*intRSLen = 40;
strcpy(strMod, "16QAM");
*intBaud = 100;
break;
case D4FSK_500_50_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 1;
*intDataLen = 32;
*intRSLen = 8;
strcpy(strMod, "4FSK");
*intBaud = 50;
*bytQualThres = 30;
break;
case D4PSK_500_50_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 2;
*intDataLen = 32;
*intRSLen = 8;
strcpy(strMod, "4PSK");
*intBaud = 50;
break;
case D4PSK_500_100_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 2;
*intDataLen = 64;
*intRSLen = 16;
strcpy(strMod, "4PSK");
*intBaud = 100;
break;
case D16QAMR_500_100_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 2;
*intDataLen = 120;
*intRSLen = 40;
strcpy(strMod, "16QAMR");
*intBaud = 100;
break;
case D16QAM_500_100_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 2;
*intDataLen = 120;
*intRSLen = 40;
strcpy(strMod, "16QAM");
*intBaud = 100;
break;
case DOFDM_200_55_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 3;
*intDataLen = 40;
*intRSLen = 10;
strcpy(strMod, "OFDM");
*intBaud = 55;
break;
case DOFDM_500_55_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 9;
*intDataLen = 40;
*intRSLen = 10;
strcpy(strMod, "OFDM");
*intBaud = 55;
break;
case D4FSK_1000_50_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 2;
*intDataLen = 32;
*intRSLen = 8;
strcpy(strMod, "4FSK");
*intBaud = 50;
break;
case D4PSKR_2500_50_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 10;
*intDataLen = 32;
*intRSLen = 8;
strcpy(strMod, "4PSKR");
*intBaud = 50;
break;
case D4PSK_2500_50_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 10;
*intDataLen = 32;
*intRSLen = 8;
strcpy(strMod, "4PSK");
*intBaud = 50;
break;
case D4PSK_2500_100_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 10;
*intDataLen = 64;
*intRSLen = 16;
strcpy(strMod, "4PSK");
*intBaud = 100;
break;
case D16QAMR_2500_100_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 10;
*intDataLen = 120;
*intRSLen = 40;
strcpy(strMod, "16QAMR");
*intBaud = 100;
break;
case D16QAM_2500_100_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 10;
*intDataLen = 120;
*intRSLen = 40;
strcpy(strMod, "16QAM");
*intBaud = 100;
break;
case DOFDM_2500_55_E:
*blnOdd = (1 & bytFrameType) != 0;
*intNumCar = 43;
*intDataLen = 40;
*intRSLen = 10;
strcpy(strMod, "OFDM");
*intBaud = 55;
break;
default:
Debugprintf("No data for frame type= %X", bytFrameType);
return FALSE;
}
}
strcpy(strType,strFrameType[bytFrameType]);
return TRUE;
}
int xNPAR = -1; // Number of Parity Bytes - used in RS Code
int MaxErrors = 0;
int xRSEncode(UCHAR * bytToRS, UCHAR * RSBytes, int DataLen, int RSLen)
{
// This just returns the Parity Bytes. I don't see the point
// in copying the message about
unsigned char Padded[256]; // The padded Data
int Length = DataLen + RSLen; // Final Length of packet
int PadLength = 255 - Length; // Padding bytes needed for shortened RS codes
// subroutine to do the RS encode. For full length and shortend RS codes up to 8 bit symbols (mm = 8)
if (NPAR != RSLen) // Changed RS Len, so recalc constants;
{