修正buffer里面的数据处理方式,以前那个清除之后指针丢失
This commit is contained in:
+103
-29
@@ -1267,6 +1267,8 @@ void OPMapWidget::WPFollowPrevious(bool flag,WayPointItem *w)
|
||||
//先清除再读取
|
||||
void OPMapWidget::WPLoad(QString path)//带文件目录参数
|
||||
{
|
||||
//清除所有
|
||||
WPDeleteAll();
|
||||
qDebug() << "WPLoad" << path;
|
||||
//读取
|
||||
QFile jsonFile(path);
|
||||
@@ -1288,11 +1290,70 @@ void OPMapWidget::WPLoad(QString path)//带文件目录参数
|
||||
QJsonObject json = doc.object();
|
||||
|
||||
//解码
|
||||
QJsonArray itemValue = json.value("mission").toObject().value("items").toArray();
|
||||
QJsonArray itemsArray = json.value("mission").toObject().value("items").toArray();
|
||||
|
||||
for(QJsonValue item: itemsArray) {
|
||||
if (!item.isObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t AMSLAltAboveTerrain = item.toObject().find("AMSLAltAboveTerrain").value().toInt();
|
||||
uint8_t Altitude = item.toObject().find("Altitude").value().toDouble();
|
||||
uint8_t AltitudeMode = item.toObject().find("AltitudeMode").value().toInt();
|
||||
uint8_t autocontinue = item.toObject().find("autoContinue").value().toInt();//bool
|
||||
uint8_t command = item.toObject().find("command").value().toInt();
|
||||
uint16_t seq = item.toObject().find("doJumpId").value().toInt();
|
||||
uint8_t frame = item.toObject().find("frame").value().toInt();
|
||||
QJsonArray params = item.toObject().find("params").value().toArray();//array
|
||||
uint8_t mission_type = item.toObject().find("type").value().toInt();
|
||||
|
||||
float param1 = params.at(0).toDouble();
|
||||
float param2 = params.at(1).toDouble();
|
||||
float param3 = params.at(2).toDouble();
|
||||
float param4 = params.at(3).toDouble();
|
||||
float x = params.at(4).toDouble();
|
||||
float y = params.at(5).toDouble();
|
||||
float z = params.at(6).toDouble();
|
||||
|
||||
internals::PointLatLng LatLng;
|
||||
LatLng.SetLat(x);
|
||||
LatLng.SetLng(y);
|
||||
|
||||
WayPointItem *Item = WPCreate(LatLng,z);
|
||||
|
||||
Item->SetNumber(seq);
|
||||
|
||||
if(command > MAV_CMD::MAV_CMD_NAV_LAST)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//WPLineCreate(WPFind(Item->Number() - 1),Item,Qt::green,false,2);
|
||||
}
|
||||
|
||||
//Item->setParent(map);
|
||||
|
||||
|
||||
|
||||
emit setWPProperty(param1,param2,param3,param4,
|
||||
x,y,z,
|
||||
seq,
|
||||
0,
|
||||
command,
|
||||
0,
|
||||
0,
|
||||
frame,
|
||||
0,
|
||||
autocontinue,
|
||||
mission_type);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
qDebug() << itemValue;
|
||||
|
||||
}
|
||||
|
||||
@@ -1322,41 +1383,52 @@ void OPMapWidget::WPSave(QString path)//带文件目录参数
|
||||
{
|
||||
QJsonArray items;
|
||||
|
||||
QJsonArray plannedHomePosition;
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
if (w) {//逐渐往下增加
|
||||
//存到items
|
||||
QJsonArray params;
|
||||
params.append(w->Param1());
|
||||
params.append(w->Param2());
|
||||
params.append(w->Param3());
|
||||
params.append(w->Param4());
|
||||
params.append(w->Coord().Lat());
|
||||
params.append(w->Coord().Lng());
|
||||
params.append(w->Alt());
|
||||
|
||||
//可能有点问题
|
||||
QJsonObject item;
|
||||
item.insert("AMSLAltAboveTerrain",0);
|
||||
item.insert("Altitude",w->Alt());
|
||||
item.insert("AltitudeMode",1);
|
||||
item.insert("autoContinue",w->AutoContinue());
|
||||
item.insert("command",w->Command());
|
||||
item.insert("doJumpId",w->Number());
|
||||
item.insert("frame",w->Frame());
|
||||
item.insert("params",params);
|
||||
item.insert("type","SimpleItem");
|
||||
if(w->Number()>0)
|
||||
{
|
||||
|
||||
//这里有问题
|
||||
items.append(item);
|
||||
//存到items
|
||||
QJsonArray params;
|
||||
params.append(w->Param1());
|
||||
params.append(w->Param2());
|
||||
params.append(w->Param3());
|
||||
params.append(w->Param4());
|
||||
params.append(w->Coord().Lat());
|
||||
params.append(w->Coord().Lng());
|
||||
params.append(w->Alt());
|
||||
|
||||
//可能有点问题
|
||||
QJsonObject item;
|
||||
item.insert("AMSLAltAboveTerrain",0);
|
||||
item.insert("Altitude",w->Alt());
|
||||
item.insert("AltitudeMode",1);
|
||||
item.insert("autoContinue",w->AutoContinue()?true:false);
|
||||
item.insert("command",w->Command());
|
||||
item.insert("doJumpId",w->Number());
|
||||
item.insert("frame",w->Frame());
|
||||
item.insert("params",params);
|
||||
item.insert("type","SimpleItem");
|
||||
|
||||
//这里有问题
|
||||
items.append(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
plannedHomePosition.append(w->Coord().Lat());
|
||||
plannedHomePosition.append(w->Coord().Lng());
|
||||
plannedHomePosition.append(w->Alt());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QJsonArray plannedHomePosition;
|
||||
plannedHomePosition.append(0);
|
||||
plannedHomePosition.append(1);
|
||||
plannedHomePosition.append(2);
|
||||
|
||||
|
||||
|
||||
|
||||
mission.insert("cruiseSpeed",2);
|
||||
@@ -1504,6 +1576,8 @@ void OPMapWidget::receivedPoint(float param1,float param2,float param3,float par
|
||||
|
||||
WayPointItem *Item = WPCreate(LatLng,z);
|
||||
|
||||
Item->SetNumber(seq+1);
|
||||
|
||||
if(command > MAV_CMD::MAV_CMD_NAV_LAST)
|
||||
{
|
||||
|
||||
@@ -1518,7 +1592,7 @@ void OPMapWidget::receivedPoint(float param1,float param2,float param3,float par
|
||||
|
||||
emit setWPProperty(param1,param2,param3,param4,
|
||||
x,y,z,
|
||||
seq,
|
||||
seq+1,
|
||||
group,
|
||||
command,
|
||||
target_system,
|
||||
|
||||
Reference in New Issue
Block a user