📄 gpscomm.cpp
字号:
// GpsComm.cpp: implementation of the CGpsComm class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GpsComm.h"
//#include "CarOption.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//构造函数
//##ModelId=3FE8F86C01C7
CGpsComm::CGpsComm()
{
//m_nOKGPS = 0;
}
//析构函数
//##ModelId=3FE8F86C01DA
CGpsComm::~CGpsComm()
{
}
//////////////////////////////////////////////////
//下面是从定时返回信息中获得各种信息的函数
//////////////////////////////////////////////////
//获得月
//返回
// 0:错误
// 其他:月
// 说明:第9个‘,’之后是DDMMYY,因此 month+2
//##ModelId=3FE8F86C018A
unsigned char CGpsComm::GetMonthFromInfo(void *pVoid)
{
unsigned char *pByte1;
unsigned char *pByteS;
int Count=0;
pByte1 = (unsigned char *)pVoid;
pByteS = pByte1;
//从缓冲中搜索',',取出第9个','后面的第一个数字
while (Count<9)
{
if (*pByte1 == ',')
{
Count ++;
pByte1 ++;
continue;
}
while (*pByte1 != ',')
{
pByte1 ++;
if (*pByte1 == ',')
{
Count++;
pByte1 ++;
break;
}
//如果移出了缓冲,则直接返回0
if (pByte1-pByteS >= MaxInfoBlock)
return 0;
}
}
//将字符转换成数字
pByte1 += 2;
return (*pByte1-'0')*10 + (*(pByte1+1) -'0');
}
//获得日
//返回
// 0:错误
// 其他:日
// 说明:第9个‘,’之后是DDMMYY,因此 Day 不加
//##ModelId=3FE8F86C016C
unsigned char CGpsComm::GetDayFromInfo(void *pVoid)
{
unsigned char *pByte1;
unsigned char *pByteS;
int Count=0;
pByte1 = (unsigned char *)pVoid;
pByteS = pByte1;
//从缓冲中搜索',',取出第9个','后面的第一个数字
while (Count<9)
{
if (*pByte1 == ',')
{
Count ++;
pByte1 ++;
continue;
}
while (*pByte1 != ',')
{
pByte1 ++;
if (*pByte1 == ',')
{
Count++;
pByte1 ++;
break;
}
if (pByte1-pByteS>=MaxInfoBlock)
return 0;
}
}
//字符转换成数字
return (*pByte1-'0')*10 + (*(pByte1+1) -'0');
}
//获得年
//返回
// 0:错误
// 其他:年
// 说明:第9个‘,’之后是DDMMYY,因此year+4
//##ModelId=3FE8F86C0158
long CGpsComm::GetYearFromInfo(void *pVoid)
{
unsigned char *pByte1;
unsigned char *pByteS;
int Count=0;
pByte1 = (unsigned char *)pVoid;
pByteS=pByte1;
//从缓冲中搜索',',取出第9个','后面的第一个数字
while (Count<9)
{
if (*pByte1 == ',')
{
Count ++;
pByte1 ++;
continue;
}
while (*pByte1 != ',')
{
pByte1 ++;
if (*pByte1 == ',')
{
Count++;
pByte1 ++;
break;
}
if (pByte1-pByteS>=MaxInfoBlock)
return 0;
}
}
pByte1 += 4;
return (*pByte1-'0')*10 + (*(pByte1+1) -'0');
}
//获得时
//返回
// 0:错误
// 其他:时
// 说明:第1个‘,’之后是HHMMSS
//##ModelId=3FE8F86C013A
unsigned char CGpsComm::GetHourFromInfo(void *pVoid)
{
unsigned char *pByte1;
unsigned char Hour;
pByte1 = (unsigned char *)pVoid;
//从缓冲中搜索',',取出第1个','后的数据
while (*pByte1 != ',') pByte1++;
pByte1++;
Hour = (*pByte1-'0')*10 + (*(pByte1+1)-'0');
return Hour;
}
//获得分
//返回
// 0:错误
// 其他:分
// 说明:第1个‘,’之后是HHMMSS
//##ModelId=3FE8F86C011C
unsigned char CGpsComm::GetMinuteFromInfo(void *pBuf)
{
unsigned char *pByte1;
unsigned char Minute;
pByte1 = (unsigned char *)pBuf;
//从缓冲中搜索',',取出第1个','后的数据
while (*pByte1 != ',') pByte1++;
pByte1++;
pByte1+=2;
Minute = (*pByte1-'0')*10 + (*(pByte1+1)-'0');
return Minute;
}
//获得秒
//返回
// 0:错误
// 其他:秒
// 说明:第1个‘,’之后是HHMMSS
//##ModelId=3FE8F86C0108
unsigned char CGpsComm::GetSecondFromInfo(void *pBuf)
{
unsigned char *pByte1;
unsigned char Second;
pByte1 = (unsigned char *)pBuf;
//从缓冲中搜索',',取出第1个','后的数据
while (*pByte1 != ',') pByte1++;
pByte1++;
pByte1+=4;
Second = (*pByte1-'0')*10 + (*(pByte1+1)-'0');
return Second;
}
//获得秒的小数部分
//返回
// 0:错误
// 其他:秒小数部分
//##ModelId=3FE8F86C00EA
long CGpsComm::GetMiniSecondFromInfo(void *pVoid)
{
return 0;
}
//获得纬度
//返回
// 0:错误
// 其他:纬度
// 说明:格式 度度分分.分分分分
//##ModelId=3FE8F86C00D6
double CGpsComm::GetLatitudeFromInfo(void *pBuf)
{
double TmpFloat;
unsigned char *pByte;
unsigned char *pByte1;
unsigned char *pByte2;
unsigned char *pByteS;
int Degree; //度
int Minute; //分
int MiniMinute; //分的小数部分
pByte = (unsigned char *)pBuf;
pByteS=pByte;
//从缓冲中搜索',',取出第2个','与第3个','之间的数据转换成纬度
pByte1 = pByte;
//第1个','
while (*pByte1 != ',' )
{
pByte1++;
if ((pByte1-pByteS) >= MaxInfoBlock)
return 0.0;
}
pByte1++;
//第2个','
while (*pByte1 != ',' )
{
pByte1++;
if ((pByte1-pByteS) >=MaxInfoBlock)
return 0.0;
}
pByte1++; //第2个','后面的第一个字符
pByte2=pByte1;
while (*pByte2 != ',' )
{
pByte2++;
if ((pByte2-pByteS) >=MaxInfoBlock)
return 0.0;
}
//度
Degree = (*pByte1-'0')*10 +(*(pByte1+1) -'0');
//分
pByte1 += 2;
Minute = (*pByte1-'0')*10 + (*(pByte1+1) -'0');
//分的小数部分
pByte1 += 3;
MiniMinute = (*pByte1-'0')*1000 + (*(pByte1+1) -'0')*100+
(*(pByte1+2)-'0')*10 + (*(pByte1+3) -'0');
TmpFloat = static_cast<double>(Degree) + (static_cast<double>(Minute) +static_cast<double>(MiniMinute) / 10000.0) /60.0;
return TmpFloat;
}
//获得经度
//返回
// 0:错误
// 其他:经度
// 说明:格式 度度度分分.分分分分
//##ModelId=3FE8F86C00C2
double CGpsComm::GetLongitudeFromInfo(void *pBuf)
{
double TmpFloat;
unsigned char *pByte;
unsigned char *pByte1;
unsigned char *pByteS;
//BYTE *pByte2;
int Degree; //度
int Minute; //分
int MiniMinute; //分的小数部分
int Count=0;
pByte = (unsigned char *)pBuf;
pByteS= pByte;
//从缓冲中搜索',',取出第4个','与第5个','之间的数据转换成纬度
pByte1 = pByte;
//找到第4个','后面的第一个数字
while (Count<4)
{
if (*pByte1 == ',')
{
Count ++;
pByte1 ++;
continue;
}
while (*pByte1 != ',')
{
pByte1 ++;
if (*pByte1 == ',')
{
Count++;
pByte1 ++;
break;
}
if (pByte1-pByteS>=MaxInfoBlock)
return 0.0;
}
}
//度
Degree = (*pByte1-'0')*100+
(*(pByte1+1)-'0')*10+
*(pByte1+2)-'0';
//分
pByte1 += 3;
Minute = (*pByte1-'0')*10 + (*(pByte1+1) -'0');
//分的小数部分
pByte1 += 3;
MiniMinute = (*pByte1-'0')*1000 + (*(pByte1+1) -'0')*100+
(*(pByte1+2)-'0')*10 + (*(pByte1+3) -'0');
TmpFloat = static_cast<double>(Degree) + (static_cast<double>(Minute) +static_cast<double>(MiniMinute) / 10000.0) /60.0;
return TmpFloat;
}
//获得高度
//返回
// 0:错误
// 其他:高度
//说明:第9个“,”后面是高度
//##ModelId=3FE8F86C00AE
float CGpsComm::GetHeightFromInfo(void *pBuf)
{
unsigned char *pByte1;
unsigned char *pByte2;
unsigned char *pByteS;
char ConStr[10];
int Count=0;
int Len;
pByte1 = (unsigned char *)pBuf;
pByteS = pByte1;
//从缓冲中搜索',',取出第9个','后面的第一个数字
while (Count<9)
{
if (*pByte1 == ',')
{
Count ++;
pByte1 ++;
continue;
}
while (*pByte1 != ',')
{
pByte1 ++;
if (*pByte1 == ',')
{
Count++;
pByte1 ++;
break;
}
if (pByte1-pByteS>=MaxInfoBlock)
return 0;
}
}
pByte2=pByte1;
//
while (*pByte2 !=',') pByte2++;
//
Len =pByte2-pByte1;
for (int i=0;i<Len;i++)
{
ConStr[i] = pByte1[i];
}
ConStr[Len]=0;
return float(atof(ConStr));
}
//获得速度
//返回
// 0:错误
// 其他:速度
//##ModelId=3FE8F86C009A
float CGpsComm::GetVelocityFromInfo(void *pBuf)
{
unsigned char *pByte1;
unsigned char *pByte2;
unsigned char *pByteS;
char ConStr[10];
int Count=0;
int Len;
pByte1 = (unsigned char *)pBuf;
pByteS = pByte1;
//从缓冲中搜索',',取出第7个','后面的第一个数字
while (Count<7)
{
if (*pByte1 == ',')
{
Count ++;
pByte1 ++;
continue;
}
while (*pByte1 != ',')
{
pByte1 ++;
if (*pByte1 == ',')
{
Count++;
pByte1 ++;
break;
}
if (pByte1-pByteS>=MaxInfoBlock)
return 0;
}
}
pByte2=pByte1;
//
while (*pByte2 !=',') pByte2++;
//
Len =pByte2-pByte1;
for (int i=0;i<Len;i++)
{
ConStr[i] = pByte1[i];
}
ConStr[Len]=0;
return float(atof(ConStr));
}
//获得方向
//返回
// 0:错误
// 其他:方向
//##ModelId=3FE8F86C0086
float CGpsComm::GetDirectionFromInfo(void *pBuf)
{
unsigned char *pByte1;
unsigned char *pByte2;
unsigned char *pByteS;
char ConStr[10];
int Count=0;
int Len;
pByte1 = (unsigned char *)pBuf;
pByteS = pByte1;
//从缓冲中搜索',',取出第7个','后面的第一个数字
while (Count<8)
{
if (*pByte1 == ',')
{
Count ++;
pByte1 ++;
continue;
}
while (*pByte1 != ',')
{
pByte1 ++;
if (*pByte1 == ',')
{
Count++;
pByte1 ++;
break;
}
if (pByte1-pByteS>=MaxInfoBlock)
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -