Apollo  6.0
Open source self driving car software
hermes_can_client.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #pragma once
18 
19 #include <string>
20 #include <vector>
21 
22 #include "gflags/gflags.h"
23 
24 #include "modules/common/proto/error_code.pb.h"
25 #include "modules/drivers/canbus/proto/can_card_parameter.pb.h"
26 
30 
36 namespace apollo {
37 namespace drivers {
38 namespace canbus {
39 namespace can {
40 
46 class HermesCanClient : public CanClient {
47  public:
52  // explicit HermesCanClient(const CANCardParameter &parameter);
53 
57  virtual ~HermesCanClient();
58 
64  bool Init(const CANCardParameter &parameter) override;
65 
71  apollo::common::ErrorCode Start() override;
72 
77  virtual void Stop();
78 
86  virtual apollo::common::ErrorCode Send(const std::vector<CanFrame> &frames,
87  int32_t *const frame_num);
88 
96  virtual apollo::common::ErrorCode Receive(std::vector<CanFrame> *const frames,
97  int32_t *const frame_num);
102  virtual std::string GetErrorString(const int32_t status);
107  void SetInited(bool init);
108 
109  private:
110  bool is_init_ = false;
111  bcan_hdl_t dev_handler_;
112  CANCardParameter::CANChannelId port_;
113  bcan_msg_t _send_frames[MAX_CAN_SEND_FRAME_LEN];
114  bcan_msg_t _recv_frames[MAX_CAN_RECV_FRAME_LEN];
115 };
116 
117 } // namespace can
118 } // namespace canbus
119 } // namespace drivers
120 } // namespace apollo
121 
122 /* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */
const int32_t MAX_CAN_RECV_FRAME_LEN
Definition: canbus_consts.h:35
bool Init(const CANCardParameter &parameter) override
Start the ESD CAN client.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Defines the CanFrame struct and CanClient interface.
The class which defines the CAN client to send and receive message.
Definition: can_client.h:92
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.
virtual apollo::common::ErrorCode Receive(std::vector< CanFrame > *const frames, int32_t *const frame_num)
Receive messages.
uint64_t bcan_hdl_t
Definition: bcan.h:48
The class which defines a BCAN client which inherits CanClient.
Definition: hermes_can_client.h:46
const int32_t MAX_CAN_SEND_FRAME_LEN
Definition: canbus_consts.h:34
Definition: bcan_defs.h:28
virtual std::string GetErrorString(const int32_t status)
Get the error string.
virtual ~HermesCanClient()
Initialize the BCAN client by specified CAN card parameters.