247int main(int32_t argc,
char **argv) {
248 google::InitGoogleLogging(argv[0]);
249 google::ParseCommandLineFlags(&argc, &argv,
true);
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());
261 auto can_client_factory = CanClientFactory::Instance();
262 can_client_factory->RegisterCanClients();
265 &can_client_conf_a)) {
266 AERROR <<
"Unable to load canbus conf file: "
267 << FLAGS_can_client_conf_file_a;
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.";
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;
282 CANCardParameter can_client_conf_b;
283 std::unique_ptr<CanClient> client_b;
284 if (!FLAGS_only_one_send) {
286 &can_client_conf_b)) {
287 AERROR <<
"Unable to load canbus conf file: "
288 << FLAGS_can_client_conf_file_b;
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.";
299 param_ptr_b->can_client = client_b.get();
300 param_ptr_b->conf = can_client_conf_b;
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.";
311 if (FLAGS_only_one_send) {
312 agent_b.is_receiving(
true);
313 agent_b.is_sending_finish(
true);
315 if (!agent_b.Start()) {
316 AERROR <<
"Agent b start failed.";
321 agent_a.WaitForFinish();
322 if (!FLAGS_only_one_send) {
323 agent_b.WaitForFinish();
325 param_ptr_a->print();
326 if (!FLAGS_only_one_send) {
327 param_ptr_b->print();
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,...