[sweeper310] 增加调试按钮从文件读取下发启动自驾命令参数
This commit is contained in:
53
OCH/sweeper/sweeper-cloud/AutopilotModeConfig.json
Normal file
53
OCH/sweeper/sweeper-cloud/AutopilotModeConfig.json
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"mode": 1,
|
||||
"source": 1,
|
||||
"routeInfo": {
|
||||
"startLocation": {
|
||||
"longitude": 2.1,
|
||||
"latitude": 2.2,
|
||||
"altitude": 2.3,
|
||||
"heading": 2.4
|
||||
},
|
||||
"startName": "name1",
|
||||
"endLocation": {
|
||||
"longitude": 3.1,
|
||||
"latitude": 3.2,
|
||||
"altitude": 3.3,
|
||||
"heading": 3.4
|
||||
},
|
||||
"endName": "name2",
|
||||
"wayPoints": [
|
||||
{
|
||||
"longitude": 4.1,
|
||||
"latitude": 4.2,
|
||||
"altitude": 4.3,
|
||||
"heading": 4.4
|
||||
},
|
||||
{
|
||||
"longitude": 5.1,
|
||||
"latitude": 5.2,
|
||||
"altitude": 5.3,
|
||||
"heading": 5.4
|
||||
}
|
||||
],
|
||||
"speedLimit": 8.8,
|
||||
"vehicleType": 1,
|
||||
"isSpeakVoice": true,
|
||||
"routeID": 2,
|
||||
"routeName": "name3",
|
||||
"line": {
|
||||
"lineId": 1234567,
|
||||
"trajUrl": "trajUrl1",
|
||||
"trajMd5": "trajMd52",
|
||||
"stopUrl": "stopUrl3",
|
||||
"stopMd5": "stopMd54",
|
||||
"timestamp": 987654321,
|
||||
"vehicleModel": "vehicleModel5",
|
||||
"trajUrl_dpqp": "trajUrl_dpqp6",
|
||||
"trajMd5_dpqp": "trajMd5_dpqp7",
|
||||
"stopUrl_dpqp": "stopUrl_dpqp8",
|
||||
"stopMd5_dpqp": "stopMd5_dpqp9",
|
||||
"timestamp_dpqp": 101
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,30 @@
|
||||
package com.mogo.och.sweepercloud.fragment;
|
||||
|
||||
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_SWEEPER;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.elegant.network.utils.GsonUtil;
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters;
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager;
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotRecordListenerManager;
|
||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager;
|
||||
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager;
|
||||
@@ -20,19 +33,24 @@ import com.mogo.eagle.core.function.hmi.ui.msgbox.DriverMsgBoxBubbleView;
|
||||
import com.mogo.eagle.core.function.hmi.ui.msgbox.DriverMsgBoxButtonView;
|
||||
import com.mogo.eagle.core.function.hmi.ui.msgbox.DriverMsgBoxListView;
|
||||
import com.mogo.eagle.core.function.view.MapBizView;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
import com.mogo.eagle.core.utilcode.mogo.view.OnPreventFastClickListener;
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.listener.MogoMapListenerHandler;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.map.uicontroller.VisualAngleMode;
|
||||
import com.mogo.och.common.module.manager.OCHAdasAbilityManager;
|
||||
import com.mogo.och.common.module.utils.PinYinUtil;
|
||||
import com.mogo.och.sweepercloud.R;
|
||||
import com.mogo.och.sweepercloud.bean.SweeperRoutePlanningUpdateReqBean;
|
||||
import com.mogo.och.sweepercloud.callback.ISweeperTaskDataToFragmentCallback;
|
||||
import com.mogo.och.sweepercloud.callback.IWeltMapSwitchToSmallCallback;
|
||||
import com.mogo.och.sweepercloud.database.bean.WeltDataBean;
|
||||
import com.mogo.och.sweepercloud.util.AutopilotModeConfigManager;
|
||||
import com.mogo.och.sweepercloud.util.SweeperCloudTaskUtils;
|
||||
import com.mogo.och.sweepercloud.view.SweeperTrafficDataView;
|
||||
import com.mogo.och.sweepercloud.view.WeltSmallMapView;
|
||||
@@ -42,10 +60,7 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
* 网约车基础Fragment,主要负责布局通用界面,处理站点面板和通话面板互斥情况
|
||||
@@ -115,6 +130,57 @@ public abstract class BaseSweeperTabFragment<V extends IView, P extends Presente
|
||||
setMessageBox();
|
||||
//设置左下角四个按钮监听事件
|
||||
setBottomBtnListener();
|
||||
// 模拟 下发启动自驾命令
|
||||
findViewById(R.id.btnStartAutopilot).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!FunctionBuildConfig.isDemoMode && !OCHAdasAbilityManager.getInstance().getAutopilotAbilityStatus()) {
|
||||
ToastUtils.showLong(OCHAdasAbilityManager.getInstance().getAutopilotUnAbilityReason() + ", 请稍候重试");
|
||||
return;
|
||||
}
|
||||
new AutopilotModeConfigManager(new AutopilotModeConfigManager.OnReadAutopilotModeConfigListener() {
|
||||
@Override
|
||||
public void onReadFailed(String err) {
|
||||
ThreadUtils.runOnUiThread(() -> {
|
||||
ToastUtils.showLong("读取失败=" + err);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParseFailed(String err) {
|
||||
ToastUtils.showLong("解析失败=" + err);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParse(MessagePad.SetAutopilotModeReq bean) {
|
||||
ToastUtils.showLong("下发命令\n" + TextFormat.printer().escapingNonAscii(false).printToString(bean));
|
||||
AutopilotControlParameters parameters = new AutopilotControlParameters();
|
||||
MessagePad.RouteInfo routeInfo = bean.getRouteInfo();
|
||||
if (routeInfo.getRouteID() > 0) {
|
||||
parameters.routeID = routeInfo.getRouteID();
|
||||
}
|
||||
parameters.routeName = routeInfo.getRouteName();
|
||||
parameters.startName = routeInfo.getStartName();//拼音
|
||||
parameters.endName = routeInfo.getEndName();//拼音
|
||||
parameters.startLatLon = new AutopilotControlParameters
|
||||
.AutoPilotLonLat(routeInfo.getStartLocation().getLatitude(), routeInfo.getStartLocation().getLongitude());
|
||||
parameters.endLatLon = new AutopilotControlParameters
|
||||
.AutoPilotLonLat(routeInfo.getEndLocation().getLatitude(), routeInfo.getEndLocation().getLongitude());
|
||||
parameters.vehicleType = 10;
|
||||
MessagePad.Line line = routeInfo.getLine();
|
||||
parameters.autoPilotLine = new AutopilotControlParameters.AutoPilotLine(
|
||||
line.getLineId(),
|
||||
line.getTrajUrl(), line.getTrajMd5(),
|
||||
line.getStopUrl(), line.getStopMd5(),
|
||||
line.getTimestamp(), line.getVehicleModel(),
|
||||
line.getTrajUrlDpqp(), line.getTrajMd5Dpqp(),
|
||||
line.getStopUrlDpqp(), line.getStopMd5Dpqp(),
|
||||
line.getTimestampDpqp());
|
||||
CallerAutoPilotControlManager.INSTANCE.startAutoPilot(parameters);
|
||||
}
|
||||
}).read();
|
||||
}
|
||||
});
|
||||
// 模拟 查询当前任务
|
||||
findViewById(R.id.btnQueryCurrentTask).setOnClickListener(view ->
|
||||
SweeperCloudTaskUtils.mockQueryCurrentTaskInfo()
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.mogo.och.sweepercloud.util;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.util.JsonFormat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
* 读取启动自动驾驶配置
|
||||
*/
|
||||
public class AutopilotModeConfigManager {
|
||||
private final static String TAG = AutopilotModeConfigManager.class.getSimpleName();
|
||||
private final AtomicBoolean isReadConfig = new AtomicBoolean(false);
|
||||
private OnReadAutopilotModeConfigListener listener;
|
||||
|
||||
|
||||
public interface OnReadAutopilotModeConfigListener {
|
||||
void onReadFailed(String err);//文件不存在或读取失败
|
||||
|
||||
void onParseFailed(String err);//配置文件解析失败
|
||||
|
||||
void onParse(MessagePad.SetAutopilotModeReq bean);//解析完成
|
||||
}
|
||||
|
||||
public AutopilotModeConfigManager(OnReadAutopilotModeConfigListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
||||
public void registerListener(OnReadAutopilotModeConfigListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void unregisterListener() {
|
||||
listener = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取配置文件
|
||||
*
|
||||
* @return 是否调用成功
|
||||
*/
|
||||
public boolean read() {
|
||||
if (!isReadConfig.get()) {
|
||||
isReadConfig.set(true);
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Pair<String, String> config = readFilesToString(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "AutopilotModeConfig.json"));
|
||||
if (TextUtils.isEmpty(config.first)) {
|
||||
if (listener != null) {
|
||||
listener.onReadFailed(config.second);
|
||||
}
|
||||
} else {
|
||||
MessagePad.SetAutopilotModeReq.Builder builder = MessagePad.SetAutopilotModeReq.newBuilder();
|
||||
String err = null;
|
||||
try {
|
||||
JsonFormat.parser().ignoringUnknownFields().merge(config.first, builder);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
e.printStackTrace();
|
||||
err = e.getMessage();
|
||||
}
|
||||
if (TextUtils.isEmpty(err)) {
|
||||
MessagePad.SetAutopilotModeReq bean = builder.build();
|
||||
if (listener != null) {
|
||||
listener.onParse(bean);
|
||||
}
|
||||
} else {
|
||||
if (listener != null) {
|
||||
listener.onParseFailed(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
isReadConfig.set(false);
|
||||
}
|
||||
};
|
||||
new Thread(runnable).start();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* @return first:读取到的内容 second:失败信息
|
||||
*/
|
||||
private Pair<String, String> readFilesToString(File file) {
|
||||
InputStream inputStream = null;
|
||||
String err = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
byte[] buffer = new byte[1024];
|
||||
int length = -1;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
while ((length = inputStream.read(buffer)) != -1) {
|
||||
stringBuilder.append(new String(buffer, 0, length));
|
||||
}
|
||||
return new Pair<String, String>(stringBuilder.toString(), err);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
err = e.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
err = e.toString();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Pair<String, String>(null, err);
|
||||
}
|
||||
}
|
||||
@@ -183,17 +183,25 @@
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnStartAutopilot"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_200"
|
||||
android:background="#aa0"
|
||||
android:text="下发启动自驾命令"
|
||||
android:textSize="30sp"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<Button
|
||||
android:id="@+id/btnQueryCurrentTask"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_200"
|
||||
android:background="#f80"
|
||||
android:text="pad查询当前任务"
|
||||
android:textSize="30sp"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintRight_toRightOf="@+id/btnStartAutopilot"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnStartAutopilot" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSendTask"
|
||||
|
||||
Reference in New Issue
Block a user