38 if (!parameter.has_channel_id()) {
39 AERROR <<
"Init CAN failed: parameter does not have channel id. The "
41 << parameter.DebugString();
46 if (port_ >
static_cast<int32_t
>(num_ports) || port_ < 0) {
47 AERROR <<
"Can port number [" << port_ <<
"] is out of bound [0,"
66 if (ret != ErrorCode::OK) {
67 AERROR <<
"Open device error code: " << ret <<
", channel id: " << port_;
68 return ErrorCode::CAN_CLIENT_ERROR_BASE;
70 AINFO <<
"Open device success, channel id: " << port_;
74 if (ret != ErrorCode::OK) {
75 AERROR <<
"Set baudrate error Code: " << ret;
76 return ErrorCode::CAN_CLIENT_ERROR_BASE;
81 if (ret != ErrorCode::OK) {
82 AERROR <<
"Start hermes can card failed: " << ret;
83 return ErrorCode::CAN_CLIENT_ERROR_BASE;
94 if (ret != ErrorCode::OK) {
95 AERROR <<
"close error code: " << ret;
102 const std::vector<CanFrame> &frames, int32_t *
const frame_num) {
112 CHECK_NOTNULL(frame_num);
113 CHECK_EQ(frames.size(),
static_cast<size_t>(*frame_num));
116 AERROR <<
"Hermes can client is not init! Please init first!";
117 return ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED;
124 for (
int i = 0; i < *frame_num; ++i) {
127 memcpy(_send_frames[i].bcan_msg_data, frames[i].data, frames[i].len);
131 int32_t send_num = *frame_num;
132 int32_t ret =
bcan_send(dev_handler_, _send_frames, send_num);
135 AERROR <<
"send message failed, error code: " << ret
136 <<
", send error: " << ret_send_error;
137 return ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED;
140 return ErrorCode::OK;
147 std::vector<CanFrame> *
const frames, int32_t *
const frame_num) {
149 AERROR <<
"Hermes can client is not init! Please init first!";
150 return ErrorCode::CAN_CLIENT_ERROR_RECV_FAILED;
154 <<
"], frame_num:" << *frame_num;
155 return ErrorCode::CAN_CLIENT_ERROR_FRAME_NUM;
158 int32_t ret =
bcan_recv(dev_handler_, _recv_frames, *frame_num);
162 return ErrorCode::OK;
166 AERROR <<
"receive message failed, error code:" << ret
167 <<
"receive error:" << ret_rece_error;
168 return ErrorCode::CAN_CLIENT_ERROR_RECV_FAILED;
173 for (
int i = 0; i < *frame_num; ++i) {
180 frames->push_back(cf);
183 return ErrorCode::OK;
int bcan_recv(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg)
int bcan_set_baudrate(bcan_hdl_t hdl, uint32_t rate)
int bcan_get_status(bcan_hdl_t hdl)
int bcan_open(uint32_t dev_index, uint32_t flags, uint64_t tx_to, uint64_t rx_to, bcan_hdl_t *hdl)
int bcan_start(bcan_hdl_t hdl)
int bcan_close(bcan_hdl_t hdl)
int bcan_send(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg)
virtual ~HermesCanClient()
Initialize the BCAN client by specified CAN card parameters.
bool Init(const CANCardParameter ¶meter) override
Start the ESD CAN client.
virtual std::string GetErrorString(const int32_t status)
Get the error string.
virtual apollo::common::ErrorCode Receive(std::vector< CanFrame > *const frames, int32_t *const frame_num)
Receive messages
void SetInited(bool init)
Set inited status.
virtual void Stop()
Stop the ESD CAN client.
apollo::common::ErrorCode Start() override
Start the ESD CAN client.
virtual apollo::common::ErrorCode Send(const std::vector< CanFrame > &frames, int32_t *const frame_num)
Send messages
const int32_t MAX_CAN_RECV_FRAME_LEN
optional CANChannelId channel_id
optional uint32 num_ports
The class which defines the information to send and receive.
uint8_t len
Message length
struct timeval timestamp
Time stamp
uint8_t data[8]
Message content
struct timeval bcan_msg_timestamp
unsigned char bcan_msg_data[8]
unsigned char bcan_msg_datalen