package com.xiaopeng.automaticPilot.util;
|
|
import cn.hutool.core.lang.Snowflake;
|
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpUtil;
|
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson2.JSON;
|
import com.xiaopeng.api.dto.automaticPilot.MqttPublishDto;
|
import com.xiaopeng.api.feignClient.automaticPilot.XPUClient;
|
import com.xiaopeng.api.vo.automaticPilot.MqttPublishVo;
|
import com.xiaopeng.api.vo.automaticPilot.proto.down.*;
|
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.RTTask;
|
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudOrderOperation.OrderOperation;
|
import com.xiaopeng.common.core.utils.uuid.UUID;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
|
/**
|
* 自动驾驶接口对接文档
|
*/
|
@Slf4j
|
@Component
|
public class XPUUtil {
|
|
@Resource
|
private XPUClient xpuClient;
|
|
|
/**
|
* Robotaxi创建订单推送给XPU
|
*
|
* @param task
|
* @return
|
*/
|
public MqttPublishDto cloudCreateOrder(RTTask task, String vin) {
|
MsgContent msgContent = new MsgContent();
|
// 消息头
|
RtMsgHeader header = new RtMsgHeader();
|
header.setMsg_id(UUID.randomUUID().toString());
|
header.setTimestamp(System.currentTimeMillis());
|
header.setCmd(RTCmdType.CLOUD_CREATE_ORDER);
|
header.setSequence(1L);
|
header.setType(MessageType.MESSAGE_TYPE_RESPONSE);
|
msgContent.setHeader(header);
|
// 消息内容
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("task", task);
|
msgContent.setContent_detail(jsonObject);
|
log.info("云端-->XPU 创建订单:{}", msgContent);
|
|
//组装请求消息体
|
MqttPublishVo vo = new MqttPublishVo();
|
vo.setTopic("topic-prod-xpu-robotaxi-high/" + vin);
|
vo.setPayload(JSON.toJSONString(msgContent));
|
return xpuClient.publish(vo);
|
}
|
|
|
/**
|
* 操作订单
|
* 取消订单/修改途经点、终点/下发导航地址到车端
|
*
|
* @param operation
|
* @return
|
*/
|
public MqttPublishDto cloudOrderOperation(OrderOperation operation, String vin) {
|
MsgContent msgContent = new MsgContent();
|
// 消息头
|
RtMsgHeader header = new RtMsgHeader();
|
header.setMsg_id(UUID.randomUUID().toString());
|
header.setTimestamp(System.currentTimeMillis());
|
header.setCmd(RTCmdType.CLOUD_ORDER_OPERATION);
|
Snowflake snowflake = IdUtil.getSnowflake(0, 0);
|
header.setSequence(snowflake.nextId());
|
header.setType(MessageType.MESSAGE_TYPE_REQUEST);
|
msgContent.setHeader(header);
|
// 消息内容
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("operation", operation);
|
msgContent.setContent_detail(jsonObject);
|
log.info("云端-->XPU 操作订单:{}", msgContent);
|
//组装请求消息体
|
MqttPublishVo vo = new MqttPublishVo();
|
vo.setTopic("topic-prod-xpu-robotaxi-high/" + vin);
|
vo.setPayload(JSON.toJSONString(msgContent));
|
return xpuClient.publish(vo);
|
}
|
|
|
|
|
/**
|
* 响应消息
|
*
|
* @param responseMessage
|
* @return
|
*/
|
public MqttPublishDto responseMessage(ResponseMessage responseMessage, String vin) {
|
MsgContent msgContent = new MsgContent();
|
// 消息头
|
RtMsgHeader header = new RtMsgHeader();
|
header.setMsg_id(UUID.randomUUID().toString());
|
header.setTimestamp(System.currentTimeMillis());
|
header.setCmd(RTCmdType.CLOUD_TASK_CONTROL);
|
Snowflake snowflake = IdUtil.getSnowflake(0, 0);
|
header.setSequence(snowflake.nextId());
|
header.setType(MessageType.MESSAGE_TYPE_RESPONSE);
|
msgContent.setHeader(header);
|
// 消息内容
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("resposne", responseMessage);
|
msgContent.setContent_detail(jsonObject);
|
log.info("云端-->XPU 响应消息:{}", msgContent);
|
//组装请求消息体
|
MqttPublishVo vo = new MqttPublishVo();
|
vo.setTopic("topic-prod-xpu-robotaxi-high/" + vin);
|
vo.setPayload(JSON.toJSONString(msgContent));
|
return xpuClient.publish(vo);
|
}
|
|
}
|