Apollo  6.0
Open source self driving car software
socket_can_client_raw.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 
22 #pragma once
23 
24 #include <unistd.h>
25 
26 #include <net/if.h>
27 #include <sys/ioctl.h>
28 #include <sys/socket.h>
29 #include <sys/types.h>
30 
31 #include <linux/can.h>
32 #include <linux/can/raw.h>
33 
34 #include <cstdio>
35 #include <cstdlib>
36 #include <cstring>
37 #include <string>
38 #include <vector>
39 
40 #include "modules/common/proto/error_code.pb.h"
41 #include "modules/drivers/canbus/proto/can_card_parameter.pb.h"
42 
43 #include "gflags/gflags.h"
46 
51 namespace apollo {
52 namespace drivers {
53 namespace canbus {
54 namespace can {
55 
60 class SocketCanClientRaw : public CanClient {
61  public:
67  bool Init(const CANCardParameter &parameter) override;
68 
72  virtual ~SocketCanClientRaw();
73 
79  apollo::common::ErrorCode Start() override;
80 
84  void Stop() override;
85 
93  apollo::common::ErrorCode Send(const std::vector<CanFrame> &frames,
94  int32_t *const frame_num) override;
95 
103  apollo::common::ErrorCode Receive(std::vector<CanFrame> *const frames,
104  int32_t *const frame_num) override;
105 
110  std::string GetErrorString(const int32_t status) override;
111 
112  private:
113  int dev_handler_ = 0;
114  CANCardParameter::CANChannelId port_;
115  CANCardParameter::CANInterface interface_;
116  can_frame send_frames_[MAX_CAN_SEND_FRAME_LEN];
117  can_frame recv_frames_[MAX_CAN_RECV_FRAME_LEN];
118 };
119 
120 } // namespace can
121 } // namespace canbus
122 } // namespace drivers
123 } // namespace apollo
const int32_t MAX_CAN_RECV_FRAME_LEN
Definition: canbus_consts.h:35
std::string GetErrorString(const int32_t status) override
Get the error string.
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 Stop() override
Stop the ESD CAN client.
const int32_t MAX_CAN_SEND_FRAME_LEN
Definition: canbus_consts.h:34
bool Init(const CANCardParameter &parameter) override
Initialize the ESD CAN client by specified CAN card parameters.
apollo::common::ErrorCode Start() override
Start the ESD CAN client.
apollo::common::ErrorCode Receive(std::vector< CanFrame > *const frames, int32_t *const frame_num) override
Receive messages.
apollo::common::ErrorCode Send(const std::vector< CanFrame > &frames, int32_t *const frame_num) override
Send messages.
The class which defines an ESD CAN client which inherites CanClient.
Definition: socket_can_client_raw.h:60