⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpsmodule.h

📁 gps的数据解析
💻 H
字号:
/*
串口基础类库(WIN32) ver 0.1

编译器 : BC++ 5; C++ BUILDER 4, 5, 6, X; VC++ 5, 6; VC.NET;  GCC;

class   _base_com : 虚基类 基本串口接口;
class   _sync_com : 同步I/O 串口类;
class   _asyn_com : 异步I/O 串口类;
class _thread_com : 异步I/O 辅助读监视线程 可转发窗口消息 串口类(可继承虚函数on_receive用于读操作);
class        _com : _thread_com 同名

copyright(c) 2004.8 llbird wushaojian@21cn.com
*/
/*
Example :
*/
#ifndef _COM_H_
#define _COM_H_

#ifdef DLL_API
#else
#define DLL_API _declspec(dllimport)
#endif

#pragma warning(disable: 4530)
#pragma warning(disable: 4786)
#pragma warning(disable: 4800)

#include <cassert>
#include <strstream>
#include <algorithm>
#include <exception>
#include <iomanip>
#include <fstream>
using namespace std;

#include <windows.h>



class DLL_API GpsPoint  
{
public:
	double X, Y;		//高斯投影坐标x y
	double B, L;	//参心坐标系经 纬度
	double L0;		//中央子午线经度
public:
	bool BLtoXY_2();
	GpsPoint();	
	bool XYtoBL();
	bool BLtoXY();
	bool SetBL( double b0, double l0 );
	bool SetXY( double x0, double y0 );
	virtual ~GpsPoint();
	
};

class DLL_API GPSParam  
{
private:
	bool m_IsOK;
public:
	bool IsOk();
	bool SetParam(char str[],int length);
	GPSParam();
	bool DataTransform();
	GPSParam(char str[],int length=200);	//length为一条指令的最大长度,<=200
	virtual ~GPSParam();
	CString Data[20];
	
	double X,Y;
	
	
	CString m_name;
	struct 
	{
		int hour;
		int mimute;
		double second;
	}m_time;
	CString m_status;
	double m_latitude;
	bool m_nsindicator;
	double m_longtitude;
	bool m_ewindicator;
	double m_speed;
	double m_cog;
	struct 
	{
		int day;
		int month;
		int year;
	}m_date;
};

class _base_com   //虚基类 基本串口接口
{
protected:

	 volatile int _port;  //串口号
	 volatile HANDLE _com_handle;//串口句柄
	 char _com_str[20];
	 DCB _dcb;     //波特率,停止位,等
	 COMMTIMEOUTS _co;  // 超时时间

	 virtual bool open_port() = 0;
	 void init(); //初始化
                 
	 virtual bool setup_port();      
	 inline void set_com_port(int port);
public:
 _base_com();
 virtual ~_base_com();
  //设置串口参数:波特率,停止位,等 支持设置字符串 "9600, 8, n, 1"
 bool set_state(char *set_str) ;
  //设置内置结构串口参数:波特率,停止位
 bool set_state(int BaudRate = 9600, int ByteSize = 8, int Parity = NOPARITY, int StopBits = ONESTOPBIT, char EvtChar='\n' );
  //打开串口 缺省 9600, 8, n, 1
 inline bool open(int port);
  //打开串口 缺省 baud_rate, 8, n, 1
 inline bool open(int port, int baud_rate);
  //打开串口
 inline bool open(int port, char *set_str);
 inline bool set_buf(int in, int out);
 //关闭串口
 inline virtual void close();
 //判断串口是或打开
 inline bool is_open();
 //获得串口句炳
 HANDLE get_handle();
 operator HANDLE();
};

class _sync_com : public _base_com
{
protected:
 //打开串口
 virtual bool open_port();
 
public:

 _sync_com();

 //同步读
 int read(char *buf, int buf_len);
  //同步写
 int write(char *buf, int buf_len);
 //同步写
 inline int write(char *buf);
 
 //同步写, 支持部分类型的流输出
 template<typename T>
 _sync_com& operator << (T x);
 
};

class  _asyn_com : public _base_com
{
protected:

 OVERLAPPED _ro, _wo; // 重叠I/O

 virtual bool open_port();
 

public:

 _asyn_com();
 
 virtual ~_asyn_com();
 
 //异步读
 int read(char *buf, int buf_len, int time_wait = 20);
  //异步写
 int write(char *buf, int buf_len);
 
 //异步写
 inline int write(char *buf);

 //异步写, 支持部分类型的流输出
 template<typename T>
 _asyn_com& operator << (T x);
 
};

//当接受到数据送到窗口的消息
#define ON_COM_RECEIVE WM_USER + 618  //  WPARAM 端口号

class _thread_com : public _asyn_com
{
protected:
 volatile HANDLE _thread_handle; //辅助线程
 volatile HANDLE _file_thread_handle; //文件辅助线程
 CString m_filename;				//文件名
 volatile HWND _notify_hwnd; // 通知窗口
 volatile long _notify_num;//接受多少字节(>_notify_num)发送通知消息
 volatile bool _run_flag; //线程运行循环标志
 void (*_func)(int port);

 GPSParam gps;		//存储临时gps返回参数
 OVERLAPPED _wait_o; //WaitCommEvent use

 //线程收到消息自动调用, 如窗口句柄有效, 送出消息, 包含窗口编号
 virtual void on_receive();
 
 //打开串口,同时打开监视线程
 virtual bool open_port();
 

public:
 _thread_com();
 
 ~_thread_com();
 
 //设定发送通知, 接受字符最小值
 void set_notify_num(int num);
 
 int get_notify_num();

 //送消息的窗口句柄
 inline void set_hwnd(HWND hWnd);
 
 inline HWND get_hwnd();
 
 inline void set_func(void (*f)(int));
 
 //关闭线程及串口
 virtual void close();
 
 /*辅助线程控制*/
 //获得线程句柄
 HANDLE get_thread();
 
 //暂停监视线程
 bool suspend();
 
 //恢复监视线程
 bool resume();

 //重建监视线程
 bool restart() ;
 
bool Open_file(CString str);

private:
 //监视线程
 static DWORD WINAPI com_thread(LPVOID para);

 static DWORD WINAPI file_thread(LPVOID para);
 
};

typedef _thread_com _com; //名称简化

#endif //_COM_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -