?? dgpslistener.cpp
字號(hào):
// DGPSListener.cpp -- listens to a dBlackBox plus DGPS receiver manufactured
// by GPS Gesellschaft f黵 professionelle Satellitennavigation GmbH
// Written by Walter Piechulla in April 2000
// Based on: Allen Denver. (December 11, 1995). Serial Communications
// in Win32. Microsoft Windows Developer Support [The Article and code
// is located on the MSDN CDs shipped with MSVCPP Version 6.0]
// This also uses code from Geodesy Foundation Classes and NMEA0183 Parser written by
// Sam Blackburn http://ourworld.compuserve.com/homepages/Sam_Blackburn/homepage.htm
#include "stdafx.h"
#include "DGPSListener.h"
// Globals originally in settings.c
DCB dcbTemp;
char* szBaud[] =
{
"110",
"300",
"600",
"1200",
"2400",
"4800",
"9600",
"14400",
"19200",
"38400",
"56000",
"57600",
"115200",
"128000",
"256000"
};
DWORD BaudTable[] =
{
CBR_110,
CBR_300,
CBR_600,
CBR_1200,
CBR_2400,
CBR_4800,
CBR_9600,
CBR_14400,
CBR_19200,
CBR_38400,
CBR_56000,
CBR_57600,
CBR_115200,
CBR_128000,
CBR_256000
};
char* szParity[] =
{
"None",
"Even",
"Odd",
"Mark",
"Space"
};
DWORD ParityTable[] =
{
NOPARITY,
EVENPARITY,
ODDPARITY,
MARKPARITY,
SPACEPARITY
};
char* szStopBits[] =
{
"1",
"1.5",
"2"
};
DWORD StopBitsTable[] =
{
ONESTOPBIT,
ONE5STOPBITS,
TWOSTOPBITS
};
char* szDTRControlStrings[] =
{
"Enable",
"Disable",
"Handshake"
};
DWORD DTRControlTable[] =
{
DTR_CONTROL_ENABLE,
DTR_CONTROL_DISABLE,
DTR_CONTROL_HANDSHAKE
};
char* szRTSControlStrings[] =
{
"Enable",
"Disable",
"Handshake",
"Toggle"
};
DWORD RTSControlTable[] =
{
RTS_CONTROL_ENABLE,
RTS_CONTROL_DISABLE,
RTS_CONTROL_HANDSHAKE,
RTS_CONTROL_TOGGLE
};
DWORD EventFlagsTable[] =
{
EV_BREAK,
EV_CTS,
EV_DSR,
EV_ERR,
EV_RING,
EV_RLSD,
EV_RXCHAR,
EV_RXFLAG,
EV_TXEMPTY
};
// TimeoutsDefault
// We need ReadIntervalTimeout here to cause the read operations
// that we do to actually timeout and become overlapped.
// Specifying 1 here causes ReadFile to return very quickly
// so that our reader thread will continue execution.
COMMTIMEOUTS gTimeoutsDefault = { 0x01, 0, 0, 0, 0 };
// End Global originally in init.c
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
MSG msg;
if (!VersionCheck())
{
MessageBox(NULL,"DGPSListener can't run on this version of Windows.",NULL,MB_OK);
return 0;
}
if (!InitializeApp(hInstance,nCmdShow))
{
MessageBox(NULL,"DGPSListener couldn't start!",NULL,MB_OK);
return 0;
}
while (GetMessage(&msg,NULL,0,0))
{
if (!TranslateAccelerator(ghwndMain,ghAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 1;
}
BOOL VersionCheck()
{
gOSV.dwOSVersionInfoSize = sizeof(gOSV);
if (!GetVersionEx(&gOSV))
return FALSE;
if (gOSV.dwPlatformId == VER_PLATFORM_WIN32s)
return FALSE;
return TRUE ;
}
BOOL InitializeApp(HINSTANCE hInst,int nCmdShow)
{
WNDCLASS wc = {0};
GlobalInitialize(); // get all global variables initialized to defaults
// setup program's main window class
wc.lpfnWndProc = (WNDPROC) MTTTYWndProc;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_APPICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MTTTYMENU);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1) ;
wc.lpszClassName = "MTTTYClass";
if (!RegisterClass(&wc))
{
GlobalCleanup();
return FALSE;
}
// setup program's tty child window class
wc.lpfnWndProc = (WNDPROC) TTYChildProc;
wc.hInstance = hInst;
wc.hCursor = LoadCursor(NULL, IDC_IBEAM);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszClassName = "MTTTYChildClass";
wc.lpszMenuName = NULL;
wc.hIcon = NULL;
if (!RegisterClass(&wc))
{
GlobalCleanup();
return FALSE;
}
// create main window
ghwndMain = CreateWindow("MTTTYClass",
"DGPSListener",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
STARTXWINDOW, STARTYWINDOW,
MAXXWINDOW, MAXYWINDOW,
NULL, NULL, hInst, NULL);
if (ghwndMain == NULL)
{
GlobalCleanup();
return FALSE;
}
ShowWindow(ghwndMain,nCmdShow);
UpdateWindow(ghwndMain);
ghInst = hInst;
ghAccel = LoadAccelerators(hInst,MAKEINTRESOURCE(IDR_MTTTYACCELERATOR));
return TRUE;
}
int WINAPI MTTTYWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
// since main window is created, I can now open all other windows
InitTTYInfo();
OpenTTYChildWindow(hwnd);
OpenSettingsToolbar(hwnd);
OpenStatusToolbar(hwnd);
ChangeConnection(hwnd, CONNECTED(TTYInfo));
break;
case WM_DESTROY:
// since main windows is being destroyed, so same to other windows
DestroyTTYInfo();
DestroyWindow(ghWndToolbarDlg);
DestroyWindow(ghWndStatusDlg);
DestroyWindow(ghWndTTY);
GlobalCleanup();
PostQuitMessage(0);
break;
case WM_GETMINMAXINFO:
{
// make sure that main window doesn't get smaller than
// the minimum child windows.
LPMINMAXINFO lpTemp;
POINT ptTemp;
lpTemp = (LPMINMAXINFO) lParam;
ptTemp.x = (long) lpTemp->ptMinTrackSize.x;
ptTemp.y = (long) gcyMinimumWindowHeight;
lpTemp->ptMinTrackSize = ptTemp;
}
break;
case WM_SIZE:
{
// main window size has changed,
// so I need to change the positions of child windows
WORD wTop;
WORD wHeight;
WORD wWidth = LOWORD(lParam);
// put Settings window at top
wHeight = SETTINGSFACTOR*gwBaseY;
wTop = 0;
MoveWindow(ghWndToolbarDlg,0,wTop,wWidth,wHeight,TRUE);
// put Status window at bottom
wHeight = STATUSFACTOR*gwBaseY;
wTop = HIWORD(lParam) - wHeight;
MoveWindow(ghWndStatusDlg,0,wTop,wWidth,wHeight,TRUE);
// put DGPSListener window right in the middle
// height = whole window - height of two previous windows
wHeight = HIWORD(lParam) - ((STATUSFACTOR + SETTINGSFACTOR)*gwBaseY);
wTop = SETTINGSFACTOR*gwBaseY;
MoveWindow(ghWndTTY,0,wTop,wWidth,wHeight,TRUE);
}
break;
case WM_COMMAND:
CmdDispatch(LOWORD(wParam),hwnd,lParam);
break;
case WM_CHAR:
SetFocus(ghWndTTY);
SendMessage(ghWndTTY,WM_CHAR,wParam,lParam);
break;
case WM_CLOSE:
if (DisconnectOK())
{
if (CONNECTED(TTYInfo))
{
if (TRANSFERRING(TTYInfo))
{
TransferFileTextEnd();
}
BreakDownCommPort();
}
DestroyWindow(hwnd);
}
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0L;
}
void CmdDispatch(int iMenuChoice,HWND hwnd,LPARAM lParam)
{
static char szFileName[MAX_PATH] = {0};
switch (iMenuChoice)
{
case ID_HELP_ABOUTMTTTY:
CmdAbout(hwnd);
break;
case ID_TRANSFER_SENDFILETEXT:
{
char * szFilter = "Text Files\0*.TXT\0";
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Send File";
ofn.Flags = OFN_FILEMUSTEXIST;
if (!GetOpenFileName(&ofn))
break;
if (TRUE)
TransferFileTextStart(szFileName);
}
break;
case ID_BLACKBOX_CAPTURERAW: // fallthrough
case ID_TRANSFER_RECEIVEFILETEXT:
{
char * szFilter = "Text Files\0*.TXT\0";
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Receive File";
ofn.Flags = OFN_OVERWRITEPROMPT;
if (!GetSaveFileName(&ofn))
break;
ReceiveFileText(szFileName,false);
}
break;
case ID_BLACKBOX_CAPTURECOOKED:
{
char * szFilter = "Text Files\0*.TXT\0";
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Receive File";
ofn.Flags = OFN_OVERWRITEPROMPT;
if (!GetSaveFileName(&ofn))
break;
ReceiveFileText(szFileName,true);
}
break;
case ID_TRANSFER_ABORTSENDING:
// was abort sent from the abort button?
if (LOWORD(lParam) == IDC_ABORTBTN)
{
if (REPEATING(TTYInfo)) // am I in a transfer repeat?
{
TransferRepeatDestroy();
}
else if (gdwReceiveState == RECEIVE_TTY) // am I in a normal receive state, then stop sending
{
TransferFileTextEnd();
}
else // if I am not in a normal receive state, then stop capturing
{
gfAbortTransfer = TRUE;
}
}
else // if I am not in a normal receive state, then stop capturing
{
TransferFileTextEnd();
}
break;
case ID_TRANSFER_SENDREPEATEDLY:
{
DWORD dwFreq;
char * szFilter = "Text Files\0*.TXT\0";
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Send File Repeatedly";
ofn.Flags = OFN_FILEMUSTEXIST;
if (!GetOpenFileName(&ofn))
break;
dwFreq = GetAFrequency();
TransferRepeatCreate(szFileName,dwFreq);
}
break;
case ID_TRANSFER_ABORTREPEATEDSENDING:
TransferRepeatDestroy();
break;
case ID_TTY_CLEAR:
ClearTTYContents();
InvalidateRect(ghWndTTY, NULL, TRUE);
break;
// The following correspond to menu choices and buttons in the settings dlog
case IDC_FONTBTN:
case IDC_COMMEVENTSBTN:
case IDC_FLOWCONTROLBTN:
case IDC_TIMEOUTSBTN:
SendMessage(ghWndToolbarDlg,WM_COMMAND,(WPARAM)iMenuChoice,(LPARAM)GetDlgItem(ghWndToolbarDlg,iMenuChoice));
break;
case ID_BLACKBOX_DUMPCOOKED:
gdwReceiveState = RECEIVE_TTYBLACKBOXCOOKED;
if (SetupCommPort() != NULL)
{
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -