Apollo 11.0
自动驾驶开放平台
apollo::drivers::canbus::can::FakeCanClient类 参考

The class which defines a fake CAN client which inherits CanClient. 更多...

#include <fake_can_client.h>

类 apollo::drivers::canbus::can::FakeCanClient 继承关系图:
apollo::drivers::canbus::can::FakeCanClient 的协作图:

Public 成员函数

bool Init (const CANCardParameter &param) override
 Initialize the fake CAN client by specified CAN card parameters.
 
virtual ~FakeCanClient ()=default
 Destructor
 
apollo::common::ErrorCode Start () override
 Start the fake CAN client.
 
void Stop () override
 Stop the fake CAN client.
 
apollo::common::ErrorCode Send (const std::vector< CanFrame > &frames, int32_t *const frame_num) override
 Send messages
 
apollo::common::ErrorCode Receive (std::vector< CanFrame > *frames, int32_t *const frame_num) override
 Receive messages
 
std::string GetErrorString (const int32_t status) override
 Get the error string.
 
- Public 成员函数 继承自 apollo::drivers::canbus::CanClient
 CanClient ()=default
 Constructor
 
virtual ~CanClient ()=default
 Destructor
 
virtual apollo::common::ErrorCode SendSingleFrame (const std::vector< CanFrame > &frames)
 Send a single message.
 

额外继承的成员函数

- Protected 属性 继承自 apollo::drivers::canbus::CanClient
bool is_started_ = false
 The CAN client is started.
 

详细描述

The class which defines a fake CAN client which inherits CanClient.

This fake CAN client is used for testing.

在文件 fake_can_client.h 第 45 行定义.

构造及析构函数说明

◆ ~FakeCanClient()

virtual apollo::drivers::canbus::can::FakeCanClient::~FakeCanClient ( )
virtualdefault

Destructor

成员函数说明

◆ GetErrorString()

std::string apollo::drivers::canbus::can::FakeCanClient::GetErrorString ( const int32_t  status)
overridevirtual

Get the error string.

参数
statusThe status to get the error string.

实现了 apollo::drivers::canbus::CanClient.

在文件 fake_can_client.cc 第 76 行定义.

76 {
77 return "";
78}

◆ Init()

bool apollo::drivers::canbus::can::FakeCanClient::Init ( const CANCardParameter &  param)
overridevirtual

Initialize the fake CAN client by specified CAN card parameters.

参数
parameterCAN card parameters to initialize the CAN client.
返回
If the initialization is successful.

实现了 apollo::drivers::canbus::CanClient.

在文件 fake_can_client.cc 第 29 行定义.

29{ return true; }

◆ Receive()

ErrorCode apollo::drivers::canbus::can::FakeCanClient::Receive ( std::vector< CanFrame > *  frames,
int32_t *const  frame_num 
)
overridevirtual

Receive messages

参数
framesThe messages to receive.
frame_numThe amount of messages to receive.
返回
The status of the receiving action which is defined by apollo::common::ErrorCode.

实现了 apollo::drivers::canbus::CanClient.

在文件 fake_can_client.cc 第 55 行定义.

56 {
57 if (frame_num == nullptr || frames == nullptr) {
58 AERROR << "frames or frame_num pointer is null";
59 return ErrorCode::CAN_CLIENT_ERROR_BASE;
60 }
61 frames->resize(*frame_num);
62 const int MOCK_LEN = 8;
63 for (size_t i = 0; i < frames->size(); ++i) {
64 for (int j = 0; j < MOCK_LEN; ++j) {
65 (*frames)[i].data[j] = static_cast<uint8_t>(j);
66 }
67 (*frames)[i].id = static_cast<uint32_t>(i);
68 (*frames)[i].len = MOCK_LEN;
69 ADEBUG << (*frames)[i].CanFrameString() << "frame_num[" << i << "]";
70 }
71 std::this_thread::sleep_for(std::chrono::milliseconds(10));
72 ++recv_counter_;
73 return ErrorCode::OK;
74}
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44

◆ Send()

ErrorCode apollo::drivers::canbus::can::FakeCanClient::Send ( const std::vector< CanFrame > &  frames,
int32_t *const  frame_num 
)
overridevirtual

Send messages

参数
framesThe messages to send.
frame_numThe amount of messages to send.
返回
The status of the sending action which is defined by apollo::common::ErrorCode.

实现了 apollo::drivers::canbus::CanClient.

在文件 fake_can_client.cc 第 35 行定义.

36 {
37 if (frame_num == nullptr) {
38 AERROR << "frame_num pointer is null";
39 return ErrorCode::CAN_CLIENT_ERROR_BASE;
40 }
41
42 if (static_cast<size_t>(*frame_num) != frames.size()) {
43 AERROR << "frame num is incorrect.";
44 return ErrorCode::CAN_CLIENT_ERROR_FRAME_NUM;
45 }
46 for (size_t i = 0; i < frames.size(); ++i) {
47 ADEBUG << "send frame i:" << i;
48 ADEBUG << frames[i].CanFrameString();
49 frame_info_ << frames[i].CanFrameString();
50 }
51 ++send_counter_;
52 return ErrorCode::OK;
53}

◆ Start()

ErrorCode apollo::drivers::canbus::can::FakeCanClient::Start ( )
overridevirtual

Start the fake CAN client.

返回
The status of the start action which is defined by apollo::common::ErrorCode.

实现了 apollo::drivers::canbus::CanClient.

在文件 fake_can_client.cc 第 31 行定义.

31{ return ErrorCode::OK; }

◆ Stop()

void apollo::drivers::canbus::can::FakeCanClient::Stop ( )
overridevirtual

Stop the fake CAN client.

实现了 apollo::drivers::canbus::CanClient.

在文件 fake_can_client.cc 第 33 行定义.

33{}

该类的文档由以下文件生成: