[change] 添加数据订阅、取消订阅请求

This commit is contained in:
xinfengkun
2022-08-02 18:51:14 +08:00
parent 6973324a1f
commit dbd56a89a8
24 changed files with 1325 additions and 74 deletions

View File

@@ -114,7 +114,6 @@ 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<>();
@@ -144,14 +143,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) {

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

@@ -129,8 +129,6 @@ 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)) {

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;
@@ -148,7 +148,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,7 +613,6 @@ 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_CAR_CONFIG_RESP);
@@ -882,7 +881,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());
}
@@ -1024,6 +1023,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 +1091,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);
@@ -1227,30 +1229,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,11 @@ 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_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

@@ -3,7 +3,7 @@ package mogo.telematics.pad;
enum ProtocolVersion{
Defaultver = 0;
CurrentVersion = 4; //每次修改proto文件增加1
CurrentVersion = 6; //每次修改proto文件增加1
}
enum MessageType
@@ -44,6 +44,8 @@ enum MessageType
MsgTypeSetRainModeReq = 0x10113; //设置雨天模式
MsgTypeRecordDataConfigReq = 0x10114; //数据采集配置查询请求
MsgTypeRecordDataConfigResp = 0x10115; //数据采集配置查询应答
MsgTypeOperatorCmdReq = 0x10116; //操控指令
MsgTypeSubscribeDataReq = 0x10117; //数据订阅、取消订阅请求
}
message Header
@@ -156,6 +158,7 @@ message PlanningObjects
// message definition for MessageType: MsgTypeOBU
// refer to obu.proto
// message definition for MsgTypeTrajectoryDownloadReq
message Line
{
@@ -376,3 +379,29 @@ 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
}

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;
@@ -393,6 +400,7 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
sendCarConfigReq();
ipcConnectedIp = ipAddress;
ipcConnectedPort = port;
subscribeInterface = new SubscribeInterface(this);
updateConnectStatus(Constants.IPC_CONNECTION_STATUS.CONNECTED, "已连接");
}
@@ -400,6 +408,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);
}
@@ -483,9 +492,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();
@@ -496,6 +502,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);
}
@@ -945,5 +954,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;
@@ -479,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;
@@ -69,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);
@@ -77,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();
@@ -95,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);
@@ -104,7 +108,7 @@ public interface IAdasNetCommApi {
*
* @param id
* @param type
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean startRecordPackage(int id, int type);
@@ -113,7 +117,7 @@ public interface IAdasNetCommApi {
*
* @param id
* @param type
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean startRecordPackage(int id, int duration, int type);
@@ -124,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);
@@ -133,7 +137,7 @@ public interface IAdasNetCommApi {
*
* @param id
* @param type
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean stopRecordPackage(int id, int type);
@@ -145,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);
@@ -153,7 +157,7 @@ public interface IAdasNetCommApi {
* 设置自动驾驶最大速度
*
* @param speedLimit 最大车辆速度 m/s
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendAutopilotSpeedReq(double speedLimit);
@@ -171,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,
@@ -180,7 +184,7 @@ public interface IAdasNetCommApi {
/**
* 自动驾驶路径请求
*
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendGlobalPathReq();
@@ -190,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);
@@ -198,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();
@@ -213,7 +217,7 @@ public interface IAdasNetCommApi {
* 设置雨天模式
*
* @param enable 1: enable, 0: disable
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendRainModeReq(int enable);
@@ -221,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();
@@ -232,7 +282,7 @@ public interface IAdasNetCommApi {
* 向工控机发送数据
*
* @param bytes 数据
* @return boolean
* @return 加入WS发送消息队列是否成功
*/
boolean sendWsMessage(byte[] bytes);

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,8 @@ 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, "数据订阅、取消订阅请求");
/**
* 消息action code

View File

@@ -0,0 +1,166 @@
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());
}
}
}
// subscribedInterface.put(MessageType.TYPE_RECEIVE_TRAJECTORY, MessageType.TYPE_RECEIVE_TRAJECTORY.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_TRACKED_OBJECTS, MessageType.TYPE_RECEIVE_TRACKED_OBJECTS.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_GNSS_INFO, MessageType.TYPE_RECEIVE_GNSS_INFO.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_VEHICLE_STATE, MessageType.TYPE_RECEIVE_VEHICLE_STATE.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_AUTOPILOT_STATE, MessageType.TYPE_RECEIVE_AUTOPILOT_STATE.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_REPORT_MESSAGE, MessageType.TYPE_RECEIVE_REPORT_MESSAGE.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_PERCEPTION_TRAFFIC_LIGHT, MessageType.TYPE_RECEIVE_PERCEPTION_TRAFFIC_LIGHT.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY, MessageType.TYPE_RECEIVE_PREDICTION_OBSTACLE_TRAJECTORY.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_POINT_CLOUD, MessageType.TYPE_RECEIVE_POINT_CLOUD.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_PLANNING_OBJECTS, MessageType.TYPE_RECEIVE_PLANNING_OBJECTS.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_BASIC_INFO_REQ, MessageType.TYPE_RECEIVE_BASIC_INFO_REQ.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_CAR_CONFIG_RESP, MessageType.TYPE_RECEIVE_CAR_CONFIG_RESP.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_RECORD_RESULT, MessageType.TYPE_RECEIVE_RECORD_RESULT.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_GLOBAL_PATH_RESP, MessageType.TYPE_RECEIVE_GLOBAL_PATH_RESP.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_WARN, MessageType.TYPE_RECEIVE_WARN.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_ARRIVAL_NOTIFICATION, MessageType.TYPE_RECEIVE_ARRIVAL_NOTIFICATION.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_STATUS_QUERY_RESP, MessageType.TYPE_RECEIVE_STATUS_QUERY_RESP.typeCode.getNumber());
// subscribedInterface.put(MessageType.TYPE_RECEIVE_RECORD_DATA_CONFIG_RESP, MessageType.TYPE_RECEIVE_RECORD_DATA_CONFIG_RESP.typeCode.getNumber());
}
}