Apollo 10.0
自动驾驶开放平台
apollo::drivers::canbus::CanSender< SensorType > 模板类 参考

CAN sender. 更多...

#include <can_sender.h>

apollo::drivers::canbus::CanSender< SensorType > 的协作图:

Public 成员函数

 CanSender ()=default
 Constructor.
 
virtual ~CanSender ()=default
 Destructor.
 
common::ErrorCode Init (CanClient *can_client, MessageManager< SensorType > *pt_manager, bool enable_log)
 Initialize by a CAN client based on its brand.
 
void AddMessage (uint32_t message_id, ProtocolData< SensorType > *protocol_data, bool init_with_one=false)
 Add a message with its ID, protocol data.
 
void ClearMessage ()
 
bool IsMessageClear ()
 
apollo::common::ErrorCode Start ()
 Start the CAN sender.
 
void Update ()
 
void Update_Heartbeat ()
 
void Stop ()
 Stop the CAN sender.
 
bool IsRunning () const
 Get the working status of this CAN sender.
 
bool enable_log () const
 
 FRIEND_TEST (CanSenderTest, OneRunCase)
 

详细描述

template<typename SensorType>
class apollo::drivers::canbus::CanSender< SensorType >

CAN sender.

在文件 can_sender.h139 行定义.

构造及析构函数说明

◆ CanSender()

template<typename SensorType >
apollo::drivers::canbus::CanSender< SensorType >::CanSender ( )
default

Constructor.

◆ ~CanSender()

template<typename SensorType >
virtual apollo::drivers::canbus::CanSender< SensorType >::~CanSender ( )
virtualdefault

Destructor.

成员函数说明

◆ AddMessage()

template<typename SensorType >
void apollo::drivers::canbus::CanSender< SensorType >::AddMessage ( uint32_t  message_id,
ProtocolData< SensorType > *  protocol_data,
bool  init_with_one = false 
)

Add a message with its ID, protocol data.

参数
message_idThe message ID.
protocol_dataA pointer of ProtocolData which contains the content to send.
init_with_oneIf it is true, then initialize all bits in the protocol data as one. By default, it is false.

在文件 can_sender.h388 行定义.

390 {
391 if (protocol_data == nullptr) {
392 AERROR << "invalid protocol data.";
393 return;
394 }
395 send_messages_.emplace_back(
396 SenderMessage<SensorType>(message_id, protocol_data, init_with_one));
397 AINFO << "Add send message:" << std::hex << message_id;
398}
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42

◆ ClearMessage()

template<typename SensorType >
void apollo::drivers::canbus::CanSender< SensorType >::ClearMessage ( )

在文件 can_sender.h428 行定义.

428 {
429 send_messages_.clear();
430}

◆ enable_log()

template<typename SensorType >
bool apollo::drivers::canbus::CanSender< SensorType >::enable_log ( ) const

在文件 can_sender.h462 行定义.

462 {
463 return enable_log_;
464}

◆ FRIEND_TEST()

template<typename SensorType >
apollo::drivers::canbus::CanSender< SensorType >::FRIEND_TEST ( CanSenderTest  ,
OneRunCase   
)

◆ Init()

template<typename SensorType >
common::ErrorCode apollo::drivers::canbus::CanSender< SensorType >::Init ( CanClient can_client,
MessageManager< SensorType > *  pt_manager,
bool  enable_log 
)

Initialize by a CAN client based on its brand.

参数
can_clientThe CAN client to use for sending messages.
enable_logwhether enable record the send can frame log
返回
An error code indicating the status of this initialization.

在文件 can_sender.h365 行定义.

367 {
368 if (is_init_) {
369 AERROR << "Duplicated Init request.";
371 }
372 if (can_client == nullptr) {
373 AERROR << "Invalid can client.";
375 }
376 is_init_ = true;
377 can_client_ = can_client;
378 pt_manager_ = pt_manager;
379 enable_log_ = enable_log;
380 if (pt_manager_ == nullptr) {
381 AERROR << "Invalid protocol manager.";
382 return ::apollo::common::ErrorCode::CANBUS_ERROR;
383 }
385}

◆ IsMessageClear()

template<typename SensorType >
bool apollo::drivers::canbus::CanSender< SensorType >::IsMessageClear ( )

在文件 can_sender.h433 行定义.

433 {
434 if (send_messages_.empty()) {
435 return true;
436 }
437 return false;
438}

◆ IsRunning()

template<typename SensorType >
bool apollo::drivers::canbus::CanSender< SensorType >::IsRunning ( ) const

Get the working status of this CAN sender.

To check if it is running.

返回
If this CAN sender is running.

在文件 can_sender.h457 行定义.

457 {
458 return is_running_;
459}

◆ Start()

template<typename SensorType >
common::ErrorCode apollo::drivers::canbus::CanSender< SensorType >::Start ( )

Start the CAN sender.

返回
The error code indicating the status of this action.

在文件 can_sender.h401 行定义.

401 {
402 if (is_running_) {
403 AERROR << "Cansender has already started.";
405 }
406 is_running_ = true;
407 thread_.reset(new std::thread([this] { PowerSendThreadFunc(); }));
408
410}

◆ Stop()

template<typename SensorType >
void apollo::drivers::canbus::CanSender< SensorType >::Stop ( )

Stop the CAN sender.

在文件 can_sender.h441 行定义.

441 {
442 if (is_running_) {
443 AINFO << "Stopping can sender ...";
444 is_running_ = false;
445 if (thread_ != nullptr && thread_->joinable()) {
446 thread_->join();
447 }
448 thread_.reset();
449 } else {
450 AERROR << "CanSender is not running.";
451 }
452
453 AINFO << "Can client sender stopped [ok].";
454}

◆ Update()

template<typename SensorType >
void apollo::drivers::canbus::CanSender< SensorType >::Update ( )

在文件 can_sender.h421 行定义.

421 {
422 for (auto &message : send_messages_) {
423 message.Update();
424 }
425}

◆ Update_Heartbeat()

template<typename SensorType >
void apollo::drivers::canbus::CanSender< SensorType >::Update_Heartbeat ( )

在文件 can_sender.h414 行定义.

414 {
415 for (auto &message : send_messages_) {
416 message.Update_Heartbeat();
417 }
418}

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