|
From: <to...@us...> - 2008-08-08 05:41:30
|
Revision: 302
http://gearbox.svn.sourceforge.net/gearbox/?rev=302&view=rev
Author: tobasco
Date: 2008-08-08 05:41:39 +0000 (Fri, 08 Aug 2008)
Log Message:
-----------
removing binary characters now
Modified Paths:
--------------
gearbox/trunk/src/gbxsmartbatteryacfr/oceanserverparser.cpp
gearbox/trunk/src/gbxsmartbatteryacfr/smartbatteryacfr.dox
gearbox/trunk/src/gbxsmartbatteryacfr/test/CMakeLists.txt
gearbox/trunk/src/gbxsmartbatteryacfr/test/example.readme
Added Paths:
-----------
gearbox/trunk/src/gbxsmartbatteryacfr/test/longtest.cpp
gearbox/trunk/src/gbxsmartbatteryacfr/test/shorttest.cpp
Removed Paths:
-------------
gearbox/trunk/src/gbxsmartbatteryacfr/test/test.cpp
Modified: gearbox/trunk/src/gbxsmartbatteryacfr/oceanserverparser.cpp
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/oceanserverparser.cpp 2008-08-08 02:51:04 UTC (rev 301)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/oceanserverparser.cpp 2008-08-08 05:41:39 UTC (rev 302)
@@ -8,6 +8,7 @@
*
*/
+#include <iostream>
#include <sstream>
#include <gbxutilacfr/tokenise.h>
#include <gbxsmartbatteryacfr/exceptions.h>
@@ -259,46 +260,53 @@
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<stringList.size(); i++)
{
const string &str = stringList[i];
- ss << i << ": " << str;
-
- // output in hex
- ss << i << " hex: ";
- for (unsigned k=0; k<str.size(); k++)
+ ss << "Line: " << str;
+ for (unsigned k=0; k<str.size()-2; k++)
{
unsigned int charValue = (unsigned int)str[k];
- ss << str[k] << ": " << std::hex << charValue << " ";
+ ss << "Character (str/hex): " << str[k] << "/" << std::hex << charValue << endl;
}
- ss << std::dec;
-
+ ss << std::dec << endl;
}
ss << endl;
tracer_.debug( ss.str(), debugLevel );
- }
+ }
+
//
// Parsing
//
for (unsigned int i=0; i<stringList.size(); i++)
{
const string &line = stringList[i];
-
- // Known problem with oceanserver system: sometimes \0 is inserted in the middle of the string.
- // To get around this, we check for 'control characters' in the string.
- // Don't check the last 2 characters of the string: they're \0 and \n.
+
+ stringstream filteredStream;
+ bool haveBinary = false;
+
for (unsigned int k=0; k<line.size()-2; k++)
- {
- if ( iscntrl( line[k] ) )
- throw ParsingException( ERROR_INFO, "Found a control character (binary) in the string!" );
+ {
+ // Sometimes we get binary characters in the string: either caused by dodgy serial ports
+ // or by the oceanserver controller. We need to remove those.
+ if ( !iscntrl( line[k] ) ) {
+ filteredStream << line[k];
+ haveBinary = true;
+ } else {
+ unsigned int charValue = (unsigned int)line[k];
+ stringstream ss;
+ ss << "Found a binary character in the following line: " << endl << line;
+ ss << "The character is: " << std::hex << charValue << ". Will remove it.";
+ tracer_.warning( ss.str() );
+ }
}
-
- // divide the line into 2 parts: data and checksum (if present)
- vector<string> checksumList = gbxutilacfr::tokenise( line, "%" );
- if (checksumList.size()==2)
- {
+ string filteredString = filteredStream.str();
+
+ // divide the filteredString into 2 parts: data and checksum (if present)
+ vector<string> checksumList = gbxutilacfr::tokenise( filteredString, "%" );
+ if ( (checksumList.size()==2) && (!haveBinary) )
+ {
// we have a checksum, is it correct?
if (!isChecksumValid( checksumList[0], checksumList[1] ) )
throw ParsingException( ERROR_INFO, "Checksum failed!" );
@@ -310,6 +318,7 @@
vector<string> fields = gbxutilacfr::tokenise( checksumList[0], "," );
parseFields( fields, batterySystem );
}
+
}
}
Modified: gearbox/trunk/src/gbxsmartbatteryacfr/smartbatteryacfr.dox
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/smartbatteryacfr.dox 2008-08-08 02:51:04 UTC (rev 301)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/smartbatteryacfr.dox 2008-08-08 05:41:39 UTC (rev 302)
@@ -27,7 +27,7 @@
@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
Modified: gearbox/trunk/src/gbxsmartbatteryacfr/test/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/test/CMakeLists.txt 2008-08-08 02:51:04 UTC (rev 301)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/test/CMakeLists.txt 2008-08-08 05:41:39 UTC (rev 302)
@@ -1,10 +1,13 @@
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 )
ENDIF( GBX_BUILD_TESTS )
Modified: gearbox/trunk/src/gbxsmartbatteryacfr/test/example.readme
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/test/example.readme 2008-08-08 02:51:04 UTC (rev 301)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/test/example.readme 2008-08-08 05:41:39 UTC (rev 302)
@@ -12,6 +12,6 @@
$ 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.
Added: gearbox/trunk/src/gbxsmartbatteryacfr/test/longtest.cpp
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/test/longtest.cpp (rev 0)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/test/longtest.cpp 2008-08-08 05:41:39 UTC (rev 302)
@@ -0,0 +1,72 @@
+#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: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;
+}
+
Copied: gearbox/trunk/src/gbxsmartbatteryacfr/test/shorttest.cpp (from rev 299, gearbox/trunk/src/gbxsmartbatteryacfr/test/test.cpp)
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/test/shorttest.cpp (rev 0)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/test/shorttest.cpp 2008-08-08 05:41:39 UTC (rev 302)
@@ -0,0 +1,75 @@
+#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: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;
+}
+
Property changes on: gearbox/trunk/src/gbxsmartbatteryacfr/test/shorttest.cpp
___________________________________________________________________
Added: svn:mergeinfo
+
Deleted: gearbox/trunk/src/gbxsmartbatteryacfr/test/test.cpp
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/test/test.cpp 2008-08-08 02:51:04 UTC (rev 301)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/test/test.cpp 2008-08-08 05:41:39 UTC (rev 302)
@@ -1,75 +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(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;
-}
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|