yy1717
2023-03-31 4bd08f0355b6b2cf3c027202d5ad301b4e182953
lib/src/main/cpp/master/comm_if.cpp
@@ -16,6 +16,7 @@
#include "../jni_log.h"
#include "../mcu/mcu_if.h"
#include "../test_common/car_sensor.h"
#include "../map.h"
#include <string>
#include <iostream>
@@ -146,6 +147,31 @@
                DEBUG("发送失败");
                usleep(500000);
                sem_post(&sem_msg_income);
            }
        }
    }
}
static void LoadPoint(PointF &p, const rapidjson::Value &v)
{
    if (v.IsArray() && v.Size() >= 2) {
        p.X = v[0].GetDouble();
        p.Y = v[1].GetDouble();
    }
}
static void LoadPoints(vector<PointF> &ps, const rapidjson::Value &v)
{
    if (v.IsArray()) {
        PointF point;
        for (int i = 0; i < v.Size();) {
            if (v.Size() - i >= 2) {
                point.X = v[i].GetDouble();
                point.Y = v[i+1].GetDouble();
                ps.push_back(point);
                i += 2;
            } else {
                break;
            }
        }
    }
@@ -420,7 +446,7 @@
    writer.Double(brief->coord_y);
    writer.Key("coord_y_dir");
    writer.String(b);
    writer.Key("heading");
    writer.Key("yaw");
    writer.Double(brief->heading);
    writer.Key("pitch");
    writer.Double(brief->pitch);
@@ -556,7 +582,7 @@
    writer.Int(brief->move);
    writer.Key("speed");
    writer.Double(brief->speed);
    writer.Key("heading");
    writer.Key("yaw");
    writer.Double(brief->heading);
    writer.Key("main_ant");
@@ -597,16 +623,16 @@
    writer.Key("body");
    writer.StartArray();
    for (int i = 0; i < brief->bodyNum; ++i) {
    for (int i = 0; i < brief->body.size(); ++i) {
        writer.Int(brief->body[i]);
    }
    writer.EndArray();
    writer.Key("point");
    writer.StartArray();
    for (int i = 0; i < brief->pointNum; ++i) {
        writer.Double(brief->point[i*2]);
        writer.Double(brief->point[i*2+1]);
    for (int i = 0; i < brief->point.size(); ++i) {
        writer.Double(brief->point[i][0]);
        writer.Double(brief->point[i][1]);
    }
    writer.EndArray();
    writer.EndObject();
@@ -1673,63 +1699,136 @@
                    if (a.IsArray()) {
                        for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) {
                            // a Map
                            int id, type, pointNum = 0, point2Num = 0;
                            double (*map)[2] = NULL, (*map2)[2] = NULL;
                            string name;
                            int id = -1, type = -1;
                            //int id, type, pointNum = 0, point2Num = 0;
                            //double (*map)[2] = NULL, (*map2)[2] = NULL;
                            if (itr->IsObject()) {
                                if (itr->HasMember("id")) {
                                    const Value &s = (*itr)["id"];
                                    id = s.GetInt();
                                }
                                if (itr->HasMember("name")) {
                                    const Value &s = (*itr)["id"];
                                    name = s.GetString();
                                }
                                if (itr->HasMember("item")) {
                                    const Value &s = (*itr)["item"];
                                    type = s.GetInt();
                                }
                                if (itr->HasMember("point")) {
                                    const Value &s = (*itr)["point"];
                                    int map_index = 0;
                                    for (Value::ConstValueIterator itr2 = s.Begin();
                                         itr2 != s.End(); ++itr2, ++map_index) {
                                        // 曲线驾驶有2组
                                        const Value &s2 = (*itr2)["x-y"];
                                        if (map_index == 0) {
                                            int i = 0, j = 0;
                                            pointNum = s2.Size() / 2;
                                            map = (double (*)[2]) new double[pointNum][2];
//                                        map = (double (*)[2]) malloc(pointNum * 2 * sizeof(double));
                                            for (Value::ConstValueIterator itr3 = s2.Begin();
                                                 itr3 != s2.End(); ++itr3) {
                                                map[i][j] = (*itr3).GetDouble();
                                                if (++j == 2) {
                                                    j = 0;
                                                    i++;
                                                }
                                    switch (type) {
                                        case MAP_TYPE_CURVE: {
                                            curve_map_t map;
                                            map.id = id;
                                            if (itr->HasMember("left_start_point")) {
                                                const Value &s2 = (*itr)["left_start_point"];
                                                LoadPoint(map.left_start_point, s2);
                                            }
                                        } else if (map_index == 1) {
                                            int i = 0, j = 0;
                                            point2Num = s2.Size() / 2;
                                            map2 = (double (*)[2]) new double[s2.Size()][2];
//                                        map2 = (double (*)[2]) malloc(point2Num * 2 * sizeof(double));
                                            for (Value::ConstValueIterator itr3 = s2.Begin();
                                                 itr3 != s2.End(); ++itr3) {
                                                map2[i][j] = (*itr3).GetDouble();
                                                if (++j == 2) {
                                                    j = 0;
                                                    i++;
                                                }
                                            if (itr->HasMember("right_start_point")) {
                                                const Value &s2 = (*itr)["right_start_point"];
                                                LoadPoint(map.right_start_point, s2);
                                            }
                                            if (itr->HasMember("left_end_point")) {
                                                const Value &s2 = (*itr)["left_end_point"];
                                                LoadPoint(map.left_end_point, s2);
                                            }
                                            if (itr->HasMember("right_end_point")) {
                                                const Value &s2 = (*itr)["right_end_point"];
                                                LoadPoint(map.right_end_point, s2);
                                            }
                                            AddCurveMap(map);
                                            break;
                                        }
                                        case MAP_TYPE_PARK_BUTTOM: {
                                            park_button_map_t map;
                                            map.id = id;
                                            if (itr->HasMember("point") && (*itr)["point"].IsArray()) {
                                                const Value &arr = (*itr)["point"];
                                                LoadPoints(map.map, arr);
                                            }
                                            AddParkButtonMap(map);
                                            break;
                                        }
                                        case MAP_TYPE_PARK_EDGE: {
                                            park_edge_map_t map;
                                            map.id = id;
                                            if (itr->HasMember("point") && (*itr)["point"].IsArray()) {
                                                const Value &arr = (*itr)["point"];
                                                LoadPoints(map.map, arr);
                                            }
                                            AddParkEdgeMap(map);
                                            break;
                                        }
                                        case MAP_TYPE_UPHILL: {
                                            uphill_map_t map;
                                            map.id = id;
                                            if (itr->HasMember("point") && (*itr)["point"].IsArray()) {
                                                const Value &arr = (*itr)["point"];
                                                LoadPoints(map.map, arr);
                                            }
                                            break;
                                        }
                                        case MAP_TYPE_TURN_90: {
                                            turn_a90_map_t map;
                                            map.id = id;
                                            if (itr->HasMember("point") && (*itr)["point"].IsArray()) {
                                                const Value &arr = (*itr)["point"];
                                                LoadPoints(map.map, arr);
                                            }
                                            break;
                                        }
                                        default:
                                            break;
                                    }
                                }
                                AddAreaMap(id, type, map, pointNum, map2, point2Num);
//                                if (itr->HasMember("point")) {
//                                    const Value &s = (*itr)["point"];
//                                    int map_index = 0;
//
//                                    for (Value::ConstValueIterator itr2 = s.Begin();
//                                         itr2 != s.End(); ++itr2, ++map_index) {
//                                        // 曲线驾驶有2组
//                                        const Value &s2 = (*itr2)["x-y"];
//
//                                        if (map_index == 0) {
//                                            int i = 0, j = 0;
//                                            pointNum = s2.Size() / 2;
//                                            map = (double (*)[2]) new double[pointNum][2];
////                                        map = (double (*)[2]) malloc(pointNum * 2 * sizeof(double));
//
//                                            for (Value::ConstValueIterator itr3 = s2.Begin();
//                                                 itr3 != s2.End(); ++itr3) {
//                                                map[i][j] = (*itr3).GetDouble();
//                                                if (++j == 2) {
//                                                    j = 0;
//                                                    i++;
//                                                }
//                                            }
//                                        } else if (map_index == 1) {
//                                            int i = 0, j = 0;
//                                            point2Num = s2.Size() / 2;
//                                            map2 = (double (*)[2]) new double[s2.Size()][2];
////                                        map2 = (double (*)[2]) malloc(point2Num * 2 * sizeof(double));
//
//                                            for (Value::ConstValueIterator itr3 = s2.Begin();
//                                                 itr3 != s2.End(); ++itr3) {
//                                                map2[i][j] = (*itr3).GetDouble();
//                                                if (++j == 2) {
//                                                    j = 0;
//                                                    i++;
//                                                }
//                                            }
//                                        }
//                                    }
//                                }
                                if (map) delete[]map;
                                if (map2) delete[]map2;
//                                AddAreaMap(id, type, map, pointNum, map2, point2Num);
//
//                                if (map) delete[]map;
//                                if (map2) delete[]map2;
                            }
                        }
                    }
@@ -1968,7 +2067,7 @@
            Document doc;
            doc.Parse(value);
            if (!doc.HasParseError()) {
                DEBUG("解析灯光配置...");
                /*DEBUG("解析灯光配置...");
                if (doc.HasMember("exam")) {
                    const Value& s = doc["exam"];
                    s.GetInt();
@@ -2022,12 +2121,11 @@
                        delete []content;
                    }
                }
                }*/
            }
            break;
        }
        case ID_MS_INQ_ROAD_CROSSING: {
            MasterInqRoadStatus();
            break;
        }
        case ID_MS_BLUETOOTH_NAME: {