rosserial for Hydro

Dependencies:   MODSERIAL

Fork of rosserial_mbed_lib by nucho

Committer:
isad
Date:
Thu May 08 06:34:18 2014 +0000
Revision:
5:c30c76e8c3f1
Parent:
1:ff0ec969dad1
rosserial_mbed for ROS hydro

Who changed what in which revision?

UserRevisionLine numberNew contents of line
isad 5:c30c76e8c3f1 1 /*
isad 5:c30c76e8c3f1 2 * Software License Agreement (BSD License)
isad 5:c30c76e8c3f1 3 *
isad 5:c30c76e8c3f1 4 * Copyright (c) 2011, Willow Garage, Inc.
isad 5:c30c76e8c3f1 5 * All rights reserved.
isad 5:c30c76e8c3f1 6 *
isad 5:c30c76e8c3f1 7 * Redistribution and use in source and binary forms, with or without
isad 5:c30c76e8c3f1 8 * modification, are permitted provided that the following conditions
isad 5:c30c76e8c3f1 9 * are met:
isad 5:c30c76e8c3f1 10 *
isad 5:c30c76e8c3f1 11 * * Redistributions of source code must retain the above copyright
isad 5:c30c76e8c3f1 12 * notice, this list of conditions and the following disclaimer.
isad 5:c30c76e8c3f1 13 * * Redistributions in binary form must reproduce the above
isad 5:c30c76e8c3f1 14 * copyright notice, this list of conditions and the following
isad 5:c30c76e8c3f1 15 * disclaimer in the documentation and/or other materials provided
isad 5:c30c76e8c3f1 16 * with the distribution.
isad 5:c30c76e8c3f1 17 * * Neither the name of Willow Garage, Inc. nor the names of its
isad 5:c30c76e8c3f1 18 * contributors may be used to endorse or promote prducts derived
isad 5:c30c76e8c3f1 19 * from this software without specific prior written permission.
isad 5:c30c76e8c3f1 20 *
isad 5:c30c76e8c3f1 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
isad 5:c30c76e8c3f1 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
isad 5:c30c76e8c3f1 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
isad 5:c30c76e8c3f1 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
isad 5:c30c76e8c3f1 25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
isad 5:c30c76e8c3f1 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
isad 5:c30c76e8c3f1 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
isad 5:c30c76e8c3f1 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
isad 5:c30c76e8c3f1 29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
isad 5:c30c76e8c3f1 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
isad 5:c30c76e8c3f1 31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
isad 5:c30c76e8c3f1 32 * POSSIBILITY OF SUCH DAMAGE.
isad 5:c30c76e8c3f1 33 */
isad 5:c30c76e8c3f1 34
isad 5:c30c76e8c3f1 35 #ifndef ROS_TIME_H_
isad 5:c30c76e8c3f1 36 #define ROS_TIME_H_
isad 5:c30c76e8c3f1 37
isad 5:c30c76e8c3f1 38 #include <ros/duration.h>
isad 5:c30c76e8c3f1 39 #include <math.h>
isad 5:c30c76e8c3f1 40
isad 5:c30c76e8c3f1 41 namespace ros
isad 5:c30c76e8c3f1 42 {
isad 5:c30c76e8c3f1 43 void normalizeSecNSec(unsigned long &sec, unsigned long &nsec);
isad 5:c30c76e8c3f1 44
isad 5:c30c76e8c3f1 45 class Time
isad 5:c30c76e8c3f1 46 {
isad 5:c30c76e8c3f1 47 public:
isad 5:c30c76e8c3f1 48 unsigned long sec, nsec;
isad 5:c30c76e8c3f1 49
isad 5:c30c76e8c3f1 50 Time() : sec(0), nsec(0) {}
isad 5:c30c76e8c3f1 51 Time(unsigned long _sec, unsigned long _nsec) : sec(_sec), nsec(_nsec)
isad 5:c30c76e8c3f1 52 {
isad 5:c30c76e8c3f1 53 normalizeSecNSec(sec, nsec);
isad 5:c30c76e8c3f1 54 }
isad 5:c30c76e8c3f1 55
isad 5:c30c76e8c3f1 56 double toSec() const { return (double)sec + 1e-9*(double)nsec; };
isad 5:c30c76e8c3f1 57 void fromSec(double t) { sec = (unsigned long) floor(t); nsec = (unsigned long) rint((t-sec) * 1e9); };
isad 5:c30c76e8c3f1 58
isad 5:c30c76e8c3f1 59 unsigned long toNsec() { return (unsigned long)sec*1000000000ull + (unsigned long)nsec; };
isad 5:c30c76e8c3f1 60 Time& fromNSec(long t);
isad 5:c30c76e8c3f1 61
isad 5:c30c76e8c3f1 62 Time& operator +=(const Duration &rhs);
isad 5:c30c76e8c3f1 63 Time& operator -=(const Duration &rhs);
isad 5:c30c76e8c3f1 64
isad 5:c30c76e8c3f1 65 static Time now();
isad 5:c30c76e8c3f1 66 static void setNow( Time & new_now);
isad 5:c30c76e8c3f1 67 };
isad 5:c30c76e8c3f1 68
isad 5:c30c76e8c3f1 69 }
isad 5:c30c76e8c3f1 70
isad 5:c30c76e8c3f1 71 #endif