00001 /********************************************************************* 00002 * Software License Agreement (Proprietary and Confidential) 00003 * 00004 * Copyright (c) 2017-2018, Dataspeed Inc. 00005 * All rights reserved. 00006 * 00007 * NOTICE: All information contained herein is, and remains the 00008 * property of Dataspeed Inc. The intellectual and technical concepts 00009 * contained herein are proprietary to Dataspeed Inc. and may be 00010 * covered by U.S. and Foreign Patents, patents in process, and are 00011 * protected by trade secret or copyright law. Dissemination of this 00012 * information or reproduction of this material is strictly forbidden 00013 * unless prior written permission is obtained from Dataspeed Inc. 00014 *********************************************************************/ 00015 00016 #ifndef _MSG_RX_H_ 00017 #define _MSG_RX_H_ 00018 00019 #include <ros/ros.h> 00020 00021 template <typename MsgT> 00022 class MsgRx { 00023 public: 00024 MsgRx(const ros::WallDuration& thresh) : dur_(thresh) {}; 00025 MsgRx(const ros::WallDuration& thresh, const MsgT& msg) : dur_(thresh) { set(msg); }; 00026 void set(const MsgT& msg) { msg_ = msg; stamp_ = ros::WallTime::now(); } 00027 void clear() { stamp_ = ros::WallTime(0); } 00028 bool fresh(ros::WallDuration delta) const { return age() < delta; } 00029 bool fresh() const { return fresh(dur_); } 00030 ros::WallDuration age() const { return !stamp_.isZero() ? ros::WallTime::now() - stamp_ : ros::WallDuration(9999.0); } 00031 const MsgT& get() const { return msg_; } 00032 const ros::WallTime& stamp() const { return stamp_; } 00033 private: 00034 MsgT msg_; 00035 ros::WallTime stamp_; 00036 ros::WallDuration dur_; 00037 }; 00038 00039 #endif // _MSG_RX_H_