log.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2015 Aldebaran
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 
00018 #include "log.hpp"
00019 
00020 namespace naoqi
00021 {
00022 namespace recorder
00023 {
00024 
00025 LogRecorder::LogRecorder(const std::string& topic , float buffer_frequency):
00026   topic_( topic ),
00027   buffer_duration_(helpers::recorder::bufferDefaultDuration),
00028   buffer_frequency_(buffer_frequency),
00029   counter_(1)
00030 {}
00031 
00032 void LogRecorder::write(std::list<rosgraph_msgs::Log>& log_msgs)
00033 {
00034   while ( !log_msgs.empty() )
00035   {
00036     if (!log_msgs.front().header.stamp.isZero()) {
00037       gr_->write(topic_, log_msgs.front(), log_msgs.front().header.stamp);
00038     }
00039     else {
00040       gr_->write(topic_, log_msgs.front());
00041     }
00042     {
00043       log_msgs.pop_front();
00044     }
00045   }
00046 }
00047 
00048 void LogRecorder::writeDump(const ros::Time& time)
00049 {
00050   boost::mutex::scoped_lock lock_write_buffer( mutex_ );
00051   boost::circular_buffer< std::list<rosgraph_msgs::Log> >::iterator it;
00052   for (it = buffer_.begin(); it != buffer_.end(); it++)
00053   {
00054     write(*it);
00055   }
00056 }
00057 
00058 void LogRecorder::reset(boost::shared_ptr<GlobalRecorder> gr, float conv_frequency)
00059 {
00060   gr_ = gr;
00061   conv_frequency_ = conv_frequency;
00062   if (buffer_frequency_ != 0)
00063   {
00064     max_counter_ = static_cast<int>(conv_frequency/buffer_frequency_);
00065     buffer_size_ = static_cast<size_t>(buffer_duration_*(conv_frequency/max_counter_));
00066   }
00067   else
00068   {
00069     max_counter_ = 1;
00070     buffer_size_ = static_cast<size_t>(buffer_duration_*conv_frequency);
00071   }
00072   buffer_.resize(buffer_size_);
00073   is_initialized_ = true;
00074 }
00075 
00076 void LogRecorder::bufferize( std::list<rosgraph_msgs::Log>& log_msgs )
00077 {
00078   boost::mutex::scoped_lock lock_bufferize( mutex_ );
00079   if (counter_ < max_counter_)
00080   {
00081     counter_++;
00082   }
00083   else
00084   {
00085     counter_ = 1;
00086     buffer_.push_back(log_msgs);
00087   }
00088 }
00089 
00090 void LogRecorder::setBufferDuration(float duration)
00091 {
00092   boost::mutex::scoped_lock lock_bufferize( mutex_ );
00093   buffer_size_ = static_cast<size_t>(duration*(conv_frequency_/max_counter_));
00094   buffer_duration_ = duration;
00095   buffer_.set_capacity(buffer_size_);
00096 }
00097 
00098 } //publisher
00099 } // naoqi


naoqi_driver
Author(s): Karsten Knese
autogenerated on Tue Jul 9 2019 03:21:56