Merge branch 'dev_robotaxi-d-app-module_290_220715_2.9.0_interface_subscribe' into dev_robotaxi-d-app-module_2100_220816_2.10.0

This commit is contained in:
zhongchao
2022-08-16 17:49:24 +08:00
52 changed files with 1907 additions and 133 deletions

View File

@@ -24,6 +24,7 @@ import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_CLOUD_CONNECT_FAIL
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_CLOUD_CONNECT_LOST
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_CLOUD_CONNECT_SUCCESS
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_HTTP_DNS_CHANGED
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_CLOUD_SHOW
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_CONNECT_STATUS
import com.mogo.eagle.core.data.map.MogoLocation
@@ -236,6 +237,14 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
*/
private fun registerSocketHttpDnsTTL(host: String?) {
mogoHttpDns.addressChangedListener(object : OnAddressChangedListener {
@ChainLog(
linkChainLog = CHAIN_LINK_LOG_CONNECT_STATUS,
linkCode = CHAIN_LINK_CLOUD_SHOW,
endpoint = PAD,
nodeAliasCode = CHAIN_ALIAS_CODE_HTTP_DNS_CHANGED,
paramIndexes = [0],
clientPkFileName = "sn"
)
override fun onAddressChanged(address: Map<String, String>?) {
val dnsCacheIp = mogoHttpDns.getCachedHttpDnsIps(
host,

View File

@@ -11,9 +11,9 @@ import com.zhidao.adas.client.bean.ErrorData;
import com.zhidao.adas.client.bean.GlobalPathResp;
import com.zhidao.adas.client.bean.GnssInfo;
import com.zhidao.adas.client.bean.MogoReportMessage;
import com.zhidao.adas.client.bean.MyPointCloud;
import com.zhidao.adas.client.bean.OriginalPointCloudData;
import com.zhidao.adas.client.bean.PerceptionTrafficLight;
import com.zhidao.adas.client.bean.PlanningDecisionState;
import com.zhidao.adas.client.bean.PlanningObjects;
import com.zhidao.adas.client.bean.PredictionObstacleTrajectory;
import com.zhidao.adas.client.bean.RecordDataConfig;
@@ -114,9 +114,9 @@ public class DataDistribution {
public final List<String> listStatusInfo = new ArrayList<>();
public final List<String> listRecordDataConfig = new ArrayList<>();
public final List<String> listErrorData = new ArrayList<>();
public final List<String> listPointCloud = new ArrayList<>();
public final List<String> listOriginalPointCloud = new ArrayList<>();
public final List<String> listPlanningObjects = new ArrayList<>();
public final List<String> listPlanningDecisionState = new ArrayList<>();
public String cutDown(String str) {
if (isCutDown && str.length() > 650) {
@@ -144,14 +144,6 @@ public class DataDistribution {
if (listener != null && Constants.TITLE.RECEIVE_TRACKED_OBJECTS.equals(listener.first)) {
listener.second.onRefresh();
}
} else if (data instanceof MyPointCloud) {
listPointCloud.add(0, time + str);
if (listPointCloud.size() > LIST_SIZE) {
listPointCloud.remove(listPointCloud.size() - 1);
}
if (listener != null && Constants.TITLE.RECEIVE_POINT_CLOUD.equals(listener.first)) {
listener.second.onRefresh();
}
} else if (data instanceof OriginalPointCloudData) {
listOriginalPointCloud.add(0, time + str);
if (listOriginalPointCloud.size() > LIST_SIZE) {
@@ -168,6 +160,14 @@ public class DataDistribution {
if (listener != null && Constants.TITLE.RECEIVE_PLANNING_OBJECTS.equals(listener.first)) {
listener.second.onRefresh();
}
} else if (data instanceof PlanningDecisionState) {
listPlanningDecisionState.add(0, time + str);
if (listPlanningDecisionState.size() > LIST_SIZE) {
listPlanningDecisionState.remove(listPlanningDecisionState.size() - 1);
}
if (listener != null && Constants.TITLE.RECEIVE_PLANNING_DECISION_STATE.equals(listener.first)) {
listener.second.onRefresh();
}
} else if (data instanceof GnssInfo) {
listGnssInfo.add(0, time + str);
if (listGnssInfo.size() > LIST_SIZE) {

View File

@@ -0,0 +1,217 @@
package com.zhidao.adas.client.adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.zhidao.adas.client.R;
import com.zhidao.adas.client.bean.InterfaceModel;
import com.zhidao.support.adas.high.common.MessageType;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class InterfaceAdapter extends RecyclerView.Adapter<InterfaceAdapter.MyViewHolder> {
private List<InterfaceModel> mDatas;
private boolean isEnabled = true;//是否可操作
private boolean oldIsEnabled = isEnabled;
private int isCheckAll = 2;//0全选 1全不选 2任意选
private int checkNum;
private boolean oldIsCheckAll = false;
private OnInterfaceAdapterListener listener;
public void setListener(OnInterfaceAdapterListener listener) {
this.listener = listener;
}
public interface OnInterfaceAdapterListener {
void onCheckAll(boolean isCheckAll);
void onCheckNum(int checkNum);
}
public int getCheckNum() {
return checkNum;
}
//获取已选中的
public Set<MessageType> getCheckedModel() {
Set<MessageType> messageTypes = new HashSet<>();
if (mDatas != null) {
for (InterfaceModel model : mDatas) {
if (model.isSelected()) {
messageTypes.add(model.getMessageType());
}
}
}
return messageTypes;
}
private void init() {
isEnabled = true;
oldIsEnabled = true;
isCheckAll = 2;
checkNum = 0;
}
public void setData(List<InterfaceModel> mDatas, int checkNum) {
init();
this.mDatas = mDatas;
if (mDatas != null && !mDatas.isEmpty()) {
this.checkNum = checkNum;
updateCheckAllStatus(true);
}
}
//全选 全不选
public void setCheckAll(boolean checkAll) {
isCheckAll = checkAll ? 0 : 1;
checkNum = checkAll ? getItemCount() : 0;
notifyDataSetChanged();
updateCheckNumStatusCall();
updateCheckAllStatus(false);
}
public void setEnabled(boolean isEnabled) {
if (oldIsEnabled != isEnabled) {
oldIsEnabled = isEnabled;
this.isEnabled = isEnabled;
notifyDataSetChanged();
}
}
//创建ViewHolder
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//实例化得到Item布局文件的View对象
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_interface, parent, false);
//返回MyViewHolder的对象
return new MyViewHolder(v);
}
//绑定数据
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.index.setEnabled(isEnabled);
holder.name.setEnabled(isEnabled);
holder.itemView.setEnabled(isEnabled);
holder.itemCheck.setEnabled(isEnabled);
InterfaceModel model = mDatas.get(position);
holder.name.setText(model.getMessageType().desc);
holder.index.setText((position + 1) + ".");
if (isCheckAll == 0) {
model.setSelected(true);
} else if (isCheckAll == 1) {
model.setSelected(false);
}
holder.itemCheck.setChecked(model.isSelected());
}
//返回Item的数量
@Override
public int getItemCount() {
return mDatas == null ? 0 : mDatas.size();
}
/***
* 获取制定 位置的Data
* @param position 下标
* @return Data
*/
public InterfaceModel getItem(int position) {
return mDatas == null ? null : mDatas.get(position);
}
//继承RecyclerView.ViewHolder抽象类的自定义ViewHolder
class MyViewHolder extends RecyclerView.ViewHolder {
TextView name;
TextView index;
CheckBox itemCheck;
MyViewHolder(View itemView) {
super(itemView);
index = itemView.findViewById(R.id.index);
name = itemView.findViewById(R.id.name);
name.setSelected(true);
itemCheck = itemView.findViewById(R.id.item_check);
init();
}
private void init() {
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InterfaceModel model = getItem(getBindingAdapterPosition());
model.setSelected(!model.isSelected());
updateCheckNum(model.isSelected());
itemCheck.setChecked(model.isSelected());
}
});
itemCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.isPressed()) {
updateCheckNum(isChecked);
InterfaceModel model = getItem(getBindingAdapterPosition());
model.setSelected(isChecked);
}
}
});
}
}
//更新选中个数
private void updateCheckNum(boolean isChecked) {
if (isChecked) {
checkNum++;
} else {
checkNum--;
}
updateCheckNumStatusCall();
updateCheckAllStatus(true);
}
private void updateCheckNumStatusCall() {
if (listener != null)
listener.onCheckNum(checkNum);
}
//更新全选状态
private void updateCheckAllStatus(boolean isNotice) {
if (getItemCount() == checkNum) {
isCheckAll = 0;
updateCheckAllStatusCall(isNotice, true);
} else if (0 == checkNum) {
isCheckAll = 1;
updateCheckAllStatusCall(isNotice, false);
} else {
isCheckAll = 2;
updateCheckAllStatusCall(isNotice, false);
}
}
private void updateCheckAllStatusCall(boolean isNotice, boolean isCheckAll) {
if (isNotice)
if (oldIsCheckAll != isCheckAll) {
oldIsCheckAll = isCheckAll;
if (listener != null)
listener.onCheckAll(isCheckAll);
}
}
}

View File

@@ -27,6 +27,7 @@ import perception.TrafficLightOuterClass;
public abstract class BaseFragment extends Fragment {
protected final String TAG = this.getClass().getSimpleName();
private static final int WHAT_REFRESH = 0x01;
private static final int WHAT_UPDATE_CONNECT_STATUS = 0x02;
protected static final int WHAT_REFRESH_TRAFFIC_LIGHTS = 0x02;
protected String title;
@@ -64,6 +65,18 @@ public abstract class BaseFragment extends Fragment {
}
}
public void updateConnectStatus(int ipcConnectionStatus) {
if (getHandler() != null) {
Message msg = Message.obtain();
msg.what = WHAT_UPDATE_CONNECT_STATUS;
msg.arg1 = ipcConnectionStatus;
getHandler().sendMessage(msg);
}
}
protected void onConnectionIPCStatus(int ipcConnectionStatus) {
}
@Override
public void onDestroyView() {
@@ -197,6 +210,11 @@ public abstract class BaseFragment extends Fragment {
if (isVisible())
onRefreshView();
break;
case WHAT_UPDATE_CONNECT_STATUS:
if (isVisible())
onConnectionIPCStatus(msg.arg1);
break;
}
}

View File

@@ -0,0 +1,34 @@
package com.zhidao.adas.client.bean;
import com.zhidao.support.adas.high.common.MessageType;
public class InterfaceModel {
private boolean isSelected = false;//是否选择
private final MessageType messageType;
public InterfaceModel(MessageType messageType) {
this.messageType = messageType;
}
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
public MessageType getMessageType() {
return messageType;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InterfaceModel that = (InterfaceModel) o;
return messageType == that.messageType;
}
}

View File

@@ -0,0 +1,23 @@
package com.zhidao.adas.client.bean;
import com.google.protobuf.TextFormat;
import java.text.SimpleDateFormat;
import mogo.telematics.pad.MessagePad;
public class PlanningDecisionState extends BaseInfo {
public final MessagePad.PlanningActionMsg bean;
public PlanningDecisionState(MessagePad.Header header, MessagePad.PlanningActionMsg bean, SimpleDateFormat sdf) {
super("接收", bean.getSerializedSize(), header, sdf);
this.bean = bean;
}
@Override
public String toString() {
return super.toString() + TextFormat.printer().escapingNonAscii(false).printToString(bean);
}
}

View File

@@ -129,12 +129,12 @@ public class InfoFragment extends BaseFragment {
adapter.setData(DataDistribution.getInstance().listPerceptionTrafficLight);
} else if (Constants.TITLE.RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY.equals(title)) {
adapter.setData(DataDistribution.getInstance().listPredictionObstacleTrajectory);
} else if (Constants.TITLE.RECEIVE_POINT_CLOUD.equals(title)) {
adapter.setData(DataDistribution.getInstance().listPointCloud);
} else if (Constants.TITLE.RECEIVE_POINT_CLOUD_ORIGINAL.equals(title)) {
adapter.setData(DataDistribution.getInstance().listOriginalPointCloud);
} else if (Constants.TITLE.RECEIVE_PLANNING_OBJECTS.equals(title)) {
adapter.setData(DataDistribution.getInstance().listPlanningObjects);
} else if (Constants.TITLE.RECEIVE_PLANNING_DECISION_STATE.equals(title)) {
adapter.setData(DataDistribution.getInstance().listPlanningDecisionState);
} else {
adapter.setData(DataDistribution.getInstance().listErrorData);
}

View File

@@ -35,7 +35,6 @@ import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatButton;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.GridLayoutManager;
@@ -54,6 +53,7 @@ import com.zhidao.adas.client.R;
import com.zhidao.adas.client.adapter.InfoTitleAdapter;
import com.zhidao.adas.client.base.BaseActivity;
import com.zhidao.adas.client.base.BaseAdapter;
import com.zhidao.adas.client.base.BaseFragment;
import com.zhidao.adas.client.bean.ArrivalNotification;
import com.zhidao.adas.client.bean.AutopilotState;
import com.zhidao.adas.client.bean.BasicInfoReq;
@@ -65,6 +65,7 @@ import com.zhidao.adas.client.bean.IPCConnectState;
import com.zhidao.adas.client.bean.MogoReportMessage;
import com.zhidao.adas.client.bean.OriginalPointCloudData;
import com.zhidao.adas.client.bean.PerceptionTrafficLight;
import com.zhidao.adas.client.bean.PlanningDecisionState;
import com.zhidao.adas.client.bean.PlanningObjects;
import com.zhidao.adas.client.bean.PredictionObstacleTrajectory;
import com.zhidao.adas.client.bean.RecordDataConfig;
@@ -148,7 +149,7 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
private final List<String> titleBtnData = new ArrayList<>();
private final List<IPCConnectState> connectStatusList = new ArrayList<>();
private InfoTitleAdapter fragmentAdapter;
private Fragment fromFragment;
private BaseFragment fromFragment;
private FragmentManager manager;
private String ftpTime;
private boolean isPad;
@@ -613,9 +614,9 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
titleFragmentData.add(Constants.TITLE.RECEIVE_REPORT_MESSAGE);
titleFragmentData.add(Constants.TITLE.RECEIVE_PERCEPTION_TRAFFIC_LIGHT);
titleFragmentData.add(Constants.TITLE.RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY);
titleFragmentData.add(Constants.TITLE.RECEIVE_POINT_CLOUD);
titleFragmentData.add(Constants.TITLE.RECEIVE_POINT_CLOUD_ORIGINAL);
titleFragmentData.add(Constants.TITLE.RECEIVE_PLANNING_OBJECTS);
titleFragmentData.add(Constants.TITLE.RECEIVE_PLANNING_DECISION_STATE);
titleFragmentData.add(Constants.TITLE.RECEIVE_CAR_CONFIG_RESP);
titleFragmentData.add(Constants.TITLE.RECEIVE_RECORD_DATA_CONFIG_RESP);
titleFragmentData.add(Constants.TITLE.RECEIVE_RECORD_RESULT);
@@ -882,7 +883,7 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
public void onBasicInfoReq(MessagePad.Header header, MessagePad.BasicInfoReq basicInfoReq) {
BasicInfoReq info = new BasicInfoReq(header, basicInfoReq, sdf);
DataDistribution.getInstance().addData(info);
AdasManager.getInstance().sendBasicInfoResp("X202021111192N41VY", 0);
AdasManager.getInstance().sendBasicInfoResp("", 0, com.zhidao.support.adas.high.common.Constants.TERMINAL_ROLE.DEBUG);
showToastCenter("收到车机基础信息请求:" + info.toString());
}
@@ -930,6 +931,12 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
DataDistribution.getInstance().addData(base);
}
@Override
public void onPlanningActionMsg(MessagePad.Header header, MessagePad.PlanningActionMsg planningActionMsg) {
PlanningDecisionState base = new PlanningDecisionState(header, planningActionMsg, sdf);
DataDistribution.getInstance().addData(base);
}
private void initAdas() {
CupidLogUtils.e(TAG, "--->初始化");
@@ -1024,6 +1031,9 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
@Override
public void onConnectionIPCStatus(int ipcConnectionStatus, String reason) {
if (fromFragment != null) {
fromFragment.updateConnectStatus(ipcConnectionStatus);
}
// Log.i(TAG, "连接状态=" + (reason == null ? "主动断开连接" : reason));
String time = sdf.format(new Date());
ConnectStatusSave.getInstance().saveLog(time + " ipcConnectionStatus=" + ipcConnectionStatus + " reason=" + reason);
@@ -1089,7 +1099,7 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
}
private void showFragment(String title) {
Fragment to = manager.findFragmentByTag(title);
BaseFragment to = (BaseFragment) manager.findFragmentByTag(title);
if (to == null) {
if (Constants.TITLE.RECEIVE_CAR_CONFIG_RESP.equals(title)) {
to = new VersionFragment(Constants.TITLE.TITLE_CAR_CONFIG_RESP);
@@ -1149,7 +1159,42 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
break;
case Constants.TITLE.SEND_BASIC_INFO_RESP:
//发送sn
AdasManager.getInstance().sendBasicInfoResp("X202021111192N41VY", 0);
//速度设置
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("发送SN");
View view = getLayoutInflater().inflate(R.layout.dialog_sn, null);
final EditText et = view.findViewById(R.id.et);
final EditText ev = view.findViewById(R.id.ev);
final EditText role = view.findViewById(R.id.role);
builder.setView(view);//
builder.setCancelable(false);//
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, "请输入SN", Toast.LENGTH_SHORT).show();
return;
}
int evInt = 0;
Editable evEd = ev.getText();
if (!TextUtils.isEmpty(evEd)) {
evInt = Integer.parseInt(evEd.toString().trim());
}
int roleInt = com.zhidao.support.adas.high.common.Constants.TERMINAL_ROLE.DEBUG;
Editable roleEd = role.getText();
if (!TextUtils.isEmpty(roleEd)) {
roleInt = Integer.parseInt(roleEd.toString().trim());
}
AdasManager.getInstance().sendBasicInfoResp(editable.toString().trim(), evInt, roleInt);
alertDialog.dismiss();
}
});
break;
case Constants.TITLE.SEND_RECORD_DATA_5:
//数据采集5秒
@@ -1192,30 +1237,31 @@ public class MainActivity extends BaseActivity implements OnAdasListener, OnAdas
break;
case Constants.TITLE.SEND_SET_AUTOPILOT_SPEED_REQ:
//速度设置
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("自动驾驶限速");
View view = getLayoutInflater().inflate(R.layout.dialog_speed, null);
final EditText et = (EditText) view.findViewById(R.id.et);
builder.setView(view);//
builder.setCancelable(false);//
builder.setPositiveButton("设置", new DialogInterface.OnClickListener() {
AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
builder1.setTitle("自动驾驶限速");
View view1 = getLayoutInflater().inflate(R.layout.dialog_speed, null);
final EditText et1 = (EditText) view1.findViewById(R.id.et);
builder1.setView(view1);//
builder1.setCancelable(false);//
builder1.setPositiveButton("设置", null);
//设置反面按钮,并做事件处理
builder1.setNegativeButton("取消", null);
AlertDialog alertDialog1 = builder1.show();//显示Dialog对话框
alertDialog1.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Editable editable = et.getText();
public void onClick(View v) {
Editable editable = et1.getText();
if (TextUtils.isEmpty(editable)) {
// 条件不成立不能关闭 AlertDialog 窗口
Toast.makeText(MainActivity.this, "请输入速度", Toast.LENGTH_SHORT).show();
return;
}
String temp = et.getText().toString().trim();
String temp = et1.getText().toString().trim();
double speed = Double.parseDouble(temp) / 3.6;
AdasManager.getInstance().sendAutopilotSpeedReq(speed);
alertDialog1.dismiss();
}
});
//设置反面按钮,并做事件处理
builder.setNegativeButton("取消", null);
builder.show();//显示Dialog对话框
break;
case Constants.TITLE.SEND_SYSTEM_CMD_REQ_REBOOT:
//重启所有节点

View File

@@ -7,8 +7,13 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@@ -21,12 +26,15 @@ import androidx.recyclerview.widget.SimpleItemAnimator;
import com.zhidao.adas.client.BuildConfig;
import com.zhidao.adas.client.R;
import com.zhidao.adas.client.adapter.ConfigAdapter;
import com.zhidao.adas.client.adapter.InterfaceAdapter;
import com.zhidao.adas.client.base.BaseFragment;
import com.zhidao.adas.client.bean.Config;
import com.zhidao.adas.client.bean.InterfaceModel;
import com.zhidao.support.adas.high.AdasManager;
import com.zhidao.support.adas.high.bean.VersionCompatibility;
import com.zhidao.support.adas.high.common.Constants;
import com.zhidao.support.adas.high.common.CupidLogUtils;
import com.zhidao.support.adas.high.common.MessageType;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -34,6 +42,7 @@ import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import mogo.telematics.pad.MessagePad;
@@ -42,11 +51,26 @@ import mogo.telematics.pad.MessagePad;
*/
public class VersionFragment extends BaseFragment {
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS ", Locale.getDefault());
private TextView ipsView;
private EditText ipView;
private RecyclerView recyclerView;
private RecyclerView rec_registered;
private RecyclerView rec_unregistered;
private CheckBox registered_check_all;
private CheckBox unregistered_check_all;
private TextView hint_registered;
private TextView hint_unregistered;
private ConfigAdapter adapter;
private InterfaceAdapter unregisteredAdapter;
private InterfaceAdapter registeredAdapter;
private int role = Constants.TERMINAL_ROLE.DEBUG;//角色 默认调试屏
public VersionFragment() {
}
private ConfigAdapter adapter;
public VersionFragment(String title) {
super(title);
@@ -87,7 +111,7 @@ public class VersionFragment extends BaseFragment {
for (String ip : ips) {
i++;
builder.append(ip);
if (i % 2 == 0) {
if (i % 4 == 0) {
builder.append("\n");
} else {
builder.append("\t\t\t\t");
@@ -98,9 +122,6 @@ public class VersionFragment extends BaseFragment {
}
private TextView ipsView;
private EditText ipView;
private RecyclerView recyclerView;
private void initView(View view) {
TextView tvTitle = view.findViewById(R.id.tv_title);
@@ -113,7 +134,7 @@ public class VersionFragment extends BaseFragment {
CupidLogUtils.w("InfoFragment===>" + title);
tvTitle.setText(title);
tvTitle.setGravity(Gravity.CENTER);
initRegistrationView(view);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -154,6 +175,18 @@ public class VersionFragment extends BaseFragment {
}
//根据连接状态更新数据
@Override
public void onConnectionIPCStatus(int ipcConnectionStatus) {
super.onConnectionIPCStatus(ipcConnectionStatus);
if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.DISCONNECTED || ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
showVersion();
initRegistrationData();
if (ipcConnectionStatus == Constants.IPC_CONNECTION_STATUS.DISCONNECTED) {
clearRegistrationViewState();
}
}
}
public void showVersion() {
List<Config> list = new ArrayList<>();
@@ -204,4 +237,197 @@ public class VersionFragment extends BaseFragment {
adapter = new ConfigAdapter();
recyclerView.setAdapter(adapter);
}
private void initRegistrationView(View view) {
recyclerView = view.findViewById(R.id.config_list);
rec_registered = view.findViewById(R.id.rec_registered);
rec_unregistered = view.findViewById(R.id.rec_unregistered);
registered_check_all = view.findViewById(R.id.registered_check_all);
unregistered_check_all = view.findViewById(R.id.unregistered_check_all);
hint_unregistered = view.findViewById(R.id.hint_unregistered);
hint_registered = view.findViewById(R.id.hint_registered);
Button update = view.findViewById(R.id.update);
initFragmentRecyclerView();
initRegisteredRecyclerView();
initUnregisteredRecyclerView();
initSpinner(view);
registered_check_all.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.isPressed()) {
registeredAdapter.setCheckAll(isChecked);
unregisteredAdapter.setCheckAll(false);
unregisteredAdapter.setEnabled(!isChecked);
unregistered_check_all.setEnabled(!isChecked);
}
}
});
registeredAdapter.setListener(new InterfaceAdapter.OnInterfaceAdapterListener() {
@Override
public void onCheckAll(boolean isCheckAll) {
registered_check_all.setChecked(isCheckAll);
}
@Override
public void onCheckNum(int checkNum) {
boolean isEnable = checkNum == 0;
unregisteredAdapter.setEnabled(isEnable);
unregistered_check_all.setEnabled(isEnable);
}
});
unregistered_check_all.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.isPressed()) {
unregisteredAdapter.setCheckAll(isChecked);
registeredAdapter.setCheckAll(false);
registeredAdapter.setEnabled(!isChecked);
registered_check_all.setEnabled(!isChecked);
}
}
});
unregisteredAdapter.setListener(new InterfaceAdapter.OnInterfaceAdapterListener() {
@Override
public void onCheckAll(boolean isCheckAll) {
unregistered_check_all.setChecked(isCheckAll);
}
@Override
public void onCheckNum(int checkNum) {
boolean isEnable = checkNum == 0;
registeredAdapter.setEnabled(isEnable);
registered_check_all.setEnabled(isEnable);
}
});
update.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
update();
}
});
initRegistrationData();
}
private void update() {
if (registeredAdapter.getCheckNum() == 0 && unregisteredAdapter.getCheckNum() == 0) {
Toast.makeText(getContext(), "请选择后在更新", Toast.LENGTH_SHORT).show();
return;
}
Set<MessageType> set;
if (registeredAdapter.getCheckNum() == 0) {
//注册
set = unregisteredAdapter.getCheckedModel();
if (set == null || set.isEmpty()) {
Toast.makeText(getContext(), "请选择要注册的接口", Toast.LENGTH_SHORT).show();
return;
}
if (set.size() == 1) {
AdasManager.getInstance().subscribeInterface(role, Constants.SUBSCRIBE_TYPE.SUBSCRIBE, set.iterator().next());
} else {
AdasManager.getInstance().subscribeInterface(role, Constants.SUBSCRIBE_TYPE.SUBSCRIBE, set);
}
} else {
//取消注册
set = registeredAdapter.getCheckedModel();
if (set == null || set.isEmpty()) {
Toast.makeText(getContext(), "请选择要取消注册的接口", Toast.LENGTH_SHORT).show();
return;
}
if (set.size() == 1) {
AdasManager.getInstance().subscribeInterface(role, Constants.SUBSCRIBE_TYPE.UNSUBSCRIBE, set.iterator().next());
} else {
AdasManager.getInstance().subscribeInterface(role, Constants.SUBSCRIBE_TYPE.UNSUBSCRIBE, set);
}
}
clearRegistrationViewState();
initRegistrationData();
}
private void clearRegistrationViewState() {
registered_check_all.setChecked(false);
unregistered_check_all.setChecked(false);
registered_check_all.setEnabled(true);
unregistered_check_all.setEnabled(true);
if (registeredAdapter != null)
registeredAdapter.notifyDataSetChanged();
if (unregisteredAdapter != null)
unregisteredAdapter.notifyDataSetChanged();
}
private void initRegistrationData() {
//初始化数据
Set<MessageType> set = AdasManager.getInstance().getSubscribedInterface();
List<InterfaceModel> registeredList = new ArrayList<>();
List<InterfaceModel> unregisteredList = new ArrayList<>();
if (set != null && !set.isEmpty()) {
registered_check_all.setVisibility(View.VISIBLE);
for (MessageType messageType : set) {
registeredList.add(new InterfaceModel(messageType));
}
} else {
registered_check_all.setVisibility(View.INVISIBLE);
}
set = AdasManager.getInstance().getUnsubscribedInterface();
if (set != null && !set.isEmpty()) {
unregistered_check_all.setVisibility(View.VISIBLE);
for (MessageType messageType : set) {
unregisteredList.add(new InterfaceModel(messageType));
}
} else {
unregistered_check_all.setVisibility(View.INVISIBLE);
}
registeredAdapter.setData(registeredList, 0);
unregisteredAdapter.setData(unregisteredList, 0);
hint_registered.setText("已注册接口(" + registeredAdapter.getItemCount() + ")");
hint_unregistered.setText("未注册接口(" + unregisteredAdapter.getItemCount() + ")");
}
private void initRegisteredRecyclerView() {
//创建默认的线性LayoutManager 横向的GridLayoutManager
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rec_registered.setLayoutManager(linearLayoutManager);
//如果可以确定每个item的高度是固定的设置这个选项可以提高性能
rec_registered.setHasFixedSize(false);
rec_registered.setNestedScrollingEnabled(false);
registeredAdapter = new InterfaceAdapter();
rec_registered.setAdapter(registeredAdapter);
}
private void initUnregisteredRecyclerView() {
//创建默认的线性LayoutManager 横向的GridLayoutManager
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rec_unregistered.setLayoutManager(linearLayoutManager);
//如果可以确定每个item的高度是固定的设置这个选项可以提高性能
rec_unregistered.setHasFixedSize(false);
rec_unregistered.setNestedScrollingEnabled(false);
unregisteredAdapter = new InterfaceAdapter();
rec_unregistered.setAdapter(unregisteredAdapter);
}
private void initSpinner(View view) {
String[] s = {"司机", "乘客", "调试"};
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item, s);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner sp = view.findViewById(R.id.spinner);
sp.setAdapter(dataAdapter);
sp.setSelection(2);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
role = position;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}

View File

@@ -10,10 +10,8 @@ import com.zhidao.support.adas.high.common.JsonUtil;
import com.zhidao.support.adas.high.common.MessageType;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* @author song kenan
@@ -157,12 +155,12 @@ public class Constants {
String RECEIVE_REPORT_MESSAGE = MessageType.TYPE_RECEIVE_REPORT_MESSAGE.desc;
String RECEIVE_PERCEPTION_TRAFFIC_LIGHT = MessageType.TYPE_RECEIVE_PERCEPTION_TRAFFIC_LIGHT.desc;
String RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY = MessageType.TYPE_RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY.desc;
String RECEIVE_POINT_CLOUD = MessageType.TYPE_RECEIVE_POINT_CLOUD.desc;
String RECEIVE_POINT_CLOUD_ORIGINAL = "点云原始透传";
String RECEIVE_POINT_CLOUD_ORIGINAL = MessageType.TYPE_RECEIVE_POINT_CLOUD.desc;
String RECEIVE_PLANNING_OBJECTS = MessageType.TYPE_RECEIVE_PLANNING_OBJECTS.desc;
String RECEIVE_PLANNING_DECISION_STATE = MessageType.TYPE_RECEIVE_PLANNING_DECISION_STATE.desc;
// String RECEIVE_BASIC_INFO_REQ = "自动驾驶设备基础信息请求";
String TITLE_CAR_CONFIG_RESP = "工控机版本\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t固定IP配置";
String TITLE_CAR_CONFIG_RESP = "工控机版本\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t配置";
String RECEIVE_CAR_CONFIG_RESP = "信息与配置";
String RECEIVE_RECORD_RESULT = MessageType.TYPE_RECEIVE_RECORD_RESULT.desc;
String RECEIVE_RECORD_DATA_CONFIG_RESP = MessageType.TYPE_RECEIVE_RECORD_DATA_CONFIG_RESP.desc;

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#7CFC00" android:state_pressed="true" />
<item android:color="#7CFC00" android:state_checked="true" />
<item android:color="#c9c9c9" android:state_enabled="false" />
<item android:color="#000000" />
</selector>

View File

@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.12"
android:gravity="right"
android:text="SN"
android:textColor="#000000" />
<EditText
android:id="@+id/et"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="输入SN"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1"
android:minWidth="100dp"
android:textColor="#000"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.12"
android:gravity="right"
android:text="环境:"
android:textColor="#000000" />
<EditText
android:id="@+id/ev"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="默认01研发环境2测试环境3生产环境4演示环境"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLines="1"
android:minWidth="100dp"
android:textColor="#000"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.12"
android:gravity="right"
android:text="角色:"
android:textColor="#000000" />
<EditText
android:id="@+id/role"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="默认20司机屏1乘客屏2调试屏"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLines="1"
android:minWidth="100dp"
android:textColor="#000"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>

View File

@@ -52,7 +52,16 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:padding="10dp">
android:paddingStart="10dp">
<TextView
android:id="@+id/ip_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="工控机固定IP配置"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/ip"
@@ -71,13 +80,13 @@
android:textSize="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@id/ip_hint" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="36dp"
android:layout_margin="5dp"
android:background="@drawable/btn_bg"
android:text="添加"
@@ -89,7 +98,7 @@
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="36dp"
android:layout_margin="5dp"
android:layout_toEndOf="@id/btn1"
android:background="@drawable/btn_bg"
@@ -106,10 +115,151 @@
android:layout_marginTop="10dp"
android:lineSpacingExtra="5dp"
android:textIsSelectable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn1" />
<View
android:id="@+id/line2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ips_view" />
<TextView
android:id="@+id/interface_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="接收接口订阅、取消订阅配置"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="@id/update"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/update" />
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/update"
app:layout_constraintStart_toEndOf="@id/interface_hint"
app:layout_constraintTop_toTopOf="@id/update" />
<Button
android:id="@+id/update"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_bg"
android:text="更新"
android:textColor="#ffffff"
app:layout_constraintStart_toEndOf="@id/spinner"
app:layout_constraintTop_toBottomOf="@id/line2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="选中已注册接口点击更新取消注册\n选中未注册接口点击更新进行注册"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="@id/update"
app:layout_constraintStart_toEndOf="@id/update"
app:layout_constraintTop_toTopOf="@id/update" />
<LinearLayout
android:id="@+id/layout_list_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/update">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="5dp"
android:paddingEnd="5dp">
<TextView
android:id="@+id/hint_registered"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="已注册接口" />
<CheckBox
android:id="@+id/registered_check_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_gravity="end"
android:text="全选" />
</RelativeLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="@color/colorSlateGray" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="5dp"
android:paddingEnd="5dp">
<TextView
android:id="@+id/hint_unregistered"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="未注册接口" />
<CheckBox
android:id="@+id/unregistered_check_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:text="全选" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_list_title">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rec_registered"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="@color/colorSlateGray" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rec_unregistered"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -15,7 +15,7 @@
android:background="?android:attr/selectableItemBackground"
android:gravity="center"
android:text="INFO"
android:textColor="@drawable/item_text_color"
android:textColor="@color/item_text_color"
android:textSize="14sp" />
</LinearLayout>

View File

@@ -15,7 +15,7 @@
android:background="?android:attr/selectableItemBackground"
android:gravity="center"
android:text="INFO"
android:textColor="@drawable/item_text_color"
android:textColor="@color/item_text_color"
android:textSize="16sp" />
</LinearLayout>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="3dp"
android:layout_marginBottom="2dp"
android:foreground="?android:attr/selectableItemBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
android:id="@+id/index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:textColor="@color/item_text_color1"
android:textSize="12sp" />
<CheckBox
android:id="@+id/item_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:ellipsize="marquee"
android:focusable="false"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="sssds"
android:textColor="@color/item_text_color1"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>

View File

@@ -1,6 +1,5 @@
package com.mogo.eagle.core.function.autopilot.adapter
import android.util.*
import chassis.VehicleStateOuterClass
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.config.HdMapBuildConfig
@@ -14,6 +13,7 @@ import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_C
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_ADAS_MESSAGE_AUTOPILOT_VEHICLE
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_ADAS_MESSAGE_CAR_CONFIG
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_ADAS_MESSAGE_CAR_STATE
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_ADAS_MESSAGE_PLANNING_ACTIONS
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_ADAS_MESSAGE_PLANNING_OBJECTS
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_ADAS_MESSAGE_RECT_DATA
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_ADAS_STATUS_QUERY_RESP
@@ -22,6 +22,7 @@ import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LO
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_WEB_SOCKET_AUTOPILOT
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_WEB_SOCKET_DATA_TRACKED
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_WEB_SOCKET_GNSSINFO
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_WEB_SOCKET_PLANNING_ACTIONS
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_WEB_SOCKET_PLANNING_OBJECTS
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_WEB_SOCKET_TRAFFIC_LIGHT
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_WEB_SOCKET_TRAJECTORY
@@ -39,13 +40,13 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListen
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager.invokeAutopilotIdentifyDataUpdate
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager.invokeAutopilotIdentifyPlanningObj
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager.invokeAutopilotWarnMessage
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningActionsListenerManager.invokePNCActions
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager.invokeAutopilotRotting
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningListenerManager.invokeAutopilotTrajectory
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPointCloudListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotRecordListenerManager.invokeAutopilotRecordResult
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotVehicleStateListenerManager
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.network.utils.*
import com.zhidao.support.adas.high.AdasManager
import com.zhidao.support.adas.high.OnAdasListener
import com.zhidao.support.adas.high.common.ProtocolStatus
@@ -57,7 +58,6 @@ import mogo_msg.MogoReportMsg
import perception.TrafficLightOuterClass
import prediction.Prediction
import record_cache.RecordPanelOuterClass
import rule_segement.MogoPointCloudOuterClass
import system_master.SystemStatusInfo
/**
@@ -401,6 +401,26 @@ class MoGoAdasListenerImpl : OnAdasListener {
}
/**
* planning决策状态, 透传
*/
@ChainLog(
linkChainLog = CHAIN_LINK_LOG_WEB_SOCKET_PLANNING_ACTIONS,
linkCode = CHAIN_LINK_ADAS,
endpoint = PAD,
nodeAliasCode = CHAIN_ALIAS_CODE_ADAS_MESSAGE_PLANNING_ACTIONS,
paramIndexes = [0, 1],
clientPkFileName = "sn"
)
override fun onPlanningActionMsg(
header: MessagePad.Header?,
planningActionMsg: MessagePad.PlanningActionMsg?
) {
planningActionMsg?.let {
invokePNCActions(it)
}
}
override fun onError(status: ProtocolStatus, bytes: ByteArray) {

View File

@@ -2,7 +2,7 @@ package com.mogo.eagle.core.function.autopilot.adapter
import android.annotation.SuppressLint
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.commons.debug.DebugConfig
import com.mogo.commons.debug.DebugConfig.*
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
@@ -11,6 +11,7 @@ import com.mogo.eagle.core.function.autopilot.network.AdasServiceModel
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotManager
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
import com.mogo.eagle.core.function.call.cloud.CallerCloudListenerManager
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_ADAS_IMPL
import com.mogo.eagle.core.utilcode.util.ToastUtils
@@ -18,6 +19,9 @@ import com.zhidao.support.adas.high.AdasManager
import com.zhidao.support.adas.high.OnAdasConnectStatusListener
import com.zhidao.support.adas.high.bean.VersionCompatibility
import com.zhidao.support.adas.high.common.Constants
import com.zhidao.support.adas.high.common.Constants.ENVIRONMENT.*
import com.zhidao.support.adas.high.common.Constants.TERMINAL_ROLE.DRIVER
import com.zhidao.support.adas.high.common.Constants.TERMINAL_ROLE.PASSENGER
import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
@@ -133,7 +137,29 @@ class MoGoAdasMsgConnectStatusListenerImpl : OnAdasConnectStatusListener,
CallerLogger.d("$M_ADAS_IMPL$TAG", "同步PAD的SN给工控机……")
// 设置PAD-SN给工控,网络环境
AdasManager.getInstance()
.sendBasicInfoResp(MoGoAiCloudClientConfig.getInstance().sn, DebugConfig.getNetMode())
.sendBasicInfoResp(
MoGoAiCloudClientConfig.getInstance().sn,
getEnvironment(),
getTerminalRole()
)
}
private fun getEnvironment(): Int {
return when (getNetMode()) {
NET_MODE_DEV -> DEVELOP
NET_MODE_QA -> TEST
NET_MODE_RELEASE -> PRODUCTION
NET_MODE_DEMO -> DEMO
else -> PRODUCTION
}
}
private fun getTerminalRole(): Int {
return when {
AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode) -> DRIVER
AppIdentityModeUtils.isPassenger(FunctionBuildConfig.appIdentityMode) -> PASSENGER
else -> DRIVER
}
}
/**

View File

@@ -3,7 +3,7 @@ package com.mogo.eagle.core.function.autopilot.server
import com.mogo.eagle.core.data.trafficlight.TrafficLightResult
import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotManager
import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightListenerManager
import com.mogo.eagle.core.function.call.trafficlight.CallerTrafficLightListenerManager
/**
* @author xiaoyuzhou
@@ -22,7 +22,7 @@ class AsyncDataToAutopilotServer private constructor() : IMoGoTrafficLightListen
}
fun initServer() {
CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
CallerTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
}
override fun onTrafficLightStatus(trafficLightResult: TrafficLightResult) {

View File

@@ -57,6 +57,8 @@ class TraceManager : IMoGoCloudListener {
FwBuild(false, 30, pkgName + ChainConstant.CHAIN_LINK_LOG_ADAS_TRAFFIC_LIGHT)
fwBuildMap[ChainConstant.CHAIN_LINK_LOG_WEB_SOCKET_PLANNING_OBJECTS] =
FwBuild(false, 30, pkgName + ChainConstant.CHAIN_LINK_LOG_ADAS_PLANNING_OBJECTS)
fwBuildMap[ChainConstant.CHAIN_LINK_LOG_WEB_SOCKET_PLANNING_ACTIONS] =
FwBuild(true, -1, pkgName + ChainConstant.CHAIN_LINK_LOG_ADAS_PLANNING_ACTIONS)
traceInfoCache[ChainConstant.CHAIN_LINK_LOG_CONNECT_STATUS] =
ChainLogParam(true, "ADAS连接状态")
@@ -70,8 +72,12 @@ class TraceManager : IMoGoCloudListener {
ChainLogParam(false, "ADAS车前引导线")
traceInfoCache[ChainConstant.CHAIN_LINK_LOG_WEB_SOCKET_VEHICLE] =
ChainLogParam(false, "ADAS车辆底盘数据")
traceInfoCache[ChainConstant.CHAIN_LINK_LOG_WEB_SOCKET_TRAFFIC_LIGHT] =
ChainLogParam(false, "ADAS红绿灯数据")
traceInfoCache[ChainConstant.CHAIN_LINK_LOG_WEB_SOCKET_PLANNING_OBJECTS] =
ChainLogParam(false, "ADAS PLANNING 感知障碍物")
traceInfoCache[ChainConstant.CHAIN_LINK_LOG_WEB_SOCKET_PLANNING_ACTIONS] =
ChainLogParam(true, "ADAS PLANNING 决策行为")
FileWriteManager.getInstance()
.init(context, MoGoAiCloudClientConfig.getInstance().sn, pkgName, fwBuildMap)

View File

@@ -0,0 +1,91 @@
package com.mogo.eagle.core.function.hmi.ui.pnc
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.eagle.core.data.autopilot.pnc.PncActionsHelper
import com.mogo.eagle.core.data.trafficlight.TrafficLightResult
import com.mogo.eagle.core.data.trafficlight.currentRoadTrafficLight
import com.mogo.eagle.core.data.trafficlight.isRed
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningActionsListener
import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningActionsListenerManager
import com.mogo.eagle.core.function.call.trafficlight.CallerTrafficLightListenerManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import kotlinx.android.synthetic.main.view_pnc_actions.view.*
import mogo.telematics.pad.MessagePad
class PncActionsView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr), IMoGoAutopilotPlanningActionsListener,
IMoGoTrafficLightListener {
companion object {
const val TAG = "PncActionsView"
}
@Volatile
private var mTrafficLightResult: TrafficLightResult? = null
init {
LayoutInflater.from(context).inflate(R.layout.view_pnc_actions, this, true)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
CallerAutopilotPlanningActionsListenerManager.addListener(TAG, this)
CallerTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
CallerAutopilotPlanningActionsListenerManager.removeListener(TAG)
CallerTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
}
override fun pncActions(planningActionMsg: MessagePad.PlanningActionMsg) {
UiThreadHandler.post {
var actions: String? = null
planningActionMsg.actionMsg?.let {
actions = PncActionsHelper.getAction(it.drivingState.number, it.drivingAction.number)
//如果是存在云端红绿灯数据条件下,设置云端数据
if (PncActionsHelper.isWaitingTrafficlight(
it.drivingState.number,
it.drivingAction.number
)
&& mTrafficLightResult != null
&& getWaitTrafficlightTime().isNotBlank()
) {
actions += ",预计${getWaitTrafficlightTime()}秒后通过"
} else {
mTrafficLightResult = null
}
}
// update view
actions?.let {
tvHmiPncActions.text = actions
}
}
}
override fun onTrafficLightStatus(trafficLightResult: TrafficLightResult) {
mTrafficLightResult = trafficLightResult
}
private fun getWaitTrafficlightTime(): String {
return if (mTrafficLightResult != null
&& mTrafficLightResult!!.currentRoadTrafficLight() != null
&& mTrafficLightResult!!.currentRoadTrafficLight()!!.isRed()
) {
mTrafficLightResult!!.currentRoadTrafficLight()!!.remain.toString()
} else {
""
}
}
}

View File

@@ -565,6 +565,15 @@ class DebugSettingView @JvmOverloads constructor(
tbIsRainMode.visibility = View.GONE
}
tbBeautyMode.isChecked = FunctionBuildConfig.isBeautyMode
//感知优化模式
tbBeautyMode.setOnCheckedChangeListener { _, isChecked ->
FunctionBuildConfig.isBeautyMode = isChecked
if (!FunctionBuildConfig.isBeautyMode) {
tbBeautyMode.isChecked = false
}
}
//重启工控机所有节点
btnIpcReboot.onClick {
CallerAutoPilotManager.sendIpcReboot()
@@ -1379,6 +1388,19 @@ class DebugSettingView @JvmOverloads constructor(
}
}
/**
* ADAS红绿灯数据
*/
cbAdasTrafficlight.setOnCheckedChangeListener { _, isChecked ->
val map = CallerDevaToolsManager.getTraceInfo()
val param = map[ChainConstant.CHAIN_LINK_LOG_WEB_SOCKET_TRAFFIC_LIGHT]
param?.let {
it.record = isChecked
map[ChainConstant.CHAIN_LINK_LOG_WEB_SOCKET_TRAFFIC_LIGHT] = param
CallerDevaToolsManager.refreshTraceInfo(map)
}
}
/**
* ADAS PLANNING OBJ 感知障碍物
*/
@@ -1412,6 +1434,10 @@ class DebugSettingView @JvmOverloads constructor(
vehicle?.let {
cbAdasVehicle.isChecked = it.record
}
val trafficlight = traceInfoMap[ChainConstant.CHAIN_LINK_LOG_WEB_SOCKET_TRAFFIC_LIGHT]
trafficlight?.let {
cbAdasTrafficlight.isChecked = it.record
}
}
/**

View File

@@ -181,6 +181,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.mogo.eagle.core.function.hmi.ui.pnc.PncActionsView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dp_200"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<!--APP、MAP版本-->
<com.mogo.eagle.core.function.hmi.ui.widget.VersionNameView
android:layout_width="wrap_content"

View File

@@ -232,6 +232,17 @@
android:textSize="@dimen/dp_24"
android:background="@drawable/radio_button_normal_background_right"/>
<ToggleButton
android:id="@+id/tbBeautyMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dp_10"
android:textColor="#000"
android:textOff="开启感知优化模式"
android:textOn="关闭感知优化模式"
android:textSize="@dimen/dp_24"
android:background="@drawable/radio_button_normal_background_right"/>
<Button
android:id="@+id/btnIpcReboot"
android:layout_width="match_parent"
@@ -2030,6 +2041,16 @@
android:textColor="#000"
android:textSize="@dimen/dp_24" />
<CheckBox
android:id="@+id/cbAdasTrafficlight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:padding="@dimen/dp_10"
android:text="ADAS红绿灯数据"
android:textColor="#000"
android:textSize="@dimen/dp_24" />
<CheckBox
android:id="@+id/cbAdasPlanningObj"
android:layout_width="wrap_content"

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvHmiPncActions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/sp_30"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -2,6 +2,7 @@ package com.mogo.eagle.core.function.map.identify
import android.os.Handler
import android.os.Message
import android.util.Log
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.mogo.eagle.core.utilcode.mogo.thread.WorkThreadHandler
@@ -20,7 +21,7 @@ object IdentifyFactory : Identify {
private var identify: Identify? = null
init {
identify = if (AppIdentityModeUtils.isBus(FunctionBuildConfig.appIdentityMode)) {
identify = if (FunctionBuildConfig.isBeautyMode) {
UserIdentify.beautifyDataDrawer
} else {
DriverIdentify.originDataDrawer
@@ -36,6 +37,17 @@ object IdentifyFactory : Identify {
object : Handler(WorkThreadHandler.newInstance("IdentifyFactoryDrawer").looper) {
override fun handleMessage(msg: Message) {
super.handleMessage(msg)
if(!FunctionBuildConfig.isBeautyMode){
if(identify is IdentifyBeautifyDataDrawer){
identify!!.clearOldMarker()
identify = DriverIdentify.originDataDrawer
}
}else{
if(identify is IdentifyOriginDataDrawer){
identify!!.clearOldMarker()
identify = UserIdentify.beautifyDataDrawer
}
}
when(msg.what){
MSG_DATA_TRACK -> {
if(msg.obj is List<*>){

View File

@@ -154,11 +154,11 @@ class IdentifyOriginDataDrawer : Identify, IMoGoAutopilotStatusListener {
//首次过来的数据不添加,首次未添加的感知物在调用完绘制方法后再塞入cache map
val cacheData = mMarkersCaches[uuid]
if (cacheData != null) {
if (data.speed < 0.5) {
temp = data.toBuilder().setHeading(cacheData.heading)
.setLongitude(cacheData.longitude)
.setLatitude(cacheData.latitude).build()
}
// if (data.speed < 0.5) {
// temp = data.toBuilder().setHeading(cacheData.heading)
// .setLongitude(cacheData.longitude)
// .setLatitude(cacheData.latitude).build()
// }
if (colorTrafficData.containsKey(uuid)) {
val planningTrack = colorTrafficData[uuid]
if (!timeOut(planningTrack!!.time)) {

View File

@@ -5,9 +5,8 @@ import com.alibaba.android.arouter.facade.annotation.Route
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.constants.MogoServicePaths.PATH_V2X_MODULE
import com.mogo.eagle.core.function.api.base.IMoGoFunctionServerProvider
import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightManager
import com.mogo.eagle.core.function.call.trafficlight.CallerTrafficLightManager
import com.mogo.eagle.core.function.v2x.events.V2XEventManager
import com.mogo.eagle.core.function.v2x.redlightwarning.RedLightWarningManager
import com.mogo.eagle.core.function.v2x.speedlimit.SpeedLimitDataManager
import com.mogo.eagle.core.function.v2x.trafficlight.core.TrafficLightDispatcher
import com.mogo.eagle.core.function.v2x.vip.VipCarManager
@@ -20,7 +19,7 @@ class V2XProvider : IMoGoFunctionServerProvider {
get() = "V2XProvider"
override fun init(context: Context) {
CallTrafficLightManager.getTrafficLightProvider().initTrafficLightServer(context)
CallerTrafficLightManager.getTrafficLightProvider().initTrafficLightServer(context)
VipCarManager.INSTANCE.initServer(context)
SpeedLimitDataManager.getInstance().start()
TrafficLightDispatcher.INSTANCE.initServer(context)

View File

@@ -10,9 +10,8 @@ import com.mogo.eagle.core.function.api.vip.IMoGoVipSetListener
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightListenerManager
import com.mogo.eagle.core.function.call.trafficlight.CallerTrafficLightListenerManager
import com.mogo.eagle.core.function.call.vip.CallVipSetListenerManager
import com.mogo.eagle.core.function.v2x.vip.VipCarManager
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.mogo.map.navi.IMogoCarLocationChangedListener2
import com.mogo.module.common.MogoApisHandler
@@ -72,12 +71,9 @@ class RedLightWarningManager : IMoGoTrafficLightListener, IMoGoVipSetListener,
}
fun listenTrafficLight() {
CallTrafficLightListenerManager.registerEnterCrossRoadListener(TAG, this)
CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
MogoApisHandler.getInstance().apis.registerCenterApi.registerCarLocationChangedListener(
VipCarManager.TAG,
this
)
CallerTrafficLightListenerManager.registerEnterCrossRoadListener(TAG, this)
CallerTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
MogoApisHandler.getInstance().apis.registerCenterApi.registerCarLocationChangedListener(TAG, this)
CallVipSetListenerManager.registerVipSetListener(TAG, this)
}
@@ -196,9 +192,9 @@ class RedLightWarningManager : IMoGoTrafficLightListener, IMoGoVipSetListener,
}
fun onDestroy() {
CallTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
CallerTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
CallVipSetListenerManager.unRegisterVipSetListener(TAG)
CallTrafficLightListenerManager.unRegisterEnterCrossRoadListener(TAG)
CallerTrafficLightListenerManager.unRegisterEnterCrossRoadListener(TAG)
MogoApisHandler.getInstance().apis.registerCenterApi.unregisterCarLocationChangedListener(
TAG, this
)

View File

@@ -11,7 +11,7 @@ import com.mogo.eagle.core.data.trafficlight.TrafficLightResult
import com.mogo.eagle.core.data.trafficlight.isInRange
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightListenerManager
import com.mogo.eagle.core.function.call.trafficlight.CallerTrafficLightListenerManager
import com.mogo.eagle.core.function.v2x.trafficlight.TrafficLightHMIManager
import com.mogo.eagle.core.function.v2x.trafficlight.core.TrafficLightThreadHandler.Companion.MSG_WHAT_LOOP_SEARCH_CROSS_ROAD
import com.mogo.eagle.core.function.v2x.trafficlight.core.TrafficLightThreadHandler.Companion.MSG_WHAT_LOOP_SEARCH_TRAFFIC_LIGHT
@@ -52,7 +52,7 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 {
//第一次查询路口时,如果红绿灯显示,则隐藏掉
if(firstLoopCrossRoad && TrafficLightHMIManager.INSTANCE.isWarningTrafficLightShow()){
TrafficLightHMIManager.INSTANCE.hideTrafficLight()
CallTrafficLightListenerManager.resetTrafficLightData()
CallerTrafficLightListenerManager.resetTrafficLightData()
}
firstLoopCrossRoad = false
mLocation?.let { it ->
@@ -81,7 +81,7 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 {
it.latitude, it.longitude, it.bearing.toDouble(), road, { result ->
trafficLightResult = result
// TrafficLightHMIManager.INSTANCE.updateTrafficLight(result)
CallTrafficLightListenerManager.invokeTrafficLightStatus(result)
CallerTrafficLightListenerManager.invokeTrafficLightStatus(result)
},
{ errorMsg ->
//如果没有获取到正确的红绿灯数据,则取消读灯,继续读路口,防止出现一直读灯的情况
@@ -103,9 +103,9 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 {
}
if (TrafficLightHMIManager.INSTANCE.isWarningTrafficLightShow()) {
TrafficLightHMIManager.INSTANCE.hideTrafficLight()
CallTrafficLightListenerManager.resetTrafficLightData()
CallerTrafficLightListenerManager.resetTrafficLightData()
}
CallTrafficLightListenerManager.invokeTrafficRequestError()
CallerTrafficLightListenerManager.invokeTrafficRequestError()
})
}
@@ -130,18 +130,18 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 {
if (trafficLightResult != null && it.isInRange(loc.latitude, loc.longitude)) {
inRange = true
// CallerLogger.d(M_V2X + TAG, "进入路口")
CallTrafficLightListenerManager.invokeEnterCrossRoad(true)
CallerTrafficLightListenerManager.invokeEnterCrossRoad(true)
return
}
if (inRange) {
// CallerLogger.d(M_V2X + TAG, "离开路口")
CallTrafficLightListenerManager.invokeEnterCrossRoad(false)
CallerTrafficLightListenerManager.invokeEnterCrossRoad(false)
inRange = false
trafficLightResult = null
firstLoopCrossRoad = true
mThreadHandler?.sendEmptyMessage(MSG_WHAT_STOP_SEARCH_TRAFFIC_LIGHT)
TrafficLightHMIManager.INSTANCE.hideTrafficLight()
CallTrafficLightListenerManager.resetTrafficLightData()
CallerTrafficLightListenerManager.resetTrafficLightData()
}
}
}

View File

@@ -7,7 +7,7 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotIdentifyListener
import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotIdentifyListenerManager
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightListenerManager
import com.mogo.eagle.core.function.call.trafficlight.CallerTrafficLightListenerManager
import com.mogo.eagle.core.function.v2x.trafficlight.TrafficLightHMIManager
import perception.TrafficLightOuterClass
import perception.TrafficLightOuterClass.TrafficLight
@@ -34,11 +34,11 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener , IMoGoTrafficLigh
fun initServer(context: Context){
mContext = context
//注册监听AI云获取红绿灯状态
CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
CallerTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
//注册监听AI云进入路口
CallTrafficLightListenerManager.registerEnterCrossRoadListener(TAG, this)
CallerTrafficLightListenerManager.registerEnterCrossRoadListener(TAG, this)
//注册监听红绿灯请求失败
CallTrafficLightListenerManager.registerTrafficRequestErrorListener(TAG,this)
CallerTrafficLightListenerManager.registerTrafficRequestErrorListener(TAG,this)
//注册监听工控机感知红绿灯
CallerAutopilotIdentifyListenerManager.addListener(TAG, this)
}
@@ -119,13 +119,13 @@ class TrafficLightDispatcher : IMoGoAutopilotIdentifyListener , IMoGoTrafficLigh
fun destroy(){
//取消注册监听AI云获取红绿灯状态
CallTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
CallerTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
//取消注册监听工控机感知红绿灯
CallerAutopilotIdentifyListenerManager.removeListener(TAG)
//取消注册监听红绿灯请求失败
CallTrafficLightListenerManager.unRegisterTrafficRequestErrorListener(TAG)
CallerTrafficLightListenerManager.unRegisterTrafficRequestErrorListener(TAG)
//取消注册监听AI云进入路口
CallTrafficLightListenerManager.unRegisterEnterCrossRoadListener(TAG)
CallerTrafficLightListenerManager.unRegisterEnterCrossRoadListener(TAG)
}
}

View File

@@ -15,7 +15,7 @@ import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightListenerManager
import com.mogo.eagle.core.function.call.trafficlight.CallerTrafficLightListenerManager
import com.mogo.eagle.core.function.call.vip.CallVipSetListenerManager
import com.mogo.eagle.core.function.v2x.trafficlight.core.MogoTrafficLightManager
import com.mogo.eagle.core.function.v2x.vip.network.VipNetWorkModel
@@ -183,8 +183,8 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
)
CallerHmiManager.vipIdentification(true)
CallVipSetListenerManager.invokeVipSetStatus(true)
CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
CallTrafficLightListenerManager.registerEnterCrossRoadListener(TAG, this)
CallerTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
CallerTrafficLightListenerManager.registerEnterCrossRoadListener(TAG, this)
}
private fun cancelVip() {
@@ -194,8 +194,8 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
}
CallerHmiManager.vipIdentification(false)
CallVipSetListenerManager.invokeVipSetStatus(false)
CallTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
CallTrafficLightListenerManager.unRegisterEnterCrossRoadListener(TAG)
CallerTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
CallerTrafficLightListenerManager.unRegisterEnterCrossRoadListener(TAG)
}
private fun canGetThroughCross(

View File

@@ -0,0 +1,54 @@
package com.mogo.eagle.core.data.autopilot.pnc
import mogo.telematics.pad.MessagePad.DrivingState.*
class PncActionsHelper {
companion object {
fun getAction(driveState: Int, driveAction: Int): String {
return when (driveState) {
// 不在自动驾驶状态
NO_AUTODRIVING_VALUE -> {
""
}
// 车道保持
LANKE_KEEP_VALUE -> {
"正在跟随车辆行驶"
}
// 红绿灯通行状态 driving_action1 表示停止动作driving_action:2 表示通行动作
TRAFFIC_LIGHT_VALUE -> {
if (driveAction == 1) "正在等红灯" else ""
}
// follow全局择机向左变道状态 driving_action1 表示触发变道driving_action:2 表示择机保持driving_action:3 表示变道完成
FOLLOW_LANE_CHANGE_LEFT_VALUE -> {
if (driveAction == 2) "正在向左变道" else if (driveAction == 3) "正在完成变道" else ""
}
// follow全局择机向右变道状态 driving_action1 表示触发变道driving_action:2 表示择机保持driving_action:3 表示变道完成
FOLLOW_LANE_CHANGE_RIGHT_VALUE -> {
if (driveAction == 2) "正在向右变道" else if (driveAction == 3) "正在完成变道" else ""
}
// 变道绕障 主动向左/右变道状态 driving_action1 表示触发变道driving_action:2 表示执行变道driving_action:3 表示变道取消driving_action:4 表示变道完成
AUTO_LANE_CHANGE_LEFT_VALUE, AUTO_LANE_CHANGE_RIGHT_VALUE -> {
if (driveAction == 2) "正在绕过障碍物" else if (driveAction == 3) "变道取消" else ""
}
// 主动向左/右绕行状态 driving_action1 表示触发绕行driving_action:2 表示执行绕行driving_action:3 表示绕行取消driving_action:4 表示绕行完成
LANE_AVOID_LEFT_VALUE, LANE_AVOID_RIGHT_VALUE -> {
if (driveAction == 2) "正在避让障碍物" else ""
}
// 起步状态 driving_action1 表示正常启动driving_action:2 表示择机起步;
START_UP_VALUE -> {
if (driveAction == 1) "正在出站" else if (driveAction == 2) "正在等待出站" else ""
}
// 靠边停车状态 driving_action1 表示正常靠边停车driving_action:2 表示择机靠边停车;
PULL_OVER_VALUE -> {
if (driveAction == 1) "正在进站" else if (driveAction == 2) "正在等待进站" else ""
}
else -> ""
}
}
fun isWaitingTrafficlight(driveState: Int, driveAction: Int): Boolean {
return driveState == TRAFFIC_LIGHT_VALUE && driveAction == 1
}
}
}

View File

@@ -29,6 +29,17 @@ object FunctionBuildConfig {
@JvmField
var isRainMode = false
/**
* 是否是感知优化模式
* 默认开启
* 打开后可实现感知优化效果
* 1、静止车辆抖动优化
* 2、静止车辆航向角和位置按车道方向优化
*/
@Volatile
@JvmField
var isBeautyMode = true
/**
* 当前APP的身份模式
*

View File

@@ -19,6 +19,7 @@ class ChainConstant {
const val CHAIN_LINK_LOG_WEB_SOCKET_VEHICLE = 5
const val CHAIN_LINK_LOG_WEB_SOCKET_TRAFFIC_LIGHT = 6
const val CHAIN_LINK_LOG_WEB_SOCKET_PLANNING_OBJECTS = 7
const val CHAIN_LINK_LOG_WEB_SOCKET_PLANNING_ACTIONS = 8
const val CHAIN_LINK_LOG_ADAS_INIT = "-eagleInitStatus"
const val CHAIN_LINK_LOG_ADAS_GNSS = "-adasWsGnssInfo"
@@ -28,6 +29,7 @@ class ChainConstant {
const val CHAIN_LINK_LOG_ADAS_VEHICLE = "-adasWsVehicle"
const val CHAIN_LINK_LOG_ADAS_TRAFFIC_LIGHT = "-adasWsTrafficLight"
const val CHAIN_LINK_LOG_ADAS_PLANNING_OBJECTS = "-adasWsPlanningObj"
const val CHAIN_LINK_LOG_ADAS_PLANNING_ACTIONS = "-adasWsPlanningActions"
const val CHAIN_ALIAS_CODE_MULTI_CONNECT = "CHAIN_ALIAS_CODE_MULTI_CONNECT"
const val CHAIN_ALIAS_CODE_ADAS_MESSAGE_CAR_CONFIG = "CHAIN_ALIAS_CODE_CAR_CONFIG"
@@ -42,12 +44,14 @@ class ChainConstant {
const val CHAIN_ALIAS_CODE_ADAS_MESSAGE_AUTOPILOT_VEHICLE = "PAD_ADAS_MESSAGE_AUTOPILOT_VEHICLE"
const val CHAIN_ALIAS_CODE_ADAS_MESSAGE_AUTOPILOT_TRAFFIC_LIGHT = "PAD_ADAS_MESSAGE_AUTOPILOT_TRAFFIC_LIGHT"
const val CHAIN_ALIAS_CODE_ADAS_MESSAGE_PLANNING_OBJECTS = "CHAIN_ALIAS_CODE_ADAS_MESSAGE_PLANNING_OBJECTS"
const val CHAIN_ALIAS_CODE_ADAS_MESSAGE_PLANNING_ACTIONS = "CHAIN_ALIAS_CODE_ADAS_MESSAGE_PLANNING_ACTIONS"
const val CHAIN_ALIAS_CODE_ADAS_STATUS_QUERY_RESP = "CHAIN_ALIAS_CODE_ADAS_STATUS_QUERY_RESP"
const val CHAIN_ALIAS_CODE_ADAS_MESSAGE_AUTOPILOT_WARN = "PAD_ADAS_MESSAGE_AUTOPILOT_WARN"
const val CHAIN_ALIAS_CODE_CLOUD_CONNECT_FAIL = "CHAIN_ALIAS_CODE_CLOUD_CONNECT_FAIL"
const val CHAIN_ALIAS_CODE_CLOUD_CONNECT_SUCCESS = "CHAIN_ALIAS_CODE_CLOUD_CONNECT_SUCCESS"
const val CHAIN_ALIAS_CODE_CLOUD_CONNECT_LOST = "CHAIN_ALIAS_CODE_CLOUD_CONNECT_LOST"
const val CHAIN_ALIAS_CODE_HTTP_DNS_CHANGED = "CHAIN_ALIAS_CODE_HTTP_DNS_CHANGED"
const val CHAIN_ALIAS_CODE_INIT_ON_MAP_LOADED = "CHAIN_ALIAS_CODE_INIT_ON_MAP_LOADED"
const val CHAIN_ALIAS_CODE_INIT_ON_MAP_INIT = "CHAIN_ALIAS_CODE_INIT_ON_MAP_INIT"

View File

@@ -0,0 +1,14 @@
package com.mogo.eagle.core.function.api.autopilot
import mogo.telematics.pad.MessagePad
/**
* 自动驾驶决策行为相关的监听
*/
interface IMoGoAutopilotPlanningActionsListener {
/**
* pnc actions 决策 驾驶的意图
*/
fun pncActions(planningActionMsg: MessagePad.PlanningActionMsg)
}

View File

@@ -0,0 +1,69 @@
package com.mogo.eagle.core.function.call.autopilot
import androidx.annotation.Nullable
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningActionsListener
import com.mogo.eagle.core.function.call.base.CallerBase
import mogo.telematics.pad.MessagePad
import java.util.concurrent.ConcurrentHashMap
/**
* PNC 决策行为相关监听
*/
object CallerAutopilotPlanningActionsListenerManager : CallerBase() {
private val M_AUTOPILOT_PLANNING_ACTIONS_LISTENER: ConcurrentHashMap<String, IMoGoAutopilotPlanningActionsListener> =
ConcurrentHashMap()
/**
* 添加监听
* @param tag 标记,用来注销监听使用
* @param listener 监听回调
*/
fun addListener(
@Nullable tag: String,
@Nullable listener: IMoGoAutopilotPlanningActionsListener
) {
if (M_AUTOPILOT_PLANNING_ACTIONS_LISTENER.containsKey(tag)) {
return
}
M_AUTOPILOT_PLANNING_ACTIONS_LISTENER[tag] = listener
}
/**
* 删除监听
* @param tag 标记,用来注销监听使用
*/
fun removeListener(@Nullable tag: String) {
if (!M_AUTOPILOT_PLANNING_ACTIONS_LISTENER.containsKey(tag)) {
return
}
M_AUTOPILOT_PLANNING_ACTIONS_LISTENER.remove(tag)
}
/**
* 删除自动驾驶按钮选中监听
* @param listener 要删除的监听对象
*/
fun removeListener(@Nullable listener: IMoGoAutopilotPlanningActionsListener) {
M_AUTOPILOT_PLANNING_ACTIONS_LISTENER.forEach {
if (it.value == listener) {
M_AUTOPILOT_PLANNING_ACTIONS_LISTENER.remove(it.key)
}
}
}
/**
* pnc actions 决策回调
* @param planningActionMsg 具体决策
*/
@Synchronized
fun invokePNCActions(planningActionMsg: MessagePad.PlanningActionMsg) {
M_AUTOPILOT_PLANNING_ACTIONS_LISTENER.forEach {
val tag = it.key
val listener = it.value
listener.pncActions(planningActionMsg)
}
}
}

View File

@@ -5,7 +5,7 @@ import com.mogo.eagle.core.data.trafficlight.TrafficLightResult
import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener
import java.util.concurrent.ConcurrentHashMap
object CallTrafficLightListenerManager {
object CallerTrafficLightListenerManager {
private val M_TRAFFIC_LIGHT_LISTENER: ConcurrentHashMap<String, IMoGoTrafficLightListener> =
ConcurrentHashMap()

View File

@@ -4,7 +4,7 @@ import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.function.api.trafficlight.ITrafficLightProvider
import com.mogo.eagle.core.function.call.base.CallerBase
object CallTrafficLightManager : CallerBase() {
object CallerTrafficLightManager : CallerBase() {
fun getTrafficLightProvider(): ITrafficLightProvider {
return getApiInstance(

View File

@@ -3,13 +3,15 @@ package mogo.telematics.pad;
enum ProtocolVersion{
Defaultver = 0;
CurrentVersion = 4; //每次修改proto文件增加1
CurrentVersion = 7; //每次修改proto文件增加1
}
enum MessageType
{
MsgTypeDefault = 0;
MsgTypePlanningDecisionState = 0x00001; //planning决策状态, 透传
MsgTypeTrajectory = 0x10000; //局部轨迹,车前引导线
MsgTypeTrackedObjects = 0x10001; //障碍物信息
MsgTypeGnssInfo = 0x10002; //惯导信息
@@ -44,6 +46,8 @@ enum MessageType
MsgTypeSetRainModeReq = 0x10113; //设置雨天模式
MsgTypeRecordDataConfigReq = 0x10114; //数据采集配置查询请求
MsgTypeRecordDataConfigResp = 0x10115; //数据采集配置查询应答
MsgTypeOperatorCmdReq = 0x10116; //操控指令
MsgTypeSubscribeDataReq = 0x10117; //数据订阅、取消订阅请求
}
message Header
@@ -156,6 +160,7 @@ message PlanningObjects
// message definition for MessageType: MsgTypeOBU
// refer to obu.proto
// message definition for MsgTypeTrajectoryDownloadReq
message Line
{
@@ -188,6 +193,7 @@ message BasicInfoResp
{
string sn = 1;
uint32 environment = 2; //1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
uint32 role = 3; //客户端角色0: 司机屏1: 乘客屏2: 调试屏
}
// message definition for MsgTypeSetAutopilotModeReq
@@ -375,3 +381,62 @@ message RecordDataConfig
repeated RecordDataType recordTypes = 1;
}
// message definition for MsgTypeSubscribeDataReq
message SubscribeDataReq
{
uint32 role = 1; //客户端角色0: 司机屏1: 乘客屏2: 调试屏
uint32 reqType = 2; //1:订阅, 2:取消订阅
repeated uint32 dataTypes = 3; //订阅/取消订阅的消息类型列表, 透传的消息类型参考配置列表其他消息类型见MsgType
}
// message definition for MsgTypeOperatorCmdReq
enum OperatorCmdType {
OPERATOR_CMD_NONE = 0;
OPERATOR_CMD_CHANGE_LANE = 1;
OPERATOR_CMD_SET_ACCELERATED_SPEED = 2;
OPERATOR_CMD_SET_HORN = 3;
}
message OperatorCmdReq
{
OperatorCmdType cmdType = 1;
double value = 2; //OPERATOR_CMD_CHANGE_LANE: 1: left 2: right
//OPERATOR_CMD_SET_ACCELERATED_SPEED: accelerated speed
//OPERATOR_CMD_SET_HORN: 1: honk 2: stop honking
}
//message definition for MsgTypePlanningDecisionState
enum DrivingState{
NO_AUTODRIVING = 0; //不在自动驾驶状态
LANKE_KEEP = 1; //车道保持状态
TRAFFIC_LIGHT = 2; //红绿灯通行状态: driving_action1 表示停止动作driving_action:2 表示通行动作
FOLLOW_LANE_CHANGE_LEFT = 3; //follow全局择机向左变道状态: driving_action1 表示触发变道driving_action:2 表示择机保持driving_action:3 表示变道完成
FOLLOW_LANE_CHANGE_RIGHT = 4; //follow全局择机向右变道状态: driving_action1 表示触发变道driving_action:2 表示择机保持driving_action:3 表示变道完成
AUTO_LANE_CHANGE_LEFT = 5; //主动向左变道状态: driving_action1 表示触发变道driving_action:2 表示执行变道driving_action:3 表示变道取消driving_action:4 表示变道完成
AUTO_LANE_CHANGE_RIGHT = 6; //主动向左变道状态: driving_action1 表示触发变道driving_action:2 表示执行变道driving_action:3 表示变道取消driving_action:4 表示变道完成
LANE_AVOID_LEFT = 7; //主动向左绕行状态: driving_action1 表示触发绕行driving_action:2 表示执行绕行driving_action:3 表示绕行取消driving_action:4 表示绕行完成
LANE_AVOID_RIGHT = 8; //主动向右绕行状态: driving_action1 表示触发绕行driving_action:2 表示执行绕行driving_action:3 表示绕行取消driving_action:4 表示绕行完成
START_UP = 9; //起步状态: driving_action1 表示正常启动driving_action:2 表示择机起步;
PULL_OVER = 10; //靠边停车状态: driving_action1 表示正常靠边停车driving_action:2 表示择机靠边停车;
UN_PROTECTED_INTERSECTION = 11; //路口预测响应状态: driving_action1 表示触发了预测响应;
}
enum DrivingAction{
DRIVING_Action_STATE_NONE = 0;
DRIVING_ACTION_STATE_ONE = 1;
DRIVING_ACTION_STATE_TWO = 2;
DRIVING_ACTION_STATE_THREE = 3;
DRIVING_ACTION_STATE_FOUR = 4;
}
message DrivingActionMsg
{
DrivingState driving_state = 1;
DrivingAction driving_action = 2;
}
message PlanningActionMsg
{
DrivingActionMsg action_msg = 1;
double destination_acc = 2; //驾驶的意图(规划期望的加速或者减速值)
}

View File

@@ -4,8 +4,8 @@ package rule_segement;
import "header.proto";
message MogoPointCloud
{
optional common.Header header = 1;
{
optional common.Header header = 1;
optional double self_longitude = 2;
optional double self_latitude = 3;
optional double self_altitude = 4;
@@ -13,4 +13,5 @@ message MogoPointCloud
optional double self_pitch = 6;
optional double self_yaw = 7;
repeated int32 add_data = 8 [packed=true];
optional double newgpstimestamp = 9;
}

View File

@@ -36,11 +36,13 @@ import com.zhidao.support.adas.high.protocol.RawUnpack;
import com.zhidao.support.adas.high.queue.WSByteQueueManager;
import com.zhidao.support.adas.high.queue.WebSocketQueueManager;
import com.zhidao.support.adas.high.socket.FpgaSocket;
import com.zhidao.support.adas.high.subscribe.SubscribeInterface;
import com.zhidao.support.adas.high.thread.DispatchHandler;
import com.zhjt.service.chain.ChainLog;
import com.zhjt.service.chain.TracingConstants;
import java.util.HashSet;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;
@@ -60,7 +62,7 @@ import okio.ByteString;
* @UpdateRemark: 更新说明:
* @Version: 1.0
*/
public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnectListener, IPCFixationIPHelper.IIPCFixationIPListener, DispatchHandler.OnDispatchHandlerListener {
public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnectListener, IPCFixationIPHelper.IIPCFixationIPListener, DispatchHandler.OnDispatchHandlerListener, SubscribeInterface.OnSubscribeInterfaceListener {
private static final String TAG = AdasChannel.class.getSimpleName();
private static final String THREAD_NAME_DISPATCH_EVENT = "IPCEventDispatchHandler";//除点云单独拆分线程以外都是用此名称
private static final String THREAD_NAME_DISPATCH_POINT_CLOUD = "IPCPointCloudDispatchHandler";
@@ -104,6 +106,11 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
* IPC固定IP查询工具类
*/
private IPCFixationIPHelper ipcFixationIPHelper;
/**
* 工控机接口注册 连接成功后可以进行操作 乘客屏未null
* 乘客屏无法进行注册或取消注册,因为乘客屏无法感知司机屏与工控机连接状态。无法重置已注册或未注册接口列表
*/
private SubscribeInterface subscribeInterface;
public void setOnMultiDeviceListener(OnMultiDeviceListener onMultiDeviceListener) {
this.onMultiDeviceListener = onMultiDeviceListener;
@@ -397,6 +404,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
sendCarConfigReq();
ipcConnectedIp = ipAddress;
ipcConnectedPort = port;
subscribeInterface = new SubscribeInterface(this);
updateConnectStatus(Constants.IPC_CONNECTION_STATUS.CONNECTED, "已连接");
}
@@ -404,6 +412,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
public void onWebSocketConnectFailed(String t) {
ipcConnectedIp = null;
ipcConnectedPort = Constants.DEFAULT_PORT;
subscribeInterface = null;
updateConnectStatus(Constants.IPC_CONNECTION_STATUS.DISCONNECTED, t);
}
@@ -487,9 +496,6 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
clientPkFileName = "sn")
private void updateConnectStatus(@Define.IPCConnectionStatus int status, @Nullable String reason) {
ipcConnectionStatus.set(status);
if (adasConnectStatusListener != null) {
adasConnectStatusListener.onConnectionIPCStatus(ipcConnectionStatus.get(), reason);
}
if (status == Constants.IPC_CONNECTION_STATUS.CONNECTED) {
startDispatchHandler();
startCheckCompatibility();
@@ -500,6 +506,9 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
AdasManager.getInstance().setCarConfig(null);
stopDispatchHandler();
}
if (adasConnectStatusListener != null) {
adasConnectStatusListener.onConnectionIPCStatus(ipcConnectionStatus.get(), reason);
}
CupidLogUtils.i(TAG, "工控机连接状态 status=" + status + " reason=" + reason);
}
@@ -620,11 +629,12 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
* 自动驾驶设备基础信息应答
*
* @param sn SN
* @param environment 1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
* @return boolean
*/
@Override
public boolean sendBasicInfoResp(@NonNull String sn, int environment) {
public boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role) {
if (sn == null) {
sn = "";
}
@@ -632,6 +642,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
.newBuilder()
.setSn(sn)
.setEnvironment(environment)
.setRole(role)
.build();
return sendPBMessage(MessageType.TYPE_SEND_BASIC_INFO_RESP.typeCode, resp.toByteArray());
}
@@ -947,5 +958,75 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
.build();
return sendPBMessage(MessageType.TYPE_SEND_RECORD_DATA_CONFIG_REQ.typeCode, req.toByteArray());
}
/**************************************注册接口相关*******************************************/
@Override
public boolean onSendSubscribe(byte[] bytes) {
return sendPBMessage(MessageType.TYPE_SEND_SUBSCRIBE_DATA_REQ.typeCode, bytes);
}
/**
* 获取已注册接口
*/
@Override
public Set<MessageType> getSubscribedInterface() {
return subscribeInterface == null ? null : subscribeInterface.getSubscribedInterface();
}
/**
* 获取未注册接口
*/
@Override
public Set<MessageType> getUnsubscribedInterface() {
return subscribeInterface == null ? null : subscribeInterface.getUnsubscribedInterface();
}
/**
* 根据参数查询是否已订阅
*
* @param messageType messageType
* @return 是否已订阅
*/
@Override
public boolean isSubscribedInterface(@NonNull MessageType messageType) {
return subscribeInterface != null && subscribeInterface.isSubscribed(messageType);
}
/**
* 根据参数查询是否未订阅
*
* @param messageType messageType
* @return 是否未订阅
*/
@Override
public boolean iUnsubscribedInterface(@NonNull MessageType messageType) {
return subscribeInterface != null && subscribeInterface.isUnsubscribed(messageType);
}
/**
* 注册或取消注册
*
* @param role 角色 详情参见{@link Constants.TERMINAL_ROLE}
* @param type 注册类型 详情参见{@link Constants.SUBSCRIBE_TYPE}
* @param messageTypes 要操作的接口
* @return boolean
*/
@Override
public boolean subscribeInterface(@Define.TerminalRole int role, @Define.SubscribeType int type, @NonNull Set<MessageType> messageTypes) {
return subscribeInterface != null && subscribeInterface.subscribeInterface(role, type, messageTypes);
}
/**
* 注册或取消注册
*
* @param role 角色 详情参见{@link Constants.TERMINAL_ROLE}
* @param type 注册类型 详情参见{@link Constants.SUBSCRIBE_TYPE}
* @param messageType 要操作的接口
* @return boolean
*/
@Override
public boolean subscribeInterface(@Define.TerminalRole int role, @Define.SubscribeType int type, @NonNull MessageType messageType) {
return subscribeInterface != null && subscribeInterface.subscribeInterface(role, type, messageType);
}
}

View File

@@ -7,9 +7,12 @@ import androidx.annotation.NonNull;
import com.zhidao.support.adas.high.bean.VersionCompatibility;
import com.zhidao.support.adas.high.common.AppPreferenceHelper;
import com.zhidao.support.adas.high.common.Constants;
import com.zhidao.support.adas.high.common.Define;
import com.zhidao.support.adas.high.common.MessageType;
import com.zhidao.support.adas.high.common.ReceiveTimeoutManager;
import java.util.HashSet;
import java.util.Set;
import mogo.telematics.pad.MessagePad;
@@ -262,12 +265,13 @@ public class AdasManager implements IAdasNetCommApi {
* 自动驾驶设备基础信息应答
*
* @param sn SN
* @param environment 1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
* @return
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
* @return boolean
*/
@Override
public boolean sendBasicInfoResp(@NonNull String sn, int environment) {
return mChannel != null && mChannel.sendBasicInfoResp(sn, environment);
public boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role) {
return mChannel != null && mChannel.sendBasicInfoResp(sn, environment, role);
}
/**
@@ -478,6 +482,70 @@ public class AdasManager implements IAdasNetCommApi {
return mChannel != null && mChannel.sendRecordDataConfigReq();
}
/**
* 获取已注册接口
*/
@Override
public Set<MessageType> getSubscribedInterface() {
return mChannel == null ? null : mChannel.getSubscribedInterface();
}
/**
* 获取未注册接口
*/
@Override
public Set<MessageType> getUnsubscribedInterface() {
return mChannel == null ? null : mChannel.getUnsubscribedInterface();
}
/**
* 根据参数查询是否已订阅
*
* @param messageType messageType
* @return 是否已订阅
*/
@Override
public boolean isSubscribedInterface(@NonNull MessageType messageType) {
return mChannel != null && mChannel.isSubscribedInterface(messageType);
}
/**
* 根据参数查询是否未订阅
*
* @param messageType messageType
* @return 是否未订阅
*/
@Override
public boolean iUnsubscribedInterface(@NonNull MessageType messageType) {
return mChannel != null && mChannel.iUnsubscribedInterface(messageType);
}
/**
* 注册或取消注册
*
* @param role 角色 详情参见{@link Constants.TERMINAL_ROLE}
* @param type 注册类型 详情参见{@link Constants.SUBSCRIBE_TYPE}
* @param messageTypes 要操作的接口
* @return boolean
*/
@Override
public boolean subscribeInterface(@Define.TerminalRole int role, @Define.SubscribeType int type, @NonNull Set<MessageType> messageTypes) {
return mChannel != null && mChannel.subscribeInterface(role, type, messageTypes);
}
/**
* 注册或取消注册
*
* @param role 角色 详情参见{@link Constants.TERMINAL_ROLE}
* @param type 注册类型 详情参见{@link Constants.SUBSCRIBE_TYPE}
* @param messageType 要操作的接口
* @return boolean
*/
@Override
public boolean subscribeInterface(@Define.TerminalRole int role, @Define.SubscribeType int type, @NonNull MessageType messageType) {
return mChannel != null && mChannel.subscribeInterface(role, type, messageType);
}
/**
* 获取工控机固定IP列表
*

View File

@@ -4,6 +4,10 @@ import androidx.annotation.NonNull;
import com.zhidao.support.adas.high.bean.VersionCompatibility;
import com.zhidao.support.adas.high.common.Constants;
import com.zhidao.support.adas.high.common.Define;
import com.zhidao.support.adas.high.common.MessageType;
import java.util.Set;
import mogo.telematics.pad.MessagePad;
@@ -57,10 +61,11 @@ public interface IAdasNetCommApi {
* 自动驾驶设备基础信息应答
*
* @param sn SN
* @param environment 1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
* @return boolean
* @param environment 环境 详情参见{@link Constants.ENVIRONMENT}1: 研发环境, 2:测试环境, 3:生产环境 4:演示环境
* @param role 终端角色 详情参见{@link Constants.TERMINAL_ROLE}
* @return 加入WS发送消息队列是否成功
*/
boolean sendBasicInfoResp(@NonNull String sn, int environment);
boolean sendBasicInfoResp(@NonNull String sn, @Define.Environment int environment, @Define.TerminalRole int role);
/**
* 设置自动驾驶模式 启动自动驾驶
@@ -68,7 +73,7 @@ public interface IAdasNetCommApi {
* @param mode 1: enter autopilot mode, 0: quit autopilot mode
* @param source 命令来源: 0: pad模拟(模拟时routeInfo传null), 1: AICloud业务
* @param routeInfo 自动驾驶路径信息
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendAutoPilotModeReq(int mode, int source, MessagePad.RouteInfo routeInfo);
@@ -76,14 +81,14 @@ public interface IAdasNetCommApi {
* 设置演示模式
*
* @param enable 1: enable, 0: disable
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendDemoModeReq(int enable);
/**
* 车机基础信息请求
*
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendCarConfigReq();
@@ -94,7 +99,7 @@ public interface IAdasNetCommApi {
* @param filename 文件路径
* @param reasonID 接管原因id
* @param reason 接管原因
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendRecordCause(long key, @NonNull String filename, @NonNull String reasonID, @NonNull String reason);
@@ -103,7 +108,7 @@ public interface IAdasNetCommApi {
*
* @param id
* @param type
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean startRecordPackage(int id, int type);
@@ -112,7 +117,7 @@ public interface IAdasNetCommApi {
*
* @param id
* @param type
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean startRecordPackage(int id, int duration, int type);
@@ -123,7 +128,7 @@ public interface IAdasNetCommApi {
* @param duration
* @param type
* @param bduration
* @return
* @return 加入WS发送消息队列是否成功
*/
boolean startRecordPackage(int id, int duration, int type, int bduration);
@@ -132,7 +137,7 @@ public interface IAdasNetCommApi {
*
* @param id
* @param type
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean stopRecordPackage(int id, int type);
@@ -144,7 +149,7 @@ public interface IAdasNetCommApi {
* @param type 采集类型, 1:badcase, 2: map; 3: rests
* @param isRecord 采集指令, true: 采集, false: 停止采集
* @param bduration 前溯时长
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendRecordData(int id, int duration, int type, boolean isRecord, int bduration);
@@ -152,7 +157,7 @@ public interface IAdasNetCommApi {
* 设置自动驾驶最大速度
*
* @param speedLimit 最大车辆速度 m/s
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendAutopilotSpeedReq(double speedLimit);
@@ -170,7 +175,7 @@ public interface IAdasNetCommApi {
* @param flashYellow 黄灯总时间
* @param laneDetail 灯态具体信息
* @param timestamp 当前卫星时间, 单位: ms
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendTrafficLightData(@NonNull String crossID, double latitude, double longitude,
@NonNull String heading, @NonNull String direction, int lightId, int laneNo,
@@ -179,7 +184,7 @@ public interface IAdasNetCommApi {
/**
* 自动驾驶路径请求
*
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendGlobalPathReq();
@@ -189,7 +194,7 @@ public interface IAdasNetCommApi {
* @param type SystemCmdType。SYSTEMCMD_REBOOT 重启所有节点
* SystemCmdType。SYSTEMCMD_EMPLOY_NEW_IMAGE 使用新镜像(推镜像)
* SystemCmdType。SYSTEMCMD_SHUT_DOWN 关机
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendSystemCmdReq(@NonNull MessagePad.SystemCmdType type);
@@ -197,14 +202,14 @@ public interface IAdasNetCommApi {
* 发送 轨迹下载请求
*
* @param line 线路相关参数详情见PB message_pad.proto -> Line
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendTrajectoryDownloadReq(MessagePad.Line line);
/**
* 发送 状态查询请求
*
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendStatusQueryReq();
@@ -212,7 +217,7 @@ public interface IAdasNetCommApi {
* 设置雨天模式
*
* @param enable 1: enable, 0: disable
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendRainModeReq(int enable);
@@ -220,10 +225,56 @@ public interface IAdasNetCommApi {
* 数据采集配置查询
* 0: all, 其他保留
*
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendRecordDataConfigReq();
/**
* 获取已注册接口
*/
Set<MessageType> getSubscribedInterface();
/**
* 获取未注册接口
*/
Set<MessageType> getUnsubscribedInterface();
/**
* 根据参数查询是否已订阅
*
* @param messageType messageType
* @return 是否已订阅
*/
boolean isSubscribedInterface(@NonNull MessageType messageType);
/**
* 根据参数查询是否未订阅
*
* @param messageType messageType
* @return 是否未订阅
*/
boolean iUnsubscribedInterface(@NonNull MessageType messageType);
/**
* 注册或取消注册
*
* @param role 角色 详情参见{@link Constants.TERMINAL_ROLE}
* @param type 注册类型 详情参见{@link Constants.SUBSCRIBE_TYPE}
* @param messageTypes 要操作的接口
* @return 加入WS发送消息队列是否成功
*/
boolean subscribeInterface(@Define.TerminalRole int role, @Define.SubscribeType int type, @NonNull Set<MessageType> messageTypes);
/**
* 注册或取消注册
*
* @param role 角色 详情参见{@link Constants.TERMINAL_ROLE}
* @param type 注册类型 详情参见{@link Constants.SUBSCRIBE_TYPE}
* @param messageType 要操作的接口
* @return 加入WS发送消息队列是否成功
*/
boolean subscribeInterface(@Define.TerminalRole int role, @Define.SubscribeType int type, @NonNull MessageType messageType);
// TODO 需求暂停 待讨论
// boolean getRoutes();
@@ -231,7 +282,7 @@ public interface IAdasNetCommApi {
* 向工控机发送数据
*
* @param bytes 数据
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendWsMessage(byte[] bytes);

View File

@@ -170,6 +170,14 @@ public interface OnAdasListener {
*/
void onRecordDataConfigResp(MessagePad.Header header, MessagePad.RecordDataConfig config);
/**
* planning决策状态, 透传
*
* @param header 头
* @param planningActionMsg 数据
*/
void onPlanningActionMsg(MessagePad.Header header, MessagePad.PlanningActionMsg planningActionMsg);
/**
* 数据错误
*

View File

@@ -54,4 +54,60 @@ public class Constants {
*/
int NOT_FOUND_ADDRESS = 0x04;
}
/**
* 终端角色类型
*/
public interface TERMINAL_ROLE {
/**
* 司机端
*/
int DRIVER = 0;
/**
* 乘客端
*/
int PASSENGER = 1;
/**
* 调试端
*/
int DEBUG = 2;
}
/**
* 环境
*/
public interface ENVIRONMENT {
/**
* 研发
*/
int DEVELOP = 1;
/**
* 测试
*/
int TEST = 2;
/**
* 生产
*/
int PRODUCTION = 3;
/**
* 演示
*/
int DEMO = 4;
}
/**
* 接口订阅类型
*/
public interface SUBSCRIBE_TYPE {
/**
* 订阅
*/
int SUBSCRIBE = 1;
/**
* 取消订阅
*/
int UNSUBSCRIBE = 2;
}
}

View File

@@ -25,4 +25,25 @@ public final class Define {
@Retention(RetentionPolicy.SOURCE)
public @interface VersionCompatibilityDegree {
}
@IntDef(flag = true, value = {Constants.TERMINAL_ROLE.DRIVER,
Constants.TERMINAL_ROLE.PASSENGER,
Constants.TERMINAL_ROLE.DEBUG})
@Retention(RetentionPolicy.SOURCE)
public @interface TerminalRole {
}
@IntDef(flag = true, value = {Constants.ENVIRONMENT.DEVELOP,
Constants.ENVIRONMENT.TEST,
Constants.ENVIRONMENT.PRODUCTION,
Constants.ENVIRONMENT.DEMO})
@Retention(RetentionPolicy.SOURCE)
public @interface Environment {
}
@IntDef(flag = true, value = {Constants.SUBSCRIBE_TYPE.SUBSCRIBE,
Constants.SUBSCRIBE_TYPE.UNSUBSCRIBE})
@Retention(RetentionPolicy.SOURCE)
public @interface SubscribeType {
}
}

View File

@@ -4,6 +4,7 @@ import mogo.telematics.pad.MessagePad;
/**
* 工控机发送或接收的类型
* 工控机接收接口必须包含TYPE_RECEIVE
*
* @author nie yunlong
* @description 请求值
@@ -45,7 +46,11 @@ public enum MessageType {
TYPE_RECEIVE_STATUS_QUERY_RESP(MessagePad.MessageType.MsgTypeStatusQueryResp, "状态查询应答"),
TYPE_SEND_SET_RAIN_MODE_REQ(MessagePad.MessageType.MsgTypeSetRainModeReq, "设置雨天模式"),
TYPE_SEND_RECORD_DATA_CONFIG_REQ(MessagePad.MessageType.MsgTypeRecordDataConfigReq, "数据采集配置查询"),
TYPE_RECEIVE_RECORD_DATA_CONFIG_RESP(MessagePad.MessageType.MsgTypeRecordDataConfigResp, "数据采集配置");
TYPE_RECEIVE_RECORD_DATA_CONFIG_RESP(MessagePad.MessageType.MsgTypeRecordDataConfigResp, "数据采集配置"),
TYPE_SEND_SUBSCRIBE_DATA_REQ(MessagePad.MessageType.MsgTypeSubscribeDataReq, "数据订阅、取消订阅请求"),
//透传 原始pb文件中不存在以下type。由于Java中无法强转所以在ADAS_DATA message_pad.proto中放开注释
TYPE_RECEIVE_PLANNING_DECISION_STATE(MessagePad.MessageType.MsgTypePlanningDecisionState, "Planning决策状态");
/**
* 消息action code

View File

@@ -29,6 +29,7 @@ public class MyMessageFactory implements IMyMessageFactory {
private IMsg arrivalNotificationMessage;//到站提醒
private IMsg statusQueryRespMessage;//状态查询应答
private IMsg recordDataConfigRespMessage;//数据采集配置应答
private IMsg planningDecisionStateMessage;//planning决策状态
@Override
@@ -135,6 +136,12 @@ public class MyMessageFactory implements IMyMessageFactory {
recordDataConfigRespMessage = new RecordDataConfigRespMessage();
}
return recordDataConfigRespMessage;
} else if (messageType == MessageType.TYPE_RECEIVE_PLANNING_DECISION_STATE.typeCode) {
//planning决策状态
if (planningDecisionStateMessage == null) {
planningDecisionStateMessage = new PlanningDecisionStateMessage();
}
return planningDecisionStateMessage;
} else {
//MessageType.TYPE_DEFAULT.typeCode
return null;

View File

@@ -0,0 +1,23 @@
package com.zhidao.support.adas.high.msg;
import com.google.protobuf.InvalidProtocolBufferException;
import com.zhidao.support.adas.high.AdasManager;
import com.zhidao.support.adas.high.OnAdasListener;
import com.zhidao.support.adas.high.common.CupidLogUtils;
import com.zhidao.support.adas.high.protocol.RawData;
import mogo.telematics.pad.MessagePad;
/**
* planning决策状态, 透传
*/
public class PlanningDecisionStateMessage extends MyAbstractMessageHandler {
@Override
public void handlerMsg(RawData raw, OnAdasListener adasListener) throws InvalidProtocolBufferException {
MessagePad.PlanningActionMsg planningActionMsg = MessagePad.PlanningActionMsg.parser().parseFrom(raw.originalData.toByteArray(), raw.getOffsetValue(), raw.getPackageLengthValue() - raw.getOffsetValue());
if (adasListener != null) {
adasListener.onPlanningActionMsg(raw.getHeader(), planningActionMsg);
}
}
}

View File

@@ -0,0 +1,148 @@
package com.zhidao.support.adas.high.subscribe;
import androidx.annotation.NonNull;
import com.zhidao.support.adas.high.common.Constants;
import com.zhidao.support.adas.high.common.Define;
import com.zhidao.support.adas.high.common.MessageType;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import mogo.telematics.pad.MessagePad;
/**
* 工控机注册接口
* Taxi红旗、东风 MAP260上线
* Bus 预计MAP260上线
*/
public class SubscribeInterface {
/**
* 已注册接口
*/
private final Map<MessageType, Integer> subscribedInterface = new HashMap<>();
/**
* 未注册接口
*/
private final Map<MessageType, Integer> unsubscribedInterface = new HashMap<>();
private final OnSubscribeInterfaceListener listener;
public interface OnSubscribeInterfaceListener {
boolean onSendSubscribe(byte[] bytes);
}
public SubscribeInterface(@NonNull OnSubscribeInterfaceListener listener) {
this.listener = listener;
if (listener == null) throw new RuntimeException();
init();
}
/**
* 获取已注册接口
*/
public Set<MessageType> getSubscribedInterface() {
return subscribedInterface.keySet();
}
/**
* 获取未注册接口
*/
public Set<MessageType> getUnsubscribedInterface() {
return unsubscribedInterface.keySet();
}
/**
* 注册或取消注册
*
* @param role 角色 详情参见{@link Constants.TERMINAL_ROLE}
* @param type 注册类型 详情参见{@link Constants.SUBSCRIBE_TYPE}
* @param messageTypes 要操作的接口
* @return
*/
public boolean subscribeInterface(@Define.TerminalRole int role, @Define.SubscribeType int type, @NonNull Set<MessageType> messageTypes) {
if (messageTypes == null) return false;
MessagePad.SubscribeDataReq.Builder builder = MessagePad.SubscribeDataReq.newBuilder();
builder.setRole(role).setReqType(type);
Map<MessageType, Integer> temp = new HashMap<>();
for (MessageType messageType : messageTypes) {
temp.put(messageType, messageType.typeCode.getNumber());
}
builder.addAllDataTypes(temp.values());
boolean isSendSucceed = listener.onSendSubscribe(builder.build().toByteArray());
if (isSendSucceed) {
for (MessageType messageType : messageTypes) {
if (type == Constants.SUBSCRIBE_TYPE.SUBSCRIBE) {
if (!subscribedInterface.containsKey(messageType)) {
subscribedInterface.put(messageType, messageType.typeCode.getNumber());
}
unsubscribedInterface.remove(messageType);
} else if (type == Constants.SUBSCRIBE_TYPE.UNSUBSCRIBE) {
if (!unsubscribedInterface.containsKey(messageType)) {
unsubscribedInterface.put(messageType, messageType.typeCode.getNumber());
}
subscribedInterface.remove(messageType);
}
}
}
return false;
}
/**
* 注册或取消注册
*
* @param role 角色 详情参见{@link Constants.TERMINAL_ROLE}
* @param type 注册类型 详情参见{@link Constants.SUBSCRIBE_TYPE}
* @param messageType 要操作的接口
* @return 是否加入ws发送队列
*/
public boolean subscribeInterface(@Define.TerminalRole int role, @Define.SubscribeType int type, @NonNull MessageType messageType) {
if (messageType == null) return false;
MessagePad.SubscribeDataReq.Builder builder = MessagePad.SubscribeDataReq.newBuilder();
builder.setRole(role).setReqType(type).addDataTypes(messageType.typeCode.getNumber());
boolean isSendSucceed = listener.onSendSubscribe(builder.build().toByteArray());
if (isSendSucceed) {
if (type == Constants.SUBSCRIBE_TYPE.SUBSCRIBE) {
if (!subscribedInterface.containsKey(messageType)) {
subscribedInterface.put(messageType, messageType.typeCode.getNumber());
}
unsubscribedInterface.remove(messageType);
} else if (type == Constants.SUBSCRIBE_TYPE.UNSUBSCRIBE) {
if (!unsubscribedInterface.containsKey(messageType)) {
unsubscribedInterface.put(messageType, messageType.typeCode.getNumber());
}
subscribedInterface.remove(messageType);
}
}
return false;
}
//根据参数查询是否已订阅
public boolean isSubscribed(@NonNull MessageType messageType) {
return subscribedInterface.containsKey(messageType);
}
//根据参数查询是否未订阅
public boolean isUnsubscribed(@NonNull MessageType messageType) {
return unsubscribedInterface.containsKey(messageType);
}
private void init() {
//默认RECEIVE的全部注册
MessageType[] types = MessageType.values();
if (types.length > 0) {
for (MessageType messageType : types) {
if (messageType.name().toLowerCase().contains("type_receive")) {
subscribedInterface.put(messageType, messageType.typeCode.getNumber());
}
}
}
}
}