forked from erikarn/LinBPQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RigControl.c
4733 lines (3592 loc) · 96.4 KB
/
RigControl.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
/*
Copyright 2001-2015 John Wiseman G8BPQ
This file is part of LinBPQ/BPQ32.
LinBPQ/BPQ32 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LinBPQ/BPQ32 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
*/
//
// Rig Control Module
//
// Dec 29 2009
// Add Scan Control for SCS
// August 2010
// Fix logic error in Port Initialisation (wasn't always raising RTS and DTR
// Clear RTS and DTR on close
// Fix Kenwood processing of multiple messages in one packet.
// Fix reporting of set errors in scan to the wrong session
// Yaesu List
// FT990 define as FT100
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_32BIT_TIME_T
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "CHeaders.h"
#include "tncinfo.h"
#ifndef LINBPQ
#include <commctrl.h>
#endif
#include "bpq32.h"
struct TNCINFO * TNCInfo[34]; // Records are Malloc'd
extern char * RigConfigMsg[35];
int Row = -20;
BOOL RIG_DEBUG = FALSE;
extern struct PORTCONTROL * PORTTABLE;
VOID __cdecl Debugprintf(const char * format, ...);
struct RIGINFO * RigConfig(struct TNCINFO * TNC, char * buf, int Port);
struct RIGPORTINFO * CreateTTYInfo(int port, int speed);
BOOL OpenConnection(int);
BOOL SetupConnection(int);
BOOL RigCloseConnection(struct RIGPORTINFO * PORT);
BOOL RigWriteCommBlock(struct RIGPORTINFO * PORT);
BOOL DestroyTTYInfo(int port);
void CheckRX(struct RIGPORTINFO * PORT);
static OpenRigCOMMPort(struct RIGPORTINFO * PORT, VOID * Port, int Speed);
VOID ICOMPoll(struct RIGPORTINFO * PORT);
VOID ProcessFrame(struct RIGPORTINFO * PORT, UCHAR * rxbuff, int len);
VOID ProcessICOMFrame(struct RIGPORTINFO * PORT, UCHAR * rxbuffer, int Len);
int SendResponse(int Stream, char * Msg);
VOID ProcessYaesuFrame(struct RIGPORTINFO * PORT);
VOID YaesuPoll(struct RIGPORTINFO * PORT);
VOID ProcessYaesuCmdAck(struct RIGPORTINFO * PORT);
VOID ProcessKenwoodFrame(struct RIGPORTINFO * PORT, int Length);
VOID KenwoodPoll(struct RIGPORTINFO * PORT);
VOID DummyPoll(struct RIGPORTINFO * PORT);
VOID SwitchAntenna(struct RIGINFO * RIG, char Antenna);
VOID DoBandwidthandAntenna(struct RIGINFO *RIG, struct ScanEntry * ptr);
VOID SetupScanInterLockGroups(struct RIGINFO *RIG);
VOID ProcessFT100Frame(struct RIGPORTINFO * PORT);
VOID ProcessFT990Frame(struct RIGPORTINFO * PORT);
VOID ProcessFT1000Frame(struct RIGPORTINFO * PORT);
VOID AddNMEAChecksum(char * msg);
VOID ProcessNMEA(struct RIGPORTINFO * PORT, char * NMEAMsg, int len);
VOID COMSetDTR(HANDLE fd);
VOID COMClearDTR(HANDLE fd);
VOID COMSetRTS(HANDLE fd);
VOID COMClearRTS(HANDLE fd);
VOID SetupPortRIGPointers();
VOID PTTCATThread(struct RIGINFO *RIG);
int SendPTCRadioCommand(struct TNCINFO * TNC, char * Block, int Length);
int GetPTCRadioCommand(struct TNCINFO * TNC, char * Block);
extern TRANSPORTENTRY * L4TABLE;
HANDLE hInstance;
VOID APIENTRY CreateOneTimePassword(char * Password, char * KeyPhrase, int TimeOffset);
BOOL APIENTRY CheckOneTimePassword(char * Password, char * KeyPhrase);
char * GetApplCallFromName(char * App);
char Modes[20][6] = {"LSB", "USB", "AM", "CW", "RTTY", "FM", "WFM", "CW-R", "RTTY-R",
"????","????","????","????","????","????","????","????","DV", "????",};
// 0 1 2 3 4 5 6 7 8 9 0A 0B 0C 88
char YaesuModes[16][6] = {"LSB", "USB", "CW", "CWR", "AM", "", "", "", "FM", "", "DIG", "", "PKT", "FMN", "????"};
char FT100Modes[9][6] = {"LSB", "USB", "CW", "CWR", "AM", "DIG", "FM", "WFM", "????"};
char FT990Modes[13][6] = {"LSB", "USB", "CW2k4", "CW500", "AM6k", "AM2k4", "FM", "FM", "RTTYL", "RTTYU", "PKTL", "PKTFM", "????"};
char FT1000Modes[13][6] = {"LSB", "USB", "CW", "CWR", "AM", "AMS", "FM", "WFM", "RTTYL", "RTTYU", "PKTL", "PKTF", "????"};
char FTRXModes[8][6] = {"LSB", "USB", "CW", "AM", "FM", "RTTY", "PKT", ""};
char KenwoodModes[16][6] = {"????", "LSB", "USB", "CW", "FM", "AM", "FSK", "????"};
//char FT2000Modes[16][6] = {"????", "LSB", "USB", "CW", "FM", "AM", "FSK", "PKT-L", "FSK-R", "PKT-FM", "FM-N", "PKT-U", "????"};
char FT2000Modes[16][6] = {"????", "LSB", "USB", "CW", "FM", "AM", "FSK", "CW-R", "PKT-L", "FSK-R", "PKT-FM", "FM-N", "PKT-U", "????"};
char FLEXModes[16][6] = {"LSB", "USB", "DSB", "CWL", "CWU", "FM", "AM", "DIGU", "SPEC", "DIGL", "SAM", "DRM"};
char AuthPassword[100] = "";
char LastPassword[17];
int NumberofPorts = 0;
BOOL EndPTTCATThread = FALSE;
struct RIGPORTINFO * PORTInfo[34] = {NULL}; // Records are Malloc'd
struct TimeScan * AllocateTimeRec(struct RIGINFO * RIG)
{
struct TimeScan * Band = malloc(sizeof (struct TimeScan));
RIG->TimeBands = realloc(RIG->TimeBands, (++RIG->NumberofBands+2)*4);
RIG->TimeBands[RIG->NumberofBands] = Band;
RIG->TimeBands[RIG->NumberofBands+1] = NULL;
return Band;
}
struct ScanEntry ** CheckTimeBands(struct RIGINFO * RIG)
{
int i = 0;
time_t NOW = time(NULL) % 86400;
// Find TimeBand
while (i < RIG->NumberofBands)
{
if (RIG->TimeBands[i + 1]->Start > NOW)
{
break;
}
i++;
}
RIG->FreqPtr = RIG->TimeBands[i]->Scanlist;
return RIG->FreqPtr;
}
VOID Rig_PTT(struct RIGINFO * RIG, BOOL PTTState)
{
struct RIGPORTINFO * PORT;
if (RIG == NULL) return;
PORT = RIG->PORT;
if (PTTState)
{
MySetWindowText(RIG->hPTT, "T");
RIG->WEB_PTT = 'T';
RIG->PTTTimer = PTTLimit;
}
else
{
MySetWindowText(RIG->hPTT, "");
RIG->WEB_PTT = ' ';
RIG->PTTTimer = 0;
}
if (RIG->PTTMode & PTTCI_V)
{
UCHAR * Poll = PORT->TXBuffer;
switch (PORT->PortType)
{
case ICOM:
case KENWOOD:
case FT2000:
case FLEX:
case NMEA:
if (PTTState)
{
memcpy(Poll, RIG->PTTOn, RIG->PTTOnLen);
PORT->TXLen = RIG->PTTOnLen;
}
else
{
memcpy(Poll, RIG->PTTOff, RIG->PTTOffLen);
PORT->TXLen = RIG->PTTOffLen;
}
RigWriteCommBlock(PORT);
if (PORT->PortType == ICOM && !PTTState)
RigWriteCommBlock(PORT); // Send ICOP PTT OFF Twice
PORT->Retries = 1;
if (PORT->PortType != ICOM)
PORT->Timeout = 0;
return;
case FT100:
case FT990:
case FT1000:
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = PTTState; // OFF/ON
*(Poll++) = 15;
PORT->TXLen = 5;
RigWriteCommBlock(PORT);
PORT->Retries = 1;
PORT->Timeout = 0;
return;
case YAESU: // 897 - maybe others
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = PTTState ? 0x08 : 0x88; // CMD = 08 : PTT ON CMD = 88 : PTT OFF
PORT->TXLen = 5;
RigWriteCommBlock(PORT);
PORT->Retries = 1;
PORT->Timeout = 0;
return;
}
}
if (RIG->PTTMode & PTTRTS)
if (PTTState)
COMSetRTS(PORT->hPTTDevice);
else
COMClearRTS(PORT->hPTTDevice);
if (RIG->PTTMode & PTTDTR)
if (PTTState)
COMSetDTR(PORT->hPTTDevice);
else
COMClearDTR(PORT->hPTTDevice);
}
struct RIGINFO * Rig_GETPTTREC(int Port)
{
struct RIGINFO * RIG;
struct RIGPORTINFO * PORT;
int i, p;
for (p = 0; p < NumberofPorts; p++)
{
PORT = PORTInfo[p];
for (i=0; i< PORT->ConfiguredRigs; i++)
{
RIG = &PORT->Rigs[i];
if (RIG->BPQPort & (1 << Port))
return RIG;
}
}
return NULL;
}
int Rig_Command(int Session, char * Command)
{
int n, Port, ModeNo, Filter;
double Freq = 0.0;
char FreqString[80]="", FilterString[80]="", Mode[80]="", Data[80] = "";
UINT * buffptr;
UCHAR * Poll;
char Valchar[64];
// int dec, sign;
struct RIGPORTINFO * PORT;
int i, p;
struct RIGINFO * RIG;
TRANSPORTENTRY * L4 = L4TABLE;
char * ptr;
int Split, DataFlag, Bandwidth, Antenna;
struct ScanEntry * FreqPtr;
char * CmdPtr;
int Len;
char MemoryBank = 0; // For Memory Scanning
int MemoryNumber = 0;
// Only Allow RADIO from Secure Applications
_strupr(Command);
ptr = strchr(Command, 13);
if (ptr) *(ptr) = 0; // Null Terminate
if (memcmp(Command, "AUTH ", 5) == 0)
{
if (AuthPassword[0] && (memcmp(LastPassword, &Command[5], 16) != 0))
{
if (CheckOneTimePassword(&Command[5], AuthPassword))
{
L4 += Session;
L4->Secure_Session = 1;
sprintf(Command, "Ok\r");
memcpy(LastPassword, &Command[5], 16); // Save
return FALSE;
}
}
sprintf(Command, "Sorry AUTH failed\r");
return FALSE;
}
if (Session != -1) // Used for internal Stop/Start
{
L4 += Session;
if (L4->Secure_Session == 0)
{
sprintf(Command, "Sorry - you are not allowed to use this command\r");
return FALSE;
}
}
if (NumberofPorts == 0)
{
sprintf(Command, "Sorry - Rig Control not configured\r");
return FALSE;
}
n = sscanf(Command,"%d %s %s %s %s", &Port, &FreqString[0], &Mode[0], &FilterString[0], &Data[0]);
// Look for the port
for (p = 0; p < NumberofPorts; p++)
{
PORT = PORTInfo[p];
for (i=0; i< PORT->ConfiguredRigs; i++)
{
RIG = &PORT->Rigs[i];
if (RIG->BPQPort & (1 << Port))
goto portok;
}
}
sprintf(Command, "Sorry - Port not found\r");
return FALSE;
portok:
if (RIG->RIGOK == 0 && Session != -1)
{
sprintf(Command, "Sorry - Radio not responding\r");
return FALSE;
}
if (n > 1)
{
if (_stricmp(FreqString, "SCANSTART") == 0)
{
if (RIG->NumberofBands)
{
RIG->ScanStopped &= (0xffffffff ^ (1 << Port));
if (Session != -1) // Used for internal Stop/Start
RIG->ScanStopped &= 0xfffffffe; // Clear Manual Stopped Bit
if (n > 2)
RIG->ScanCounter = atoi(Mode) * 10; //Start Delay
else
RIG->ScanCounter = 10;
RIG->WaitingForPermission = FALSE; // In case stuck
if (RIG->ScanStopped == 0)
{
SetWindowText(RIG->hSCAN, "S");
RIG->WEB_SCAN = 'S';
}
sprintf(Command, "Ok\r");
if (RIG_DEBUG)
Debugprintf("BPQ32 SCANSTART Port %d", Port);
}
else
sprintf(Command, "Sorry no Scan List defined for this port\r");
return FALSE;
}
if (_stricmp(FreqString, "SCANSTOP") == 0)
{
RIG->ScanStopped |= (1 << Port);
if (Session != -1) // Used for internal Stop/Start
RIG->ScanStopped |= 1; // Set Manual Stopped Bit
SetWindowText(RIG->hSCAN, "");
RIG->WEB_SCAN = ' ';
sprintf(Command, "Ok\r");
if (RIG_DEBUG)
Debugprintf("BPQ32 SCANSTOP Port %d", Port);
return FALSE;
}
}
RIG->Session = Session; // BPQ Stream
if (_memicmp(FreqString, "Chan", 4) == 0)
{
if (strchr(FreqString, '/') ) // Bank/Chan
{
MemoryBank = FreqString[4];
MemoryNumber = atoi(&FreqString[6]);
}
else
MemoryNumber = atoi(&FreqString[4]); // Just Chan
Freq = 0.0;
}
else
{
Freq = atof(FreqString);
if (Freq < 0.1)
{
strcpy(Command, "Sorry - Invalid Frequency\r");
return FALSE;
}
}
Freq = Freq * 1000000.0;
snprintf(FreqString, 32, "%.9d", Freq);
if (PORT->PortType != ICOM)
strcpy(Data, FilterString); // Others don't have a filter.
Split = DataFlag = Bandwidth = Antenna = 0;
_strupr(Data);
if (strchr(Data, '+'))
Split = '+';
else if (strchr(Data, '-'))
Split = '-';
else if (strchr(Data, 'S'))
Split = 'S';
else if (strchr(Data, 'D'))
DataFlag = 1;
if (strchr(Data, 'W'))
Bandwidth = 'W';
else if (strchr(Data, 'N'))
Bandwidth = 'N';
if (strstr(Data, "A1"))
Antenna = '1';
else if (strstr(Data, "A2"))
Antenna = '2';
if (strstr(Data, "A3"))
Antenna = '3';
else if (strstr(Data, "A4"))
Antenna = '4';
switch (PORT->PortType)
{
case ICOM:
if (n == 2)
// Set Freq Only
ModeNo = -1;
else
{
if (n < 4)
{
strcpy(Command, "Sorry - Invalid Format - should be Port Freq Mode Filter Width\r");
return FALSE;
}
Filter = atoi(FilterString);
for (ModeNo = 0; ModeNo < 8; ModeNo++)
{
if (_stricmp(Modes[ModeNo], Mode) == 0)
break;
}
if (ModeNo == 8)
{
sprintf(Command, "Sorry - Invalid Mode\r");
return FALSE;
}
}
buffptr = GetBuff();
if (buffptr == 0)
{
sprintf(Command, "Sorry - No Buffers available\r");
return FALSE;
}
// Build a ScanEntry in the buffer
FreqPtr = (struct ScanEntry *)&buffptr[2];
memset(FreqPtr, 0, sizeof(struct ScanEntry));
FreqPtr->Freq = Freq;
FreqPtr->Bandwidth = Bandwidth;
FreqPtr->Antenna = Antenna;
FreqPtr->Dwell = 51;
CmdPtr = FreqPtr->Cmd1 = (UCHAR *)&buffptr[20];
FreqPtr->Cmd2 = NULL;
FreqPtr->Cmd3 = NULL;
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = RIG->RigAddr;
*(CmdPtr++) = 0xE0;
if (MemoryNumber)
{
// Set Memory Channel instead of Freq, Mode, etc
char ChanString[5];
// Send Set Memory, then Channel
*(CmdPtr++) = 0x08;
*(CmdPtr++) = 0xFD;
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = RIG->RigAddr;
*(CmdPtr++) = 0xE0;
sprintf(ChanString, "%04d", MemoryNumber);
*(CmdPtr++) = 0x08;
*(CmdPtr++) = (ChanString[1] - 48) | ((ChanString[0] - 48) << 4);
*(CmdPtr++) = (ChanString[3] - 48) | ((ChanString[2] - 48) << 4);
*(CmdPtr++) = 0xFD;
FreqPtr[0].Cmd1Len = 14;
if (MemoryBank)
{
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = RIG->RigAddr;
*(CmdPtr++) = 0xE0;
*(CmdPtr++) = 0x08;
*(CmdPtr++) = 0xA0;
*(CmdPtr++) = MemoryBank - 0x40;
*(CmdPtr++) = 0xFD;
FreqPtr[0].Cmd1Len += 8;
}
}
else
{
*(CmdPtr++) = 0x5; // Set frequency command
// Need to convert two chars to bcd digit
*(CmdPtr++) = (FreqString[8] - 48) | ((FreqString[7] - 48) << 4);
*(CmdPtr++) = (FreqString[6] - 48) | ((FreqString[5] - 48) << 4);
*(CmdPtr++) = (FreqString[4] - 48) | ((FreqString[3] - 48) << 4);
*(CmdPtr++) = (FreqString[2] - 48) | ((FreqString[1] - 48) << 4);
*(CmdPtr++) = (FreqString[0] - 48);
*(CmdPtr++) = 0xFD;
FreqPtr[0].Cmd1Len = 11;
// Send Set VFO in case last chan was memory
// *(CmdPtr++) = 0xFE;
// *(CmdPtr++) = 0xFE;
// *(CmdPtr++) = RIG->RigAddr;
// *(CmdPtr++) = 0xE0;
// *(CmdPtr++) = 0x07;
// *(CmdPtr++) = 0xFD;
// FreqPtr[0].Cmd1Len = 17;
if (ModeNo != -1) // Dont Set
{
CmdPtr = FreqPtr->Cmd2 = (UCHAR *)&buffptr[30];
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = RIG->RigAddr;
*(CmdPtr++) = 0xE0;
*(CmdPtr++) = 0x6; // Set Mode
*(CmdPtr++) = ModeNo;
*(CmdPtr++) = Filter;
*(CmdPtr++) = 0xFD;
FreqPtr->Cmd2Len = 8;
if (Split)
{
CmdPtr = FreqPtr->Cmd3 = (UCHAR *)&buffptr[40];
FreqPtr->Cmd3Len = 7;
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = RIG->RigAddr;
*(CmdPtr++) = 0xE0;
*(CmdPtr++) = 0xF; // Set Mode
if (Split == 'S')
*(CmdPtr++) = 0x10;
else
if (Split == '+')
*(CmdPtr++) = 0x12;
else
if (Split == '-')
*(CmdPtr++) = 0x11;
*(CmdPtr++) = 0xFD;
}
else if (DataFlag)
{
CmdPtr = FreqPtr->Cmd3 = (UCHAR *)&buffptr[40];
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = 0xFE;
*(CmdPtr++) = RIG->RigAddr;
*(CmdPtr++) = 0xE0;
*(CmdPtr++) = 0x1a;
if ((strcmp(RIG->RigName, "IC7100") == 0) || (strcmp(RIG->RigName, "IC7410") == 0)) {
FreqPtr[0].Cmd3Len = 9;
*(CmdPtr++) = 0x6; // Send/read DATA mode with filter set
*(CmdPtr++) = 0x1; // Data On
*(CmdPtr++) = Filter; //Filter
}
else if (strcmp(RIG->RigName, "IC7200") == 0)
{
FreqPtr[0].Cmd3Len = 9;
*(CmdPtr++) = 0x4; // Send/read DATA mode with filter set
*(CmdPtr++) = 0x1; // Data On
*(CmdPtr++) = Filter; // Filter
}
else
{
FreqPtr[0].Cmd3Len = 8;
*(CmdPtr++) = 0x6; // Set Data
*(CmdPtr++) = 0x1; //On
}
*(CmdPtr++) = 0xFD;
}
}
}
buffptr[1] = 200;
C_Q_ADD(&RIG->BPQtoRADIO_Q, buffptr);
return TRUE;
case YAESU:
if (n < 3)
{
strcpy(Command, "Sorry - Invalid Format - should be Port Freq Mode\r");
return FALSE;
}
for (ModeNo = 0; ModeNo < 15; ModeNo++)
{
if (_stricmp(YaesuModes[ModeNo], Mode) == 0)
break;
}
if (ModeNo == 15)
{
sprintf(Command, "Sorry -Invalid Mode\r");
return FALSE;
}
buffptr = GetBuff();
if (buffptr == 0)
{
sprintf(Command, "Sorry - No Buffers available\r");
return FALSE;
}
// Build a ScanEntry in the buffer
FreqPtr = (struct ScanEntry *)&buffptr[2];
FreqPtr->Freq = Freq;
FreqPtr->Bandwidth = Bandwidth;
FreqPtr->Antenna = Antenna;
Poll = (UCHAR *)&buffptr[20];
// Send Mode then Freq - setting Mode seems to change frequency
*(Poll++) = ModeNo;
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 7; // Set Mode
*(Poll++) = (FreqString[1] - 48) | ((FreqString[0] - 48) << 4);
*(Poll++) = (FreqString[3] - 48) | ((FreqString[2] - 48) << 4);
*(Poll++) = (FreqString[5] - 48) | ((FreqString[4] - 48) << 4);
*(Poll++) = (FreqString[7] - 48) | ((FreqString[6] - 48) << 4);
*(Poll++) = 1; // Set Freq
buffptr[1] = 10;
if (strcmp(PORT->Rigs[0].RigName, "FT847") == 0)
{
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 3; // Status Poll
buffptr[1] = 15;
}
C_Q_ADD(&RIG->BPQtoRADIO_Q, buffptr);
return TRUE;
case FT100:
case FT990:
case FT1000:
if (n == 2) // Set Freq Only
ModeNo = -1;
else
{
if (n < 3)
{
strcpy(Command, "Sorry - Invalid Format - should be Port Freq Mode\r");
return FALSE;
}
if (PORT->PortType == FT100)
{
for (ModeNo = 0; ModeNo < 8; ModeNo++)
{
if (_stricmp(FT100Modes[ModeNo], Mode) == 0)
break;
}
if (ModeNo == 8)
{
sprintf(Command, "Sorry -Invalid Mode\r");
return FALSE;
}
}
else if (PORT->PortType == FT990)
{
for (ModeNo = 0; ModeNo < 12; ModeNo++)
{
if (_stricmp(FT990Modes[ModeNo], Mode) == 0)
break;
}
if (ModeNo == 12)
{
sprintf(Command, "Sorry -Invalid Mode\r");
return FALSE;
}
}
else
{
for (ModeNo = 0; ModeNo < 12; ModeNo++)
{
if (_stricmp(FT1000Modes[ModeNo], Mode) == 0)
break;
}
if (ModeNo == 12)
{
sprintf(Command, "Sorry -Invalid Mode\r");
return FALSE;
}
}
}
buffptr = GetBuff();
if (buffptr == 0)
{
sprintf(Command, "Sorry - No Buffers available\r");
return FALSE;
}
// Build a ScanEntry in the buffer
FreqPtr = (struct ScanEntry *)&buffptr[2];
FreqPtr->Freq = Freq;
FreqPtr->Bandwidth = Bandwidth;
FreqPtr->Antenna = Antenna;
Poll = (UCHAR *)&buffptr[20];
// Send Mode then Freq - setting Mode seems to change frequency
if (ModeNo == -1) // Don't set Mode
{
// Changing the length messes up a lot of code,
// so set freq twice instead of omitting entry
*(Poll++) = (FreqString[7] - 48) | ((FreqString[6] - 48) << 4);
*(Poll++) = (FreqString[5] - 48) | ((FreqString[4] - 48) << 4);
*(Poll++) = (FreqString[3] - 48) | ((FreqString[2] - 48) << 4);
*(Poll++) = (FreqString[1] - 48) | ((FreqString[0] - 48) << 4);
*(Poll++) = 10; // Set Freq
}
else
{
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = ModeNo;
*(Poll++) = 12; // Set Mode
}
*(Poll++) = (FreqString[7] - 48) | ((FreqString[6] - 48) << 4);
*(Poll++) = (FreqString[5] - 48) | ((FreqString[4] - 48) << 4);
*(Poll++) = (FreqString[3] - 48) | ((FreqString[2] - 48) << 4);
*(Poll++) = (FreqString[1] - 48) | ((FreqString[0] - 48) << 4);
*(Poll++) = 10; // Set Freq
*(Poll++) = 0;
*(Poll++) = 0;
*(Poll++) = 0;
if (PORT->PortType == FT990 || PORT->YaesuVariant == FT1000D)
*(Poll++) = 3;
else
*(Poll++) = 2; // 100 or 1000MP
*(Poll++) = 16; // Status Poll
buffptr[1] = 15;
C_Q_ADD(&RIG->BPQtoRADIO_Q, buffptr);
return TRUE;
case KENWOOD:
case FT2000:
case FLEX:
if (n < 3)
{
strcpy(Command, "Sorry - Invalid Format - should be Port Freq Mode\r");
return FALSE;
}
for (ModeNo = 0; ModeNo < 14; ModeNo++)
{
if (PORT->PortType == FT2000)
if (_stricmp(FT2000Modes[ModeNo], Mode) == 0)
break;
if (PORT->PortType == KENWOOD)
if (_stricmp(KenwoodModes[ModeNo], Mode) == 0)
break;
if (PORT->PortType == FLEX)
if (_stricmp(FLEXModes[ModeNo], Mode) == 0)
break;
}
if (ModeNo > 12)
{
sprintf(Command, "Sorry -Invalid Mode\r");
return FALSE;
}
buffptr = GetBuff();
if (buffptr == 0)
{
sprintf(Command, "Sorry - No Buffers available\r");
return FALSE;
}
// Build a ScanEntry in the buffer
FreqPtr = (struct ScanEntry *)&buffptr[2];
FreqPtr->Freq = Freq;
FreqPtr->Bandwidth = Bandwidth;
FreqPtr->Antenna = Antenna;
Poll = (UCHAR *)&buffptr[20];
if (PORT->PortType == FT2000)
buffptr[1] = sprintf(Poll, "FA%s;MD0%X;FA;MD;", &FreqString[1], ModeNo);
else
if (PORT->PortType == FLEX)
buffptr[1] = sprintf(Poll, "ZZFA00%s;ZZMD%02d;ZZFA;ZZMD;", &FreqString[1], ModeNo);
else
buffptr[1] = sprintf(Poll, "FA00%s;MD%d;FA;MD;", FreqString, ModeNo);
C_Q_ADD(&RIG->BPQtoRADIO_Q, buffptr);
return TRUE;
case NMEA:
if (n < 3)
{
strcpy(Command, "Sorry - Invalid Format - should be Port Freq Mode\r");
return FALSE;
}
buffptr = GetBuff();
if (buffptr == 0)
{
sprintf(Command, "Sorry - No Buffers available\r");
return FALSE;
}
// Build a ScanEntry in the buffer
FreqPtr = (struct ScanEntry *)&buffptr[2];
FreqPtr->Freq = Freq;
FreqPtr->Bandwidth = Bandwidth;
FreqPtr->Antenna = Antenna;
Poll = (UCHAR *)&buffptr[20];
i = sprintf(Poll, "$PICOA,90,%02x,RXF,%.6f*xx\r\n", RIG->RigAddr, Freq/1000000.);
AddNMEAChecksum(Poll);
Len = i;
i = sprintf(Poll + Len, "$PICOA,90,%02x,TXF,%.6f*xx\r\n", RIG->RigAddr, Freq/1000000.);
AddNMEAChecksum(Poll + Len);
Len += i;
i = sprintf(Poll + Len, "$PICOA,90,%02x,MODE,%s*xx\r\n", RIG->RigAddr, Mode);
AddNMEAChecksum(Poll + Len);