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

📄 gps.cpp

📁 这是一个罗盘的串口数据读取过程,并且在此之前加入了标定过程
💻 CPP
字号:
#include "StdAfx.h"
#include "GPS.h"

const string GPS::m_sPrefix = "GPGGA";

GPS::GPS(void)
{
	m_sInputBuffer.reserve(GPS_STRINIG_BUFFER_SIZE);
	m_bNewLine = false;
	m_bValid = false;
	m_nFlag = -1;
}

GPS::~GPS(void)
{
}

void GPS::OnReceiveChar(const char ch)
{
	switch (ch)
	{
	case '$':
		m_bNewLine = true;
		m_nFlag = 0;
		break;
	case '*':
		if (m_bValid)
		{
			AnalyseGPGGA(m_sInputBuffer);
			m_bValid = false;
		}
		m_sInputBuffer = "";
		break;
	case 13:	//cr
		break;
	case 10:	//lf
		break;
	default:
		if (m_bNewLine)
		{
			if (m_bValid)
			{
				m_sInputBuffer += ch;
			}
			else
			{
				if (m_nFlag != -1)
				{
					m_sInputBuffer += ch;
					++m_nFlag;

					if (m_nFlag == m_sPrefix.size())
					{
						if (m_sPrefix == m_sInputBuffer)
						{
							m_bValid = true;
						}
						else
						{
							m_nFlag = -1;
						}
					}
				}
			}
		}
		break;
	}
}

void GPS::AnalyseGPGGA(const string& str)
{
	assert(!str.empty());
	//14 ',' total

	GPGGADATA data = {0};
	const char comma = ',';
	size_t start = 0, end = 0;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	end = str.find_first_of(comma, start);
	cout << str.substr(start, end - start) << endl;
	start =  end + 1;

	UpdateDataBuffer(data);
	
}

void GPS::OnReceiveCh(const char ch)
{
}

⌨️ 快捷键说明

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