-
Notifications
You must be signed in to change notification settings - Fork 0
/
HFCommon.c
1388 lines (1014 loc) · 30.1 KB
/
HFCommon.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-2018 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
*/
#pragma data_seg("_BPQDATA")
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_32BIT_TIME_T
#include <time.h>
#define SD_RECEIVE 0x00
#define SD_SEND 0x01
#define SD_BOTH 0x02
#include "kernelresource.h"
#include "CHeaders.h"
#include "tncinfo.h"
#ifndef LINBPQ
#include <commctrl.h>
#endif
//#include <stdlib.h>
#include "bpq32.h"
extern char * PortConfig[33];
HANDLE hInstance;
extern HBRUSH bgBrush;
extern HWND ClientWnd, FrameWnd;
extern int OffsetH, OffsetW;
extern HMENU hMainFrameMenu;
extern HMENU hBaseMenu;
extern HANDLE hInstance;
extern HKEY REGTREE;
extern int Ver[];
int KillTNC(struct TNCINFO * TNC);
int RestartTNC(struct TNCINFO * TNC);
VOID ARDOPAbort(struct TNCINFO * TNC);
unsigned long _beginthread( void( *start_address )(), unsigned stack_size, int arglist);
char * GetChallengeResponse(char * Call, char * ChallengeString);
VOID __cdecl Debugprintf(const char * format, ...);
static RECT Rect;
struct TNCINFO * TNCInfo[34]; // Records are Malloc'd
#define WSA_ACCEPT WM_USER + 1
#define WSA_DATA WM_USER + 2
#define WSA_CONNECT WM_USER + 3
int Winmor_Socket_Data(int sock, int error, int eventcode);
struct WL2KInfo * WL2KReports;
int WL2KTimer = 0;
int ModetoBaud[31] = {0,0,0,0,0,0,0,0,0,0,0, // 0 = 10
200,600,3200,600,3200,3200, // 11 - 16
0,0,0,0,0,0,0,0,0,0,0,0,0,600}; // 17 - 30
extern char HFCTEXT[];
extern int HFCTEXTLEN;
extern char WL2KCall[10];
extern char WL2KLoc[7];
VOID MoveWindows(struct TNCINFO * TNC)
{
#ifndef LINBPQ
RECT rcClient;
int ClientHeight, ClientWidth;
GetClientRect(TNC->hDlg, &rcClient);
ClientHeight = rcClient.bottom;
ClientWidth = rcClient.right;
if (TNC->hMonitor)
if (RigConfigMsg[TNC->Port])
MoveWindow(TNC->hMonitor,2 , TNC->RigControlRow + 25, ClientWidth-4, ClientHeight - (TNC->RigControlRow + 25), TRUE);
else
MoveWindow(TNC->hMonitor,2 , TNC->RigControlRow + 3, ClientWidth-4, ClientHeight - (TNC->RigControlRow + 3), TRUE);
#endif
}
char * Config;
static char * ptr1, * ptr2;
#ifndef LINBPQ
LRESULT CALLBACK PacWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
MINMAXINFO * mmi;
int i;
struct TNCINFO * TNC;
HKEY hKey;
char Key[80];
int retCode, disp;
for (i=1; i<33; i++)
{
TNC = TNCInfo[i];
if (TNC == NULL)
continue;
if (TNC->hDlg == hWnd)
break;
}
if (TNC == NULL)
return DefMDIChildProc(hWnd, message, wParam, lParam);
switch (message) {
case WM_CREATE:
break;
case WM_PAINT:
// hdc = BeginPaint (hWnd, &ps);
// SelectObject( hdc, hFont) ;
// EndPaint (hWnd, &ps);
//
// wParam = hdc;
break;
case WM_GETMINMAXINFO:
if (TNC->ClientHeight)
{
mmi = (MINMAXINFO *)lParam;
mmi->ptMaxSize.x = TNC->ClientWidth;
mmi->ptMaxSize.y = TNC->ClientHeight;
mmi->ptMaxTrackSize.x = TNC->ClientWidth;
mmi->ptMaxTrackSize.y = TNC->ClientHeight;
}
break;
case WM_MDIACTIVATE:
{
// Set the system info menu when getting activated
if (lParam == (LPARAM) hWnd)
{
// Activate
RemoveMenu(hBaseMenu, 1, MF_BYPOSITION);
if (TNC->hMenu)
AppendMenu(hBaseMenu, MF_STRING + MF_POPUP, (UINT)TNC->hMenu, "Actions");
SendMessage(ClientWnd, WM_MDISETMENU, (WPARAM) hBaseMenu, (LPARAM) hWndMenu);
// SendMessage(ClientWnd, WM_MDISETMENU, (WPARAM) TNC->hMenu, (LPARAM) TNC->hWndMenu);
}
else
{
// Deactivate
SendMessage(ClientWnd, WM_MDISETMENU, (WPARAM) hMainFrameMenu, (LPARAM) NULL);
}
// call DrawMenuBar after the menu items are set
DrawMenuBar(FrameWnd);
return DefMDIChildProc(hWnd, message, wParam, lParam);
}
case WM_INITMENUPOPUP:
if (wParam == (WPARAM)TNC->hMenu)
{
if (TNC->ProgramPath)
{
if (strstr(TNC->ProgramPath, " TNC") || strstr(TNC->ProgramPath, "ARDOP") || strstr(TNC->ProgramPath, "VARA"))
{
EnableMenuItem(TNC->hMenu, WINMOR_RESTART, MF_BYCOMMAND | MF_ENABLED);
EnableMenuItem(TNC->hMenu, WINMOR_KILL, MF_BYCOMMAND | MF_ENABLED);
break;
}
}
EnableMenuItem(TNC->hMenu, WINMOR_RESTART, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(TNC->hMenu, WINMOR_KILL, MF_BYCOMMAND | MF_GRAYED);
}
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case WINMOR_KILL:
KillTNC(TNC);
break;
case WINMOR_RESTART:
KillTNC(TNC);
RestartTNC(TNC);
break;
case WINMOR_RESTARTAFTERFAILURE:
TNC->RestartAfterFailure = !TNC->RestartAfterFailure;
CheckMenuItem(TNC->hMenu, WINMOR_RESTARTAFTERFAILURE, (TNC->RestartAfterFailure) ? MF_CHECKED : MF_UNCHECKED);
sprintf(Key, "SOFTWARE\\G8BPQ\\BPQ32\\PACTOR\\PORT%d", TNC->Port);
retCode = RegCreateKeyEx(REGTREE, Key, 0, 0, 0, KEY_ALL_ACCESS, NULL, &hKey, &disp);
if (retCode == ERROR_SUCCESS)
{
RegSetValueEx(hKey,"TNC->RestartAfterFailure",0,REG_DWORD,(BYTE *)&TNC->RestartAfterFailure, 4);
RegCloseKey(hKey);
}
break;
case ARDOP_ABORT:
if (TNC->ForcedCloseProc)
TNC->ForcedCloseProc(TNC, 0);
break;
}
return DefMDIChildProc(hWnd, message, wParam, lParam);
case WM_SIZING:
case WM_SIZE:
MoveWindows(TNC);
return DefMDIChildProc(hWnd, message, wParam, lParam);
case WM_SYSCOMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case SC_RESTORE:
TNC->Minimized = FALSE;
break;
case SC_MINIMIZE:
TNC->Minimized = TRUE;
break;
}
return DefMDIChildProc(hWnd, message, wParam, lParam);
case WM_CTLCOLORDLG:
return (LONG)bgBrush;
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, RGB(0, 0, 0));
SetBkMode(hdcStatic, TRANSPARENT);
return (LONG)bgBrush;
}
case WM_DESTROY:
break;
}
return DefMDIChildProc(hWnd, message, wParam, lParam);
}
#endif
BOOL CreatePactorWindow(struct TNCINFO * TNC, char * ClassName, char * WindowTitle, int RigControlRow, WNDPROC WndProc, int Width, int Height, VOID ForcedCloseProc())
{
#ifdef LINBPQ
return FALSE;
#else
WNDCLASS wc;
char Title[80];
int retCode, Type, Vallen;
HKEY hKey=0;
char Key[80];
char Size[80];
int Top, Left;
HANDLE hDlg = 0;
static int LP = 1235;
if (TNC->hDlg)
{
ShowWindow(TNC->hDlg, SW_SHOWNORMAL);
SetForegroundWindow(TNC->hDlg);
return FALSE; // Already open
}
wc.style = CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(BPQICON) );
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = bgBrush;
wc.lpszMenuName = NULL;
wc.lpszClassName = ClassName;
RegisterClass(&wc);
// if (TNC->Hardware == H_WINMOR || TNC->Hardware == H_TELNET ||TNC->Hardware == H_ARDOP ||
// TNC->Hardware == H_V4 || TNC->Hardware == H_FLDIGI || TNC->Hardware == H_UIARQ || TNC->Hardware == H_VARA)
sprintf(Title, "%s Status - Port %d %s", WindowTitle, TNC->Port, TNC->PortRecord->PORTCONTROL.PORTDESCRIPTION);
if (TNC->Hardware == H_UZ7HO)
sprintf(Title, "Rigcontrol for UZ7HO Port %d", TNC->Port);
else if (TNC->Hardware == H_MPSK)
sprintf(Title, "Rigcontrol for MultiPSK Port %d", TNC->Port);
else
sprintf(Title, "%s Status - Port %d %s", WindowTitle, TNC->Port, TNC->PortRecord->PORTCONTROL.PORTDESCRIPTION);
TNC->hDlg = hDlg = CreateMDIWindow(ClassName, Title, 0,
0, 0, Width, Height, ClientWnd, hInstance, ++LP);
// CreateDialog(hInstance,ClassName,0,NULL);
sprintf(Key, "SOFTWARE\\G8BPQ\\BPQ32\\PACTOR\\PORT%d", TNC->Port);
retCode = RegOpenKeyEx (REGTREE, Key, 0, KEY_QUERY_VALUE, &hKey);
if (retCode == ERROR_SUCCESS)
{
Vallen=80;
retCode = RegQueryValueEx(hKey,"Size",0,
(ULONG *)&Type,(UCHAR *)&Size,(ULONG *)&Vallen);
if (retCode == ERROR_SUCCESS)
{
sscanf(Size,"%d,%d,%d,%d,%d",&Rect.left,&Rect.right,&Rect.top,&Rect.bottom, &TNC->Minimized);
if (Rect.top < - 500 || Rect.left < - 500)
{
Rect.left = 0;
Rect.top = 0;
Rect.right = 600;
Rect.bottom = 400;
}
if (Rect.top < OffsetH)
{
int Error = OffsetH - Rect.top;
Rect.top += Error;
Rect.bottom += Error;
}
}
if (TNC->Hardware == H_WINMOR || TNC->Hardware == H_ARDOP)
retCode = RegQueryValueEx(hKey,"TNC->RestartAfterFailure",0,
(ULONG *)&Type,(UCHAR *)&TNC->RestartAfterFailure,(ULONG *)&Vallen);
RegCloseKey(hKey);
}
Top = Rect.top;
Left = Rect.left;
// GetWindowRect(hDlg, &Rect); // Get the real size
MoveWindow(hDlg, Left - (OffsetW /2), Top - OffsetH, Rect.right - Rect.left, Rect.bottom - Rect.top, TRUE);
if (TNC->Minimized)
ShowWindow(hDlg, SW_SHOWMINIMIZED);
else
ShowWindow(hDlg, SW_RESTORE);
TNC->RigControlRow = RigControlRow;
SetWindowText(TNC->xIDC_TNCSTATE, "Free");
TNC->ForcedCloseProc = ForcedCloseProc;
return TRUE;
#endif
}
// WL2K Reporting Code.
static SOCKADDR_IN sinx;
VOID SendReporttoWL2KThread();
VOID SendHTTPReporttoWL2KThread();
VOID CheckWL2KReportTimer()
{
if (WL2KReports == NULL)
return; // Shouldn't happen!
WL2KTimer--;
if (WL2KTimer != 0)
return;
WL2KTimer = 32910; // Every Hour
if (CheckAppl(NULL, "RMS ") == NULL)
if (CheckAppl(NULL, "RELAY ") == NULL)
return;
_beginthread(SendHTTPReporttoWL2KThread, 0, 0);
return;
}
static char HeaderTemplate[] = "POST %s HTTP/1.1\r\n"
"Accept: application/json\r\n"
// "Accept-Encoding: gzip,deflate,gzip, deflate\r\n"
"Content-Type: application/json\r\n"
"Host: %s:%d\r\n"
"Content-Length: %d\r\n"
//r\nUser-Agent: BPQ32(G8BPQ)\r\n"
// "Expect: 100-continue\r\n"
"\r\n{%s}";
char Missing[] = "** Missing **";
VOID GetJSONValue(char * _REPLYBUFFER, char * Name, char * Value)
{
char * ptr1, * ptr2;
strcpy(Value, Missing);
ptr1 = strstr(_REPLYBUFFER, Name);
if (ptr1 == 0)
return;
ptr1 += (strlen(Name) + 1);
ptr2 = strchr(ptr1, '"');
if (ptr2)
{
int ValLen = ptr2 - ptr1;
memcpy(Value, ptr1, ValLen);
Value[ValLen] = 0;
}
return;
}
char APIKey[] = ",\"Key\":\"0D0C7AD6B38C45A7A9534E67111C38A7\"";
VOID SendHTTPRequest(SOCKET sock, char * Host, int Port, char * Request, char * Params, int Len, char * Return)
{
int InputLen = 0;
int inptr = 0;
char Buffer[2048];
char Header[2048];
char * ptr, * ptr1;
int Sent;
strcat(Params, APIKey);
Len += strlen(APIKey);
sprintf(Header, HeaderTemplate, Request, Host, Port, Len + 2, Params);
Sent = send(sock, Header, strlen(Header), 0);
if (Sent == -1)
{
int Err = WSAGetLastError();
Debugprintf("Error %d from WL2K Update send()", Err);
return;
}
while (InputLen != -1)
{
InputLen = recv(sock, &Buffer[inptr], 2048 - inptr, 0);
if (InputLen == -1 || InputLen == 0)
{
int Err = WSAGetLastError();
Debugprintf("Error %d from WL2K Update recv()", Err);
return;
}
// As we are using a persistant connection, can't look for close. Check
// for complete message
inptr += InputLen;
ptr = strstr(Buffer, "\r\n\r\n");
if (ptr)
{
// got header
int Hddrlen = ptr - Buffer;
ptr1 = strstr(Buffer, "Content-Length:");
if (ptr1)
{
// Have content length
int ContentLen = atoi(ptr1 + 16);
if (ContentLen + Hddrlen + 4 == inptr)
{
// got whole response
if (strstr(Buffer, " 200 OK"))
{
if (Return)
{
memcpy(Return, ptr + 4, ContentLen);
Return[ContentLen] = 0;
}
else
Debugprintf("WL2K Database update ok");
}
return;
}
}
else
{
ptr1 = strstr(_strlwr(Buffer), "transfer-encoding:");
if (ptr1)
{
// Just accept anything until I've sorted things with Lee
Debugprintf("WL2K Database update ok");
return;
}
}
}
}
}
VOID SendHTTPReporttoWL2KThread()
{
// Uses HTTP/JSON Interface
struct WL2KInfo * WL2KReport = WL2KReports;
char * LastHost = NULL;
char * LastRMSCall = NULL;
char Message[512];
int LastSocket = 0;
SOCKET sock = 0;
struct sockaddr_in destaddr;
int addrlen=sizeof(sinx);
struct hostent * HostEnt;
int err;
u_long param=1;
BOOL bcopt=TRUE;
int Len;
// Send all reports in list
while (WL2KReport)
{
// Resolve Name if needed
if (LastHost && strcmp(LastHost, WL2KReport->Host) == 0) // Same host?
goto SameHost;
// New Host - Connect to it
LastHost = WL2KReport->Host;
destaddr.sin_family = AF_INET;
destaddr.sin_addr.s_addr = inet_addr(WL2KReport->Host);
destaddr.sin_port = htons(WL2KReport->WL2KPort);
if (destaddr.sin_addr.s_addr == INADDR_NONE)
{
// Resolve name to address
Debugprintf("Resolving %s", WL2KReport->Host);
HostEnt = gethostbyname (WL2KReport->Host);
if (!HostEnt)
{
err = WSAGetLastError();
Debugprintf("Resolve Failed for %s %d %x", WL2KReport->Host, err, err);
return; // Resolve failed
}
memcpy(&destaddr.sin_addr.s_addr,HostEnt->h_addr,4);
}
// Allocate a Socket entry
if (sock)
closesocket(sock);
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET)
return;
// ioctlsocket(sock, FIONBIO, ¶m);
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const char FAR *)&bcopt, 4);
destaddr.sin_family = AF_INET;
if (sock == INVALID_SOCKET)
{
sock = 0;
return;
}
setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (const char FAR *)&bcopt,4);
// Connect to Host
if (connect(sock,(LPSOCKADDR) &destaddr, sizeof(destaddr)) != 0)
{
err=WSAGetLastError();
//
// Connect failed
//
Debugprintf("Connect Failed");
closesocket(sock);
sock = 0;
break;
}
SameHost:
Len = sprintf(Message,
"\"Callsign\":\"%s\","
"\"BaseCallsign\":\"%s\","
"\"GridSquare\":\"%s\","
"\"Frequency\":%d,"
"\"Mode\":%d,"
"\"Baud\":%d,"
"\"Power\":%d,"
"\"Height\":%d,"
"\"Gain\":%d,"
"\"Direction\":%d,"
"\"Hours\":\"%s\","
"\"ServiceCode\":\"%s\"",
WL2KReport->RMSCall, WL2KReport->BaseCall, WL2KReport->GridSquare,
WL2KReport->Freq, WL2KReport->mode, WL2KReport->baud, WL2KReport->power,
WL2KReport->height, WL2KReport->gain, WL2KReport->direction,
WL2KReport->Times, WL2KReport->ServiceCode);
Debugprintf("Sending %s", Message);
SendHTTPRequest(sock, WL2KReport->Host, WL2KReport->WL2KPort,
"/channel/add", Message, Len, NULL);
// Send Version Message
if (LastRMSCall == NULL || strcmp(WL2KReport->RMSCall, LastRMSCall) != 0)
{
int Len;
LastRMSCall = WL2KReport->RMSCall;
// "Callsign":"String","Program":"String","Version":"String","Comments":"String"
Len = sprintf(Message, "\"Callsign\":\"%s\",\"Program\":\"BPQ32\","
"\"Version\":\"%d.%d.%d.%d\",\"Comments\":\"Test Comment\"",
WL2KReport->RMSCall, Ver[0], Ver[1], Ver[2], Ver[3]);
Debugprintf("Sending %s", Message);
SendHTTPRequest(sock, WL2KReport->Host, WL2KReport->WL2KPort,
"/version/add", Message, Len, NULL);
}
WL2KReport = WL2KReport->Next;
}
Sleep(100);
closesocket(sock);
sock = 0;
}
struct WL2KInfo * DecodeWL2KReportLine(char * buf)
{
//06'<callsign>', '<base callsign>', '<grid square>', <frequency>, <mode>, <baud>, <power>,
// <antenna height>, <antenna gain>, <antenna direction>, '<hours>', <group reference>, '<service code>'
// WL2KREPORT service, www.winlink.org, 8778, GM8BPQ, IO68VL, 00-23, 144800000, PKT1200, 10, 20, 5, 0, BPQTEST
char * Context;
char * p_cmd;
char * param;
char errbuf[256];
struct WL2KInfo * WL2KReport = zalloc(sizeof(struct WL2KInfo));
char * ptr;
char Param[8][256];
char * ptr1, * ptr2;
int n = 0;
memset(Param, 0, 2048);
strcpy(errbuf, buf);
p_cmd = strtok_s(&buf[10], ", \t\n\r", &Context);
if (p_cmd == NULL) goto BadLine;
strcpy(WL2KReport->ServiceCode, p_cmd);
// Can default Host and Port, so cant use strtok for them
ptr1 = Context;
while (ptr1 && *ptr1 && n < 2)
{
while(ptr1 && *ptr1 && *ptr1 == ' ')
ptr1++;
ptr2 = strchr(ptr1, ',');
if (ptr2) *ptr2++ = 0;
strcpy(&Param[n][0], ptr1);
strlop(Param[n++], ' ');
ptr1 = ptr2;
}
if (n < 2)
goto BadLine;
if (Param[1][0] == 0)
WL2KReport->WL2KPort = 80; // HTTP Interface
else
WL2KReport->WL2KPort = atoi(&Param[1][0]);
if (Param[0][0] == 0)
WL2KReport->Host = _strdup("api.winlink.org");
else
{
_strlwr(&Param[0][0]);
if (strstr(&Param[0][0], "winlink.org"))
{
WL2KReport->WL2KPort = 80; // HTTP Interface
WL2KReport->Host = _strdup("api.winlink.org");
}
else
WL2KReport->Host = _strdup(&Param[0][0]);
}
Context = ptr1;
p_cmd = strtok_s(NULL, ", \t\n\r", &Context);
if (p_cmd == NULL) goto BadLine;
if (WL2KReport->WL2KPort == 0) goto BadLine;
strcpy(WL2KReport->RMSCall, p_cmd);
strcpy(WL2KReport->BaseCall, p_cmd);
strlop(WL2KReport->BaseCall, '-'); // Remove any SSID
strcpy(WL2KCall, WL2KReport->BaseCall); // For SYSOP Update
p_cmd = strtok_s(NULL, " ,\t\n\r", &Context);
if (p_cmd == NULL) goto BadLine;
if (strlen(p_cmd) != 6) goto BadLine;
strcpy(WL2KReport->GridSquare, p_cmd);
strcpy(WL2KLoc, p_cmd);
p_cmd = strtok_s(NULL, " ,\t\n\r", &Context);
if (p_cmd == NULL) goto BadLine;
if (strlen(p_cmd) > 79) goto BadLine;
// Convert any : in times to comma
ptr = strchr(p_cmd, ':');
while (ptr)
{
*ptr = ',';
ptr = strchr(p_cmd, ':');
}
strcpy(WL2KReport->Times, p_cmd);
p_cmd = strtok_s(NULL, " ,\t\n\r", &Context);
if (p_cmd == NULL) goto BadLine;
WL2KReport->Freq = atoi(p_cmd);
if (WL2KReport->Freq == 0) // Invalid
goto BadLine;
param = strtok_s(NULL, " ,\t\n\r", &Context);
// Mode Designator - one of
// PKTnnnnnn
// WINMOR500
// WINMOR1600
// ROBUST
// P1 P12 P123 P1234 etc
if (memcmp(param, "PKT", 3) == 0)
{
int Speed, Mode;
Speed = atoi(¶m[3]);
WL2KReport->baud = Speed;
if (Speed <= 1200)
Mode = 0; // 1200
else if (Speed <= 2400)
Mode = 1; // 2400
else if (Speed <= 4800)
Mode = 2; // 4800
else if (Speed <= 9600)
Mode = 3; // 9600
else if (Speed <= 19200)
Mode = 4; // 19200
else if (Speed <= 38400)
Mode = 5; // 38400
else
Mode = 6; // >38400
WL2KReport->mode = Mode;
}
else if (_stricmp(param, "WINMOR500") == 0)
WL2KReport->mode = 21;
else if (_stricmp(param, "WINMOR1600") == 0)
WL2KReport->mode = 22;
else if (_stricmp(param, "ROBUST") == 0)
{
WL2KReport->mode = 30;
WL2KReport->baud = 600;
}
else if (_stricmp(param, "ARDOP200") == 0)
WL2KReport->mode = 40;
else if (_stricmp(param, "ARDOP500") == 0)
WL2KReport->mode = 41;
else if (_stricmp(param, "ARDOP1000") == 0)
WL2KReport->mode = 42;
else if (_stricmp(param, "ARDOP2000") == 0)
WL2KReport->mode = 43;
else if (_stricmp(param, "ARDOP2000FM") == 0)
WL2KReport->mode = 44;
else if (_stricmp(param, "P1") == 0)
WL2KReport->mode = 11;
else if (_stricmp(param, "P12") == 0)
WL2KReport->mode = 12;
else if (_stricmp(param, "P123") == 0)
WL2KReport->mode = 13;
else if (_stricmp(param, "P2") == 0)
WL2KReport->mode = 14;
else if (_stricmp(param, "P23") == 0)
WL2KReport->mode = 15;
else if (_stricmp(param, "P3") == 0)
WL2KReport->mode = 16;
else if (_stricmp(param, "P1234") == 0)
WL2KReport->mode = 17;
else if (_stricmp(param, "P234") == 0)
WL2KReport->mode = 18;
else if (_stricmp(param, "P34") == 0)
WL2KReport->mode = 19;
else if (_stricmp(param, "P4") == 0)
WL2KReport->mode = 20;
else if (_stricmp(param, "VARA") == 0)
WL2KReport->mode = 50;
else
goto BadLine;
param = strtok_s(NULL, " ,\t\n\r", &Context);
// Optional Params
WL2KReport->power = (param)? atoi(param) : 0;
param = strtok_s(NULL, " ,\t\n\r", &Context);
WL2KReport->height = (param)? atoi(param) : 0;
param = strtok_s(NULL, " ,\t\n\r", &Context);
WL2KReport->gain = (param)? atoi(param) : 0;
param = strtok_s(NULL, " ,\t\n\r", &Context);
WL2KReport->direction = (param)? atoi(param) : 0;
WL2KTimer = 60;
WL2KReport->Next = WL2KReports;
WL2KReports = WL2KReport;
return WL2KReport;
BadLine:
WritetoConsole(" Bad config record ");
WritetoConsole(errbuf);
WritetoConsole("\r\n");
return 0;
}
VOID UpdateMHSupport(struct TNCINFO * TNC, UCHAR * Call, char Mode, char Direction, char * Loc);
VOID UpdateMHEx(struct TNCINFO * TNC, UCHAR * Call, char Mode, char Direction, char * LOC)
{
UpdateMHSupport(TNC, Call, Mode, Direction, LOC);
}
VOID UpdateMH(struct TNCINFO * TNC, UCHAR * Call, char Mode, char Direction)
{
UpdateMHSupport(TNC, Call, Mode, Direction, NULL);
}
VOID UpdateMHSupport(struct TNCINFO * TNC, UCHAR * Call, char Mode, char Direction, char * Loc)
{
PMHSTRUC MH = TNC->PortRecord->PORTCONTROL.PORTMHEARD;
PMHSTRUC MHBASE = MH;
UCHAR AXCall[8];
int i;
char * LOC, * LOCEND;
char ReportMode[20];
char NoLOC[7] = "";
double Freq;
char ReportFreq[350] = "";
if (MH == 0) return;
ConvToAX25(Call, AXCall);
AXCall[6] |= 1; // Set End of address
// Adjust freq to centre
// if (Mode != ' ' && TNC->RIG->Valchar[0])
if (TNC->RIG->Valchar[0])
{
Freq = atof(TNC->RIG->Valchar) + 0.0015;
_gcvt(Freq, 9, ReportFreq);
}
if (TNC->Hardware == H_ARDOP)
{
LOC = memchr(Call, '[', 20);
if (LOC)
{
LOCEND = memchr(Call, ']', 30);