modify for Hydro version

Dependencies:   MODSERIAL

Fork of rosserial_mbed_lib by nucho

Committer:
jjzak
Date:
Sat Oct 26 15:38:35 2013 +0000
Revision:
5:8cd48977ec68
Parent:
1:ff0ec969dad1
modify for Hydro version

Who changed what in which revision?

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