// // Created by YY on 2020/1/7. // #include "comm_if.h" #include "../native-lib.h" #include "../rapidjson/document.h" #include "../rapidjson/writer.h" #include "../rapidjson/stringbuffer.h" #include "../rtk_platform/platform.h" #include "../utils/xconvert.h" #include "../driver_test.h" #include "../defs.h" #include "../common/apptimer.h" #include "../jni_log.h" #include "../mcu/mcu_if.h" #include "../test_common/car_sensor.h" #include "../map.h" #include #include #include #include #include #include #include #include #define DEBUG(fmt, args...) LOGD(" <%s>: " fmt, __func__, ##args) using namespace rapidjson; using namespace std; #define ID_SM_NDK_START 0x0001 #define ID_MS_NDK_ACK 0x8001 #define ID_SM_REQ_RTK_PLAT_CFG 0x0002 #define ID_MS_RTK_PLAT_CFG 0x8002 #define ID_SM_RTK_PLAT_CONN 0x0003 #define ID_SM_RTK_PLAT_REG 0x0004 #define ID_SM_RTK_PLAT_LOGIN 0x0005 #define ID_SM_READ_MAP 0x0006 #define ID_MS_MAP 0x8006 #define ID_MS_ROAD_MAP 0x8014 #define ID_MS_ROAD_MAP2 0x8013 #define ID_MS_SCHEME 0x8017 #define ID_MS_EXAM_PARAM 0x8019 #define ID_MS_BLUETOOTH_NAME 0x8020 #define ID_SM_READ_CAR 0x0007 #define ID_MS_CAR 0x8007 #define ID_SM_MCU_BRIEF 0x0008 #define ID_MS_SENSOR_CFG 0x8008 #define ID_MS_START_EXAM 0x8009 #define ID_SM_EXAM_STATUS 0x0009 #define ID_MS_IND_ONOFF 0x800A #define ID_SM_GPS_BRIEF 0x000A #define ID_SM_RTK_BRIEF 0x000B #define ID_SM_EXAM_BRIEF 0x000C #define ID_SM_ENTER_MAP 0x000D #define ID_MS_EXAM_MAP 0x800D #define ID_SM_CAR 0x000E #define ID_SM_RTCM_IND 0x000F #define ID_SM_DEBUG_INFO 0x0010 #define ID_MS_FILE 0x8100 #define ID_MS_READ_CARD 0x8011 #define ID_SM_PUT_CARD 0x0011 #define ID_MS_SYS_SHUTDOWN 0x8010 #define ID_SM_LIGHT_EXAM_REQ 0x0012 #define ID_MS_LIGHT_EXAM_RES 0x8012 #define ID_SM_DISTANCE 0x0020 #define ID_SM_CARSENSOR 0x0013 #define ID_SM_ROAD_BRIEF 0x0015 // 科目三项目标定,进出某条路的提示 #define ID_SM_CROSSING_BRIEF 0x0016 // 科目三项目标定,接近/驶离某各路口的提示 #define ID_MS_INQ_ROAD_CROSSING 0x8018 // Master查询当前路段和路口 #define ID_SM_CAN_BRIEF 0x0021 #define ID_SM_BLUETOOTH_BRIEF 0x0022 #define ID_SM_RTK_STATUS_BRIEF 0x0023 #define MA_OUT_GPS_BRIEF 0x0001 #define MA_OUT_RTK_BRIEF 0x0002 #define MA_OUT_CAR_BRIEF 0x0004 #define MA_OUT_RTCM_IND 0x0008 #define MA_OUT_DBG_INFO 0x0010 static int OnOff = 0xFFFF; struct msg_2_main_t { int cmd; string value; }; static list MessageBuffer; static sem_t sem_msg_income; static std::mutex msg_mutex; static void SendMsgToMainProcIndep(int cmd, const char *value); static void SendMsgToMainProcThread(void); static void SendMsgToMainProcIndep(int cmd, const char *value) { struct msg_2_main_t msg; msg.cmd = cmd; if (value != NULL) { msg.value = value; } else { msg.value.clear(); } lock_guard lock(msg_mutex); // DEBUG("加入传输队列 0x%04X, 当前长度 %d", cmd, MessageBuffer.size()); MessageBuffer.push_front(msg); sem_post(&sem_msg_income); } static void SendMsgToMainProcThread(void) { while (true) { sem_wait(&sem_msg_income); if (MessageBuffer.size() > 0) { struct msg_2_main_t msg; int success; unique_lock lock(msg_mutex); msg = MessageBuffer.back(); lock.unlock(); if (msg.value.length() > 0) success = SendMsgToMainProc(msg.cmd, msg.value.c_str()); else success = SendMsgToMainProc(msg.cmd, NULL); if (success == 0) { lock.lock(); MessageBuffer.pop_back(); lock.unlock(); } else { // 延迟重发 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 &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; } } } } void MA_Init(void) { sem_init(&sem_msg_income, 0, 0); MessageBuffer.clear(); std::thread(SendMsgToMainProcThread).detach(); } void MA_NdkStart(void) { SendMsgToMainProcIndep(ID_SM_NDK_START, NULL); } void MA_ReqRtkPlatformConfig(void) { SendMsgToMainProcIndep(ID_SM_REQ_RTK_PLAT_CFG, NULL); } void MA_RtkPlatformConnect(int conn, const char *ip, int port) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("connected"); writer.Int(conn); writer.Key("ip"); writer.String(ip); writer.Key("port"); writer.Int(port); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_RTK_PLAT_CONN, sb.GetString()); } void MA_RtkPlatformRegister(int reg, const uint8_t *pwd, int length) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("register_code"); writer.Int(reg); if (reg == 0 && length > 0) { writer.Key("password"); char *str = new char[length*2 + 1]; ConvertHex2String(str, pwd, length); writer.String(str); delete[]str; } writer.EndObject(); SendMsgToMainProcIndep(ID_SM_RTK_PLAT_REG, sb.GetString()); } void MA_RtkPlatformLogin(int login) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("login_code"); writer.Int(login); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_RTK_PLAT_LOGIN, sb.GetString()); } void MA_ReadMap(void) { SendMsgToMainProcIndep(ID_SM_READ_MAP, NULL); } void MA_ReadCar(void) { SendMsgToMainProcIndep(ID_SM_READ_CAR, NULL); } void MA_ReadSensor(void) { ReadCard(); } void MA_SendExamStatus(int start, int errorCode) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("exam"); writer.Int(start); writer.Key("error"); writer.Int(errorCode); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_EXAM_STATUS, sb.GetString()); } void MA_SendCardBrief(const struct cardBrief *brief) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("result"); writer.Int(brief->result); writer.Key("serialno"); writer.String(brief->card); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_PUT_CARD, sb.GetString()); } void MA_SendMcuBrief(const struct mcuBrief *brief) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("version"); writer.String(brief->version); writer.Key("selftest"); writer.Int(brief->selftest); // writer.Key("gpio"); // writer.Int(brief->gpio); // writer.Key("speed"); // writer.Int(brief->speed); // writer.Key("engine"); // writer.Int(brief->engine); writer.Key("sn"); writer.String(brief->sn); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_MCU_BRIEF, sb.GetString()); } void MA_SendCarSensorBrief(const struct carSensorBrief *brief) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("odo"); writer.Int(brief->odo); writer.Key("trip"); writer.Int(brief->trip); writer.Key("trip_time"); writer.Int(brief->tripTime); writer.Key("cell_volt"); writer.Double(brief->cellVolt); writer.Key("speed"); writer.Double(brief->speed); writer.Key("engine"); writer.Int(brief->engine); writer.Key("sas"); writer.Int(brief->sas); writer.Key("key"); writer.Int(brief->key); writer.Key("gear"); writer.Int(brief->gear); writer.Key("aps"); writer.Int(brief->aps); writer.Key("lock"); writer.Int(brief->door); writer.Key("seat_belt"); writer.Int(brief->seatBelt); writer.Key("clutch"); writer.Int(brief->clutch); writer.Key("horn"); writer.Int(brief->horn); writer.Key("wiper"); writer.Int(brief->wiper); writer.Key("hand_brake"); writer.Int(brief->handBreak); writer.Key("brake"); writer.Int(brief->mainBreak); writer.Key("left_turn_lamp"); writer.Int(brief->leftTurnLamp); writer.Key("right_turn_lamp"); writer.Int(brief->rightTurnLamp); writer.Key("clearance_lamp"); writer.Int(brief->clearanceLamp); writer.Key("dipped_beam_lamp"); writer.Int(brief->dippedBeamLamp); writer.Key("main_beam_lamp"); writer.Int(brief->mainBeamLamp); writer.Key("fog_lamp"); writer.Int(brief->fogLamp); writer.Key("assist_break"); writer.Int(brief->assBreak); writer.Key("surround1"); writer.Int(brief->surround1); writer.Key("surround2"); writer.Int(brief->surround2); writer.Key("surround3"); writer.Int(brief->surround3); writer.Key("surround4"); writer.Int(brief->surround4); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_CARSENSOR, sb.GetString()); } void MA_SendGpsBrief(const struct gpsBrief *brief) { if (!(OnOff & MA_OUT_GPS_BRIEF)) return; StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("utc"); writer.String(brief->utc); writer.Key("sat_num"); writer.Int(brief->sat_num); writer.Key("qf"); writer.Int(brief->qf); writer.Key("latitude"); writer.Double(brief->latitude); writer.Key("longitude"); writer.Double(brief->longitude); writer.Key("altitude"); writer.Double(brief->altitude); writer.Key("speed"); writer.Double(brief->speed); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_GPS_BRIEF, sb.GetString()); } void MA_SendRtkBrief(const struct rtkBrief *brief) { if (!(OnOff & MA_OUT_RTK_BRIEF)) return; char a[2] = {brief->coord_x_dir, 0}; char b[2] = {brief->coord_y_dir, 0}; StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("utc"); writer.String(brief->utc); writer.Key("qf"); writer.Int(brief->qf); writer.Key("coord_x"); writer.Double(brief->coord_x); writer.Key("coord_x_dir"); writer.String(a); writer.Key("coord_y"); writer.Double(brief->coord_y); writer.Key("coord_y_dir"); writer.String(b); writer.Key("yaw"); writer.Double(brief->heading); writer.Key("pitch"); writer.Double(brief->pitch); writer.Key("roll"); writer.Double(brief->roll); writer.Key("sat_num"); writer.Int(brief->sat_num); writer.Key("latitude"); writer.Double(brief->latitude); writer.Key("longitude"); writer.Double(brief->longitude); writer.Key("altitude"); writer.Double(brief->altitude); writer.Key("speed"); writer.Double(brief->speed); writer.Key("track_ture"); writer.Double(brief->trackTure); writer.Key("rtcm_length"); writer.Int(brief->rtcm_length); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_RTK_BRIEF, sb.GetString()); } void MA_SendDistance(double l, double r) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("left"); writer.Double(l); writer.Key("right"); writer.Double(r); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_DISTANCE, sb.GetString()); } void MA_SendCanStatus(const struct canBrief *brief) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("gpio"); writer.Int(brief->gpio); writer.Key("rpm"); writer.Int(brief->rpm); writer.Key("speed"); writer.Int(brief->speed); writer.Key("voltage"); writer.Int(brief->voltage); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_CAN_BRIEF, sb.GetString()); } void MA_SendRoadStatus(const struct roadStatusBrief *brief) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("road_id"); writer.Int(brief->road_id); writer.Key("status"); writer.Int(brief->status); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_ROAD_BRIEF, sb.GetString()); } void MA_SendCrossingStatus(const struct crossingStatusBrief *brief) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("road_id"); writer.Int(brief->road_id); writer.Key("crossing_index"); writer.Int(brief->crossing_index); writer.Key("status"); writer.Int(brief->status); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_CROSSING_BRIEF, sb.GetString()); } void MA_SendExamWrong(vector &ExamFaultList) { StringBuffer sb; Writer writer(sb); writer.StartArray(); for (vector::iterator iter = ExamFaultList.begin(); iter != ExamFaultList.end(); ++iter) { writer.StartObject(); writer.Key("sn"); writer.Int(iter->sn); writer.Key("utc"); writer.String(iter->utc); writer.Key("wrong_id"); writer.Int(iter->wrong_id); writer.EndObject(); } writer.EndArray(); SendMsgToMainProcIndep(ID_SM_EXAM_BRIEF, sb.GetString()); } void MA_SendCarPosition(const struct carBrief *brief) { if (!(OnOff & MA_OUT_CAR_BRIEF)) return; StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("utc"); writer.String(brief->utc); writer.Key("qf"); writer.Int(brief->qf); writer.Key("map_id"); writer.Int(brief->map_id); writer.Key("move"); writer.Int(brief->move); writer.Key("speed"); writer.Double(brief->speed); writer.Key("yaw"); writer.Double(brief->heading); writer.Key("main_ant"); writer.StartArray(); writer.Double(brief->main_ant[0]); writer.Double(brief->main_ant[1]); writer.EndArray(); writer.Key("axial"); writer.StartArray(); writer.Int(brief->axial[0]); writer.Int(brief->axial[1]); writer.EndArray(); writer.Key("left_front_tire"); writer.StartArray(); writer.Int(brief->left_front_tire[0]); writer.Int(brief->left_front_tire[1]); writer.EndArray(); writer.Key("right_front_tire"); writer.StartArray(); writer.Int(brief->right_front_tire[0]); writer.Int(brief->right_front_tire[1]); writer.EndArray(); writer.Key("left_rear_tire"); writer.StartArray(); writer.Int(brief->left_rear_tire[0]); writer.Int(brief->left_rear_tire[1]); writer.EndArray(); writer.Key("right_rear_tire"); writer.StartArray(); writer.Int(brief->right_rear_tire[0]); writer.Int(brief->right_rear_tire[1]); writer.EndArray(); writer.Key("body"); writer.StartArray(); 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->point.size(); ++i) { writer.Double(brief->point[i][0]); writer.Double(brief->point[i][1]); } writer.EndArray(); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_CAR, sb.GetString()); } void MA_SendRtcmInd(int length) { if (!(OnOff & MA_OUT_RTCM_IND)) return; StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("length"); writer.Int(length); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_RTCM_IND, sb.GetString()); } void MA_SendDebugInfo(const char *str, ...) { if (!(OnOff & MA_OUT_DBG_INFO)) return; va_list argp; char buffer[1024]; va_start(argp, str); vsprintf(buffer, str, argp); va_end(argp); StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("info"); writer.String(buffer); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_DEBUG_INFO, sb.GetString()); } void MA_MainProcMsgEntry(int cmd, const char *value) { switch (cmd) { case ID_MS_RTK_PLAT_CFG: { DEBUG("平台信息 %s", value); if (OnOff == 0) OnOff = MA_OUT_GPS_BRIEF + MA_OUT_RTK_BRIEF + MA_OUT_CAR_BRIEF; rtk_platform_cfg_t cfg; memset(&cfg, 0, sizeof(cfg)); Document d; d.Parse(value); if (d.HasMember("ip")) { Value& s = d["ip"]; strcpy(cfg.domain_name, s.GetString()); } if (d.HasMember("port")) { Value& s = d["port"]; cfg.port = s.GetInt(); } if (d.HasMember("province")) { Value& s = d["province"]; cfg.province = s.GetInt(); } if (d.HasMember("city")) { Value& s = d["city"]; cfg.city = s.GetInt(); } if (d.HasMember("model")) { Value& s = d["model"]; strcpy(cfg.device_model, s.GetString()); } if (d.HasMember("sn")) { Value& s = d["sn"]; strcpy(cfg.device_sn, s.GetString()); } if (d.HasMember("imei")) { Value& s = d["imei"]; strcpy(cfg.imei, s.GetString()); } if (d.HasMember("phone")) { Value& s = d["phone"]; strcpy(cfg.phone, s.GetString()); } if (d.HasMember("password")) { Value& s = d["password"]; strcpy(cfg.password, s.GetString()); } if (d.HasMember("registered")) { Value& s = d["registered"]; cfg.registered = s.GetInt(); } if (d.HasMember("interval")) { Value& s = d["interval"]; cfg.rtk_interval = s.GetInt(); } ConfigPlatform(&cfg); break; } case ID_MS_EXAM_PARAM: { Document doc; doc.Parse(value); /*if (!doc.HasParseError()) { if (doc.HasMember("hold_start_key_limit_time")) { const Value &a = doc["hold_start_key_limit_time"]; examParam.hold_start_key_limit_time = a.GetInt(); DEBUG("hold_start_key_limit_time = %d", examParam.hold_start_key_limit_time); } if (doc.HasMember("curve_pause_criteria")) { const Value &a = doc["curve_pause_criteria"]; examParam.curve_pause_criteria = a.GetInt(); DEBUG("curve_pause_criteria = %d", examParam.curve_pause_criteria); } if (doc.HasMember("park_bottom_pause_criteria")) { const Value &a = doc["park_bottom_pause_criteria"]; examParam.park_bottom_pause_criteria = a.GetInt(); DEBUG("park_bottom_pause_criteria = %d", examParam.park_bottom_pause_criteria); } if (doc.HasMember("park_bottom_limit_time")) { const Value &a = doc["park_bottom_limit_time"]; examParam.park_bottom_limit_time = D_SEC(a.GetInt()); DEBUG("park_bottom_limit_time = %d", examParam.park_bottom_limit_time); } if (doc.HasMember("park_edge_pause_criteria")) { const Value &a = doc["park_edge_pause_criteria"]; examParam.park_edge_pause_criteria = a.GetInt(); DEBUG("park_edge_pause_criteria = %d", examParam.park_edge_pause_criteria); } if (doc.HasMember("park_edge_limit_time")) { const Value &a = doc["park_edge_limit_time"]; examParam.park_edge_limit_time = D_SEC(a.GetInt()); DEBUG("park_edge_limit_time = %d", examParam.park_edge_limit_time); } if (doc.HasMember("turn_a90_pause_criteria")) { const Value &a = doc["turn_a90_pause_criteria"]; examParam.turn_a90_pause_criteria = a.GetInt(); DEBUG("turn_a90_pause_criteria = %d", examParam.turn_a90_pause_criteria); } if (doc.HasMember("ramp_stoppoint_red_distance")) { const Value &a = doc["ramp_stoppoint_red_distance"]; examParam.ramp_stoppoint_red_distance = a.GetDouble(); DEBUG("ramp_stoppoint_red_distance = %f", examParam.ramp_stoppoint_red_distance); } if (doc.HasMember("ramp_edge_yellow_distance")) { const Value &a = doc["ramp_edge_yellow_distance"]; examParam.ramp_edge_yellow_distance = a.GetDouble(); DEBUG("ramp_edge_yellow_distance = %f", examParam.ramp_edge_yellow_distance); } if (doc.HasMember("ramp_edge_red_distance")) { const Value &a = doc["ramp_edge_red_distance"]; examParam.ramp_edge_red_distance = a.GetDouble(); DEBUG("ramp_edge_red_distance = %f", examParam.ramp_edge_red_distance); } if (doc.HasMember("ramp_slide_yellow_distance")) { const Value &a = doc["ramp_slide_yellow_distance"]; examParam.ramp_slide_yellow_distance = a.GetDouble(); DEBUG("ramp_slide_yellow_distance = %f", examParam.ramp_slide_yellow_distance); } if (doc.HasMember("ramp_slide_red_distance")) { const Value &a = doc["ramp_slide_red_distance"]; examParam.ramp_slide_red_distance = a.GetDouble(); DEBUG("ramp_slide_red_distance = %f", examParam.ramp_slide_red_distance); } if (doc.HasMember("ramp_start_car_limit_time")) { const Value &a = doc["ramp_start_car_limit_time"]; examParam.ramp_start_car_limit_time = D_SEC(a.GetInt()); DEBUG("ramp_start_car_limit_time = %d", examParam.ramp_start_car_limit_time); } if (doc.HasMember("road_slide_yellow_distance")) { const Value &a = doc["road_slide_yellow_distance"]; examParam.road_slide_yellow_distance = a.GetDouble(); DEBUG("road_slide_yellow_distance = %f", examParam.road_slide_yellow_distance); } double road_slide_red_distance; if (doc.HasMember("road_slide_red_distance")) { const Value &a = doc["road_slide_red_distance"]; examParam.road_slide_red_distance = a.GetDouble(); DEBUG("road_slide_red_distance = %f", examParam.road_slide_red_distance); } if (doc.HasMember("road_total_distance")) { const Value &a = doc["road_total_distance"]; examParam.road_total_distance = a.GetInt(); DEBUG("road_total_distance = %d", examParam.road_total_distance); } if (doc.HasMember("road_max_speed")) { const Value &a = doc["road_max_speed"]; examParam.road_max_speed = a.GetInt(); DEBUG("road_max_speed = %d", examParam.road_max_speed); } if (doc.HasMember("gear_speed_table")) { const Value &a = doc["gear_speed_table"]; int m = 0, n = 0; if (a.IsArray()) { for (Value::ConstValueIterator itr = a.Begin(); itr != a.End() && m < 6; ++itr, ++m) { n = 0; if ((*itr).IsArray()) { for (Value::ConstValueIterator itr2 = (*itr).Begin(); itr2 != (*itr).End() && n < 2; ++itr2, ++n) { examParam.gear_speed_table[m][n] = (*itr2).GetInt(); DEBUG("gear_speed_table[%d][%d] = %d", m, n, examParam.gear_speed_table[m][n]); } } } } } if (doc.HasMember("gear_n_allow_time")) { const Value &a = doc["gear_n_allow_time"]; examParam.gear_n_allow_time = D_SEC(a.GetInt()); DEBUG("gear_n_allow_time = %d", examParam.gear_n_allow_time); } if (doc.HasMember("same_gear_min_time")) { const Value &a = doc["same_gear_min_time"]; examParam.same_gear_min_time = D_SEC(a.GetInt()); DEBUG("same_gear_min_time = %d", examParam.same_gear_min_time); } if (doc.HasMember("gear_speed_error_cumulative_time")) { const Value &a = doc["gear_speed_error_cumulative_time"]; examParam.gear_speed_error_cumulative_time = D_SEC(a.GetInt()); DEBUG("gear_speed_error_cumulative_time = %d", examParam.gear_speed_error_cumulative_time); } if (doc.HasMember("road_pause_criteria")) { const Value &a = doc["road_pause_criteria"]; examParam.road_pause_criteria = a.GetInt(); DEBUG("road_pause_criteria = %d", examParam.road_pause_criteria); } if (doc.HasMember("continuous_change_lane_min_time")) { const Value &a = doc["continuous_change_lane_min_time"]; examParam.continuous_change_lane_min_time = D_SEC(a.GetInt()); DEBUG("continuous_change_lane_min_time = %d", examParam.continuous_change_lane_min_time); } if (doc.HasMember("crash_dotted_line_cumulative_time")) { const Value &a = doc["crash_dotted_line_cumulative_time"]; examParam.crash_dotted_line_cumulative_time = D_SEC(a.GetInt()); DEBUG("crash_dotted_line_cumulative_time = %d", examParam.crash_dotted_line_cumulative_time); } if (doc.HasMember("turn_signal_min_advance")) { const Value &a = doc["turn_signal_min_advance"]; examParam.turn_signal_min_advance = D_SEC(a.GetInt()); DEBUG("turn_signal_min_advance = %d", examParam.turn_signal_min_advance); } if (doc.HasMember("start_car_max_rpm")) { const Value &a = doc["start_car_max_rpm"]; examParam.start_car_max_rpm = a.GetInt(); DEBUG("start_car_max_rpm = %d", examParam.start_car_max_rpm); } if (doc.HasMember("start_car_limit_distance")) { const Value &a = doc["start_car_limit_distance"]; examParam.start_car_limit_distance = a.GetInt(); DEBUG("start_car_limit_distance = %d", examParam.start_car_limit_distance); } if (doc.HasMember("open_door_drive_allow_distance")) { const Value &a = doc["open_door_drive_allow_distance"]; examParam.open_door_drive_allow_distance = a.GetDouble(); DEBUG("open_door_drive_allow_distance = %f", examParam.open_door_drive_allow_distance); } if (doc.HasMember("change_lane_limit_distance")) { const Value &a = doc["change_lane_limit_distance"]; examParam.change_lane_limit_distance = a.GetInt(); DEBUG("change_lane_limit_distance = %d", examParam.change_lane_limit_distance); } if (doc.HasMember("shift_limit_distance")) { const Value &a = doc["shift_limit_distance"]; examParam.shift_limit_distance = a.GetInt(); DEBUG("shift_limit_distance = %d", examParam.shift_limit_distance); } if (doc.HasMember("shift_hold_time")) { const Value &a = doc["shift_hold_time"]; examParam.shift_hold_time = D_SEC(a.GetInt()); DEBUG("shift_hold_time = %d", examParam.shift_hold_time); } int straight_limit_distance; if (doc.HasMember("straight_limit_distance")) { const Value &a = doc["straight_limit_distance"]; examParam.straight_limit_distance = a.GetInt(); DEBUG("straight_limit_distance = %d", examParam.straight_limit_distance); } if (doc.HasMember("straight_max_offset")) { const Value &a = doc["straight_max_offset"]; examParam.straight_max_offset = a.GetDouble(); DEBUG("straight_max_offset = %f", examParam.straight_max_offset); } if (doc.HasMember("overtake_limit_distance")) { const Value &a = doc["overtake_limit_distance"]; examParam.overtake_limit_distance = a.GetInt(); DEBUG("overtake_limit_distance = %d", examParam.overtake_limit_distance); } if (doc.HasMember("stop_car_limit_distance")) { const Value &a = doc["stop_car_limit_distance"]; examParam.stop_car_limit_distance = a.GetInt(); DEBUG("stop_car_limit_distance = %d", examParam.stop_car_limit_distance); } if (doc.HasMember("stop_car_open_door_allow_time")) { const Value &a = doc["stop_car_open_door_allow_time"]; examParam.stop_car_open_door_allow_time = D_SEC(a.GetInt()); DEBUG("stop_car_open_door_allow_time = %d", examParam.stop_car_open_door_allow_time); } if (doc.HasMember("stop_car_edge_red_distance")) { const Value &a = doc["stop_car_edge_red_distance"]; examParam.stop_car_edge_red_distance = a.GetDouble(); DEBUG("stop_car_edge_red_distance = %f", examParam.stop_car_edge_red_distance); } if (doc.HasMember("stop_car_edge_yellow_distance")) { const Value &a = doc["stop_car_edge_yellow_distance"]; examParam.stop_car_edge_yellow_distance = a.GetDouble(); DEBUG("stop_car_edge_yellow_distance = %f", examParam.stop_car_edge_yellow_distance); } if (doc.HasMember("crossing_stop_valid_distance")) { const Value &a = doc["crossing_stop_valid_distance"]; examParam.crossing_stop_valid_distance = a.GetDouble(); DEBUG("crossing_stop_valid_distance = %f", examParam.crossing_stop_valid_distance); } if (doc.HasMember("cross_school_max_speed")) { const Value &a = doc["cross_school_max_speed"]; examParam.cross_school_max_speed = a.GetInt(); DEBUG("cross_school_max_speed = %d", examParam.cross_school_max_speed); } if (doc.HasMember("crossing_break_valid_distance")) { const Value &a = doc["crossing_break_valid_distance"]; examParam.crossing_break_valid_distance = a.GetInt(); DEBUG("crossing_break_valid_distance = %d", examParam.crossing_break_valid_distance); } }*/ break; } case ID_MS_MAP: { Document doc; doc.Parse(value); if (!doc.HasParseError()) { ClearAreaMap(); if (doc.IsObject() && doc.HasMember("items")) { const Value &a = doc["items"]; if (a.IsArray()) { for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) { if (itr->IsObject()) { if (itr->HasMember("item")) { const Value &s = (*itr)["item"]; // 项目类型:倒库,侧方停车... int type = s.GetInt(); switch (type) { case MAP_TYPE_CURVE: { curve_map_t map; if (itr->HasMember("id")) { const Value &s2 = (*itr)["id"]; map.id = s2.GetInt(); } if (itr->HasMember("name")) { const Value &s2 = (*itr)["name"]; map.name = s2.GetString(); } if (itr->HasMember("left_start_point")) { const Value &s2 = (*itr)["left_start_point"]; LoadPoint(map.left_start_point, s2); } 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); } if (itr->HasMember("front_half_big_circle_centre")) { const Value &s2 = (*itr)["front_half_big_circle_centre"]; LoadPoint(map.right_end_point, s2); } if (itr->HasMember("front_half_big_circle_radius")) { const Value &s2 = (*itr)["front_half_big_circle_radius"]; map.front_half_big_circle_radius = s2.GetDouble(); } if (itr->HasMember("front_half_small_circle_centre")) { const Value &s2 = (*itr)["front_half_small_circle_centre"]; LoadPoint(map.right_end_point, s2); } if (itr->HasMember("front_half_small_circle_radius")) { const Value &s2 = (*itr)["front_half_small_circle_radius"]; map.front_half_small_circle_radius = s2.GetDouble(); } if (itr->HasMember("back_half_big_circle_centre")) { const Value &s2 = (*itr)["back_half_big_circle_centre"]; LoadPoint(map.right_end_point, s2); } if (itr->HasMember("back_half_big_circle_radius")) { const Value &s2 = (*itr)["back_half_big_circle_radius"]; map.back_half_big_circle_radius = s2.GetDouble(); } if (itr->HasMember("back_half_small_circle_centre")) { const Value &s2 = (*itr)["back_half_small_circle_centre"]; LoadPoint(map.right_end_point, s2); } if (itr->HasMember("back_half_small_circle_radius")) { const Value &s2 = (*itr)["back_half_small_circle_radius"]; map.back_half_small_circle_radius = s2.GetDouble(); } //AddCurveMap(map); break; } case MAP_TYPE_PARK_BUTTOM: { park_button_map_t map; if (itr->HasMember("id")) { const Value &s2 = (*itr)["id"]; map.id = s2.GetInt(); } if (itr->HasMember("name")) { const Value &s2 = (*itr)["name"]; map.name = s2.GetString(); } if (itr->HasMember("line_width")) { const Value &s2 = (*itr)["line_width"]; map.line_width = s2.GetDouble(); } if (itr->HasMember("point") && (*itr)["point"].IsArray()) { const Value &arr = (*itr)["point"][0]["x-y"]; LoadPoints(map.points, arr); } AddParkButtonMap(map); break; } case MAP_TYPE_PARK_EDGE: { park_edge_map_t map; if (itr->HasMember("id")) { const Value &s2 = (*itr)["id"]; map.id = s2.GetInt(); } if (itr->HasMember("name")) { const Value &s2 = (*itr)["name"]; map.name = s2.GetString(); } if (itr->HasMember("line_width")) { const Value &s2 = (*itr)["line_width"]; map.line_width = s2.GetDouble(); } if (itr->HasMember("point") && (*itr)["point"].IsArray()) { const Value &arr = (*itr)["point"][0]["x-y"]; LoadPoints(map.points, arr); } AddParkEdgeMap(map); break; } case MAP_TYPE_UPHILL: { uphill_map_t map; if (itr->HasMember("id")) { const Value &s2 = (*itr)["id"]; map.id = s2.GetInt(); } if (itr->HasMember("name")) { const Value &s2 = (*itr)["name"]; map.name = s2.GetString(); } if (itr->HasMember("point") && (*itr)["point"].IsArray()) { const Value &arr = (*itr)["point"][0]["x-y"]; LoadPoints(map.points, arr); } AddUphillMap(map); break; } case MAP_TYPE_RIGHT_CORNER: { turn_a90_map_t map; if (itr->HasMember("id")) { const Value &s2 = (*itr)["id"]; map.id = s2.GetInt(); } if (itr->HasMember("name")) { const Value &s2 = (*itr)["name"]; map.name = s2.GetString(); } if (itr->HasMember("point") && (*itr)["point"].IsArray()) { const Value &arr = (*itr)["point"][0]["x-y"]; LoadPoints(map.points, arr); } AddTurnA90Map(map); break; } default: break; } } // 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++; // } // } // } // } // } // AddAreaMap(id, type, map, pointNum, map2, point2Num); // // if (map) delete[]map; // if (map2) delete[]map2; } } } } } break; } case ID_MS_CAR: { Document doc; doc.Parse(value); if (!doc.HasParseError()) { double basePoint[2]; int axial[2], left_front_tire[2], right_front_tire[2], left_rear_tire[2], right_rear_tire[2]; int bodyNum = 0; int *body = NULL; int pointNum = 0; double antPitch = 0; double antHeight = 0; double groundHeight = 0; double (*point)[2] = NULL; if (doc.HasMember("main_ant")) { const Value& s = doc["main_ant"]; if (s.IsArray()) { int i = 0; for(Value::ConstValueIterator itr = s.Begin(); itr != s.End(); ++itr) { if (i < 2) basePoint[i++] = itr->GetDouble(); } } } if (doc.HasMember("axial")) { const Value& s = doc["axial"]; if (s.IsArray()) { int i = 0; for(Value::ConstValueIterator itr = s.Begin(); itr != s.End(); ++itr) { if (i < 2) axial[i++] = itr->GetInt(); } } } if (doc.HasMember("left_front_tire")) { const Value& s = doc["left_front_tire"]; if (s.IsArray()) { int i = 0; for(Value::ConstValueIterator itr = s.Begin(); itr != s.End(); ++itr) { if (i < 2) left_front_tire[i++] = itr->GetInt(); } } } if (doc.HasMember("right_front_tire")) { const Value& s = doc["right_front_tire"]; if (s.IsArray()) { int i = 0; for(Value::ConstValueIterator itr = s.Begin(); itr != s.End(); ++itr) { if (i < 2) right_front_tire[i++] = itr->GetInt(); } } } if (doc.HasMember("left_rear_tire")) { const Value& s = doc["left_rear_tire"]; if (s.IsArray()) { int i = 0; for(Value::ConstValueIterator itr = s.Begin(); itr != s.End(); ++itr) { if (i < 2) left_rear_tire[i++] = itr->GetInt(); } } } if (doc.HasMember("right_rear_tire")) { const Value& s = doc["right_rear_tire"]; if (s.IsArray()) { int i = 0; for(Value::ConstValueIterator itr = s.Begin(); itr != s.End(); ++itr) { if (i < 2) right_rear_tire[i++] = itr->GetInt(); } } } if (doc.HasMember("body")) { const Value& s = doc["body"]; if (s.IsArray()) { int i = 0; bodyNum = s.Size(); body = new int[bodyNum]; for(Value::ConstValueIterator itr = s.Begin(); itr != s.End(); ++itr) { body[i++] = itr->GetInt(); } } } if (doc.HasMember("point")) { const Value& s = doc["point"]; if (s.IsArray()) { int i = 0, j = 0; pointNum = s.Size()/2; point = (double (*)[2]) new double[pointNum][2]; // point = (double (*)[2])malloc(pointNum * 2 * sizeof(double)); for(Value::ConstValueIterator itr = s.Begin(); itr != s.End(); ++itr) { point[i][j] = itr->GetDouble(); if (++j == 2) { j = 0; i++; } } } } if (doc.HasMember("ant_pitch")) { const Value& s = doc["ant_pitch"]; antPitch = s.GetDouble(); } if (doc.HasMember("ant_height")) { const Value& s = doc["ant_height"]; antHeight = s.GetDouble(); } if (doc.HasMember("ground_height")) { const Value& s = doc["ground_height"]; groundHeight = s.GetDouble(); } SetCarMeasurePoint(basePoint, axial, left_front_tire, right_front_tire, left_rear_tire, right_rear_tire, body, bodyNum, point, pointNum, antPitch, antHeight, groundHeight); if (body != NULL) delete []body; if (point != NULL) delete []point; } break; } case ID_MS_SENSOR_CFG: { /*Document doc; doc.Parse(value); if (!doc.HasParseError()) { const Value &a = doc.GetArray(); if (a.IsArray() && a.Size() > 0) { int n = a.Size(); int i = 0; int (*sensor)[3] = (int (*)[3]) new int[n][3]; for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) { // a gpio mapping if (itr->HasMember("gpio_num")) { const Value &s = (*itr)["gpio_num"]; sensor[i][0] = s.GetInt(); } if (itr->HasMember("func_id")) { const Value &s = (*itr)["func_id"]; sensor[i][1] = s.GetInt(); } if (itr->HasMember("level")) { const Value &s = (*itr)["level"]; sensor[i][2] = s.GetInt(); } ++i; } SetSensorCfg(sensor, n); delete []sensor; } }*/ break; } case ID_MS_START_EXAM: { Document doc; doc.Parse(value); if (!doc.HasParseError()) { int start = 0, type = 0; if (doc.HasMember("exam")) { Value& s = doc["exam"]; start = s.GetInt(); } if (doc.HasMember("type")) { Value& s = doc["type"]; type = s.GetInt(); } StartDriverExam(start, type); } break; } case ID_MS_EXAM_MAP: { Document doc; doc.Parse(value); if (!doc.HasParseError()) { if (doc.HasMember("map_id") && doc.HasMember("exam")) { Value& s = doc["map_id"]; Value& s2 = doc["exam"]; } } break; } case ID_MS_IND_ONOFF: { Document doc; doc.Parse(value); if (!doc.HasParseError()) { if (doc.HasMember("on_off")) { Value& s = doc["on_off"]; do { OnOff = s.GetInt(); } while (OnOff != s.GetInt()); } } break; } case ID_MS_READ_CARD : { ReadCard(); break; } case ID_MS_SYS_SHUTDOWN: { Document doc; doc.Parse(value); if (!doc.HasParseError()) { int event = 0, timeout = 15; if (doc.HasMember("event")) { Value& s = doc["event"]; event = s.GetInt(); } if (doc.HasMember("timeout")) { Value& s = doc["timeout"]; timeout = s.GetInt(); } SystemShutdown(event, timeout); } break; } case ID_MS_LIGHT_EXAM_RES: { Document doc; doc.Parse(value); if (!doc.HasParseError()) { /*DEBUG("解析灯光配置..."); if (doc.HasMember("exam")) { const Value& s = doc["exam"]; s.GetInt(); } if (doc.HasMember("question")) { const Value& s = doc["question"]; if (s.IsArray() && s.Size() > 0) { int n = 0; struct dummy_light_exam *content = new struct dummy_light_exam[s.Size()]; DEBUG("题目数量 %d", s.Size()); for(Value::ConstValueIterator itr = s.Begin(); itr != s.End(); ++itr) { if (itr->HasMember("item") && itr->HasMember("tts")) { const Value &s1 = (*itr)["item"]; const Value &s2 = (*itr)["tts"]; content[n].item = s1.GetInt(); content[n].tts = s2.GetString(); DEBUG("题目 %s", s2.GetString()); } if (itr->HasMember("wrong_code")) { const Value &s = (*itr)["wrong_code"]; content[n].wrongCode = s.GetInt(); DEBUG("题目wrongCode %d", s.GetInt()); } if (itr->HasMember("process")) { const Value& s = (*itr)["process"]; for(Value::ConstValueIterator itr2 = s.Begin(); itr2 != s.End(); ++itr2) { DEBUG("题目process %d", itr2->GetInt()); content[n].process.push_back(itr2->GetInt()); } } if (itr->HasMember("solution")) { const Value& s = (*itr)["solution"]; for(Value::ConstValueIterator itr2 = s.Begin(); itr2 != s.End(); ++itr2) { DEBUG("题目solution %d", itr2->GetInt()); content[n].solution.push_back(itr2->GetInt()); } } n++; } SetDummyLightExam(n, content); delete []content; } }*/ } break; } case ID_MS_INQ_ROAD_CROSSING: { break; } case ID_MS_BLUETOOTH_NAME: { Document doc; doc.Parse(value); if (!doc.HasParseError()) { if (doc.HasMember("bluetooth_name") && doc.HasMember("bluetooth_addr")) { const Value& s1 = doc["bluetooth_name"]; const Value& s2 = doc["bluetooth_addr"]; SetRemoteBluetooth(s1.GetString(), s2.GetString()); } else if (doc.HasMember("bluetooth_addr")) { const Value& s = doc["bluetooth_addr"]; SetRemoteBluetooth(NULL, s.GetString()); } } break; } default:break; } } void MA_MainProcBinMsgEntry(int cmd, const uint8_t *value, int length) { switch (cmd) { case ID_MS_FILE: { ////////////////////UploadDfuFile(value, length); break; } default: break; } } void MA_EnterMap(int map_id, int type, int enter) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("map_id"); writer.Int(map_id); writer.Key("type"); writer.Int(type); writer.Key("enter"); writer.Int(enter); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_ENTER_MAP, sb.GetString()); } void MA_ExamLight(void) { SendMsgToMainProcIndep(ID_SM_LIGHT_EXAM_REQ, NULL); } void MA_SendBlueStatus(const char *name, const char *addr, int status) { StringBuffer sb; Writer writer(sb); writer.StartObject(); if (name != NULL) { writer.Key("bluetooth_name"); writer.String(name); } if (addr != NULL) { writer.Key("bluetooth_addr"); writer.String(addr); } writer.Key("bluetooth_status"); writer.Int(status); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_BLUETOOTH_BRIEF, sb.GetString()); } void MA_SendRtkStatus(const char *model, int status) { StringBuffer sb; Writer writer(sb); writer.StartObject(); writer.Key("model"); if (model == NULL || model[0] == 0) { writer.String("Unknown"); } else { writer.String(model); } writer.Key("status"); writer.Int(status); writer.EndObject(); SendMsgToMainProcIndep(ID_SM_RTK_STATUS_BRIEF, sb.GetString()); }