forked from Discriminator/PDW
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
11225 lines (9069 loc) · 334 KB
/
main.cpp
File metadata and controls
11225 lines (9069 loc) · 334 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
// main.cpp
//
// Main module of the PDW program.
//
// Authors:
//
// Peter Hunt (PH)
// Rutger A. Heunks (RAH)
// Andreas Verhoeven (AVE)
// Danny D. (DD)
// Andrey Grodzovsky (AG)
// discriminator.nl (DNL)
// Fred N. van Kempen (FVK)
//
// See the CHANGELOG file for a history of (most) changes.
//
// FILTERS.INI lines :
//
// Filter1=0,"1234567","Description / label","text",1,2,3,4,5,"sepfile",118,20-04-04,16:22:22
//
// 0: 1=FLEX , 2=POCSAG , 3=TEXT
// 1: 1=Reject / 2=Monitor-only
// 2: Wavenumber
// 3: 1=CMD-enabled
// 4: 1=Label-enabled += label-color
// 5: 1=SEP-enabled , 2=SEP-HTML , 4=SEP-FTP , 8=SMTP , 16=Match exact text
//
#include <windows.h>
#include <commctrl.h>
#include <shlobj.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "pdw.h"
#include "resource.h"
#include "language.h"
#include "gfx.h"
#include "misc.h"
#include "menu.h"
#include "printer.h"
#include "sigind.h"
#include "smtp.h"
#include "sound_in.h"
#include "toolbar.h"
#include "version.h"
#include "utils/rs232.h"
#include "utils/debug.h"
#include "utils/ostype.h"
#include "utils/messagequeue.h" // FIXME: NICO
#include "utils/utils.h"
#include "decode/acars.h"
#include "decode/ermes.h"
#include "decode/flex.h"
#include "decode/mobitex.h"
#include "decode/pocsag.h"
#include "decode/decode.h"
#define MIN_X_WIN_SIZE 444 // Smallest main win X size can be (was 444)
#define MIN_Y_WIN_SIZE 261 // Smallest main win Y size can be (was 261)
#define TOOLBAR_SIZE 49 // Space for Toolbar/Top of Pane1 (was 52)
#define WIN_DIVIDER_SIZE 19 // Pane1/Pane2 seperator size (was 56)
#define PANE1_SIZE 1000 // Pane1 default scrollback size
#define PANE2_SIZE 200 // Pane2 default scrollback size
#define PDW_TIMER 101 // Timer ID
#define SCROLL_TIMER 102
#define SECOND_TIMER 103 // Timer ID
#define MINUTE_TIMER 104 // Timer ID
#define CLICK_TIMER 105 // Timer ID
#define WM_MOUSEWHEEL 0x020A
#define HMENU_MAIN 1
#define HMENU_FILTERS 2
#define HMENU_SYSTRAY 3
#define DRIVER_NOT_LOADED 0
#define DRIVER_VXD_LOADED 1
#define DRIVER_COM_LOADED 2
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
PROFILE Profile; // User profile information
HANDLE hDriver = 0; // Handle of Virtual Device
int *pComPorts; // Array with available comports
int bWin9x;
int nDriverLoaded = DRIVER_NOT_LOADED; // VxD/comport loaded?
int bEditFilter = FALSE; // Set before/after calling edit dialog
int bPauseFlag = FALSE; // Decides if message output is paused.
int bUpdateFilters = FALSE; // PH: Needs FILTERS.INI to be updated?
int nCount_Messages = 0; // PH: Counts # Messages
int nCount_Groupcalls = 0; // PH: Counts # Groupcalls
int nCount_Biterrors = 0; // PH: Counts # Message-biterrors
int nCount_Rejected = 0; // PH: Counts # Rejected Messages
int nCount_Blocked = 0; // PH: Counts # Blocked Messages
int nCount_Missed[2] = { 0,0 }; // PH: Counts # Missed Groupcalls
int nCount_BlockBuffer[2] = { 0,0 }; // PH: Counts # Block Buffer
//int iDebug_Test = 0;
int iMouseClick = 0; // PH: Used for detecting double click
//int Notification=0; // PH: Used for notification windows
int bTrayed=FALSE; // PH: Is TRUE if trayed
int bLBUTTONDBLCLK=FALSE; // PH: Is TRUE after 2 WM_LBUTTONDOWN messages
int bFilterFindCASE=FALSE; // PH: Filter Find Case Sensitive?
int iTEMP = 0; // Global temporary int
char szTEMP[MAX_STR_LEN]; // Global temporary buffer
int iDuplicateFilter=0;
char szFilenameDate[16]; // PH: Global buffer for date as filename
char szDebugStarted[32]; // PH: Time and date when PDW has been started
char szWindowText[6][1000]; // [0] = PDW version
// [1] = SPARE
// [2] = Current mode
// [3] = FLEX/ERMES cycle/frame(/batch)
// [4] = FLEX - Groupcall
// [5] = Rejected/Blocked messages
// Text editing globals
unsigned int iSelectionStartCol, iSelectionStartRow, iSelectionEndCol, iSelectionEndRow;
int select_on = 0, selected = 0, selecting = 0;
PaneStruct *select_pane; // selects pain to copy text from
// The following COLORREFS are used while changing POCSAG/FLEX colors
COLORREF custom_colors[16];
COLORREF tmp_background;
COLORREF tmp_address;
COLORREF tmp_timestamp;
COLORREF tmp_modetypebit;
COLORREF tmp_numeric;
COLORREF tmp_message;
COLORREF tmp_misc;
COLORREF tmp_filterlabel;
COLORREF tmp_filtermatch;
COLORREF tmp_biterrors;
// Tempory fonts-see gfx.c for other fonts
HFONT tmp_hfont=NULL;
LOGFONT tmp_logfont;
time_t tStarted; // Contains the time when PDW was started
// If copy upper/lower pane or just copy is successful then this flag is set to TRUE.
int bOK_to_save=FALSE;
// RAH: record and playback stuff
OPENFILENAME openplayback;
OPENFILENAME openrecording;
char szPlayback[MAX_PATH];
char szRecording[MAX_PATH];
//HWi
typedef enum sroll {
scrollNull,
scrollUp,
scrollDown
} EScrollDirection;
HIMAGELIST hDragImageList;
LPNMHDR pnmhdr;
int bDragging, bDragLine;
int bSortingFilters, bDeletingFilters;
LVHITTESTINFO lvhti;
HWND hListView, hDebugDlg, hSystemTrayDlg, hFilterDlg, hCurrentHWND;
int m_uScrollTimer, m_ScrollDirection, m_nScrollOffset, m_nDropIndex=-1;
int nCopyStart=-1, nCopyEnd=-1;
void OnBeginDrag(NMHDR* pnmhdr);
void InitListControl(HWND hDlg);
int WINAPI InsertListViewItem(char *szLine, int nItem);
void OnMouseMove(UINT nFlags, int x, int y);
void OnMouseWheel(WPARAM wParam, int x, int y, RECT g_rect);
void OnLButtonUp(UINT nFlags, int x, int y);
void DropItemOnList(int x, int y);
void OnTimer(UINT nIDEvent);
void KillScrollTimer(void);
void SetScrollTimer(EScrollDirection ScrollDirection);
LONG OnCustomDraw(LPNMLVCUSTOMDRAW lpDraw);
void SortFilter(HWND hDlg, int bAddress);
int CheckSelection(int bMore);
int CompareCapcodes(char *szCapcode1, char *szCapcode2);
void CopyFilter(void);
void PasteFilter(void);
void ResetHitcounters(int bAll);
void ShowContextMenu(int menu, HWND hWindow);
void GoogleMaps(int iPosition);
void SelectByDoubleClick(HWND hWnd, PaneStruct *pane, int iPosition, int StartRow);
int FindFilter(int index, char *szSearchString, int bShowHits, int bBackwards);
void pumpMessages(void);
DWORD GetColorRGB(BYTE color);
void AutoRecording(); // PH: temp/test
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow)
{
MSG msg;
//FIXME: first of all, process commandline options. --FVK
// PH: Set version info in szWindowText buffer
//FIXME: optionally use commandline arg here! --FVK
sprintf(szWindowText[0], " %s %s", APP_NAME, APP_VERSION);
// Initialize global variables.
ghWnd = NULL;
ghInstance = hInst;
ZeroMemory(&openplayback, sizeof(openplayback));
ZeroMemory(&openrecording,sizeof(openrecording));
openplayback.lStructSize = sizeof(openplayback);
openrecording.lStructSize = sizeof(openrecording);
szPlayback[0] = '\0';
// Initialize the user profile.
ZeroMemory(&Profile, sizeof(Profile));
Profile.LabelLog = 1; // flag for labels in monitored-logfile
Profile.LabelNewline = 1; // flag for labels on new line
Profile.Linefeed = 1; // flag for converting » to linefeed
Profile.Separator = 1; // flag for separating messages (empty line)
Profile.MonthNumber = 1; // flag for using monthnumber in logfilenames
Profile.FilterWindowColors = 1; // flag for showing label colors in filterwindow
Profile.FilterWindowExtra = 1; // flag for showing CMD/DESC/SEP/etc in filterwindow
Profile.xPos = 0;
Profile.yPos = 0;
Profile.xSize = 593;
Profile.ySize = 442;
Profile.showtone = 1;
Profile.shownumeric = 1;
Profile.showmisc = 1;
Profile.confirmExit = 1;
Profile.decodepocsag = 1;
Profile.decodeflex = 1;
Profile.showinstr = 1; // PH: Show Short Instructions
Profile.convert_si = 1; // PH: Convert Short Instructions to textmessage
Profile.pocsag_512 = 1;
Profile.pocsag_1200 = 1;
Profile.pocsag_2400 = 1;
Profile.pocsag_fnu = 0;
Profile.pocsag_showboth = 0;
Profile.flex_1600 = 1;
Profile.flex_3200 = 1;
Profile.flex_6400 = 1;
Profile.acars_parity_check = 0;
Profile.comPortEnabled = 0;
Profile.comPort = 2;
Profile.comPortRS232 = 0;
Profile.comPortAddr = 0x2F8;
Profile.comPortIRQ = 3;
Profile.invert = 0; // Current invert status. 0=No,1=Yes
Profile.fourlevel = 0;
Profile.percent = 65; // Set pane1 to 65% of client area
// setup default font information
Profile.fontInfo.lfHeight = -11;
Profile.fontInfo.lfWidth = 0;
Profile.fontInfo.lfEscapement = 0;
Profile.fontInfo.lfOrientation = 0;
Profile.fontInfo.lfWeight = FW_NORMAL;
Profile.fontInfo.lfItalic = 0;
Profile.fontInfo.lfUnderline = 0;
Profile.fontInfo.lfStrikeOut = 0;
Profile.fontInfo.lfCharSet = OEM_CHARSET;
Profile.fontInfo.lfOutPrecision = OUT_STROKE_PRECIS;
Profile.fontInfo.lfClipPrecision = CLIP_DEFAULT_PRECIS;
Profile.fontInfo.lfQuality = DEFAULT_QUALITY;
Profile.fontInfo.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
lstrcpy(Profile.fontInfo.lfFaceName, "Courier New");
Profile.reverse_msg = FALSE; // flag to reverse message output.
Profile.lang_mi_index = 0; // set default language menu item.
Profile.lang_tbl_index= 0; // decides language character map.
Profile.logfile_enabled = 1;
Profile.logfile_use_date = 1;
Profile.maximize_flg = 1;
Profile.filterfile_enabled = 1;
Profile.filterfile_use_date = 1;
Profile.filters.clear();
// COLORS.
Profile.color_background = RGB(rgbColor[BLACK][0], rgbColor[BLACK][1], rgbColor[BLACK][2]);
Profile.color_address = RGB(rgbColor[WHITE][0], rgbColor[WHITE][1], rgbColor[WHITE][2]);
Profile.color_modetypebit = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
Profile.color_timestamp = RGB(rgbColor[LTBLUE][0], rgbColor[LTBLUE][1], rgbColor[LTBLUE][2]);
Profile.color_numeric = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
Profile.color_message = RGB(rgbColor[LTCYAN][0], rgbColor[LTCYAN][1], rgbColor[LTCYAN][2]);
Profile.color_misc = RGB(rgbColor[BROWN][0], rgbColor[BROWN][1], rgbColor[BROWN][2]);
Profile.color_biterrors = RGB(rgbColor[LTGRAY][0], rgbColor[LTGRAY][1], rgbColor[LTGRAY][2]);
Profile.color_filtermatch = RGB(rgbColor[LTGREEN][0], rgbColor[LTGREEN][1],rgbColor[LTGREEN][2]);
Profile.color_instructions = RGB(rgbColor[LTCYAN][0], rgbColor[LTCYAN][1], rgbColor[LTCYAN][2]);
Profile.color_ac_message_nr = RGB(rgbColor[WHITE][0], rgbColor[WHITE][1], rgbColor[WHITE][2]);
Profile.color_ac_dbi = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
Profile.color_mb_sender = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
// Filter label colors
Profile.color_filterlabel[0] = RGB(rgbColor[LTBLUE][0], rgbColor[LTBLUE][1], rgbColor[LTBLUE][2]);
Profile.color_filterlabel[1] = RGB(rgbColor[YELLOW][0], rgbColor[YELLOW][1], rgbColor[YELLOW][2]);
Profile.color_filterlabel[2] = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
Profile.color_filterlabel[3] = RGB(0xFF, 0xAA, 0x00); /* orange */
Profile.color_filterlabel[4] = RGB(rgbColor[LTBLUE][0], rgbColor[LTBLUE][1], rgbColor[LTBLUE][2]);
Profile.color_filterlabel[5] = RGB(rgbColor[CYAN][0], rgbColor[CYAN][1], rgbColor[CYAN][2]);
Profile.color_filterlabel[6] = RGB(rgbColor[WHITE][0], rgbColor[WHITE][1], rgbColor[WHITE][2]);
Profile.color_filterlabel[7] = RGB(rgbColor[LTGREEN][0], rgbColor[LTGREEN][1], rgbColor[LTGREEN][2]);
Profile.color_filterlabel[8] = RGB(rgbColor[LTGRAY][0], rgbColor[LTGRAY][1], rgbColor[LTGRAY][2]);
Profile.color_filterlabel[9] = RGB(rgbColor[BROWN][0], rgbColor[BROWN][1], rgbColor[BROWN][2]);
Profile.color_filterlabel[10] = RGB(rgbColor[LTCYAN][0], rgbColor[LTCYAN][1], rgbColor[LTCYAN][2]);
Profile.color_filterlabel[11] = RGB(0x00, 0x33, 0x99); /* navy blue */
Profile.color_filterlabel[12] = RGB(0xFF, 0x00, 0xFF); /* magenta */
Profile.color_filterlabel[13] = RGB(0x33, 0xCC, 0x99); /* sea green */
Profile.color_filterlabel[14] = RGB(0xFF, 0x99, 0xCC); /* pink */
Profile.color_filterlabel[15] = RGB(0x99, 0xFF, 0xFF); /* ice blue */
Profile.color_filterlabel[16] = RGB(0x99, 0xFF, 0xCC); /* turquoise */
Profile.pane1_size = PANE1_SIZE;
Profile.pane2_size = PANE2_SIZE;
Profile.ScrollSpeed = 1;
Profile.stat_file_enabled = 0;
Profile.stat_file[0] = '\0';
Profile.stat_file_use_date = 0;
// These control Audio input.
Profile.audioEnabled = 1;
Profile.audioDevice = 0;
Profile.audioSampleRate = 44100;
Profile.audioConfig = 5; // audio input configuration
Profile.audioThreshold[4] = 0;
Profile.audioResync[4] = 0;
Profile.audioCentering[4] = 0;
SetAudioConfig(Profile.audioConfig); // set default audio config
// Keep track of minimized state (user could exit while minimized)
Profile.minimize_flg = 0;
// Default is to decode POCSAG/FLEX signals.
Profile.monitor_paging = TRUE;
Profile.monitor_acars = FALSE;
Profile.monitor_mobitex = FALSE;
Profile.monitor_ermes = FALSE;
nOSType = GetOSType(NULL); // HWi
bWin9x = (nOSType < OS_WIN2000) ? TRUE : FALSE;
if (!hPrevInst && !InitApplication(hInst)) {
ErrorMessageBox(TEXT("InitApplication() Failed"),
szApiFailedMsg, lpszSourceFileName, __LINE__);
return FALSE;
}
// Check if PDW is already running
CreateMutex(NULL, FALSE, szPath);
// Shut down, as an instance of PDW is already running in this folder
if (GetLastError() == ERROR_ALREADY_EXISTS) {
MessageBox(ghWnd, "PDW is already running", "Warning", MB_ICONINFORMATION);
return FALSE;
}
if ((ghWnd = InitInstance(hInst, nCmdShow)) == NULL) {
ErrorMessageBox(TEXT("InitInstance() Failed"),
szApiFailedMsg, lpszSourceFileName, __LINE__);
return FALSE;
}
// keep toolbar correct size!
if (hToolbar)
TB_AutoSize(hToolbar);
// Load Acars data base files.
acars.read_data();
// Load language tables and add languge menu items.
read_language_tables();
set_lang_menu();
// Check/Uncheck required menu items.
set_menu_items();
// PH: Set Max_X_Client / iMaxWidth / NewLinePoint
SetWindowPaneSize(WINDOW_SIZE);
Get_Date_Time();
sprintf(szDebugStarted, "%s %s", szCurrentDate, szCurrentTime);
// Put all available comports in array pComports
pComPorts = rs232_find_ports();
tStarted = time(NULL); // Time when PDW was started
// Load VxD if using serial port else see if using sound card
if (Profile.comPortEnabled && !nDriverLoaded) {
if (LoadDriver()) {
// start timer.
SetTimer(ghWnd, PDW_TIMER, 100, (TIMERPROC)NULL);
}
} else if (Profile.audioEnabled && !bCapturing) {
if (Start_Capturing()) {
// start timer.
SetTimer(ghWnd, PDW_TIMER, 100, (TIMERPROC)NULL);
}
}
#if 0 //FIXME: NICO
if (Profile.MESSAGE_QUEUE)
StartMQMonitor();
#endif
// start minute and second timers
SetTimer(ghWnd, MINUTE_TIMER, 1000*60, (TIMERPROC)NULL);
SetTimer(ghWnd, SECOND_TIMER, 1000, (TIMERPROC)NULL);
if (Max_X_Client < 800) {
// PH: Check if the screen width is less than 800
MessageBox(ghWnd, "WARNING! PDW is optimized for 800x600 resolution (and higher)\nYour computer seems to be using a lower resolution...", "PDW Resolution", MB_ICONWARNING);
}
while (GetMessage(&msg, NULL, 0, 0)) {
if (! TranslateAccelerator(ghWnd, ghAccel, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
// Used if WM_CREATE fails or when program exits.
void
Free_Common_Objects(void)
{
if (Pane1.buff_char != NULL)
free(Pane1.buff_char);
if (Pane1.buff_color != NULL)
free(Pane1.buff_color);
if (Pane2.buff_char != NULL)
free(Pane2.buff_char);
if (Pane2.buff_color != NULL)
free(Pane2.buff_color);
Free_Drawing_Objects(); // see gfx.cpp
FreeSysObjects(); // see gfx.cpp
FreeLogFONTS(); // see gfx.cpp
FreeSigInd(); // see sigind.cpp
FreeToolBarImages(ghInstance); // free toolbar button bitmaps
}
LRESULT CALLBACK
PDWWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC ghDC;
TEXTMETRIC g_tm;
static RECT g_rect = {0};
RECT g_sys_rect;
size_t g_mem_size;
LPMINMAXINFO lpMMI;
time_t lTime;
struct tm *recTm;
int g_xNew, g_yNew, g_scrollSize;
unsigned int g_min_col, g_max_col, g_min_row, g_max_row, g_index;
char szFile[MAX_PATH];
char filters_reload[64]; // PH: Buffer for reloading filters
char filters_temp[64]; // PH: Buffer for reloading filters
int pane1 = FALSE;
extern int bMode_IDLE; // Set if no signal
extern int bEmpty_Frame; // Set if FLEX-Frame=EMTPY / ERMES-Batch=0
extern unsigned long int aMessages[1000][3]; // PH: Array used for blocking messages
int BlockTimer = (Profile.BlockDuplicate >> 4) * 60;
switch (uMsg) {
case WM_TIMER: // Decode POCSAG/FLEX with comport or sound card.
if (! bPauseFlag) {
// RAH: Playing recording?
if (bPlayback)
pdw_playback();
else {
// Log messages/statistics & Update signal indicator.
if (nDriverLoaded)
pdw_decode();
else if (bCapturing) {
// Using sound card?
Process_ReadyBuffers(hWnd);
}
}
switch (wParam) {
case SECOND_TIMER:
DrawPaneLabels(ghWnd, PANERXQUAL);
// Get current systemtime
lTime = time(NULL);
iSecondsElapsed = (unsigned long)difftime(lTime, tStarted);
if (BlockTimer) {
while (aMessages[0][0] && (iSecondsElapsed > (aMessages[0][1] + BlockTimer))) {
// First entry Overdue?
memmove(aMessages[0], aMessages[1], sizeof(aMessages)); // Move entries
nCount_BlockBuffer[0]--;
}
}
if (hDebugDlg)
SendMessage(hDebugDlg, WM_WININICHANGE, 0, 0L);
break;
case MINUTE_TIMER: // Handle minute timer
if (bMode_IDLE || bEmpty_Frame || Profile.monitor_acars || Profile.monitor_mobitex) {
if (bUpdateFilters) {
WriteFilters(&Profile, 0); // PH: Save FILTERS.INI
bUpdateFilters = FALSE; // PH: Reset for new messages
}
}
lTime = time(NULL);
recTm = localtime(&lTime);
if ((recTm->tm_mon == 4) && (recTm->tm_mday == 4)) strcpy(szWindowText[1], "Today is Peter Hunt's birthday :-)");
else if ((recTm->tm_mon == 11) && ((recTm->tm_mday == 25) || (recTm->tm_mday == 26))) strcpy(szWindowText[1], "Merry Christmas!");
else if ((recTm->tm_mon == 0) && (recTm->tm_mday == 1)) strcpy(szWindowText[1], "Happy New Year!");
else strcpy(szWindowText[1], "");
// Check if there is a "PDW Resolution" dialog
if (FindWindow(NULL, "PDW Resolution")) {
// Close it
PostMessage(FindWindow(NULL, "PDW Resolution"), WM_CLOSE, 0, 0L);
}
if (bAutoRecording) {
AutoRecording(); // PH: temp/test
}
break;
case CLICK_TIMER: // Handle click timer
KillTimer(ghWnd, CLICK_TIMER); // Stop Click Timer
iMouseClick = 0;
break;
}
}
break;
case WM_POWERBROADCAST:
OUTPUTDEBUGMSG((("WM_POWERBROADCAST PowerMode = 0x%08lX Data 0x%08lX\n"), (DWORD) wParam, (DWORD) lParam));
if (bWin9x) {
switch (wParam) {
case PBT_APMRESUMECRITICAL:
case PBT_APMRESUMESUSPEND:
case PBT_APMRESUMESTANDBY:
case PBT_APMRESUMEAUTOMATIC:
OUTPUTDEBUGMSG((("Out of Suspend: Reload VxD!\n")));
UnloadDriver();
pd_reset_all();
if (LoadDriver()) {
SetTimer(ghWnd, PDW_TIMER, 100, (TIMERPROC) NULL);
}
break;
default:
break;
}
}
break;
case WM_PAINT: // Keep main gfx data valid
PAINTSTRUCT pdw_ps;
BeginPaint(hWnd, &pdw_ps);
DrawSigInd(hWnd); // draw the signal indicator
DrawTitleBarGfx(hWnd); // draw pane1/pane2 title bars
EndPaint(hWnd, &pdw_ps);
break;
case WM_NOTIFY: // If we receive this message, need to get toolbar tooltip text
switch (((LPNMHDR)lParam)->code) {
case TTN_NEEDTEXT:
SetToolTXT(ghInstance, lParam);
break;
default:
DrawSigInd(hWnd); // draw the signal indicator
break;
}
// Draw pane1/pane2 title bars
DrawTitleBarGfx(hWnd);
break;
case WM_CREATE:
Pane1.buff_char = NULL;
Pane1.buff_color = NULL;
Pane2.buff_char = NULL;
Pane2.buff_color = NULL;
if (! LoadSigInd(ghInstance))
return -1;
// Get general purpose drawing objects.
if (! GetSysObjects(hWnd)) {
// Free any objects we got!
Free_Common_Objects();
return -1; // these use standard system colors
}
// Get general purpose font objects.
if (! GetLogFONTS()) {
// Free any objects we got!
Free_Common_Objects();
return -1;
}
// Display tool bar
if (! (hToolbar = (HWND)ShowMakeToolBar(hWnd, ghInstance))) {
// Free any objects we got!
Free_Common_Objects();
return -1;
}
hfont = CreateFontIndirect(&Profile.fontInfo);
ghDC = GetDC(hWnd);
SelectObject(ghDC, hfont);
GetTextMetrics(ghDC, &g_tm);
cxChar = g_tm.tmAveCharWidth;
cxCaps = (g_tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;
cyChar = g_tm.tmHeight + g_tm.tmExternalLeading;
ReleaseDC(hWnd, ghDC);
g_mem_size = (Profile.pane1_size+1) * (LINE_SIZE+1);
Pane1.buff_char = (char *)malloc(g_mem_size);
Pane1.buff_color = (BYTE *)malloc(g_mem_size);
if ((Pane1.buff_char == NULL) || (Pane1.buff_color == NULL)) {
if (Pane1.buff_char != NULL)
free(Pane1.buff_char);
Pane1.buff_char = NULL;
if (Pane1.buff_color != NULL)
free(Pane1.buff_color);
Pane1.buff_color = NULL;
Profile.pane1_size = PANE1_SIZE;
g_mem_size = (Profile.pane1_size+1) * (LINE_SIZE+1);
Pane1.buff_char = (char *)malloc(g_mem_size);
if (Pane1.buff_char == NULL) {
// Free any objects we got!
Free_Common_Objects();
return -1;
}
Pane1.buff_color = (BYTE *)malloc(g_mem_size);
if (Pane1.buff_color == NULL) {
// Free any objects we got!
Free_Common_Objects();
return -1;
}
}
Pane1.buff_lines = Profile.pane1_size;
InitializePane(&Pane1);
g_mem_size = (Profile.pane2_size+1) * (LINE_SIZE+1);
Pane2.buff_char = (char *)malloc(g_mem_size);
Pane2.buff_color = (BYTE *)malloc(g_mem_size);
if ((Pane2.buff_char == NULL) || (Pane2.buff_color == NULL)) {
if (Pane2.buff_char != NULL)
free(Pane2.buff_char);
Pane2.buff_char = NULL;
if (Pane2.buff_color != NULL)
free(Pane2.buff_color);
Pane2.buff_color = NULL;
Profile.pane2_size = PANE2_SIZE;
g_mem_size = (Profile.pane2_size+1) * (LINE_SIZE+1);
Pane2.buff_char = (char *)malloc(g_mem_size);
if (Pane2.buff_char == NULL) {
// Free any objects we got!
Free_Common_Objects();
return -1;
}
Pane2.buff_color = (BYTE *)malloc(g_mem_size);
if (Pane2.buff_color == NULL) {
// Free any objects we got!
Free_Common_Objects();
return -1;
}
}
Pane2.buff_lines = Profile.pane2_size;
InitializePane(&Pane2);
Pane1.hWnd = CreateWindow(gszPane1Class, NULL, WS_CHILD | WS_VISIBLE, 0,0,0,0, hWnd,
NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE), 0);
if (Pane1.hWnd == NULL)
{
Free_Common_Objects(); // Free any objects we got!
return(-1);
}
Pane2.hWnd = CreateWindow(gszPane2Class, NULL, WS_CHILD | WS_VISIBLE, 0,0,0,0, hWnd,
NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE), 0);
if (Pane2.hWnd == NULL)
{
Free_Common_Objects(); // Free any objects we got!
return(-1);
}
ClearPanes(TRUE, TRUE);
setupecc();
flex_init();
pocsag_init();
for (g_index=0; g_index<64; g_index++) rcver[g_index] = 0.0;
rcv_clkt = rcv_clkt_hi;
// ct is the number of expected clock ticks per bit
ct1600 = 1.0/(1600.0*838.8e-9); // 745.1
ct3200 = 1.0/(3200.0*838.8e-9); // 372.5
ct_bit = ct1600;
for (g_index=0; g_index<16; g_index++)
{
custom_colors[g_index] = RGB(255,255,255); // default to WHITE
}
for (g_index=0; g_index < NUM_STAT; g_index++)
{
hourly_stat[g_index][STAT_NUMERIC] = 0L;
hourly_char[g_index][STAT_NUMERIC] = 0L;
daily_stat [g_index][STAT_NUMERIC] = 0L;
daily_char [g_index][STAT_NUMERIC] = 0L;
hourly_stat[g_index][STAT_ALPHA] = 0L;
hourly_char[g_index][STAT_ALPHA] = 0L;
daily_stat [g_index][STAT_ALPHA] = 0L;
daily_char [g_index][STAT_ALPHA] = 0L;
}
GetLocalTime(&statTime);
prev_statTime = statTime;
stat_timer = 100 - ((statTime.wSecond % 10) * 10);
// invert audio input-bits?.
low_audio = Profile.invert ? DFLT_HI_AUDIO : DFLT_LO_AUDIO;
high_audio = Profile.invert ? DFLT_LO_AUDIO : DFLT_HI_AUDIO;
pd_reset_all(); // see decode.cpp.
break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDM_ENGLISH: // select English character mapping
case IDM_ENGLISH+1: // select Hebrew character mapping
case IDM_ENGLISH+2: // select ? character mapping
case IDM_ENGLISH+3: // select ? character mapping
case IDM_ENGLISH+4: // select ? character mapping
case IDM_ENGLISH+5: // select ? character mapping
case IDM_ENGLISH+6: // select ? character mapping
case IDM_ENGLISH+7: // select ? character mapping
case IDM_ENGLISH+8: // select ? character mapping
case IDM_ENGLISH+9: // select ? character mapping
Profile.lang_mi_index = wParam - IDM_ENGLISH;
break;
case IDT_TOOLBAR_BTN12: // Cycle data modes
if (Profile.monitor_paging) // Paging -> ACARS
{
ChangeDataMode(hWnd, MODE_ACARS);
}
else if (Profile.monitor_acars) // ACARS -> Mobitex
{
ChangeDataMode(hWnd, MODE_MOBITEX);
}
else if (Profile.monitor_mobitex) // Mobitex -> ERMES
{
ChangeDataMode(hWnd, MODE_ERMES);
}
else if (Profile.monitor_ermes) // ERMES -> Paging
{
ChangeDataMode(hWnd, MODE_PAGING);
}
Profile.FlexGroupMode = 0;
break;
case IDM_POCSAGFLEX: // Monitor POCSAG/FLEX signals?
if (!Profile.monitor_paging)
{
ChangeDataMode(hWnd, MODE_PAGING);
}
break;
case IDM_ACARS: // Monitor ACARS signals?
if (!Profile.monitor_acars)
{
ChangeDataMode(hWnd, MODE_ACARS);
Profile.FlexGroupMode = 0;
}
break;
case IDM_MOBITEX: // Monitor Mobitex signals?
if (!Profile.monitor_mobitex)
{
ChangeDataMode(hWnd, MODE_MOBITEX);
Profile.FlexGroupMode = 0;
}
break;
case IDM_ERMES: // Monitor Ermes signals?
if (!Profile.monitor_ermes)
{
ChangeDataMode(hWnd, MODE_ERMES);
Profile.FlexGroupMode = 0;
}
break;
case IDM_VOLUME: // Run the PDW volume control (Note: runs windows mixer)
ShellExecute(ghWnd, NULL, "Sndvol32.exe","", "",SW_SHOWNORMAL);
break;
case IDT_TOOLBAR_BTN0:
case IDM_LOGFILE:
GoModalDialogBoxParam(ghInstance, MAKEINTRESOURCE(LOGFILEDLGBOX),
hWnd, (DLGPROC) LogFileDlgProc, 0L);
break;
case IDT_TOOLBAR_BTN11:
case IDM_CLEARDISPLAY:
GoModalDialogBoxParam(ghInstance, MAKEINTRESOURCE(CLEARSCREENDLGBOX),
hWnd, (DLGPROC) ClearScreenDlgProc, 0L);
break;
case IDM_PLAYBACK: // RAH
if (bCapturing)
{
MessageBox(ghWnd, "This option can't be used when using the soundcard!", "PDW Playback", MB_ICONWARNING);
break;
}
else if (bPlayback)
{
Stop_Playback();
}
else if (bRecording) // HWi
{
Stop_Recording();
}
if (Open_Recording(&openplayback,szPlayback,TRUE))
{
if (Start_Playback(openplayback.lpstrFile))
{
SetTimer(ghWnd, PDW_TIMER, 100, (TIMERPROC) NULL);
}
}
break;
// HWi
case IDM_RECORD: // RAH
if (bCapturing)
{
MessageBox(ghWnd, "This option can't be used when using the soundcard!", "PDW Recording", MB_ICONWARNING);
break;
}
if (bPlayback) Stop_Playback();
if (bRecording) Stop_Recording();
else if (Open_Recording(&openrecording,szRecording,FALSE))
{
Start_Recording(openrecording.lpstrFile);
}
break;
case IDM_AUTORECORD:
if (bCapturing)
{
MessageBox(ghWnd, "This option can't be used when using the soundcard!", "PDW Recording", MB_ICONWARNING);
break;
}
if (!bRecording && !bPlayback) AutoRecording();
else if (bAutoRecording)
{
Stop_Recording();
bAutoRecording=FALSE;
MessageBox(ghWnd, "Recording Stopped!", "PDW Recording", MB_ICONINFORMATION);
}
break;
case IDM_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0L);
break;
case IDT_TOOLBAR_BTN4:
case IDM_COPY_SAVE:
if (bOK_to_save)
{
if (GetEditSaveName(hWnd))
{
if (Need_Ext(Profile.edit_save_file))
strcat(Profile.edit_save_file,".txt");
SaveClipToDisk(Profile.edit_save_file);
}
}
else MessageBox(ghWnd, "Nothing to save!", "Save Clipboard data", MB_ICONWARNING);
break;
case IDT_TOOLBAR_BTN5: // Print clip.
case IDM_COPY_PRINT:
if (bOK_to_save) PrintClip();
else MessageBox(ghWnd, "Nothing to print!", "Print Clipboard data", MB_ICONWARNING);
break;
case IDT_TOOLBAR_BTN2:
case IDM_COPY_UPPER:
g_max_row = min(Pane1.Bottom, Pane1.cyLines);
if (g_max_row > 0)
{
CopyToClipboard(&Pane1, 0,NewLinePoint, 0, g_max_row - 1);
bOK_to_save=TRUE;
}
else MessageBox(ghWnd,"Nothing to copy!", "Copy data",MB_ICONWARNING);
break;
case IDT_TOOLBAR_BTN3:
case IDM_COPY_LOWER:
g_max_row = min(Pane2.Bottom, Pane2.cyLines);
if (g_max_row > 0)
{
CopyToClipboard(&Pane2, 0,NewLinePoint, 0, g_max_row - 1);
bOK_to_save=TRUE;
}
else MessageBox(ghWnd, "Nothing to copy!", "Copy data",MB_ICONWARNING);
break;
case IDT_TOOLBAR_BTN1:
case IDM_COPY_SELECTION:
if (select_on)
{
select_on = 0;
selected = 0;
selecting = 0;
InvertSelection();
g_min_col = min(iSelectionStartCol, iSelectionEndCol);
g_max_col = max(iSelectionStartCol, iSelectionEndCol);
g_min_row = min(iSelectionStartRow, iSelectionEndRow);
g_max_row = max(iSelectionStartRow, iSelectionEndRow);
CopyToClipboard(select_pane, g_min_col, g_max_col, g_min_row, g_max_row);
bOK_to_save=TRUE;
}
else MessageBox(ghWnd, "Nothing selected to copy!", "Copy data", MB_ICONWARNING);
break;