大神帮忙看下GPS数据包如何循环解析
求大神帮忙看下如何实现遍历所有编辑框的中数据,实现循环解析GPS的数据!以下代码仅能实现一行数据的解析!数据源:
$GPRMC,014254.70,A,2603.613111,N,11910.693806,E,0.364,273.16,230719,,,A*69
$GPGGA,014254.70,2603.613111,N,11910.693806,E,1,12,1.13,4.50,M,9.90,M,,*64
$GPRMC,014254.80,A,2603.613113,N,11910.693794,E,0.370,272.77,230719,,,A*63
$GPGGA,014254.80,2603.613113,N,11910.693794,E,1,12,1.13,4.50,M,9.90,M,,*6D
$GPRMC,014254.90,A,2603.613115,N,11910.693792,E,0.368,271.60,230719,,,A*6E
$GPGGA,014254.90,2603.613115,N,11910.693792,E,1,12,1.13,4.60,M,9.90,M,,*6F
$GPRMC,014255.00,A,2603.613123,N,11910.693764,E,0.365,273.78,230719,,,A*6C
$GPGGA,014255.00,2603.613123,N,11910.693764,E,1,12,1.13,4.60,M,9.90,M,,*6B
//GPS数据解析
split split;//切分函数类
CString buffString;
int nlinecout1 = (m_EditRev.GetLineCount() - 1);//获取行数
for (int i = 0; i < nlinecout1; i++)
{
int len = m_EditRev.LineLength(m_EditRev.LineIndex(i));
buffString = m_strReceive;//编辑框值变量,原始数据保存在该变量
split.SetSplitFlag(_T(","));//切分标志
split.SetSequenceAsOne(TRUE);
split.SetData(buffString);
CStringArray array;
split.GetSplitStrArray(array);//将切分的数据存入数组中
//判断读取的GPS信息的类型
if (array = "$GPRMC")
{
m_strJD = array.Left(2) + "." + array.Mid(2, 2) + array.Right(6) ;
m_strWD = array.Left(3) + "." + array.Mid(3, 2) + array.Right(6) ;
}
UpdateData(false);
}
之前尝试用GetLine()循坏获取EDIT控件中的每一行的内容,但是每一行的正确数据后面总带有乱码!
请大神在代码上指点一下! 什么乱码 如果是python 做这个事情 就很容易的
>>> lst=
>>> lst
[['$GPRMC', '014254.70', 'A', '2603.613111', 'N', '11910.693806', 'E', '0.364', '273.16', '230719', '', '', 'A*69'], ['$GPGGA', '014254.70', '2603.613111', 'N', '11910.693806', 'E', '1', '12', '1.13', '4.50', 'M', '9.90', 'M', '', '*64'], ['$GPRMC', '014254.80', 'A', '2603.613113', 'N', '11910.693794', 'E', '0.370', '272.77', '230719', '', '', 'A*63'], ['$GPGGA', '014254.80', '2603.613113', 'N', '11910.693794', 'E', '1', '12', '1.13', '4.50', 'M', '9.90', 'M', '', '*6D'], ['$GPRMC', '014254.90', 'A', '2603.613115', 'N', '11910.693792', 'E', '0.368', '271.60', '230719', '', '', 'A*6E'], ['$GPGGA', '014254.90', '2603.613115', 'N', '11910.693792', 'E', '1', '12', '1.13', '4.60', 'M', '9.90', 'M', '', '*6F'], ['$GPRMC', '014255.00', 'A', '2603.613123', 'N', '11910.693764', 'E', '0.365', '273.78', '230719', '', '', 'A*6C'], ['$GPGGA', '014255.00', '2603.613123', 'N', '11910.693764', 'E', '1', '12', '1.13', '4.60', 'M', '9.90', 'M', '', '*6B'], ['']]
>>> joe_mao 发表于 2019-7-24 15:13
什么乱码
"F:\1.png" 蛋蛋N 发表于 2019-7-24 15:57
后面会出现这样一串乱码
L"$GPRMC,075308.60,A,2603.612225,N,11910.677423,E,0.280,245.95,240719,,,A*61췍﷽﷽" joe_mao 发表于 2019-7-24 15:13
什么乱码
我的循环代码是这样写的,辛苦您帮我看下问题出在哪里?
split split;
CString buffString;
//赋值
int nlinecout1 = (m_EditRev.GetLineCount() - 1);//获取行数
CString*strText = new CString;
for (int i = 0; i < nlinecout1; i++)
{
int len = m_EditRev.LineLength(m_EditRev.LineIndex(i));
buffString==m_EditRev.GetLine(i, strText.GetBuffer(len), len);
//buffString = m_strReceive;//编辑框值变量,原始数据保存在该变量
split.SetSplitFlag(_T(","));
split.SetSequenceAsOne(TRUE);
split.SetData(buffString);
CStringArray array;
split.GetSplitStrArray(array);//数组出现错误
//判断读取的GPS信息的类型
if (array = "$GPRMC")//
{
m_strJD = array.Left(2) + "." + array.Mid(2, 2) + array.Right(6) ;
m_strWD = array.Left(3) + "." + array.Mid(3, 2) + array.Right(6) ;
}
strText.ReleaseBuffer(len);
UpdateData(false);
} C++{:5_90:} 18133942901 发表于 2019-7-24 16:18
C++
每一步都输出一下,看是不是和预想的一样,直接跳到结果太快了,或者你用的编译器也可以单步调试看变化,应该就可以看到哪里出现问题了 joe_mao 发表于 2019-7-24 16:31
每一步都输出一下,看是不是和预想的一样,直接跳到结果太快了,或者你用的编译器也可以单步调试看变化, ...
问题应该出现在:buffString==m_EditRev.GetLine(i, strText.GetBuffer(len), len);通过该句获取内容后,后面会出现乱码:"$GPRMC,075308.60,A,2603.612225,N,11910.677423,E,0.280,245.95,240719,,,A*61췍﷽﷽" 然后再检查这个函数调用,看是不是传参数的时候是不是和它需要的是一个意思,比如说len是不是调用说明的那个len还是数长度要加一,buffer够不够等
页:
[1]