android提取串口返回nmea,实现GPS 串口 NMEA 解析的代码

本文提供了一段C++代码,用于初始化并解析GPS串口返回的NMEA信息。代码包括初始化串口、设置串口参数、读取线程以及解析NMEA数据等功能,适用于Android平台。
摘要由CSDN通过智能技术生成

经常需求使用 GPS 串口 NMEA 解析的功能,写了一段代码来完成引功能。

分享一下,大家一起学习。

头文件:#ifndef _GPS_MONITER_HH_

#define _GPS_MONITER_HH_

BOOL InitSerailPort(CString csSerialPort,LPVOID pParent = NULL);

DWORD WINAPI ReadNMEAThread(LPVOID lpParameter);

void SetSystemTimeFormUTC(CString csDate,CString csUTCTime);

void DeinitSerialPort(void);

#endif

源文件:#include "stdafx.h"

#include "GPSMoniter.h"

#define SATTATOLNUMBER32

// 用于在 GPS 监控界面显示 NMEA 信息

char gcBuff[4096];

CString gcsTime;

CString gcsDate;

int gdSignalNumber[SATTATOLNUMBER];

CString csLat;

CString csLatdir;

CString csLon;

CString csLondir;

CString csAltitude;

CString csSpeed;

CString csOrientation;

int nNumDisplayed;

int giGSVSatNumber;

HANDLE ghCommHandle;

HANDLE nmeathread_hand;// Global handle to the NMEA reading thread

CString gcsGPSState;//定位: A; 导航: V

CString gcsTimeOp;

CString gcsLatField;

CString gcsLonField;

int giResult;

int giSalNumber;

int giGSVCurrentPackage;

int giHourDiff;

BOOL InitSerailPort(CString csSerialPort,LPVOID pParent)

{

DCB commDCB;

COMMTIMEOUTS timeouts;

ghCommHandle = CreateFile(csSerialPort, GENERIC_READ | GENERIC_WRITE, 0, NULL,

OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, NULL);

if(INVALID_HANDLE_VALUE == ghCommHandle)

{

RETAILMSG(1, (TEXT("Opening GPS %s failed: %d!rn"),csSerialPort,(int)GetLastError()));

return FALSE;

}

commDCB.DCBlength = sizeof (DCB);

if(!GetCommState(ghCommHandle,&commDCB))

{

CloseHandle(ghCommHandle);

ghCommHandle = INVALID_HANDLE_VALUE;

RETAILMSG(1,(L"Failed in getting GPS %s DCB settings: %d!rn",csSerialPort,(int)GetLastError()));

return FALSE;

}

commDCB.DCBlength = sizeof(DCB);

commDCB.BaudRate = 9600;             // Current baud

commDCB.ByteSize = 8;                 // Number of bits/bytes, 4-8

commDCB.Parity = NOPARITY;            // 0-4=no,odd,even,mark,space

commDCB.StopBits = ONESTOPBIT;        // 0,1,2 = 1, 1.5, 2

// Setting serial port to Centrality speicifcations

if(!SetCommState(ghCommHandle,&commDCB))

{

CloseHandle(ghCommHandle);

ghCommHandle = INVALID_HANDLE_VALUE;

RETAILMSG(1,(L"Error in trying to set GPS %s DCB settings: %d!rn",csSerialPort,(int)GetLastError()));

return FALSE;

}

// Get the default timeout settings for port

if(!GetCommTimeouts(ghCommHandle, &timeouts))

{

CloseHandle(ghCommHandle);

ghCommHandle = INVALID_HANDLE_VALUE;

RETAILMSG(1,(L"Fail

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值