/*
Module : GPS.CPP
Purpose: "C" style Implementation to GPS32
Created: PJN / 28-12-1997
History: PJN / 20-01-1998 1. A number of problems were discovered when GPSLIB was being
used in a UNICODE build. These problems have been fixed
2. Mak file now includes all the possible build options
3. Mak file no longer hard codes output to d:\winnt\system32
4. Included release binaries in distribution
PJN / 26-08-1998 1. Small change to stdafx.h to include afxcview.h in gps32exe
2. The GpsShowControlPanel function now actually works
3. Minor tweaks to the GPS Mak files
4. Removed a number of unused symbols
5. Change ID of a number of GPS32EXE menu items to avoid conflict
with new VC 6 defines.
6. Updated all Version Infos to 1.02
7. Removed a level 4 warning from the Test app.
8. Removed unused toolbar from GPS CPL file
9. GPS cpl file now uses standard F2 accelerator for Rename
10. GPS32EXE toolbar is now shown flat
11. Number of extra TRACE statements have been added to
aid in debugging.
PJN / 11-08-1999 1. Now uses the WINAPI calling convention meaning that GPSLIB is now
callable from VB.
2. Now also ships a GPS.BAS file for use of GPSLIB in VB
PJN / 27-09-2001 1. Fixed a problem where the background serial port thread using causing
heavy CPU utilization.
2. Updated the project settings so that all binaries get build to the Bin
directory and all Lib files get created in a Lib directory
3. Updated the version info's in all the binaries
4. Updated the copyright message in the code modules
PJN / 21-08-2002 1. Fixed a synchronisation problem between the worker thread and the
GpsGetPosition method. Thanks to Bill Oatman for spotting this problem.
Copyright (c) 1997 - 2002 by PJ Naughter. (Web: www.naughter.com, Email: pjna@naughter.com)
All rights reserved.
Copyright / Usage Details:
You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise)
when your product is released in binary form. You are allowed to modify the source code in any way you want
except you cannot modify the copyright details at the top of each module. If you want to distribute source
code with your application, then you are only allowed to distribute versions released by the author. This is
to maintain a single distribution point for the source code.
*/
///////////////////////////////// Includes //////////////////////////////////
#include "stdafx.h"
#include "gps.h"
#include "serport.h"
#include "resource.h"
#include "nmea.h"
#include "math.h"
#include "gpssetup.h"
////////////////////////////////// Macros / Defines //////////////////////////
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif
////////////////////////////////// Locals /////////////////////////////////////
class GPSHandle
{
public:
GPSHandle();
~GPSHandle();
GPSPOSITION m_Position; //the actual data
CEvent* m_pKillEvent; //Event to signal thread to exit
CEvent* m_pStartEvent; //Is the background thread running
GPSDEVINFO m_DevInfo; //Settings of the comms port to use
BOOL m_bRunning; //Is the background thread running
CWinThread* m_pThread; //The pointer to the background thread
CCriticalSection m_csPosition; //Critical section used to serialized access to m_Position
};
BOOL GetGpsDevice(DWORD dwDevice, LPGPSDEVINFO lpGpsDevInfo);
BOOL SetGpsDevice(DWORD dwDevice, LPCGPSDEVINFO lpGpsDevInfo, BOOL bCheckDefault = TRUE);
BOOL SetGpsNumDevices(DWORD dwDevices);
UINT GpsMonitorThead(LPVOID pParam);
////////////////////////////////// Implementation /////////////////////////////
GPSHandle::GPSHandle()
{
ZeroMemory(&m_Position, sizeof(GPSPOSITION));
m_pKillEvent = new CEvent(FALSE, TRUE);
m_pStartEvent = new CEvent(FALSE, TRUE);
m_pThread = NULL;
}
GPSHandle::~GPSHandle()
{
delete m_pStartEvent;
m_pStartEvent = NULL;
delete m_pKillEvent;
m_pKillEvent = NULL;
}
BOOL GetGpsDevice(DWORD dwDevice, LPGPSDEVINFO lpGpsDevInfo)
{
BOOL bSuccess = FALSE;
HKEY hKey;
CString sValueKey;
sValueKey.Format(_T("SOFTWARE\\PJ Naughter\\GPS32\\%d"), dwDevice);
LONG nError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sValueKey, 0, KEY_ALL_ACCESS, &hKey);
if (nError == ERROR_SUCCESS)
{
DWORD dwType;
DWORD dwSize;
RegQueryValueEx(hKey, _T("DeviceName"), 0, &dwType, NULL, &dwSize);
TCHAR* pszName = new TCHAR[dwSize / sizeof(TCHAR)];
RegQueryValueEx(hKey, _T("DeviceName"), 0, &dwType, (LPBYTE) pszName, &dwSize);
_tcscpy(lpGpsDevInfo->szDeviceName, pszName);
delete [] pszName;
RegQueryValueEx(hKey, _T("DefaultReceiver"), 0, &dwType, (LPBYTE) &lpGpsDevInfo->bDefaultReceiver, &dwSize);
RegQueryValueEx(hKey, _T("Port"), 0, &dwType, (LPBYTE) &lpGpsDevInfo->wCommPort, &dwSize);
RegQueryValueEx(hKey, _T("BaudRate"), 0, &dwType, (LPBYTE) &lpGpsDevInfo->dwCommBaudRate, &dwSize);
RegQueryValueEx(hKey, _T("DataBits"), 0, &dwType, (LPBYTE) &lpGpsDevInfo->wCommDataBits, &dwSize);
RegQueryValueEx(hKey, _T("StopBits"), 0, &dwType, (LPBYTE) &lpGpsDevInfo->wCommStopBits, &dwSize);
bSuccess = TRUE;
RegCloseKey(hKey);
}
else
{
TRACE(_T("GetGpsDevice, Failed to open a registry key, Error was: %d\n"), nError);
}
return bSuccess;
}
BOOL GpsSetNumDevices(DWORD dwDevices)
{
BOOL bSuccess = FALSE;
HKEY hKey;
DWORD dwDisposition;
LONG nError = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\PJ Naughter\\GPS32"), 0, _T(""),
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (nError == ERROR_SUCCESS)
{
RegSetValueEx(hKey, _T("NumberOfDevices"), 0, REG_DWORD, (CONST BYTE*) &dwDevices, sizeof(DWORD));
RegCloseKey(hKey);
bSuccess = TRUE;
}
else
{
TRACE(_T("GpsSetNumDevices, Failed in call to create a registry key, Error was: %d\n"), nError);
}
return bSuccess;
}
BOOL SetGpsDevice(DWORD dwDevice, LPCGPSDEVINFO lpDevice, BOOL bCheckDefault)
{
//Fix up the case where we have just made this device
//the default by removing the default flag from all
//other devices
if (bCheckDefault && lpDevice->bDefaultReceiver)
{
//make all other devices non default
for (DWORD i=0; i<GpsGetNumDevices(); i++)
{
GPSDEVINFO devInfo;
GetGpsDevice(i, &devInfo);
devInfo.bDefaultReceiver = FALSE;
SetGpsDevice(i, &devInfo, FALSE);
}
}
BOOL bSuccess = FALSE;
HKEY hKey;
DWORD dwDisposition;
CString sValueKey;
sValueKey.Format(_T("SOFTWARE\\PJ Naughter\\GPS32\\%d"), dwDevice);
LONG nError = RegCreateKeyEx(HKEY_LOCAL_MACHINE, sValueKey, 0, _T(""), REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (nError == ERROR_SUCCESS)
{
RegSetValueEx(hKey, _T("DeviceName"), 0, REG_SZ, (CONST BYTE*) lpDevice->szDeviceName, _tcslen(lpDevice->szDeviceName));
RegSetValueEx(hKey, _T("DefaultReceiver"), 0, REG_DWORD, (CONST BYTE*) &lpDevice->bDefaultReceiver, sizeof(BOOL));
DWORD dwData = lpDevice->wCommPort;
RegSetValueEx(hKey, _T("Port"), 0, REG_DWORD, (CONST BYTE*) &dwData, sizeof(DWORD));
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
这是一个简单的软件开发包(SDK),你可以利用这个 GPSLIB 在自己的32位 Windows 应用程序中加入全球定位系统的支持。源代码压缩文件中包含有 GPSLIB 库的源代码和 Demo 程序。很多文件中都有详细的注释说明。为了保证可下载文件的体积尽量的小,压缩文件中不含任何二进制文件。请使用Visual C++ 5 以上的版本编译并生成 DLLs、控制面板程序和可执行文件。
资源推荐
资源详情
资源评论
收起资源包目录
2004021616300329569.rar (80个子文件)
GPSLibsrc
ReleaseU
GPSLib.h 393B
GPSLib.rc 13KB
Gps32.001 9KB
NMEA.CPP 8KB
GPS32d.def 540B
SERPORT.H 1KB
Response.h 632B
Gps32.dsp 9KB
TestGPSBas
Form1.frm 12KB
gps.bas 2KB
TestGPSBas.vbp 654B
RES
GPSLib.rc2 398B
wizinstall.bmp 28KB
properties.ico 766B
MAINFRM.ICO 9KB
Gps32.ncb 121KB
NMEA.H 3KB
Gps32.def 541B
GPSCPL
Gpscpld.def 131B
Gpscpl.def 130B
CTRLPAN.CPP 2KB
CTRLPAN.H 812B
Gpscplu.def 128B
GPSCPL.rc 3KB
RES
MAINFRM.ICO 1KB
GPSCPL.H 653B
GPSCPL.001 8KB
Gpscplud.def 129B
RESOURCE.H 543B
GPSCPL.DSP 8KB
Gpscpl.cpp 1KB
Gps32.dsw 1KB
GPSLIB.GIF 1KB
GPS32EXE
FlatBar.h 925B
GPSGuiDoc.cpp 747B
GPS32EXE.DSP 7KB
FlatBar.cpp 7KB
GPS32EXE.001 7KB
RES
BIGIL.BMP 1KB
MAINFRAM.BMP 2KB
SMALLIL.BMP 374B
Toolbar.bmp 1KB
MAINFRM.ICO 9KB
App.cpp 771B
GPSGuiView.h 2KB
App.h 401B
StdAfx.cpp 204B
MainFrm.cpp 2KB
GPSGuiView.cpp 10KB
MainFrm.h 743B
RESOURCE.H 4KB
StdAfx.h 250B
GPSGuiDoc.h 709B
GPS32EXE.rc 11KB
StdAfx.cpp 204B
GPS32ud.def 543B
resource.h 2KB
GPSSETUP.CPP 11KB
SerialPort.cpp 17KB
GPSSETUP.H 4KB
StdAfx.h 250B
Gps.h 4KB
SerialPort.h 3KB
SERPORT.CPP 4KB
GPS32u.def 544B
Gps32.opt 64KB
TestGPS
TestGPS.cpp 576B
TestGPS.001 6KB
Resource.h 1KB
RES
TestGPS.rc2 399B
MAINFRM.ICO 1KB
TestGPSDlg.h 1KB
TestGPS.h 429B
StdAfx.cpp 205B
StdAfx.h 331B
TestGPSDlg.cpp 6KB
TestGPS.rc 6KB
TestGPS.dsp 6KB
GPSLib.cpp 312B
Gps.cpp 24KB
共 80 条
- 1
资源评论
普通网友
- 粉丝: 882
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功