GPS数据解析

This commit is contained in:
LQF 2017-06-21 09:10:21 +08:00
parent e0134dc0a5
commit 7ea4e07fa5
2 changed files with 34 additions and 1 deletions

View File

@ -22,6 +22,10 @@
static const cstring ok = "OK";
static const cstring err = "ERROR";
static float latitude;
static float longitude;
struct CmdState
{
const String* Command = nullptr;
@ -41,6 +45,8 @@ AT::AT()
Port = nullptr;
DataKey = nullptr;
_Expect = nullptr;
latitude = 0;
longitude = 0;
}
AT::~AT()
@ -64,6 +70,18 @@ void AT::Init(ITransport* port)
if (Port) Port->Register(OnPortReceive, this);
}
float AT::GetLatitude()
{
return latitude;
}
float AT::GetLongitude()
{
return longitude;
}
bool AT::Open()
{
if (!Port->Open()) return false;
@ -276,10 +294,22 @@ uint AT::OnReceive(Buffer& bs, void* param)
//bs.Show(true);
bs.AsString().Show(true);*/
//分割数据查询是否有GPS数据输出
auto str = bs.AsString();
auto sp = str.Split(",");
auto sp1=sp.Next();
if (sp1.Contains("+UGNSINF: 1") )
{
sp.Next();
sp.Next();
latitude = sp.Next().ToFloat();
longitude = sp.Next().ToFloat();
return 0;
}
//!!! 分析数据和命令返回,特别要注意粘包
int s = 0;
int p = 0;
auto str = bs.AsString();
while (p >= 0 && p < bs.Length())
{
s = p;

View File

@ -6,6 +6,7 @@ class AT
{
public:
ITransport* Port; // 传输口
cstring DataKey; // 数据关键字
@ -16,6 +17,8 @@ public:
void Init(COM idx, int baudrate = 115200);
void Init(ITransport* port);
float GetLatitude();
float GetLongitude();
// 打开与关闭
bool Open();