yy1717
2020-05-11 a073dc3c983b4c56c5da92642c9ad11995bdb844
lib/src/main/cpp/master/comm_if.cpp
@@ -37,7 +37,8 @@
#define ID_SM_RTK_PLAT_LOGIN     0x0005
#define ID_SM_READ_MAP          0x0006
#define ID_MS_MAP               0x8006
#define ID_MS_ROAD_MAP          0x8013
#define ID_MS_ROAD_MAP          0x8014
#define ID_MS_ROAD_MAP2         0x8013
#define ID_SM_READ_CAR          0x0007
#define ID_MS_CAR               0x8007
@@ -745,6 +746,263 @@
            }
            break;
        }
        case ID_MS_ROAD_MAP2: {
            Document doc;
            doc.Parse(value);
            if (!doc.HasParseError()) {
                DEBUG("开始解析路考地图");
                vector<PointF> mapPoints;
                mapPoints.clear();
                if (doc.HasMember("points")) {
                    const Value &s = doc["points"];
                    DEBUG("得到所有点 共 %d", s.Size()/2);
                    int n = 0;
                    PointF temp;
                    // X-Y坐标集合
                    for (Value::ConstValueIterator itr = s.Begin();
                         itr != s.End(); ++itr, ++n) {
                        if ((n % 2) == 0) {
                            temp.X = (*itr).GetDouble();
                        } else {
                            temp.Y = (*itr).GetDouble();
                            mapPoints.push_back(temp);
                        }
                    }
                }
                road_exam_map map;
                map.roads.clear();
                map.specialAreas.clear();
                map.triggerLines.clear();
                if (doc.HasMember("road")) {
                    const Value &a = doc["road"];
                    if (a.IsArray()) {
                        for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) {
                            road_t road;
                            if (itr->HasMember("id")) {
                                const Value &s = (*itr)["id"];
                                DEBUG("路id %d", s.GetInt());
                                road.id = s.GetInt();
                            }
                            if (itr->HasMember("start_line")) {
                                const Value &a2 = (*itr)["start_line"];
                                PointF p1, p2;
                                int n = 0;
                                for (Value::ConstValueIterator itr2 = a2.Begin(); itr2 != a2.End(); ++itr2, ++n) {
                                    DEBUG("起始线 %d", (*itr2).GetInt());
                                    if (n == 0) {
                                        p1 = mapPoints[(*itr2).GetInt()];
                                    } else if (n == 1) {
                                        p2 = mapPoints[(*itr2).GetInt()];
                                    }
                                }
                                MakeLine(&road.startLine, &p1, &p2);
                            }
                            if (itr->HasMember("stop_line")) {
                                const Value &a2 = (*itr)["stop_line"];
                                PointF p1, p2;
                                int n = 0;
                                for (Value::ConstValueIterator itr2 = a2.Begin(); itr2 != a2.End(); ++itr2, ++n) {
                                    DEBUG("结束线 %d", (*itr2).GetInt());
                                    if (n == 0) {
                                        p1 = mapPoints[(*itr2).GetInt()];
                                    } else if (n == 1) {
                                        p2 = mapPoints[(*itr2).GetInt()];
                                    }
                                }
                                MakeLine(&road.stopLine, &p1, &p2);
                            }
                            if (itr->HasMember("active")) {
                                const Value &s = (*itr)["active"];
                                DEBUG("路口动作 %d", s.GetInt());
                                road.active = s.GetInt();
                            }
                            if (itr->HasMember("tts")) {
                                const Value &s = (*itr)["tts"];
                                road.tts = s.GetString();
                            }
                            if (itr->HasMember("stop_flag")) {
                                const Value &s = (*itr)["stop_flag"];
                                road.stopFlag = s.GetInt();
                            }
                            if (itr->HasMember("next_road")) {
                                const Value &s = (*itr)["next_road"];
                                road.targetRoad  = s.GetInt();
                            }
                            if (itr->HasMember("left_edge")) {
                                const Value &a2 = (*itr)["left_edge"];
                                DEBUG("左边线");
                                if (a2.IsArray()) {
                                    for (Value::ConstValueIterator itr2 = a2.Begin(); itr2 != a2.End(); ++itr2) {
                                        edge_t edge;
                                        if (itr2->HasMember("type")) {
                                            const Value &s = (*itr2)["type"];
                                            DEBUG("\t类型 %d", s.GetInt());
                                            edge.character = s.GetInt();
                                        }
                                        if (itr2->HasMember("line")) {
                                            const Value &a3 = (*itr2)["line"];
                                            if (a3.IsArray()) {
                                                for (Value::ConstValueIterator itr3 = a3.Begin(); itr3 != a3.End(); ++itr3) {
                                                    DEBUG("\t线点 %d", (*itr3).GetInt());
                                                    edge.points.push_back(mapPoints[(*itr3).GetInt()]);
                                                }
                                            }
                                        }
                                        road.leftEdge.push_back(edge);
                                    }
                                }
                            }
                            if (itr->HasMember("right_edge")) {
                                const Value &a2 = (*itr)["right_edge"];
                                DEBUG("右边线");
                                if (a2.IsArray()) {
                                    for (Value::ConstValueIterator itr2 = a2.Begin(); itr2 != a2.End(); ++itr2) {
                                        edge_t edge;
                                        if (itr2->HasMember("type")) {
                                            const Value &s = (*itr2)["type"];
                                            DEBUG("\t类型 %d", s.GetInt());
                                            edge.character = s.GetInt();
                                        }
                                        if (itr2->HasMember("line")) {
                                            const Value &a3 = (*itr2)["line"];
                                            if (a3.IsArray()) {
                                                for (Value::ConstValueIterator itr3 = a3.Begin(); itr3 != a3.End(); ++itr3) {
                                                    DEBUG("\t线点 %d", (*itr3).GetInt());
                                                    edge.points.push_back(mapPoints[(*itr3).GetInt()]);
                                                }
                                            }
                                        }
                                        road.rightEdge.push_back(edge);
                                    }
                                }
                            }
                            if (itr->HasMember("separate")) {
                                const Value &a2 = (*itr)["separate"];
                                DEBUG("段数量 %d", a2.Size());
                                for (Value::ConstValueIterator itr2 = a2.Begin(); itr2 != a2.End(); ++itr2) {
                                    DEBUG("\t线数量 %d", (*itr2).Size());
                                    separate_t sep;
                                    for (Value::ConstValueIterator itr3 = (*itr2).Begin(); itr3 != (*itr2).End(); ++itr3) {
                                        DEBUG("\t\t节数量 %d", (*itr3).Size());
                                        vector<segment_t> sline;
                                        for (Value::ConstValueIterator itr4 = (*itr3).Begin(); itr4 != (*itr3).End(); ++itr4) {
                                            const Value &type = (*itr4)["type"];
                                            const Value &line = (*itr4)["line"];
                                            segment_t seg;
                                            DEBUG("\t\t\t节类型 = %d", type.GetInt());
                                            seg.character = type.GetInt();
                                            if ((*itr4).HasMember("left_lane_direct")) {
                                                const Value &dir = (*itr4)["left_lane_direct"];
                                                DEBUG("\t\t\t左车道方向 %d", dir.GetInt());
                                                seg.left_lane_direct = dir.GetInt();
                                            } else {
                                                seg.left_lane_direct = 0;
                                            }
                                            if ((*itr4).HasMember("right_lane_direct")) {
                                                const Value &dir = (*itr4)["right_lane_direct"];
                                                DEBUG("\t\t\t右车道方向 %d", dir.GetInt());
                                                seg.right_lane_direct = dir.GetInt();
                                            } else {
                                                seg.right_lane_direct = 0;
                                            }
                                            for (Value::ConstValueIterator itr5 = line.Begin(); itr5 != line.End(); ++itr5) {
                                                DEBUG("\t\t\t点 = %d", (*itr5).GetInt());
                                                seg.points.push_back(mapPoints[(*itr5).GetInt()]);
                                            }
                                            sline.push_back(seg);
                                        }
                                        sep.lines.push_back(sline);
                                    }
                                    road.separate.push_back(sep);
                                }
                            }
                            map.roads.push_back(road);
                        }
                    }
                }
                if (doc.HasMember("special_area")) {
                    const Value &a = doc["special_area"];
                    vector<special_area_t> specialAreas;
                    for (Value::ConstValueIterator itr = a.Begin();
                         itr != a.End(); ++itr) {
                        special_area_t specialArea;
                        if (itr->HasMember("type")) {
                            const Value &s = (*itr)["type"];
                            specialArea.type = s.GetInt();
                        }
                        if (itr->HasMember("id")) {
                            const Value &s = (*itr)["id"];
                            specialArea.id = s.GetInt();
                        }
                        if (itr->HasMember("road")) {
                            const Value &s = (*itr)["road"];
                            specialArea.road = s.GetInt();
                        }
                        if (itr->HasMember("area")) {
                            const Value &a2 = (*itr)["area"];
                            for (Value::ConstValueIterator itr2 = a2.Begin();
                                 itr2 != a2.End(); ++itr2) {
                                specialArea.area.push_back(mapPoints[(*itr2).GetInt()]);
                            }
                        }
                        map.specialAreas.push_back(specialArea);
                    }
                }
                if (doc.HasMember("trigger_line")) {
                }
                DEBUG("地图解析完毕");
                CleanRoadMap();
                SetRoadMap(map);
            } else {
                DEBUG("############## 地图解析出错###################");
            }
            break;
        }
        case ID_MS_MAP: {
            Document doc;
            doc.Parse(value);