From eb07d2c49fb90d5da10b26dc9f4ab933d24d01a5 Mon Sep 17 00:00:00 2001 From: yaoweifeng01 Date: Wed, 20 Mar 2019 13:01:19 +0800 Subject: [PATCH] cyber: fix lint & add record info tools for python --- cyber/py_wrapper/py_node.h | 15 ++--- cyber/python/examples/record_channel_info.py | 58 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 cyber/python/examples/record_channel_info.py diff --git a/cyber/py_wrapper/py_node.h b/cyber/py_wrapper/py_node.h index 5adc1484e6..b16eac4ca9 100644 --- a/cyber/py_wrapper/py_node.h +++ b/cyber/py_wrapper/py_node.h @@ -163,6 +163,7 @@ class PyReader { std::condition_variable msg_cond_; }; +using PyMsgWrapPtr = std::shared_ptr; class PyService { public: PyService(const std::string& service_name, const std::string& data_type, @@ -175,7 +176,7 @@ class PyService { const std::shared_ptr& request, std::shared_ptr& response) { - this->cb(request, response); + response = this->cb(request); }; service_ = node_->CreateService( @@ -201,9 +202,9 @@ class PyService { } private: - void cb(const std::shared_ptr& - request, - std::shared_ptr& response) { + PyMsgWrapPtr cb( + const std::shared_ptr& + request) { std::lock_guard lg(msg_lock_); request_cache_.push_back(request->data()); @@ -218,9 +219,9 @@ class PyService { response_cache_.pop_front(); } - std::shared_ptr m; - m.reset(new apollo::cyber::message::PyMessageWrap(msg, data_type_)); - response = m; + PyMsgWrapPtr response; + response.reset(new apollo::cyber::message::PyMessageWrap(msg, data_type_)); + return response; } apollo::cyber::Node* node_; diff --git a/cyber/python/examples/record_channel_info.py b/cyber/python/examples/record_channel_info.py new file mode 100644 index 0000000000..407a54a612 --- /dev/null +++ b/cyber/python/examples/record_channel_info.py @@ -0,0 +1,58 @@ +# **************************************************************************** +# Copyright 2018 The Apollo Authors. All Rights Reserved. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# **************************************************************************** +# -*- coding: utf-8 -*- +"""Module for example of record.""" + +import time +import sys + +from cyber_py import cyber +from cyber_py import record +from cyber.proto import record_pb2 +from google.protobuf.descriptor_pb2 import FileDescriptorProto + +def print_channel_info(file_path): + freader = record.RecordReader(file_path) + channels = freader.get_channellist() + + header_msg = freader.get_headerstring() + header = record_pb2.Header() + header.ParseFromString(header_msg) + + print "" + print "++++++++++++Begin Channel Info Statistics++++++++++++++" + print "-" * 40 + print "record version: %d.%d" % (header.major_version, header.minor_version) + print "record message_number: ", header.message_number + print "record file size(Byte) ", header.size + print "chunk_number: ", header.chunk_number + print "channel counts: ", len(channels) + print "-" * 40 + counts = 1 + for channel in channels: + desc = freader.get_protodesc(channel) + print "[", counts , "]", "channel name: ", channel, "; desc size is ", len(desc) + counts = counts + 1 + # print desc + print "++++++++++++Finish Channel Info Statistics++++++++++++++" + + print "" + +if __name__ == '__main__': + cyber.init() + rec_file = (sys.argv[1]) + print_channel_info(rec_file) + cyber.shutdown() -- GitLab