semin ahn / Mbed OS zeta_stm_kinetic

Dependencies:   BufferedSerial

Committer:
_seminahn
Date:
Fri Apr 02 05:24:49 2021 +0000
Revision:
0:4ff8aeb3e4d1
top_module

Who changed what in which revision?

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