-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCSHostInterface.c
1692 lines (1289 loc) · 34.4 KB
/
SCSHostInterface.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 Serial Interface
// Based on SCS Extended Hodtmode, as used in
// SCS PTC and Dragon controllers.
// Operates in two modes, SCS Emulation and ARDOP Native.
// SCS Emulation allows programs writter for the SCS
// controllers to use ARDOP
// ARDOP Native supports full ARDOP command set
// Native Mode uses Stream 32 for commands, 33 for Data
// and 34 for Monitor/Logging.
#include "ARDOPC.h"
#define LOGTOHOST
#ifndef WIN32
#define strtok_s strtok_r
#define _strupr strupr
int _memicmp(unsigned char *a, unsigned char *b, int n);
char * strupr(char* s);
#endif
VOID ProcessSCSPacket(UCHAR * rxbuffer, unsigned int Length);
VOID EmCRCStuffAndSend(UCHAR * Msg, int Len);
void ProcessRIGPacket(int Command, char * Buffer, int Len);
VOID PutString(UCHAR * Msg);
int PutChar(UCHAR c);
int SerialSendData(UCHAR * Message,int MsgLen);
void CatWrite(char * Buffer, int Len);
int RadioPoll();
void ProcessCommandFromHost(char * strCMD);
BOOL GetNextARQFrame();
VOID ProcessKISSBytes(UCHAR * RXBUFFER, int Read);
BOOL CheckKISS(UCHAR * SCSReply);
UCHAR * PacketSessionPoll(UCHAR * NextChan);
BOOL CheckForPktData(int Channel);
VOID ProcessPktData(int Channel, UCHAR * Buffer, int Len);
BOOL ProcessPktCommand(int Channel, char *Buffer, int Len);
#ifdef LOGTOHOST
// Log output sent to host instead of File
#define LOGBUFFERSIZE 2048
char LogToHostBuffer[LOGBUFFERSIZE];
int LogToHostBufferLen = 0;
#endif
int bytDataToSendLength = 0;
UCHAR bytDataToSend[DATABUFFERSIZE];
// Outbound data buffer
char ReportCall[10];
UCHAR bytDataforHost[2048]; // has to be at least max packet size (8 * 159)
int bytesforHost = 0;
UCHAR bytEchoData[1280]; // has to be at least max packet size (?1272)
int bytesEchoed = 0;
UCHAR DelayedEcho = 0;
UCHAR SCSReply[256 + 10]; // Host Mode reply buffer
int Toggle;
char CommandToHostBuffer[512]; // Async Commands to Host (BUFFER etc)
int CommandToHostBufferLen;
char CMDReplyBuffer[256]; // Used by Command Handler. Null Terminated
extern char Callsign[10];
extern BOOL blnBusyStatus;
extern int intNumCar;
extern int intBaud;
extern int intDataLen;
extern int intRSLen;
extern int intSampleLen;
extern int intDataPtr;
extern int intSampPerSym;
extern int intDataBytesPerCar;
unsigned char CatRXbuffer[256];
int CatRXLen = 0;
BOOL Term4Mode;
BOOL DEDMode = 0; // Used by RMS Express for Packet
BOOL PACMode = 0;
BOOL HostMode = 0; // Host or Term
BOOL PTCMode = FALSE; // Running in PTC compatibility mode?
volatile int RXBPtr;
int change = 0; // Flag for connect/disconnect reports
int SCSState = 0;
int DataChannel = 31;
int ReplyLen;
extern float dblOffsetHz;
extern int intSessionBW;
extern int SerialWatchDog;
void SCSSendCommandToHost(char * Cmd)
{
if (HostMode & !PTCMode) // ARDOP Native
{
char * ptr = &CommandToHostBuffer[CommandToHostBufferLen];
int len = strlen(Cmd);
WriteDebugLog(LOGDEBUG, "Command to Host %s", Cmd);
if (CommandToHostBufferLen + len > 500)
return; // ignore if full
// Add headers and queue for host
strcpy(ptr, Cmd);
ptr += len;
*ptr++ = '\r';
CommandToHostBufferLen += (len + 1);
if (CommandToHostBufferLen > 512)
CommandToHostBufferLen = 0;
return;
}
if (memcmp(Cmd, "STATUS ", 7) == 0)
{
if (memcmp(&Cmd[7], "CONNECT TO", 10) == 0)
{
if (HostMode)
{
memcpy(ReportCall, &Cmd[18], 10);
strlop(ReportCall, ' ');
change = 1;
SCSState = 0;
}
else
PutString("Disconnected\r");
}
}
if (memcmp(Cmd, "CONNECTED ", 10) == 0)
{
if (HostMode)
{
memcpy(ReportCall, &Cmd[10], 10);
strlop(ReportCall, ' ');
change = 1;
SCSState = 1;
}
else
{
PutString(Cmd);
PutString("\r");
}
}
if (memcmp(Cmd, "DISCON", 6) == 0)
{
if (HostMode)
{
change = 1;
SCSState = 0;
}
else
PutString("Disconnected\r");
}
WriteDebugLog(LOGDEBUG, "Command to Host %s", Cmd);
}
void SCSQueueCommandToHost(char * Cmd)
{
SendCommandToHost(Cmd); // no queuing now
}
void SCSSendReplyToHost(char * Cmd)
{
// Used by command handler
if (HostMode)
if (PTCMode)
return; // shouldnt have commands jn PTC Mode
else
strcpy(CMDReplyBuffer, Cmd);
else
PutString(Cmd);
}
void SCSSendCommandToHostQuiet(char * Cmd) // Higher Debug Level for PTT
{
if (HostMode & !PTCMode) // ARDOP Native
{
char * ptr = &CommandToHostBuffer[CommandToHostBufferLen];
int len = strlen(Cmd);
WriteDebugLog(LOGDEBUG, "Command to Host %s", Cmd);
if (CommandToHostBufferLen + len > 500)
return; // ignore if full
// Add headers and queue for host
strcpy(ptr, Cmd);
ptr += len;
*ptr++ = '\r';
CommandToHostBufferLen += (len + 1);
if (CommandToHostBufferLen > 512)
CommandToHostBufferLen = 0;
return;
}
if (memcmp(Cmd, "STATUS ", 7) == 0)
{
if (memcmp(&Cmd[7], "CONNECT TO", 10) == 0)
{
if (HostMode)
{
memcpy(ReportCall, &Cmd[18], 10);
strlop(ReportCall, ' ');
change = 1;
SCSState = 0;
}
else
PutString("Disconnected\r");
}
}
if (memcmp(Cmd, "CONNECTED ", 10) == 0)
{
if (HostMode)
{
memcpy(ReportCall, &Cmd[10], 10);
strlop(ReportCall, ' ');
change = 1;
SCSState = 1;
}
else
{
PutString(Cmd);
PutString("\r");
}
}
if (memcmp(Cmd, "DISCON", 6) == 0)
{
if (HostMode)
{
change = 1;
SCSState = 0;
}
else
PutString("Disconnected\r");
}
}
void SCSAddTagToDataAndSendToHost(UCHAR * Msg, char * Type, int Len)
{
if (!HostMode)
{
Msg[Len] = 0;
PutString(Msg);
return;
}
if (PTCMode)
{
// only pass ARQ Data to Host
if (strcmp(Type, "ARQ") == 0)
{
memcpy(&bytDataforHost[bytesforHost], Msg, Len);
bytesforHost += Len;
}
return;
}
// In ARDOP Native add header (Type and Len)
Len += 3; // Tag
bytDataforHost[bytesforHost++] = Len >> 8; //' MS byte of count (Includes strDataType but does not include the two trailing CRC bytes)
bytDataforHost[bytesforHost++] = Len & 0xFF; // LS Byte
memcpy(&bytDataforHost[bytesforHost], Type, 3);
memcpy(&bytDataforHost[bytesforHost + 3], Msg, Len - 3);
bytesforHost += Len;
}
BOOL CheckStatusChange()
{
if (change == 1)
{
change = 0;
if (SCSState == 1)
{
// Connected
SCSReply[2] = DataChannel;
SCSReply[3] = 3;
ReplyLen = sprintf(&SCSReply[4], "(%d) CONNECTED to %s", DataChannel, ReportCall);
ReplyLen += 5;
EmCRCStuffAndSend(SCSReply, ReplyLen);
return TRUE;
}
// Disconnected
SCSReply[2] = DataChannel;
SCSReply[3] = 3;
ReplyLen = sprintf(&SCSReply[4], "(%d) DISCONNECTED fm %s", DataChannel, ReportCall);
ReplyLen += 5; // Include Null
EmCRCStuffAndSend(SCSReply, ReplyLen);
return TRUE;
}
return FALSE;
}
BOOL CheckForControl()
{
int Length;
if (CommandToHostBufferLen == 0)
return FALSE;
if (CommandToHostBufferLen > 256)
Length = 256;
else
Length = CommandToHostBufferLen;
memcpy(&SCSReply[5], CommandToHostBuffer, Length);
CommandToHostBufferLen -= Length;
if (CommandToHostBufferLen)
memmove(CommandToHostBuffer, &CommandToHostBuffer[Length], CommandToHostBufferLen);
SCSReply[2] = 32;
SCSReply[3] = 7;
SCSReply[4] = Length - 1;
ReplyLen = Length + 5;
EmCRCStuffAndSend(SCSReply, ReplyLen);
return TRUE;
}
BOOL CheckForData()
{
int Length;
if (bytesEchoed)
{
// Echo back acked data
if (bytesEchoed > 256)
Length = 256;
else
Length = bytesEchoed;
memcpy(&SCSReply[5], bytEchoData, Length);
bytesEchoed -= Length;
if (bytesEchoed)
memmove(bytEchoData, &bytEchoData[Length], bytesEchoed);
SCSReply[2] = DataChannel;
SCSReply[3] = 8; // PTC Special - delayed echoed data
SCSReply[4] = Length - 1;
ReplyLen = Length + 5;
EmCRCStuffAndSend(SCSReply, ReplyLen);
return TRUE;
}
if (bytesforHost == 0)
return FALSE;
if (bytesforHost > 256)
Length = 256;
else
Length = bytesforHost;
memcpy(&SCSReply[5], bytDataforHost, Length);
bytesforHost -= Length;
if (bytesforHost)
memmove(bytDataforHost, &bytDataforHost[Length], bytesforHost);
if (PTCMode)
SCSReply[2] = DataChannel;
else
SCSReply[2] = 33;
SCSReply[3] = 7;
SCSReply[4] = Length - 1;
ReplyLen = Length + 5;
EmCRCStuffAndSend(SCSReply, ReplyLen);
return TRUE;
}
#ifdef LOGTOHOST
BOOL CheckForLog()
{
int Length;
char * ptr;
if (LogToHostBufferLen == 0)
return FALSE;
// Return first message from buffer
// Terminated with LF, but beware of LF in timestamp
ptr = memchr(&LogToHostBuffer[4], 10, LogToHostBufferLen -4);
if (ptr == NULL) // shouldn't happen!
{
LogToHostBufferLen = 0;
return FALSE;
}
Length = 1 + ptr - &LogToHostBuffer[0];
if (Length > 256)
Length = 256;
memcpy(&SCSReply[5], LogToHostBuffer, Length);
LogToHostBufferLen -= Length;
if (LogToHostBufferLen)
memmove(LogToHostBuffer, &LogToHostBuffer[Length], LogToHostBufferLen);
SCSReply[2] = 248;
SCSReply[3] = 7;
SCSReply[4] = Length - 1;
ReplyLen = Length + 5;
EmCRCStuffAndSend(SCSReply, ReplyLen);
return TRUE;
}
#endif
// SCS Emulator
const unsigned short CRCTAB[256];
unsigned short int xcompute_crc(unsigned char *buf,int len)
{
unsigned short fcs = 0xffff;
int i;
for(i = 0; i < len; i++)
fcs = (fcs >>8 ) ^ CRCTAB[(fcs ^ buf[i]) & 0xff];
return fcs;
}
// SCS Mode Stuff
unsigned short int compute_crc(unsigned char *buf,int len);
VOID EmCRCStuffAndSend(UCHAR * Msg, int Len);
int EmUnstuff(UCHAR * MsgIn, UCHAR * MsgOut, int len)
{
int i, j=0;
for (i=0; i<len; i++, j++)
{
MsgOut[j] = MsgIn[i];
if (MsgIn[i] == 170) // Remove next byte
{
i++;
if (MsgIn[i] != 0)
if (i != len) return -1;
}
}
return j;
}
UCHAR PacketMon[360];
int PacketMonMore = 0;
int PacketMonLength = 0;
VOID ProcessSCSHostFrame(UCHAR * Buffer, int Length)
{
int Channel = Buffer[0];
int Command = Buffer[1] & 0x3f;
int Len = Buffer[2];
int len;
int RXToggle = Buffer[1] & 0x80;
// WriteDebugLog(LOGINFO, "SCS Host Frame Toggle %x RXToggle %x Chan %d Cmd %d Len %d",
// Toggle, RXToggle, Channel, Command, Len);
if (Toggle == RXToggle && (Buffer[1] & 0x40) == 0)
{
// Repeat Condition
EmCRCStuffAndSend(SCSReply, ReplyLen);
WriteDebugLog(LOGINFO, "Same Toggle - Repeating last packet");
return;
}
Toggle = RXToggle;
if (Channel == 255)
{
UCHAR * NextChan = &SCSReply[4];
// General Poll
// if Teensy, kick link watchdog
#ifdef TEENSY
SerialWatchDog = 0;
#endif
// See if any channels have anything available
// Although spec say Dragon only sends log data in response
// to poll of chan 248 it seems to send in response to gen poll
// Give priority to packet monitor data, as
// we only have one buffer
if (PacketMonLength)
{
// If length is less than 257, return whole
// lot in a Type 4 message
// if not, first 256 as a type 5 Message
// Next poll return rest in type 6
int Length = PacketMonLength;
if (Length > 256)
Length = 256;
if (PacketMonMore)
memcpy(&SCSReply[5], &PacketMon[256], Length);
else
memcpy(&SCSReply[5], PacketMon, Length);
SCSReply[2] = 0; // Channel 0
if (PacketMonLength > 256)
{
PacketMonMore = 1;
PacketMonLength -= 256;
SCSReply[3] = 5;
}
else
{
if (PacketMonMore)
SCSReply[3] = 6;
else
SCSReply[3] = 4;
PacketMonLength = PacketMonMore = 0;
}
SCSReply[4] = Length - 1;
EmCRCStuffAndSend(SCSReply, Length + 5);
return;
}
// Send KISS data in response to gen poll
if (CheckKISS(SCSReply)) // only used in Native mode
{
// got a message
return;
}
if (newStatus)
{
newStatus = FALSE;
*(NextChan++) = 255;
}
if (CatRXLen == 0)
{
#ifndef TEENSY
if (hCATDevice)
{
CatRXLen = ReadCOMBlock(hCATDevice, CatRXbuffer, 256);
}
#endif
}
if (CatRXLen) // Cat data available?
{
*(NextChan++) = 254; // 253 + 1
}
if (CommandToHostBufferLen) // only used in Native mode
*(NextChan++) = 33; // Native mode cmd channel
if (bytesforHost || bytesEchoed || change)
if (PTCMode)
*(NextChan++) = DataChannel; // Something for this channel
else
*(NextChan++) = 34; // Native mode data channel
NextChan = PacketSessionPoll(NextChan); // See if anythinkg from packet Sessions
#ifdef LOGTOHOST
// if (LogToHostBufferLen) // only used in Native mode
// *(NextChan++) = 35; // Native mode log channel
#endif
*(NextChan++) = 0;
SCSReply[2] = 255;
SCSReply[3] = 1;
ReplyLen = NextChan - &SCSReply[0];
#ifdef LOGTOHOST
if (ReplyLen == 5) // nothing doing
{
// if we have log data send it
if (LogToHostBufferLen) // only used in Native mode
{
// Send next message
if (CheckForLog())
{
// got a message
return;
}
}
}
#endif
EmCRCStuffAndSend(SCSReply, ReplyLen);
return;
}
if (Channel == 254) // Status
{
// Extended Status Poll
SCSReply[2] = 254;
SCSReply[3] = 7; // Status
SCSReply[4] = 3; // Len -1
// if (ProtocolState == IDLE || ProtocolState == IRS || ProtocolState == ISS)
if (ProtocolState != DISC)
{
// connected states
SCSReply[5] = 0xa2; // ARQ, Traffic
if (ProtocolState != IRS)
SCSReply[5] |= 0x8; // Send Bit
if (intSessionBW == 200)
SCSReply[6] = 1; // P1
else if (intSessionBW == 500)
SCSReply[6] = 2; // P2
else if (intSessionBW == 1000)
SCSReply[6] = 3; // P2
else
SCSReply[6] = 4; // P4
// Speedlevel Mapping from RMS Express
// P1 {100, 200}, _
// P2 {200, 400, 600, 800}, _
// P3 {200, 600, 1400, 2800, 3200, 3600}, _
// P4 {47, 85, 150, 300, 450, 1100, 2200, 3300, 4400, 5500}}
if (intSessionBW == 200)
SCSReply[7] = 1;
else if (intSessionBW == 500)
SCSReply[7] = 2; // P2
else if (intSessionBW == 1000)
SCSReply[7] = 3; // P2
else
SCSReply[7] = 6; // P4
SCSReply[8] = dblOffsetHz; // Freq Error
}
else
{
if (blnBusyStatus)
SCSReply[5] = 0xf0;
else
SCSReply[5] = 0;
SCSReply[6] = 0;
SCSReply[7] = 0;
SCSReply[8] = 0;
}
ReplyLen = 9;
EmCRCStuffAndSend(SCSReply, 9);
return;
}
if (Channel == 253) // Rig Control
{
if (Command == 1 && Buffer[3] == 'G')
{
// Poll for Rig Data
memcpy(&SCSReply[5], CatRXbuffer, CatRXLen);
SCSReply[2] = Channel;
SCSReply[3] = 7;
SCSReply[4] = CatRXLen - 1;
ReplyLen = CatRXLen + 5;
EmCRCStuffAndSend(SCSReply, ReplyLen);
CatRXLen = 0;
return;
}
Len = Buffer[2] + 1;
Buffer[Len + 3] = 0;
// RMS Express sends #TRX: Commands, eg #TRX TY I 9600 $00 TTL
// BPQ sends Data Frames with the raw contents
ProcessRIGPacket(Command, &Buffer[3], Len);
goto AckIt;
}
if (Channel == 250) // KISS Interface
{
if (Command == 1 && Buffer[3] == 'G')
{
// Poll for KISS Data
memcpy(&SCSReply[5], CatRXbuffer, CatRXLen);
SCSReply[2] = Channel;
SCSReply[3] = 7;
SCSReply[4] = CatRXLen - 1;
ReplyLen = CatRXLen + 5;
EmCRCStuffAndSend(SCSReply, ReplyLen);
CatRXLen = 0;
return;
}
Len = Buffer[2] + 1;
Buffer[Len + 3] = 0;
ProcessKISSBytes(&Buffer[3], Len);
goto AckIt;
}
if (Command == 0)
{
// Data Frame
// WriteDebugLog(LOGDEBUG, "Data Frame Channel %d", Channel);
if (Channel < 11) // Packet Data
{
ProcessPktData(Channel, &Buffer[3], Buffer[2] + 1);
return;
}
else if (Channel == 31) // PTC Mode Data
AddDataToDataToSend(&Buffer[3], Buffer[2] + 1);
else if (Channel == 32) // Native Mode Command
{
Buffer[Len + 3] = 0;
CMDReplyBuffer[0] = 0; // in case no reply
ProcessCommandFromHost(&Buffer[3]); // No C:
// Command will have put reply in CMDReplyBuffer
if (CMDReplyBuffer[0] == 0) // no response
goto AckIt;
SCSReply[2] = Channel;
SCSReply[3] = 1;
strcpy(&SCSReply[4], CMDReplyBuffer);
ReplyLen = strlen(CMDReplyBuffer) + 5;
EmCRCStuffAndSend(SCSReply, ReplyLen);
WriteDebugLog(LOGDEBUG, "Sending CMD Reply %s", CMDReplyBuffer);
return;
}
else if (Channel == 33) // Native Mode Data
AddDataToDataToSend(&Buffer[5], Buffer[2] - 1);
goto AckIt;
}
// Command Frame
if (Channel < 11 && Buffer[3] != 'G')
{
// Packet Channel Command
ProcessPktCommand(Channel, &Buffer[3], Len);
return;
}
switch (Buffer[3])
{
case 'J': // JHOST
HostMode = FALSE;
WriteDebugLog(LOGINFO, "Exit Host Mode");
return;
case 'L':
/*
' Status responses from the 'L' command will have 6 fields separated by spaces.
' The field definitions are as follows:
' Field 1: Number of link status messages not yet displayed
' Field 2: NUmber of receive frames not yet displayed
' Field 3: NUmber of send frames not yet delivered
' Field 4: NUmber of transmitted frames not yet acknowledged
' Field 5: NUmber of tries on the current operation
' Field 6: Link state:
' 0 = Disconnected
' 1 = Link Setop
' 2 = Frame Reject
' 3 = Disconnect Request
' 4 = Information transfer
' 5 = Reject Frame Sent
' 6 = Waiting Acknowledgement
' 7 = Device Busy
' 8 = Remote Device Busy
' 9 = Both Devices Busy
' 10 = Waiting Acknowledgement and Device Busy
' 11 = Waiting Acknowledgement and Remote Busy
' 12 = Waiting Acknowledgement and Both Device Busy
' 13 = Reject Frame Sent and Device Busy
' 14 = Reject Frame Sent and Remote Busy
' 15 = Reject Frame Sent and Both Device Busy
'
*/
// I think only 3 is important as it is used for flow control
// RMS Express stops at 20
SCSReply[2] = Channel;
SCSReply[3] = 1;
len = sprintf(&SCSReply[4], "%d %d %d %d %d %d", 0, 0, (bytDataToSendLength > 3000)?51:0, 0, 0, 4);
ReplyLen = len + 5;
EmCRCStuffAndSend(SCSReply, len + 5);
return;
return;
case 'G': // Specific Poll
if (Channel > 0 && Channel < 11)
if (CheckForPktData(Channel))
return; // It has sent reply
if (PTCMode)
{
if (CheckStatusChange())
return; // It has sent reply
if (CheckForData())
return; // It has sent reply
}
else
{
// Native mode
if (Channel == 32)
if (CheckForControl())
return; // It has sent reply
if (Channel == 33)
if (CheckForData())
return; // It has sent reply
#ifdef LOGTOHOST
if (Channel == 34)
if (CheckForLog())
return; // It has sent reply
#endif
}
// reply nothing doing
SCSReply[2] = Channel;
SCSReply[3] = 0;
ReplyLen = 4;
EmCRCStuffAndSend(SCSReply, 4);
return;
case 'C': // Connect
// Could be real, or just C to request status
if (Channel == 0)
goto AckIt;
if (Length == 0)
{
// STATUS REQUEST - IF CONNECTED, GET CALL
return;
}
Buffer[Length - 2] = 0;
if (Buffer[5] == '%' || Buffer[5] == '!' ||Buffer[5] == ';' )
Buffer++; // Long Path / Robust
SendARQConnectRequest(Callsign, &Buffer[5]);
AckIt:
SCSReply[2] = Channel;
SCSReply[3] = 0;
ReplyLen = 4;
EmCRCStuffAndSend(SCSReply, 4);
return;
case 'D':
// Disconnect
if (ProtocolState == IDLE || ProtocolState == IRS || ProtocolState == ISS)
blnARQDisconnect = TRUE;
goto AckIt;
case '%':
// %X commands
Buffer[Length - 2] = 0;
WriteDebugLog(LOGDEBUG, "SCS Host Command %s", &Buffer[3]);
switch (Buffer[4])
{
case 'V': // Version
SCSReply[2] = Channel;
SCSReply[3] = 1;
strcpy(&SCSReply[4], "4.8 1.32");
ReplyLen = 13;
EmCRCStuffAndSend(SCSReply, 13);
return;