diff -Narup gearbox.old/cmake/internal/Setup.cmake gearbox/cmake/internal/Setup.cmake --- gearbox.old/cmake/internal/Setup.cmake 2008-09-24 18:46:44.000000000 +0200 +++ gearbox/cmake/internal/Setup.cmake 2008-09-24 18:48:53.000000000 +0200 @@ -40,7 +40,7 @@ INCLUDE( ${GBX_CMAKE_DIR}/DependencyUtil # Defaults for big source code switches # (these are defaults. after the user modifies these in GUI they stay in cache) # -OPTION( GBX_BUILD_LICENSE "Enables writing LICENCE file. For admins only." OFF ) +OPTION( GBX_BUILD_LICENSE "Enables writing LICENCE file. For admins only." ON ) # # check compiler type and version @@ -77,7 +77,7 @@ SET( CMAKE_INSTALL_RPATH ${GBX_LIB_INSTA # Enable testing by including the Dart module # (must be done *before* entering source directories ) INCLUDE(${CMAKE_ROOT}/Modules/Dart.cmake) -ENABLE_TESTING() +ENABLE_TESTING(ON) # # Enter the source tree diff -Narup gearbox.old/cmake/SetupDirectories.cmake gearbox/cmake/SetupDirectories.cmake --- gearbox.old/cmake/SetupDirectories.cmake 2008-07-25 14:15:01.000000000 +0200 +++ gearbox/cmake/SetupDirectories.cmake 2008-09-24 18:10:21.000000000 +0200 @@ -22,7 +22,7 @@ IF( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) MESSAGE( STATUS "Setting default installation directory..." ) IF( NOT GBX_OS_WIN ) - SET( CMAKE_INSTALL_PREFIX /usr/local CACHE PATH "Installation directory" FORCE ) + SET( CMAKE_INSTALL_PREFIX /usr CACHE PATH "Installation directory" FORCE ) ELSE ( NOT GBX_OS_WIN ) SET( CMAKE_INSTALL_PREFIX "C:\Program Files\${PROJECT_NAME}\Include" CACHE PATH "Installation directory" FORCE ) ENDIF( NOT GBX_OS_WIN ) diff -Narup gearbox.old/CMakeLists.txt gearbox/CMakeLists.txt --- gearbox.old/CMakeLists.txt 2008-07-25 14:16:42.000000000 +0200 +++ gearbox/CMakeLists.txt 2008-09-24 18:10:21.000000000 +0200 @@ -11,7 +11,7 @@ PROJECT( gearbox ) # # project version string # -SET( GBX_PROJECT_VERSION 8.07 CACHE STRING "Version of GearBox distribution" ) +SET( GBX_PROJECT_VERSION 8.07+ CACHE STRING "Version of GearBox distribution" ) # # The rest is done by a script diff -Narup gearbox.old/doc/images/gearbox_logo.svg gearbox/doc/images/gearbox_logo.svg --- gearbox.old/doc/images/gearbox_logo.svg 1970-01-01 01:00:00.000000000 +0100 +++ gearbox/doc/images/gearbox_logo.svg 2008-09-24 18:10:21.000000000 +0200 @@ -0,0 +1,120 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + Box + Gear + + diff -Narup gearbox.old/doc/release_instructions.dox gearbox/doc/release_instructions.dox --- gearbox.old/doc/release_instructions.dox 2008-07-25 14:25:57.000000000 +0200 +++ gearbox/doc/release_instructions.dox 2008-09-24 18:10:21.000000000 +0200 @@ -30,21 +30,21 @@ -# Check in those changes. -# Tag the distributions, eg with: @verbatim -$ svn copy https://gearbox.svn.sf.net/svnroot/gearbox/gearbox/trunk https://gearbox.svn.sf.net/svnroot/gearbox/gearbox/tags/RELEASE_1.7.0 -m 'Tagging release 1.7.0' +$ svn copy https://gearbox.svn.sf.net/svnroot/gearbox/gearbox/trunk https://gearbox.svn.sf.net/svnroot/gearbox/gearbox/tags/RELEASE_9.02 -m 'Tagging release 9.02' @endverbatim -# Delete all .svn directories (eg with 'find . -name .svn | xargs rm -rf') - -# Create tar-ball, named eg. 'gearbox-1.7.0.tar.gz' + -# Create tar-ball, named eg. 'gearbox-9.02.tar.gz' -# Now the tar-ball is ready to roll. But first test that the original untars and builds cleanly. -# Copy the tar-ball to a machine with external access. -# On a machine with external access: - -# ftp to upload.sf.net (anonymous login) - -# cd /incoming + -# sftp [USERNAME]\@frs.sf.net + -# cd uploads -# 'put' the tarball -# Create a new distro through the sourceforge web interface - Login a project administrator - (Go through "'Admin' -> 'File Releases'" from the GearBox project page) -# Update the web page - Use the script: /doc/rebuild_docco.sh --# Increment the version numbers (eg '1.7.0' -> '1.7.0+') in the top-level CMakeLists.txt files. +-# Increment the version numbers (eg '9.02' -> '9.02+') in the top-level CMakeLists.txt files. */ diff -Narup gearbox.old/retired/CMakeLists.txt gearbox/retired/CMakeLists.txt --- gearbox.old/retired/CMakeLists.txt 2008-07-25 14:15:11.000000000 +0200 +++ gearbox/retired/CMakeLists.txt 2008-09-24 18:10:21.000000000 +0200 @@ -1,6 +1,6 @@ # A place for libraries that have been retired from the source tree. -OPTION ( GBX_BUILD_RETIRED "Build retired libraries" OFF ) +OPTION ( GBX_BUILD_RETIRED "Build retired libraries" ON ) MARK_AS_ADVANCED ( FORCE GBX_BUILD_RETIRED ) IF( GBX_BUILD_RETIRED ) diff -Narup gearbox.old/src/basicexample/CMakeLists.txt gearbox/src/basicexample/CMakeLists.txt --- gearbox.old/src/basicexample/CMakeLists.txt 2008-07-25 14:15:10.000000000 +0200 +++ gearbox/src/basicexample/CMakeLists.txt 2008-09-24 18:10:21.000000000 +0200 @@ -2,7 +2,7 @@ SET( lib_name basicexample ) GBX_ADD_LICENSE( LGPL ) SET( build TRUE ) -GBX_REQUIRE_OPTION( build LIB ${lib_name} OFF ) +GBX_REQUIRE_OPTION( build LIB ${lib_name} ON ) IF( build ) diff -Narup gearbox.old/src/flexiport/flexiport.cpp gearbox/src/flexiport/flexiport.cpp --- gearbox.old/src/flexiport/flexiport.cpp 2008-07-25 14:15:09.000000000 +0200 +++ gearbox/src/flexiport/flexiport.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -4,17 +4,17 @@ * Copyright (c) 2008 Geoffrey Biggs * * flexiport flexible hardware data communications library. - * - * This distribution is licensed to you under the terms described in the LICENSE file included in + * + * This distribution is licensed to you under the terms described in the LICENSE file included in * this distribution. * * This work is a product of the National Institute of Advanced Industrial Science and Technology, * Japan. Registration number: H20PRO-881 - * + * * This file is part of flexiport. * * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU - * Lesser General Public License as published by the Free Software Foundation, either version 3 of + * Lesser General Public License as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without @@ -103,49 +103,28 @@ Port* CreatePort (map op #ifdef FLEXIPORT_INCLUDE_SERIAL if (type == "serial") - { - SerialPort *newPort = new SerialPort (options); - if (newPort == NULL) - throw PortException ("Failed to allocate new port"); - return newPort; - } + return new SerialPort (options); #endif // FLEXIPORT_INCLUDE_SERIAL #ifdef FLEXIPORT_INCLUDE_TCP if (type == "tcp") - { - TCPPort *newPort = new TCPPort (options); - if (newPort == NULL) - throw PortException ("Failed to allocate new port"); - return newPort; - } + return new TCPPort (options); #endif // FLEXIPORT_INCLUDE_TCP #ifdef FLEXIPORT_INCLUDE_LOGGING if (type == "logreader") - { - LogReaderPort *newPort = new LogReaderPort (options); - if (newPort == NULL) - throw PortException ("Failed to allocate new port"); - return newPort; - } + return new LogReaderPort (options); #ifdef FLEXIPORT_INCLUDE_SERIAL if (type == "seriallog") { options["type"] = "serial"; - LogWriterPort *newPort = new LogWriterPort (options); - if (newPort == NULL) - throw PortException ("Failed to allocate new port"); - return newPort; + return new LogWriterPort (options); } #endif // FLEXIPORT_INCLUDE_SERIAL #ifdef FLEXIPORT_INCLUDE_TCP if (type == "tcplog") { options["type"] = "tcp"; - LogWriterPort *newPort = new LogWriterPort (options); - if (newPort == NULL) - throw PortException ("Failed to allocate new port"); - return newPort; + return new LogWriterPort (options); } #endif // FLEXIPORT_INCLUDE_TCP #endif // FLEXIPORT_INCLUDE_LOGGING diff -Narup gearbox.old/src/flexiport/logfile.cpp gearbox/src/flexiport/logfile.cpp --- gearbox.old/src/flexiport/logfile.cpp 2008-07-25 14:15:09.000000000 +0200 +++ gearbox/src/flexiport/logfile.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -633,11 +633,7 @@ bool LogFile::CheckWrite (const void * c // Allocate space to store the data to compare with uint8_t *fileData; - if ((fileData = new uint8_t[count]) == NULL) - { - throw PortException (string ("LogFile::") + __func__ + - string ("Failed to allocate temporary space for write comparison.")); - } + fileData = new uint8_t[count]; // Pull any data out of the overflow first bool needMore = true; diff -Narup gearbox.old/src/flexiport/logreaderport.cpp gearbox/src/flexiport/logreaderport.cpp --- gearbox.old/src/flexiport/logreaderport.cpp 2008-07-25 14:15:09.000000000 +0200 +++ gearbox/src/flexiport/logreaderport.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -52,11 +52,7 @@ LogReaderPort::LogReaderPort (mapOpen (_logFileName, true, _ignoreTimes); if (_alwaysOpen) diff -Narup gearbox.old/src/flexiport/logwriterport.cpp gearbox/src/flexiport/logwriterport.cpp --- gearbox.old/src/flexiport/logwriterport.cpp 2008-07-25 14:15:09.000000000 +0200 +++ gearbox/src/flexiport/logwriterport.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -71,11 +71,7 @@ LogWriterPort::LogWriterPort (mapOpen (_logFileName, false); } diff -Narup gearbox.old/src/flexiport/port.cpp gearbox/src/flexiport/port.cpp --- gearbox.old/src/flexiport/port.cpp 2008-07-25 14:15:09.000000000 +0200 +++ gearbox/src/flexiport/port.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -4,17 +4,17 @@ * Copyright (c) 2008 Geoffrey Biggs * * flexiport flexible hardware data communications library. - * - * This distribution is licensed to you under the terms described in the LICENSE file included in + * + * This distribution is licensed to you under the terms described in the LICENSE file included in * this distribution. * * This work is a product of the National Institute of Advanced Industrial Science and Technology, * Japan. Registration number: H20PRO-881 - * + * * This file is part of flexiport. * * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU - * Lesser General Public License as published by the Free Software Foundation, either version 3 of + * Lesser General Public License as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without @@ -73,7 +73,7 @@ ssize_t Port::ReadString (std::string &b { char *charBuffer = NULL; ssize_t bytesAvailable = 0, numRead = 0; - + buffer.clear (); CheckPort (true); @@ -86,17 +86,13 @@ ssize_t Port::ReadString (std::string &b if (_debug >= 2) { - cerr << "Port::" << __func__ << "() Got " << bytesAvailable << + cerr << "Port::" << __func__ << "() Got " << bytesAvailable << " bytes waiting to be read into a string" << endl; } // Read this many characters into a string - include space for a NULL incase one doesn't // come in the transmitted data. - if ((charBuffer = new char[bytesAvailable + 1]) == NULL) - { - throw PortException (string ("Port::") + __func__ + - string ("() Failed to allocate temporary string storage.")); - } + charBuffer = new char[bytesAvailable + 1]; if ((numRead = Read (charBuffer, bytesAvailable)) < 0) return -1; // Timeout charBuffer[numRead] = '\0'; @@ -104,8 +100,8 @@ ssize_t Port::ReadString (std::string &b if (numRead != bytesAvailable && _debug >= 1) { - cerr << "WARNING: Port::" << __func__ << - " Read different number of bytes than peek said were available: " << + cerr << "WARNING: Port::" << __func__ << + " Read different number of bytes than peek said were available: " << numRead << " != " << bytesAvailable << endl; } if (_debug >= 2) @@ -125,7 +121,7 @@ ssize_t Port::ReadUntil (void * const bu if (_debug >= 2) { - cerr << "Port::" << __func__ << "() Reading until '" << terminator << "' or " << + cerr << "Port::" << __func__ << "() Reading until '" << terminator << "' or " << count << " bytes." << endl; } // Read bytes one at a time until either a timeout occurs, we hit the terminator byte, or @@ -170,7 +166,7 @@ ssize_t Port::ReadStringUntil (std::stri if (_debug >= 2) { - cerr << "Port::" << __func__ << "() Reading string until receive '" << terminator << + cerr << "Port::" << __func__ << "() Reading string until receive '" << terminator << "'" << endl; } // Read bytes one at a time until either a timeout occurs or we hit the terminator byte @@ -256,7 +252,7 @@ ssize_t Port::SkipUntil (uint8_t termina if (_debug >= 2) { - cerr << "Port::" << __func__ << "() Skipping until '" << terminator << "' is seen " << + cerr << "Port::" << __func__ << "() Skipping until '" << terminator << "' is seen " << count << " times." << endl; } // Read bytes one at a time until either a timeout occurs or we hit the terminator byte @@ -309,15 +305,15 @@ ssize_t Port::WriteFull (const void * co if (!IsOpen ()) { stringstream ss; - ss << "Port::" << __func__ << "() Port closed while trying to write " << + ss << "Port::" << __func__ << "() Port closed while trying to write " << count << " bytes"; throw PortException (ss.str ()); } // If it is open we can keep going, but with a warning if (_debug >= 1) { - cerr << "WARNING: Port::" << __func__ << - " Port closed during WriteFull operation; data may be missing/corrupted." << + cerr << "WARNING: Port::" << __func__ << + " Port closed during WriteFull operation; data may be missing/corrupted." << endl; } } @@ -342,7 +338,7 @@ ssize_t Port::WriteString (const char * return -1; // Timeout if (numWritten < numToWrite && _debug >= 1) { - cerr << "WARNING: Port::" << __func__ << "() Did not write whole string; only wrote " << + cerr << "WARNING: Port::" << __func__ << "() Did not write whole string; only wrote " << numWritten << " of " << numToWrite << " bytes" << endl; } diff -Narup gearbox.old/src/flexiport/port.h gearbox/src/flexiport/port.h --- gearbox.old/src/flexiport/port.h 2008-07-25 14:15:09.000000000 +0200 +++ gearbox/src/flexiport/port.h 2008-09-24 18:10:21.000000000 +0200 @@ -4,17 +4,17 @@ * Copyright (c) 2008 Geoffrey Biggs * * flexiport flexible hardware data communications library. - * - * This distribution is licensed to you under the terms described in the LICENSE file included in + * + * This distribution is licensed to you under the terms described in the LICENSE file included in * this distribution. * * This work is a product of the National Institute of Advanced Industrial Science and Technology, * Japan. Registration number: H20PRO-881 - * + * * This file is part of flexiport. * * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU - * Lesser General Public License as published by the Free Software Foundation, either version 3 of + * Lesser General Public License as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without @@ -154,7 +154,7 @@ class FLEXIPORT_EXPORT Port /** @brief Read a new-line terminated string of data. A convenience function that reads until a newline character (\\n, 0x0A) is received and - stores the received data in a caller-provided buffer, @ref buffer. Good for text-based + stores the received data in a caller-provided buffer, @ref buffer. Good for text-based protocols that use newlines as message terminators. Will not read more than @ref count bytes. @@ -166,10 +166,10 @@ class FLEXIPORT_EXPORT Port strlen ()). @note This function makes many calls to Read, each of which has an individual timeout. The - maximum length of time this function make take may therefore be longer than one timeout. + maximum length of time this function may take may therefore be longer than one timeout. @note If the port is set to non-blocking mode (by setting the timeout to zero), this will - effectively timeout immediatly when there is no data available, returning -1 irrespective of + effectively timeout immediately when there is no data available, returning -1 irrespective of the quantity of data actually received before that point. @return The length of the string (including the new line), or -1 if a timeout occured. */ @@ -180,7 +180,7 @@ class FLEXIPORT_EXPORT Port A convenience function that reads until a newline character (\\n, 0x0A) is received and stores the received data in a string, @buffer. Good for text-based protocols that use newlines as message terminators. - + @note This function makes many calls to Read, each of which has an individual timeout. The maximum length of time this function make take may therefore be longer than one timeout. @@ -268,7 +268,7 @@ class FLEXIPORT_EXPORT Port /** @brief Set the timeout value. Set seconds to -1 to disable timeouts and block forever. @note On Mac OS X, the timer is reset each time data is received, making the timeout an - inactivity timer in that there must be no data at all for the length of the timeout for it + inactivity timer in that there must be no data at all for the length of the timeout for it to trigger. This can potentially lead to very long blocking if the sender is sending data slightly faster than the timeout. */ virtual void SetTimeout (Timeout timeout) = 0; diff -Narup gearbox.old/src/flexiport/timeout.h gearbox/src/flexiport/timeout.h --- gearbox.old/src/flexiport/timeout.h 2008-07-25 14:15:09.000000000 +0200 +++ gearbox/src/flexiport/timeout.h 2008-09-24 18:10:21.000000000 +0200 @@ -4,17 +4,17 @@ * Copyright (c) 2008 Geoffrey Biggs * * flexiport flexible hardware data communications library. - * - * This distribution is licensed to you under the terms described in the LICENSE file included in + * + * This distribution is licensed to you under the terms described in the LICENSE file included in * this distribution. * * This work is a product of the National Institute of Advanced Industrial Science and Technology, * Japan. Registration number: H20PRO-881 - * + * * This file is part of flexiport. * * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU - * Lesser General Public License as published by the Free Software Foundation, either version 3 of + * Lesser General Public License as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without @@ -28,9 +28,6 @@ #ifndef __TIMEOUT_H #define __TIMEOUT_H -#include -#include - #if defined (WIN32) #if defined (FLEXIPORT_EXPORTS) #define FLEXIPORT_EXPORT __declspec (dllexport) diff -Narup gearbox.old/src/gbxadvancedexample/CMakeLists.txt gearbox/src/gbxadvancedexample/CMakeLists.txt --- gearbox.old/src/gbxadvancedexample/CMakeLists.txt 2008-07-25 14:15:05.000000000 +0200 +++ gearbox/src/gbxadvancedexample/CMakeLists.txt 2008-09-24 18:10:21.000000000 +0200 @@ -2,7 +2,7 @@ SET( lib_name GbxAdvancedExample ) GBX_ADD_LICENSE( GPL ) SET( build TRUE ) -GBX_REQUIRE_OPTION( build LIB ${lib_name} OFF ) +GBX_REQUIRE_OPTION( build LIB ${lib_name} ON ) GBX_REQUIRE_VAR( build LIB ${lib_name} GBX_OS_LINUX "only Linux OS is supported" ) SET( dep_libs basicexample ) diff -Narup gearbox.old/src/gbxgarminacfr/driver.cpp gearbox/src/gbxgarminacfr/driver.cpp --- gearbox.old/src/gbxgarminacfr/driver.cpp 2008-07-25 14:15:07.000000000 +0200 +++ gearbox/src/gbxgarminacfr/driver.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -344,8 +344,8 @@ Driver::read() nmeaExceptionCount = 0; // debug - if ( nmeaFailChecksumCount>0 ) - cout<0 ) +// cout< data; // Read a few times - const int numReads = 30; + const int numReads = 30 + 10000000; for ( int i=0; i < numReads; i++ ) { try @@ -94,25 +101,31 @@ int main( int argc, char **argv ) case gbxgarminacfr::GpGga : { gbxgarminacfr::GgaData* d = (gbxgarminacfr::GgaData*)data.get(); - cout<<"GPGGA:"< #include #include #include @@ -259,25 +260,21 @@ OceanServerParser::parse( vector if (tracer_.verbosity( gbxutilacfr::Tracer::DebugTrace, gbxutilacfr::Tracer::ToAny ) >= debugLevel) { stringstream ss; - ss << "OceanServerParser: Received the following input: " << endl; for (unsigned int i=0; i for (unsigned int i=0; i checksumList = gbxutilacfr::tokenise( line, "%" ); - if (checksumList.size()==2) - { + string filteredString = filteredStream.str(); + + // divide the filteredString into 2 parts: data and checksum (if present) + vector checksumList = gbxutilacfr::tokenise( filteredString, "%" ); + if ( checksumList.size()==2 ) + { // we have a checksum, is it correct? if (!isChecksumValid( checksumList[0], checksumList[1] ) ) throw ParsingException( ERROR_INFO, "Checksum failed!" ); @@ -310,6 +317,7 @@ OceanServerParser::parse( vector vector fields = gbxutilacfr::tokenise( checksumList[0], "," ); parseFields( fields, batterySystem ); } + } } diff -Narup gearbox.old/src/gbxsmartbatteryacfr/smartbatteryacfr.dox gearbox/src/gbxsmartbatteryacfr/smartbatteryacfr.dox --- gearbox.old/src/gbxsmartbatteryacfr/smartbatteryacfr.dox 2008-07-25 14:15:11.000000000 +0200 +++ gearbox/src/gbxsmartbatteryacfr/smartbatteryacfr.dox 2008-09-24 18:10:21.000000000 +0200 @@ -27,7 +27,7 @@ For a full list of classes and functions @endverbatim @par Examples -- See 'test/test.cpp' for a simple example of how to use the library. The test makes use of the 'oceanserver' class to read a few records from the oceanserver system and prints the results on the screen. +- See 'test/shorttest.cpp' for a simple example of how to use the library. The test makes use of the 'oceanserver' class to read a few records from the oceanserver system and prints the results on the screen. @par Style See http://orca-robotics.sourceforge.net/orca/orca_doc_style.html diff -Narup gearbox.old/src/gbxsmartbatteryacfr/test/CMakeLists.txt gearbox/src/gbxsmartbatteryacfr/test/CMakeLists.txt --- gearbox.old/src/gbxsmartbatteryacfr/test/CMakeLists.txt 2008-07-25 14:15:10.000000000 +0200 +++ gearbox/src/gbxsmartbatteryacfr/test/CMakeLists.txt 2008-09-24 18:10:21.000000000 +0200 @@ -1,9 +1,12 @@ INCLUDE( ${GBX_CMAKE_DIR}/UseBasicRules.cmake ) -GBX_ADD_EXECUTABLE( gbxsmartbatteryacfrtest test.cpp ) -TARGET_LINK_LIBRARIES( gbxsmartbatteryacfrtest GbxSmartBatteryAcfr ) +GBX_ADD_EXECUTABLE( gbxsmartbatteryshorttest shorttest.cpp ) +TARGET_LINK_LIBRARIES( gbxsmartbatteryshorttest GbxSmartBatteryAcfr ) -GBX_ADD_EXAMPLE( gbxsmartbatteryacfrtest example.cmake.in example.cmake test.cpp example.readme ) +GBX_ADD_EXECUTABLE( gbxsmartbatterylongtest longtest.cpp ) +TARGET_LINK_LIBRARIES( gbxsmartbatterylongtest GbxSmartBatteryAcfr ) + +GBX_ADD_EXAMPLE( gbxsmartbatteryshorttest example.cmake.in example.cmake shorttest.cpp example.readme ) IF( GBX_BUILD_TESTS ) ADD_SUBDIRECTORY( darttest ) diff -Narup gearbox.old/src/gbxsmartbatteryacfr/test/example.readme gearbox/src/gbxsmartbatteryacfr/test/example.readme --- gearbox.old/src/gbxsmartbatteryacfr/test/example.readme 2008-07-25 14:15:10.000000000 +0200 +++ gearbox/src/gbxsmartbatteryacfr/test/example.readme 2008-09-24 18:10:21.000000000 +0200 @@ -12,6 +12,6 @@ $ cd gbxsmartbatteryacfr_example $ ccmake /usr/local/share/gearbox/gbxsmartbatteryacfr (press 'c' and 'g') $ make -$ ./gbxsmartbatteryacfrtest +$ ./gbxsmartbatteryshorttest See the library documentation (smartbatteryacfr.dox) for a description of the test. diff -Narup gearbox.old/src/gbxsmartbatteryacfr/test/longtest.cpp gearbox/src/gbxsmartbatteryacfr/test/longtest.cpp --- gearbox.old/src/gbxsmartbatteryacfr/test/longtest.cpp 1970-01-01 01:00:00.000000000 +0100 +++ gearbox/src/gbxsmartbatteryacfr/test/longtest.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -0,0 +1,72 @@ +#include +#include +#include + +using namespace std; + +int main( int argc, char **argv ) +{ + int opt; + std::string port = "/dev/ttyS0"; + bool debug = false; + + // Get some options from the command line + while ((opt = getopt(argc, argv, "p:v")) != -1) + { + switch ( opt ) + { + case 'p': + port = optarg; + break; + case 'v': + debug = true; + break; + default: + cout << "Usage: " << argv[0] << " [-p port] [-v(erbose)]" << endl + << "-p port\tPort the oceanserver battery system is connected to. E.g. /dev/ttyS0" << endl; + return 1; + } + } + + int numRecords = 0; + gbxutilacfr::TrivialTracer tracer( debug ); + + try + { + gbxsmartbatteryacfr::OceanServer oceanserver( port, tracer ); + + while (true) + { + gbxsmartbatteryacfr::OceanServerSystem data = oceanserver.getData(); + + cout << "TRACE(test): Reading record " << numRecords << endl; + numRecords++; + } + } + catch ( gbxsmartbatteryacfr::HardwareReadingException &e ) + { + cout << "ERROR(test): Caught a hardware reading exception: " + << e.what() << endl + << "This shouldn't happen!" << endl; + return 1; + } + catch ( gbxutilacfr::Exception &e ) + { + cout << "ERROR(test): Caught a gbxutilacfr::Exception: " + << e.what() << endl + << "This shouldn't happen!" << endl; + return 1; + } + catch ( std::exception &e ) + { + cout << "ERROR(test): Caught an unknown exception: " + << e.what() << endl + << "This shouldn't happen!" << endl; + return 1; + } + + cout << "INFO(test): Successfully read " << numRecords << " records." << endl; + + return 0; +} + diff -Narup gearbox.old/src/gbxsmartbatteryacfr/test/shorttest.cpp gearbox/src/gbxsmartbatteryacfr/test/shorttest.cpp --- gearbox.old/src/gbxsmartbatteryacfr/test/shorttest.cpp 1970-01-01 01:00:00.000000000 +0100 +++ gearbox/src/gbxsmartbatteryacfr/test/shorttest.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -0,0 +1,75 @@ +#include +#include +#include + +using namespace std; + +int main( int argc, char **argv ) +{ + int opt; + std::string port = "/dev/ttyS0"; + bool debug = false; + + // Get some options from the command line + while ((opt = getopt(argc, argv, "p:v")) != -1) + { + switch ( opt ) + { + case 'p': + port = optarg; + break; + case 'v': + debug = true; + break; + default: + cout << "Usage: " << argv[0] << " [-p port] [-v(erbose)]" << endl + << "-p port\tPort the oceanserver battery system is connected to. E.g. /dev/ttyS0" << endl; + return 1; + } + } + + const unsigned int numRecords = 5; + cout << "INFO(test): The plan is to read " << numRecords << " records from the oceanserver system and display the results." << endl << endl; + + gbxutilacfr::TrivialTracer tracer( debug ); + + try + { + gbxsmartbatteryacfr::OceanServer oceanserver( port, tracer ); + + for (unsigned int i=0; i<=numRecords; i++) + { + gbxsmartbatteryacfr::OceanServerSystem data = oceanserver.getData(); + + cout << "TRACE(test): Reading record " << i << ": " << endl + << "=================================" << endl << endl + << gbxsmartbatteryacfr::toString( data ) << endl; + } + } + catch ( gbxsmartbatteryacfr::HardwareReadingException &e ) + { + cout << "ERROR(test): Caught a hardware reading exception: " + << e.what() << endl + << "This shouldn't happen!" << endl; + return 1; + } + catch ( gbxutilacfr::Exception &e ) + { + cout << "ERROR(test): Caught a gbxutilacfr::Exception: " + << e.what() << endl + << "This shouldn't happen!" << endl; + return 1; + } + catch ( std::exception &e ) + { + cout << "ERROR(test): Caught an unknown exception: " + << e.what() << endl + << "This shouldn't happen!" << endl; + return 1; + } + + cout << "INFO(test): Successfully read " << numRecords << " records." << endl; + + return 0; +} + diff -Narup gearbox.old/src/gbxsmartbatteryacfr/test/test.cpp gearbox/src/gbxsmartbatteryacfr/test/test.cpp --- gearbox.old/src/gbxsmartbatteryacfr/test/test.cpp 2008-07-25 14:15:10.000000000 +0200 +++ gearbox/src/gbxsmartbatteryacfr/test/test.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,75 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main( int argc, char **argv ) -{ - int opt; - std::string port = "/dev/ttyS0"; - bool debug = false; - - // Get some options from the command line - while ((opt = getopt(argc, argv, "p:")) != -1) - { - switch ( opt ) - { - case 'p': - port = optarg; - break; - case 'v': - debug = true; - break; - default: - cout << "Usage: " << argv[0] << " [-p port] [-v(erbose)]" << endl - << "-p port\tPort the oceanserver battery system is connected to. E.g. /dev/ttyS0" << endl; - return 1; - } - } - - const unsigned int numRecords = 5; - cout << "INFO(test): The plan is to read " << numRecords << " records from the oceanserver system and display the results." << endl << endl; - - gbxutilacfr::TrivialTracer tracer( debug ); - - try - { - gbxsmartbatteryacfr::OceanServer oceanserver( port, tracer ); - - for (unsigned int i=0; i<=numRecords; i++) - { - gbxsmartbatteryacfr::OceanServerSystem data = oceanserver.getData(); - - cout << "TRACE(test): Reading record " << i << ": " << endl - << "=================================" << endl << endl - << gbxsmartbatteryacfr::toString( data ) << endl; - } - } - catch ( gbxsmartbatteryacfr::HardwareReadingException &e ) - { - cout << "ERROR(test): Caught a hardware reading exception: " - << e.what() << endl - << "This shouldn't happen!" << endl; - return 1; - } - catch ( gbxutilacfr::Exception &e ) - { - cout << "ERROR(test): Caught a gbxutilacfr::Exception: " - << e.what() << endl - << "This shouldn't happen!" << endl; - return 1; - } - catch ( std::exception &e ) - { - cout << "ERROR(test): Caught an unknown exception: " - << e.what() << endl - << "This shouldn't happen!" << endl; - return 1; - } - - cout << "INFO(test): Successfully read " << numRecords << " records." << endl; - - return 0; -} - diff -Narup gearbox.old/src/gbxutilacfr/mathdefs.h gearbox/src/gbxutilacfr/mathdefs.h --- gearbox.old/src/gbxutilacfr/mathdefs.h 2008-07-25 14:15:08.000000000 +0200 +++ gearbox/src/gbxutilacfr/mathdefs.h 2008-09-24 18:10:21.000000000 +0200 @@ -130,17 +130,10 @@ inline void NORMALISE_ANGLE( float &thet //dox For example, ROUND_TO(8,5) and ROUND_TO(12,5) will both result in 10. #define ROUND_TO(n,d) (d*rint(n/d)) #endif -//#ifndef SQR -//#define SQR(x) ((x)*(x)) -//#endif #ifndef SIGN //dox Sign of a number. #define SIGN(A) ((A)<0?(-1):(1)) #endif -#ifndef HYPOTENEUSE -//dox Finds hypoeneuse -#define HYPOTENEUSE(a,b) (sqrt(SQR(a)+SQR(b))) -#endif #ifndef COS_LAW //dox Law of cosines. #define COS_LAW(side1, side2, theta) \ diff -Narup gearbox.old/src/hokuyo_aist/CMakeLists.txt gearbox/src/hokuyo_aist/CMakeLists.txt --- gearbox.old/src/hokuyo_aist/CMakeLists.txt 2008-07-25 14:15:11.000000000 +0200 +++ gearbox/src/hokuyo_aist/CMakeLists.txt 2008-09-24 18:10:21.000000000 +0200 @@ -26,4 +26,9 @@ IF (build) IF (GBX_BUILD_TESTS) ADD_SUBDIRECTORY (test) ENDIF (GBX_BUILD_TESTS) -ENDIF( build ) + + OPTION (HOKUYO_AIST_BUILD_BINDINGS "Build the Python bindings for Hokuyo_aist" ON) + IF (HOKUYO_AIST_BUILD_BINDINGS) + ADD_SUBDIRECTORY (python) + ENDIF (HOKUYO_AIST_BUILD_BINDINGS) +ENDIF (build) diff -Narup gearbox.old/src/hokuyo_aist/hokuyo_aist.cpp gearbox/src/hokuyo_aist/hokuyo_aist.cpp --- gearbox.old/src/hokuyo_aist/hokuyo_aist.cpp 2008-07-25 14:15:11.000000000 +0200 +++ gearbox/src/hokuyo_aist/hokuyo_aist.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -566,10 +566,14 @@ HokuyoData::HokuyoData (uint32_t *ranges } else { - if ((_ranges = new uint32_t[_length]) == NULL) + try + { + _ranges = new uint32_t[_length]; + } + catch (std::bad_alloc &e) { _length = 0; - throw HokuyoError (HOKUYO_ERR_MEMORY, "Failed to allocate space to copy range data."); + throw; } memcpy (_ranges, ranges, sizeof (uint32_t) * _length); @@ -589,18 +593,18 @@ HokuyoData::HokuyoData (uint32_t *ranges } else { - if ((_ranges = new uint32_t[_length]) == NULL) + try + { + _ranges = new uint32_t[_length]; + } + catch (std::bad_alloc &e) { _length = 0; - throw HokuyoError (HOKUYO_ERR_MEMORY, "Failed to allocate space to copy range data."); + throw; } memcpy (_ranges, ranges, sizeof (uint32_t) * _length); - if ((_intensities = new uint32_t[_length]) == NULL) - { - throw HokuyoError (HOKUYO_ERR_MEMORY, - "Failed to allocate space to copy intensity data."); - } + _intensities = new uint32_t[_length]; memcpy (_intensities, intensities, sizeof (uint32_t) * _length); } } @@ -612,20 +616,20 @@ HokuyoData::HokuyoData (const HokuyoData _ranges = NULL; else { - if ((_ranges = new uint32_t[_length]) == NULL) + try + { + _ranges = new uint32_t[_length]; + } + catch (std::bad_alloc &e) { _length = 0; - throw HokuyoError (HOKUYO_ERR_MEMORY, "Failed to allocate space to copy data."); + throw; } memcpy (_ranges, rhs.Ranges (), sizeof (uint32_t) * _length); if (rhs.Intensities () != NULL) { - if ((_intensities = new uint32_t[_length]) == NULL) - { - throw HokuyoError (HOKUYO_ERR_MEMORY, - "Failed to allocate space to copy intensity data."); - } + _intensities = new uint32_t[_length]; memcpy (_intensities, rhs.Intensities (), sizeof (uint32_t) * _length); } } @@ -739,11 +743,7 @@ HokuyoData& HokuyoData::operator= (const { // Copy the data into a temporary variable pointing to new space (prevents dangling // pointers on allocation error and prevents self-assignment making a mess). - if ((newData = new uint32_t[rhsLength]) == NULL) - { - throw HokuyoError (HOKUYO_ERR_MEMORY, - "Failed to allocate space to copy range data."); - } + newData = new uint32_t[rhsLength]; memcpy (newData, rhs.Ranges (), sizeof (uint32_t) * rhsLength); if (_ranges != NULL) delete[] _ranges; @@ -752,14 +752,17 @@ HokuyoData& HokuyoData::operator= (const if (rhs.Intensities () != NULL) { - if ((newData = new uint32_t[rhsLength]) == NULL) + try + { + newData = new uint32_t[rhsLength]; + } + catch (std::bad_alloc &e) { // We have to remove any old intensity data or the length won't match if (_intensities != NULL) delete[] _intensities; _intensities = NULL; - throw HokuyoError (HOKUYO_ERR_MEMORY, - "Failed to allocate space to copy intensity data."); + throw; } memcpy (newData, rhs.Intensities (), sizeof (uint32_t) * rhsLength); if (_intensities != NULL) @@ -837,10 +840,14 @@ void HokuyoData::AllocateData (unsigned // If no data yet, allocate new if (_ranges == NULL) { - if ((_ranges = new uint32_t[length]) == NULL) + try + { + _ranges = new uint32_t[length]; + } + catch (std::bad_alloc &e) { _length = 0; - throw HokuyoError (HOKUYO_ERR_MEMORY, "Failed to allocate space for range data."); + throw; } _length = length; } @@ -848,10 +855,14 @@ void HokuyoData::AllocateData (unsigned else if (length != _length) { delete[] _ranges; - if ((_ranges = new uint32_t[length]) == NULL) + try + { + _ranges = new uint32_t[length]; + } + catch (std::bad_alloc &e) { _length = 0; - throw HokuyoError (HOKUYO_ERR_MEMORY, "Failed to allocate space for range data."); + throw; } _length = length; } @@ -862,21 +873,13 @@ void HokuyoData::AllocateData (unsigned // If no data yet, allocate new if (_intensities == NULL) { - if ((_intensities = new uint32_t[length]) == NULL) - { - throw HokuyoError (HOKUYO_ERR_MEMORY, - "Failed to allocate space for intensity data."); - } + _intensities = new uint32_t[length]; } // If there is data, reallocate only if the length is different else if (length != _length) { delete[] _intensities; - if ((_intensities = new uint32_t[length]) == NULL) - { - throw HokuyoError (HOKUYO_ERR_MEMORY, - "Failed to allocate space for intensity data."); - } + _intensities = new uint32_t[length]; } // Else data is already allocated to the right length, so do nothing } @@ -1162,7 +1165,7 @@ void HokuyoLaser::GetSensorInfo (HokuyoS info->serial = &buffer[5]; // Get either the status line or the end of message ReadLine (buffer); - if (buffer[0] != '\n') + if (buffer[0] != '\0') { // Got a status line info->sensorDiagnostic = &buffer[5]; @@ -1188,7 +1191,7 @@ void HokuyoLaser::GetSensorInfo (HokuyoS } // Now put it through sscanf and hope... int aperture; - int numFound = sscanf (valueStart, "%d-%d[mm],%d[deg],%d-%d[step],%d[rpm]", + int numFound = sscanf (valueStart, "(%d-%d[mm],%d[deg],%d-%d[step],%d[rpm]", &info->minRange, &info->maxRange, &aperture, &info->firstStep, &info->lastStep, &info->speed); if (numFound != 6) @@ -1198,19 +1201,28 @@ void HokuyoLaser::GetSensorInfo (HokuyoS info->CalculateValues (); if (_verbose) { - cerr << "Retrieved sensor info (hard-coded):" << endl; + cerr << "Retrieved sensor info (hard-coded, not enough values):" << endl; cerr << info->AsString (); } } + else + { + // Need to calculate stuff differently since it gave us an aperture value + info->resolution = DTOR (static_cast (aperture)) / + static_cast (info->lastStep - info->firstStep); + // Assume that the range is evenly spread + info->scanableSteps = info->lastStep - info->firstStep + 1; + info->frontStep = info->scanableSteps / 2 + info->firstStep - 1; + info->minAngle = (static_cast (info->firstStep) - + static_cast (info->frontStep)) * info->resolution; + info->maxAngle = (info->lastStep - info->frontStep) * info->resolution; - // Need to calculate stuff differently since it gave us an aperture value - info->resolution = static_cast (aperture) / - static_cast (info->lastStep - info->firstStep); - // Assume that the range is evenly spread - info->scanableSteps = info->lastStep - info->firstStep + 1; - info->frontStep = info->scanableSteps / 2; - info->minAngle = (info->firstStep - info->frontStep) * info->resolution; - info->maxAngle = (info->lastStep - info->frontStep) * info->resolution; + if (_verbose) + { + cerr << "Retrieved sensor info (from FIRM line):" << endl; + cerr << info->AsString (); + } + } } else { @@ -1431,7 +1443,7 @@ unsigned int HokuyoLaser::GetRanges (Hok return data->_length; } -unsigned int HokuyoLaser::GetRanges (HokuyoData *data, double startAngle, +unsigned int HokuyoLaser::GetRangesByAngle (HokuyoData *data, double startAngle, double endAngle, unsigned int clusterCount) { if (data == NULL) @@ -1497,7 +1509,7 @@ unsigned int HokuyoLaser::GetNewRanges ( // Mx commands will perform a scan, then send the data prefixed with another command echo // Read back the command echo (minimum of 3 bytes, maximum of 16 bytes) char response[17]; - SkipLines (1); // End of the command echo message + SkipLines (1); // End of the command echo message ReadLine (response, 16); // Size is command (2) + params (13) + new line (1) // Check the echo is correct if (response[0] != 'M' || response[1] != 'D') @@ -1546,7 +1558,7 @@ unsigned int HokuyoLaser::GetNewRanges ( return data->_length; } -unsigned int HokuyoLaser::GetNewRanges (HokuyoData *data, double startAngle, double endAngle, +unsigned int HokuyoLaser::GetNewRangesByAngle (HokuyoData *data, double startAngle, double endAngle, unsigned int clusterCount) { if (data == NULL) @@ -1618,7 +1630,7 @@ unsigned int HokuyoLaser::GetNewRangesAn // Mx commands will perform a scan, then send the data prefixed with another command echo // Read back the command echo (minimum of 3 bytes, maximum of 16 bytes) char response[17]; - SkipLines (1); // End of the command echo message + SkipLines (1); // End of the command echo message ReadLine (response, 16); // Size is command (2) + params (13) + new line (1) // Check the echo is correct if (response[0] != 'M' || response[1] != 'E') @@ -1667,7 +1679,7 @@ unsigned int HokuyoLaser::GetNewRangesAn return data->_length; } -unsigned int HokuyoLaser::GetNewRangesAndIntensities (HokuyoData *data, double startAngle, +unsigned int HokuyoLaser::GetNewRangesAndIntensitiesByAngle (HokuyoData *data, double startAngle, double endAngle, unsigned int clusterCount) { if (data == NULL) @@ -2038,7 +2050,7 @@ int HokuyoLaser::SendCommand (const char void HokuyoLaser::GetAndSetSCIPVersion (void) { bool scip1Failed = false; - + if (_verbose) cerr << "HokuyoLaser::" << __func__ << "() Testing SCIP protocol version." << endl; diff -Narup gearbox.old/src/hokuyo_aist/hokuyo_aist.h gearbox/src/hokuyo_aist/hokuyo_aist.h --- gearbox.old/src/hokuyo_aist/hokuyo_aist.h 2008-07-25 14:15:11.000000000 +0200 +++ gearbox/src/hokuyo_aist/hokuyo_aist.h 2008-09-24 18:10:21.000000000 +0200 @@ -252,7 +252,7 @@ class HOKUYO_AIST_EXPORT HokuyoData /// @brief Get the number of samples in the data. unsigned int Length (void) const { return _length; } /** @brief Indicates if one or more steps had an error. - + A step's value will be less than 20 if it had an error. Use @ref ErrorCodeToString to get a textual representation of the error. */ bool GetErrorStatus (void) const { return _error; } @@ -273,7 +273,7 @@ class HOKUYO_AIST_EXPORT HokuyoData /// @brief Force the data to clean up. void CleanUp (void); - private: + protected: uint32_t *_ranges; uint32_t *_intensities; unsigned int _length; @@ -330,7 +330,7 @@ class HOKUYO_AIST_EXPORT HokuyoLaser (startup) value. Values between 1 and 10 specify a ratio of the default speed. The speeds in revolutions per minute that these correspond to will depend on the scanner model. For example, for a URG-04LX, they are (from 1 to 10) 594, 588, 576, 570, 564, 558, 552, 546, and - 540 rpm. + 540 rpm. Not available with the SCIP v1 protocol. */ void SetMotorSpeed (unsigned int speed); @@ -381,7 +381,7 @@ class HOKUYO_AIST_EXPORT HokuyoLaser @param clusterCount The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. @return The number of range readings read into @ref data. */ - unsigned int GetRanges (HokuyoData *data, double startAngle, double endAngle, + unsigned int GetRangesByAngle (HokuyoData *data, double startAngle, double endAngle, unsigned int clusterCount = 1); /** @brief Get a new scan from the scanner. @@ -390,7 +390,7 @@ class HOKUYO_AIST_EXPORT HokuyoLaser will request a new scan. This means it will wait while the scanner performs the scan, which means the rate at which scans can be retrieved using this function is less than with @ref GetRanges. Otherwise behaves identicallty to @ref GetRanges. - + Not available with the SCIP v1 protocol. @note The command used to retrieve a fresh scan is also used for the continuous scanning @@ -420,7 +420,7 @@ class HOKUYO_AIST_EXPORT HokuyoLaser @param clusterCount The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. @return The number of range readings read into @ref data. */ - unsigned int GetNewRanges (HokuyoData *data, double startAngle, double endAngle, + unsigned int GetNewRangesByAngle (HokuyoData *data, double startAngle, double endAngle, unsigned int clusterCount = 1); /** @brief Get a new scan from the scanner with intensity data. @@ -458,7 +458,7 @@ class HOKUYO_AIST_EXPORT HokuyoLaser @param clusterCount The number of readings to cluster together into a single reading. The minimum value from a cluster is returned as the range for that cluster. @return The number of range readings read into @ref data. */ - unsigned int GetNewRangesAndIntensities (HokuyoData *data, double startAngle, + unsigned int GetNewRangesAndIntensitiesByAngle (HokuyoData *data, double startAngle, double endAngle, unsigned int clusterCount = 1); /// @brief Return the major version of the SCIP protocol in use. diff -Narup gearbox.old/src/hokuyo_aist/python/CMakeLists.txt gearbox/src/hokuyo_aist/python/CMakeLists.txt --- gearbox.old/src/hokuyo_aist/python/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100 +++ gearbox/src/hokuyo_aist/python/CMakeLists.txt 2008-09-24 18:10:21.000000000 +0200 @@ -0,0 +1,67 @@ +# Find the Python libraries and headers +FIND_PACKAGE (PythonLibs) +IF (NOT PYTHON_LIBRARIES) + MESSAGE (STATUS "Python libaries not found. Cannot build Python bindings for Hokuyo_aist.") +ENDIF (NOT PYTHON_LIBRARIES) + +# Find Boost::Python +# There is a new, much better, FindBoost.cmake in 2.6 +IF (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6) + OPTION (Boost_USE_STATIC_LIBS "Use the static versions of the Boost libraries" OFF) + MARK_AS_ADVANCED (Boost_USE_STATIC_LIBS) + + SET (BOOST_COMPONENTS python) + FIND_PACKAGE (Boost COMPONENTS ${BOOST_COMPONENTS}) + IF (Boost_FOUND) + INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIR}) + LINK_DIRECTORIES (${Boost_LIBRARY_DIRS}) + + IF (Boost_PYTHON_FOUND) + GET_FILENAME_COMPONENT (boostPythonLib ${Boost_PYTHON_LIBRARY} NAME_WE CACHE) + # Chop off the lib at the front, too, if present + STRING (REGEX REPLACE "^lib" "" boostPythonLib ${boostPythonLib}) + MESSAGE (STATUS + "PlayerC++ client library will be built with Boost::Thread support.") + ELSE (Boost_PYTHON_FOUND) + MESSAGE (STATUS + "Boost::Python library was not found. Cannot build Python bindings for Hokuyo_aist.") + ENDIF (Boost_PYTHON_FOUND) + ELSE (Boost_FOUND) + MESSAGE (STATUS + "Boost libraries were not found. Cannot build Python bindings for Hokuyo_aist.") + ENDIF (Boost_FOUND) +ELSE (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6) + FIND_PACKAGE (Boost) + IF (Boost_FOUND) + # For 2.4, assume that if boost is found then boost::python is present + OPTION (Boost_USE_MULTITHREAD "Use the multithreaded versions of the Boost libraries" ON) + MARK_AS_ADVANCED (Boost_USE_MULTITHREAD) + IF (Boost_USE_MULTITHREAD) + SET (BOOST_LIB_SUFFIX "-mt" CACHE STRING "Boost library name suffix") + ELSE (Boost_USE_MULTITHREAD) + SET (BOOST_LIB_SUFFIX "" CACHE STRING "Boost library name suffix") + ENDIF (Boost_USE_MULTITHREAD) + MARK_AS_ADVANCED (BOOST_LIB_SUFFIX) + + SET (boostPythonLib boost_python${BOOST_LIB_SUFFIX}) + INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIRS}) + LINK_DIRECTORIES (${Boost_LIBRARY_DIRS}) + ELSE (Boost_FOUND) + MESSAGE (STATUS + "Boost libraries were not found. Cannot build Python bindings for Hokuyo_aist.") + ENDIF (Boost_FOUND) +ENDIF (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6) + +IF (PYTHON_LIBRARIES AND Boost_FOUND) + MESSAGE (STATUS "Hokuyo_aist Python bindings will be built.") + SET (srcs hokuyo_aist.cpp) + + SET (pyModuleTarget hokuyo_aist_py) + INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/hokuyo_aist ${PYTHON_INCLUDE_PATH}) + ADD_LIBRARY (${pyModuleTarget} MODULE ${srcs}) + TARGET_LINK_LIBRARIES (${pyModuleTarget} hokuyo_aist ${boostPythonLib} ${PYTHON_LIBRARIES}) + SET_TARGET_PROPERTIES (${pyModuleTarget} PROPERTIES PREFIX "" OUTPUT_NAME "hokuyo_aist") + INSTALL (TARGETS ${pyModuleTarget} LIBRARY DESTINATION lib/python/site-packages) + + ADD_SUBDIRECTORY (test) +ENDIF (PYTHON_LIBRARIES AND Boost_FOUND) \ Brak znaku nowej linii na końcu pliku diff -Narup gearbox.old/src/hokuyo_aist/python/hokuyo_aist.cpp gearbox/src/hokuyo_aist/python/hokuyo_aist.cpp --- gearbox.old/src/hokuyo_aist/python/hokuyo_aist.cpp 1970-01-01 01:00:00.000000000 +0100 +++ gearbox/src/hokuyo_aist/python/hokuyo_aist.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -0,0 +1,162 @@ +#include +using namespace hokuyo_aist; + +#include +#include + +#include + +class HokuyoErrorWrap : public HokuyoError, public boost::python::wrapper +{ + public: + HokuyoErrorWrap (unsigned int code, std::string desc) + : HokuyoError (code, desc) + {} + + unsigned int Code (void) const throw () + { + if (boost::python::override f = get_override ("Code")) + return f (); + return HokuyoError::Code (); + } + unsigned int DefaultCode (void) const throw () + { return HokuyoError::Code (); } + + const char* what (void) const throw () + { + if (boost::python::override f = get_override ("what")) + return f (); + return HokuyoError::what (); + } + const char* Defaultwhat (void) const throw () + { return HokuyoError::what (); } + + std::string AsString (void) const throw () + { + if (boost::python::override f = get_override ("AsString")) + return f (); + return HokuyoError::AsString (); + } + std::string DefaultAsString (void) const throw () + { return HokuyoError::AsString (); } +}; + +class HokuyoDataWrap : public HokuyoData, public boost::python::wrapper +{ + public: + HokuyoDataWrap (void) + : HokuyoData () + {} + HokuyoDataWrap (uint32_t *ranges, unsigned int length, bool error, unsigned int time) + : HokuyoData (ranges, length, error, time) + {} + HokuyoDataWrap (uint32_t *ranges, uint32_t *intensities, unsigned int length, bool error, + unsigned int time) + : HokuyoData (ranges, intensities, length, error, time) + {} + + uint32_t Range (unsigned int index) + { return _ranges[index]; } + uint32_t Intensity (unsigned int index) + { return _intensities[index]; } +}; + +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads1, GetRanges, 1, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads2, GetRangesByAngle, 3, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads3, GetNewRanges, 1, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads4, GetNewRangesByAngle, 3, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads5, GetNewRangesAndIntensities, 1, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads6, GetNewRangesAndIntensitiesByAngle, 3, 4) + +BOOST_PYTHON_MODULE (hokuyo_aist) +{ + using namespace boost::python; + + class_ ("HokuyoError", init ()) + .def ("Code", &HokuyoError::Code, &HokuyoErrorWrap::DefaultCode) + .def ("what", &HokuyoError::what, &HokuyoErrorWrap::Defaultwhat) + .def ("AsString", &HokuyoError::AsString, &HokuyoErrorWrap::DefaultAsString) + ; + + scope ().attr ("HOKUYO_ERR_READ") = HOKUYO_ERR_READ; + scope ().attr ("HOKUYO_ERR_WRITE") = HOKUYO_ERR_WRITE; + scope ().attr ("HOKUYO_ERR_PROTOCOL") = HOKUYO_ERR_PROTOCOL; + scope ().attr ("HOKUYO_ERR_CHANGEBAUD") = HOKUYO_ERR_CHANGEBAUD; + scope ().attr ("HOKUYO_ERR_CONNECT_FAILED") = HOKUYO_ERR_CONNECT_FAILED; + scope ().attr ("HOKUYO_ERR_CLOSE_FAILED") = HOKUYO_ERR_CLOSE_FAILED; + scope ().attr ("HOKUYO_ERR_NODESTINATION") = HOKUYO_ERR_NODESTINATION; + scope ().attr ("HOKUYO_ERR_BADFIRMWARE") = HOKUYO_ERR_BADFIRMWARE; + scope ().attr ("HOKUYO_ERR_SCIPVERSION") = HOKUYO_ERR_SCIPVERSION; + scope ().attr ("HOKUYO_ERR_MEMORY") = HOKUYO_ERR_MEMORY; + scope ().attr ("HOKUYO_ERR_UNSUPPORTED") = HOKUYO_ERR_UNSUPPORTED; + scope ().attr ("HOKUYO_ERR_BADARG") = HOKUYO_ERR_BADARG; + scope ().attr ("HOKUYO_ERR_NODATA") = HOKUYO_ERR_NODATA; + scope ().attr ("HOKUYO_ERR_NOTSERIAL") = HOKUYO_ERR_NOTSERIAL; + + // TODO: this causes an undefined symbol error when importing into Python +// class_ ("HokuyoSensorInfo") +// .def ("AsString", &HokuyoSensorInfo::AsString) +// .def_readonly ("vendor", &HokuyoSensorInfo::vendor) +// .def_readonly ("product", &HokuyoSensorInfo::product) +// .def_readonly ("firmware", &HokuyoSensorInfo::firmware) +// .def_readonly ("protocol", &HokuyoSensorInfo::protocol) +// .def_readonly ("serial", &HokuyoSensorInfo::serial) +// .def_readonly ("model", &HokuyoSensorInfo::model) +// .def_readonly ("minRange", &HokuyoSensorInfo::minRange) +// .def_readonly ("maxRange", &HokuyoSensorInfo::maxRange) +// .def_readonly ("steps", &HokuyoSensorInfo::steps) +// .def_readonly ("firstStep", &HokuyoSensorInfo::firstStep) +// .def_readonly ("lastStep", &HokuyoSensorInfo::lastStep) +// .def_readonly ("frontStep", &HokuyoSensorInfo::frontStep) +// .def_readonly ("standardSpeed", &HokuyoSensorInfo::standardSpeed) +// .def_readonly ("power", &HokuyoSensorInfo::power) +// .def_readonly ("speed", &HokuyoSensorInfo::speed) +// .def_readonly ("speedLevel", &HokuyoSensorInfo::speedLevel) +// .def_readonly ("measureState", &HokuyoSensorInfo::measureState) +// .def_readonly ("baud", &HokuyoSensorInfo::baud) +// .def_readonly ("time", &HokuyoSensorInfo::time) +// .def_readonly ("sensorDiagnostic", &HokuyoSensorInfo::sensorDiagnostic) +// .def_readonly ("minAngle", &HokuyoSensorInfo::minAngle) +// .def_readonly ("maxAngle", &HokuyoSensorInfo::maxAngle) +// .def_readonly ("resolution", &HokuyoSensorInfo::resolution) +// .def_readonly ("scanableSteps", &HokuyoSensorInfo::scanableSteps) +// ; + + class_ ("HokuyoData") + .def (init ()) + .def (init ()) + // TODO: write a wrapper function to copy the data into a python array, because this doesn't work +// .def ("Ranges", &HokuyoData::Ranges, return_value_policy (), with_custodian_and_ward_postcall<1, 0> ()) + .def ("Range", &HokuyoDataWrap::Range) + .def ("Intensity", &HokuyoDataWrap::Intensity) + .def ("Length", &HokuyoData::Length) + .def ("GetErrorStatus", &HokuyoData::GetErrorStatus) + .def ("ErrorCodeToString", &HokuyoData::ErrorCodeToString) + .def ("TimeStamp", &HokuyoData::TimeStamp) + .def ("AsString", &HokuyoData::AsString) + .def ("CleanUp", &HokuyoData::CleanUp) + ; + + class_ ("HokuyoLaser") + .def ("Open", &HokuyoLaser::Open) + .def ("Close", &HokuyoLaser::Close) + .def ("IsOpen", &HokuyoLaser::IsOpen) + .def ("SetPower", &HokuyoLaser::SetPower) + .def ("SetBaud", &HokuyoLaser::SetBaud) + .def ("Reset", &HokuyoLaser::Reset) + .def ("SetMotorSpeed", &HokuyoLaser::SetMotorSpeed) + .def ("SetHighSensitivity", &HokuyoLaser::SetHighSensitivity) + .def ("GetSensorInfo", &HokuyoLaser::GetSensorInfo) + .def ("GetTime", &HokuyoLaser::GetTime) + .def ("GetRanges", &HokuyoLaser::GetRanges, HokuyoLaserOverloads1 ()) + .def ("GetRangesByAngle", &HokuyoLaser::GetRangesByAngle, HokuyoLaserOverloads2 ()) + .def ("GetNewRanges", &HokuyoLaser::GetNewRanges, HokuyoLaserOverloads3 ()) + .def ("GetNewRangesByAngle", &HokuyoLaser::GetNewRangesByAngle, HokuyoLaserOverloads4 ()) + .def ("GetNewRangesAndIntensities", &HokuyoLaser::GetNewRangesAndIntensities, HokuyoLaserOverloads5 ()) + .def ("GetNewRangesAndIntensitiesByAngle", &HokuyoLaser::GetNewRangesAndIntensitiesByAngle, HokuyoLaserOverloads6 ()) + .def ("SCIPVersion", &HokuyoLaser::SCIPVersion) + .def ("SetVerbose", &HokuyoLaser::SetVerbose) + .def ("StepToAngle", &HokuyoLaser::StepToAngle) + .def ("AngleToStep", &HokuyoLaser::AngleToStep) + ; +} diff -Narup gearbox.old/src/hokuyo_aist/python/test/CMakeLists.txt gearbox/src/hokuyo_aist/python/test/CMakeLists.txt --- gearbox.old/src/hokuyo_aist/python/test/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100 +++ gearbox/src/hokuyo_aist/python/test/CMakeLists.txt 2008-09-24 18:10:21.000000000 +0200 @@ -0,0 +1 @@ +INSTALL (FILES hokuyo_aist_example.py DESTINATION share/${PROJECT_NAME}/hokuyo_aist/example) diff -Narup gearbox.old/src/hokuyo_aist/python/test/hokuyo_aist_example.py gearbox/src/hokuyo_aist/python/test/hokuyo_aist_example.py --- gearbox.old/src/hokuyo_aist/python/test/hokuyo_aist_example.py 1970-01-01 01:00:00.000000000 +0100 +++ gearbox/src/hokuyo_aist/python/test/hokuyo_aist_example.py 2008-09-24 18:10:21.000000000 +0200 @@ -0,0 +1,91 @@ +#!/usr/bin/env python + +import hokuyo_aist +from optparse import OptionParser + +def main (): + parser = OptionParser () + parser.add_option ('-b', '--baud', dest = 'baudRate', type = 'int', default = '19200', + help = 'Baud rate to set the laser to *after* connecting [default: %default]') + parser.add_option ('-c', '--clustercount', dest = 'clusterCount', type = 'int', default = '1', + help = 'Cluster count [default: %default]') + parser.add_option ('-e', '--endangle', dest = 'endAngle', type = 'float', default = '0', + help = 'End angle to get ranges to [default: %default]') + parser.add_option ('-f', '--firststep', dest = 'firstStep', type = 'int', default = '-1', + help = 'First step to get ranges from [default: %default]') + parser.add_option ('-l', '--laststep', dest = 'lastStep', type = 'int', default = '-1', + help = 'Last step to get ranges to [default: %default]') + parser.add_option ('-m', '--motorspeed', dest = 'motorSpeed', type = 'int', default = '0', + help = 'Motor speed stepping (higher is slower) [default: %default]') + parser.add_option ('-n', '--new', dest = 'getNew', action = 'store_true', default = 'False', + help = 'Get new ranges instead of latest ranges [default: %default]') + parser.add_option ('-o', '--portoptions', dest = 'portOptions', type = 'string', default = 'type=serial,device=/dev/ttyACM0,timeout=1', + help = 'Port options (see flexiport library) [default: %default]') + parser.add_option ('-s', '--startangle', dest = 'startAngle', type = 'float', default = '0', + help = 'Start angle to get ranges from [default: %default]') + parser.add_option ('-v', '--verbose', dest = 'verbose', action = 'store_true', default = 'False', + help = 'Put the hokuyo_aist library into verbose mode [default: %default]') + + # Scan command line arguments + options, args = parser.parse_args () + + try: + # Create an instance of a laser scanner object + laser = hokuyo_aist.HokuyoLaser () + if options.verbose == True: + # Set verbose mode so we see more information in stderr + laser.SetVerbose (True) + + # Open the laser + laser.Open (options.portOptions) + # Turn the laser on + laser.SetPower (True) + # Set the baud rate + try: + laser.SetBaud (options.baudRate) + except hokuyo_aist.HokuyoError, e: + print 'Failed to change baud rate: (' + str (e.Code ()) + ') ' + e.what () + # Set the motor speed + laser.SetMotorSpeed (options.motorSpeed) + + # Get some laser info + #print 'Laser sensor information:' + #info = hokuyo_aist.HokuyoSensorInfo info () + #laser.GetSensorInfo (info) + #print info.AsString () + + # Get range data + data = hokuyo_aist.HokuyoData () + if (options.firstStep == -1 and options.lastStep == -1) and \ + (options.startAngle == 0 and options.endAngle == 0): + # Get all ranges + if options.getNew == True: + laser.GetNewRanges (data, -1, -1, options.clusterCount) + else: + laser.GetRanges (data, -1, -1, options.clusterCount) + elif options.firstStep != -1 or options.lastStep != -1: + # Get by step + if options.getNew == True: + laser.GetNewRanges (data, options.firstStep, options.lastStep, options.clusterCount) + else: + laser.GetRanges (data, options.firstStep, options.lastStep, options.clusterCount) + else: + # Get by angle + if options.getNew == True: + laser.GetNewRangesByAngle (data, options.startAngle, options.endAngle, options.clusterCount) + else: + laser.GetRangesByAngle (data, options.startAngle, options.endAngle, options.clusterCount) + + print 'Laser range data:' + print data.AsString () + + # Close the laser + laser.Close () + + except hokuyo_aist.HokuyoError, e: + print 'Caught exception: (' + str (e.Code ()) + ') ' + e.what () + sys.exit (1) + + +if __name__ == '__main__': + main () diff -Narup gearbox.old/src/hokuyo_aist/test/example.cpp gearbox/src/hokuyo_aist/test/example.cpp --- gearbox.old/src/hokuyo_aist/test/example.cpp 2008-07-25 14:15:11.000000000 +0200 +++ gearbox/src/hokuyo_aist/test/example.cpp 2008-09-24 18:10:21.000000000 +0200 @@ -118,7 +118,14 @@ int main(int argc, char **argv) cerr << "Failed to change baud rate: (" << e.Code () << ") " << e.what () << endl; } // Set the motor speed - laser.SetMotorSpeed (speed); + try + { + laser.SetMotorSpeed (speed); + } + catch (hokuyo_aist::HokuyoError e) + { + cerr << "Failed to set motor speed: (" << e.Code () << ") " << e.what () << endl; + } // Get some laser info cout << "Laser sensor information:" << endl; @@ -137,7 +144,7 @@ int main(int argc, char **argv) else laser.GetRanges (&data, -1, -1, clusterCount); } - else if (firstStep != -1 && lastStep != -1) + else if (firstStep != -1 || lastStep != -1) { // Get by step if (getNew) @@ -149,9 +156,9 @@ int main(int argc, char **argv) { // Get by angle if (getNew) - laser.GetNewRanges (&data, startAngle, endAngle, clusterCount); + laser.GetNewRangesByAngle (&data, startAngle, endAngle, clusterCount); else - laser.GetRanges (&data, startAngle, endAngle, clusterCount); + laser.GetRangesByAngle (&data, startAngle, endAngle, clusterCount); } cout << "Laser range data:" << endl; diff -Narup gearbox.old/submitted/CMakeLists.txt gearbox/submitted/CMakeLists.txt --- gearbox.old/submitted/CMakeLists.txt 2008-07-25 14:15:03.000000000 +0200 +++ gearbox/submitted/CMakeLists.txt 2008-09-24 18:10:21.000000000 +0200 @@ -1,6 +1,6 @@ # Libraries submitted for consideration for inclusion in Gearbox. -OPTION ( GBX_BUILD_SUBMITTED "Build submitted libraries" OFF ) +OPTION ( GBX_BUILD_SUBMITTED "Build submitted libraries" ON ) MARK_AS_ADVANCED ( FORCE GBX_BUILD_SUBMITTED ) IF( GBX_BUILD_SUBMITTED )