|
From: <to...@us...> - 2008-07-02 03:17:49
|
Revision: 246
http://gearbox.svn.sourceforge.net/gearbox/?rev=246&view=rev
Author: tobasco
Date: 2008-07-01 20:17:57 -0700 (Tue, 01 Jul 2008)
Log Message:
-----------
Added wrapper class, down to a single example now
Modified Paths:
--------------
gearbox/trunk/submitted/gbxsmartbatteryacfr/gbxsmartbatteryacfr.h
gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryacfr.dox
gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.h
gearbox/trunk/submitted/gbxsmartbatteryacfr/test/CMakeLists.txt
gearbox/trunk/submitted/gbxsmartbatteryacfr/test/example.cmake.in
gearbox/trunk/submitted/gbxsmartbatteryacfr/test/example.readme
Added Paths:
-----------
gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserver.cpp
gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserver.h
gearbox/trunk/submitted/gbxsmartbatteryacfr/test/test.cpp
Removed Paths:
-------------
gearbox/trunk/submitted/gbxsmartbatteryacfr/test/fancytest.cpp
gearbox/trunk/submitted/gbxsmartbatteryacfr/test/simpletest.cpp
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/gbxsmartbatteryacfr.h
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/gbxsmartbatteryacfr.h 2008-07-02 00:06:06 UTC (rev 245)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/gbxsmartbatteryacfr.h 2008-07-02 03:17:57 UTC (rev 246)
@@ -11,6 +11,7 @@
#ifndef GBX_SMARTBATTERY_ACFR_H
#define GBX_SMARTBATTERY_ACFR_H
+#include <gbxsmartbatteryacfr/oceanserver.h>
#include <gbxsmartbatteryacfr/oceanserverparser.h>
#include <gbxsmartbatteryacfr/oceanserverreader.h>
#include <gbxsmartbatteryacfr/exceptions.h>
Added: gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserver.cpp
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserver.cpp (rev 0)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserver.cpp 2008-07-02 03:17:57 UTC (rev 246)
@@ -0,0 +1,49 @@
+/*
+ * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
+ * http://gearbox.sf.net/
+ * Copyright (c) 2004-2008 Tobias Kaupp
+ *
+ * This distribution is licensed to you under the terms described in
+ * the LICENSE file included in this distribution.
+ *
+ */
+
+#include <sstream>
+#include <gbxsmartbatteryacfr/exceptions.h>
+#include "oceanserver.h"
+
+namespace gbxsmartbatteryacfr {
+
+OceanServer::OceanServer( const std::string &port,
+ gbxutilacfr::Tracer &tracer)
+ : tracer_(tracer)
+{
+ reader_.reset(new gbxsmartbatteryacfr::OceanServerReader( port, tracer_ ));
+}
+
+void
+OceanServer::read()
+{
+ try
+ {
+ gbxsmartbatteryacfr::OceanServerSystem data;
+ reader_->read(data);
+ gbxsmartbatteryacfr::updateWithNewData( data, data_ );
+ }
+ catch ( gbxsmartbatteryacfr::ParsingException &e )
+ {
+ stringstream ss;
+ ss << "OceanServer: " << __func__ << ": Caught a parsing exception: "
+ << e.what() << endl
+ << "This can happen sometimes. Will continue regardless.";
+ tracer_.info( ss.str() );
+ }
+}
+
+const gbxsmartbatteryacfr::OceanServerSystem&
+OceanServer::getData() const
+{
+ return data_;
+}
+
+}
Added: gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserver.h
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserver.h (rev 0)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserver.h 2008-07-02 03:17:57 UTC (rev 246)
@@ -0,0 +1,55 @@
+/*
+ * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
+ * http://gearbox.sf.net/
+ * Copyright (c) 2004-2008 Tobias Kaupp
+ *
+ * This distribution is licensed to you under the terms described in
+ * the LICENSE file included in this distribution.
+ *
+ */
+
+#ifndef GBX_OCEANSERVER_H
+#define GBX_OCEANSERVER_H
+
+#include <memory>
+#include <gbxutilacfr/tracer.h>
+#include <gbxsmartbatteryacfr/oceanserverreader.h>
+
+using namespace std;
+
+namespace gbxsmartbatteryacfr {
+
+//! Class for reading data from an OceanServer battery system.
+//! Wraps up all the logic required to read from the system and
+//! maintain some incremental internal data storage.
+//! Also handles all ParsingExceptions.
+//!
+//! @author Tobias Kaupp
+//!
+class OceanServer
+{
+public:
+
+ OceanServer( const std::string &port,
+ gbxutilacfr::Tracer &tracer);
+
+ //! Reads data from OceanServer and incrementally updates internal storage
+ void read();
+
+ //! Returns a reference to the current (incrementally updated) OceanServer data
+ const gbxsmartbatteryacfr::OceanServerSystem& getData() const;
+
+private:
+
+ gbxsmartbatteryacfr::OceanServerSystem data_;
+ gbxutilacfr::Tracer& tracer_;
+ auto_ptr<gbxsmartbatteryacfr::OceanServerReader> reader_;
+
+};
+
+} //namespace
+
+#endif
+
+
+
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryacfr.dox
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryacfr.dox 2008-07-02 00:06:06 UTC (rev 245)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryacfr.dox 2008-07-02 03:17:57 UTC (rev 246)
@@ -26,8 +26,7 @@
@endverbatim
@par Examples
-- See 'test/simpletest.cpp' for a simple example of how to use the library. The test reads a few records from the oceanserver system and prints the results on the screen.
-- See 'test/fancytest.cpp' for a more advanced example. The test uses a class to read a few records from the oceanserver system and stores an internal (full) record which gets incrementally updated with new data.
+- 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.
@par Style
See http://orca-robotics.sourceforge.net/orca/orca_doc_style.html
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.h
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.h 2008-07-02 00:06:06 UTC (rev 245)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.h 2008-07-02 03:17:57 UTC (rev 246)
@@ -40,11 +40,11 @@
//! May throw ParsingException
int readNumBatteries( const std::string &str );
-//! Expects 4 hex characters, returns percentage
+//! Expects 4 hex characters, returns percentage [%]
//! May throw ParsingException
int readPercentWord( const std::string &str );
-//! Expects 2 hex characters, returns percentage
+//! Expects 2 hex characters, returns percentage [%]
//! May throw ParsingException
int readPercentByte( const std::string &str );
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/test/CMakeLists.txt
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/test/CMakeLists.txt 2008-07-02 00:06:06 UTC (rev 245)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/test/CMakeLists.txt 2008-07-02 03:17:57 UTC (rev 246)
@@ -1,13 +1,10 @@
INCLUDE( ${GBX_CMAKE_DIR}/UseBasicRules.cmake )
-GBX_ADD_EXECUTABLE( gbxsmartbatterysimpletest simpletest.cpp )
-TARGET_LINK_LIBRARIES( gbxsmartbatterysimpletest GbxSmartBatteryAcfr )
+GBX_ADD_EXECUTABLE( gbxsmartbatteryacfrtest test.cpp )
+TARGET_LINK_LIBRARIES( gbxsmartbatteryacfrtest GbxSmartBatteryAcfr )
-GBX_ADD_EXECUTABLE( gbxsmartbatteryfancytest fancytest.cpp )
-TARGET_LINK_LIBRARIES( gbxsmartbatteryfancytest GbxSmartBatteryAcfr )
+GBX_ADD_EXAMPLE( gbxsmartbatteryacfrtest example.cmake.in example.cmake test.cpp example.readme )
-GBX_ADD_EXAMPLE( gbxsmartbatteryacfr example.cmake.in example.cmake simpletest.cpp fancytest.cpp example.readme )
-
IF( GBX_BUILD_TESTS )
ADD_SUBDIRECTORY( darttest )
ENDIF( GBX_BUILD_TESTS )
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/test/example.cmake.in
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/test/example.cmake.in 2008-07-02 00:06:06 UTC (rev 245)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/test/example.cmake.in 2008-07-02 03:17:57 UTC (rev 246)
@@ -2,18 +2,11 @@
INCLUDE_DIRECTORIES( @CMAKE_INSTALL_PREFIX@/include/gearbox )
-ADD_EXECUTABLE( gbxsmartbatteryacfrsimple simpletest.cpp )
-TARGET_LINK_LIBRARIES( gbxsmartbatteryacfrsimple GbxSmartBatteryAcfr )
-SET_TARGET_PROPERTIES( gbxsmartbatteryacfrsimple PROPERTIES
+ADD_EXECUTABLE( gbxsmartbatteryacfrtest test.cpp )
+TARGET_LINK_LIBRARIES( gbxsmartbatteryacfrtest GbxSmartBatteryAcfr )
+SET_TARGET_PROPERTIES( gbxsmartbatteryacfrtest PROPERTIES
LINK_FLAGS "-L@CMAKE_INSTALL_PREFIX@/lib/gearbox"
INSTALL_RPATH "${INSTALL_RPATH};@CMAKE_INSTALL_PREFIX@/lib/gearbox"
BUILD_WITH_INSTALL_RPATH TRUE )
-
-ADD_EXECUTABLE( gbxsmartbatteryacfrfancy fancytest.cpp )
-TARGET_LINK_LIBRARIES( gbxsmartbatteryacfrfancy GbxSmartBatteryAcfr )
-SET_TARGET_PROPERTIES( gbxsmartbatteryacfrfancy PROPERTIES
- LINK_FLAGS "-L@CMAKE_INSTALL_PREFIX@/lib/gearbox"
- INSTALL_RPATH "${INSTALL_RPATH};@CMAKE_INSTALL_PREFIX@/lib/gearbox"
- BUILD_WITH_INSTALL_RPATH TRUE )
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/test/example.readme
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/test/example.readme 2008-07-02 00:06:06 UTC (rev 245)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/test/example.readme 2008-07-02 03:17:57 UTC (rev 246)
@@ -1,7 +1,7 @@
Building
--------
-The examples can be built by making a directory (anywhere on your system where
+The example can be built by making a directory (anywhere on your system where
you have write permissions will do), changing to that directory and executing
CMake with the example's source directory as an argument. For example, if you
have installed GearBox into /usr/local, you could do the following:
@@ -12,7 +12,6 @@
$ ccmake /usr/local/share/gearbox/gbxsmartbatteryacfr
(press 'c' and 'g')
$ make
-$ ./gbxsmartbatteryacfrsimple
-$ ./gbxsmartbatteryacfrfancy
+$ ./gbxsmartbatteryacfrtest
-See the library documentation (smartbatteryacfr.dox) for a description of the tests.
+See the library documentation (smartbatteryacfr.dox) for a description of the test.
Deleted: gearbox/trunk/submitted/gbxsmartbatteryacfr/test/fancytest.cpp
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/test/fancytest.cpp 2008-07-02 00:06:06 UTC (rev 245)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/test/fancytest.cpp 2008-07-02 03:17:57 UTC (rev 246)
@@ -1,115 +0,0 @@
-#include <iostream>
-#include <memory>
-#include <cstdlib>
-#include <gbxutilacfr/trivialtracer.h>
-#include <gbxsmartbatteryacfr/gbxsmartbatteryacfr.h>
-
-using namespace std;
-
-class MyClass
-{
-public:
- MyClass(const std::string &port, bool debug);
- ~MyClass() {};
- void read();
-private:
- gbxsmartbatteryacfr::OceanServerSystem data_;
- gbxutilacfr::TrivialTracer tracer_;
- auto_ptr<gbxsmartbatteryacfr::OceanServerReader> reader_;
-};
-
-MyClass::MyClass(const std::string &port, bool debug)
- : tracer_(debug)
-{
- try
- {
- reader_.reset(new gbxsmartbatteryacfr::OceanServerReader( port, tracer_ ));
- }
- catch ( gbxsmartbatteryacfr::HardwareReadingException &e )
- {
- cout << "ERROR(fancy_test): Caught a hardware reading exception when initialising reader: "
- << e.what() << endl;
- exit(1);
- }
-}
-
-void
-MyClass::read()
-{
- gbxsmartbatteryacfr::OceanServerSystem data;
- reader_->read(data);
- gbxsmartbatteryacfr::updateWithNewData( data, data_ );
-
- cout << "Current data:" << endl
- << "=============" << endl
- << gbxsmartbatteryacfr::toString( data ) << endl;
- cout << "Stored data:" << endl
- << "============" << endl
- << gbxsmartbatteryacfr::toString( data_ ) << endl;
-}
-
-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;
- MyClass myClass( port, debug );
-
- for (unsigned int i=0; i<=numRecords; i++)
- {
- cout << "TRACE(fancy_test): Reading record " << i << ": " << endl
- << "====================================" << endl << endl;
-
- try
- {
- myClass.read();
- }
- catch ( gbxsmartbatteryacfr::ParsingException &e )
- {
- cout << "INFO(fancy_test): Caught a parsing exception: "
- << e.what() << endl
- << "This can happen sometimes. Not a problem of the driver." << endl
- << "The higher level program which uses the driver has to deal with this situation." << endl;
- continue;
- }
- catch ( gbxsmartbatteryacfr::HardwareReadingException &e )
- {
- cout << "ERROR(fancy_test): Caught a hardware reading exception: "
- << e.what() << endl
- << "This shouldn't happen!" << endl;
- return 1;
- }
- catch(std::exception &e)
- {
- cout << "ERROR(fancy_test): Caught an unknown exception: "
- << e.what() << endl
- << "This shouldn't happen!" << endl;
- return 1;
- }
- } // end of for loop
-
- cout << "INFO(fancy_test): Successfully read " << numRecords << " records." << endl;
-
- return 0;
-}
-
Deleted: gearbox/trunk/submitted/gbxsmartbatteryacfr/test/simpletest.cpp
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/test/simpletest.cpp 2008-07-02 00:06:06 UTC (rev 245)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/test/simpletest.cpp 2008-07-02 03:17:57 UTC (rev 246)
@@ -1,93 +0,0 @@
-#include <iostream>
-#include <gbxutilacfr/trivialtracer.h>
-#include <gbxsmartbatteryacfr/gbxsmartbatteryacfr.h>
-
-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(simple_test): The plan is to read " << numRecords << " records from the oceanserver system and display the results." << endl << endl;
-
- // instantiate reader
- gbxutilacfr::TrivialTracer tracer( debug );
-
- gbxsmartbatteryacfr::OceanServerReader *reader;
-
- try
- {
- reader = new gbxsmartbatteryacfr::OceanServerReader( port, tracer );
- }
- catch ( gbxsmartbatteryacfr::HardwareReadingException &e )
- {
- cout << "ERROR(simple_test): Caught a hardware reading exception when initialising reader: "
- << e.what() << endl;
- return 1;
- }
-
- // data storage
- gbxsmartbatteryacfr::OceanServerSystem data;
-
- for (unsigned int i=0; i<=numRecords; i++)
- {
- try
- {
- reader->read( data );
- cout << "TRACE(simple_test): Reading record " << i << ": " << endl
- << "=====================================" << endl << endl
- << gbxsmartbatteryacfr::toString( data ) << endl;
- }
- catch ( gbxsmartbatteryacfr::ParsingException &e )
- {
- cout << "INFO(simple_test): Caught a parsing exception: "
- << e.what() << endl
- << "This can happen sometimes. Not a problem of the driver." << endl
- << "The higher level program which uses the driver has to deal with this situation." << endl;
- continue;
- }
- catch ( gbxsmartbatteryacfr::HardwareReadingException &e )
- {
- cout << "ERROR(simple_test): Caught a hardware reading exception: "
- << e.what() << endl
- << "This shouldn't happen!" << endl;
- delete reader;
- return 1;
- }
- catch(std::exception &e)
- {
- cout << "ERROR(simple_test): Caught an unknown exception: "
- << e.what() << endl
- << "This shouldn't happen!" << endl;
- delete reader;
- return 1;
- }
- } //end of for loop
-
-
- cout << "INFO(simple_test): Successfully read " << numRecords << " records." << endl;
-
- delete reader;
- return 0;
-}
Added: gearbox/trunk/submitted/gbxsmartbatteryacfr/test/test.cpp
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/test/test.cpp (rev 0)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/test/test.cpp 2008-07-02 03:17:57 UTC (rev 246)
@@ -0,0 +1,69 @@
+#include <iostream>
+#include <gbxutilacfr/trivialtracer.h>
+#include <gbxsmartbatteryacfr/gbxsmartbatteryacfr.h>
+
+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++)
+ {
+ oceanserver.read();
+ 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 ( 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;
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|