Apollo 10.0
自动驾驶开放平台
can_client_factory.cc
浏览该文件的文档.
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
18
20#if USE_ESD_CAN
22#endif
23
25
27
28#include "cyber/common/log.h"
30
31namespace apollo {
32namespace drivers {
33namespace canbus {
34
35CanClientFactory::CanClientFactory() {}
36
38 AINFO << "CanClientFactory::RegisterCanClients";
40 []() -> CanClient* { return new can::FakeCanClient(); });
41#if USE_ESD_CAN
42 AINFO << "register can: " << CANCardParameter::ESD_CAN;
44 []() -> CanClient* { return new can::EsdCanClient(); });
45#endif
47 []() -> CanClient* { return new can::SocketCanClientRaw(); });
48
50 []() -> CanClient* { return new can::HermesCanClient(); });
51}
52
53std::unique_ptr<CanClient> CanClientFactory::CreateCANClient(
54 const CANCardParameter& parameter) {
55 auto factory = CreateObject(parameter.brand());
56 if (!factory) {
57 AERROR << "Failed to create CAN client with parameter: "
58 << parameter.DebugString();
59 } else if (!factory->Init(parameter)) {
60 AERROR << "Failed to initialize CAN card with parameter: "
61 << parameter.DebugString();
62 }
63 return factory;
64}
65
66} // namespace canbus
67} // namespace drivers
68} // namespace apollo
Defines the CanClientFactory class.
std::unique_ptr< CanClient > CreateObject(const CANCardParameter::CANCardBrand &id, Args &&... args)
Creates and transfers membership of an object of type matching id.
Definition factory.h:115
bool Register(const CANCardParameter::CANCardBrand &id, CanClient *(*)() creator)
Registers the class given by the creator function, linking it to id.
Definition factory.h:70
void RegisterCanClients()
Register the CAN clients of all brands.
std::unique_ptr< CanClient > CreateCANClient(const CANCardParameter &parameter)
Create a pointer to a specified brand of CAN client.
The class which defines the CAN client to send and receive message.
Definition can_client.h:92
The class which defines an ESD CAN client which inherits CanClient.
The class which defines a fake CAN client which inherits CanClient.
The class which defines a BCAN client which inherits CanClient.
The class which defines an ESD CAN client which inherites CanClient.
Defines the EsdCanClient class which inherits CanClient.
Defines the FakeCanClient class which inherites CanClient.
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
Some util functions.
class register implement
Definition arena_queue.h:37
Defines the SocketCanClientRaw class which inherits CanClient.