fixed conflict
This commit is contained in:
@@ -0,0 +1,799 @@
|
||||
package com.zhidao.adas.magic.ui;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.provider.Settings;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListPopupWindow;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.AppCompatButton;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils;
|
||||
import com.zhidao.adas.magic.R;
|
||||
import com.zhidao.adas.magic.adapter.InfoTitleAdapter;
|
||||
import com.zhidao.adas.magic.base.BaseActivity;
|
||||
import com.zhidao.adas.magic.base.BaseAdapter;
|
||||
import com.zhidao.adas.magic.bean.IPCConnectState;
|
||||
import com.zhidao.adas.magic.bean.TitleBean;
|
||||
import com.zhidao.adas.magic.utils.Constants;
|
||||
import com.zhidao.support.adas.high.AdasManager;
|
||||
import com.zhidao.support.adas.high.AdasOptions;
|
||||
import com.zhidao.support.adas.high.OnAdasConnectStatusListener;
|
||||
import com.zhidao.support.adas.high.OnAdasListener;
|
||||
import com.zhidao.support.adas.high.bean.VersionCompatibility;
|
||||
import com.zhidao.support.adas.high.common.Constants.IPC_CONNECTION_STATUS;
|
||||
import com.zhidao.support.adas.high.common.CupidLogUtils;
|
||||
import com.zhidao.support.adas.high.common.ProtocolStatus;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import chassis.VehicleStateOuterClass;
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
import mogo_msg.MogoReportMsg;
|
||||
import perception.TrafficLightOuterClass;
|
||||
import prediction.Prediction;
|
||||
import record_cache.RecordPanelOuterClass;
|
||||
import rule_segement.MogoPointCloudOuterClass;
|
||||
import system_master.SystemStatusInfo;
|
||||
|
||||
public class MainActivity extends BaseActivity implements OnAdasListener, OnAdasConnectStatusListener, BaseAdapter.OnItemClickListener<TitleBean> {
|
||||
private final static String TAG = MainActivity.class.getSimpleName();
|
||||
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault());
|
||||
private static final String GNSS_HINT = "%s\n经度:%f 纬度:%f 海拔:%f 航向角:%f 加速度:%f 曲率:%f 惯导车速:%f 车辆车速:%f";
|
||||
|
||||
private static final int WHAT_IPC_IP = 0x00;
|
||||
private static final int WHAT_IPC_CONNECT_STATE = 0x01;
|
||||
private static final int WHAT_UPDATE_GNSS = 0x02;
|
||||
private EditText etIp;
|
||||
private ImageView tvIp;
|
||||
private TextView title;
|
||||
private TextView ipcIp;
|
||||
private TextView localIp;
|
||||
private RadioGroup connectionType;
|
||||
private AppCompatButton connect;
|
||||
private AppCompatButton disconnect;
|
||||
private RadioButton fixation;
|
||||
private RadioButton assign;
|
||||
private RecyclerView infoBtn;
|
||||
private TextView tvConnectState;
|
||||
private TextView gnss_hint;
|
||||
private InfoTitleAdapter btnAdapter;
|
||||
private Timer timerHorn;
|
||||
private Timer timerAcc;
|
||||
private final List<TitleBean> titleBtnData = new ArrayList<>();
|
||||
private final List<IPCConnectState> connectStatusList = new ArrayList<>();
|
||||
private boolean isPad;
|
||||
private int connectStatus;
|
||||
private ListPopupWindow listPopupWindow;
|
||||
private FloatWindow floatWindow;
|
||||
private View include_title;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
initHandler();
|
||||
isPad = isPad(this);
|
||||
if (!isPad)
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
initView();
|
||||
initAdas();
|
||||
connectStatus = AdasManager.getInstance().getIpcConnectionStatus();
|
||||
onUpdateConnectStateView();
|
||||
showIPCIP();
|
||||
AdasManager.getInstance().setEnableLog(false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AdasManager.getInstance().setOnAdasListener(null);
|
||||
AdasManager.getInstance().disconnect();
|
||||
if (floatWindow != null) {
|
||||
floatWindow.hideFloatWindow();
|
||||
floatWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canDrawOverlays() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (!Settings.canDrawOverlays(this)) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("权限申请")
|
||||
.setMessage("请找到“" + getString(R.string.app_name) + "”授予悬浮窗权限")
|
||||
.setPositiveButton("去授予",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())));
|
||||
}
|
||||
}).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void connect(boolean isConnect) {
|
||||
if (isConnect) {
|
||||
switch (Constants.getIpcConnectionMode(this)) {
|
||||
case AdasOptions.IPC_CONNECTION_MODE.FIXATION:
|
||||
AdasManager.getInstance().getAdasOptions().setIpcFixationIP(AdasManager.getInstance().getIPCFixationIPList(this));
|
||||
break;
|
||||
case AdasOptions.IPC_CONNECTION_MODE.ASSIGN:
|
||||
String ip = etIp.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(ip)) {
|
||||
Toast.makeText(this, "请输入指定IP", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
AdasManager.getInstance().getAdasOptions().setIpcAssignIP(ip);
|
||||
break;
|
||||
}
|
||||
AdasManager.getInstance().getAdasOptions().setIpcConnectionMode(Constants.getIpcConnectionMode(this));
|
||||
AdasManager.getInstance().connect();
|
||||
} else
|
||||
AdasManager.getInstance().disconnect();
|
||||
}
|
||||
|
||||
|
||||
private void initView() {
|
||||
gnss_hint = findViewById(R.id.gnss_hint);
|
||||
include_title = findViewById(R.id.include_title);
|
||||
etIp = findViewById(R.id.et_ip);
|
||||
connectionType = findViewById(R.id.connection_type);
|
||||
tvIp = findViewById(R.id.tv_ip);
|
||||
connect = findViewById(R.id.connect);
|
||||
disconnect = findViewById(R.id.disconnect);
|
||||
fixation = findViewById(R.id.fixation);
|
||||
assign = findViewById(R.id.assign);
|
||||
|
||||
title = findViewById(R.id.title);
|
||||
infoBtn = findViewById(R.id.info_btn);
|
||||
tvConnectState = findViewById(R.id.tv_connect_state);
|
||||
ipcIp = findViewById(R.id.ipc_ip);
|
||||
localIp = findViewById(R.id.local_ip);
|
||||
|
||||
connect.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
connect(true);
|
||||
}
|
||||
});
|
||||
disconnect.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
connect(false);
|
||||
}
|
||||
});
|
||||
initListData();
|
||||
initBtnRecyclerView();
|
||||
switch (Constants.getIpcConnectionMode(this)) {
|
||||
case 0:
|
||||
fixation.setChecked(true);
|
||||
break;
|
||||
case 1:
|
||||
assign.setChecked(true);
|
||||
break;
|
||||
|
||||
}
|
||||
String ip = Constants.getIPCIp(this);
|
||||
if (!TextUtils.isEmpty(ip)) {
|
||||
etIp.setText(ip);
|
||||
etIp.setSelection(ip.length());
|
||||
}
|
||||
|
||||
|
||||
connectionType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
AdasManager.getInstance().disconnect();
|
||||
int type;
|
||||
switch (checkedId) {
|
||||
default:
|
||||
case R.id.assign:
|
||||
type = AdasOptions.IPC_CONNECTION_MODE.ASSIGN;
|
||||
break;
|
||||
case R.id.fixation:
|
||||
type = AdasOptions.IPC_CONNECTION_MODE.FIXATION;
|
||||
break;
|
||||
}
|
||||
Constants.setIpcConnectionMode(MainActivity.this, type);
|
||||
}
|
||||
});
|
||||
etIp.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (TextUtils.isEmpty(s)) {
|
||||
Constants.delIPCIp(MainActivity.this);
|
||||
} else {
|
||||
String str = s.toString();
|
||||
if (str.contains(":")) {
|
||||
str = str.replace(":", ":");
|
||||
etIp.setText(str);
|
||||
etIp.setSelection(str.length());
|
||||
}
|
||||
Constants.setIPCIp(MainActivity.this, str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
});
|
||||
showLocalIP();
|
||||
title.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showLocalIP();
|
||||
}
|
||||
});
|
||||
|
||||
tvIp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listPopupWindow == null) {
|
||||
tvIp.setSelected(true);
|
||||
showListPopupWindow();
|
||||
} else {
|
||||
tvIp.setSelected(false);
|
||||
listPopupWindow.dismiss();
|
||||
listPopupWindow = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
tvConnectState.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!canDrawOverlays()) {
|
||||
return;
|
||||
}
|
||||
if (floatWindow == null) {
|
||||
floatWindow = new FloatWindow(MainActivity.this, connectStatusList);
|
||||
floatWindow.showFloatWindow(include_title.getY() + include_title.getHeight());
|
||||
} else {
|
||||
floatWindow.hideFloatWindow();
|
||||
floatWindow = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void showListPopupWindow() {
|
||||
List<String> ips = Constants.getIpcUsedIps(this);
|
||||
if (ips != null && !ips.isEmpty()) {
|
||||
listPopupWindow = new ListPopupWindow(this);
|
||||
listPopupWindow.setAdapter(new ArrayAdapter<String>(this, R.layout.item_pop, ips));
|
||||
listPopupWindow.setAnchorView(etIp);//以哪个控件为基准,在该处以mEditText为基准
|
||||
listPopupWindow.setModal(true);
|
||||
listPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss() {
|
||||
listPopupWindow = null;
|
||||
tvIp.setSelected(false);
|
||||
}
|
||||
});
|
||||
listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
String text = ips.get(i);
|
||||
etIp.setText(text);
|
||||
etIp.setSelection(text.length());
|
||||
listPopupWindow.dismiss();
|
||||
listPopupWindow = null;
|
||||
}
|
||||
});
|
||||
listPopupWindow.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void initListData() {
|
||||
titleBtnData.add(new TitleBean(Constants.TITLE.SEND_RESTORATION));
|
||||
titleBtnData.add(new TitleBean(Constants.TITLE.SEND_ACCELERATED_SPEED_1));
|
||||
titleBtnData.add(new TitleBean(Constants.TITLE.SEND_ACCELERATED_SPEED_2));
|
||||
titleBtnData.add(new TitleBean(Constants.TITLE.SEND_CHANGE_LANE_LEFT));
|
||||
titleBtnData.add(new TitleBean(Constants.TITLE.SEND_CHANGE_LANE_RIGHT));
|
||||
titleBtnData.add(new TitleBean(Constants.TITLE.SEND_HORN));
|
||||
titleBtnData.add(new TitleBean(Constants.TITLE.START_AUTOPILOT));
|
||||
}
|
||||
|
||||
private void initBtnRecyclerView() {
|
||||
//初始info-recycle
|
||||
GridLayoutManager nodLinearLayoutManage = new GridLayoutManager(this, 3);
|
||||
nodLinearLayoutManage.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
infoBtn.setLayoutManager(nodLinearLayoutManage);
|
||||
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
|
||||
infoBtn.setHasFixedSize(true);
|
||||
//解决局部刷新闪屏问题
|
||||
SimpleItemAnimator animatorInfo = (SimpleItemAnimator) infoBtn.getItemAnimator();
|
||||
if (animatorInfo != null)
|
||||
animatorInfo.setSupportsChangeAnimations(false);
|
||||
//创建并设置Adapter
|
||||
btnAdapter = new InfoTitleAdapter(titleBtnData);
|
||||
infoBtn.setAdapter(btnAdapter);
|
||||
btnAdapter.setOnItemClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 感知接口 提示
|
||||
*
|
||||
* @param isSeriaNet 是否是透传接口
|
||||
*/
|
||||
private void hintTrackedObjects(boolean isSeriaNet) {
|
||||
int value = 0;
|
||||
MessagePad.CarConfigResp carConfigResp = AdasManager.getInstance().getCarConfig();
|
||||
if (carConfigResp != null) {
|
||||
value = carConfigResp.getProtocolVersionValue();
|
||||
}
|
||||
if (isSeriaNet && value < 3 && value > 0 || value > 2) {
|
||||
showToastCenter("当前工控机协议版本:" + value + ",此接口不受支持");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getIPCIP() {
|
||||
final String ip = AdasManager.getInstance().getIpcConnectedIp();
|
||||
final int port = AdasManager.getInstance().getIpcConnectedPort();
|
||||
String temp = "";
|
||||
if (!TextUtils.isEmpty(ip)) {
|
||||
temp = ip + ":" + port;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
public void showIPCIP() {
|
||||
ipcIp.setVisibility(View.VISIBLE);
|
||||
ipcIp.setText("IPC IP:" + getIPCIP());
|
||||
|
||||
}
|
||||
|
||||
private int getStatusColor(int connectStatus) {
|
||||
int color;
|
||||
switch (connectStatus) {
|
||||
case IPC_CONNECTION_STATUS.CONNECTED:
|
||||
color = R.color.connect_status_connected;
|
||||
break;
|
||||
default:
|
||||
case IPC_CONNECTION_STATUS.DISCONNECTED:
|
||||
color = R.color.connect_status_disconnected;
|
||||
break;
|
||||
case IPC_CONNECTION_STATUS.CONNECTING:
|
||||
color = R.color.connect_status_connecting;
|
||||
break;
|
||||
case IPC_CONNECTION_STATUS.SEARCH_ADDRESS:
|
||||
color = R.color.connect_status_search_address;
|
||||
break;
|
||||
case IPC_CONNECTION_STATUS.NOT_FOUND_ADDRESS:
|
||||
color = R.color.connect_status_disconnecting;
|
||||
break;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private String onUpdateConnectStateView() {
|
||||
String status;
|
||||
switch (connectStatus) {
|
||||
case IPC_CONNECTION_STATUS.CONNECTED:
|
||||
status = "已连接";
|
||||
break;
|
||||
default:
|
||||
case IPC_CONNECTION_STATUS.DISCONNECTED:
|
||||
status = "未连接";
|
||||
break;
|
||||
case IPC_CONNECTION_STATUS.CONNECTING:
|
||||
status = "连接中";
|
||||
break;
|
||||
case IPC_CONNECTION_STATUS.SEARCH_ADDRESS:
|
||||
status = "搜索IP";
|
||||
break;
|
||||
case IPC_CONNECTION_STATUS.NOT_FOUND_ADDRESS:
|
||||
status = "未找到";
|
||||
break;
|
||||
}
|
||||
Message msg = Message.obtain();
|
||||
msg.obj = new IPCConnectState(status, getStatusColor(connectStatus));
|
||||
msg.what = WHAT_IPC_CONNECT_STATE;
|
||||
getHandler().sendMessage(msg);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onError(ProtocolStatus status, byte[] bytes) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrajectory(MessagePad.Header header, MessagePad.Trajectory trajectory) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackedObjects(MessagePad.Header header, MessagePad.TrackedObjects trackedObjects) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onGnssInfo(MessagePad.Header header, MessagePad.GnssInfo gnssInfo) {
|
||||
Message message = Message.obtain();
|
||||
message.what = WHAT_UPDATE_GNSS;
|
||||
message.obj = String.format(Locale.getDefault(), GNSS_HINT, sdf.format(new Date((long) (header.getTimestamp() * 1000))),
|
||||
gnssInfo.getLongitude(), gnssInfo.getLatitude(), gnssInfo.getAltitude(), gnssInfo.getHeading(), gnssInfo.getAcceleration(),
|
||||
gnssInfo.getYawRate(), gnssInfo.getGnssSpeed(), gnssInfo.getVehicleSpeed());
|
||||
getHandler().sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVehicleState(MessagePad.Header header, VehicleStateOuterClass.VehicleState vehicleState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutopilotState(MessagePad.Header header, MessagePad.AutopilotState autopilotState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReportMessage(MessagePad.Header header, MogoReportMsg.MogoReportMessage mogoReportMessage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPerceptionTrafficLight(MessagePad.Header header, TrafficLightOuterClass.TrafficLights trafficLights) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPredictionObstacleTrajectory(MessagePad.Header header, Prediction.mPredictionObjects predictionObjects) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPointCloud(MessagePad.Header header, MogoPointCloudOuterClass.MogoPointCloud pointCloud) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointCloud(byte[] pointCloud) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlanningObjects(MessagePad.Header header, MessagePad.PlanningObjects planningObjects) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBasicInfoReq(MessagePad.Header header, MessagePad.BasicInfoReq basicInfoReq) {
|
||||
AdasManager.getInstance().sendBasicInfoResp("", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCarConfigResp(MessagePad.Header header, MessagePad.CarConfigResp carConfigResp) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordResult(MessagePad.Header header, RecordPanelOuterClass.RecordPanel recordPanel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGlobalPathResp(MessagePad.Header header, MessagePad.GlobalPathResp globalPathResp) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWarn(MessagePad.Header header, MessagePad.Warn warn) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArrivalNotification(MessagePad.Header header, MessagePad.ArrivalNotification arrivalNotification) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusQueryResp(MessagePad.Header header, SystemStatusInfo.StatusInfo statusInfo) {
|
||||
}
|
||||
|
||||
|
||||
private void initAdas() {
|
||||
CupidLogUtils.e(TAG, "--->初始化");
|
||||
AdasOptions options;
|
||||
/*—————————————作为司机端———————————*/
|
||||
int mode = Constants.getIpcConnectionMode(this);
|
||||
switch (mode) {
|
||||
default:
|
||||
case AdasOptions.IPC_CONNECTION_MODE.FIXATION:
|
||||
options = new AdasOptions.Builder().setClient(false).setIpcFixationIP(AdasManager.getInstance().getIPCFixationIPList(this)).setIpcConnectionMode(mode).build();
|
||||
break;
|
||||
case AdasOptions.IPC_CONNECTION_MODE.ASSIGN:
|
||||
options = new AdasOptions.Builder().setClient(false).setIpcAssignIP(Constants.getIPCIp(this)).setIpcConnectionMode(mode).build();
|
||||
break;
|
||||
}
|
||||
AdasManager.getInstance().create(options, this);
|
||||
AdasManager.getInstance().setOnAdasListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onConnectionIPCStatus(int ipcConnectionStatus, String reason) {
|
||||
// Log.i(TAG, "连接状态=" + (reason == null ? "主动断开连接" : reason));
|
||||
String time = sdf.format(new Date());
|
||||
connectStatusList.add(0, new IPCConnectState(reason == null ? "主动断开连接" : reason, getStatusColor(ipcConnectionStatus)));
|
||||
if (connectStatusList.size() > 100) {
|
||||
connectStatusList.remove(connectStatusList.size() - 1);
|
||||
}
|
||||
connectStatus = ipcConnectionStatus;
|
||||
String status = onUpdateConnectStateView();
|
||||
if (connectStatus == IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
getHandler().sendEmptyMessage(WHAT_IPC_IP);
|
||||
String tem = getIPCIP();
|
||||
if (!TextUtils.isEmpty(tem)) {
|
||||
List<String> ips = Constants.getIpcUsedIps(this);
|
||||
Constants.addIpcUsedIps(this, ips, tem);
|
||||
}
|
||||
} else if (connectStatus == IPC_CONNECTION_STATUS.DISCONNECTED) {
|
||||
getHandler().sendEmptyMessage(WHAT_IPC_IP);
|
||||
}
|
||||
// LogSave.getInstance().saveLog("连接状态", status);
|
||||
// CupidLogUtils.i(TAG, "connectStatus=" + status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompatibility(VersionCompatibility versionCompatibility) {
|
||||
showToastCenter("所连工控机:\n" + (versionCompatibility == null ? "未连接" : versionCompatibility.toString()), Toast.LENGTH_LONG);
|
||||
}
|
||||
|
||||
private void showLocalIP() {
|
||||
showToastCenter("已刷新本机IP");
|
||||
localIp.setText("本机IP:" + getIpAddressString());
|
||||
}
|
||||
|
||||
private String getIpAddressString() {
|
||||
try {
|
||||
for (Enumeration<NetworkInterface> enNetI = NetworkInterface
|
||||
.getNetworkInterfaces(); enNetI.hasMoreElements(); ) {
|
||||
NetworkInterface netI = enNetI.nextElement();
|
||||
for (Enumeration<InetAddress> enumIpAddr = netI
|
||||
.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
|
||||
return inetAddress.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "127.0.0.1";
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前设备是手机还是平板,代码来自 Google I/O App for Android
|
||||
*
|
||||
* @param context
|
||||
* @return 平板返回 True,手机返回 False
|
||||
*/
|
||||
public static boolean isPad(Context context) {
|
||||
return (context.getResources().getConfiguration().screenLayout
|
||||
& Configuration.SCREENLAYOUT_SIZE_MASK)
|
||||
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onItemClick(int position, TitleBean data) {
|
||||
if (connectStatus != IPC_CONNECTION_STATUS.CONNECTED) {
|
||||
String msg = "未连接工控机";
|
||||
showToastCenter(msg);
|
||||
return;
|
||||
}
|
||||
switch (data.name) {
|
||||
case Constants.TITLE.SEND_RESTORATION:
|
||||
updateItem(Constants.TITLE.SEND_ACCELERATED_SPEED_2, -1, null);
|
||||
updateItem(Constants.TITLE.SEND_ACCELERATED_SPEED_1, -1, null);
|
||||
sendAcc(false, 0.0);
|
||||
break;
|
||||
case Constants.TITLE.SEND_CHANGE_LANE_LEFT:
|
||||
AdasManager.getInstance().sendOperatorCmdChangeLaneLeft();
|
||||
break;
|
||||
case Constants.TITLE.SEND_CHANGE_LANE_RIGHT:
|
||||
AdasManager.getInstance().sendOperatorCmdChangeLaneRight();
|
||||
break;
|
||||
case Constants.TITLE.SEND_ACCELERATED_SPEED_1:
|
||||
updateItem(Constants.TITLE.SEND_ACCELERATED_SPEED_2, position, data);
|
||||
sendAcc(true, -1);
|
||||
break;
|
||||
case Constants.TITLE.SEND_ACCELERATED_SPEED_2:
|
||||
updateItem(Constants.TITLE.SEND_ACCELERATED_SPEED_1, position, data);
|
||||
sendAcc(true, -2);
|
||||
break;
|
||||
case Constants.TITLE.SEND_HORN:
|
||||
if (timerHorn == null) {
|
||||
updateItem(null, position, data);
|
||||
AdasManager.getInstance().sendOperatorCmdStartHonking();
|
||||
timerHorn = new Timer();
|
||||
timerHorn.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
AdasManager.getInstance().sendOperatorCmdStopHonking();
|
||||
timerHorn = null;
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateItem(Constants.TITLE.SEND_HORN, -1, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, Constants.getHornDuration(this));
|
||||
}
|
||||
break;
|
||||
case Constants.TITLE.START_AUTOPILOT:
|
||||
AdasManager.getInstance().sendAutoPilotModeReq(1, 0, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateItem(String name, int position, TitleBean data) {
|
||||
if (!TextUtils.isEmpty(name)) {
|
||||
int index = titleBtnData.indexOf(new TitleBean(name));
|
||||
if (index != -1) {
|
||||
titleBtnData.get(index).isSelected = false;
|
||||
btnAdapter.setSelectedPosition(index);
|
||||
}
|
||||
}
|
||||
if (data != null) {
|
||||
data.isSelected = true;
|
||||
btnAdapter.setSelectedPosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
private volatile double accelerated;//加速度
|
||||
|
||||
/**
|
||||
* 定频发送加速度
|
||||
*
|
||||
* @param isSend 是否发送
|
||||
* @param acc 加速度
|
||||
*/
|
||||
private synchronized void sendAcc(boolean isSend, double acc) {
|
||||
if (isSend) {
|
||||
accelerated = acc;
|
||||
if (timerAcc == null) {
|
||||
timerAcc = new Timer();
|
||||
timerAcc.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
AdasManager.getInstance().sendOperatorCmdSetAcceleratedSpeed(accelerated);
|
||||
}
|
||||
}, 0, Constants.getAccelerateDuration(this));
|
||||
}
|
||||
} else {
|
||||
if (timerAcc != null) {
|
||||
timerAcc.cancel();
|
||||
timerAcc = null;
|
||||
}
|
||||
AdasManager.getInstance().sendOperatorCmdSetAcceleratedSpeed(acc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(int position, TitleBean data) {
|
||||
if (Constants.TITLE.SEND_HORN.equals(data.name)) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
||||
builder.setTitle("鸣笛时长配置");
|
||||
View view = getLayoutInflater().inflate(R.layout.dialog_time, null);
|
||||
final EditText et = view.findViewById(R.id.et);
|
||||
String timeout = String.valueOf(Constants.getHornDuration(this));
|
||||
et.setText(timeout);
|
||||
et.setSelection(timeout.length());
|
||||
builder.setView(view);//
|
||||
builder.setPositiveButton("确定", null);
|
||||
//设置反面按钮,并做事件处理
|
||||
builder.setNegativeButton("取消", null);
|
||||
AlertDialog alertDialog = builder.show();//显示Dialog对话框
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Editable editable = et.getText();
|
||||
if (TextUtils.isEmpty(editable)) {
|
||||
// 条件不成立不能关闭 AlertDialog 窗口
|
||||
Toast.makeText(MainActivity.this, "请输入时长", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
String temp = et.getText().toString().trim();
|
||||
Constants.setHornDuration(MainActivity.this, Long.parseLong(temp));
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else if (Constants.TITLE.SEND_ACCELERATED_SPEED_1.equals(data.name) || Constants.TITLE.SEND_ACCELERATED_SPEED_2.equals(data.name)) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
||||
builder.setTitle("ACC发送频率配置");
|
||||
View view = getLayoutInflater().inflate(R.layout.dialog_time, null);
|
||||
final EditText et = view.findViewById(R.id.et);
|
||||
String timeout = String.valueOf(Constants.getAccelerateDuration(this));
|
||||
et.setText(timeout);
|
||||
et.setSelection(timeout.length());
|
||||
builder.setView(view);//
|
||||
builder.setPositiveButton("确定", null);
|
||||
//设置反面按钮,并做事件处理
|
||||
builder.setNegativeButton("取消", null);
|
||||
AlertDialog alertDialog = builder.show();//显示Dialog对话框
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Editable editable = et.getText();
|
||||
if (TextUtils.isEmpty(editable)) {
|
||||
// 条件不成立不能关闭 AlertDialog 窗口
|
||||
Toast.makeText(MainActivity.this, "请输入频率", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
String temp = et.getText().toString().trim();
|
||||
Constants.setAccelerateDuration(MainActivity.this, Long.parseLong(temp));
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case WHAT_IPC_IP:
|
||||
showIPCIP();
|
||||
break;
|
||||
case WHAT_IPC_CONNECT_STATE:
|
||||
if (floatWindow != null) {
|
||||
floatWindow.refreshView();
|
||||
}
|
||||
IPCConnectState status = (IPCConnectState) msg.obj;
|
||||
tvConnectState.setText(status.status);
|
||||
tvConnectState.setTextColor(getResources().getColor(status.color));
|
||||
break;
|
||||
case WHAT_UPDATE_GNSS:
|
||||
gnss_hint.setText((String) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.zhidao.adas.magic.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.zhidao.adas.client.utils.PreferencesUtils;
|
||||
import com.zhidao.support.adas.high.common.JsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song kenan
|
||||
* @des
|
||||
* @date 2021/10/8
|
||||
*/
|
||||
public class Constants {
|
||||
public static final String ROOT_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "IPCMonitoring" + File.separator;//程序外部存储跟目录
|
||||
public static final String FILE_PATH = ROOT_PATH + "Crash" + File.separator;
|
||||
|
||||
|
||||
/***********************是否使用固定IP******************/
|
||||
// 0:固定IP 1:指定 2:UDP
|
||||
private static final String IPC_CONNECTION_MODE = "ipc_connection_mode";
|
||||
|
||||
public static void setIpcConnectionMode(Context context, int type) {
|
||||
PreferencesUtils.putInt(context, IPC_CONNECTION_MODE, type);
|
||||
}
|
||||
|
||||
public static int getIpcConnectionMode(Context context) {
|
||||
return PreferencesUtils.getInt(context, IPC_CONNECTION_MODE, 0);
|
||||
}
|
||||
|
||||
public static boolean delIpcConnectionMode(Context context) {
|
||||
return PreferencesUtils.delete(context, IPC_CONNECTION_MODE);
|
||||
}
|
||||
|
||||
/***********************保存IP******************/
|
||||
private static final String IPC_IP = "ipc_ip";
|
||||
|
||||
public static void setIPCIp(Context context, String ip) {
|
||||
PreferencesUtils.putString(context, IPC_IP, ip);
|
||||
}
|
||||
|
||||
public static String getIPCIp(Context context) {
|
||||
return PreferencesUtils.getString(context, IPC_IP, null);
|
||||
}
|
||||
|
||||
public static boolean delIPCIp(Context context) {
|
||||
return PreferencesUtils.delete(context, IPC_IP);
|
||||
}
|
||||
|
||||
|
||||
/***********************保存使用过的IP列表******************/
|
||||
|
||||
|
||||
private static final String IPC_USED_IP = "ipc_used_ip";
|
||||
|
||||
public static List<String> getIpcUsedIps(Context context) {
|
||||
String json = PreferencesUtils.getString(context, IPC_USED_IP, null);
|
||||
if (TextUtils.isEmpty(json)) return null;
|
||||
List<String> list = JsonUtil.fromJson(json, new TypeToken<List<String>>() {
|
||||
}.getType());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean addIpcUsedIps(Context context, List<String> list, String mode) {
|
||||
if (list == null)
|
||||
list = new ArrayList<>();
|
||||
list.remove(mode);
|
||||
list.add(0, mode);
|
||||
if (list.size() > 10) {
|
||||
list.remove(list.size() - 1);
|
||||
}
|
||||
return PreferencesUtils.putString(context, IPC_USED_IP, JsonUtil.toJson(list));
|
||||
}
|
||||
|
||||
public static boolean delIpcUsedIps(Context context, List<String> list, String mode) {
|
||||
if (list == null) {
|
||||
return PreferencesUtils.delete(context, IPC_USED_IP);
|
||||
} else {
|
||||
if (list.contains(mode)) {
|
||||
list.remove(mode);
|
||||
return PreferencesUtils.putString(context, IPC_USED_IP, JsonUtil.toJson(list));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/********************acc 发送频率******************/
|
||||
private static final String ACCELERATE_DURATION = "accelerate_duration";
|
||||
|
||||
public static void setAccelerateDuration(Context context, long duration) {
|
||||
PreferencesUtils.putLong(context, ACCELERATE_DURATION, duration);
|
||||
}
|
||||
|
||||
public static long getAccelerateDuration(Context context) {
|
||||
return PreferencesUtils.getLong(context, ACCELERATE_DURATION, 500);
|
||||
}
|
||||
|
||||
public static boolean delAccelerateDuration(Context context) {
|
||||
return PreferencesUtils.delete(context, ACCELERATE_DURATION);
|
||||
}
|
||||
/********************鸣笛时长******************/
|
||||
private static final String HORN_DURATION = "horn_duration";
|
||||
|
||||
public static void setHornDuration(Context context, long duration) {
|
||||
PreferencesUtils.putLong(context, HORN_DURATION, duration);
|
||||
}
|
||||
|
||||
public static long getHornDuration(Context context) {
|
||||
return PreferencesUtils.getLong(context, HORN_DURATION, 500);
|
||||
}
|
||||
|
||||
public static boolean delHornDuration(Context context) {
|
||||
return PreferencesUtils.delete(context, HORN_DURATION);
|
||||
}
|
||||
|
||||
public interface TITLE {
|
||||
|
||||
String SEND_RESTORATION = "复位";
|
||||
String SEND_CHANGE_LANE_LEFT = "向左变道";
|
||||
String SEND_CHANGE_LANE_RIGHT = "向右变道";
|
||||
String SEND_ACCELERATED_SPEED_1 = "-1减速";
|
||||
String SEND_ACCELERATED_SPEED_2 = "-2减速";
|
||||
String SEND_HORN = "鸣笛";
|
||||
String START_AUTOPILOT = "开启自动驾驶";
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user