Apollo 10.0
自动驾驶开放平台
channel_test_writer.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
17#include "cyber/cyber.h"
18#include "cyber/examples/proto/examples.pb.h"
19#include "cyber/time/rate.h"
20#include "cyber/time/time.h"
21
25
26int main(int argc, char *argv[]) {
27 // init cyber framework
28 apollo::cyber::Init(argv[0]);
29 // create talker node
30 auto talker_node = apollo::cyber::CreateNode("channel_test_writer");
31 // create talker
32 auto talker = talker_node->CreateWriter<Driver>("/apollo/test");
33 Rate rate(2.0);
34
35 std::string content("apollo_test");
36 while (apollo::cyber::OK()) {
37 static uint64_t seq = 0;
38 auto msg = std::make_shared<Driver>();
39 msg->set_timestamp(Time::Now().ToNanosecond());
40 msg->set_msg_id(seq++);
41 msg->set_content(content + std::to_string(seq - 1));
42 talker->Write(msg);
43 AINFO << "/apollo/test sent message, seq=" << (seq - 1) << ";";
44 rate.Sleep();
45 }
46 return 0;
47}
int main(int argc, char *argv[])
Cyber has builtin time type Time.
Definition time.h:31
static Time Now()
get the current time.
Definition time.cc:57
#define AINFO
Definition log.h:42
bool Init(const char *binary_name, const std::string &dag_info)
Definition init.cc:98
bool OK()
Definition state.h:44
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33