這篇文章主要介紹怎么添加新的CAN卡,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到武侯網(wǎng)站設(shè)計(jì)與武侯網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、國(guó)際域名空間、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋武侯地區(qū)。
簡(jiǎn)介
控制器區(qū)域網(wǎng)絡(luò)(CAN)是在許多微控制器和設(shè)備中密集使用的網(wǎng)絡(luò),用于在沒(méi)有主計(jì)算機(jī)幫助的情況下在設(shè)備之間傳輸數(shù)據(jù)。
Apollo中使用的默認(rèn)CAN卡是 ESD CAN-PCIe卡。您可以使用以下步驟添加新的CAN卡:
添加新的CAN卡
添加新的CAN卡需要完成以下幾個(gè)步驟:
實(shí)現(xiàn)新CAN卡的
CanClient
類。在
CanClientFactory
中注冊(cè)新的CAN卡。更新配置文件。
以下步驟展示了如何添加新的CAN卡 - 示例添加CAN卡到您的工程。
步驟1
實(shí)現(xiàn)新CAN卡的CanClient類,下面的代碼展示了如何實(shí)現(xiàn) CANClient
類:
#include <string> #include <vector> #include "hermes_can/include/bcan.h" #include "modules/canbus/can_client/can_client.h" #include "modules/canbus/common/canbus_consts.h" #include "modules/common/proto/error_code.pb.h" /** * @namespace apollo::canbus::can * @brief apollo::canbus::can */ namespace apollo { namespace canbus { namespace can { /** * @class ExampleCanClient * @brief The class which defines a Example CAN client which inherits CanClient. */ class ExampleCanClient : public CanClient { public: /** * @brief Initialize the Example CAN client by specified CAN card parameters. * @param parameter CAN card parameters to initialize the CAN client. * @return If the initialization is successful. */ bool Init(const CANCardParameter& parameter) override; /** * @brief Destructor */ virtual ~ExampleCanClient() = default; /** * @brief Start the Example CAN client. * @return The status of the start action which is defined by * apollo::common::ErrorCode. */ apollo::common::ErrorCode Start() override; /** * @brief Stop the Example CAN client. */ void Stop() override; /** * @brief Send messages * @param frames The messages to send. * @param frame_num The amount of messages to send. * @return The status of the sending action which is defined by * apollo::common::ErrorCode. */ apollo::common::ErrorCode Send(const std::vector<CanFrame>& frames, int32_t* const frame_num) override; /** * @brief Receive messages * @param frames The messages to receive. * @param frame_num The amount of messages to receive. * @return The status of the receiving action which is defined by * apollo::common::ErrorCode. */ apollo::common::ErrorCode Receive(std::vector<CanFrame>* const frames, int32_t* const frame_num) override; /** * @brief Get the error string. * @param status The status to get the error string. */ std::string GetErrorString(const int32_t status) override; private: ... ... }; } // namespace can } // namespace canbus } // namespace apollo
步驟2
在CanClientFactory中注冊(cè)新CAN卡, 在 CanClientFactory
中添加如下代碼:
void CanClientFactory::RegisterCanClients() { Register(CANCardParameter::ESD_CAN, []() -> CanClient* { return new can::EsdCanClient(); }); // register the new CAN card here. Register(CANCardParameter::EXAMPLE_CAN, []() -> CanClient* { return new can::ExampleCanClient(); }); }
步驟3
接下來(lái),需要更新配置文件 在/modules/canbus/proto/can_card_parameter.proto
添加 EXAMPLE_CAN;
message CANCardParameter { enum CANCardBrand { FAKE_CAN = 0; ESD_CAN = 1; EXAMPLE_CAN = 2; // add new CAN card here. } ... ... }
Update /modules/canbus/conf/canbus_conf.pb.txt
can_card_parameter { brand:EXAMPLE_CAN type: PCI_CARD // suppose the new can card is PCI_CARD channel_id: CHANNEL_ID_ZERO // suppose the new can card has CHANNEL_ID_ZERO } ... ...
以上是“怎么添加新的CAN卡”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
本文名稱:怎么添加新的CAN卡
標(biāo)題來(lái)源:http://bm7419.com/article18/pciddp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、全網(wǎng)營(yíng)銷推廣、品牌網(wǎng)站建設(shè)、、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)