Apollo 11.0
自动驾驶开放平台
can_client_tool.cc 文件参考
#include <cstdint>
#include <iostream>
#include <memory>
#include <thread>
#include "cyber/common/file.h"
#include "cyber/common/log.h"
#include "cyber/time/time.h"
#include "gflags/gflags.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/common/util/factory.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_client/can_client_factory.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
can_client_tool.cc 的引用(Include)关系图:

浏览源代码.

类

struct  apollo::drivers::canbus::TestCanParam
 
class  apollo::drivers::canbus::CanAgent
 

命名空间

namespace  apollo
 class register implement
 
namespace  apollo::drivers
 apollo::drivers
 
namespace  apollo::drivers::canbus
 apollo::drivers::canbus
 

函数

 DEFINE_bool (only_one_send, false, "only send test.")
 
 DEFINE_string (can_client_conf_file_a, "modules/canbus/conf/can_client_conf_a.pb.txt", "can client conf for client a")
 
 DEFINE_string (can_client_conf_file_b, "modules/canbus/conf/can_client_conf_b.pb.txt", "can client conf for client b")
 
 DEFINE_int64 (agent_mutual_send_frames, 1000, "Every agent send frame num")
 
int main (int32_t argc, char **argv)
 

变量

const int32_t MAX_CAN_SEND_FRAME_LEN = 1
 
const int32_t MAX_CAN_RECV_FRAME_LEN = 10
 

函数说明

◆ DEFINE_bool()

DEFINE_bool ( only_one_send  ,
false  ,
"only send test."   
)

◆ DEFINE_int64()

DEFINE_int64 ( agent_mutual_send_frames  ,
1000  ,
"Every agent send frame num"   
)

◆ DEFINE_string() [1/2]

DEFINE_string ( can_client_conf_file_a  ,
"modules/canbus/conf/can_client_conf_a.pb.txt"  ,
"can client conf for client a"   
)

◆ DEFINE_string() [2/2]

DEFINE_string ( can_client_conf_file_b  ,
"modules/canbus/conf/can_client_conf_b.pb.txt"  ,
"can client conf for client b"   
)

◆ main()

int main ( int32_t  argc,
char **  argv 
)

在文件 can_client_tool.cc 第 247 行定义.

247 {
248 google::InitGoogleLogging(argv[0]);
249 google::ParseCommandLineFlags(&argc, &argv, true);
250
257 CANCardParameter can_client_conf_a;
258 std::shared_ptr<TestCanParam> param_ptr_a(new TestCanParam());
259 std::shared_ptr<TestCanParam> param_ptr_b(new TestCanParam());
260
261 auto can_client_factory = CanClientFactory::Instance();
262 can_client_factory->RegisterCanClients();
263
264 if (!apollo::cyber::common::GetProtoFromFile(FLAGS_can_client_conf_file_a,
265 &can_client_conf_a)) {
266 AERROR << "Unable to load canbus conf file: "
267 << FLAGS_can_client_conf_file_a;
268 return -1;
269 }
270 AINFO << "Conf file is loaded: " << FLAGS_can_client_conf_file_a;
271 AINFO << can_client_conf_a.ShortDebugString();
272 auto client_a = can_client_factory->CreateObject(can_client_conf_a.brand());
273 if (!client_a || !client_a->Init(can_client_conf_a) ||
274 client_a->Start() != ErrorCode::OK) {
275 AERROR << "Create can client a failed.";
276 return -1;
277 }
278 param_ptr_a->can_client = client_a.get();
279 param_ptr_a->is_first_agent = true;
280 param_ptr_a->conf = can_client_conf_a;
281
282 CANCardParameter can_client_conf_b;
283 std::unique_ptr<CanClient> client_b;
284 if (!FLAGS_only_one_send) {
285 if (!apollo::cyber::common::GetProtoFromFile(FLAGS_can_client_conf_file_b,
286 &can_client_conf_b)) {
287 AERROR << "Unable to load canbus conf file: "
288 << FLAGS_can_client_conf_file_b;
289 return -1;
290 }
291 AINFO << "Conf file is loaded: " << FLAGS_can_client_conf_file_b;
292 AINFO << can_client_conf_b.ShortDebugString();
293 client_b = can_client_factory->CreateObject(can_client_conf_b.brand());
294 if (!client_b || !client_b->Init(can_client_conf_b) ||
295 client_b->Start() != ErrorCode::OK) {
296 AERROR << "Create can client b failed.";
297 return -1;
298 }
299 param_ptr_b->can_client = client_b.get();
300 param_ptr_b->conf = can_client_conf_b;
301 }
302
303 CanAgent agent_a(param_ptr_a.get());
304 CanAgent agent_b(param_ptr_b.get());
305 agent_a.AddOtherAgent(&agent_b);
306 agent_b.AddOtherAgent(&agent_a);
307 if (!agent_a.Start()) {
308 AERROR << "Agent a start failed.";
309 return -1;
310 }
311 if (FLAGS_only_one_send) {
312 agent_b.is_receiving(true);
313 agent_b.is_sending_finish(true);
314 } else {
315 if (!agent_b.Start()) {
316 AERROR << "Agent b start failed.";
317 return -1;
318 }
319 }
320
321 agent_a.WaitForFinish();
322 if (!FLAGS_only_one_send) {
323 agent_b.WaitForFinish();
324 }
325 param_ptr_a->print();
326 if (!FLAGS_only_one_send) {
327 param_ptr_b->print();
328 }
329
330 return 0;
331}
CanClientFactory inherites apollo::common::util::Factory.
The class which defines the CAN client to send and receive message.
Definition can_client.h:92
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132

变量说明

◆ MAX_CAN_RECV_FRAME_LEN

const int32_t MAX_CAN_RECV_FRAME_LEN = 10

在文件 can_client_tool.cc 第 43 行定义.

◆ MAX_CAN_SEND_FRAME_LEN

const int32_t MAX_CAN_SEND_FRAME_LEN = 1

在文件 can_client_tool.cc 第 42 行定义.