[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi include/certi.hh libRTI/RTIfedTime.cc lib...
From: |
certi-cvs |
Subject: |
[certi-cvs] certi include/certi.hh libRTI/RTIfedTime.cc lib... |
Date: |
Sun, 28 Feb 2010 18:54:44 +0000 |
CVSROOT: /sources/certi
Module name: certi
Changes by: Eric NOULARD <erk> 10/02/28 18:54:44
Modified files:
include : certi.hh
libRTI : RTIfedTime.cc CMakeLists.txt
Added files:
libRTI : TestFedTime.cc
Log message:
Fix bug:
CERTI - Bugs: bug #29028, FedTime encoding and decoding...
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/include/certi.hh?cvsroot=certi&r1=3.42&r2=3.43
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/RTIfedTime.cc?cvsroot=certi&r1=3.1&r2=3.2
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/CMakeLists.txt?cvsroot=certi&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/TestFedTime.cc?cvsroot=certi&rev=3.1
Patches:
Index: include/certi.hh
===================================================================
RCS file: /sources/certi/certi/include/certi.hh,v
retrieving revision 3.42
retrieving revision 3.43
diff -u -b -r3.42 -r3.43
--- include/certi.hh 7 Feb 2010 10:39:50 -0000 3.42
+++ include/certi.hh 28 Feb 2010 18:54:44 -0000 3.43
@@ -16,7 +16,7 @@
// License along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: certi.hh,v 3.42 2010/02/07 10:39:50 gotthardp Exp $
+// $Id: certi.hh,v 3.43 2010/02/28 18:54:44 erk Exp $
// ----------------------------------------------------------------------------
#ifndef CERTI_HH_INCLUDED
@@ -74,6 +74,39 @@
#define CERTI_EXPORT
#endif
+#define CERTI_UINT64_SWAP_LE_BE_CONSTANT(val) ((uint64_t) ( \
+ (((uint64_t) (val) & \
+ (uint64_t) CERTI_INT64_CONSTANT(0x00000000000000ffU)) << 56) | \
+ (((uint64_t) (val) & \
+ (uint64_t) CERTI_INT64_CONSTANT(0x000000000000ff00U)) << 40) | \
+ (((uint64_t) (val) & \
+ (uint64_t) CERTI_INT64_CONSTANT(0x0000000000ff0000U)) << 24) | \
+ (((uint64_t) (val) & \
+ (uint64_t) CERTI_INT64_CONSTANT(0x00000000ff000000U)) << 8) | \
+ (((uint64_t) (val) & \
+ (uint64_t) CERTI_INT64_CONSTANT(0x000000ff00000000U)) >> 8) | \
+ (((uint64_t) (val) & \
+ (uint64_t) CERTI_INT64_CONSTANT(0x0000ff0000000000U)) >> 24) | \
+ (((uint64_t) (val) & \
+ (uint64_t) CERTI_INT64_CONSTANT(0x00ff000000000000U)) >> 40) | \
+ (((uint64_t) (val) & \
+ (uint64_t) CERTI_INT64_CONSTANT(0xff00000000000000U)) >> 56)))
+
+#ifdef HOST_IS_BIG_ENDIAN
+ #define CERTI_UINT64_SWAP_LE_BE(val) (CERTI_UINT64_SWAP_LE_BE_CONSTANT(val))
+ #define CERTI_UINT64_TO_BE(val) (val)
+ #define CERTI_UINT64_TO_LE(val) (CERTI_UINT64_SWAP_LE_BE (val))
+#else
+ #define CERTI_UINT64_SWAP_LE_BE(val) (CERTI_UINT64_SWAP_LE_BE_CONSTANT(val))
+ #define CERTI_UINT64_TO_BE(val) (CERTI_UINT64_SWAP_LE_BE (val))
+ #define CERTI_UINT64_TO_LE(val) (val)
+#endif
+
+#define CERTI_UINT64_FROM_BE(val) (CERTI_UINT64_TO_BE(val))
+#define CERTI_UINT64_FROM_LE(val) (CERTI_UINT64_TO_LE(val))
+#define CERTI_ENCODE_DOUBLE_TO_UINT64BE(val) (CERTI_UINT64_TO_BE
(*(uint64_t*)(val)))
+#define CERTI_DECODE_DOUBLE_FROM_UINT64BE(val) (CERTI_UINT64_FROM_BE
(*(uint64_t*)(val)))
+
#include "RTI.hh"
/**
@@ -231,4 +264,4 @@
(uint64_t) CERTI_INT64_CONSTANT(0xff00000000000000U)) >> 56)))
#endif // CERTI_HH_INCLUDED
-// $Id: certi.hh,v 3.42 2010/02/07 10:39:50 gotthardp Exp $
+// $Id: certi.hh,v 3.43 2010/02/28 18:54:44 erk Exp $
Index: libRTI/RTIfedTime.cc
===================================================================
RCS file: /sources/certi/certi/libRTI/RTIfedTime.cc,v
retrieving revision 3.1
retrieving revision 3.2
diff -u -b -r3.1 -r3.2
--- libRTI/RTIfedTime.cc 2 Apr 2009 19:58:06 -0000 3.1
+++ libRTI/RTIfedTime.cc 28 Feb 2010 18:54:44 -0000 3.2
@@ -78,8 +78,13 @@
RTI::FedTimeFactory::decode(const char *buf)
throw (RTI::MemoryExhausted)
{
+ union ud {
+ double dv;
+ uint64_t uv;
+ } value;
try {
- return new RTIfedTime(*(const RTI::Double*)buf);
+ value.uv = CERTI_DECODE_DOUBLE_FROM_UINT64BE(buf);
+ return new RTIfedTime(value.dv);
}
catch (std::bad_alloc) {
//throw RTI::MemoryExhausted("Cannot allocate RTI::FedTime.");
@@ -159,18 +164,27 @@
RTIfedTime::encodedLength() const
{
// current implementation of RTIfedtime takes
- // four IEEE-754 double values.
- return (sizeof(_fedTime)+
- sizeof(_zero)+
- sizeof(_epsilon)+
- sizeof(_positiveInfinity));
+ // four IEEE-754 double values:
+ // _fedTime
+ // _zero
+ // _epsilon
+ // _positiveInfinity
+ // but we only transmit _fedTime because other value will
+ // be reconstructed autonomously
+ return (sizeof(double));
}
// ----------------------------------------------------------------------------
void
RTIfedTime::encode(char *buffer) const
{
- memcpy(buffer, &_fedTime, sizeof(RTI::Double));
+#ifdef HOST_IS_BIG_ENDIAN
+ memcpy(buffer, &_fedTime, sizeof(double));
+#else
+ uint64_t value;
+ value = CERTI_ENCODE_DOUBLE_TO_UINT64BE(&_fedTime);
+ memcpy(buffer,&value,sizeof(double));
+#endif
}
// ----------------------------------------------------------------------------
Index: libRTI/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libRTI/CMakeLists.txt,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- libRTI/CMakeLists.txt 1 Feb 2010 14:06:40 -0000 1.13
+++ libRTI/CMakeLists.txt 28 Feb 2010 18:54:44 -0000 1.14
@@ -77,6 +77,16 @@
SET_TARGET_PROPERTIES(FedTime PROPERTIES VERSION 1.0.0 SOVERSION 1)
+SET(TestFedTime_SRCS
+ TestFedTime.cc
+)
+
+ADD_EXECUTABLE(TestFedTime ${TestFedTime_SRCS})
+
+TARGET_LINK_LIBRARIES(TestFedTime FedTime RTI)
+
+ADD_TEST(TestLibFedTime TestFedTime)
+
# Install rules for both libRTI-NG and libFedTime
INSTALL(TARGETS RTI FedTime
RUNTIME DESTINATION bin
Index: libRTI/TestFedTime.cc
===================================================================
RCS file: libRTI/TestFedTime.cc
diff -N libRTI/TestFedTime.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libRTI/TestFedTime.cc 28 Feb 2010 18:54:44 -0000 3.1
@@ -0,0 +1,89 @@
+// ----------------------------------------------------------------------------
+// TestFedTime.cc - Module test for the libFedTime
+// Copyright (C) 2008 Eric Noulard <address@hidden>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1, as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// $Id: TestFedTime.cc,v 3.1 2010/02/28 18:54:44 erk Exp $
+// ----------------------------------------------------------------------------
+
+#include <iostream>
+#include <sstream>
+#include <cstdlib>
+
+#include "certi.hh"
+#include "fedtime.hh"
+
+#define BUFLEN 12
+#define PRINTBUFLEN 50
+std::string
+show(const void* data, uint32_t n) {
+ uint32_t i;
+ std::stringstream msg;
+
+ const uint8_t* u8data = reinterpret_cast<const uint8_t*>(data);
+ msg << "0x";
+ for (i=0;i<n;++i) {
+ if ((0==(i%2))&&(i>0)) {
+ msg << " ";
+ }
+ msg << std::uppercase << std::hex << (int)u8data[i];
+ }
+ return msg.str();
+}
+
+int
+main(int argc, char* argv[]) {
+ int result = EXIT_SUCCESS;
+ char buffer[BUFLEN];
+ char printBuffer[PRINTBUFLEN];
+
+ std::cout << "Host byte-order: "
+#ifdef HOST_IS_BIG_ENDIAN
+ << "big-endian" << std::endl;
+#else
+ << "little-endian" << std::endl;
+#endif
+ RTI::FedTime* time = RTI::FedTimeFactory::makeZero();
+ std::cout << "PrintableLength = " << time->getPrintableLength()
<<std::endl;
+ if (time->getPrintableLength() > (PRINTBUFLEN+1)) {
+ std::cerr << "Cannot print value " << PRINTBUFLEN+1 << " < "<<
time->getPrintableLength() << std::endl;
+ exit(EXIT_FAILURE);
+ }
+ time->getPrintableString(printBuffer);
+ std::cout << "Zero = " << printBuffer <<std::endl;
+ time->setEpsilon();time->getPrintableString(printBuffer);
+ std::cout << "Epsilon = " << printBuffer<<std::endl;
+ time->setPositiveInfinity();time->getPrintableString(printBuffer);
+ std::cout << "Positive Infinity = " << printBuffer<<std::endl;
+ time->setZero();
+ RTIfedTime pi(RTI::Double(3.14159));
+ *time = pi;
+ time->getPrintableString(printBuffer);
+ std::cout << "Pi = " << printBuffer<<std::endl;
+ double pid = pi.getTime();
+ std::cout << " raw value = " << show(&pid,sizeof(pid)) <<
std::endl;
+ std::cout << "Trying to encode time..." <<std::endl;
+ std::cout << " encoded length = " << time->encodedLength()
<<std::endl;
+ if (time->encodedLength()<(BUFLEN+1)) {
+ time->encode(buffer);
+ } else {
+ std::cerr << "Cannot encode :"<< (BUFLEN+1) << "<" <<
time->encodedLength() << std::endl;
+ return EXIT_FAILURE;
+ }
+ std::cout << " encoded value = " <<
show(buffer,time->encodedLength()) << std::endl;
+ std::cout << "Trying to decode time..." <<std::endl;
+ RTI::FedTime* time2 = RTI::FedTimeFactory::decode(buffer);
+ time2->getPrintableString(printBuffer);
+ std::cout << " decoded value = " << printBuffer << std::endl;
+ return result;
+}
+
+// $Id: TestFedTime.cc,v 3.1 2010/02/28 18:54:44 erk Exp $
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] certi include/certi.hh libRTI/RTIfedTime.cc lib...,
certi-cvs <=