getRecords() {
+ return records;
+ }
+
+ public int getStat() {
+ return stat;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getTimestamp() {
+ return timestamp;
+ }
+
+ public Integer getTotalSize() {
+ return totalSize;
+ }
+
+ public Triggerinfo getTriggerinfo() {
+ return triggerinfo;
+ }
+
+ @Override
+ public String toString() {
+ return "AutopilotRecordResult{" +
+ "diskFree=" + diskFree +
+ ", duration=" + duration +
+ ", filename='" + filename + '\'' +
+ ", note='" + note + '\'' +
+ ", key='" + key + '\'' +
+ ", stat=" + stat +
+ ", type=" + type +
+ ", id=" + id +
+ ", timestamp='" + timestamp + '\'' +
+ ", totalSize=" + totalSize +
+ ", triggerinfo=" + triggerinfo +
+ ", records=" + records +
+ '}';
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/bean/record/RecordCauseParam.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/bean/record/RecordCauseParam.java
new file mode 100644
index 0000000000..750b884e43
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/bean/record/RecordCauseParam.java
@@ -0,0 +1,66 @@
+package com.zhidao.support.adas.high.bean.record;
+
+/**
+ * @author song kenan
+ * @des
+ * @date 2021/8/25
+ */
+
+public class RecordCauseParam {
+ private final String action = "record_cause";
+ private Result result;
+
+ public String getAction() {
+ return action;
+ }
+
+ public Result getResult() {
+ return result;
+ }
+
+ public void setResult(Result result) {
+ this.result = result;
+ }
+
+ public static class Result{
+ //bag key 唯一标识
+ private String key;
+ //文件路径
+ private String filename;
+ //接管原因
+ private String reason;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getFilename() {
+ return filename;
+ }
+
+ public void setFilename(String filename) {
+ this.filename = filename;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public void setReason(String reason) {
+ this.reason = reason;
+ }
+
+ }
+
+ @Override
+ public String toString() {
+ return "RecordDataParam{" +
+ "action='" + action + '\'' +
+ ", result='" + result + '\'' +
+ '}';
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/bean/record/RecordDataParam.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/bean/record/RecordDataParam.java
new file mode 100644
index 0000000000..f3ff1966a9
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/bean/record/RecordDataParam.java
@@ -0,0 +1,113 @@
+package com.zhidao.support.adas.high.bean.record;
+
+/**
+ * @author song kenan
+ * @des
+ * @date 2021/8/25
+ */
+
+public class RecordDataParam {
+ private final String action = "record_data";
+ private Result result;
+
+ public String getAction() {
+ return action;
+ }
+
+ public Result getResult() {
+ return result;
+ }
+
+ public void setResult(Result result) {
+ this.result = result;
+ }
+
+ public static class Result{
+ //采集时间
+ private String time;
+ //采集指令 true 采集 , false 停止采集
+ private boolean isRecord;
+ //采集类型 1 badcase; 2 map; 3 rests
+ private int type;
+ //采集id
+ private int id;
+ //是否持续采集
+ private boolean sustain;
+ //采集时间长
+ private int duration;
+ //余留字段
+ private String note;
+
+ public String getTime() {
+ return time;
+ }
+
+ public void setTime(String time) {
+ this.time = time;
+ }
+
+ public boolean getIsRecord() {
+ return isRecord;
+ }
+
+ public void setIsRecord(boolean isRecord) {
+ this.isRecord = isRecord;
+ }
+
+ public boolean isRecord() {
+ return isRecord;
+ }
+
+ public void setRecord(boolean record) {
+ isRecord = record;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public boolean isSustain() {
+ return sustain;
+ }
+
+ public void setSustain(boolean sustain) {
+ this.sustain = sustain;
+ }
+
+ public int getDuration() {
+ return duration;
+ }
+
+ public void setDuration(int duration) {
+ this.duration = duration;
+ }
+
+ public String getNote() {
+ return note;
+ }
+
+ public void setNote(String note) {
+ this.note = note;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "RecordDataParam{" +
+ "action='" + action + '\'' +
+ ", result='" + result + '\'' +
+ '}';
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ActionTypeReceive.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ActionTypeReceive.java
new file mode 100644
index 0000000000..276de17756
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ActionTypeReceive.java
@@ -0,0 +1,152 @@
+package com.zhidao.support.adas.high.common;
+
+/**
+ * 接收的Action
+ *
+ * @author nie yunlong
+ * @description 请求值
+ * @date 2018/7/3
+ */
+public enum ActionTypeReceive {
+
+ /**
+ * udp 消息渲染 action
+ */
+ ACTION_WS_MSG_RENDER_TYPE("view", 0x101, "渲染流 渲染图像"),
+ /**
+ * 周边物体的状态
+ */
+ ACTION_WS_OBSTACLES_MESSAGE_TYPE("obstacles", -1, "周边物体的状态"),
+ /**
+ * 车道线渲染
+ */
+ ACTION_WS_LANES_MESSAGE_TYPE("lanes", -1, "车道线渲染"),
+ /**
+ * 车辆状态
+ */
+ ACTION_WS_CAR_STATE_TYPE("state", 0x102, "车辆状态"),
+ /**
+ * ws 报警消息 action
+ */
+ ACTION_WS_MSG_WARNING_TYPE("warn", -1, "ws 报警消息"),
+ /**
+ * 红绿灯状态
+ */
+ ACTION_UDP_LIGHT_STATE_TYPE("light", -1, "udp 红绿灯状态"),
+ /**
+ * gps数据
+ */
+ ACTION_WS_GPS_TYPE("gdgps", -1, "gps 数据"),
+ /**
+ * 自动驾驶状态
+ */
+ ACTION_WS_AUTOPILOT_STATUE("autopilotstate", -1, "自动驾驶状态"),
+ /**
+ * 自动驾驶控制
+ */
+ ACTION_WS_AUTOPILOT_CONTROL("autopilotmode", -1, "自动驾驶控制"),
+ /**
+ * obu红绿灯数据
+ */
+ ACTION_WS_AI_CLOUD_OBU_RED_GREEN_LIGHT_TYPE("obuTrafficLight", -1, "obu红绿灯数据"),
+ /**
+ * ai云
+ */
+ ACTION_WS_AI_CLOUD_TYPE("aiCloudToStartAutopilot", -1, "云端控制自动驾驶"),
+ /**
+ * 图片大小
+ */
+ ACTION_WS_MSG_IMAGE_SIZE_TYPE("imagesize", -1, "ws 图片大小"),
+ /**
+ * ai云推送 在线车辆
+ */
+ ACTION_WS_AI_CLOUD_ONLINE_CAR_TYPE("aiCloudToOnLineCar", -1, "云端推送在线车辆"),
+ /**
+ * 自动驾驶站点通信
+ */
+ ACTION_WS_AUTOPILOT_WAY_ARRIVE("autopilotArrive", -1, "自动驾驶站点"),
+ /**
+ * 获取自动驾驶路径
+ */
+ ACTION_WS_AUTOPILOT_ROUTE("global_path", -1, "自动驾驶路径"),
+ /**
+ * 查询自动驾驶路径
+ */
+ ACTION_WS_AUTOPILOT_QUERY_ROUTE("query_global_path", -1, "查询自动驾驶路径"),
+ /**
+ * 工控机请求SN
+ */
+ ACTION_WS_AUTOPILOT_SN_REQUEST("autopilotSN", -1, "工控机请求SN"),
+ /**
+ * 监控车辆节点
+ */
+ ACTION_WS_AUTOPILOT_GUARDIAN("guardian", 0x105, "监控车辆节点"),
+ /**
+ * 采集信息
+ */
+ ACTION_WS_AUTOPILOT_IDENTIFY("identify", -1, "FTP消息"),
+ /**
+ * 局部轨迹
+ */
+ ACTION_WS_AUTOPILOT_TRAJECTORY("trajectory", 0x100, "局部轨迹"),
+ /**
+ * car dock 基础信息
+ */
+ ACTION_WS_AUTOPILOT_CAR_CONFIG("car_config", -1, "car_config"),
+ /**
+ * 轨迹列表 routes
+ */
+ ACTION_WS_AUTOPILOT_ROUTES("route_list", 0x104, "轨迹列表"),
+ /**
+ * 工控机升级包下载状态
+ */
+ ACTION_WS_AUTOPILOT_UPGRADE_PATCH_DOWNLOAD_STATUS("ipc_upgrade_patch_download_status", -1, "IPC升级包下载状态"),
+ /**
+ * 工控机升级进度
+ */
+ ACTION_WS_AUTOPILOT_UPGRADE_STATUS("ipc_upgrade_status", -1, "IPC升级状态");
+
+ /**
+ * 消息action 类型
+ */
+ String mActionType;
+
+ /**
+ * 消息action code
+ */
+ int mActionCode;
+ /**
+ * 描述
+ */
+ String mMsgDesc;
+
+ ActionTypeReceive(String actionType, int actionCode, String msgDesc) {
+ this.mActionType = actionType;
+ this.mActionCode = actionCode;
+ this.mMsgDesc = msgDesc;
+ }
+
+ public String getmActionType() {
+ return mActionType;
+ }
+
+ public void setmActionType(String mActionType) {
+ this.mActionType = mActionType;
+ }
+
+ public int getmActionCode() {
+ return mActionCode;
+ }
+
+ public void setmActionCode(int mActionCode) {
+ this.mActionCode = mActionCode;
+ }
+
+ public String getmMsgDesc() {
+ return mMsgDesc;
+ }
+
+ public void setmMsgDesc(String mMsgDesc) {
+ this.mMsgDesc = mMsgDesc;
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/AppPreferenceHelper.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/AppPreferenceHelper.java
new file mode 100644
index 0000000000..bab5488aaf
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/AppPreferenceHelper.java
@@ -0,0 +1,280 @@
+package com.zhidao.support.adas.high.common;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.text.TextUtils;
+import android.util.Base64;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.bean.FaceLoginResponse;
+import com.zhidao.support.adas.high.bean.UserInfo;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+/**
+ * Created by nie yunlong on 2018/4/13.
+ * sharePreference 操作
+ * 根据 具体情况来写
+ */
+
+public class AppPreferenceHelper implements IPreferencesHelper {
+
+ public static AppPreferenceHelper appPreferenceHelper;
+ /**
+ * 保存deviceId 文件名称
+ */
+ private final String UDP_RECEIVER_ADDRESS_FILE_NAME = "upd_receive";
+
+ /**
+ * 假的数据 share
+ */
+ private final String FAKE_DATA_PRE_FILE_NAME = "data_fake";
+ /**
+ * 用户信息
+ */
+ private final String USER_INFO_FILE_NAME = "user_info";
+
+ /**
+ * 保存raw
+ */
+ private final String CONFIG_RAW_FILE_NAME = "raw_config";
+
+ private final String USER_NAME = "user_name";
+
+
+ private final String CONFIG_PRE_FILE_NAME = "config";
+
+ /**
+ * 用户信息pre
+ */
+ private final SharedPreferences mUserLoginInfoPre;
+ /**
+ * 假的数据share
+ */
+ private final SharedPreferences mFakeDataPre;
+
+ private final SharedPreferences mRawConfigPre;
+ /**
+ * 手机Id
+ */
+ private SharedPreferences mDevicePre;
+ /**
+ * 配置标志位
+ */
+ private SharedPreferences mConfigPre;
+ /**
+ * 默认data
+ */
+ private String defaultData = "{\"configInfoHistory\":[{\"kCode\":\"d_fcw_touch\",\"kName\":\"前车碰撞预警\",\"kOrder\":1,\"kType\":\"aided_driving_dic\",\"kVal\":\"5\",\"userId\":0},{\"kCode\":\"d_fcw_start\",\"kName\":\"前车启动提醒\",\"kOrder\":1,\"kType\":\"aided_driving_dic\",\"kVal\":\"5\",\"userId\":0},{\"kCode\":\"d_hdw_driver\",\"kName\":\"驾驶员疲劳/危险预警\",\"kOrder\":1,\"kType\":\"aided_driving_dic\",\"kVal\":\"5\",\"userId\":0},{\"kCode\":\"d_fcw_person\",\"kName\":\"行人碰撞预警\",\"kOrder\":1,\"kType\":\"aided_driving_dic\",\"kVal\":\"5\",\"userId\":0},{\"kCode\":\"d_hdw_sliding\",\"kName\":\"溜车碰撞预警\",\"kOrder\":1,\"kType\":\"aided_driving_dic\",\"kVal\":\"5\",\"userId\":0},{\"kCode\":\"d_ldw_out\",\"kName\":\"车道线偏离预警\",\"kOrder\":1,\"kType\":\"aided_driving_dic\",\"kVal\":\"5\",\"userId\":0},{\"kCode\":\"d_hmw_follow\",\"kName\":\"跟车距离预警\",\"kOrder\":1,\"kType\":\"aided_driving_dic\",\"kVal\":\"5\",\"userId\":0},{\"kCode\":\"d_volume_size\",\"kName\":\"音量大小\",\"kOrder\":1,\"kType\":\"aided_driving_dic\",\"kVal\":\"60\",\"userId\":0},{\"kCode\":\"is_use_ar_navBar\",\"kName\":\"是否使用AR导航\",\"kOrder\":1,\"kType\":\"aided_driving_dic\",\"kVal\":\"5\",\"userId\":0}]}";
+
+ public static AppPreferenceHelper getInstance(Context context) {
+ if (appPreferenceHelper == null) {
+ appPreferenceHelper = new AppPreferenceHelper(context.getApplicationContext());
+ }
+ return appPreferenceHelper;
+ }
+
+ private AppPreferenceHelper(Context context) {
+ mDevicePre = context.getSharedPreferences(UDP_RECEIVER_ADDRESS_FILE_NAME, Context.MODE_PRIVATE);
+ mUserLoginInfoPre = context.getSharedPreferences(USER_INFO_FILE_NAME, Context.MODE_PRIVATE);
+ mFakeDataPre = context.getSharedPreferences(FAKE_DATA_PRE_FILE_NAME, Context.MODE_PRIVATE);
+ mRawConfigPre = context.getSharedPreferences(CONFIG_RAW_FILE_NAME, Context.MODE_PRIVATE);
+ mConfigPre = context.getSharedPreferences(CONFIG_PRE_FILE_NAME, Context.MODE_PRIVATE);
+ }
+
+ @Override
+ public void saveUdpClientAddress(String address) {
+ mDevicePre.edit().putString("upd_client_address", address).apply();
+ }
+
+ @Override
+ public String getUdpClientAddress() {
+ return mDevicePre.getString("upd_client_address", null);
+ }
+
+ @Override
+ public void saveDockConfig(String dockConfig) {
+ mDevicePre.edit().putString("dock_version", dockConfig).apply();
+ }
+
+ @Override
+ public String getDockConfig() {
+ return mDevicePre.getString("dock_version", null);
+ }
+
+ @Override
+ public void setUserInfo(FaceLoginResponse.DataBean loginResponse) {
+
+ try {
+ saveUser(mUserLoginInfoPre, "userInfo", loginResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ @Override
+ public FaceLoginResponse.DataBean getUserInfo() {
+ return getUser(mUserLoginInfoPre, "userInfo");
+ }
+
+ @Override
+ public void setConfigNaviMapVis(int selectIndex) {
+ mFakeDataPre.edit().putInt("selectIndex", selectIndex).apply();
+ }
+
+ @Override
+ public int getConfigNaviMapVis() {
+ return mFakeDataPre.getInt("selectIndex", 1);
+ }
+
+
+ private void saveUser(SharedPreferences sharedPreferences, String key, FaceLoginResponse.DataBean user) throws Exception {
+ if (user instanceof Serializable) {
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ //把对象写到流里
+ oos.writeObject(user);
+ String temp = new String(Base64.encode(baos.toByteArray(), Base64.DEFAULT));
+ editor.putString(key, temp);
+ editor.commit();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ } else {
+ throw new Exception("User must implements Serializable");
+ }
+ }
+
+
+ private FaceLoginResponse.DataBean getUser(SharedPreferences sharedPreferences, String key) {
+ String temp = sharedPreferences.getString(key, "");
+ FaceLoginResponse.DataBean user = null;
+ try {
+ if (!TextUtils.isEmpty(temp)) {
+ ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decode(temp.getBytes(), Base64.DEFAULT));
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ user = (FaceLoginResponse.DataBean) ois.readObject();
+ }
+ } catch (IOException e) {
+ } catch (ClassNotFoundException e1) {
+
+ }
+ try {
+ if (user == null) {
+ //是空的 使用默认的配置
+ Gson gson = new Gson();
+ FaceLoginResponse.DataBean dataConfig = gson.fromJson(defaultData, FaceLoginResponse.DataBean.class);
+
+ saveUser(mUserLoginInfoPre, "userInfo", dataConfig);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return user;
+ }
+
+ @Override
+ public void saveUserUnInfo(UserInfo userInfo) {
+ if (userInfo == null) {
+ userInfo = new UserInfo();
+ }
+ if (userInfo instanceof Serializable) {
+ SharedPreferences.Editor editor = mUserLoginInfoPre.edit();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ //把对象写到流里
+ oos.writeObject(userInfo);
+ String temp = new String(Base64.encode(baos.toByteArray(), Base64.DEFAULT));
+ editor.putString("userInfoId", temp);
+ editor.apply();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ public UserInfo getUserUnInfo() {
+ String temp = mUserLoginInfoPre.getString("userInfoId", "");
+ ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decode(temp.getBytes(), Base64.DEFAULT));
+ UserInfo user = null;
+ try {
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ user = (UserInfo) ois.readObject();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ if (user == null) {
+ user = new UserInfo();
+ }
+ return user;
+ }
+
+ @Override
+ public void setConfigInitResutl(boolean flag) {
+ mConfigPre.edit().putBoolean("configInit", flag).apply();
+ }
+
+ @Override
+ public boolean getConfigInitResutl() {
+ return mConfigPre.getBoolean("configInit", false);
+ }
+
+
+ @Override
+ public void setSelectCarInfo(String brand, String model, String style) {
+ mConfigPre.edit().putString("brand", brand).putString("model", model).putString("style", style).apply();
+ }
+
+ @Override
+ public String getSelectBrand() {
+ return mConfigPre.getString("brand", "");
+ }
+
+ @Override
+ public String getSelectModel() {
+ return mConfigPre.getString("model", "");
+ }
+
+ @Override
+ public String getSelectStyle() {
+ return mConfigPre.getString("style", "");
+ }
+
+
+
+ @Override
+ public void saveRawPath(int rawName, String rawPath) {
+
+ mRawConfigPre.edit().putString("" + rawName, rawPath).apply();
+ }
+
+ @Override
+ public String getRawPath(int rawName) {
+ return mRawConfigPre.getString("" + rawName, "");
+ }
+
+ @Override
+ public void clearRawConfig(int rawName) {
+ mRawConfigPre.edit().putString("" + rawName, "").apply();
+ }
+
+ @Override
+ public void setAppAttachTime(long time) {
+ mRawConfigPre.edit().putLong("appAttachTime", time).commit();
+ }
+
+ @Override
+ public long getAppAttachTime() {
+ return mRawConfigPre.getLong("appAttachTime", 3000);
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/BaseIoUtils.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/BaseIoUtils.java
new file mode 100644
index 0000000000..c5cbd962b6
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/BaseIoUtils.java
@@ -0,0 +1,84 @@
+package com.zhidao.support.adas.high.common;
+
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Created by nie yunlong on 2018/4/9.
+ * IO 操作
+ */
+
+public class BaseIoUtils {
+
+ public static final int DEFAULT_IMAGE_TOTAL_SIZE = 500 * 1024; // 500 Kb
+
+ /**
+ * 从输入流中获取数据
+ *
+ * @param inStream 输入流
+ * @return
+ * @throws Exception
+ */
+ public static byte[] readInputStreamToByte(InputStream inStream) throws Exception {
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int len = 0;
+ while ((len = inStream.read(buffer)) != -1) {
+ outStream.write(buffer, 0, len);
+ }
+ inStream.close();
+ return outStream.toByteArray();
+ }
+
+ /**
+ * 从输入流中获取数据
+ *
+ * @param inStream 输入流
+ * @return
+ * @throws Exception
+ */
+ public static String readInputStreamToString(InputStream inStream) throws Exception {
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int len = 0;
+ while ((len = inStream.read(buffer)) != -1) {
+ outStream.write(buffer, 0, len);
+ }
+ inStream.close();
+ return outStream.toString("utf-8");
+ }
+
+ public static void closeSilently(Closeable closeable) {
+
+ try {
+ if (closeable != null) {
+ closeable.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public static boolean copyStream(InputStream is, OutputStream os, int bufferSize)
+ throws IOException {
+ int current = 0;
+ int total = is.available();
+ if (total <= 0) {
+ total = DEFAULT_IMAGE_TOTAL_SIZE;
+ }
+
+ final byte[] bytes = new byte[bufferSize];
+ int count;
+ while ((count = is.read(bytes, 0, bufferSize)) != -1) {
+ os.write(bytes, 0, count);
+ current += count;
+ }
+ os.flush();
+ return true;
+ }
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/BaseSDCardHelper.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/BaseSDCardHelper.java
new file mode 100644
index 0000000000..1fdceec991
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/BaseSDCardHelper.java
@@ -0,0 +1,276 @@
+package com.zhidao.support.adas.high.common;
+
+import android.content.Context;
+import android.os.Environment;
+import android.os.StatFs;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class BaseSDCardHelper {
+
+ // 判断SD卡是否被挂载
+ public static boolean isSDCardMounted() {
+ // return Environment.getExternalStorageState().equals("mounted");
+ return Environment.getExternalStorageState().equals(
+ Environment.MEDIA_MOUNTED);
+ }
+
+ // 获取SD卡的根目录
+ public static String getSDCardBaseDir() {
+ if (isSDCardMounted()) {
+ return Environment.getExternalStorageDirectory().getAbsolutePath();
+ }
+ return null;
+ }
+
+
+ // 获取SD卡的完整空间大小,返回MB
+ public static long getSDCardSize() {
+ if (isSDCardMounted()) {
+ StatFs fs = new StatFs(getSDCardBaseDir());
+ int count = fs.getBlockCount();
+ int size = fs.getBlockSize();
+ return count * size / 1024 / 1024;
+ }
+ return 0;
+ }
+
+ // 获取SD卡的剩余空间大小
+ public static long getSDCardFreeSize() {
+ if (isSDCardMounted()) {
+ StatFs fs = new StatFs(getSDCardBaseDir());
+ int count = fs.getFreeBlocks();
+ int size = fs.getBlockSize();
+ return count * size / 1024 / 1024;
+ }
+ return 0;
+ }
+
+ // 获取SD卡的可用空间大小
+ public static long getSDCardAvailableSize() {
+ if (isSDCardMounted()) {
+ StatFs fs = new StatFs(getSDCardBaseDir());
+ int count = fs.getAvailableBlocks();
+ int size = fs.getBlockSize();
+ return count * size / 1024 / 1024;
+ }
+ return 0;
+ }
+
+ // 往SD卡的公有目录下保存文件
+ public static boolean saveFileToSDCardPublicDir(byte[] data, String type,
+ String fileName) {
+ BufferedOutputStream bos = null;
+ if (isSDCardMounted()) {
+ File file = Environment.getExternalStoragePublicDirectory(type);
+ try {
+ bos = new BufferedOutputStream(new FileOutputStream(new File(
+ file, fileName)));
+ bos.write(data);
+ bos.flush();
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ bos.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ return false;
+ }
+
+ // 往SD卡的自定义目录下保存文件
+ public static boolean saveFileToSDCardCustomDir(byte[] data, String dir,
+ String fileName) {
+ BufferedOutputStream bos = null;
+ if (isSDCardMounted()) {
+ File file = new File(getSDCardBaseDir() + File.separator + dir);
+ if (!file.exists()) {
+ file.mkdirs();// 递归创建自定义目录
+ }
+ try {
+ bos = new BufferedOutputStream(new FileOutputStream(new File(
+ file, fileName)));
+ bos.write(data);
+ bos.flush();
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ bos.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ return false;
+ }
+
+ // 往SD卡的私有Files目录下保存文件
+ public static boolean saveFileToSDCardPrivateFilesDir(byte[] data,
+ String type, String fileName, Context context) {
+ BufferedOutputStream bos = null;
+ if (isSDCardMounted()) {
+ File file = context.getExternalFilesDir(type);
+ try {
+ bos = new BufferedOutputStream(new FileOutputStream(new File(
+ file, fileName)));
+ bos.write(data);
+ bos.flush();
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ bos.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ return false;
+ }
+
+ // 往SD卡的私有Cache目录下保存文件
+ public static boolean saveFileToSDCardPrivateCacheDir(byte[] data,
+ String fileName, Context context) {
+ BufferedOutputStream bos = null;
+ if (isSDCardMounted()) {
+ File file = context.getExternalCacheDir();
+ try {
+ bos = new BufferedOutputStream(new FileOutputStream(new File(
+ file, fileName)));
+ bos.write(data);
+ bos.flush();
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ bos.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ return false;
+ }
+
+ // 从SD卡获取文件
+ public static byte[] loadFileFromSDCard(String fileDir) {
+ BufferedInputStream bis = null;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ try {
+ bis = new BufferedInputStream(
+ new FileInputStream(new File(fileDir)));
+ byte[] buffer = new byte[8 * 1024];
+ int c = 0;
+ while ((c = bis.read(buffer)) != -1) {
+ baos.write(buffer, 0, c);
+ baos.flush();
+ }
+ return baos.toByteArray();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ baos.close();
+ if (bis != null) {
+ bis.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ // 获取SD卡公有目录的路径
+ public static String getSDCardPublicDir(String type) {
+ return Environment.getExternalStoragePublicDirectory(type).toString();
+ }
+
+ // 获取SD卡私有Cache目录的路径
+ public static String getSDCardPrivateCacheDir(Context context) {
+ return context.getExternalCacheDir().getAbsolutePath();
+ }
+
+ // 获取SD卡私有Files目录的路径
+ public static String getSDCardPrivateFilesDir(Context context, String type) {
+ return context.getExternalFilesDir(type).getAbsolutePath();
+ }
+
+ // 获取SD卡文件目录的路径
+ public static String getSDCardPrivateFilesDirOne(Context context,
+ String type) {
+ return Environment.getExternalStorageDirectory().getAbsolutePath()
+ + File.separator + type;
+ }
+
+ /*
+ * 获取sdcard绝对物理路径
+ */
+ public static String getSDCardPath() {
+ if (isSDCardMounted()) {
+ return Environment.getExternalStorageDirectory().getAbsolutePath();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * 删除文件夹
+ * @param path
+ */
+ public static boolean deleteAllFilesOfDir(File path) {
+ if (!path.exists()){
+ return false;
+ }
+ if (path.isFile()) {
+ path.delete();
+ return true;
+ }
+ File[] files = path.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ deleteAllFilesOfDir(files[i]);
+ }
+ path.delete();
+ System.out.println("删除文件夹成功");
+ return true;
+ }
+ /**
+ * 删除文件夹2
+ * @param path
+ */
+ public static void deleteAllFilesOfDir2(File path) {
+ if (!path.exists()){
+ return ;
+ }
+ if (path.isFile()) {
+ path.delete();
+ return ;
+ }
+ File[] files = path.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ deleteAllFilesOfDir(files[i]);
+ }
+ path.delete();
+ System.out.println("删除文件夹成功");
+ }
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/BaseTimeUtils.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/BaseTimeUtils.java
new file mode 100644
index 0000000000..19d015f249
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/BaseTimeUtils.java
@@ -0,0 +1,139 @@
+package com.zhidao.support.adas.high.common;
+
+import android.text.TextUtils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+/**
+ * @author nie yunlong
+ * @description
+ * @date 2018/7/25
+ */
+public class BaseTimeUtils {
+
+
+ /**
+ * 格式化日期
+ *
+ * @return
+ */
+ public static String[] formatTimeDate() {
+ Date d = new Date();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm");
+ String time = sdf.format(d);
+ if (!TextUtils.isEmpty(time) && time.contains("-")) {
+ String[] timeSplit = time.split("-");
+ return timeSplit;
+ }
+ return null;
+ }
+
+ /**
+ * 格式化时间
+ *
+ * @param time
+ * @return
+ */
+ public static String formatTimeDate1(long time) {
+ Date date = new Date();
+ date.setTime(time);
+ SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
+ return sdf.format(date);
+ }
+
+ /**
+ * 格式化时间
+ *
+ * @param time
+ * @return
+ */
+ public static String formatTimeDate(long time, String format) {
+ Date date = new Date();
+ date.setTime(time);
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
+ return sdf.format(date);
+ }
+
+ /**
+ * 格式化时间
+ *
+ * @return
+ */
+ public static String formatTimeDate2() {
+ Date date = new Date();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ return sdf.format(date);
+ }
+
+ public static String formatTimeDate3() {
+ Date date = new Date();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
+ return sdf.format(date);
+ }
+
+
+ /**
+ *
+ * Description: 本地时间转化为UTC时间
+ * @param localTime
+ * @return
+ * @author wgs
+ * @date 2018年10月19日 下午2:23:43
+ *
+ */
+ public static Date localToUTC(String localTime) {
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+// Date localDate= null;
+// try {
+// localDate = sdf.parse(localTime);
+// } catch (ParseException e) {
+// e.printStackTrace();
+// }
+ long localTimeInMillis=Long.parseLong(localTime);
+ /** long时间转换成Calendar */
+ Calendar calendar= Calendar.getInstance();
+ calendar.setTimeInMillis(localTimeInMillis);
+ /** 取得时间偏移量 */
+ int zoneOffset = calendar.get(java.util.Calendar.ZONE_OFFSET);
+ /** 取得夏令时差 */
+ int dstOffset = calendar.get(java.util.Calendar.DST_OFFSET);
+ /** 从本地时间里扣除这些差量,即可以取得UTC时间*/
+ calendar.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));
+ /** 取得的时间就是UTC标准时间 */
+ Date utcDate=new Date(calendar.getTimeInMillis());
+ return utcDate;
+ }
+
+ /**
+ *
+ * Description:UTC时间转化为本地时间
+ * @param utcTime
+ * @return
+ * @author wgs
+ * @date 2018年10月19日 下午2:23:24
+ *
+ */
+ public static Date utcToLocal(String utcTime){
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
+ Date utcDate = null;
+ try {
+ utcDate = sdf.parse(utcTime);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ sdf.setTimeZone(TimeZone.getDefault());
+ Date locatlDate = null;
+ String localTime = sdf.format(utcDate.getTime());
+ try {
+ locatlDate = sdf.parse(localTime);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return locatlDate;
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/Constants.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/Constants.java
new file mode 100644
index 0000000000..8c24926f9f
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/Constants.java
@@ -0,0 +1,52 @@
+package com.zhidao.support.adas.high.common;
+
+/**
+ * @ProjectName: lib-adas-fpga
+ * @Package: PACKAGE_NAME
+ * @ClassName: com.zhidao.lib.adas.high.common.Constants
+ * @Description: java类作用描述
+ * @Author: fenghl
+ * @CreateDate: 2020/2/7 15:53
+ * @UpdateUser: 更新者:
+ * @UpdateDate: 2020/2/7 15:53
+ * @UpdateRemark: 更新说明:
+ * @Version: 1.0
+ */
+public class Constants {
+ /**
+ * ws 主机地址 需要从udp里面获取
+ */
+ public static final String WS_IP_HOST_HEAD = "ws:";
+ /**
+ * ws 端口以及资源名称
+ */
+ public static final String WS_PORT = ":4110/xvideo-detector";
+ /**
+ * 端口
+ */
+ public static final String WS_PORT_=":4110";
+
+ /**
+ * 发送位置信息 action
+ */
+ public static final int WS_SEND_LOCATION = 2;
+
+ /**
+ * 查询自动驾驶轨迹
+ */
+ public static final String QUERY_GLOBAL_PATH = "{\"action\":\"query_global_path\",\"result\":null}";
+ /**
+ * 查询节点信息
+ */
+ public static final String QUERY_GUARDIAN = "{\"action\":\"query_guardian\",\"result\":null}";
+
+ /**
+ * 查询docker版本
+ */
+ public static final String QUERY_CAR_CONFIG = "{\"action\":\"car_config\",\"result\":null}";
+
+ /**
+ * 查询轨迹
+ */
+ public static final String QUERY_ROUTES = "{\"action\":\"query_routes\",\"result\":null}";
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/CupidLogUtils.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/CupidLogUtils.java
new file mode 100644
index 0000000000..1b3c9d2217
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/CupidLogUtils.java
@@ -0,0 +1,85 @@
+package com.zhidao.support.adas.high.common;
+
+import android.util.Log;
+
+import com.zhidao.support.adas.high.BuildConfig;
+
+/**
+ * @author nie yunlong
+ * @description video-lib
+ * @date 2018/6/15
+ */
+public class CupidLogUtils {
+ /**
+ * 默认是打开日志
+ */
+// private static boolean mIsEnableLog = BuildConfig.DEBUG;
+ private static boolean mIsEnableLog = true;
+ /**
+ * 是否写日志
+ */
+ private static boolean isWriteLog = true;
+
+ /**
+ * @param isEnableLog true开启 false关闭
+ */
+ public static void setEnableLog(boolean isEnableLog) {
+ mIsEnableLog = isEnableLog;
+ }
+
+
+ public static boolean isIsWriteLog() {
+ return isWriteLog;
+ }
+
+ public static void setIsWriteLog(boolean isWriteLog) {
+ CupidLogUtils.isWriteLog = isWriteLog;
+ }
+
+ public static void i(String tag, String msg) {
+ if (!mIsEnableLog) {
+ return;
+ }
+ Log.i(tag, msg);
+ }
+
+ public static void w(String tag, String msg) {
+ if (!mIsEnableLog) {
+ return;
+ }
+ Log.w(tag, msg);
+ }
+
+ public static void e(String tag, String msg) {
+ if (!mIsEnableLog) {
+ return;
+ }
+ Log.e(tag, msg);
+ }
+
+ public static void e(String msg) {
+ if (!mIsEnableLog) {
+ return;
+ }
+ Log.e("elita_lib", msg);
+ }
+
+ public static void w(String msg) {
+ if (!mIsEnableLog) {
+ return;
+ }
+ Log.e("elita_lib", msg);
+ }
+
+ /**
+ * 写文件
+ *
+ * @param msg
+ */
+ public static void writeOwnerCarStateLog(String msg) {
+ if (!isWriteLog) {
+ return;
+ }
+ LogSaveManage.getInstance().saveWrite(msg);
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/DigitalTrans.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/DigitalTrans.java
new file mode 100644
index 0000000000..fe344bee47
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/DigitalTrans.java
@@ -0,0 +1,516 @@
+package com.zhidao.support.adas.high.common;
+
+public class DigitalTrans {
+
+ /**
+ * 数字字符串转ASCII码字符串
+ *
+ * @param content 字符串
+ * @return ASCII字符串
+ */
+ public static String StringToAsciiString(String content) {
+ String result = "";
+ int max = content.length();
+ for (int i = 0; i < max; i++) {
+ char c = content.charAt(i);
+ String b = Integer.toHexString(c);
+ result = result + b;
+ }
+ return result;
+ }
+
+ /**
+ * 十六进制转字符串
+ *
+ * @param hexString 十六进制字符串
+ * @param encodeType 编码类型4:Unicode,2:普通编码
+ * @return 字符串
+ */
+ public static String hexStringToString(String hexString, int encodeType) {
+ String result = "";
+ int max = hexString.length() / encodeType;
+ for (int i = 0; i < max; i++) {
+ char c = (char) DigitalTrans.hexStringToAlgorism(hexString
+ .substring(i * encodeType, (i + 1) * encodeType));
+ result += c;
+ }
+ return result;
+ }
+
+ /**
+ * 十六进制字符串装十进制
+ *
+ * @param hex 十六进制字符串
+ * @return 十进制数值
+ */
+ public static int hexStringToAlgorism(String hex) {
+ hex = hex.toUpperCase();
+ int max = hex.length();
+ int result = 0;
+ for (int i = max; i > 0; i--) {
+ char c = hex.charAt(i - 1);
+ int algorism = 0;
+ if (c >= '0' && c <= '9') {
+ algorism = c - '0';
+ } else {
+ algorism = c - 55;
+ }
+ result += Math.pow(16, max - i) * algorism;
+ }
+ return result;
+ }
+
+ /**
+ * 十六转二进制
+ *
+ * @param hex 十六进制字符串
+ * @return 二进制字符串
+ */
+ public static String hexStringToBinary(String hex) {
+ hex = hex.toUpperCase();
+ String result = "";
+ int max = hex.length();
+ for (int i = 0; i < max; i++) {
+ char c = hex.charAt(i);
+ switch (c) {
+ case '0':
+ result += "0000";
+ break;
+ case '1':
+ result += "0001";
+ break;
+ case '2':
+ result += "0010";
+ break;
+ case '3':
+ result += "0011";
+ break;
+ case '4':
+ result += "0100";
+ break;
+ case '5':
+ result += "0101";
+ break;
+ case '6':
+ result += "0110";
+ break;
+ case '7':
+ result += "0111";
+ break;
+ case '8':
+ result += "1000";
+ break;
+ case '9':
+ result += "1001";
+ break;
+ case 'A':
+ result += "1010";
+ break;
+ case 'B':
+ result += "1011";
+ break;
+ case 'C':
+ result += "1100";
+ break;
+ case 'D':
+ result += "1101";
+ break;
+ case 'E':
+ result += "1110";
+ break;
+ case 'F':
+ result += "1111";
+ break;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * ASCII码字符串转数字字符串
+ *
+ * @param content ASCII字符串
+ * @return 字符串
+ */
+ public static String AsciiStringToString(String content) {
+ String result = "";
+ int length = content.length() / 2;
+ for (int i = 0; i < length; i++) {
+ String c = content.substring(i * 2, i * 2 + 2);
+ int a = hexStringToAlgorism(c);
+ char b = (char) a;
+ String d = String.valueOf(b);
+ result += d;
+ }
+ return result;
+ }
+
+ /**
+ * 将十进制转换为指定长度的十六进制字符串
+ *
+ * @param algorism int 十进制数字
+ * @param maxLength int 转换后的十六进制字符串长度
+ * @return String 转换后的十六进制字符串
+ */
+ public static String algorismToHEXString(int algorism, int maxLength) {
+ String result = "";
+ result = Integer.toHexString(algorism);
+
+ if (result.length() % 2 == 1) {
+ result = "0" + result;
+ }
+ return patchHexString(result.toUpperCase(), maxLength);
+ }
+
+ /**
+ * 字节数组转为普通字符串(ASCII对应的字符)
+ *
+ * @param bytearray byte[]
+ * @return String
+ */
+ public static String bytetoString(byte[] bytearray) {
+ String result = "";
+ char temp;
+
+ int length = bytearray.length;
+ for (int i = 0; i < length; i++) {
+ temp = (char) bytearray[i];
+ result += temp;
+ }
+ return result;
+ }
+
+ /**
+ * 二进制字符串转十进制
+ *
+ * @param binary 二进制字符串
+ * @return 十进制数值
+ */
+ public static int binaryToAlgorism(String binary) {
+ int max = binary.length();
+ int result = 0;
+ for (int i = max; i > 0; i--) {
+ char c = binary.charAt(i - 1);
+ int algorism = c - '0';
+ result += Math.pow(2, max - i) * algorism;
+ }
+ return result;
+ }
+
+ /**
+ * 十进制转换为十六进制字符串
+ *
+ * @param algorism int 十进制的数字
+ * @return String 对应的十六进制字符串
+ */
+ public static String algorismToHEXString(int algorism) {
+ String result = "";
+ result = Integer.toHexString(algorism);
+
+ if (result.length() % 2 == 1) {
+ result = "0" + result;
+
+ }
+ result = result.toUpperCase();
+
+ return result;
+ }
+
+ /**
+ * HEX字符串前补0,主要用于长度位数不足。
+ *
+ * @param str String 需要补充长度的十六进制字符串
+ * @param maxLength int 补充后十六进制字符串的长度
+ * @return 补充结果
+ */
+ static public String patchHexString(String str, int maxLength) {
+ String temp = "";
+ for (int i = 0; i < maxLength - str.length(); i++) {
+ temp = "0" + temp;
+ }
+ str = (temp + str).substring(0, maxLength);
+ return str;
+ }
+
+ /**
+ * 将一个字符串转换为int
+ *
+ * @param s String 要转换的字符串
+ * @param defaultInt int 如果出现异常,默认返回的数字
+ * @param radix int 要转换的字符串是什么进制的,如16 8 10.
+ * @return int 转换后的数字
+ */
+ public static int parseToInt(String s, int defaultInt, int radix) {
+ int i = 0;
+ try {
+ i = Integer.parseInt(s, radix);
+ } catch (NumberFormatException ex) {
+ i = defaultInt;
+ }
+ return i;
+ }
+
+ /**
+ * 将一个十进制形式的数字字符串转换为int
+ *
+ * @param s String 要转换的字符串
+ * @param defaultInt int 如果出现异常,默认返回的数字
+ * @return int 转换后的数字
+ */
+ public static int parseToInt(String s, int defaultInt) {
+ int i = 0;
+ try {
+ i = Integer.parseInt(s);
+ } catch (NumberFormatException ex) {
+ i = defaultInt;
+ }
+ return i;
+ }
+
+ /**
+ * 十六进制字符串转为Byte数组,每两个十六进制字符转为一个Byte
+ *
+ * @param hex 十六进制字符串
+ * @return byte 转换结果
+ */
+ public static byte[] hexStringToByte(String hex) {
+ int max = hex.length() / 2;
+ byte[] bytes = new byte[max];
+ String binarys = DigitalTrans.hexStringToBinary(hex);
+ for (int i = 0; i < max; i++) {
+ bytes[i] = (byte) DigitalTrans.binaryToAlgorism(binarys.substring(
+ i * 8 + 1, (i + 1) * 8));
+ if (binarys.charAt(8 * i) == '1') {
+ bytes[i] = (byte) (0 - bytes[i]);
+ }
+ }
+ return bytes;
+ }
+
+ /**
+ * 十六进制串转化为byte数组
+ *
+ * @return the array of byte
+ */
+ public static final byte[] hex2byte(String hex)
+ throws IllegalArgumentException {
+ if (hex.length() % 2 != 0) {
+ throw new IllegalArgumentException();
+ }
+ char[] arr = hex.toCharArray();
+ byte[] b = new byte[hex.length() / 2];
+ for (int i = 0, j = 0, l = hex.length(); i < l; i++, j++) {
+ String swap = "" + arr[i++] + arr[i];
+ int byteint = Integer.parseInt(swap, 16) & 0xFF;
+ b[j] = new Integer(byteint).byteValue();
+ }
+ return b;
+ }
+
+ /**
+ * 字节数组转换为十六进制字符串
+ *
+ * @param b byte[] 需要转换的字节数组
+ * @return String 十六进制字符串
+ */
+ public static final String byte2hex(byte b[]) {
+ if (b == null) {
+ throw new IllegalArgumentException(
+ "Argument b ( byte array ) is null! ");
+ }
+ String hs = "";
+ String stmp = "";
+ for (int n = 0; n < b.length; n++) {
+ stmp = Integer.toHexString(b[n] & 0xff);
+ if (stmp.length() == 1) {
+ hs = hs + "0" + stmp;
+ } else {
+ hs = hs + stmp;
+ }
+ }
+ return hs.toUpperCase();
+ }
+
+ /**
+ * 字符串转换成十六进制字符串
+ *
+ * @param String str 待转换的ASCII字符串
+ * @return String 每个Byte之间空格分隔,如: [61 6C 6B]
+ */
+ public static String str2HexStr(String str) {
+
+ char[] chars = "0123456789ABCDEF".toCharArray();
+ StringBuilder sb = new StringBuilder("");
+ byte[] bs = str.getBytes();
+ int bit;
+
+ for (int i = 0; i < bs.length; i++) {
+ bit = (bs[i] & 0x0f0) >> 4;
+ sb.append(chars[bit]);
+ bit = bs[i] & 0x0f;
+ sb.append(chars[bit]);
+ sb.append(' ');
+ }
+ return sb.toString().trim();
+ }
+
+ /**
+ * 十六进制转换字符串
+ *
+ * @param String str Byte字符串(Byte之间无分隔符 如:[616C6B])
+ * @return String 对应的字符串
+ */
+ public static String hexStr2Str(String hexStr) {
+ String str = "0123456789ABCDEF";
+ char[] hexs = hexStr.toCharArray();
+ byte[] bytes = new byte[hexStr.length() / 2];
+ int n;
+
+ for (int i = 0; i < bytes.length; i++) {
+ n = str.indexOf(hexs[2 * i]) * 16;
+ n += str.indexOf(hexs[2 * i + 1]);
+ bytes[i] = (byte) (n & 0xff);
+ }
+ return new String(bytes);
+ }
+
+ /**
+ * bytes转换成十六进制字符串
+ *
+ * @param byte[] b byte数组
+ * @return String 每个Byte值之间空格分隔
+ */
+ public static String byte2HexStr(byte[] b) {
+ String stmp = "";
+ StringBuilder sb = new StringBuilder("");
+ for (int n = 0; n < b.length; n++) {
+ stmp = Integer.toHexString(b[n] & 0xFF);
+ sb.append((stmp.length() == 1) ? "0" + stmp : stmp);
+ sb.append(" ");
+ }
+ return sb.toString().toUpperCase().trim();
+ }
+
+ /**
+ * bytes字符串转换为Byte值
+ *
+ * @param String src Byte字符串,每个Byte之间没有分隔符
+ * @return byte[]
+ */
+ public static byte[] hexStr2Bytes(String src) {
+ int m = 0, n = 0;
+ int l = src.length() / 2;
+ System.out.println(l);
+ byte[] ret = new byte[l];
+ for (int i = 0; i < l; i++) {
+ m = i * 2 + 1;
+ n = m + 1;
+ ret[i] = Byte.decode("0x" + src.substring(i * 2, m) + src.substring(m, n));
+ }
+ return ret;
+ }
+
+ /**
+ * String的字符串转换成unicode的String
+ *
+ * @param String strText 全角字符串
+ * @return String 每个unicode之间无分隔符
+ * @throws Exception
+ */
+ public static String strToUnicode(String strText)
+ throws Exception {
+ char c;
+ StringBuilder str = new StringBuilder();
+ int intAsc;
+ String strHex;
+ for (int i = 0; i < strText.length(); i++) {
+ c = strText.charAt(i);
+ intAsc = (int) c;
+ strHex = Integer.toHexString(intAsc);
+ if (intAsc > 128)
+ str.append("\\u" + strHex);
+ else // 低位在前面补00
+ str.append("\\u00" + strHex);
+ }
+ return str.toString();
+ }
+
+ /**
+ * unicode的String转换成String的字符串
+ *
+ * @param String hex 16进制值字符串 (一个unicode为2byte)
+ * @return String 全角字符串
+ */
+ public static String unicodeToString(String hex) {
+ int t = hex.length() / 6;
+ StringBuilder str = new StringBuilder();
+ for (int i = 0; i < t; i++) {
+ String s = hex.substring(i * 6, (i + 1) * 6);
+ // 高位需要补上00再转
+ String s1 = s.substring(2, 4) + "00";
+ // 低位直接转
+ String s2 = s.substring(4);
+ // 将16进制的string转为int
+ int n = Integer.valueOf(s1, 16) + Integer.valueOf(s2, 16);
+ // 将int转换为字符
+ char[] chars = Character.toChars(n);
+ str.append(new String(chars));
+ }
+ return str.toString();
+ }
+
+ /**
+ * 整型数据拆分为长度为2的字节数组,低8位存放在序号小的元素,高8位存放在序号大的元素中(大端存储)
+ *
+ * @param data
+ * @return
+ */
+ public static byte[] intTo2Byte(int data) {
+ byte[] byteArray = new byte[2];
+ byteArray[0] = (byte) (data >> 8);
+ byteArray[1] = (byte) data;
+ return byteArray;
+ }
+
+ /**
+ * 将两个字节拼接还原成无符号的整型数据
+ * 数据域中的数据都按小端存储,示例:数据0x1234,则Byte0为0x34,Byte1为0x12
+ *
+ * @param byte1
+ * @param byte2
+ * @return
+ */
+ public static int joint2ByteToInt(byte byte1, byte byte2) {
+ int result = byte1 & 0xFF;
+ result = (result << 8) | (0x00FF & byte2);
+ return result;
+ }
+
+ /**
+ * 拼接两个byte[]
+ *
+ * @param
+ * @param
+ * @return
+ */
+ public static byte[] concatBytes(byte[] bt1, byte[] bt2) {
+ if (bt1 == null) {
+ return bt2;
+ }
+ if (bt2 == null) {
+ return bt1;
+ }
+ byte[] bt3 = new byte[bt1.length + bt2.length];
+ System.arraycopy(bt1, 0, bt3, 0, bt1.length);
+ System.arraycopy(bt2, 0, bt3, bt1.length, bt2.length);
+ return bt3;
+ }
+
+ //获得本机cpu大小端
+ public static boolean isBigendian() {
+ short i = 0x1;
+ boolean bRet = ((i >> 8) == 0x1);
+ return bRet;
+ }
+
+}
\ No newline at end of file
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/FileUtils.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/FileUtils.java
new file mode 100644
index 0000000000..4376c74e9a
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/FileUtils.java
@@ -0,0 +1,1543 @@
+package com.zhidao.support.adas.high.common;
+
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.RandomAccessFile;
+import java.net.URL;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
+import java.security.DigestInputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+import javax.net.ssl.HttpsURLConnection;
+
+/**
+ *
+ * author: Blankj
+ * blog : http://blankj.com
+ * time : 2016/05/03
+ * desc : utils about file
+ *
+ */
+public final class FileUtils {
+
+ private static final String LINE_SEP = System.getProperty("line.separator");
+
+ private FileUtils() {
+ throw new UnsupportedOperationException("u can't instantiate me...");
+ }
+
+ /**
+ * Return the file by path.
+ *
+ * @param filePath The path of file.
+ * @return the file
+ */
+ public static File getFileByPath(final String filePath) {
+ return isSpace(filePath) ? null : new File(filePath);
+ }
+
+ /**
+ * Return whether the file exists.
+ *
+ * @param filePath The path of file.
+ * @return {@code true}: yes
{@code false}: no
+ */
+ public static boolean isFileExists(final String filePath) {
+ return isFileExists(getFileByPath(filePath));
+ }
+
+ /**
+ * Return whether the file exists.
+ *
+ * @param file The file.
+ * @return {@code true}: yes
{@code false}: no
+ */
+ public static boolean isFileExists(final File file) {
+ return file != null && file.exists();
+ }
+
+ /**
+ * Rename the file.
+ *
+ * @param filePath The path of file.
+ * @param newName The new name of file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean rename(final String filePath, final String newName) {
+ return rename(getFileByPath(filePath), newName);
+ }
+
+ /**
+ * Rename the file.
+ *
+ * @param file The file.
+ * @param newName The new name of file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean rename(final File file, final String newName) {
+ // file is null then return false
+ if (file == null) return false;
+ // file doesn't exist then return false
+ if (!file.exists()) return false;
+ // the new name is space then return false
+ if (isSpace(newName)) return false;
+ // the new name equals old name then return true
+ if (newName.equals(file.getName())) return true;
+ File newFile = new File(file.getParent() + File.separator + newName);
+ // the new name of file exists then return false
+ return !newFile.exists()
+ && file.renameTo(newFile);
+ }
+
+ /**
+ * Return whether it is a directory.
+ *
+ * @param dirPath The path of directory.
+ * @return {@code true}: yes
{@code false}: no
+ */
+ public static boolean isDir(final String dirPath) {
+ return isDir(getFileByPath(dirPath));
+ }
+
+ /**
+ * Return whether it is a directory.
+ *
+ * @param file The file.
+ * @return {@code true}: yes
{@code false}: no
+ */
+ public static boolean isDir(final File file) {
+ return file != null && file.exists() && file.isDirectory();
+ }
+
+ /**
+ * Return whether it is a file.
+ *
+ * @param filePath The path of file.
+ * @return {@code true}: yes
{@code false}: no
+ */
+ public static boolean isFile(final String filePath) {
+ return isFile(getFileByPath(filePath));
+ }
+
+ /**
+ * Return whether it is a file.
+ *
+ * @param file The file.
+ * @return {@code true}: yes
{@code false}: no
+ */
+ public static boolean isFile(final File file) {
+ return file != null && file.exists() && file.isFile();
+ }
+
+ /**
+ * Create a directory if it doesn't exist, otherwise do nothing.
+ *
+ * @param dirPath The path of directory.
+ * @return {@code true}: exists or creates successfully
{@code false}: otherwise
+ */
+ public static boolean createOrExistsDir(final String dirPath) {
+ return createOrExistsDir(getFileByPath(dirPath));
+ }
+
+ /**
+ * Create a directory if it doesn't exist, otherwise do nothing.
+ *
+ * @param file The file.
+ * @return {@code true}: exists or creates successfully
{@code false}: otherwise
+ */
+ public static boolean createOrExistsDir(final File file) {
+ return file != null && (file.exists() ? file.isDirectory() : file.mkdirs());
+ }
+
+ /**
+ * Create a file if it doesn't exist, otherwise do nothing.
+ *
+ * @param filePath The path of file.
+ * @return {@code true}: exists or creates successfully
{@code false}: otherwise
+ */
+ public static boolean createOrExistsFile(final String filePath) {
+ return createOrExistsFile(getFileByPath(filePath));
+ }
+
+ /**
+ * Create a file if it doesn't exist, otherwise do nothing.
+ *
+ * @param file The file.
+ * @return {@code true}: exists or creates successfully
{@code false}: otherwise
+ */
+ public static boolean createOrExistsFile(final File file) {
+ if (file == null) return false;
+ if (file.exists()) return file.isFile();
+ if (!createOrExistsDir(file.getParentFile())) return false;
+ try {
+ return file.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Create a file if it doesn't exist, otherwise delete old file before creating.
+ *
+ * @param filePath The path of file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean createFileByDeleteOldFile(final String filePath) {
+ return createFileByDeleteOldFile(getFileByPath(filePath));
+ }
+
+ /**
+ * Create a file if it doesn't exist, otherwise delete old file before creating.
+ *
+ * @param file The file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean createFileByDeleteOldFile(final File file) {
+ if (file == null) return false;
+ // file exists and unsuccessfully delete then return false
+ if (file.exists() && !file.delete()) return false;
+ if (!createOrExistsDir(file.getParentFile())) return false;
+ try {
+ return file.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Copy the directory.
+ *
+ * @param srcDirPath The path of source directory.
+ * @param destDirPath The path of destination directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean copyDir(final String srcDirPath,
+ final String destDirPath) {
+ return copyDir(getFileByPath(srcDirPath), getFileByPath(destDirPath));
+ }
+
+ /**
+ * Copy the directory.
+ *
+ * @param srcDirPath The path of source directory.
+ * @param destDirPath The path of destination directory.
+ * @param listener The replace listener.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean copyDir(final String srcDirPath,
+ final String destDirPath,
+ final OnReplaceListener listener) {
+ return copyDir(getFileByPath(srcDirPath), getFileByPath(destDirPath), listener);
+ }
+
+ /**
+ * Copy the directory.
+ *
+ * @param srcDir The source directory.
+ * @param destDir The destination directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean copyDir(final File srcDir,
+ final File destDir) {
+ return copyOrMoveDir(srcDir, destDir, false);
+ }
+
+ /**
+ * Copy the directory.
+ *
+ * @param srcDir The source directory.
+ * @param destDir The destination directory.
+ * @param listener The replace listener.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean copyDir(final File srcDir,
+ final File destDir,
+ final OnReplaceListener listener) {
+ return copyOrMoveDir(srcDir, destDir, listener, false);
+ }
+
+ /**
+ * Copy the file.
+ *
+ * @param srcFilePath The path of source file.
+ * @param destFilePath The path of destination file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean copyFile(final String srcFilePath,
+ final String destFilePath) {
+ return copyFile(getFileByPath(srcFilePath), getFileByPath(destFilePath));
+ }
+
+ /**
+ * Copy the file.
+ *
+ * @param srcFilePath The path of source file.
+ * @param destFilePath The path of destination file.
+ * @param listener The replace listener.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean copyFile(final String srcFilePath,
+ final String destFilePath,
+ final OnReplaceListener listener) {
+ return copyFile(getFileByPath(srcFilePath), getFileByPath(destFilePath), listener);
+ }
+
+ /**
+ * Copy the file.
+ *
+ * @param srcFile The source file.
+ * @param destFile The destination file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean copyFile(final File srcFile,
+ final File destFile) {
+ return copyOrMoveFile(srcFile, destFile, false);
+ }
+
+ /**
+ * Copy the file.
+ *
+ * @param srcFile The source file.
+ * @param destFile The destination file.
+ * @param listener The replace listener.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean copyFile(final File srcFile,
+ final File destFile,
+ final OnReplaceListener listener) {
+ return copyOrMoveFile(srcFile, destFile, listener, false);
+ }
+
+ /**
+ * Move the directory.
+ *
+ * @param srcDirPath The path of source directory.
+ * @param destDirPath The path of destination directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean moveDir(final String srcDirPath,
+ final String destDirPath) {
+ return moveDir(getFileByPath(srcDirPath), getFileByPath(destDirPath));
+ }
+
+ /**
+ * Move the directory.
+ *
+ * @param srcDirPath The path of source directory.
+ * @param destDirPath The path of destination directory.
+ * @param listener The replace listener.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean moveDir(final String srcDirPath,
+ final String destDirPath,
+ final OnReplaceListener listener) {
+ return moveDir(getFileByPath(srcDirPath), getFileByPath(destDirPath), listener);
+ }
+
+ /**
+ * Move the directory.
+ *
+ * @param srcDir The source directory.
+ * @param destDir The destination directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean moveDir(final File srcDir,
+ final File destDir) {
+ return copyOrMoveDir(srcDir, destDir, true);
+ }
+
+ /**
+ * Move the directory.
+ *
+ * @param srcDir The source directory.
+ * @param destDir The destination directory.
+ * @param listener The replace listener.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean moveDir(final File srcDir,
+ final File destDir,
+ final OnReplaceListener listener) {
+ return copyOrMoveDir(srcDir, destDir, listener, true);
+ }
+
+ /**
+ * Move the file.
+ *
+ * @param srcFilePath The path of source file.
+ * @param destFilePath The path of destination file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean moveFile(final String srcFilePath,
+ final String destFilePath) {
+ return moveFile(getFileByPath(srcFilePath), getFileByPath(destFilePath));
+ }
+
+ /**
+ * Move the file.
+ *
+ * @param srcFilePath The path of source file.
+ * @param destFilePath The path of destination file.
+ * @param listener The replace listener.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean moveFile(final String srcFilePath,
+ final String destFilePath,
+ final OnReplaceListener listener) {
+ return moveFile(getFileByPath(srcFilePath), getFileByPath(destFilePath), listener);
+ }
+
+ /**
+ * Move the file.
+ *
+ * @param srcFile The source file.
+ * @param destFile The destination file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean moveFile(final File srcFile,
+ final File destFile) {
+ return copyOrMoveFile(srcFile, destFile, true);
+ }
+
+ /**
+ * Move the file.
+ *
+ * @param srcFile The source file.
+ * @param destFile The destination file.
+ * @param listener The replace listener.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean moveFile(final File srcFile,
+ final File destFile,
+ final OnReplaceListener listener) {
+ return copyOrMoveFile(srcFile, destFile, listener, true);
+ }
+
+ private static boolean copyOrMoveDir(final File srcDir,
+ final File destDir,
+ final boolean isMove) {
+ return copyOrMoveDir(srcDir, destDir, new OnReplaceListener() {
+ @Override
+ public boolean onReplace() {
+ return true;
+ }
+ }, isMove);
+ }
+
+ private static boolean copyOrMoveDir(final File srcDir,
+ final File destDir,
+ final OnReplaceListener listener,
+ final boolean isMove) {
+ if (srcDir == null || destDir == null) return false;
+ // destDir's path locate in srcDir's path then return false
+ String srcPath = srcDir.getPath() + File.separator;
+ String destPath = destDir.getPath() + File.separator;
+ if (destPath.contains(srcPath)) return false;
+ if (!srcDir.exists() || !srcDir.isDirectory()) return false;
+ if (destDir.exists()) {
+ if (listener == null || listener.onReplace()) {// require delete the old directory
+ if (!deleteAllInDir(destDir)) {// unsuccessfully delete then return false
+ return false;
+ }
+ } else {
+ return true;
+ }
+ }
+ if (!createOrExistsDir(destDir)) return false;
+ File[] files = srcDir.listFiles();
+ for (File file : files) {
+ File oneDestFile = new File(destPath + file.getName());
+ if (file.isFile()) {
+ if (!copyOrMoveFile(file, oneDestFile, listener, isMove)) return false;
+ } else if (file.isDirectory()) {
+ if (!copyOrMoveDir(file, oneDestFile, listener, isMove)) return false;
+ }
+ }
+ return !isMove || deleteDir(srcDir);
+ }
+
+ private static boolean copyOrMoveFile(final File srcFile,
+ final File destFile,
+ final boolean isMove) {
+ return copyOrMoveFile(srcFile, destFile, new OnReplaceListener() {
+ @Override
+ public boolean onReplace() {
+ return true;
+ }
+ }, isMove);
+ }
+
+ private static boolean copyOrMoveFile(final File srcFile,
+ final File destFile,
+ final OnReplaceListener listener,
+ final boolean isMove) {
+ if (srcFile == null || destFile == null) return false;
+ // srcFile equals destFile then return false
+ if (srcFile.equals(destFile)) return false;
+ // srcFile doesn't exist or isn't a file then return false
+ if (!srcFile.exists() || !srcFile.isFile()) return false;
+ if (destFile.exists()) {
+ if (listener == null || listener.onReplace()) {// require delete the old file
+ if (!destFile.delete()) {// unsuccessfully delete then return false
+ return false;
+ }
+ } else {
+ return true;
+ }
+ }
+ if (!createOrExistsDir(destFile.getParentFile())) return false;
+ try {
+ return writeFileFromIS(destFile, new FileInputStream(srcFile))
+ && !(isMove && !deleteFile(srcFile));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Delete the directory.
+ *
+ * @param filePath The path of file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean delete(final String filePath) {
+ return delete(getFileByPath(filePath));
+ }
+
+ /**
+ * Delete the directory.
+ *
+ * @param file The file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean delete(final File file) {
+ if (file == null) return false;
+ if (file.isDirectory()) {
+ return deleteDir(file);
+ }
+ return deleteFile(file);
+ }
+
+ /**
+ * Delete the directory.
+ *
+ * @param dirPath The path of directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteDir(final String dirPath) {
+ return deleteDir(getFileByPath(dirPath));
+ }
+
+ /**
+ * Delete the directory.
+ *
+ * @param dir The directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteDir(final File dir) {
+ if (dir == null) return false;
+ // dir doesn't exist then return true
+ if (!dir.exists()) return true;
+ // dir isn't a directory then return false
+ if (!dir.isDirectory()) return false;
+ File[] files = dir.listFiles();
+ if (files != null && files.length != 0) {
+ for (File file : files) {
+ if (file.isFile()) {
+ if (!file.delete()) return false;
+ } else if (file.isDirectory()) {
+ if (!deleteDir(file)) return false;
+ }
+ }
+ }
+ return dir.delete();
+ }
+
+ /**
+ * Delete the file.
+ *
+ * @param srcFilePath The path of source file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteFile(final String srcFilePath) {
+ return deleteFile(getFileByPath(srcFilePath));
+ }
+
+ /**
+ * Delete the file.
+ *
+ * @param file The file.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteFile(final File file) {
+ return file != null && (!file.exists() || file.isFile() && file.delete());
+ }
+
+ /**
+ * Delete the all in directory.
+ *
+ * @param dirPath The path of directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteAllInDir(final String dirPath) {
+ return deleteAllInDir(getFileByPath(dirPath));
+ }
+
+ /**
+ * Delete the all in directory.
+ *
+ * @param dir The directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteAllInDir(final File dir) {
+ return deleteFilesInDirWithFilter(dir, new FileFilter() {
+ @Override
+ public boolean accept(File pathname) {
+ return true;
+ }
+ });
+ }
+
+ /**
+ * Delete all files in directory.
+ *
+ * @param dirPath The path of directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteFilesInDir(final String dirPath) {
+ return deleteFilesInDir(getFileByPath(dirPath));
+ }
+
+ /**
+ * Delete all files in directory.
+ *
+ * @param dir The directory.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteFilesInDir(final File dir) {
+ return deleteFilesInDirWithFilter(dir, new FileFilter() {
+ @Override
+ public boolean accept(File pathname) {
+ return pathname.isFile();
+ }
+ });
+ }
+
+ /**
+ * Delete all files that satisfy the filter in directory.
+ *
+ * @param dirPath The path of directory.
+ * @param filter The filter.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteFilesInDirWithFilter(final String dirPath,
+ final FileFilter filter) {
+ return deleteFilesInDirWithFilter(getFileByPath(dirPath), filter);
+ }
+
+ /**
+ * Delete all files that satisfy the filter in directory.
+ *
+ * @param dir The directory.
+ * @param filter The filter.
+ * @return {@code true}: success
{@code false}: fail
+ */
+ public static boolean deleteFilesInDirWithFilter(final File dir, final FileFilter filter) {
+ if (dir == null) return false;
+ // dir doesn't exist then return true
+ if (!dir.exists()) return true;
+ // dir isn't a directory then return false
+ if (!dir.isDirectory()) return false;
+ File[] files = dir.listFiles();
+ if (files != null && files.length != 0) {
+ for (File file : files) {
+ if (filter.accept(file)) {
+ if (file.isFile()) {
+ if (!file.delete()) return false;
+ } else if (file.isDirectory()) {
+ if (!deleteDir(file)) return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Return the files in directory.
+ * Doesn't traverse subdirectories
+ *
+ * @param dirPath The path of directory.
+ * @return the files in directory
+ */
+ public static List listFilesInDir(final String dirPath) {
+ return listFilesInDir(dirPath, false);
+ }
+
+ /**
+ * Return the files in directory.
+ * Doesn't traverse subdirectories
+ *
+ * @param dir The directory.
+ * @return the files in directory
+ */
+ public static List listFilesInDir(final File dir) {
+ return listFilesInDir(dir, false);
+ }
+
+ /**
+ * Return the files in directory.
+ *
+ * @param dirPath The path of directory.
+ * @param isRecursive True to traverse subdirectories, false otherwise.
+ * @return the files in directory
+ */
+ public static List listFilesInDir(final String dirPath, final boolean isRecursive) {
+ return listFilesInDir(getFileByPath(dirPath), isRecursive);
+ }
+
+ /**
+ * Return the files in directory.
+ *
+ * @param dir The directory.
+ * @param isRecursive True to traverse subdirectories, false otherwise.
+ * @return the files in directory
+ */
+ public static List listFilesInDir(final File dir, final boolean isRecursive) {
+ return listFilesInDirWithFilter(dir, new FileFilter() {
+ @Override
+ public boolean accept(File pathname) {
+ return true;
+ }
+ }, isRecursive);
+ }
+
+ /**
+ * Return the files that satisfy the filter in directory.
+ * Doesn't traverse subdirectories
+ *
+ * @param dirPath The path of directory.
+ * @param filter The filter.
+ * @return the files that satisfy the filter in directory
+ */
+ public static List listFilesInDirWithFilter(final String dirPath,
+ final FileFilter filter) {
+ return listFilesInDirWithFilter(getFileByPath(dirPath), filter, false);
+ }
+
+ /**
+ * Return the files that satisfy the filter in directory.
+ * Doesn't traverse subdirectories
+ *
+ * @param dir The directory.
+ * @param filter The filter.
+ * @return the files that satisfy the filter in directory
+ */
+ public static List listFilesInDirWithFilter(final File dir,
+ final FileFilter filter) {
+ return listFilesInDirWithFilter(dir, filter, false);
+ }
+
+ /**
+ * Return the files that satisfy the filter in directory.
+ *
+ * @param dirPath The path of directory.
+ * @param filter The filter.
+ * @param isRecursive True to traverse subdirectories, false otherwise.
+ * @return the files that satisfy the filter in directory
+ */
+ public static List listFilesInDirWithFilter(final String dirPath,
+ final FileFilter filter,
+ final boolean isRecursive) {
+ return listFilesInDirWithFilter(getFileByPath(dirPath), filter, isRecursive);
+ }
+
+ /**
+ * Return the files that satisfy the filter in directory.
+ *
+ * @param dir The directory.
+ * @param filter The filter.
+ * @param isRecursive True to traverse subdirectories, false otherwise.
+ * @return the files that satisfy the filter in directory
+ */
+ public static List listFilesInDirWithFilter(final File dir,
+ final FileFilter filter,
+ final boolean isRecursive) {
+ if (!isDir(dir)) return null;
+ List list = new ArrayList<>();
+ File[] files = dir.listFiles();
+ if (files != null && files.length != 0) {
+ for (File file : files) {
+ if (filter.accept(file)) {
+ list.add(file);
+ }
+ if (isRecursive && file.isDirectory()) {
+ //noinspection ConstantConditions
+ list.addAll(listFilesInDirWithFilter(file, filter, true));
+ }
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Return the time that the file was last modified.
+ *
+ * @param filePath The path of file.
+ * @return the time that the file was last modified
+ */
+
+ public static long getFileLastModified(final String filePath) {
+ return getFileLastModified(getFileByPath(filePath));
+ }
+
+ /**
+ * Return the time that the file was last modified.
+ *
+ * @param file The file.
+ * @return the time that the file was last modified
+ */
+ public static long getFileLastModified(final File file) {
+ if (file == null) return -1;
+ return file.lastModified();
+ }
+
+ /**
+ * Return the charset of file simply.
+ *
+ * @param filePath The path of file.
+ * @return the charset of file simply
+ */
+ public static String getFileCharsetSimple(final String filePath) {
+ return getFileCharsetSimple(getFileByPath(filePath));
+ }
+
+ /**
+ * Return the charset of file simply.
+ *
+ * @param file The file.
+ * @return the charset of file simply
+ */
+ public static String getFileCharsetSimple(final File file) {
+ int p = 0;
+ InputStream is = null;
+ try {
+ is = new BufferedInputStream(new FileInputStream(file));
+ p = (is.read() << 8) + is.read();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (is != null) {
+ is.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ switch (p) {
+ case 0xefbb:
+ return "UTF-8";
+ case 0xfffe:
+ return "Unicode";
+ case 0xfeff:
+ return "UTF-16BE";
+ default:
+ return "GBK";
+ }
+ }
+
+ /**
+ * Return the number of lines of file.
+ *
+ * @param filePath The path of file.
+ * @return the number of lines of file
+ */
+ public static int getFileLines(final String filePath) {
+ return getFileLines(getFileByPath(filePath));
+ }
+
+ /**
+ * Return the number of lines of file.
+ *
+ * @param file The file.
+ * @return the number of lines of file
+ */
+ public static int getFileLines(final File file) {
+ int count = 1;
+ InputStream is = null;
+ try {
+ is = new BufferedInputStream(new FileInputStream(file));
+ byte[] buffer = new byte[1024];
+ int readChars;
+ if (LINE_SEP.endsWith("\n")) {
+ while ((readChars = is.read(buffer, 0, 1024)) != -1) {
+ for (int i = 0; i < readChars; ++i) {
+ if (buffer[i] == '\n') ++count;
+ }
+ }
+ } else {
+ while ((readChars = is.read(buffer, 0, 1024)) != -1) {
+ for (int i = 0; i < readChars; ++i) {
+ if (buffer[i] == '\r') ++count;
+ }
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (is != null) {
+ is.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return count;
+ }
+
+ /**
+ * Return the size of directory.
+ *
+ * @param dirPath The path of directory.
+ * @return the size of directory
+ */
+ public static String getDirSize(final String dirPath) {
+ return getDirSize(getFileByPath(dirPath));
+ }
+
+ /**
+ * Return the size of directory.
+ *
+ * @param dir The directory.
+ * @return the size of directory
+ */
+ public static String getDirSize(final File dir) {
+ long len = getDirLength(dir);
+ return len == -1 ? "" : byte2FitMemorySize(len);
+ }
+
+ /**
+ * Return the length of file.
+ *
+ * @param filePath The path of file.
+ * @return the length of file
+ */
+ public static String getFileSize(final String filePath) {
+ long len = getFileLength(filePath);
+ return len == -1 ? "" : byte2FitMemorySize(len);
+ }
+
+ /**
+ * Return the length of file.
+ *
+ * @param file The file.
+ * @return the length of file
+ */
+ public static String getFileSize(final File file) {
+ long len = getFileLength(file);
+ return len == -1 ? "" : byte2FitMemorySize(len);
+ }
+
+ /**
+ * Return the length of directory.
+ *
+ * @param dirPath The path of directory.
+ * @return the length of directory
+ */
+ public static long getDirLength(final String dirPath) {
+ return getDirLength(getFileByPath(dirPath));
+ }
+
+ /**
+ * Return the length of directory.
+ *
+ * @param dir The directory.
+ * @return the length of directory
+ */
+ public static long getDirLength(final File dir) {
+ if (!isDir(dir)) return -1;
+ long len = 0;
+ File[] files = dir.listFiles();
+ if (files != null && files.length != 0) {
+ for (File file : files) {
+ if (file.isDirectory()) {
+ len += getDirLength(file);
+ } else {
+ len += file.length();
+ }
+ }
+ }
+ return len;
+ }
+
+ /**
+ * Return the length of file.
+ *
+ * @param filePath The path of file.
+ * @return the length of file
+ */
+ public static long getFileLength(final String filePath) {
+ boolean isURL = filePath.matches("[a-zA-z]+://[^\\s]*");
+ if (isURL) {
+ try {
+ HttpsURLConnection conn = (HttpsURLConnection) new URL(filePath).openConnection();
+ conn.setRequestProperty("Accept-Encoding", "identity");
+ conn.connect();
+ if (conn.getResponseCode() == 200) {
+ return conn.getContentLength();
+ }
+ return -1;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return getFileLength(getFileByPath(filePath));
+ }
+
+ /**
+ * Return the length of file.
+ *
+ * @param file The file.
+ * @return the length of file
+ */
+ public static long getFileLength(final File file) {
+ if (!isFile(file)) return -1;
+ return file.length();
+ }
+
+ /**
+ * 获取指定文件大小
+ * @return
+ * @throws Exception
+ */
+ public static long getFileSizeLong(File file) throws Exception
+ {
+ long size = 0;
+ if (file.exists()){
+ FileInputStream fis = null;
+ fis = new FileInputStream(file);
+ size = fis.available();
+ }
+ else{
+ CupidLogUtils.e("获取文件大小","文件不存在!");
+ }
+ return size;
+ }
+
+ /**
+ * Return the MD5 of file.
+ *
+ * @param filePath The path of file.
+ * @return the md5 of file
+ */
+ public static String getFileMD5ToString(final String filePath) {
+ File file = isSpace(filePath) ? null : new File(filePath);
+ return getFileMD5ToString(file);
+ }
+
+ /**
+ * Return the MD5 of file.
+ *
+ * @param file The file.
+ * @return the md5 of file
+ */
+ public static String getFileMD5ToString(final File file) {
+ return bytes2HexString(getFileMD5(file));
+ }
+
+ /**
+ * Return the MD5 of file.
+ *
+ * @param filePath The path of file.
+ * @return the md5 of file
+ */
+ public static byte[] getFileMD5(final String filePath) {
+ return getFileMD5(getFileByPath(filePath));
+ }
+
+ /**
+ * Return the MD5 of file.
+ *
+ * @param file The file.
+ * @return the md5 of file
+ */
+ public static byte[] getFileMD5(final File file) {
+ if (file == null) return null;
+ DigestInputStream dis = null;
+ try {
+ FileInputStream fis = new FileInputStream(file);
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ dis = new DigestInputStream(fis, md);
+ byte[] buffer = new byte[1024 * 256];
+ while (true) {
+ if (!(dis.read(buffer) > 0)) break;
+ }
+ md = dis.getMessageDigest();
+ return md.digest();
+ } catch (NoSuchAlgorithmException | IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (dis != null) {
+ dis.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the file's path of directory.
+ *
+ * @param file The file.
+ * @return the file's path of directory
+ */
+ public static String getDirName(final File file) {
+ if (file == null) return "";
+ return getDirName(file.getAbsolutePath());
+ }
+
+ /**
+ * Return the file's path of directory.
+ *
+ * @param filePath The path of file.
+ * @return the file's path of directory
+ */
+ public static String getDirName(final String filePath) {
+ if (isSpace(filePath)) return "";
+ int lastSep = filePath.lastIndexOf(File.separator);
+ return lastSep == -1 ? "" : filePath.substring(0, lastSep + 1);
+ }
+
+ /**
+ * Return the name of file.
+ *
+ * @param file The file.
+ * @return the name of file
+ */
+ public static String getFileName(final File file) {
+ if (file == null) return "";
+ return getFileName(file.getAbsolutePath());
+ }
+
+ /**
+ * Return the name of file.
+ *
+ * @param filePath The path of file.
+ * @return the name of file
+ */
+ public static String getFileName(final String filePath) {
+ if (isSpace(filePath)) return "";
+ int lastSep = filePath.lastIndexOf(File.separator);
+ return lastSep == -1 ? filePath : filePath.substring(lastSep + 1);
+ }
+
+ /**
+ * Return the name of file without extension.
+ *
+ * @param file The file.
+ * @return the name of file without extension
+ */
+ public static String getFileNameNoExtension(final File file) {
+ if (file == null) return "";
+ return getFileNameNoExtension(file.getPath());
+ }
+
+ /**
+ * Return the name of file without extension.
+ *
+ * @param filePath The path of file.
+ * @return the name of file without extension
+ */
+ public static String getFileNameNoExtension(final String filePath) {
+ if (isSpace(filePath)) return "";
+ int lastPoi = filePath.lastIndexOf('.');
+ int lastSep = filePath.lastIndexOf(File.separator);
+ if (lastSep == -1) {
+ return (lastPoi == -1 ? filePath : filePath.substring(0, lastPoi));
+ }
+ if (lastPoi == -1 || lastSep > lastPoi) {
+ return filePath.substring(lastSep + 1);
+ }
+ return filePath.substring(lastSep + 1, lastPoi);
+ }
+
+ /**
+ * Return the extension of file.
+ *
+ * @param file The file.
+ * @return the extension of file
+ */
+ public static String getFileExtension(final File file) {
+ if (file == null) return "";
+ return getFileExtension(file.getPath());
+ }
+
+ /**
+ * Return the extension of file.
+ *
+ * @param filePath The path of file.
+ * @return the extension of file
+ */
+ public static String getFileExtension(final String filePath) {
+ if (isSpace(filePath)) return "";
+ int lastPoi = filePath.lastIndexOf('.');
+ int lastSep = filePath.lastIndexOf(File.separator);
+ if (lastPoi == -1 || lastSep >= lastPoi) return "";
+ return filePath.substring(lastPoi + 1);
+ }
+
+ /**
+ * Notify system to scan the file.
+ *
+ * @param file The file.
+ */
+ public static void notifySystemToScan(Context context, final File file) {
+ if (file == null || !file.exists()) return;
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ Uri uri = Uri.fromFile(file);
+ intent.setData(uri);
+ context.sendBroadcast(intent);
+ }
+
+ /**
+ * Notify system to scan the file.
+ *
+ * @param filePath The path of file.
+ */
+ public static void notifySystemToScan(final Context context, final String filePath) {
+ notifySystemToScan(context, getFileByPath(filePath));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // interface
+ ///////////////////////////////////////////////////////////////////////////
+
+ public interface OnReplaceListener {
+ boolean onReplace();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // other utils methods
+ ///////////////////////////////////////////////////////////////////////////
+
+ private static final char[] HEX_DIGITS =
+ {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+
+ private static String bytes2HexString(final byte[] bytes) {
+ if (bytes == null) return "";
+ int len = bytes.length;
+ if (len <= 0) return "";
+ char[] ret = new char[len << 1];
+ for (int i = 0, j = 0; i < len; i++) {
+ ret[j++] = HEX_DIGITS[bytes[i] >> 4 & 0x0f];
+ ret[j++] = HEX_DIGITS[bytes[i] & 0x0f];
+ }
+ return new String(ret);
+ }
+
+ private static String byte2FitMemorySize(final long byteNum) {
+ if (byteNum < 0) {
+ return "shouldn't be less than zero!";
+ } else if (byteNum < 1024) {
+ return String.format(Locale.getDefault(), "%.3fB", (double) byteNum);
+ } else if (byteNum < 1048576) {
+ return String.format(Locale.getDefault(), "%.3fKB", (double) byteNum / 1024);
+ } else if (byteNum < 1073741824) {
+ return String.format(Locale.getDefault(), "%.3fMB", (double) byteNum / 1048576);
+ } else {
+ return String.format(Locale.getDefault(), "%.3fGB", (double) byteNum / 1073741824);
+ }
+ }
+
+ private static boolean isSpace(final String s) {
+ if (s == null) return true;
+ for (int i = 0, len = s.length(); i < len; ++i) {
+ if (!Character.isWhitespace(s.charAt(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean writeFileFromIS(final File file,
+ final InputStream is) {
+ OutputStream os = null;
+ try {
+ os = new BufferedOutputStream(new FileOutputStream(file));
+ byte data[] = new byte[8192];
+ int len;
+ while ((len = is.read(data, 0, 8192)) != -1) {
+ os.write(data, 0, len);
+ }
+ return true;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
+ if (os != null) {
+ os.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 写文件 string
+ *
+ * @param fullFileName
+ * @param logContent
+ * @param isAppend
+ */
+ public static void writeFile(String fullFileName, String logContent, boolean isAppend) {
+ FileWriter fileWriter = null;
+ try {
+ fileWriter = new FileWriter(new File(fullFileName), isAppend);
+ fileWriter.write(logContent);
+ fileWriter.write("\n");
+ fileWriter.flush();
+ fileWriter.close();
+ } catch (Exception e) {
+ } finally {
+ BaseIoUtils.closeSilently(fileWriter);
+ }
+ }
+
+ /**
+ * 获取文件路径
+ *
+ * @param baseDir
+ * @param fileName
+ * @return
+ */
+ public static String getFilePath(Context context, String baseDir, String fileName) {
+ String basePath = saveVideoBasePathDir(context, baseDir);
+ File file = new File(basePath + File.separator + fileName);
+ if (!file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+
+ if (!file.exists()) {
+ try {
+ file.createNewFile();
+ return file.getAbsolutePath();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return file.getAbsolutePath();
+ }
+
+ /**
+ * 保存图片的路径
+ *
+ * @return
+ */
+ public static String saveVideoBasePathDir(Context context, String dirName) {
+ String basePath = null;
+ //有SD卡
+ if (BaseSDCardHelper.isSDCardMounted()) {
+ basePath = BaseSDCardHelper.getSDCardBaseDir();
+ } else {
+ basePath = context.getCacheDir().getAbsolutePath();
+ }
+
+ return basePath + File.separator + dirName;
+
+ }
+
+ /**
+ * 删除文件夹
+ *
+ * @param context
+ * @param baseDir
+ */
+ public static void removeAllFileDir(Context context, String baseDir) {
+ String basePath = saveVideoBasePathDir(context, baseDir);
+ File file = new File(basePath);
+ if (file.exists()) {
+ delAllFile(file.getAbsolutePath());
+ }
+ }
+
+
+ public static boolean delAllFile(String path) {
+ boolean flag = false;
+ try {
+ File file = new File(path);
+ if (!file.exists()) {
+ return flag;
+ }
+ if (!file.isDirectory()) {
+ return flag;
+ }
+ String[] tempList = file.list();
+ File temp = null;
+ for (int i = 0; i < tempList.length; i++) {
+ if (path.endsWith(File.separator)) {
+ temp = new File(path + tempList[i]);
+ } else {
+ temp = new File(path + File.separator + tempList[i]);
+ }
+ if (temp.isFile()) {
+ temp.delete();
+ }
+ if (temp.isDirectory()) {
+ delAllFile(path + "/" + tempList[i]);// 先删除文件夹里面的文件
+ delFolder(path + "/" + tempList[i]);// 再删除空文件夹
+ flag = true;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return flag;
+ }
+
+ private static void delFolder(String folderPath) {
+ try {
+ delAllFile(folderPath); // 删除完里面所有内容
+ String filePath = folderPath;
+ filePath = filePath.toString();
+ File myFilePath = new File(filePath);
+ myFilePath.delete(); // 删除空文件夹
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * 根据byte数组生成文件
+ *
+ * @param bytes 生成文件用到的byte数组
+ */
+ public static void createFileWithByte(byte[] bytes, String filePath) {
+ /**
+ * 创建File对象,其中包含文件所在的目录以及文件的命名
+ */
+ File file = new File(filePath);
+ // 创建FileOutputStream对象
+ FileOutputStream outputStream = null;
+ // 创建BufferedOutputStream对象
+ BufferedOutputStream bufferedOutputStream = null;
+ try {
+ if (!file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+ if (!file.exists()) {
+ // 在文件系统中根据路径创建一个新的空文件
+ file.createNewFile();
+ }
+ // 获取FileOutputStream对象
+ outputStream = new FileOutputStream(file);
+ // 获取BufferedOutputStream对象
+ bufferedOutputStream = new BufferedOutputStream(outputStream);
+ // 往文件所在的缓冲输出流中写byte数据
+ bufferedOutputStream.write(bytes);
+ // 刷出缓冲输出流,该步很关键,要是不执行flush()方法,那么文件的内容是空的。
+ bufferedOutputStream.flush();
+ } catch (Exception e) {
+ // 打印异常信息
+ e.printStackTrace();
+ } finally {
+ // 关闭创建的流对象
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (bufferedOutputStream != null) {
+ try {
+ bufferedOutputStream.close();
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /**
+ * Mapped File way MappedByteBuffer 可以在处理大文件时,提升性能
+ *
+ * @param filename
+ * @return
+ * @throws IOException
+ */
+ public static byte[] file2ByteArray(String filename) throws IOException {
+
+ FileChannel fc = null;
+ try {
+ fc = new RandomAccessFile(filename, "r").getChannel();
+ MappedByteBuffer byteBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0,
+ fc.size()).load();
+ System.out.println(byteBuffer.isLoaded());
+ byte[] result = new byte[(int) fc.size()];
+ if (byteBuffer.remaining() > 0) {
+ // System.out.println("remain");
+ byteBuffer.get(result, 0, byteBuffer.remaining());
+ }
+ return result;
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw e;
+ } finally {
+ try {
+ fc.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static String getNowString(final java.text.DateFormat format) {
+ return millis2String(System.currentTimeMillis(), format);
+ }
+
+ /**
+ * Milliseconds to the formatted time string.
+ *
+ * @param millis The milliseconds.
+ * @param format The format.
+ * @return the formatted time string
+ */
+ public static String millis2String(final long millis, final java.text.DateFormat format) {
+ return format.format(new Date(millis));
+ }
+
+}
\ No newline at end of file
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/HandlerThreadManager.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/HandlerThreadManager.java
new file mode 100644
index 0000000000..94cfee8328
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/HandlerThreadManager.java
@@ -0,0 +1,63 @@
+package com.zhidao.support.adas.high.common;
+
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Looper;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class HandlerThreadManager {
+ private volatile static HandlerThread sBackgroundHandlerThread;
+ private volatile static HandlerThread sIOHandlerThread;
+ private volatile static Handler sBackgroundHandler;
+ private volatile static Handler sMainHandler;
+
+ public static Handler getBackgroundHandler() {
+ if (sBackgroundHandler == null) {
+ sBackgroundHandler = new Handler(getBackgroundHandlerThread().getLooper());
+ }
+ return sBackgroundHandler;
+ }
+
+ public static HandlerThread getBackgroundHandlerThread() {
+ synchronized (HandlerThreadManager.class) {
+ if (sBackgroundHandlerThread == null) {
+ sBackgroundHandlerThread = new HandlerThread("autopilot_bgd_thread");
+ sBackgroundHandlerThread.start();
+ }
+ }
+ return sBackgroundHandlerThread;
+ }
+
+ private static HandlerThread getVideoHandlerThread() {
+ synchronized (HandlerThreadManager.class) {
+ if (sIOHandlerThread == null) {
+ sIOHandlerThread = new HandlerThread("autopilot_video_thread");
+ sIOHandlerThread.start();
+ }
+ }
+ return sIOHandlerThread;
+ }
+
+
+ public static Handler getMainHandler() {
+ if (sMainHandler == null) {
+ sMainHandler = new Handler(Looper.getMainLooper());
+ }
+ return sMainHandler;
+ }
+
+ public static final Executor EXECUTOR = new ThreadPoolExecutor(2, 5, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue(30),
+ new ThreadFactory() {
+ private final AtomicInteger mCount = new AtomicInteger(1);
+
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "autopilot-thread-pool" + mCount.getAndIncrement());
+ }
+ });
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/IPreferencesHelper.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/IPreferencesHelper.java
new file mode 100644
index 0000000000..1c843a1066
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/IPreferencesHelper.java
@@ -0,0 +1,135 @@
+package com.zhidao.support.adas.high.common;
+
+
+import com.zhidao.support.adas.high.bean.FaceLoginResponse;
+import com.zhidao.support.adas.high.bean.UserInfo;
+
+/**
+ * Created by nie yunlong on 2018/4/13.
+ */
+
+public interface IPreferencesHelper {
+ /**
+ * 保存udp client address
+ *
+ * @param address
+ */
+ void saveUdpClientAddress(String address);
+
+ /**
+ * 获取client address
+ *
+ * @return
+ */
+ String getUdpClientAddress();
+
+ /**
+ * 保存dock config
+ *
+ * @param dockConfig
+ */
+ void saveDockConfig(String dockConfig);
+
+ /**
+ * 获取dock config
+ *
+ * @return
+ */
+ String getDockConfig();
+
+ /**
+ * 设置用户信息
+ *
+ * @param loginResponse
+ */
+ void setUserInfo(FaceLoginResponse.DataBean loginResponse);
+
+ /**
+ * 获取用户信息
+ *
+ * @return
+ */
+ FaceLoginResponse.DataBean getUserInfo();
+
+ /**
+ * 假的 以后干掉
+ *
+ * @param selectIndex
+ */
+ void setConfigNaviMapVis(int selectIndex);
+
+ /**
+ * @return
+ */
+ int getConfigNaviMapVis();
+
+ /**
+ * @param userInfo
+ */
+ void saveUserUnInfo(UserInfo userInfo);
+
+ /**
+ * 用户ID userInfo 用于扩展
+ *
+ * @return
+ */
+ UserInfo getUserUnInfo();
+
+
+ /**
+ * 初始化标志位
+ *
+ * @param flag
+ */
+ void setConfigInitResutl(boolean flag);
+
+ /**
+ * 初始化标志位
+ *
+ * @return
+ */
+ boolean getConfigInitResutl();
+
+
+
+ void setSelectCarInfo(String brand, String model, String style);
+
+ String getSelectBrand();
+
+ String getSelectModel();
+
+ String getSelectStyle();
+
+
+ /**
+ * raw
+ *
+ * @param rawPath
+ */
+ void saveRawPath(int rawName, String rawPath);
+
+ /**
+ * @param rawName
+ * @return
+ */
+ String getRawPath(int rawName);
+
+ /**
+ *
+ */
+ void clearRawConfig(int rawName);
+
+ /**
+ * app 启动开始时间
+ *
+ * @param time
+ */
+ void setAppAttachTime(long time);
+
+ /**
+ * 获取
+ * @return
+ */
+ long getAppAttachTime();
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/LogSaveManage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/LogSaveManage.java
new file mode 100644
index 0000000000..48e2df1031
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/LogSaveManage.java
@@ -0,0 +1,70 @@
+package com.zhidao.support.adas.high.common;
+
+import android.text.TextUtils;
+
+import com.zhidao.support.adas.high.thread.QueuedWork;
+
+import java.io.File;
+
+public
+/**
+ * @author nie yunlong
+ * @des
+ * @date 2021/3/4
+ */
+class LogSaveManage {
+ private static final LogSaveManage ourInstance = new LogSaveManage();
+ //当前保存的文件路径
+ private String currentSaveFilePath;
+ //6M
+ private final long FILE_LIMIT_SIZE = 6 * 1024 * 1024;
+
+ static LogSaveManage getInstance() {
+ return ourInstance;
+ }
+
+ private LogSaveManage() {
+ }
+
+ /**
+ * 保存文件
+ *
+ * @param msg
+ */
+ public synchronized void saveWrite(final String msg) {
+ QueuedWork.runInBack(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ String logFilePath = createFileReturnPath();
+ FileUtils.writeFile(logFilePath, msg, true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ }
+
+ /**
+ * 创建文件
+ *
+ * @return
+ */
+ private synchronized String createFileReturnPath() throws Exception {
+ if (!TextUtils.isEmpty(currentSaveFilePath)) {
+ long fileSize = FileUtils.getFileSizeLong(new File(currentSaveFilePath));
+ if (fileSize <= FILE_LIMIT_SIZE) {
+ return currentSaveFilePath;
+ }
+ }
+ //大于6M
+ String filePath = BaseSDCardHelper.getSDCardPrivateFilesDir(MgContextUtils.getContext(), "adas-log") + File.separator + BaseTimeUtils.formatTimeDate3() + "-log.txt";
+ //把日志保存到文件
+ boolean isCreateFileSuccess = FileUtils.createOrExistsFile(filePath);
+ if (isCreateFileSuccess) {
+ currentSaveFilePath = filePath;
+ }
+ return currentSaveFilePath;
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/MgContextUtils.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/MgContextUtils.java
new file mode 100644
index 0000000000..fcc310a381
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/MgContextUtils.java
@@ -0,0 +1,33 @@
+package com.zhidao.support.adas.high.common;
+
+import android.content.Context;
+
+/**
+ * @author nie yunlong
+ * @des 上下文管理
+ * @date 2019/5/13
+ */
+public class MgContextUtils {
+ /**
+ * 上下文
+ */
+ private static Context mContext;
+
+ /**
+ * 设置上下文
+ *
+ * @param context
+ */
+ public static void setContext(Context context) {
+ mContext = context.getApplicationContext();
+ }
+
+ /**
+ * 获取上下文
+ *
+ * @return
+ */
+ public static Context getContext() {
+ return mContext;
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/RequestWsMsgType.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/RequestWsMsgType.java
new file mode 100644
index 0000000000..6eb1ffa5b2
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/RequestWsMsgType.java
@@ -0,0 +1,52 @@
+package com.zhidao.support.adas.high.common;
+
+/**
+ * @author nie yunlong
+ * @description 请求值
+ * @date 2018/7/3
+ */
+public enum RequestWsMsgType {
+
+ /**
+ * 获取视频信息
+ */
+ MSG_GET_VIDEO_INFO(1, "get video info"),
+ /**
+ * 视频分辨率
+ */
+ MSG_SEND_LOCATION(2, "视频分辨率"),
+ /**
+ * 上传配置
+ */
+ MSG_SEND_UPLOAD_CONFIG(3, "上传配置"),
+
+ MSG_SEND_CLOSE(5, "关闭socket");
+ int mMsgType;
+ /**
+ * 描述
+ */
+ String mMsgDesc;
+
+ RequestWsMsgType(int msgType, String msgDesc) {
+ this.mMsgType = msgType;
+ this.mMsgDesc = msgDesc;
+ }
+
+ /**
+ * 获取msgType
+ *
+ * @return
+ */
+ public int getMsgType() {
+ return mMsgType;
+ }
+
+ /**
+ * 获取描述
+ *
+ * @return
+ */
+ public String getmMsgDesc() {
+ return mMsgDesc;
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/SSH.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/SSH.java
new file mode 100644
index 0000000000..561a360952
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/SSH.java
@@ -0,0 +1,150 @@
+package com.zhidao.support.adas.high.common;
+
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import com.zhidao.support.adas.high.bean.SSHResult;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Properties;
+
+public class SSH {
+ private static final String TAG = SSH.class.getSimpleName();
+
+ private Session session = null;
+ private ChannelExec channelExec = null;
+ ByteArrayOutputStream err = null;
+ StringBuffer outBuf = null;
+
+ public ByteArrayOutputStream getErr() {
+ return err;
+ }
+
+ public StringBuffer getOutBuf() {
+ return outBuf;
+ }
+
+ public Session getSession() {
+ return session;
+ }
+
+ public ChannelExec getChannelExec() {
+ return channelExec;
+ }
+
+ /**
+ * 使用用户名、密码连接
+ *
+ * @param host 主机ip
+ * @param port 主机端口
+ * @param username 主机用户名
+ * @param password 主机密码
+ * @throws JSchException
+ */
+ public void connect(String host, int port, String username, String password) throws JSchException {
+ JSch jsch = new JSch();
+ session = jsch.getSession(username, host, port);
+ session.setPassword(password);
+ Properties config = new Properties();
+ config.put("StrictHostKeyChecking", "no");
+ session.setConfig(config);
+ session.setTimeout(30000);
+ session.connect();
+ Log.i(TAG, "Connected to " + host + ".");
+ }
+
+ /**
+ * 使用授信连接
+ *
+ * @param host 主机ip
+ * @param username 主机用户名
+ * @param privateKey 私钥路径
+ * @throws JSchException
+ */
+ public void connect(String host, String username, String privateKey) throws JSchException {
+ JSch jsch = new JSch();
+ jsch.addIdentity(privateKey);
+ session = jsch.getSession(username, host);
+
+ Properties config = new Properties();
+ config.put("StrictHostKeyChecking", "no");
+ session.setConfig(config);
+ session.setTimeout(30000);
+ session.connect();
+ Log.i(TAG, "Connected to " + host + ".");
+ }
+
+ /**
+ * 执行
+ *
+ * @param cmd 命令
+ * @return 状态
+ * @throws JSchException
+ * @throws IOException
+ */
+ public SSHResult exec(String cmd) throws JSchException, IOException {
+ return exec(cmd, null);
+ }
+
+ public SSHResult exec(String cmd, String suPwd) throws JSchException, IOException {
+ int exitStatus = 0;
+ channelExec = (ChannelExec) session.openChannel("exec");
+ channelExec.setInputStream(null);
+ err = new ByteArrayOutputStream();
+ channelExec.setErrStream(err);
+ channelExec.setCommand(cmd);
+ InputStream in = channelExec.getInputStream();
+ OutputStream out = channelExec.getOutputStream();
+ channelExec.connect();
+ if (!TextUtils.isEmpty(suPwd) && (cmd.contains("sudo") || cmd.contains("su"))) {
+ out.write((suPwd + "\n").getBytes()); //这里是密码后跟了一个换行符
+ out.flush();
+ }
+ outBuf = new StringBuffer();
+ byte[] tmp = new byte[1024];
+ while (true) {
+ while (in.available() > 0) {
+ int i = in.read(tmp, 0, 1024);
+ if (i < 0) break;
+ outBuf.append(new String(tmp, 0, i));
+ }
+ if (channelExec.isClosed()) {
+ if (in.available() > 0) continue;
+ exitStatus = channelExec.getExitStatus();
+ break;
+ }
+ try {
+ Thread.sleep(1000L);
+ } catch (Exception e) {
+ }
+ }
+ channelExec.disconnect();
+ if (exitStatus == 0) {
+ String outInfo = this.getOutBuf().toString();
+ return new SSHResult(exitStatus, cmd, outInfo);
+ } else {
+ String errInfo = this.getErr().toString();
+ return new SSHResult(exitStatus, cmd, errInfo);
+ }
+ }
+
+ /**
+ * 断开连接
+ */
+ public void disConnect() {
+ if (channelExec != null) {
+ channelExec.disconnect();
+ }
+ if (session != null) {
+ session.disconnect();
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ThreadPoolManager.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ThreadPoolManager.java
new file mode 100644
index 0000000000..4ae835c3ef
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ThreadPoolManager.java
@@ -0,0 +1,127 @@
+package com.zhidao.support.adas.high.common;
+
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 线程池
+ * Created by xfk on 2018/9/30.
+ */
+
+public class ThreadPoolManager {
+
+ /**
+ * 根据cpu的数量动态的配置核心线程数和最大线程数
+ */
+ private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
+ /**
+ * 核心线程数 = CPU核心数 + 1
+ */
+ private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
+ /**
+ * 线程池最大线程数 = CPU核心数 * 2 + 1
+ */
+ private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
+ /**
+ * 非核心线程闲置时超时1s
+ */
+ private static final int KEEP_ALIVE = 1;
+ /**
+ * 线程池的对象
+ */
+ private ThreadPoolExecutor executor;
+
+ /**
+ * 要确保该类只有一个实例对象,避免产生过多对象消费资源,所以采用单例模式
+ */
+ private ThreadPoolManager() {
+ }
+
+ private volatile static ThreadPoolManager INSTANCE;
+
+ public static ThreadPoolManager getsInstance() {
+ if (INSTANCE == null) {
+ synchronized (ThreadPoolManager.class) {
+ if (INSTANCE == null) {
+ INSTANCE = new ThreadPoolManager();
+ }
+ }
+
+ }
+ return INSTANCE;
+ }
+
+ /**
+ * 开启一个无返回结果的线程
+ *
+ * @param r
+ */
+ public void execute(Runnable r) {
+ if (executor == null) {
+ /**
+ * corePoolSize:核心线程数
+ * maximumPoolSize:线程池所容纳最大线程数(workQueue队列满了之后才开启)
+ * keepAliveTime:非核心线程闲置时间超时时长
+ * unit:keepAliveTime的单位
+ * workQueue:等待队列,存储还未执行的任务
+ * threadFactory:线程创建的工厂
+ * handler:异常处理机制
+ *
+ */
+ executor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE,
+ KEEP_ALIVE, TimeUnit.SECONDS, new ArrayBlockingQueue(200),
+ Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
+ }
+ // 把一个任务丢到了线程池中
+ try {
+ executor.execute(r);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * 开启一个有返回结果的线程
+ *
+ * @param r
+ * @return
+ */
+ public Future submit(Callable r) {
+ if (executor == null) {
+ /**
+ * corePoolSize:核心线程数
+ * maximumPoolSize:线程池所容纳最大线程数(workQueue队列满了之后才开启)
+ * keepAliveTime:非核心线程闲置时间超时时长
+ * unit:keepAliveTime的单位
+ * workQueue:等待队列,存储还未执行的任务
+ * threadFactory:线程创建的工厂
+ * handler:异常处理机制
+ *
+ */
+ executor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE,
+ KEEP_ALIVE, TimeUnit.SECONDS, new ArrayBlockingQueue(20),
+ Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
+ }
+ // 把一个任务丢到了线程池中
+ return executor.submit(r);
+ }
+
+ /**
+ * 把任务移除等待队列
+ *
+ * @param r
+ */
+ public void cancel(Runnable r) {
+ if (r != null) {
+ executor.getQueue().remove(r);
+ }
+ }
+
+}
+
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/IMsg.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/IMsg.java
new file mode 100644
index 0000000000..acdc45de7d
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/IMsg.java
@@ -0,0 +1,22 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.queue.UdpMsgModel;
+
+/**
+ * @author nie yunlong
+ * @des
+ * @date 2020/3/12
+ */
+public interface IMsg {
+ /**
+ * 处理消息
+ *
+ * @param msg
+ */
+ void handlerMsg(Gson gson, OnAdasListener adasListener, String msg);
+
+ void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg);
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/IMyMessageFactory.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/IMyMessageFactory.java
new file mode 100644
index 0000000000..d85aeee531
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/IMyMessageFactory.java
@@ -0,0 +1,20 @@
+package com.zhidao.support.adas.high.msg;
+
+/**
+ * 生产产品的工厂
+ */
+public interface IMyMessageFactory {
+ /**
+ *
+ * @param messageType 消息类型
+ * @return
+ */
+ public IMsg createMessage(String messageType);
+
+ /**
+ *
+ * @param messageCode 消息类型
+ * @return
+ */
+ public IMsg createMessage(int messageCode);
+}
\ No newline at end of file
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/MyAbstractMessageHandler.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/MyAbstractMessageHandler.java
new file mode 100644
index 0000000000..59dcf3d8c3
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/MyAbstractMessageHandler.java
@@ -0,0 +1,11 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.protobuf.util.JsonFormat;
+
+/**
+ * @author nie yunlong
+ * @des 消息处理中心
+ * @date 2020/3/12
+ */
+public abstract class MyAbstractMessageHandler implements IMsg {
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/MyMessageFactory.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/MyMessageFactory.java
new file mode 100644
index 0000000000..4991e7b859
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/MyMessageFactory.java
@@ -0,0 +1,242 @@
+package com.zhidao.support.adas.high.msg;
+
+import android.text.TextUtils;
+
+import com.zhidao.support.adas.high.common.ActionTypeReceive;
+
+/**
+ * @author nie yunlong
+ * @des 简易工厂
+ * @date 2020/3/12
+ */
+public class MyMessageFactory implements IMyMessageFactory {
+ /**
+ * udp 渲染 image
+ */
+ private IMsg udpRenderImageMsg;
+ /**
+ * ws 报警 消息
+ */
+ private IMsg wsWarnMessage;
+ /**
+ * ws 图像size
+ */
+ private IMsg wsImageSizeMessage;
+ /**
+ * 空实现
+ */
+ private IMsg nuImplMessage;
+ /**
+ * udp 车辆状态消息
+ */
+ private IMsg udpCarStateMessage;
+ /**
+ * 红绿灯状态
+ */
+ private IMsg udpLightStateMessage;
+ /**
+ * 周边物体的状态
+ */
+ private IMsg udpObstaclesMessage;
+
+ /**
+ * 局部轨迹消息
+ */
+ private IMsg trajectoryMessage;
+
+ /**
+ * 监控信息
+ */
+ private IMsg guardianMessage;
+ /**
+ * 车道线渲染
+ */
+ private IMsg lanesMessage;
+ /**
+ * 自动驾驶状态
+ */
+ private IMsg autopilotStatusMessage;
+ /**
+ * 自动驾驶到站
+ */
+ private IMsg autopilotArriveMessage;
+ /**
+ * 自动驾驶路径
+ */
+ private IMsg autopilotRouteMessage;
+ /**
+ * 工控机获取SN
+ */
+ private IMsg autopilotSNMessage;
+ /**
+ * 数据采集信息
+ */
+ private IMsg autopilotIdentify;
+ /**
+ * 工控机升级状态
+ */
+ private IMsg autopilotUpgradeStatusMessage;
+ /**
+ * car dock 基础信息
+ */
+ private IMsg autopilotConfig;
+ /**
+ * 工控机升级进度
+ */
+ private IMsg autopilotUpgradePatchDownloadStatusMessage;
+
+
+ @Override
+ public IMsg createMessage(String messageType) {
+ if (TextUtils.isEmpty(messageType)) {
+ if (nuImplMessage == null) {
+ nuImplMessage = new NuImplMessage();
+ }
+ return nuImplMessage;
+ }
+ if (messageType.equals(ActionTypeReceive.ACTION_WS_MSG_RENDER_TYPE.getmActionType())) {
+ //udp render
+ if (udpRenderImageMsg == null) {
+ udpRenderImageMsg = new UdpRenderImageMessage();
+ }
+ return udpRenderImageMsg;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_MSG_WARNING_TYPE.getmActionType())) {
+ //ws 报警消息
+ if (wsWarnMessage == null) {
+ wsWarnMessage = new WsWarnMessage();
+ }
+ return wsWarnMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_MSG_IMAGE_SIZE_TYPE.getmActionType())) {
+ //ws 报警消息
+ if (wsImageSizeMessage == null) {
+ wsImageSizeMessage = new WsImageSizeMessage();
+ }
+ return wsImageSizeMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_CAR_STATE_TYPE.getmActionType())) {
+ //udp 车辆消息
+ if (udpCarStateMessage == null) {
+ udpCarStateMessage = new UdpCarStateMessage();
+ }
+ return udpCarStateMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_UDP_LIGHT_STATE_TYPE.getmActionType())) {
+ //udp 红绿灯状态
+ if (udpLightStateMessage == null) {
+ udpLightStateMessage = new UdpLightStateMessage();
+ }
+ return udpLightStateMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_OBSTACLES_MESSAGE_TYPE.getmActionType())) {
+ //udp 周边物体的状态
+ if (udpObstaclesMessage == null) {
+ udpObstaclesMessage = new UdpObstaclesMessage();
+ }
+ return udpObstaclesMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_LANES_MESSAGE_TYPE.getmActionType())) {
+ // 车道线渲染
+ if (lanesMessage == null) {
+ lanesMessage = new UdpLanesMessage();
+ }
+ return lanesMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_AUTOPILOT_STATUE.getmActionType())) {
+ //ws 自动驾驶状态
+ if (autopilotStatusMessage == null) {
+ autopilotStatusMessage = new WsAutopilotStatusMessage();
+ }
+ return autopilotStatusMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_AUTOPILOT_WAY_ARRIVE.getmActionType())) {
+ //自送驾驶到站
+ if (autopilotArriveMessage == null) {
+ autopilotArriveMessage = new WsAutopilotArriveMessage();
+ }
+ return autopilotArriveMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_AUTOPILOT_ROUTE.getmActionType())) {
+ //自动驾驶路径
+ if (autopilotRouteMessage == null) {
+ autopilotRouteMessage = new WsAutopilotRouteMessage();
+ }
+ return autopilotRouteMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_AUTOPILOT_SN_REQUEST.getmActionType())) {
+ //工控机获取sn
+ if (autopilotSNMessage == null) {
+ autopilotSNMessage = new WsAutopilotSNMessage();
+ }
+ return autopilotSNMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_AUTOPILOT_IDENTIFY.getmActionType())) {
+ //数据采集信息
+ if (autopilotIdentify == null) {
+ autopilotIdentify = new WsAutopilotIdentify();
+ }
+ return autopilotIdentify;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_AUTOPILOT_TRAJECTORY.getmActionType())) {
+ //局部轨迹
+ if (trajectoryMessage == null) {
+ trajectoryMessage = new WsAutopilotTrajectoryMessage();
+ }
+ return trajectoryMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_AUTOPILOT_CAR_CONFIG.getmActionType())) {
+ //dock config
+ if (autopilotConfig == null) {
+ autopilotConfig = new WsAutopilotConfig();
+ }
+ return autopilotConfig;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_AUTOPILOT_UPGRADE_STATUS.getmActionType())) {
+ //ws 工控机升级状态
+ if (autopilotUpgradeStatusMessage == null) {
+ autopilotUpgradeStatusMessage = new WsAutopilotUpgradeStatusMessage();
+ }
+ return autopilotUpgradeStatusMessage;
+ } else if (messageType.equals(ActionTypeReceive.ACTION_WS_AUTOPILOT_UPGRADE_PATCH_DOWNLOAD_STATUS.getmActionType())) {
+ //ws 工控机升级进度
+ if (autopilotUpgradePatchDownloadStatusMessage == null) {
+ autopilotUpgradePatchDownloadStatusMessage = new WsAutopilotUpgradePatchDownloadStatusMessage();
+ }
+ return autopilotUpgradePatchDownloadStatusMessage;
+ }
+
+ if (nuImplMessage == null) {
+ nuImplMessage = new NuImplMessage();
+ }
+ return nuImplMessage;
+ }
+
+ @Override
+ public IMsg createMessage(int messageCode) {
+ if (messageCode == 0) {
+ if (nuImplMessage == null) {
+ nuImplMessage = new NuImplMessage();
+ }
+ return nuImplMessage;
+ }
+ if (messageCode == ActionTypeReceive.ACTION_WS_MSG_RENDER_TYPE.getmActionCode()) {
+ //感知数据
+ if (udpRenderImageMsg == null) {
+ udpRenderImageMsg = new UdpRenderImageMessage();
+ }
+ return udpRenderImageMsg;
+ } else if (messageCode == ActionTypeReceive.ACTION_WS_CAR_STATE_TYPE.getmActionCode()) {
+ //定位数据
+ if (udpCarStateMessage == null) {
+ udpCarStateMessage = new UdpCarStateMessage();
+ }
+ return udpCarStateMessage;
+ } else if (messageCode == (ActionTypeReceive.ACTION_WS_AUTOPILOT_TRAJECTORY.getmActionCode())) {
+ //局部轨迹
+ if (trajectoryMessage == null) {
+ trajectoryMessage = new WsAutopilotTrajectoryMessage();
+ }
+ return trajectoryMessage;
+ } else if (messageCode == (ActionTypeReceive.ACTION_WS_AUTOPILOT_ROUTES.getmActionCode())) {
+ //轨迹列表
+
+ } else if (messageCode == (ActionTypeReceive.ACTION_WS_AUTOPILOT_GUARDIAN.getmActionCode())) {
+ //监控信息
+ if (guardianMessage == null) {
+ guardianMessage = new WsAutopilotGuardian();
+ }
+ return guardianMessage;
+ }
+ if (nuImplMessage == null) {
+ nuImplMessage = new NuImplMessage();
+ }
+ return nuImplMessage;
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/NuImplMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/NuImplMessage.java
new file mode 100644
index 0000000000..31e816b59c
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/NuImplMessage.java
@@ -0,0 +1,23 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.queue.UdpMsgModel;
+
+/**
+ * @author nie yunlong
+ * @des 空实现防止空指针
+ * @date 2020/3/12
+ */
+public class NuImplMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpCarStateMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpCarStateMessage.java
new file mode 100644
index 0000000000..cc9c6b661b
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpCarStateMessage.java
@@ -0,0 +1,72 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.CarStateInfo;
+import com.zhidao.support.adas.high.common.BaseTimeUtils;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+
+import java.util.Date;
+
+import mogo.status.CarStatus;
+
+/**
+ * @author nie yunlong
+ * @des udp 车辆状态
+ * @date 2020/3/12
+ */
+public class UdpCarStateMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ CupidLogUtils.w("CarStateData", "===>carStateInfo" + adasListener);
+ CarStateInfo carStateInfo = gson.fromJson(msg, CarStateInfo.class);
+// String satelliteTime = carStateInfo.getValues().getSatelliteTime();
+// long systemTime = System.currentTimeMillis();
+// Date date = BaseTimeUtils.localToUTC(String.valueOf(System.currentTimeMillis()));
+// long time = date.getTime();
+// long l = Long.parseLong(satelliteTime)-time;
+// CupidLogUtils.w("CarStateData", "carStateInfo2 pad system time="+systemTime);
+// CupidLogUtils.w("CarStateData", "carStateInfo2 pad utc time=" + time);
+// CupidLogUtils.w("CarStateData", "carStateInfo2 gkj utc time=" + satelliteTime);
+// CupidLogUtils.w("CarStateData", "carStateInfo2 time difference=" + l);
+ if (adasListener != null) {
+ adasListener.onCarStateData(carStateInfo);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+ try {
+ CarStatus.Status status = CarStatus.Status.parseFrom(msg);
+ if (status != null) {
+ CarStateInfo carStateInfo = new CarStateInfo();
+ carStateInfo.setAction("state");
+ CarStateInfo.ValuesBean values = new CarStateInfo.ValuesBean();
+ values.setLon(status.getLon());
+ values.setLat(status.getLat());
+ values.setAlt(status.getAlt());
+ values.setHeading(status.getHeading());
+ values.setAcceleration(status.getAcceleration());
+ values.setYaw_rate(status.getYawRate());
+ values.setGnss_speed(status.getGnssSpeed());
+ values.setVehicle_speed(status.getVehicleSpeed());
+ values.setSatelliteTime(status.getSatelliteTime());
+ values.setSystemTime(status.getSystemTime());
+ values.setTurn_light(status.getTurnLight());
+ values.setFlash_light(status.getFlashLight());
+ values.setBrake_light(status.getBrakeLight());
+ values.setFrame_num(status.getFrameNum());
+ carStateInfo.setValues(values);
+ if (adasListener != null) {
+ adasListener.onCarStateData(carStateInfo);
+ CupidLogUtils.w("UdpCarStateMessage", "" + carStateInfo.toString());
+ }
+ }
+ } catch (InvalidProtocolBufferException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpLanesMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpLanesMessage.java
new file mode 100644
index 0000000000..16cea5dc1d
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpLanesMessage.java
@@ -0,0 +1,28 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.CarLaneInfo;
+import com.zhidao.support.adas.high.queue.UdpMsgModel;
+
+/**
+ * @author nie yunlong
+ * @des udp 车道线渲染
+ * @date 2020/3/12
+ */
+public class UdpLanesMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ //udp 车道线渲染
+ CarLaneInfo carLaneInfo = gson.fromJson(msg, CarLaneInfo.class);
+ if (adasListener != null) {
+ adasListener.onCarLaneInfo(carLaneInfo);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpLightStateMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpLightStateMessage.java
new file mode 100644
index 0000000000..d77597908e
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpLightStateMessage.java
@@ -0,0 +1,29 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.CarStateInfo;
+import com.zhidao.support.adas.high.bean.LightStatueInfo;
+import com.zhidao.support.adas.high.queue.UdpMsgModel;
+
+/**
+ * @author nie yunlong
+ * @des udp 红绿灯状态
+ * @date 2020/3/12
+ */
+public class UdpLightStateMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ //udp 红绿灯状态
+ LightStatueInfo lightStatueInfo = gson.fromJson(msg, LightStatueInfo.class);
+ if (adasListener != null) {
+ adasListener.onLightStateData(lightStatueInfo);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpObstaclesMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpObstaclesMessage.java
new file mode 100644
index 0000000000..5bf41edbcc
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpObstaclesMessage.java
@@ -0,0 +1,29 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.LightStatueInfo;
+import com.zhidao.support.adas.high.bean.ObstaclesInfo;
+import com.zhidao.support.adas.high.queue.UdpMsgModel;
+
+/**
+ * @author nie yunlong
+ * @des udp 周边物体渲染
+ * @date 2020/3/12
+ */
+public class UdpObstaclesMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ //udp 周边物体渲染
+ ObstaclesInfo obstaclesInfo = gson.fromJson(msg, ObstaclesInfo.class);
+ if (adasListener != null) {
+ adasListener.onObstaclesInfo(obstaclesInfo);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpRenderImageMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpRenderImageMessage.java
new file mode 100644
index 0000000000..84be2140d4
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/UdpRenderImageMessage.java
@@ -0,0 +1,101 @@
+package com.zhidao.support.adas.high.msg;
+
+import android.text.TextUtils;
+
+import com.google.gson.Gson;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.RectInfo;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+
+import java.util.ArrayList;
+
+import adas.Adas;
+
+/**
+ * @author nie yunlong
+ * @des udp渲染
+ * @date 2020/3/12
+ */
+public class UdpRenderImageMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ //渲染图像流
+ RectInfo rectInfo = gson.fromJson(msg, RectInfo.class);
+ CupidLogUtils.e("UdpRenderImageMessage--->json:num = " + rectInfo.getModels().size());
+ if (adasListener != null) {
+ adasListener.onRectData(rectInfo);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+ Adas.ViwesMsg viewMsg = null;
+ try {
+ viewMsg = Adas.ViwesMsg.parseFrom(msg);
+ } catch (InvalidProtocolBufferException e) {
+ CupidLogUtils.e("UdpRenderImageMessage--->protoBuf Exception:" + e.toString());
+ e.printStackTrace();
+ }
+ if (viewMsg != null) {
+ if (TextUtils.equals(viewMsg.getAction(), "view")) {
+ RectInfo rectInfo = new RectInfo();
+ rectInfo.setAction(viewMsg.getAction());
+ ArrayList rectBeans = new ArrayList<>();
+ for (int i = 0; i < viewMsg.getModelsList().size(); i++) {
+ RectInfo.RectBean rectBean = new RectInfo.RectBean();
+ rectBean.setYt(viewMsg.getModels(i).getYt());
+ rectBean.setYb(viewMsg.getModels(i).getYb());
+ rectBean.setXr(viewMsg.getModels(i).getXr());
+ rectBean.setXl(viewMsg.getModels(i).getXl());
+ rectBean.setDistance_x(viewMsg.getModels(i).getDistanceX());
+ rectBean.setDistance_y(viewMsg.getModels(i).getDistanceY());
+ rectBean.setType(viewMsg.getModels(i).getType());
+ rectBean.setLat(viewMsg.getModels(i).getLat());
+ rectBean.setLon(viewMsg.getModels(i).getLon());
+ rectBean.setHeading(viewMsg.getModels(i).getHeading());
+ rectBean.setSystemTime(viewMsg.getModels(i).getSystemTime());
+ rectBean.setSatelliteTime(viewMsg.getModels(i).getSatelliteTime());
+ rectBean.setAlt(viewMsg.getModels(i).getAlt());
+ rectBean.setCarId(viewMsg.getModels(i).getCarId());
+ rectBean.setUuid(viewMsg.getModels(i).getUuid());
+ rectBean.setColor(viewMsg.getModels(i).getColor());
+ rectBean.setSpeed(viewMsg.getModels(i).getSpeed());
+ rectBean.setDrawlevel(viewMsg.getModels(i).getDrawlevel());
+ rectBean.setLength(viewMsg.getModels(i).getLength());
+ rectBean.setWidth(viewMsg.getModels(i).getWidth());
+ rectBean.setHeight(viewMsg.getModels(i).getHeight());
+ rectBean.setDriverTime(viewMsg.getModels(i).getDriverTime());
+// if (viewMsg.getModels(i).getDriverTime()!=null){
+// String s16 = conversionTime(viewMsg.getModels(i).getDriverTime());
+// if (s16!=null){
+// CupidLogUtils.e("UdpRenderImageMessage--->time===>s16=" + s16);
+// String s13 = s16.substring(0, 13);
+// CupidLogUtils.e("UdpRenderImageMessage--->time===>s13=" + s13);
+// rectBean.setDriverTime(s13);
+// }else {
+// rectBean.setDriverTime(viewMsg.getModels(i).getDriverTime());
+// }
+// }
+ rectBeans.add(rectBean);
+ }
+ rectInfo.setModels(rectBeans);
+ if (adasListener != null) {
+ adasListener.onRectData(rectInfo);
+ CupidLogUtils.e("UdpRenderImageMessage--->protoBuf===>:rectInfo = " + rectInfo.toString());
+ }
+ }
+ }
+ }
+
+ public String conversionTime(String str) {
+ StringBuffer stringBuffer = new StringBuffer("");
+ for (int i = 0; i < str.length(); i++) {
+ if (str.charAt(i) != '.') {
+ stringBuffer.append(str.charAt(i));
+ }
+ }
+ return stringBuffer.toString();
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotArriveMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotArriveMessage.java
new file mode 100644
index 0000000000..bb45a115a6
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotArriveMessage.java
@@ -0,0 +1,29 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.AutopilotStatus;
+import com.zhidao.support.adas.high.bean.AutopilotWayArrive;
+import com.zhidao.support.adas.high.queue.UdpMsgModel;
+
+/**
+ * @author nie yunlong
+ * @des ws自动驾驶到站
+ * @date 2020/3/12
+ */
+public class WsAutopilotArriveMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ //ws 自动驾驶状态
+ AutopilotWayArrive autopilotWayArrive = gson.fromJson(msg, AutopilotWayArrive.class);
+ if (adasListener != null) {
+ adasListener.autopilotArrive(autopilotWayArrive);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotConfig.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotConfig.java
new file mode 100644
index 0000000000..1046cebaf1
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotConfig.java
@@ -0,0 +1,34 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.AdasConfig;
+import com.zhidao.support.adas.high.bean.AutopilotConfig;
+import com.zhidao.support.adas.high.bean.guardian.AutopilotGuardianInfo;
+import com.zhidao.support.adas.high.common.AppPreferenceHelper;
+import com.zhidao.support.adas.high.common.Constants;
+import com.zhidao.support.adas.high.common.MgContextUtils;
+
+/**
+ * @author song kenan
+ * @des
+ * @date 2021/11/17
+ */
+public class WsAutopilotConfig extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ AutopilotConfig autopilotConfig = gson.fromJson(msg, AutopilotConfig.class);
+ AutopilotConfig.ResultBean result = autopilotConfig.getResult();
+ if (result!=null){
+ String dockVersion = result.getDock_version();
+ AppPreferenceHelper.getInstance(MgContextUtils.getContext()).saveDockConfig(dockVersion);
+ }
+
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotGuardian.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotGuardian.java
new file mode 100644
index 0000000000..2dc502c8bc
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotGuardian.java
@@ -0,0 +1,51 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.google.protobuf.ByteString;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.util.JsonFormat;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.guardian.AutopilotGuardianInfo;
+import com.zhidao.support.adas.high.bean.guardian.GuardianItemsName;
+import com.zhidao.support.adas.high.bean.guardian.GuardianModule;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+
+import java.util.ArrayList;
+
+import mogo.guardian.MogoGuardian;
+
+/**
+ * @author song kenan
+ * @des
+ * @date 2021/7/7
+ */
+public class WsAutopilotGuardian extends MyAbstractMessageHandler{
+ private final JsonFormat.Printer printer = JsonFormat.printer();
+ private AutopilotGuardianInfo info;
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+// CupidLogUtils.w("WsAutopilotGuardian===>"+msg);
+ AutopilotGuardianInfo autopilotGuardian = gson.fromJson(msg, AutopilotGuardianInfo.class);
+ if (adasListener != null) {
+ adasListener.onAutopilotGuardian(autopilotGuardian);
+ }
+
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+ try {
+ MogoGuardian.GuardianProto proto = MogoGuardian.GuardianProto.parseFrom(msg);
+ String print = printer.print(proto);
+ info = gson.fromJson(print, AutopilotGuardianInfo.class);
+ if (adasListener != null) {
+ adasListener.onAutopilotGuardian(info);
+ CupidLogUtils.w("WsAutopilotGuardian===>"+ info.toString());
+
+ }
+ } catch (InvalidProtocolBufferException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotIdentify.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotIdentify.java
new file mode 100644
index 0000000000..4fb08036e6
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotIdentify.java
@@ -0,0 +1,75 @@
+package com.zhidao.support.adas.high.msg;
+
+import android.content.Intent;
+import android.os.Handler;
+import android.os.Message;
+import android.text.TextUtils;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.record.AutopilotIdentifyInfo;
+import com.zhidao.support.adas.high.bean.record.AutopilotRecordResult;
+import com.zhidao.support.adas.high.common.AppPreferenceHelper;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.common.HandlerThreadManager;
+import com.zhidao.support.adas.high.common.MgContextUtils;
+import com.zhidao.support.recorder.RecordDataManager;
+import com.zhidao.support.recorder.activity.LoginSftpActivity;
+
+/**
+ * @author song kenan
+ * @des
+ * @date 2021/7/7
+ */
+public class WsAutopilotIdentify extends MyAbstractMessageHandler {
+ private static final int SHOW_RECORDER = 0x01;
+ private boolean isConnect = false;
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ CupidLogUtils.w("WsAutopilotIdentify===>" + msg);
+ AutopilotIdentifyInfo info = gson.fromJson(msg, AutopilotIdentifyInfo.class);
+ AutopilotIdentifyInfo.Result result = info.getResult();
+ AutopilotRecordResult panel = result.getPanel();
+ if (adasListener!=null){
+ adasListener.onAutopilotRecord(panel);
+ }
+// if (panel!=null){
+// int stat = panel.getStat();
+// if (stat==1){
+// final String user = result.getUser();
+// final String passwd = result.getPasswd();
+// String timestamp = panel.getTimestamp();
+// final String udpClientAddress = AppPreferenceHelper.getInstance(MgContextUtils.getContext()).getUdpClientAddress();
+// if (TextUtils.isEmpty(user) || TextUtils.isEmpty(passwd) || TextUtils.isEmpty(udpClientAddress)) {
+// CupidLogUtils.w("ftp message error");
+// return;
+// }
+// RecordDataManager.getInstance().init(MgContextUtils.getContext(),timestamp , udpClientAddress, 22, user, passwd);
+// isConnect = RecordDataManager.getInstance().connectSftp();
+// handler.removeMessages(SHOW_RECORDER);
+// handler.sendEmptyMessage(SHOW_RECORDER);
+// }
+// }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+
+ private Handler handler = new Handler(HandlerThreadManager.getMainHandler().getLooper()) {
+ @Override
+ public void handleMessage(Message msg) {
+ super.handleMessage(msg);
+ if (isConnect) {
+ RecordDataManager.getInstance().record();
+ } else {
+ Intent intent = new Intent(MgContextUtils.getContext(), LoginSftpActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ MgContextUtils.getContext().startActivity(intent);
+ }
+ }
+ };
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotRouteMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotRouteMessage.java
new file mode 100644
index 0000000000..fa6398c9a0
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotRouteMessage.java
@@ -0,0 +1,26 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.AutopilotRoute;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+
+/**
+ * 自动驾驶路径
+ */
+public class WsAutopilotRouteMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+// CupidLogUtils.w("WsAutopilotRouteMessage===>"+msg);
+ AutopilotRoute autopilotRoute = gson.fromJson(msg, AutopilotRoute.class);
+ if (adasListener != null) {
+ adasListener.onAutopilotRoute(autopilotRoute);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotRoutesMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotRoutesMessage.java
new file mode 100644
index 0000000000..c816039bb7
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotRoutesMessage.java
@@ -0,0 +1,29 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.AutopilotTrajectory;
+import com.zhidao.support.adas.high.bean.TrajectoryInfo;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import mogo.trajectory.TrajectoryOuterClass;
+
+/**
+ * 自动驾驶路径
+ */
+public class WsAutopilotRoutesMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotSNMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotSNMessage.java
new file mode 100644
index 0000000000..dbb4e7b0fa
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotSNMessage.java
@@ -0,0 +1,27 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.AutopilotRoute;
+import com.zhidao.support.adas.high.bean.AutopilotSnRequest;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+
+/**
+ * 自动驾驶路径
+ */
+public class WsAutopilotSNMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+// CupidLogUtils.w("WsAutopilotSNMessage===>"+msg);
+ AutopilotSnRequest autopilotSn = gson.fromJson(msg, AutopilotSnRequest.class);
+ if (adasListener != null) {
+ adasListener.onAutopilotSNRequest();
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotStatusMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotStatusMessage.java
new file mode 100644
index 0000000000..5f384202d6
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotStatusMessage.java
@@ -0,0 +1,28 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.AutopilotStatus;
+import com.zhidao.support.adas.high.queue.UdpMsgModel;
+
+/**
+ * @author nie yunlong
+ * @des ws自动驾驶状态
+ * @date 2020/3/12
+ */
+public class WsAutopilotStatusMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ //ws 自动驾驶状态
+ AutopilotStatus autopilotStatus = gson.fromJson(msg, AutopilotStatus.class);
+ if (adasListener != null) {
+ adasListener.autopilotStatus(autopilotStatus);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotTrajectoryMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotTrajectoryMessage.java
new file mode 100644
index 0000000000..cc20edd9eb
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotTrajectoryMessage.java
@@ -0,0 +1,60 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.AutopilotRoute;
+import com.zhidao.support.adas.high.bean.AutopilotTrajectory;
+import com.zhidao.support.adas.high.bean.RectInfo;
+import com.zhidao.support.adas.high.bean.TrajectoryInfo;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import mogo.trajectory.TrajectoryOuterClass;
+
+/**
+ * 自动驾驶路径
+ */
+public class WsAutopilotTrajectoryMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ CupidLogUtils.w("WsAutopilotTrajectoryMessage===>"+msg);
+ AutopilotTrajectory trajectory = gson.fromJson(msg, AutopilotTrajectory.class);
+ if (adasListener != null) {
+ adasListener.onAutopilotTrajectory(trajectory.getModels());
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+ try {
+ TrajectoryOuterClass.Trajectory trajectory = TrajectoryOuterClass.Trajectory.parseFrom(msg);
+ List pointsList = trajectory.getPointsList();
+ ArrayList trajectoryInfos = new ArrayList<>();
+ for (int i = 0;i" + trajectoryInfos.toString());
+ }
+ } catch (InvalidProtocolBufferException e) {
+ e.printStackTrace();
+ }
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotUpgradePatchDownloadStatusMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotUpgradePatchDownloadStatusMessage.java
new file mode 100644
index 0000000000..5070d77b91
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotUpgradePatchDownloadStatusMessage.java
@@ -0,0 +1,25 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.IPCUpgradePatchDownloadStatusInfo;
+
+/**
+ * @des 工控机升级包下载状态
+ * @date 2020/3/12
+ */
+public class WsAutopilotUpgradePatchDownloadStatusMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ IPCUpgradePatchDownloadStatusInfo autopilotStatus = gson.fromJson(msg, IPCUpgradePatchDownloadStatusInfo.class);
+ if (adasListener != null) {
+ adasListener.onUpgradePatchDownloadStatus(autopilotStatus);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotUpgradeStatusMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotUpgradeStatusMessage.java
new file mode 100644
index 0000000000..c4dc8565eb
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsAutopilotUpgradeStatusMessage.java
@@ -0,0 +1,25 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.IPCUpgradeStateInfo;
+
+/**
+ * @des 工控机升级状态
+ * @date 2020/3/12
+ */
+public class WsAutopilotUpgradeStatusMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ IPCUpgradeStateInfo autopilotStatus = gson.fromJson(msg, IPCUpgradeStateInfo.class);
+ if (adasListener != null) {
+ adasListener.onUpgradeStateInfo(autopilotStatus);
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsImageSizeMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsImageSizeMessage.java
new file mode 100644
index 0000000000..994c4384fe
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsImageSizeMessage.java
@@ -0,0 +1,40 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.queue.UdpMsgModel;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * @author nie yunlong
+ * @des 图像大小
+ * @date 2020/3/12
+ */
+public class WsImageSizeMessage extends MyAbstractMessageHandler {
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ JSONObject jsonObject = null;
+ try {
+ jsonObject = new JSONObject(msg);
+ JSONObject videoInfo = jsonObject.optJSONObject("values");
+ if (videoInfo != null) {
+ int width = videoInfo.optInt("width");
+ int height = videoInfo.optInt("height");
+ CupidLogUtils.e("--->width" + width + ",height" + height);
+ if (adasListener != null) {
+ adasListener.onVideoSize(width, height);
+ }
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsWarnMessage.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsWarnMessage.java
new file mode 100644
index 0000000000..373c5b9ac1
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/msg/WsWarnMessage.java
@@ -0,0 +1,43 @@
+package com.zhidao.support.adas.high.msg;
+
+import com.google.gson.Gson;
+import com.zhidao.support.adas.high.OnAdasListener;
+import com.zhidao.support.adas.high.bean.WarnMessageInfo;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.queue.UdpMsgModel;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * @author nie yunlong
+ * @des 报警消息
+ * @date 2020/3/12
+ */
+public class WsWarnMessage extends MyAbstractMessageHandler {
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, String msg) {
+ try {
+ JSONObject jsonObject = new JSONObject(msg);
+ JSONObject warning = jsonObject.optJSONObject("values");
+ if (warning != null) {
+ String type = warning.optString("type");
+ String content = warning.optString("content");
+ String value = warning.optString("value");
+ String level = warning.optString("level");
+ CupidLogUtils.e(String.format("--->type:%s, content:%s, value:%s, level:%s", type, content, value, level));
+ if (adasListener != null) {
+ adasListener.onWarnMessage(new WarnMessageInfo(type, content, value, level));
+ }
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void handlerMsg(Gson gson, OnAdasListener adasListener, byte[] msg) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/PublicQueue.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/PublicQueue.java
new file mode 100644
index 0000000000..60476a7d42
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/PublicQueue.java
@@ -0,0 +1,96 @@
+package com.zhidao.support.adas.high.queue;
+
+import java.util.Iterator;
+import java.util.concurrent.BlockingDeque;
+import java.util.concurrent.LinkedBlockingDeque;
+
+/**
+ * 公共缓存队列
+ * 只做两件事:(1)生产;(2)消费
+ */
+public class PublicQueue {
+
+ private BlockingDeque blockingDeque = new LinkedBlockingDeque<>();//缓冲区
+
+ public static PublicQueue publicQueue;
+
+ public static synchronized PublicQueue getInstance() {
+ if (publicQueue == null) {
+ publicQueue = new PublicQueue();
+ }
+ return publicQueue;
+ }
+
+ public void add(T msg) {
+
+ try {
+ blockingDeque.put(msg);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 先移除最新的然后添加最新的
+ *
+ * @param msg
+ */
+ public void removeLastPutLast(T msg) {
+
+ try {
+ //移除最新的 然后把最新的添加到队尾
+ blockingDeque.takeFirst();
+ blockingDeque.put(msg);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public T remove() {
+
+ T t = null;
+ try {
+ t = blockingDeque.take();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ return t;
+ }
+
+ /**
+ * 清空所有数据
+ */
+ public void clear(){
+ if (blockingDeque!=null){
+ blockingDeque.clear();
+ }
+ }
+ /**
+ * 获取个数
+ *
+ * @return
+ */
+ public int getSize() {
+ return blockingDeque.size();
+ }
+
+ /**
+ * 移除最后一个
+ */
+ public void removeLast() {
+ blockingDeque.removeLast();
+ }
+
+
+ public String iteratorData(){
+ StringBuilder stringBuilder=new StringBuilder();
+ Iterator iterater = blockingDeque.iterator();
+ while (iterater.hasNext()){
+ T data = iterater.next();
+ stringBuilder.append(","+data);
+ }
+ return stringBuilder.toString();
+ }
+}
\ No newline at end of file
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/UdpMsgModel.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/UdpMsgModel.java
new file mode 100644
index 0000000000..9763e0dbb6
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/UdpMsgModel.java
@@ -0,0 +1,62 @@
+package com.zhidao.support.adas.high.queue;
+
+import okio.ByteString;
+
+/**
+ * author nieyunlong
+ *
+ * @des
+ * @date 2021/3/10
+ */
+public class UdpMsgModel {
+
+ /**
+ * 发送数据类型
+ * 1 json,2 pb
+ */
+ private int type;
+
+ /**
+ * 当前接收到的时间
+ */
+ private long receiverDataTimeUdp;
+
+ /**
+ * udp 数据
+ */
+ private String content;
+
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public long getReceiverDataTimeUdp() {
+ return receiverDataTimeUdp;
+ }
+
+ public void setReceiverDataTimeUdp(long receiverDataTimeUdp) {
+ this.receiverDataTimeUdp = receiverDataTimeUdp;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+
+ @Override
+ public String toString() {
+ return "UdpMsgModel{" +
+ "receiverDataTimeUdp=" + receiverDataTimeUdp +
+ ", content='" + content + '\'' +
+ ", type='" + type + '\'' +
+ '}';
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/UdpQueueManager.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/UdpQueueManager.java
new file mode 100644
index 0000000000..c4ca870879
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/UdpQueueManager.java
@@ -0,0 +1,101 @@
+package com.zhidao.support.adas.high.queue;
+
+import com.zhidao.support.adas.high.AdasChannel;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.thread.QueuedWork;
+import com.zhidao.support.adas.high.thread.callback.NormalCallback;
+
+import java.util.concurrent.Future;
+
+/**
+ * author : peng hongqiu
+ * e-mail : penghongqiu@163.com
+ * date : 2020/12/22 11:46
+ * desc :
+ * version:
+ */
+public class UdpQueueManager {
+
+ private static UdpQueueManager sInstance = new UdpQueueManager();
+ //存储dup发送的数据
+ PublicQueue publicQueue = new PublicQueue<>();
+ //实时消费
+ private boolean runConsumerFlag = true;
+ private AdasChannel adasChannel;
+ private RealTimeConsumerFrameMission realTimeConsumerFrameMission;
+ private Future mFutureTask;
+
+ public static UdpQueueManager getInstance() {
+ return sInstance;
+ }
+
+ private UdpQueueManager() {
+
+ }
+
+
+ public void addQueueData(String data) {
+ publicQueue.add(data);
+ }
+
+ public void registerAdasChannel(AdasChannel adasChannel) {
+ this.adasChannel = adasChannel;
+ }
+
+
+ /**
+ * 实时消费帧 消费完一帧 立马取最新一帧
+ */
+ private class RealTimeConsumerFrameMission extends NormalCallback {
+ //消费者
+ private PublicQueue mPublicQueue;
+
+ public RealTimeConsumerFrameMission(PublicQueue publicQueue) {
+ mPublicQueue = publicQueue;
+ }
+
+ @Override
+ public String doInBackground() {
+ try {
+ while (runConsumerFlag) {
+ String data = mPublicQueue.remove();
+ if (adasChannel != null) {
+ adasChannel.udpDataManage(data);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return super.doInBackground();
+ }
+
+ public void stop() {
+ runConsumerFlag = false;
+ }
+ }
+
+ public synchronized void initDector() {
+ CupidLogUtils.w("===>UdpQueueManager initDector");
+ release();
+ runConsumerFlag = true;
+ if (realTimeConsumerFrameMission == null){
+ realTimeConsumerFrameMission = new RealTimeConsumerFrameMission(publicQueue);
+ }
+ mFutureTask = QueuedWork.submit(null, realTimeConsumerFrameMission);
+ }
+
+ public void release() {
+ publicQueue.clear();
+ stopCallBack();
+ }
+
+ private void stopCallBack() {
+ if (realTimeConsumerFrameMission != null) {
+ realTimeConsumerFrameMission.stop();
+ realTimeConsumerFrameMission = null;
+ }
+ if (mFutureTask != null) {
+ mFutureTask.cancel(true);
+ }
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/WSByteQueueManager.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/WSByteQueueManager.java
new file mode 100644
index 0000000000..b218efb98b
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/WSByteQueueManager.java
@@ -0,0 +1,107 @@
+package com.zhidao.support.adas.high.queue;
+
+
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.socket.FpgaSocket;
+import com.zhidao.support.adas.high.thread.QueuedWork;
+import com.zhidao.support.adas.high.thread.callback.NormalCallback;
+
+import java.util.concurrent.Future;
+
+import okio.ByteString;
+
+/**
+ * author : peng hongqiu
+ * e-mail : penghongqiu@163.com
+ * date : 2020/12/22 11:46
+ * desc :
+ * version:
+ */
+public class WSByteQueueManager {
+
+ private static WSByteQueueManager sInstance = new WSByteQueueManager();
+ //存储dup/websocket发送的数据
+ PublicQueue publicQueue = new PublicQueue<>();
+ private RealTimeConsumerFrameMission realTimeConsumerFrameMission;
+
+ private Future mFutureTask;
+
+ private FpgaSocket.IWebSocketConnectListener webSocketConnectListener;
+
+ public static WSByteQueueManager getInstance() {
+ return sInstance;
+ }
+
+ private WSByteQueueManager() {
+
+ }
+
+
+ public void addQueueData(ByteString data) {
+// CupidLogUtils.w("====>生产者几个数据" + publicQueue.getSize() + ",list" + publicQueue.iteratorData());
+ publicQueue.add(data);
+ }
+
+ public void registerWebSocketListener(FpgaSocket.IWebSocketConnectListener webSocketConnectListener) {
+ this.webSocketConnectListener = webSocketConnectListener;
+ }
+
+
+ /**
+ * 实时消费帧 消费完一帧 立马取最新一帧
+ */
+ private class RealTimeConsumerFrameMission extends NormalCallback{
+ //消费者
+ private PublicQueue mPublicQueue;
+ //实时消费
+ private boolean runConsumerFlag = true;
+ public RealTimeConsumerFrameMission(PublicQueue publicQueue) {
+ mPublicQueue = publicQueue;
+ }
+ public ByteString doInBackground() {
+ try {
+ while (runConsumerFlag) {
+// CupidLogUtils.w("===>消费者==>ConsumerDataMission");
+ ByteString data = mPublicQueue.remove();
+// CupidLogUtils.w("===>socket消费者" + data + ",内容个数" + mPublicQueue.getSize() + "\n所有数据" + mPublicQueue.iteratorData());
+ if (webSocketConnectListener != null) {
+ webSocketConnectListener.onMessage(data);
+ }
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return super.doInBackground();
+ }
+
+ public void stop() {
+ runConsumerFlag = false;
+ }
+
+ }
+
+
+ public synchronized void initDector() {
+ release();
+ realTimeConsumerFrameMission = new RealTimeConsumerFrameMission(publicQueue);
+ mFutureTask = QueuedWork.submit(null,realTimeConsumerFrameMission);
+
+ }
+
+ public void release() {
+ publicQueue.clear();
+ stopCallBack();
+ }
+
+ private void stopCallBack() {
+ if (realTimeConsumerFrameMission != null) {
+ realTimeConsumerFrameMission.stop();
+ realTimeConsumerFrameMission = null;
+ }
+ if (mFutureTask != null) {
+ mFutureTask.cancel(true);
+ }
+ }
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/WebSocketQueueManager.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/WebSocketQueueManager.java
new file mode 100644
index 0000000000..b7d8c864f4
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/queue/WebSocketQueueManager.java
@@ -0,0 +1,105 @@
+package com.zhidao.support.adas.high.queue;
+
+
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.socket.FpgaSocket;
+import com.zhidao.support.adas.high.thread.QueuedWork;
+import com.zhidao.support.adas.high.thread.callback.NormalCallback;
+
+import java.util.concurrent.Future;
+
+/**
+ * author : peng hongqiu
+ * e-mail : penghongqiu@163.com
+ * date : 2020/12/22 11:46
+ * desc :
+ * version:
+ */
+public class WebSocketQueueManager {
+
+ private static WebSocketQueueManager sInstance = new WebSocketQueueManager();
+ //存储dup/websocket发送的数据
+ PublicQueue publicQueue = new PublicQueue<>();
+ private RealTimeConsumerFrameMission realTimeConsumerFrameMission;
+
+ private Future mFutureTask;
+
+ private FpgaSocket.IWebSocketConnectListener webSocketConnectListener;
+
+ public static WebSocketQueueManager getInstance() {
+ return sInstance;
+ }
+
+ private WebSocketQueueManager() {
+
+ }
+
+
+ public void addQueueData(String data) {
+// CupidLogUtils.w("====>生产者几个数据" + publicQueue.getSize() + ",list" + publicQueue.iteratorData());
+ publicQueue.add(data);
+ }
+
+ public void registerWebSocketListener(FpgaSocket.IWebSocketConnectListener webSocketConnectListener) {
+ this.webSocketConnectListener = webSocketConnectListener;
+ }
+
+
+ /**
+ * 实时消费帧 消费完一帧 立马取最新一帧
+ */
+ private class RealTimeConsumerFrameMission extends NormalCallback{
+ //消费者
+ private PublicQueue mPublicQueue;
+ //实时消费
+ private boolean runConsumerFlag = true;
+ public RealTimeConsumerFrameMission(PublicQueue publicQueue) {
+ mPublicQueue = publicQueue;
+ }
+ public String doInBackground() {
+ try {
+ while (runConsumerFlag) {
+// CupidLogUtils.w("===>消费者==>ConsumerDataMission");
+ String data = mPublicQueue.remove();
+// CupidLogUtils.w("===>socket消费者" + data + ",内容个数" + mPublicQueue.getSize() + "\n所有数据" + mPublicQueue.iteratorData());
+ if (webSocketConnectListener != null) {
+ webSocketConnectListener.onMessage(data);
+ }
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return super.doInBackground();
+ }
+
+ public void stop() {
+ runConsumerFlag = false;
+ }
+
+ }
+
+
+ public synchronized void initDector() {
+ release();
+ realTimeConsumerFrameMission = new RealTimeConsumerFrameMission(publicQueue);
+ mFutureTask = QueuedWork.submit(null,realTimeConsumerFrameMission);
+
+ }
+
+ public void release() {
+ publicQueue.clear();
+ stopCallBack();
+ }
+
+ private void stopCallBack() {
+ if (realTimeConsumerFrameMission != null) {
+ realTimeConsumerFrameMission.stop();
+ realTimeConsumerFrameMission = null;
+ }
+ if (mFutureTask != null) {
+ mFutureTask.cancel(true);
+ }
+ }
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/FpgaSocket.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/FpgaSocket.java
new file mode 100644
index 0000000000..34052cb95e
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/FpgaSocket.java
@@ -0,0 +1,325 @@
+package com.zhidao.support.adas.high.socket;
+
+import android.graphics.Bitmap;
+import android.text.TextUtils;
+
+import com.google.gson.Gson;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.zhidao.support.adas.high.AdasChannel;
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.bean.FaceLoginResponse;
+import com.zhidao.support.adas.high.common.DigitalTrans;
+import com.zhidao.support.adas.high.common.RequestWsMsgType;
+import com.zhidao.support.adas.high.queue.WSByteQueueManager;
+import com.zhidao.support.adas.high.queue.WebSocketQueueManager;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.File;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import adas.Adas;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.WebSocket;
+import okhttp3.WebSocketListener;
+import okio.ByteString;
+
+import static com.zhidao.support.adas.high.common.Constants.WS_IP_HOST_HEAD;
+import static com.zhidao.support.adas.high.common.Constants.WS_PORT;
+
+/**
+ * @ProjectName: lib-adas-fpga
+ * @Package: com.zhidao.lib.adas.high
+ * @ClassName: FpgaSocket
+ * @Description: java类作用描述
+ * @Author: fenghl
+ * @CreateDate: 2020/2/7 13:36
+ * @UpdateUser: 更新者:
+ * @UpdateDate: 2020/2/7 13:36
+ * @UpdateRemark: 更新说明:
+ * @Version: 1.0
+ */
+public class FpgaSocket implements IWebSocket {
+ private OkHttpClient client;
+
+ private WebSocket mWebSocket;
+
+ private EchoWebSocketListener listener;
+
+ private Request request;
+
+ private OkHttpClient.Builder okBuilder;
+
+ private JSONObject jsonObject;
+ /**
+ * 是否是用户主动关闭socket
+ */
+ private boolean isUserCloseWebSocket = false;
+
+ public FpgaSocket() {
+ init();
+ }
+
+ private void init() {
+ if (listener == null) {
+ listener = new EchoWebSocketListener();
+ }
+ if (okBuilder == null) {
+ okBuilder = new OkHttpClient.Builder();
+ okBuilder.readTimeout(20, TimeUnit.SECONDS);
+ okBuilder.connectTimeout(20, TimeUnit.SECONDS);
+ }
+ if (client == null) {
+ client = okBuilder.build();
+ }
+ }
+
+ @Override
+ public void connectWebSocket(String address) {
+ String wsHost = WS_IP_HOST_HEAD + address + WS_PORT;
+ CupidLogUtils.e("--->connectWebSocket" + wsHost);
+ init();
+ if (client != null) {
+ request = new Request.Builder()
+ .url(wsHost)
+ .build();
+ client.newWebSocket(request, listener);
+ }
+ }
+
+ @Override
+ public void closeWebSocket() {
+ CupidLogUtils.e("===>closeWebSocket");
+ if (AdasChannel.isUseQueue){
+ WebSocketQueueManager.getInstance().release();
+ WSByteQueueManager.getInstance().release();
+ }
+ isUserCloseWebSocket = true;
+ listener = null;
+ jsonObject = null;
+ if (mWebSocket != null) {
+ boolean isClose = mWebSocket.close(1000, null);
+ CupidLogUtils.e("===>webSocket关闭了吗" + isClose);
+
+ mWebSocket.cancel();
+ mWebSocket = null;
+ }
+ client = null;
+ request = null;
+ listener = null;
+ }
+
+ @Override
+ public boolean sendDataWebSocket(String data) {
+ if (mWebSocket != null) {
+ boolean result = mWebSocket.send(data);
+ CupidLogUtils.e("FpgaSocket--->sendDataWebSocket--->String: " + data + ", result= " + result);
+ return result;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean sendDataWebSocket(ByteString data) {
+ if (mWebSocket != null) {
+ boolean result = mWebSocket.send(data);
+ CupidLogUtils.e("FpgaSocket--->sendDataWebSocket--->ByteString: " + data + ", result= " + result);
+ return result;
+ }
+ return false;
+ }
+
+ @Override
+ public void getConfigData(String appId, String userId) {
+ CupidLogUtils.e("FpgaSocket--->getConfigData appId: " + appId + ", userId:" + userId);
+ }
+
+ @Override
+ public void doConfigChanged(int type, String ip, List configInfos) {
+ CupidLogUtils.e("FpgaSocket--->doConfigChanged, type: " + type + " ip: " + ip + " configInfos:" + configInfos);
+ }
+
+ @Override
+ public void doConfigChanged(List configInfos) {
+ CupidLogUtils.e("FpgaSocket--->doConfigChanged, configInfos:" + configInfos);
+ JSONObject jsonObject = new JSONObject();
+ //上传配置信息
+ //位置信息 action是3
+ try {
+ jsonObject.put("action", RequestWsMsgType.MSG_SEND_UPLOAD_CONFIG.getMsgType());
+ jsonObject.put("config", new JSONArray(new Gson().toJson(configInfos)));
+ sendDataWebSocket(jsonObject.toString());
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void saveShotPic(Bitmap bitmap) {
+ CupidLogUtils.e("FpgaSocket--->saveShotPic");
+ }
+
+ @Override
+ public void getTouchImage(String url, double x, double y) {
+ CupidLogUtils.e("FpgaSocket--->getTouchImage, url: " + url + " ,x: " + x + " ,y: " + y);
+ }
+
+ @Override
+ public void doRecognizeImage(File file, String deviceId, String tag) {
+ CupidLogUtils.e("FpgaSocket--->doRecognizeImage");
+ }
+
+ @Override
+ public void getUserAchieveInfo(String userId) {
+ CupidLogUtils.e("FpgaSocket--->getUserAchieveInfo, userId:" + userId);
+ }
+
+ @Override
+ public void getNaviInfo(int type) {
+ CupidLogUtils.e("FpgaSocket--->getNaviInfo, type:" + type);
+ }
+
+ @Override
+ public void syncMedalDetailInfo(String userId, int action, String medalType) {
+ CupidLogUtils.e("FpgaSocket--->syncMedalDetailInfo");
+ }
+
+ @Override
+ public void getCarModelInfo(String s, int id) {
+ CupidLogUtils.e("FpgaSocket--->getCarModelInfo");
+ }
+
+ @Override
+ public void doUpdateCarInfo(String userId, String brandId, String brandName, String modelId, String modelName, String styleId, String styleName) {
+ CupidLogUtils.e("FpgaSocket--->doUpdateCarInfo");
+ }
+
+ @Override
+ public void getApkAndFireWareInfo(String deviceId, String userId, int apkVersionCode, int xvideoCppVersionCode, int appId) {
+ CupidLogUtils.e("FpgaSocket--->getApkAndFireWareInfo");
+ }
+
+ @Override
+ public void getFireWareBaseInfo(String baseUrl) {
+ CupidLogUtils.e("FpgaSocket--->getFireWareBaseInfo");
+ }
+
+ @Override
+ public void sendFirmWareUpdateInfo(String baseUrl, String json) {
+ CupidLogUtils.e("FpgaSocket--->sendFirmWareUpdateInfo");
+ }
+
+ @Override
+ public void startNavigate(String userId, String naviStartName, String naviEndName) {
+ CupidLogUtils.e("FpgaSocket--->startNavigate");
+ }
+
+ @Override
+ public void syncUserNavigateInfo(String navigateId, String longtitude, String latitude, String poId, String currentSpeed) {
+ CupidLogUtils.e("FpgaSocket--->syncUserNavigateInfo");
+ }
+
+ @Override
+ public void doVerticalLineConfigCompleted() {
+ CupidLogUtils.e("FpgaSocket--->doVerticalLineConfigCompleted");
+ }
+
+ @Override
+ public void doSyncCarSpaceInfo(String carLength, String carWidth, String carHeight) {
+ CupidLogUtils.e("FpgaSocket--->doSyncCarSpaceInfo");
+ }
+
+ private IWebSocketConnectListener mWebSocketConnectListener;
+
+ public interface IWebSocketConnectListener {
+ void onWebSocketConnectSuccess(WebSocket webSocket);
+
+ void onWebSocketConnectFailed(WebSocket webSocket,String t);
+
+ void onMessage(String message);
+
+ void onMessage(ByteString bytes) throws InvalidProtocolBufferException;
+ }
+
+ public void setWebSocketListener(IWebSocketConnectListener listener) {
+ mWebSocketConnectListener = listener;
+ }
+
+ public class EchoWebSocketListener extends WebSocketListener {
+ @Override
+ public void onOpen(WebSocket webSocket, Response response) {
+ super.onOpen(webSocket, response);
+ mWebSocket = webSocket;
+ CupidLogUtils.e("--->websocket response connect success");
+ mWebSocketConnectListener.onWebSocketConnectSuccess(webSocket);
+ }
+
+ @Override
+ public void onMessage(WebSocket webSocket, String text) {
+ super.onMessage(webSocket, text);
+ CupidLogUtils.e("--->websocket response connect text" + text);
+ if (TextUtils.isEmpty(text)) {
+ return;
+ }
+ if (AdasChannel.isUseQueue) {
+ WebSocketQueueManager.getInstance().addQueueData(text);
+ } else {
+ mWebSocketConnectListener.onMessage(text);
+ }
+ }
+
+
+ @Override
+ public void onMessage(WebSocket webSocket, ByteString bytes) {
+ super.onMessage(webSocket, bytes);
+ CupidLogUtils.e("--->websocket response connect byte" + bytes.hex());
+ if (bytes==null){
+ return;
+ }
+ if (AdasChannel.isUseQueue) {
+ WSByteQueueManager.getInstance().addQueueData(bytes);
+ } else {
+ try {
+ mWebSocketConnectListener.onMessage(bytes);
+ } catch (InvalidProtocolBufferException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ @Override
+ public void onClosing(WebSocket webSocket, int code, String reason) {
+ super.onClosing(webSocket, code, reason);
+ mWebSocket = null;
+ CupidLogUtils.e("--->websocket onClosing==> onClosing" + reason);
+ }
+
+ @Override
+ public void onClosed(WebSocket webSocket, int code, String reason) {
+ super.onClosed(webSocket, code, reason);
+ mWebSocket = null;
+ CupidLogUtils.e("--->websocket onClosed ==> " + reason);
+ mWebSocketConnectListener.onWebSocketConnectFailed(webSocket,reason);
+ }
+
+ @Override
+ public void onFailure(WebSocket webSocket, Throwable t, Response response) {
+ super.onFailure(webSocket, t, response);
+ mWebSocket = null;
+ CupidLogUtils.e("--->websocket onFailure ===>" + t.getMessage());
+ mWebSocketConnectListener.onWebSocketConnectFailed(webSocket,t.toString());
+
+ }
+ }
+
+ public WebSocket getWebSocket() {
+ return mWebSocket;
+ }
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/IWebSocket.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/IWebSocket.java
new file mode 100644
index 0000000000..4c38b96e6a
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/IWebSocket.java
@@ -0,0 +1,154 @@
+package com.zhidao.support.adas.high.socket;
+
+import android.graphics.Bitmap;
+
+import com.zhidao.support.adas.high.bean.FaceLoginResponse;
+
+import java.io.File;
+import java.util.List;
+
+import okio.ByteString;
+
+/**
+ * @ProjectName: lib-adas-fpga
+ * @Package: com.zhidao.lib.adas.high
+ * @ClassName: IWebSocket
+ * @Description: java类作用描述
+ * @Author: fenghl
+ * @CreateDate: 2020/2/7 13:28
+ * @UpdateUser: 更新者:
+ * @UpdateDate: 2020/2/7 13:28
+ * @UpdateRemark: 更新说明:
+ * @Version: 1.0
+ */
+public interface IWebSocket {
+ /**
+ * 连接socket
+ */
+ void connectWebSocket(String address);
+
+ /**
+ * 关闭webSocket
+ */
+ void closeWebSocket();
+
+ /**
+ * websocket send data
+ *
+ * @param data
+ */
+ boolean sendDataWebSocket(String data);
+ boolean sendDataWebSocket(ByteString data);
+
+ /**
+ * 云端拉取配置信息
+ *
+ * @param
+ */
+ void getConfigData(String appId, String userId);
+
+ /**
+ * 更改云端配置信息
+ *
+ * @param configInfos
+ */
+ void doConfigChanged(int type, String ip, List configInfos);
+
+ /**
+ * 上传配置
+ * @param configInfos
+ */
+ void doConfigChanged( List configInfos);
+
+ /**
+ * 保存图片
+ */
+ void saveShotPic(Bitmap bitmap);
+
+
+ /**
+ * @param x
+ * @param y
+ */
+ void getTouchImage(String url, double x, double y);
+
+ /**
+ * @param file
+ * @param deviceId
+ * @param tag
+ */
+ void doRecognizeImage(File file, String deviceId, String tag);
+
+ /**
+ * @param userId
+ */
+ void getUserAchieveInfo(String userId);
+
+
+ /**
+ * 从板子上获取导航信息
+ *
+ * @param type 10/角度 11/位置
+ */
+ void getNaviInfo(int type);
+
+
+ /**
+ * 同步成就信息
+ *
+ * @param userId
+ * @param action
+ * @param medalType
+ */
+ void syncMedalDetailInfo(String userId, int action, String medalType);
+
+
+ /**
+ * 获取品牌车型车款信息
+ *
+ * @param s
+ */
+ void getCarModelInfo(String s, int id);
+
+ void doUpdateCarInfo(String userId, String brandId, String brandName, String modelId, String modelName, String styleId, String styleName);
+
+ /**
+ * 获取apk 以及 固件升级信息
+ *
+ * @param deviceId
+ * @param userId
+ * @param apkVersionCode
+ * @param xvideoCppVersionCode
+ * @param appId 2是专业版
+ */
+ void getApkAndFireWareInfo(String deviceId, String userId, int apkVersionCode, int xvideoCppVersionCode,int appId);
+
+ /**
+ * 获取固件基础信息
+ */
+ void getFireWareBaseInfo(String baseUrl);
+
+ /**
+ * 发送板子 更新升级信息
+ * @param baseUrl
+ * @param json
+ */
+ void sendFirmWareUpdateInfo(String baseUrl,String json);
+
+ void startNavigate(String userId, String naviStartName, String naviEndName);
+
+ void syncUserNavigateInfo(String navigateId, String longtitude, String latitude, String poId, String currentSpeed);
+
+
+ void doVerticalLineConfigCompleted();
+
+
+ /**
+ * 给板子同步长宽高信息
+ * @param carLength
+ * @param carWidth
+ * @param carHeight
+ */
+ void doSyncCarSpaceInfo(String carLength, String carWidth, String carHeight);
+}
+
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/SocketMsgType.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/SocketMsgType.java
new file mode 100644
index 0000000000..aa4d402a78
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/SocketMsgType.java
@@ -0,0 +1,62 @@
+package com.zhidao.support.adas.high.socket;
+
+/**
+ * @author nie yunlong
+ * @description 接收消息type
+ * @date 2018/7/3
+ */
+public enum SocketMsgType {
+
+ /**
+ * 警告
+ */
+ MSG_WARNING_TYPE(1, "警告"),
+ /**
+ * 视频分辨率
+ */
+ MSG_VIDEO_INFO_TYPE(2, "视频分辨率"),
+
+ /**
+ * 控制台开
+ */
+ MSG_CONSOLE_OPEN_TYPE(3, "控制台开"),
+ /**
+ * 控制台关
+ */
+ MSG_CONSOLE_CLOSE_TYPE(4, "控制台关"),
+ /**
+ * 车道线曲率
+ */
+ MSG_CONSOLE_ROAD_TYPE(11, "车道线曲率"),
+ /**
+ * 是否是最左侧车道
+ */
+ MSG_IS_ROAD_LEFT(10, "获取位置"),
+
+ /**
+ * 获取通知进度
+ */
+ MSG_UPGRADE_NOTIFY(12,"通知进度");
+
+
+ int mMsgType;
+ String mMsgContent;
+
+ SocketMsgType(int msgType, String msgContent) {
+ this.mMsgType = msgType;
+ this.mMsgContent = msgContent;
+ }
+
+ /**
+ * 获取msgType
+ *
+ * @return
+ */
+ public int getMsgType() {
+ return mMsgType;
+ }
+
+ public String getmMsgContent() {
+ return mMsgContent;
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/DefaultMessageProtocol.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/DefaultMessageProtocol.java
new file mode 100644
index 0000000000..2095861dbc
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/DefaultMessageProtocol.java
@@ -0,0 +1,50 @@
+package com.zhidao.support.adas.high.socket.read;
+
+import com.zhidao.support.adas.high.common.DigitalTrans;
+
+/**
+ * @author song kenan
+ * @des
+ * @date 2021/10/20
+ */
+public class DefaultMessageProtocol implements IMessageProtocol{
+ @Override
+ public int getMagicCodeLength() {
+ return 2;
+ }
+
+ @Override
+ public int getPackageLength() {
+ return 4;
+ }
+
+ @Override
+ public int getOffsetLength() {
+ return 2;
+ }
+
+ public int getOutHeader(){
+ return getMagicCodeLength()+getPackageLength()+getOffsetLength();
+ }
+
+ @Override
+ public int getHeaderLength(byte[] offset) {
+ if (offset == null) {
+ return 0;
+ }
+ String lengthStr = DigitalTrans.byte2hex(offset);
+ int length = DigitalTrans.hexStringToAlgorism(lengthStr);
+ return length - 8;
+ }
+
+ @Override
+ public int getPayloadLength(byte[] readData,byte[] offset) {
+ if (readData == null){
+ return 0;
+ }
+ if (offset == null){
+ return DigitalTrans.hexStringToAlgorism(DigitalTrans.byte2hex(readData));
+ }
+ return 0;
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/IMessageProtocol.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/IMessageProtocol.java
new file mode 100644
index 0000000000..e68846c9f9
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/IMessageProtocol.java
@@ -0,0 +1,35 @@
+package com.zhidao.support.adas.high.socket.read;
+
+import java.nio.ByteOrder;
+
+/**
+ * @author song kenan
+ * @des
+ * @date 2021/10/20
+ */
+public interface IMessageProtocol {
+ /**
+ * 获取magicCode的长度
+ */
+ int getMagicCodeLength();
+
+ /**
+ * 包长度
+ */
+ int getPackageLength();
+
+ /**
+ * 数据偏移量的长度
+ */
+ int getOffsetLength();
+
+ /**
+ * 获取header数据长度
+ */
+ int getHeaderLength(byte[] offset);
+
+ /**
+ * 消息体长度
+ */
+ int getPayloadLength(byte[] readData,byte[] offset);
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/OriginReadData.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/OriginReadData.java
new file mode 100644
index 0000000000..b078e4e7c7
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/OriginReadData.java
@@ -0,0 +1,103 @@
+package com.zhidao.support.adas.high.socket.read;
+
+import com.zhidao.support.adas.high.common.DigitalTrans;
+
+import java.io.Serializable;
+
+/**
+ * @author song kenan
+ * @des
+ * @date 2021/10/20
+ */
+public class OriginReadData implements Serializable {
+ /**
+ * 用于检查数据是否为正确数据
+ * mg=0x6d67
+ */
+ private byte[] magicCode;
+
+ /**
+ * 包长度
+ */
+ private byte[] packageLength;
+
+ /**
+ * 偏移量,用于计算header长度
+ */
+ private byte[] offset;
+
+ /**
+ * 头部消息,装载消息类型等
+ * 长度=offset-out_header.length
+ */
+ private byte[] header;
+
+ /**
+ * 负载数据:真实上报的数据
+ */
+ private byte[] payload;
+
+
+ /**
+ * 获取out_header 由魔数、包大小、payload偏移量组成;
+ * 用于识别连接数据和数据报解码使用。
+ * 固定8个字节,否则出错。
+ */
+ public byte[] getOutHeaderBytes() {
+ byte[] bytes = DigitalTrans.concatBytes(getMagicCode(), getPackageLength());
+ byte[] outHeader = DigitalTrans.concatBytes(bytes, getOffset());
+ return outHeader;
+ }
+
+ /**
+ * 获取完整的数据
+ *
+ * @return
+ */
+ public byte[] getOriginDataBytes() {
+ byte[] bytes = DigitalTrans.concatBytes(getOutHeaderBytes(), getHeader());
+ byte[] originData = DigitalTrans.concatBytes(bytes, getPayload());
+ return originData;
+ }
+
+
+ public byte[] getMagicCode() {
+ return magicCode;
+ }
+
+ public void setMagicCode(byte[] magicCode) {
+ this.magicCode = magicCode;
+ }
+
+ public byte[] getPackageLength() {
+ return packageLength;
+ }
+
+ public void setPackageLength(byte[] packageLength) {
+ this.packageLength = packageLength;
+ }
+
+ public byte[] getOffset() {
+ return offset;
+ }
+
+ public void setOffset(byte[] offset) {
+ this.offset = offset;
+ }
+
+ public byte[] getHeader() {
+ return header;
+ }
+
+ public void setHeader(byte[] header) {
+ this.header = header;
+ }
+
+ public byte[] getPayload() {
+ return payload;
+ }
+
+ public void setPayload(byte[] payload) {
+ this.payload = payload;
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/SocketReader.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/SocketReader.java
new file mode 100644
index 0000000000..007a41f4d2
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/socket/read/SocketReader.java
@@ -0,0 +1,69 @@
+package com.zhidao.support.adas.high.socket.read;
+
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.common.DigitalTrans;
+import com.zhidao.support.adas.high.udp.CupidUdpConstract;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+import java.util.Arrays;
+
+import okio.ByteString;
+
+/**
+ * @author song kenan
+ * @des
+ * @date 2021/10/20
+ */
+public class SocketReader {
+ private DefaultMessageProtocol messageProtocol;
+ private static final byte[] mg = new byte[]{(byte) 0x6d, 0x67};
+
+ public SocketReader() {
+ messageProtocol = new DefaultMessageProtocol();
+ }
+
+ public OriginReadData read(ByteString bytes) {
+ OriginReadData originalData = new OriginReadData();
+ OriginReadData originReadData = readData(bytes, originalData);
+ //分发
+ return originReadData;
+
+ }
+
+ private synchronized OriginReadData readData(ByteString bytes, OriginReadData originalData) {
+// CupidLogUtils.w("--->websocket byte read bytes :"+bytes.hex());
+ //读取magicCode
+ ByteString magicCode = bytes.substring(0, messageProtocol.getMagicCodeLength());
+ originalData.setMagicCode(magicCode.toByteArray());
+// CupidLogUtils.w("--->websocket byte read magic :"+magicCode.hex());
+ if (Arrays.equals(magicCode.toByteArray(), mg)) {
+ //读取offset
+ ByteString offset = bytes.substring(messageProtocol.getMagicCodeLength(), messageProtocol.getMagicCodeLength() + messageProtocol.getOffsetLength());
+ originalData.setOffset(offset.toByteArray());
+// CupidLogUtils.w("--->websocket byte read offset :"+offset.hex()+";offset length="+ DigitalTrans.hexStringToAlgorism(offset.hex()));
+ //读取packageLength
+ ByteString packageLength = bytes.substring(messageProtocol.getMagicCodeLength() + messageProtocol.getOffsetLength(), messageProtocol.getOutHeader());
+ originalData.setPackageLength(packageLength.toByteArray());
+// CupidLogUtils.w("--->websocket byte read packageLength :"+packageLength.hex()+";pl="+ DigitalTrans.hexStringToAlgorism(packageLength.hex()));
+ //读取header
+ ByteString header = bytes.substring(messageProtocol.getOutHeader(), messageProtocol.getOutHeader() + messageProtocol.getHeaderLength(offset.toByteArray()));
+ originalData.setHeader(header.toByteArray());
+// CupidLogUtils.w("--->websocket byte read header :"+header.hex());
+ //读取payload
+ ByteString payload = bytes.substring(messageProtocol.getOutHeader() + messageProtocol.getHeaderLength(offset.toByteArray()));
+ originalData.setPayload(payload.toByteArray());
+// CupidLogUtils.w("--->websocket byte read payload :"+payload.hex());
+ return originalData;
+ } else {
+ CupidLogUtils.w("--->websocket byte read magicCode error 丢弃");
+ return null;
+ }
+
+
+ }
+
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/CallableWrapper.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/CallableWrapper.java
new file mode 100644
index 0000000000..1d0508a537
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/CallableWrapper.java
@@ -0,0 +1,84 @@
+/*
+Copyright 2017 yangchong211(github.com/yangchong211)
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package com.zhidao.support.adas.high.thread;
+
+
+
+import com.zhidao.support.adas.high.thread.callback.NormalCallback;
+import com.zhidao.support.adas.high.thread.callback.ThreadCallback;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @param
+ */
+public final class CallableWrapper implements Callable {
+
+ private ThreadCallback callback;
+
+ private Callable proxy;
+
+ /**
+ * 构造方法
+ *
+ * @param proxy 线程优先级
+ */
+ public CallableWrapper(Callable proxy, NormalCallback normalCallback) {
+ this.proxy = proxy;
+ this.callback = normalCallback;
+ }
+
+ /**
+ * 详细可以看我的GitHub:https://github.com/yangchong211
+ * 自定义Callable继承Callable类,Callable 是在 JDK1.5 增加的。
+ * Callable 的 call() 方法可以返回值和抛出异常
+ *
+ * @return 泛型
+ * @throws Exception 异常
+ */
+ @Override
+ public T call() {
+ if (callback != null) {
+ //开始
+ callback.onStart();
+ }
+ T t = null;
+ try {
+ t = proxy == null ? null : proxy.call();
+ if (callback != null) {
+ T callInBackground = callback.doInBackground();
+ if (callInBackground != null) {
+ t = callInBackground;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ //异常错误
+ if (callback != null) {
+ callback.onError(e);
+ }
+ } finally {
+ //完成
+ if (callback != null) {
+ callback.onCompleted();
+ }
+ }
+ return t;
+ }
+
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/QueuedWork.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/QueuedWork.java
new file mode 100644
index 0000000000..595736858d
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/QueuedWork.java
@@ -0,0 +1,141 @@
+package com.zhidao.support.adas.high.thread;
+
+import android.os.Handler;
+import android.os.Looper;
+
+
+import com.zhidao.support.adas.high.thread.callback.NormalCallback;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Created by nieyunlong on 17/8/8.
+ * 队列
+ */
+
+public class QueuedWork {
+
+ private static Handler uiHandler;
+
+ /*sdk请求量不是很大*/
+ private static final int MAX_MISSION_COUNT = 1; //设置线程池最大线程个数
+ private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
+ // We want at least 2 threads and at most 4 threads in the core pool,
+ // preferring to have 1 less than the CPU count to avoid saturating
+ // the CPU with background work
+// private static final int CORE_POOL_SIZE = Math.max(2, Math.min(CPU_COUNT - 1, 4));
+ private static final int CORE_POOL_SIZE = 3;
+ private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
+
+ public static final ThreadPoolExecutor THREAD_POOL_EXECUTOR;
+
+ static {
+ ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, 30, TimeUnit.SECONDS,
+ new LinkedBlockingDeque(128));
+ threadPoolExecutor.allowCoreThreadTimeOut(true);
+ THREAD_POOL_EXECUTOR = threadPoolExecutor;
+ }
+
+
+ public static void runInMain(Runnable paramRunnable) {
+ if (uiHandler == null)
+ uiHandler = new Handler(Looper.getMainLooper());
+ uiHandler.post(paramRunnable);
+ }
+
+ public static void runInBack(Runnable task) {
+ THREAD_POOL_EXECUTOR.execute(task);
+ }
+
+ /**
+ * 建议停止正在执行的任务
+ */
+ public static void shutDownNow() {
+ THREAD_POOL_EXECUTOR.shutdownNow();
+ }
+
+ /**
+ * 建议停止正在执行的任务
+ */
+ public static void shutDown() {
+ THREAD_POOL_EXECUTOR.shutdown();
+ }
+
+ /**
+ * 发射任务
+ * 提交任务有返回值
+ * 当我们使用submit来提交任务时,它会返回一个future,我们就可以通过这个future来判断任务是否执行成功,
+ * 还可以通过future的get方法来获取返回值。如果子线程任务没有完成,get方法会阻塞住直到任务完成,
+ * 而使用get(long timeout, TimeUnit unit)方法则会阻塞一段时间后立即返回,这时候有可能任务并没有执行完。
+ *
+ * @param callable callable
+ * @param type
+ * @return {@link Future}
+ */
+ public static Future submit(Callable callable, NormalCallback normalCallback) {
+ callable = new CallableWrapper<>(callable, normalCallback);
+ Future result = THREAD_POOL_EXECUTOR.submit(callable);
+ return result;
+ }
+
+ /**
+ * 移除队列里面的任务
+ */
+ public static int getQueueSize() {
+ if (null != THREAD_POOL_EXECUTOR) {
+ BlockingQueue queue = THREAD_POOL_EXECUTOR.getQueue();
+ return queue.size();
+ }
+ return 0;
+ }
+
+
+ public static abstract class ZSAsyncTask {
+
+ protected Runnable thread;
+
+ protected void onPreExecute() {
+ }
+
+ protected abstract Result doInBackground();
+
+ protected void onPostExecute(Result paramResult) {
+ }
+
+ public final ZSAsyncTask execute() {
+ this.thread = new Runnable() {
+ public void run() {
+ final Result var1 = ZSAsyncTask.this.doInBackground();
+ QueuedWork.runInMain(new Runnable() {
+ public void run() {
+ ZSAsyncTask.this.onPostExecute(var1);
+ }
+ });
+ }
+ };
+ QueuedWork.runInMain(new Runnable() {
+ public void run() {
+ //pre execute
+ ZSAsyncTask.this.onPreExecute();
+ runInBack(ZSAsyncTask.this.thread);
+ }
+ });
+ return this;
+ }
+ }
+
+ private static final ThreadFactory sThreadFactory = new ThreadFactory() {
+ private final AtomicInteger mCount = new AtomicInteger(1);
+
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "ZSAsyncTask #" + mCount.getAndIncrement());
+ }
+ };
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/callback/NormalCallback.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/callback/NormalCallback.java
new file mode 100644
index 0000000000..15ba267b0a
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/callback/NormalCallback.java
@@ -0,0 +1,44 @@
+/*
+Copyright 2017 yangchong211(github.com/yangchong211)
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+package com.zhidao.support.adas.high.thread.callback;
+
+/**
+ *
+ * @param
+ */
+public class NormalCallback implements ThreadCallback {
+
+
+ @Override
+ public void onError(Throwable t) {
+
+ }
+
+ @Override
+ public Result doInBackground() {
+ return null;
+ }
+
+ @Override
+ public void onCompleted() {
+
+ }
+
+ @Override
+ public void onStart() {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/callback/ThreadCallback.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/callback/ThreadCallback.java
new file mode 100644
index 0000000000..9e9d0965b9
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/thread/callback/ThreadCallback.java
@@ -0,0 +1,47 @@
+/*
+Copyright 2017 yangchong211(github.com/yangchong211)
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+package com.zhidao.support.adas.high.thread.callback;
+
+/**
+ *
+ * @param
+ */
+public interface ThreadCallback {
+
+ /**
+ * 当线程发生错误时,将调用此方法。
+ * @param t 异常
+ */
+ void onError(Throwable t);
+
+ /**
+ * 做后台操作
+ * 如果没有Callable 代理 直接走这个后台操作 如果有代理会直接走代理
+ */
+ Result doInBackground();
+
+ /**
+ * 通知用户知道它已经完成
+ */
+ void onCompleted();
+
+ /**
+ * 通知用户任务开始运行
+ */
+ void onStart();
+
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidBufStreamImpl.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidBufStreamImpl.java
new file mode 100644
index 0000000000..b9e0497aec
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidBufStreamImpl.java
@@ -0,0 +1,88 @@
+package com.zhidao.support.adas.high.udp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+
+/**
+ * Created by wangyaofu on 2018/6/14.
+ */
+public class CupidBufStreamImpl implements IBuffStream {
+
+ // 5M
+// public static final int BUF_SIZE = 5242880;
+ public static final int BUF_SIZE = 2097152;
+ //3M
+ public static final int BUF_SIZE_LIMIT = 3145728;
+
+ ByteArrayOutputStream ostream0_;
+ ByteArrayOutputStream ostream1_;
+
+ volatile Boolean isSwitch;
+
+ @Override
+ public void init() {
+ ostream0_ = new ByteArrayOutputStream(BUF_SIZE);
+ ostream1_ = new ByteArrayOutputStream(BUF_SIZE);
+ isSwitch = false;
+ }
+
+ @Override
+ public OutputStream getOutputStream() {
+ synchronized (isSwitch) {
+ if (isSwitch) {
+ return ostream1_;
+ } else {
+ return ostream0_;
+ }
+ }
+
+ }
+
+ @Override
+ public byte[] getData() {
+ byte[] b = null;
+ synchronized (isSwitch) {
+ if (isSwitch) {
+ b = ostream0_.toByteArray();
+ } else {
+ b = ostream1_.toByteArray();
+ }
+ }
+ return b;
+ }
+
+ @Override
+ public int getLength() {
+ int size;
+ synchronized (isSwitch) {
+ if (isSwitch) {
+ size = ostream0_.size();
+ } else {
+ size = ostream1_.size();
+ }
+ }
+ return size;
+ }
+
+ @Override
+ public void close() {
+ if (ostream0_ != null) {
+ ostream0_.reset();
+ }
+ if (ostream1_ != null) {
+ ostream1_.reset();
+ }
+ }
+
+ @Override
+ public void doSwitch() {
+ synchronized (isSwitch) {
+ if (isSwitch) {
+ ostream0_.reset();
+ } else {
+ ostream1_.reset();
+ }
+ isSwitch = !isSwitch;
+ }
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidBufStreamImpl2.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidBufStreamImpl2.java
new file mode 100644
index 0000000000..df33ac8ade
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidBufStreamImpl2.java
@@ -0,0 +1,54 @@
+package com.zhidao.support.adas.high.udp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+
+/**
+ * Created by wangyaofu on 2018/6/14.
+ */
+public class CupidBufStreamImpl2 implements IBuffStream {
+
+ // 5M
+// public static final int BUF_SIZE = 5242880;
+ public static final int BUF_SIZE = 2097152;
+ //3M
+ public static final int BUF_SIZE_LIMIT = 3145728;
+
+ ByteArrayOutputStream ostream0_;
+
+ @Override
+ public void init() {
+ if (ostream0_ != null) {
+ ostream0_.reset();
+ ostream0_ = null;
+ }
+ ostream0_ = new ByteArrayOutputStream(BUF_SIZE);
+ }
+
+ @Override
+ public OutputStream getOutputStream() {
+ return ostream0_;
+ }
+
+ @Override
+ public byte[] getData() {
+ byte[] b = ostream0_.toByteArray();
+ return b;
+ }
+
+ @Override
+ public int getLength() {
+ int size = ostream0_.size();
+ return size;
+ }
+
+ @Override
+ public void close() {
+ init();
+ }
+
+ @Override
+ public void doSwitch() {
+ ostream0_.reset();
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidUdpConstract.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidUdpConstract.java
new file mode 100644
index 0000000000..77022ac8df
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidUdpConstract.java
@@ -0,0 +1,132 @@
+package com.zhidao.support.adas.high.udp;
+
+
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.udp.factory.AbstractUdpImpl;
+import com.zhidao.support.adas.high.udp.factory.CupidUdpFactory;
+
+/**
+ * @author nie yunlong
+ * @description udp 与 stream
+ * @date 2018/6/15
+ */
+public class CupidUdpConstract {
+
+
+ private CupidBufStreamImpl2 buffStreamImpl;
+ /**
+ * udp 接收数据线程
+ */
+ private Thread udpReceiverDataThread;
+ /**
+ * 默认的udp端口
+ */
+ private int defaultVideoUdpPort = 6665;
+
+ /**
+ * 默认的udp端口
+ */
+ private int defaultRenderImageUdpPort = 6661;
+
+ private AbstractUdpImpl udpImpl;
+ /**
+ * 默认是0 创建h264解析流
+ */
+ public static final int VIDEO_STREAM_UDP = 0;
+ /**
+ * 上层绘制 待开发
+ */
+ public static final int VIDEO_RENDER_IMAGE_UDP = 1;
+
+ public CupidUdpConstract(int udpType) {
+ init(udpType);
+ }
+
+ /**
+ * 初始化UDPserver 接收数据
+ */
+ private void init(int udpType) {
+ if (udpType == VIDEO_STREAM_UDP) {
+ udpImpl = CupidUdpFactory.createVideoStreamUdp();
+ udpImpl.setUdpPort(defaultVideoUdpPort);
+ // buffStreamImpl = new CupidBufStreamImpl();
+ buffStreamImpl = new CupidBufStreamImpl2();
+ buffStreamImpl.init();
+ udpImpl.setBuffStream(buffStreamImpl);
+ } else if (udpType == VIDEO_RENDER_IMAGE_UDP) {
+ udpImpl = CupidUdpFactory.createRenderImageUdp();
+ udpImpl.setUdpPort(defaultRenderImageUdpPort);
+ }
+ udpImpl.setStop(false);
+ startReceiverDataThread();
+ }
+
+ /**
+ * 开启线程 在surface准备好之后再进行接收数据
+ */
+ public void startReceiverDataThread() {
+ if (udpReceiverDataThread != null) {
+ udpReceiverDataThread.interrupt();
+ udpReceiverDataThread = null;
+ }
+ udpReceiverDataThread = new Thread(udpImpl);
+ udpReceiverDataThread.start();
+ }
+
+ public void setOnReceiverH264Data(IGetH264Data getH264Data) {
+ udpImpl.getVideoInputStreamData(getH264Data);
+ }
+
+ /**
+ * 连接listener
+ *
+ * @param connectListener
+ */
+ public void setOnConnectListener(IConnectRtpListener connectListener) {
+ udpImpl.setOnConnectListener(connectListener);
+ }
+
+ public void onPause() {
+ udpImpl.onPause();
+ }
+
+ public void onResume() {
+ udpImpl.onResume();
+ }
+
+ /**
+ * 初始化webSocket
+ */
+ public void setUdpIsFirstInit() {
+ if (udpImpl != null) {
+ udpImpl.setFirstReceiverAddress(false);
+ }
+ }
+
+ /**
+ * 服务端关闭 初始化buffer
+ */
+ public void resetBuffer() {
+ if (udpImpl != null) {
+ udpImpl.initBuffer();
+ }
+ }
+
+
+ public void release() {
+ try {
+ CupidLogUtils.e("---->关闭socket");
+ if (udpImpl != null) {
+ udpImpl.close();
+ udpImpl = null;
+ }
+ if (udpReceiverDataThread != null && !udpReceiverDataThread.isInterrupted()) {
+ udpReceiverDataThread.interrupt();
+ udpReceiverDataThread = null;
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidUdpServer.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidUdpServer.java
new file mode 100644
index 0000000000..bc4f6c1a0f
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/CupidUdpServer.java
@@ -0,0 +1,275 @@
+package com.zhidao.support.adas.high.udp;
+
+
+
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+
+/**
+ * Created by wangyaofu on 18/6/14.
+ */
+public class CupidUdpServer implements Runnable {
+
+ static final String TAG = CupidUdpServer.class.getSimpleName();
+
+ private int udpPort;
+ private boolean isMultiCast;
+ private String multiCastIp;
+ private volatile boolean isStop;
+
+ private IBuffStream buffStream;
+ /**
+ * 接口 回调一帧
+ */
+ private IGetH264Data mGetH264Data;
+
+ private IConnectRtpListener mConnectRtpListener;
+ /**
+ * 接收的ip地址
+ */
+ private volatile String mReceiveAddress;
+
+
+ public int getUdpPort() {
+ return udpPort;
+ }
+
+ public void setUdpPort(int udpPort) {
+ this.udpPort = udpPort;
+ }
+
+ public boolean isMultiCast() {
+ return isMultiCast;
+ }
+
+ public void setMultiCast(boolean multiCast) {
+ isMultiCast = multiCast;
+ }
+
+ public String getMultiCastIp() {
+ return multiCastIp;
+ }
+
+ public void setMultiCastIp(String multiCastIp) {
+ this.multiCastIp = multiCastIp;
+ }
+
+ public boolean isStop() {
+ return isStop;
+ }
+
+ public synchronized void setStop(boolean stop) {
+ isStop = stop;
+ }
+
+ public IBuffStream getBuffStream() {
+ return buffStream;
+ }
+
+ public void setBuffStream(IBuffStream buffStream) {
+ this.buffStream = buffStream;
+ }
+
+
+ /**
+ *
+ * @param connectRtpListener
+ */
+ public void setOnConnectListener(IConnectRtpListener connectRtpListener) {
+ this.mConnectRtpListener = connectRtpListener;
+ }
+
+ /**
+ *
+ * @param getH264Data
+ */
+ public void setOnReceiverListener(IGetH264Data getH264Data) {
+ this.mGetH264Data = getH264Data;
+ }
+
+ private static final int DATA_LEN = 4096;
+ byte[] inBuff = new byte[DATA_LEN];
+ /**
+ * 接收的包
+ */
+ private DatagramPacket inPacket = new DatagramPacket(inBuff, inBuff.length);
+ /**
+ * udp
+ */
+ private DatagramSocket socket = null;
+ /**
+ * 带广播的udp
+ */
+ private MulticastSocket mMulticastSocket = null;
+ /**
+ * 第一次获取到接收端的ip
+ */
+ private volatile boolean isFirstReceiverAddress;
+
+ boolean parseRTP() {
+ int naluType = 0;
+ int nalunri = 0;
+ int naluf = 0;
+
+ boolean isEnd = false;
+ if ((int) (inBuff[1] >> 7 & 0x01) == 1) {
+ isEnd = true;
+ }
+
+ byte naluHeader = inBuff[12];
+ naluType = naluHeader & 0x1f;
+ nalunri = naluHeader >> 5 & 0x03;
+ naluf = naluHeader >> 7 & 0x01;
+ int len = inPacket.getLength();
+ CupidLogUtils.i(TAG, "packet-len:" + len);
+
+ byte[] fu_h_byte = new byte[5];
+ fu_h_byte[0] = 0;
+ fu_h_byte[1] = 0;
+ fu_h_byte[2] = 0;
+ fu_h_byte[3] = 1;
+
+ if (28 == naluType) {
+ // H264 Begin
+ int fu_type = 0;
+ int fu_r = 0;
+ int fu_e = 0;
+ int fu_s = 0;
+
+ byte fu_header = inBuff[13];
+ fu_type = fu_header & 0x1f;
+ fu_r = fu_header >> 5 & 0x01;
+ fu_e = fu_header >> 6 & 0x01;
+ fu_s = fu_header >> 7 & 0x01;
+
+ if (fu_s == 1) {
+ //buffStream.doSwitch();
+ // start of fu-a
+ fu_h_byte[4] = (byte) ((fu_type & 0x1f) | (nalunri << 5 & 0x60) | (naluf << 7 & 0x80));
+ try {
+ //buffStream.getOutputStream().write(fu_h_byte, 0, 5);
+ buffStream.getOutputStream().write(inBuff, 14, len - 14);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ } else {
+ // end of fu-a
+ try {
+ buffStream.getOutputStream().write(inBuff, 14, len - 14);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ } else {
+ fu_h_byte[4] = (byte) ((naluType & 0x1f) | (nalunri << 5 & 0x60) | (naluf << 7 & 0x80));
+ try {
+ //buffStream.getOutputStream().write(fu_h_byte, 0, 5);
+ buffStream.getOutputStream().write(inBuff, 13, len - 13);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ if (isEnd) {
+ buffStream.doSwitch();
+ if (mGetH264Data != null) {
+ mGetH264Data.getH264Data(buffStream.getData(),System.currentTimeMillis());
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void run() {
+ CupidLogUtils.e(TAG, "---->开始接收数据");
+ try {
+ if (isMultiCast) {
+ mMulticastSocket = new MulticastSocket(udpPort);
+ InetAddress bcAddr = InetAddress.getByName(multiCastIp);
+ mMulticastSocket.setReuseAddress(true);
+ mMulticastSocket.joinGroup(bcAddr);
+ mMulticastSocket.setLoopbackMode(false);
+ } else {
+ CupidLogUtils.e(TAG, "---->开始连接端口" + udpPort);
+ socket = new DatagramSocket(udpPort);
+ socket.setReuseAddress(true);
+ CupidLogUtils.e(TAG, "---->连接成功" + udpPort);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ if (mConnectRtpListener != null) {
+ mConnectRtpListener.onConnectionFailedRtp(e.getMessage());
+ }
+ return;
+ }
+
+ while (!isStop) {
+ try {
+ if (isMultiCast && mMulticastSocket != null) {
+ mMulticastSocket.receive(inPacket);
+ } else {
+ if (socket != null) {
+ socket.receive(inPacket);
+ }
+ }
+ if (!isFirstReceiverAddress) {
+ mReceiveAddress = inPacket.getAddress().getHostAddress();
+ CupidLogUtils.e("mReceiveAddress--->mReceiveAddress" + mReceiveAddress);
+ isFirstReceiverAddress = true;
+ if (mConnectRtpListener != null) {
+ mConnectRtpListener.getOnConnectionAddress(mReceiveAddress);
+ }
+ }
+
+
+ if (inPacket.getLength() > 12) {
+ parseRTP();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ if (mConnectRtpListener != null) {
+ mConnectRtpListener.onConnectionFailedRtp(e.getMessage());
+ }
+ }
+ }
+ }
+
+ /**
+ * 获取到连接ip地址
+ *
+ * @return
+ */
+ public String getmReceiveAddress() {
+ return mReceiveAddress;
+ }
+
+
+ /**
+ * 关闭流
+ */
+ public synchronized void close() {
+ setStop(true);
+ if (mMulticastSocket != null) {
+ mMulticastSocket.close();
+ }
+ if (socket != null) {
+ socket.close();
+ }
+ }
+
+ public boolean isFirstReceiverAddress() {
+ return isFirstReceiverAddress;
+ }
+
+ public void setFirstReceiverAddress(boolean firstReceiverAddress) {
+ isFirstReceiverAddress = firstReceiverAddress;
+ }
+}
\ No newline at end of file
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IBuffStream.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IBuffStream.java
new file mode 100644
index 0000000000..07b065ab5b
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IBuffStream.java
@@ -0,0 +1,20 @@
+package com.zhidao.support.adas.high.udp;
+
+import java.io.OutputStream;
+
+/**
+ * Created by wangyaofu on 2018/6/14.
+ */
+public interface IBuffStream {
+ void init();
+
+ OutputStream getOutputStream();
+
+ void doSwitch();
+
+ byte[] getData();
+
+ int getLength();
+
+ void close();
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IConnectRtpListener.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IConnectRtpListener.java
new file mode 100644
index 0000000000..ecccba0bb9
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IConnectRtpListener.java
@@ -0,0 +1,25 @@
+package com.zhidao.support.adas.high.udp;
+
+/**
+ * @author nie yunlong
+ * @description
+ * @date 2018/6/15
+ */
+public interface IConnectRtpListener {
+
+ /**
+ * 连接成功 指的是 client发送数据包
+ */
+ void onConnectionSuccessRtp();
+
+ void onConnectionFailedRtp(String reason);
+
+ /**
+ * 获取到client的ip地址
+ * @param address
+ */
+ void getOnConnectionAddress(String address);
+
+ void onDisconnectRtp();
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IGetH264Data.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IGetH264Data.java
new file mode 100644
index 0000000000..d32a9f0351
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IGetH264Data.java
@@ -0,0 +1,16 @@
+package com.zhidao.support.adas.high.udp;
+
+/**
+ * @author nie yunlong
+ * @description h264数据
+ * @date 2018/6/15
+ */
+public interface IGetH264Data {
+
+ /**
+ * 获取h264数据
+ * @param data h264
+ */
+ void getH264Data(byte[] data,long receiverDataUdpTime);
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IRenderImageListener.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IRenderImageListener.java
new file mode 100644
index 0000000000..88b4495452
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/IRenderImageListener.java
@@ -0,0 +1,81 @@
+package com.zhidao.support.adas.high.udp;
+
+import android.view.SurfaceHolder;
+
+/**
+ * @author nie yunlong
+ * @description 回调获取数据时候 ui变化
+ * @date 2018/6/26
+ */
+public interface IRenderImageListener {
+ /**
+ * 获取udp包的数据 用来告知展示什么ui
+ *
+ * @param data
+ */
+ void getUdpData(String data);
+
+ /**
+ * surface create
+ *
+ * @param holder
+ */
+ void surfaceCreated(SurfaceHolder holder);
+
+ /**
+ * 改变尺寸
+ *
+ * @param holder
+ * @param format
+ * @param width
+ * @param height
+ */
+ void surfaceChanged(SurfaceHolder holder, int format, int width, int height);
+
+ /**
+ * 销毁
+ *
+ * @param holder
+ */
+ void surfaceDestroyed(SurfaceHolder holder);
+
+ /**
+ * udp 连接失败
+ */
+ void onConnectionFailedRtp(String reason);
+
+ /**
+ * 连接udpok
+ * @param address
+ */
+ void getOnConnectionAddress(String address);
+
+
+ /**
+ * 所有的都是模拟 贴图模式
+ *
+ * @param canvas
+ * @param width
+ * @param height
+ * @param scaleWidth
+ * @param scaleHeight
+ * @param isChange 是否改变元数据坐标
+ */
+ //boolean draw(Canvas canvas, int width, int height, float scaleWidth, float scaleHeight, List drawUiInfoList, boolean isChange);
+
+ /**
+ * 绘制 与帧绑定
+ *
+ * @param canvas
+ * @param width 展示UI层 宽度
+ */
+ // void draw(Canvas canvas, int width, int height, float scaleWidth, float scaleHeight, DrawUiInfo drawUiInfo);
+
+ /**
+ * @param canvas
+ * @param picWidth 图片的宽度
+ * @param picHeight 图片的高度
+ * @param drawAlarmAnimationList 报警位置的集合
+ */
+// void drawAlarm(Canvas canvas, float picWidth, float picHeight, List drawAlarmAnimationList);
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/RTPUtils.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/RTPUtils.java
new file mode 100644
index 0000000000..34bfaf260d
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/RTPUtils.java
@@ -0,0 +1,392 @@
+package com.zhidao.support.adas.high.udp;
+
+import java.util.Comparator;
+
+/**
+ * RTP-related static utility methods.
+ *
+ * @deprecated
+ *
+ * @author Boris Grozev
+ */
+public class RTPUtils
+{
+ /**
+ * Hex characters for converting bytes to readable hex strings
+ */
+ private final static char[] HEXES = new char[]
+ {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8',
+ '9', 'A', 'B', 'C', 'D', 'E', 'F'
+ };
+ /**
+ * Returns the delta between two RTP sequence numbers, taking into account
+ * rollover. This will return the 'shortest' delta between the two
+ * sequence numbers in the form of the number you'd add to b to get a. e.g.:
+ * getSequenceNumberDelta(1, 10) -> -9 (10 + -9 = 1)
+ * getSequenceNumberDelta(1, 65530) -> 7 (65530 + 7 = 1)
+ * @return the delta between two RTP sequence numbers (modulo 2^16).
+ */
+ public static int getSequenceNumberDelta(int a, int b)
+ {
+ int diff = a - b;
+
+ if (diff < -(1<<15))
+ {
+ diff += 1 << 16;
+ }
+ else if (diff > 1<<15)
+ {
+ diff -= 1 << 16;
+ }
+
+ return diff;
+ }
+
+ /**
+ * Returns whether or not seqNumOne is 'older' than seqNumTwo, taking
+ * rollover into account
+ * @param seqNumOne
+ * @param seqNumTwo
+ * @return true if seqNumOne is 'older' than seqNumTwo
+ */
+ public static boolean isOlderSequenceNumberThan(int seqNumOne, int seqNumTwo)
+ {
+ return getSequenceNumberDelta(seqNumOne, seqNumTwo) < 0;
+ }
+
+ /**
+ * Returns result of the subtraction of one RTP sequence number from another
+ * (modulo 2^16).
+ * @return result of the subtraction of one RTP sequence number from another
+ * (modulo 2^16).
+ */
+ public static int subtractNumber(int a, int b)
+ {
+ return as16Bits(a - b);
+ }
+
+
+ /**
+ * Apply a delta to a given sequence number and return the result (taking
+ * rollover into account)
+ * @param startingSequenceNumber the starting sequence number
+ * @param delta the delta to be applied
+ * @return the sequence number result from doing
+ * startingSequenceNumber + delta
+ */
+ public static int applySequenceNumberDelta(
+ int startingSequenceNumber, int delta)
+ {
+ return (startingSequenceNumber + delta) & 0xFFFF;
+ }
+
+ /**
+ * Set an integer at specified offset in network order.
+ *
+ * @param off Offset into the buffer
+ * @param data The integer to store in the packet
+ */
+ public static int writeInt(byte[] buf, int off, int data)
+ {
+ if (buf == null || buf.length < off + 4)
+ {
+ return -1;
+ }
+
+ buf[off++] = (byte)(data>>24);
+ buf[off++] = (byte)(data>>16);
+ buf[off++] = (byte)(data>>8);
+ buf[off] = (byte)data;
+ return 4;
+ }
+
+ /**
+ * Writes the least significant 24 bits from the given integer into the
+ * given byte array at the given offset.
+ * @param buf the buffer into which to write.
+ * @param off the offset at which to write.
+ * @param data the integer to write.
+ * @return 3
+ */
+ public static int writeUint24(byte[] buf, int off, int data)
+ {
+ if (buf == null || buf.length < off + 3)
+ {
+ return -1;
+ }
+
+ buf[off++] = (byte)(data>>16);
+ buf[off++] = (byte)(data>>8);
+ buf[off] = (byte)data;
+ return 3;
+ }
+
+ /**
+ * Set an integer at specified offset in network order.
+ *
+ * @param off Offset into the buffer
+ * @param data The integer to store in the packet
+ */
+ public static int writeShort(byte[] buf, int off, short data)
+ {
+ buf[off++] = (byte)(data>>8);
+ buf[off] = (byte)data;
+ return 2;
+ }
+
+ /**
+ * Read an integer from a buffer at a specified offset.
+ *
+ * @param buf the buffer.
+ * @param off start offset of the integer to be read.
+ */
+ public static int readInt(byte[] buf, int off)
+ {
+ return
+ ((buf[off++] & 0xFF) << 24)
+ | ((buf[off++] & 0xFF) << 16)
+ | ((buf[off++] & 0xFF) << 8)
+ | (buf[off] & 0xFF);
+ }
+
+ /**
+ * Reads a 32-bit unsigned integer from the given buffer at the given
+ * offset and returns its {@link long} representation.
+ * @param buf the buffer.
+ * @param off start offset of the integer to be read.
+ */
+ public static long readUint32AsLong(byte[] buf, int off)
+ {
+ return readInt(buf, off) & 0xFFFF_FFFFL;
+ }
+
+ /**
+ * Read an unsigned short at a specified offset as an int.
+ *
+ * @param buf the buffer from which to read.
+ * @param off start offset of the unsigned short
+ * @return the int value of the unsigned short at offset
+ */
+ public static int readUint16AsInt(byte[] buf, int off)
+ {
+ int b1 = (0xFF & (buf[off + 0]));
+ int b2 = (0xFF & (buf[off + 1]));
+ int val = b1 << 8 | b2;
+ return val;
+ }
+
+ /**
+ * Read a signed short at a specified offset as an int.
+ *
+ * @param buf the buffer from which to read.
+ * @param off start offset of the unsigned short
+ * @return the int value of the unsigned short at offset
+ */
+ public static int readInt16AsInt(byte[] buf, int off)
+ {
+ int ret = ((0xFF & (buf[off])) << 8)
+ | (0xFF & (buf[off + 1]));
+ if ((ret & 0x8000) != 0)
+ {
+ ret = ret | 0xFFFF_0000;
+ }
+
+ return ret;
+ }
+
+ /**
+ * Read an unsigned short at specified offset as a int
+ *
+ * @param buf
+ * @param off start offset of the unsigned short
+ * @return the int value of the unsigned short at offset
+ */
+ public static int readUint24AsInt(byte[] buf, int off)
+ {
+ int b1 = (0xFF & (buf[off + 0]));
+ int b2 = (0xFF & (buf[off + 1]));
+ int b3 = (0xFF & (buf[off + 2]));
+ return b1 << 16 | b2 << 8 | b3;
+ }
+
+ /**
+ * Returns the given integer masked to 16 bits
+ * @param value the integer to mask
+ * @return the value, masked to only keep the lower
+ * 16 bits
+ */
+ public static int as16Bits(int value)
+ {
+ return value & 0xFFFF;
+ }
+
+ /**
+ * Returns the given integer masked to 32 bits
+ * @param value the integer to mask
+ * @return the value, masked to only keep the lower
+ * 32 bits
+ */
+ public static long as32Bits(long value)
+ {
+ return value & 0xFFFF_FFFFL;
+ }
+
+ /**
+ * A {@link Comparator} implementation for unsigned 16-bit {@link Integer}s.
+ * Compares {@code a} and {@code b} inside the [0, 2^16] ring;
+ * {@code a} is considered smaller than {@code b} if it takes a smaller
+ * number to reach from {@code a} to {@code b} than the other way round.
+ *
+ * IMPORTANT: This is a valid {@link Comparator} implementation only when
+ * used for subsets of [0, 2^16) which don't span more than 2^15 elements.
+ *
+ * E.g. it works for: [0, 2^15-1] and ([50000, 2^16) u [0, 10000])
+ * Doesn't work for: [0, 2^15] and ([0, 2^15-1] u {2^16-1}) and [0, 2^16)
+ */
+ public static final Comparator super Integer> sequenceNumberComparator
+ = new Comparator() {
+ @Override
+ public int compare(Integer a, Integer b)
+ {
+ if (a.equals(b))
+ {
+ return 0;
+ }
+ else if (a > b)
+ {
+ if (a - b < 0x10000)
+ {
+ return 1;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ else //a < b
+ {
+ if (b - a < 0x10000)
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ }
+ };
+
+ /**
+ * Returns the difference between two RTP timestamps.
+ * @return the difference between two RTP timestamps.
+ */
+ public static long rtpTimestampDiff(long a, long b)
+ {
+ long diff = a - b;
+ if (diff < -(1L<<31))
+ {
+ diff += 1L << 32;
+ }
+ else if (diff > 1L<<31)
+ {
+ diff -= 1L << 32;
+ }
+
+ return diff;
+ }
+
+ /**
+ * Returns whether or not the first given timestamp is newer than the second
+ * @param a
+ * @param b
+ * @return true if a is newer than b, false otherwise
+ */
+ public static boolean isNewerTimestampThan(long a, long b)
+ {
+ return rtpTimestampDiff(a, b) > 0;
+ }
+
+ /**
+ * Return a string containing the hex string version of the given byte
+ * @param b
+ * @return
+ */
+ private static String toHexString(byte b)
+ {
+
+ StringBuilder hexStringBuilder = new StringBuilder(2);
+
+ hexStringBuilder.append(HEXES[(b & 0xF0) >> 4]);
+ hexStringBuilder.append(HEXES[b & 0x0F]);
+
+ return hexStringBuilder.toString();
+ }
+
+ /**
+ * Return a string containing the hex string version of the given bytes
+ * @param buf
+ * @return
+ */
+ public static String toHexString(byte[] buf)
+ {
+ return toHexString(buf, 0, buf.length, true);
+ }
+
+ /**
+ * Return a string containing the hex string version of the given byte
+ * @param buf
+ * @param off
+ * @param len
+ * @return
+ */
+ public static String toHexString(byte[] buf, int off, int len)
+ {
+ return toHexString(buf, off, len, true);
+ }
+
+ /**
+ * Return a string containing the hex string version of the given byte
+ * @param buf
+ * @param off
+ * @param len
+ * @param format a boolean that indicates whether or not to format the hex
+ * string.
+ * @return
+ */
+ public static String toHexString(byte[] buf, int off, int len, boolean format)
+ {
+ if (buf == null)
+ {
+ return null;
+ }
+ else
+ {
+ StringBuilder hexStringBuilder
+ = new StringBuilder(2 * buf.length);
+
+ for (int i = 0; i < len; i++)
+ {
+ if (format)
+ {
+ if (i % 16 == 0)
+ {
+ hexStringBuilder.append("\n")
+ .append(toHexString((byte) i))
+ .append(" ");
+ }
+ else if (i % 8 == 0)
+ {
+ hexStringBuilder.append(" ");
+ }
+ }
+ byte b = buf[off + i];
+
+ hexStringBuilder.append(toHexString(b));
+ hexStringBuilder.append(" ");
+ }
+ return hexStringBuilder.toString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/AbstractUdpImpl.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/AbstractUdpImpl.java
new file mode 100644
index 0000000000..69401db025
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/AbstractUdpImpl.java
@@ -0,0 +1,217 @@
+package com.zhidao.support.adas.high.udp.factory;
+
+
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.udp.IConnectRtpListener;
+import com.zhidao.support.adas.high.udp.IGetH264Data;
+
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+
+/**
+ * @author nie yunlong
+ * @description
+ * @date 2018/7/11
+ */
+public abstract class AbstractUdpImpl implements IUdpAction, Runnable {
+
+
+ static final String TAG = AbstractUdpImpl.class.getSimpleName();
+ /**
+ * udp端口
+ */
+ private int udpPort;
+ /**
+ * 是否组播
+ */
+ private boolean isMultiCast;
+ /**
+ * 组播IP
+ */
+ private String multiCastIp;
+
+ public static final int DATA_LEN = 8 * 1024;
+ byte[] inBuff;
+ /**
+ * 接收的包
+ */
+ private DatagramPacket inPacket;
+ /**
+ * udp
+ */
+ private DatagramSocket socket = null;
+ /**
+ * 带广播的udp
+ */
+ private MulticastSocket mMulticastSocket = null;
+ /**
+ * 第一次获取到接收端的ip
+ */
+ private volatile boolean isFirstReceiverAddress;
+
+ /**
+ * 接口 回调一帧
+ */
+ protected IGetH264Data mGetH264Data;
+
+ private IConnectRtpListener mConnectRtpListener;
+ /**
+ * stop
+ */
+ private volatile boolean isStop;
+
+ /**
+ * 接收的ip地址
+ */
+ private volatile String mReceiveAddress;
+ /**
+ * 暂停状态
+ */
+ protected volatile boolean isPause = false;
+
+ public AbstractUdpImpl(int byteSize) {
+ inBuff = new byte[byteSize];
+ inPacket = new DatagramPacket(inBuff, inBuff.length);
+
+
+ }
+
+ @Override
+ public void onPause() {
+ isPause = true;
+ }
+
+ @Override
+ public void onResume() {
+ isPause = false;
+ }
+
+ @Override
+ public void close() {
+ try {
+ setStop(true);
+ if (mMulticastSocket != null) {
+ mMulticastSocket.close();
+ mMulticastSocket = null;
+ }
+ if (socket != null) {
+ socket.close();
+ socket = null;
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (mConnectRtpListener != null) {
+ mConnectRtpListener = null;
+ }
+ if (mGetH264Data != null) {
+ mGetH264Data = null;
+ }
+ inPacket = null;
+ inBuff = null;
+ }
+ }
+
+ @Override
+ public void setUdpPort(int udpPort) {
+ this.udpPort = udpPort;
+ }
+
+ @Override
+ public void setMultiCast(boolean multiCast) {
+ isMultiCast = multiCast;
+ }
+
+ @Override
+ public synchronized void setStop(boolean stop) {
+ isStop = stop;
+ }
+
+ @Override
+ public void setOnConnectListener(IConnectRtpListener connectRtpListener) {
+ this.mConnectRtpListener = connectRtpListener;
+ }
+
+ @Override
+ public void getVideoInputStreamData(IGetH264Data getH264Data) {
+ this.mGetH264Data = getH264Data;
+ }
+
+ public void setFirstReceiverAddress(boolean firstReceiverAddress) {
+ isFirstReceiverAddress = firstReceiverAddress;
+ }
+
+ @Override
+ public void initBuffer() {
+
+ }
+
+ @Override
+ public void run() {
+ // CupidLogUtils.e(TAG, "---->开始接收数据");
+ try {
+ if (isMultiCast) {
+ mMulticastSocket = new MulticastSocket(udpPort);
+ InetAddress bcAddr = InetAddress.getByName(multiCastIp);
+ mMulticastSocket.setReuseAddress(true);
+ mMulticastSocket.joinGroup(bcAddr);
+ mMulticastSocket.setLoopbackMode(false);
+ } else {
+ CupidLogUtils.e(TAG, "---->开始连接端口" + udpPort + ",stop" + isStop);
+ if (socket == null) {
+ socket = new DatagramSocket(udpPort);
+ socket.setReuseAddress(true);
+ socket.setReceiveBufferSize(32 * 1024);
+ CupidLogUtils.e("--->setReceiveBufferSize:" + socket.getReceiveBufferSize());
+ CupidLogUtils.e(TAG, "---->连接成功" + udpPort);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ CupidLogUtils.e(TAG, "---->udp" + e.getMessage());
+ if (mConnectRtpListener != null) {
+ mConnectRtpListener.onConnectionFailedRtp(e.getMessage());
+ }
+ }
+
+ while (!isStop) {
+ try {
+ if (isMultiCast && mMulticastSocket != null) {
+ mMulticastSocket.receive(inPacket);
+ } else {
+ if (socket != null) {
+ //inPacket.setLength(0);
+ socket.receive(inPacket);
+ }
+ }
+ long receiverDataTimeUdp = System.currentTimeMillis();
+ if (!isFirstReceiverAddress) {
+ if (inPacket.getAddress() != null) {
+ mReceiveAddress = inPacket.getAddress().getHostAddress();
+ CupidLogUtils.e("mReceiveAddress--->mReceiveAddress" + mReceiveAddress);
+ isFirstReceiverAddress = true;
+ if (mConnectRtpListener != null) {
+ mConnectRtpListener.getOnConnectionAddress(mReceiveAddress);
+ }
+ }
+
+ }
+ if (inPacket.getAddress() != null) {
+ parseData(inPacket, receiverDataTimeUdp);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ CupidLogUtils.e("UdpException" + e.getMessage());
+ if (mConnectRtpListener != null) {
+ mConnectRtpListener.onConnectionFailedRtp(e.getMessage());
+ }
+ }
+ }
+
+ }
+
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidRenderImageServer.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidRenderImageServer.java
new file mode 100644
index 0000000000..f35b10635c
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidRenderImageServer.java
@@ -0,0 +1,55 @@
+package com.zhidao.support.adas.high.udp.factory;
+
+import com.zhidao.support.adas.high.udp.IBuffStream;
+
+import java.net.DatagramPacket;
+
+/**
+ * @author nie yunlong
+ * @description 绘制上层数据
+ * @date 2018/7/11
+ */
+public class CupidRenderImageServer extends AbstractUdpImpl {
+
+
+// StringBuilder stringBuilder = new StringBuilder();
+//
+// StringBuilder normalDataBuilder = new StringBuilder();
+ /**
+ * 内容
+ */
+ private String content;
+
+ public CupidRenderImageServer() {
+ super(8*1024);
+ }
+
+
+ /**
+ * 回调真实数据
+ *
+ * @param realData
+ */
+ public void callBackRealData(String realData) {
+ if (realData.contains("<")) {
+ realData.replace("<", "");
+ }
+ if (realData.contains(">")) {
+ realData.replace(">", "");
+ }
+ mGetH264Data.getH264Data(realData.getBytes(),System.currentTimeMillis());
+ }
+
+ @Override
+ public void parseData(DatagramPacket inPacket, long receiverDataTimeUdp) {
+ if (mGetH264Data != null && !isPause) {
+ content = new String(inPacket.getData(), 0, inPacket.getLength());
+ mGetH264Data.getH264Data(content.getBytes(),receiverDataTimeUdp);
+ }
+ }
+
+ @Override
+ public void setBuffStream(IBuffStream buffStream) {
+
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidUdpFactory.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidUdpFactory.java
new file mode 100644
index 0000000000..a5c8c22ca8
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidUdpFactory.java
@@ -0,0 +1,37 @@
+package com.zhidao.support.adas.high.udp.factory;
+
+/**
+ * @author nie yunlong
+ * @description 生产udp对象
+ * @date 2018/7/11
+ */
+public class CupidUdpFactory {
+
+ /**
+ * 创建视频流解析对象
+ *
+ * @return
+ */
+ public static AbstractUdpImpl createVideoStreamUdp() {
+ return new CupidVideoUdpServer();
+ }
+
+ /**
+ * 优化后的接收udp buffer
+ *
+ * @return
+ */
+ public static AbstractUdpImpl createVideoStreamUdp2() {
+ return new CupidVideoUdpServer2();
+ }
+
+ /**
+ * 上层绘制 接收udp 给的数据 解析展示数据
+ *
+ * @return
+ */
+ public static AbstractUdpImpl createRenderImageUdp() {
+ return new CupidRenderImageServer();
+ }
+
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidVideoUdpServer.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidVideoUdpServer.java
new file mode 100644
index 0000000000..a579e76b5f
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidVideoUdpServer.java
@@ -0,0 +1,243 @@
+package com.zhidao.support.adas.high.udp.factory;
+
+
+
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.udp.IBuffStream;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+
+import static com.zhidao.support.adas.high.udp.CupidBufStreamImpl.BUF_SIZE_LIMIT;
+
+
+/**
+ * @author nie yunlong
+ * @description 视频流
+ * @date 2018/7/11
+ */
+public class CupidVideoUdpServer extends AbstractUdpImpl {
+
+ private IBuffStream buffStream;
+
+ private byte[] fu_h_byte;
+
+ /**
+ * 是否是开始第一帧
+ */
+ boolean isBegin = false;
+ /**
+ * 对照h264帧
+ */
+ private int mIndexSeqNo = 0;
+
+ /**
+ * 容错次数
+ */
+ private int mConcernedNumber = 0;
+ /**
+ * 容错常量 2次
+ */
+ private final int CONCERNED_NUMBER_RTP = 5;
+
+ public CupidVideoUdpServer() {
+ super(DATA_LEN);
+ }
+
+
+ @Override
+ public void setBuffStream(IBuffStream buffStream) {
+ this.buffStream = buffStream;
+ }
+
+ /**
+ * 替换rtp头 暴露h264
+ *
+ * @param inPacket
+ * @return
+ */
+ boolean parseRTP(DatagramPacket inPacket) {
+ int naluType = 0;
+ int nalunri = 0;
+ int naluf = 0;
+
+ boolean isEnd = false;
+ //最高位是否是F 1111 ****
+ if ((int) (inBuff[1] >> 7 & 0x01) == 1) {
+ isEnd = true;
+ }
+ //inBuff[3] 是啥数据 就是啥 0xFF 都是1 1111 1111
+ int seq_no = inBuff[3] & 0xFF;
+ //左移 补0 结果是把inBuffer[3]inBuffer[2] 得到数据 获取到的长度
+ seq_no |= (((int) inBuff[2] << 8) & 0xFF00);
+
+// CupidLogUtils.e("seq_no" + seq_no + ",begin=>" + isBegin + ",isEnd=>" + isEnd);
+
+ if (seq_no == 1) { //0001 开始位置
+ isBegin = true;
+ mIndexSeqNo = 1;
+ } else if (seq_no == 65530) { //FFFF 结束一帧
+ isEnd = true;
+ isBegin = false;
+ mIndexSeqNo = 0;
+ }
+
+// boolean isSkip = isCheckConcernedNumer(isEnd);
+//// if (isSkip) {
+//// return false;
+//// }
+
+ if (buffStream.getLength() > BUF_SIZE_LIMIT) {
+ buffStream.close();
+ return false;
+ }
+ byte naluHeader = inBuff[12];
+ naluType = naluHeader & 0x1f; //
+ nalunri = naluHeader >> 5 & 0x03;
+ naluf = naluHeader >> 7 & 0x01;
+ int len = inPacket.getLength();
+// CupidLogUtils.i(TAG, "packet-len:" + len);
+
+ fu_h_byte = new byte[5];
+ fu_h_byte[0] = 0;
+ fu_h_byte[1] = 0;
+ fu_h_byte[2] = 0;
+ fu_h_byte[3] = 1;
+
+ if (28 == naluType) { //0x1C 0001 1100
+ // H264 Begin
+ int fu_type = 0;
+ int fu_r = 0;
+ int fu_e = 0;
+ int fu_s = 0;
+
+ byte fu_header = inBuff[13];
+ fu_type = fu_header & 0x1f;
+ fu_r = fu_header >> 5 & 0x01;
+ fu_e = fu_header >> 6 & 0x01;
+ fu_s = fu_header >> 7 & 0x01;
+
+ if (fu_s == 1) {
+ //buffStream.doSwitch();
+ // start of fu-a
+ fu_h_byte[4] = (byte) ((fu_type & 0x1f) | (nalunri << 5 & 0x60) | (naluf << 7 & 0x80));
+ try {
+ //buffStream.getOutputStream().write(fu_h_byte, 0, 5);
+ buffStream.getOutputStream().write(inBuff, 14, len - 14);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ } else if (1 == fu_e) {
+ // end of fu-a
+ try {
+ if (isBegin || isEnd) {
+ buffStream.getOutputStream().write(inBuff, 14, len - 14);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ } else {
+ // middle of fu-a
+ try {
+ if (isBegin) {
+ buffStream.getOutputStream().write(inBuff, 14, len - 14);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ }
+
+ } else {
+ //TODO 没用上
+ fu_h_byte[4] = (byte) ((naluType & 0x1f) | (nalunri << 5 & 0x60) | (naluf << 7 & 0x80));
+ try {
+ //buffStream.getOutputStream().write(fu_h_byte, 0, 5);
+ buffStream.getOutputStream().write(inBuff, 13, len - 13);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ if (isEnd) {
+ if (mGetH264Data != null) {
+ try {
+ mGetH264Data.getH264Data(buffStream.getData(),System.currentTimeMillis());
+ } catch (OutOfMemoryError outOfMemoryError) {
+ CupidLogUtils.e("===>内存溢出");
+ buffStream.close();
+ System.gc();
+ }
+ }
+ buffStream.doSwitch();
+ }
+ return true;
+ }
+
+ /**
+ * 是否跳过 后边代码
+ *
+ * @param isEnd
+ * @return
+ */
+ private boolean isCheckConcernedNumer(boolean isEnd) {
+ int seq_no = inBuff[3] & 0xFF;
+ seq_no |= (((int) inBuff[2] << 8) & 0xFF00);
+
+ CupidLogUtils.e("seq_no" + seq_no + ",begin=>" + isBegin + ",isEnd=>" + isEnd);
+
+ if (seq_no == 1) {
+ isBegin = true;
+ mIndexSeqNo = 1;
+ } else if (seq_no == 65530) {
+ isEnd = true;
+ isBegin = false;
+ mIndexSeqNo = 0;
+ } else {
+ mIndexSeqNo++;
+ if (mIndexSeqNo != seq_no && mConcernedNumber <= CONCERNED_NUMBER_RTP) {
+ mConcernedNumber++;
+ }
+ if (mConcernedNumber > CONCERNED_NUMBER_RTP) {
+ CupidLogUtils.e("===>超过次数==>mConcernedNumber" + mConcernedNumber);
+ mConcernedNumber = 0;
+ buffStream.doSwitch();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ if (buffStream != null) {
+ buffStream.close();
+ buffStream = null;
+ }
+ }
+
+ @Override
+ public void parseData(DatagramPacket inPacket, long receiverDataTimeUdp) {
+ if (isPause) {
+ buffStream.close();
+ }
+ if (inPacket.getLength() > 0 && !isPause) {
+ CupidLogUtils.w("===》数据包" + inPacket.getLength() + ",string" + new String(inPacket.getData()));
+ parseRTP(inPacket);
+ }
+ }
+
+ @Override
+ public void initBuffer() {
+ super.initBuffer();
+ if (buffStream != null) {
+ buffStream.close();
+ }
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidVideoUdpServer2.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidVideoUdpServer2.java
new file mode 100644
index 0000000000..9d2c434049
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/CupidVideoUdpServer2.java
@@ -0,0 +1,247 @@
+package com.zhidao.support.adas.high.udp.factory;
+
+
+
+import com.zhidao.support.adas.high.common.CupidLogUtils;
+import com.zhidao.support.adas.high.udp.IBuffStream;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+
+import static com.zhidao.support.adas.high.udp.CupidBufStreamImpl2.BUF_SIZE_LIMIT;
+
+
+/**
+ * @author nie yunlong
+ * @description 视频流
+ * @date 2018/7/11
+ */
+public class CupidVideoUdpServer2 extends AbstractUdpImpl {
+
+ private IBuffStream buffStream;
+
+ private byte[] fu_h_byte;
+
+ /**
+ * 是否是开始第一帧
+ */
+ boolean isBegin = false;
+ /**
+ * 对照h264帧
+ */
+ private int mIndexSeqNo = 0;
+
+ /**
+ * 容错次数
+ */
+ private int mConcernedNumber = 0;
+ /**
+ * 容错常量 2次
+ */
+ private final int CONCERNED_NUMBER_RTP = 5;
+
+ public CupidVideoUdpServer2() {
+ super(DATA_LEN);
+ }
+
+
+ @Override
+ public void setBuffStream(IBuffStream buffStream) {
+ this.buffStream = buffStream;
+ }
+
+ /**
+ * 替换rtp头 暴露h264
+ *
+ * @param inPacket
+ * @return
+ */
+ boolean parseRTP(DatagramPacket inPacket) {
+ int naluType = 0;
+ int nalunri = 0;
+ int naluf = 0;
+
+ boolean isEnd = false;
+ //最高位是否是F 1111 ****
+ if ((int) (inBuff[1] >> 7 & 0x01) == 1) {
+ isEnd = true;
+ }
+ //inBuff[3] 是啥数据 就是啥 0xFF 都是1 1111 1111
+ int seq_no = inBuff[3] & 0xFF;
+ //左移 补0 结果是把inBuffer[3]inBuffer[2] 得到数据 获取到的长度
+ seq_no |= (((int) inBuff[2] << 8) & 0xFF00);
+
+// CupidLogUtils.e("seq_no" + seq_no + ",begin=>" + isBegin + ",isEnd=>" + isEnd);
+
+ if (seq_no == 1) { //0001 开始位置
+ //如果在开始有问题 reset
+ if (buffStream.getLength() > 0) {
+ buffStream.doSwitch();
+ }
+ isBegin = true;
+ mIndexSeqNo = 1;
+ } else if (seq_no == 65530) { //FFFF 结束一帧
+ isEnd = true;
+ isBegin = false;
+ mIndexSeqNo = 0;
+ }
+
+// boolean isSkip = isCheckConcernedNumer(isEnd);
+//// if (isSkip) {
+//// return false;
+//// }
+
+ if (buffStream.getLength() > BUF_SIZE_LIMIT) {
+ buffStream.close();
+ return false;
+ }
+ byte naluHeader = inBuff[12];
+ naluType = naluHeader & 0x1f; //
+ nalunri = naluHeader >> 5 & 0x03;
+ naluf = naluHeader >> 7 & 0x01;
+ int len = inPacket.getLength();
+// CupidLogUtils.i(TAG, "packet-len:" + len);
+
+ fu_h_byte = new byte[5];
+ fu_h_byte[0] = 0;
+ fu_h_byte[1] = 0;
+ fu_h_byte[2] = 0;
+ fu_h_byte[3] = 1;
+
+ if (28 == naluType) { //0x1C 0001 1100
+ // H264 Begin
+ int fu_type = 0;
+ int fu_r = 0;
+ int fu_e = 0;
+ int fu_s = 0;
+
+ byte fu_header = inBuff[13];
+ fu_type = fu_header & 0x1f;
+ fu_r = fu_header >> 5 & 0x01;
+ fu_e = fu_header >> 6 & 0x01;
+ fu_s = fu_header >> 7 & 0x01;
+
+ if (fu_s == 1) {
+ //buffStream.doSwitch();
+ // start of fu-a
+ fu_h_byte[4] = (byte) ((fu_type & 0x1f) | (nalunri << 5 & 0x60) | (naluf << 7 & 0x80));
+ try {
+ //buffStream.getOutputStream().write(fu_h_byte, 0, 5);
+ buffStream.getOutputStream().write(inBuff, 14, len - 14);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ } else if (1 == fu_e) {
+ // end of fu-a
+ try {
+ if (isBegin || isEnd) {
+ buffStream.getOutputStream().write(inBuff, 14, len - 14);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ } else {
+ // middle of fu-a
+ try {
+ if (isBegin) {
+ buffStream.getOutputStream().write(inBuff, 14, len - 14);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ }
+
+ } else {
+ //TODO 没用上
+ fu_h_byte[4] = (byte) ((naluType & 0x1f) | (nalunri << 5 & 0x60) | (naluf << 7 & 0x80));
+ try {
+ //buffStream.getOutputStream().write(fu_h_byte, 0, 5);
+ buffStream.getOutputStream().write(inBuff, 13, len - 13);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ if (isEnd) {
+ if (mGetH264Data != null) {
+ try {
+ mGetH264Data.getH264Data(buffStream.getData(),System.currentTimeMillis());
+ } catch (OutOfMemoryError outOfMemoryError) {
+ CupidLogUtils.e("===>内存溢出");
+ buffStream.close();
+ System.gc();
+ }
+ }
+ buffStream.doSwitch();
+ }
+ return true;
+ }
+
+ /**
+ * 是否跳过 后边代码
+ *
+ * @param isEnd
+ * @return
+ */
+ private boolean isCheckConcernedNumer(boolean isEnd) {
+ int seq_no = inBuff[3] & 0xFF;
+ seq_no |= (((int) inBuff[2] << 8) & 0xFF00);
+
+ CupidLogUtils.e("seq_no" + seq_no + ",begin=>" + isBegin + ",isEnd=>" + isEnd);
+
+ if (seq_no == 1) {
+ isBegin = true;
+ mIndexSeqNo = 1;
+ } else if (seq_no == 65530) {
+ isEnd = true;
+ isBegin = false;
+ mIndexSeqNo = 0;
+ } else {
+ mIndexSeqNo++;
+ if (mIndexSeqNo != seq_no && mConcernedNumber <= CONCERNED_NUMBER_RTP) {
+ mConcernedNumber++;
+ }
+ if (mConcernedNumber > CONCERNED_NUMBER_RTP) {
+ CupidLogUtils.e("===>超过次数==>mConcernedNumber" + mConcernedNumber);
+ mConcernedNumber = 0;
+ buffStream.doSwitch();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ if (buffStream != null) {
+ buffStream.close();
+ buffStream = null;
+ }
+ }
+
+ @Override
+ public void parseData(DatagramPacket inPacket, long receiverDataTimeUdp) {
+ if (isPause) {
+ buffStream.close();
+ }
+ if (inPacket.getLength() > 12 && !isPause) {
+ CupidLogUtils.w("===》数据包" + inPacket.getLength() + ",string" + new String(inPacket.getData()));
+ parseRTP(inPacket);
+ }
+ }
+
+ @Override
+ public void initBuffer() {
+ super.initBuffer();
+ if (buffStream != null) {
+ buffStream.close();
+ }
+ }
+}
diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/IUdpAction.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/IUdpAction.java
new file mode 100644
index 0000000000..bfff270c14
--- /dev/null
+++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/udp/factory/IUdpAction.java
@@ -0,0 +1,88 @@
+package com.zhidao.support.adas.high.udp.factory;
+
+
+
+import com.zhidao.support.adas.high.udp.IBuffStream;
+import com.zhidao.support.adas.high.udp.IConnectRtpListener;
+import com.zhidao.support.adas.high.udp.IGetH264Data;
+
+import java.net.DatagramPacket;
+
+/**
+ * @author nie yunlong
+ * @description udp 抽象方法
+ * @date 2018/7/11
+ */
+public interface IUdpAction {
+
+ /**
+ * udp 关闭释放资源
+ */
+ void close();
+
+ /**
+ * set udp port
+ *
+ * @param udpPort
+ */
+ void setUdpPort(int udpPort);
+
+ /**
+ * 设置广播模式
+ *
+ * @param multiCast
+ */
+ void setMultiCast(boolean multiCast);
+
+ /**
+ * 停止udp 线程
+ *
+ * @param stop
+ */
+ void setStop(boolean stop);
+
+ /**
+ * 设置socket 连接状态监听
+ *
+ * @param connectRtpListener
+ */
+ void setOnConnectListener(IConnectRtpListener connectRtpListener);
+
+ /**
+ * 获取udp数据
+ *
+ * @param getH264Data
+ */
+ void getVideoInputStreamData(IGetH264Data getH264Data);
+
+ /**
+ * 解析接收到数据包
+ *
+ * @param inPacket
+ */
+ void parseData(DatagramPacket inPacket,long receiverDataTimeUdp);
+
+
+ /**
+ * 设置buffer
+ *
+ * @param buffStream
+ */
+ void setBuffStream(IBuffStream buffStream);
+
+ /**
+ * onPause
+ */
+ void onPause();
+
+ /**
+ * onResume
+ */
+ void onResume();
+
+ /**
+ * init buffer 服务器关闭 初始化数据
+ */
+ void initBuffer();
+
+}
diff --git a/libraries/mogo-adas/src/main/proto/adas.proto b/libraries/mogo-adas/src/main/proto/adas.proto
new file mode 100644
index 0000000000..f8b5478853
--- /dev/null
+++ b/libraries/mogo-adas/src/main/proto/adas.proto
@@ -0,0 +1,87 @@
+syntax = "proto2";
+package adas;
+
+enum CarLocation
+{
+ Same_LINE = 0;
+ Left_LINE = 1;
+ Right_LINE = 2;
+ left2_LINE = 3;
+ Right2_LINE = 4;
+}
+
+enum ActionType
+{
+ action_type_view = 1;
+ action_type_obstacles = 2;
+ action_type_lanes = 3;
+ action_type_state = 4;
+ action_type_warn = 5;
+ action_type_light = 6;
+ action_type_config = 7;
+ action_type_gdgps = 8;
+ action_type_auto_pilot_state = 9;
+ action_type_auto_pilot_mode = 10;
+ action_type_obu_traffic_light = 11;
+ action_type_ai_cloud_to_start_autopilot = 12;
+}
+
+message View
+{
+ optional int32 xl = 1;
+ optional int32 yt = 2;
+ optional int32 xr = 3;
+ optional int32 yb = 4;
+ //物体类型
+ optional string type = 5;
+ optional CarLocation showImageLocation = 6;
+ //距离x轴值
+ optional double distance_x = 7;
+ //距离y轴值
+ optional double distance_y = 8;
+ //经度
+ optional double lon = 9;
+ //纬度
+ optional double lat = 10;
+ //海拔
+ optional double alt = 11;
+ //系统时间
+ optional string systemTime = 12;
+ //gps时间
+ optional string satelliteTime = 13;
+ //车辆id
+ optional string uuid = 14;
+ //车牌id
+ optional string carId = 15;
+ //车辆颜色
+ optional string color = 16;
+ //车辆朝向
+ optional double heading = 17;
+ //车辆速度
+ optional double speed = 18;
+ //长
+ optional float length = 19;
+ //宽
+ optional float width = 20;
+ //高
+ optional float height = 21;
+ //危险等级 1 绿,2 黄,3 红
+ optional int32 drawlevel = 22;
+ //驱动感知时间
+ optional string driverTime = 23;
+}
+
+
+// 渲染流消息
+message ViwesMsg
+{
+ optional string action = 1;
+ repeated View models = 2;
+}
+
+
+
+
+
+
+
diff --git a/libraries/mogo-adas/src/main/proto/car_status.proto b/libraries/mogo-adas/src/main/proto/car_status.proto
new file mode 100644
index 0000000000..6f4f477051
--- /dev/null
+++ b/libraries/mogo-adas/src/main/proto/car_status.proto
@@ -0,0 +1,42 @@
+syntax = "proto3";
+package mogo.status;
+
+
+message Status
+{
+ //经度
+ double lon = 1;
+ //纬度
+ double lat = 2;
+ //海拔
+ double alt = 3;
+ //航向角
+ double heading = 4;
+ //加速度
+ double acceleration = 5;
+ //曲率
+ double yaw_rate = 6;
+ //惯导车速 m/s
+ float gnss_speed = 7;
+ //车辆车速 m/s
+ float vehicle_speed = 8;
+ //gps时间
+ string satelliteTime = 9;
+ //系统时间
+ string systemTime = 10;
+ //转向灯状态
+ int32 turn_light = 11;
+ //双闪灯状态
+ int32 flash_light = 12;
+ //刹车灯状态
+ int32 brake_light = 13;
+ //统计包个数
+ int32 frame_num = 14;
+}
+
+
+
+
+
+
+
diff --git a/libraries/mogo-adas/src/main/proto/geometry.proto b/libraries/mogo-adas/src/main/proto/geometry.proto
new file mode 100644
index 0000000000..9910b32a10
--- /dev/null
+++ b/libraries/mogo-adas/src/main/proto/geometry.proto
@@ -0,0 +1,84 @@
+syntax = "proto2";
+package geometry;
+
+message Vector3 {
+ optional double x = 1;
+ optional double y = 2;
+ optional double z = 3;
+}
+
+message Vector3f {
+ optional float x = 1;
+ optional float y = 2;
+ optional float z = 3;
+}
+
+message Point2D {
+ optional double x = 1 [default = nan];
+ optional double y = 2 [default = nan];
+}
+
+message Point3D {
+ optional double x = 1 [default = nan];
+ optional double y = 2 [default = nan];
+ optional double z = 3 [default = nan];
+}
+
+message Trace {
+ optional double timestamp = 1;
+ optional Point3D position = 2;
+ optional Point3D velocity = 3;
+ optional Point3D acceleration = 4;
+ optional Point3D heading = 5;
+}
+
+message PointLLH {
+ // Longitude in degrees, ranging from -180 to 180.
+ optional double lon = 1 [default = nan];
+ // Latitude in degrees, ranging from -90 to 90.
+ optional double lat = 2 [default = nan];
+ // WGS-84 ellipsoid height in meters.
+ optional double height = 3 [default = 0.0];
+}
+
+message Point {
+ optional double x = 1;
+ optional double y = 2;
+ optional double z = 3;
+}
+
+message Quaternion {
+ optional double x = 1 [default = nan];
+ optional double y = 2 [default = nan];
+ optional double z = 3 [default = nan];;
+ optional double w = 4 [default = nan];
+}
+
+message Polygon {
+ repeated Point points = 1;
+}
+
+message Transform {
+ optional Vector3 translation = 1;
+ optional Quaternion rotation = 2;
+}
+
+//pose in free space, composed of position and orientation
+message Pose {
+ optional Point position = 1;
+ optional Quaternion orientation = 2;
+}
+
+//acceleration in free space broken into its linear and angular parts
+message Accel {
+ optional Vector3 linear = 1;
+ optional Vector3 angular = 2;
+}
+
+//velocity in free space broken into its linear and angular parts
+message Twist {
+ optional Vector3 linear = 1;
+ optional Vector3 angular = 2;
+}
+
+
diff --git a/libraries/mogo-adas/src/main/proto/header.proto b/libraries/mogo-adas/src/main/proto/header.proto
new file mode 100644
index 0000000000..2a50a1702d
--- /dev/null
+++ b/libraries/mogo-adas/src/main/proto/header.proto
@@ -0,0 +1,23 @@
+syntax = "proto2";
+
+package common;
+
+message Time {
+ optional uint32 sec = 1;
+ optional uint32 nsec = 2;
+}
+
+message Header {
+ // Sequence number for each message. Each module maintains its own counter for
+ // sequence_num, always starting from 1 on boot.
+ optional uint32 seq = 1;
+
+ // Message publishing time in seconds.
+ optional Time stamp = 2;
+
+ // frame id
+ optional string frame_id = 3;
+
+ // Module name.
+ optional string module_name = 4;
+}
diff --git a/libraries/mogo-adas/src/main/proto/mogo_guardian.proto b/libraries/mogo-adas/src/main/proto/mogo_guardian.proto
new file mode 100644
index 0000000000..27e5946a47
--- /dev/null
+++ b/libraries/mogo-adas/src/main/proto/mogo_guardian.proto
@@ -0,0 +1,76 @@
+syntax = "proto3";
+package mogo.guardian;
+/*
+message xxx {
+ // 字段规则:required -> 字段只能也必须出现 1 次. proto3中移除了required
+ // 字段规则:optional -> 字段可出现 0 次或1次
+ // 字段规则:repeated -> 字段可出现任意多次(包括 0)
+ // 类型:int32、int64、sint32、sint64、string、32-bit ....
+ // 字段编号:0 ~ 536870911(除去 19000 到 19999 之间的数字)
+ 字段规则 类型 名称 = 字段编号;
+}
+*/
+/* 监控实体 */
+message GuardianProto {
+/* i接口名成*/
+ string action = 1;
+/* 监控项名称*/
+ string agentName = 2;
+/* 车牌号*/
+ string carNum = 3;
+/* 工控机mac地址*/
+ string macAddr = 4;
+/* 车型*/
+ string carType = 5;
+/* 监控类型*/
+ string monitorType = 6;
+/* sn*/
+ string sn = 7;
+/* 时间*/
+ uint64 time = 8;
+/* 模块*/
+ Modules modules = 9;
+}
+
+/* 模块*/
+message Modules {
+/* 子项*/
+ repeated ItemsName itemsname = 1;
+/* 子模块*/
+ repeated SubModules submodules = 2;
+}
+
+/* 子项*/
+message ItemsName {
+/* 子项名称*/
+ string name = 1;
+/* 子项键值属性*/
+ repeated Items items = 2;
+}
+/* 键值对*/
+message Items {
+/* key*/
+ string name = 1;
+/* value*/
+ string value = 2;
+
+}
+/* 子模块*/
+message SubModules {
+/* 子模块名称*/
+ string modulename = 1;
+/* 子节点*/
+ repeated SubNode subnodes = 2;
+
+}
+
+/* 模块中的节点*/
+message SubNode{
+/* 节点名称*/
+ string nodename = 1;
+/* 节点项*/
+ repeated Items nodeitems = 2;
+/* *topic项*/
+ repeated ItemsName topicitems = 3;
+}
+
diff --git a/libraries/mogo-adas/src/main/proto/route_list.proto b/libraries/mogo-adas/src/main/proto/route_list.proto
new file mode 100644
index 0000000000..407ca0563c
--- /dev/null
+++ b/libraries/mogo-adas/src/main/proto/route_list.proto
@@ -0,0 +1,27 @@
+syntax = "proto2";
+
+package hadmap;
+
+import "geometry.proto";
+import "header.proto";
+
+message RouteInfo {
+ optional string id = 1;
+ optional geometry.Point start = 2;//经纬度坐标
+ optional string start_eng = 3; //起点拼音大写
+ optional string start_chn = 4; //起点中文名
+ optional geometry.Point end = 5;//经纬度坐标
+ optional string end_eng = 6; //终点拼音大写
+ optional string end_chn = 7; //终点中文名
+ optional string traj_file_path = 8; // file path+file name
+ optional int32 vehicle_type = 9;
+ optional string time = 10;
+ optional string comment = 11;
+}
+
+message RouteList {
+ optional common.Header header = 1;
+ optional uint32 routes_count = 2;
+ repeated RouteInfo routes_info = 3;
+}
+
diff --git a/libraries/mogo-adas/src/main/proto/trajectory.proto b/libraries/mogo-adas/src/main/proto/trajectory.proto
new file mode 100644
index 0000000000..afd61c757c
--- /dev/null
+++ b/libraries/mogo-adas/src/main/proto/trajectory.proto
@@ -0,0 +1,18 @@
+syntax = "proto3";
+package mogo.trajectory;
+
+message TrajectoryPoint {
+ double x = 1;
+ double y = 2;
+ double z = 3;
+ double t = 4; //time in seconds
+ double v = 5; //velocity in m/s
+ double a = 6; //acceleration in m/s^26766
+ double theta = 7; //direction of v
+ double kappa = 8; //curvature
+ double s = 9; //accumulated distance in meters from beginning
+}
+
+message Trajectory {
+ repeated TrajectoryPoint points = 1;
+}
diff --git a/libraries/mogo-adas/src/main/proto/websocket_header.proto b/libraries/mogo-adas/src/main/proto/websocket_header.proto
new file mode 100644
index 0000000000..909787d1d3
--- /dev/null
+++ b/libraries/mogo-adas/src/main/proto/websocket_header.proto
@@ -0,0 +1,25 @@
+syntax = "proto3";
+package mogo.webproto;
+
+enum Constants {
+ DEFAULT = 0x0000; //0
+ Magic = 0x6d67; //"mg"
+}
+
+/************************Head Def***********************/
+/*******************************************************/
+
+message Header_websock {
+ uint32 msgType = 1; //payload type, enum @PacketType
+}
+
+
+enum MsgType_websock {
+ mogo_DEFAULT = 0x000; // 0
+ mogoTrajectory = 0x100; // 轨迹规划
+ mogoAdas = 0x101; //adas数据
+ mogoCar = 0x102; //自车数据
+ mogoDataCollect = 0x103; //数据采集文件
+ mogoRoutList = 0x104; //maplist
+ mogoGuardian = 0x105; //监控
+}
diff --git a/libraries/mogo-adas/src/main/res/values/strings.xml b/libraries/mogo-adas/src/main/res/values/strings.xml
index f02e39594e..9e8787cc20 100644
--- a/libraries/mogo-adas/src/main/res/values/strings.xml
+++ b/libraries/mogo-adas/src/main/res/values/strings.xml
@@ -1,3 +1,3 @@
- mogo-adas
+ adas-high