|
From: <to...@us...> - 2008-06-26 04:55:23
|
Revision: 220
http://gearbox.svn.sourceforge.net/gearbox/?rev=220&view=rev
Author: tobasco
Date: 2008-06-25 21:55:29 -0700 (Wed, 25 Jun 2008)
Log Message:
-----------
more cleaning up
Modified Paths:
--------------
gearbox/trunk/submitted/gbxsmartbatteryacfr/exceptions.h
gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverparser.cpp
gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverparser.h
gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverreader.cpp
gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverreader.h
gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbattery.h
gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryacfr.dox
gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.cpp
gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.h
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/exceptions.h
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/exceptions.h 2008-06-26 04:51:03 UTC (rev 219)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/exceptions.h 2008-06-26 04:55:29 UTC (rev 220)
@@ -8,47 +8,27 @@
*
*/
-#ifndef GBX_SMARTBATTERY_ACFR_EXCEPTIONS_H
-#define GBX_SMARTBATTERY_ACFR_EXCEPTIONS_H
+#ifndef GBX_SMARTBATTERYACFR_EXCEPTIONS_H
+#define GBX_SMARTBATTERYACFR_EXCEPTIONS_H
-#include <exception>
-#include <string>
+#include <gbxutilacfr/exceptions.h>
namespace gbxsmartbatteryacfr {
-//!
-//! Exceptions for gbxsmartbatteryacfr
-//!
-class Exception : public std::exception
-{
-public:
-
- Exception(const char *message)
- : message_(message) {}
- Exception(const std::string &message)
- : message_(message) {}
-
- virtual ~Exception() throw() {}
-
- virtual const char* what() const throw() { return message_.c_str(); }
-
-protected:
-
- std::string message_;
-};
-
-class HardwareReadingException : public Exception
+//! Exception for hardware reading problems
+class HardwareReadingException : public gbxutilacfr::Exception
{
public:
- HardwareReadingException( const char * message )
- : Exception( message ) {}
+ HardwareReadingException( const char *file, const char *line, const char *message )
+ : Exception( file, line, message ) {}
};
-class ParsingException : public Exception
+//! Exception for parsing problems
+class ParsingException : public gbxutilacfr::Exception
{
public:
- ParsingException( const char * message )
- : Exception( message ) {}
+ ParsingException( const char *file, const char *line, const char *message )
+ : Exception( file, line, message ) {}
};
}
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverparser.cpp
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverparser.cpp 2008-06-26 04:51:03 UTC (rev 219)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverparser.cpp 2008-06-26 04:55:29 UTC (rev 220)
@@ -8,9 +8,7 @@
*
*/
-#include <iostream>
#include <sstream>
-
#include <gbxsmartbatteryacfr/exceptions.h>
#include <gbxsmartbatteryacfr/smartbatteryparsing.h>
@@ -148,11 +146,11 @@
if ( fromB.has( ManufacturerData ) ) toB.setManufacturerData ( fromB.manufacturerData () );
}
- // check if reaping needs to be done
+ // check if reaping needs to be done, if not return
if ( from.batteries().size() == to.batteries().size() )
return;
- // store batteries to be reaped in a vector
+ // store battery ids from batteries which need to be reaped in a vector
vector<int> reapingIds;
// go through all 'to' batteries and check if they are also in 'from'
@@ -162,12 +160,12 @@
BatIt itFrom = from.batteries().find( batId );
if ( itFrom == from.batteries().end() ) {
- // battery is in 'to' but not in 'from' -> needs to be deleted
+ // battery is in 'to' but not in 'from' -> needs to be reaped
reapingIds.push_back( batId );
}
}
- // erase batteries
+ // reap batteries
for (unsigned int i=0; i<reapingIds.size(); i++) {
to.eraseBattery( reapingIds[i] );
}
@@ -225,8 +223,8 @@
if ( it==batteries_.end() )
{
stringstream ss;
- ss << "ERROR(OceanServerParser.cpp): trying to read from non-existent battery " << batteryNumber;
- throw ParsingException( ss.str().c_str() );
+ ss << "Trying to read from non-existent battery " << batteryNumber;
+ throw ParsingException( ERROR_INFO, ss.str().c_str() );
}
return it->second;
}
@@ -269,8 +267,8 @@
else
{
stringstream ss;
- ss << "OceanServerParser: Unknown System key: " << it->first;
- throw ParsingException(ss.str().c_str());
+ ss << "Unknown System key: " << it->first;
+ throw ParsingException( ERROR_INFO, ss.str().c_str() );
}
}
}
@@ -315,8 +313,8 @@
else
{
stringstream ss;
- ss << "OceanServerParser: Unknown controller key: " << it->first;
- throw ParsingException(ss.str().c_str());
+ ss << "Unknown controller key: " << it->first;
+ throw ParsingException( ERROR_INFO, ss.str().c_str() );
}
}
@@ -407,8 +405,8 @@
bat.setManufacturerData( read16Flags( it->second ) ); break;
case NUM_SMARTBATTERY_FIELDS:
default:
- stringstream ss; ss << "OceanServerParser: Unknown Battery key: " << it->first;
- throw ParsingException( ss.str().c_str() );
+ stringstream ss; ss << "Unknown Battery key: " << it->first;
+ throw ParsingException( ERROR_INFO, ss.str().c_str() );
}
}
@@ -450,8 +448,8 @@
else
{
stringstream ss;
- ss << "OceanServerParser: Unknown message type: " << msgTypeKey;
- throw ParsingException(ss.str().c_str());
+ ss << "Unknown message type: " << msgTypeKey;
+ throw ParsingException( ERROR_INFO, ss.str().c_str() );
}
}
@@ -488,9 +486,8 @@
{
//
- // Uncomment for DEBUG information
+ // Debugging output
//
-
stringstream ss;
ss << "OceanServerParser: Received the following input: " << endl;
for (unsigned int i=0; i<stringList.size(); i++)
@@ -511,16 +508,20 @@
ss << endl;
tracer_.debug( ss.str(), 10 );
+ //
+ // Parsing
+ //
for (unsigned int i=0; i<stringList.size(); i++)
{
const string &line = stringList[i];
- // check for control characters in the line (sometimes they are accidently inserted)
- // don't check the last 2 characters: they're \0 and \n
+ // 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.
for (unsigned int k=0; k<line.size()-2; k++)
{
if ( iscntrl( line[k] ) )
- throw ParsingException("ERROR(oceanserverparser.cpp): Found a control character (binary) in the string!");
+ throw ParsingException( ERROR_INFO, "Found a control character (binary) in the string!" );
}
// divide the line into 2 parts: data and checksum (if present)
@@ -530,12 +531,12 @@
{
// we have a checksum, is it correct?
if (!isChecksumValid( checksumList[0], checksumList[1] ) )
- throw ParsingException("ERROR(oceanserverparser.cpp): Checksum failed!");
+ throw ParsingException( ERROR_INFO, "Checksum failed!" );
}
// divide the data into individual fields and parse
if (checksumList.size()==0)
- throw ParsingException("ERROR(oceanserverparser.cpp): String length is 0");
+ throw ParsingException( ERROR_INFO, "String length is 0" );
vector<string> fields;
splitIntoFields( checksumList[0], fields, ",");
parseFields( fields, batterySystem );
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverparser.h
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverparser.h 2008-06-26 04:51:03 UTC (rev 219)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverparser.h 2008-06-26 04:55:29 UTC (rev 220)
@@ -8,8 +8,8 @@
*
*/
-#ifndef OCEANSERVER_PARSER_H
-#define OCEANSERVER_PARSER_H
+#ifndef GBX_OCEANSERVER_PARSER_H
+#define GBX_OCEANSERVER_PARSER_H
#include <map>
#include <gbxutilacfr/tracer.h>
@@ -31,25 +31,25 @@
OceanServerSystem();
~OceanServerSystem() {};
- // read access to all batteries
+ //! Read access to all batteries
const std::map<int,SmartBattery>& batteries() const;
- // easy write access to single battery, instantiates a new one if it doesn't exist
+ //! Easy write access to single battery, instantiates a new one if it doesn't exist
SmartBattery& battery( unsigned int batteryNumber );
- // easy read access to single battery, battery must exist
+ //! Easy read access to single battery, battery must exist
const SmartBattery& battery( unsigned int batteryNumber ) const;
- // erase a battery
+ //! Erase a battery
void eraseBattery( unsigned int batteryNumber );
- // average battery values
+ //! Average battery values
int percentCharge;
int minToEmpty;
std::string messageToSystem;
- // values from the controller
- // each vector is always of size 8 because oceanserver system has 8 slots
+ //! Battery module states
+ //! Each vector is always of size 8 because oceanserver system has 8 slots
std::vector<bool> availableBatteries;
std::vector<bool> chargingStates;
std::vector<bool> supplyingPowerStates;
@@ -58,13 +58,15 @@
std::vector<bool> chargeInhibitedStates;
private:
+
+ // key: slot number, data: a single smart battery module
std::map<int,SmartBattery> batteries_;
};
-//! Puts all available data into a human-readable string
+//! Puts OceanServerSystem data into a human-readable string
std::string toString( const OceanServerSystem &system );
-//! Puts all available data into a machine-readable ASCII string
+//! Puts OceanServerSystem data into a machine-readable ASCII string
std::string toLogString( const OceanServerSystem &system );
//! Updates all fields in 'to' with data from 'from'. Also reapes batteries in 'to' if they are not in 'from'.
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverreader.cpp
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverreader.cpp 2008-06-26 04:51:03 UTC (rev 219)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverreader.cpp 2008-06-26 04:55:29 UTC (rev 220)
@@ -8,11 +8,8 @@
*
*/
-#include <iostream>
#include <sstream>
-
#include <gbxsmartbatteryacfr/exceptions.h>
-#include <gbxsmartbatteryacfr/oceanserverparser.h>
#include "oceanserverreader.h"
@@ -84,7 +81,7 @@
string serialData;
int ret = serial_.readLine( serialData );
if (ret<0) {
- throw HardwareReadingException("Connected to the wrong serial port. Timed out while trying to read a line.");
+ throw HardwareReadingException( ERROR_INFO, "Connected to the wrong serial port. Timed out while trying to read a line.");
}
if ( isOceanServerSystem(serialData.c_str()) ) {
tracer_.info( "Oceanserverreader.cpp: We are connected to an Oceanserver system. Good." );
@@ -94,7 +91,7 @@
ss.str(""); ss << "OceanServerReader: Trying to find out whether this is an oceanserver system. Attempt number " << numTries << "/" << maxTries << ".";
tracer_.info( ss.str() );
if (numTries>=maxTries) {
- throw HardwareReadingException("Connected to the wrong serial port. Didn't recognize any of the strings.");
+ throw HardwareReadingException( ERROR_INFO, "Connected to the wrong serial port. Didn't recognize any of the strings.");
}
}
}
@@ -119,7 +116,7 @@
if (numTries>=maxTries) {
stringstream ss;
ss << "Can't read data from serial port. Timed out and/or empty strings " << maxTries << " times in a row.";
- throw HardwareReadingException( ss.str().c_str() );
+ throw HardwareReadingException( ERROR_INFO, ss.str().c_str() );
}
}
}
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverreader.h
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverreader.h 2008-06-26 04:51:03 UTC (rev 219)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/oceanserverreader.h 2008-06-26 04:55:29 UTC (rev 220)
@@ -8,10 +8,9 @@
*
*/
-#ifndef OCEANSERVER_READER_H
-#define OCEANSERVER_READER_H
+#ifndef GBX_OCEANSERVER_READER_H
+#define GBX_OCEANSERVER_READER_H
-#include <string>
#include <gbxserialacfr/serial.h>
#include <gbxutilacfr/tracer.h>
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbattery.h
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbattery.h 2008-06-26 04:51:03 UTC (rev 219)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbattery.h 2008-06-26 04:55:29 UTC (rev 220)
@@ -8,8 +8,8 @@
*
*/
-#ifndef SMARTBATTERY_H
-#define SMARTBATTERY_H
+#ifndef GBX_SMARTBATTERY_H
+#define GBX_SMARTBATTERY_H
#include <vector>
#include <string>
@@ -18,7 +18,7 @@
namespace gbxsmartbatteryacfr {
//! Smart battery data specification
-//! Table of fields can be found at http://sbs-forum.org/specs/
+//! Specs can be found at http://sbs-forum.org/specs/
enum SmartBatteryDataField
{
ManufacturerAccess = 0,
@@ -60,7 +60,7 @@
//! Converts a string to a SmartBatteryDataField, returns NUM_SMARTBATTERY_FIELDS if string is not valid
SmartBatteryDataField stringToSmartField( const std::string &fieldStr );
-//! SmartBattery class holds all the data of a single smart battery
+//! SmartBattery class holds all the data of a single smart battery.
//! Since not all data is always present, access to data needs to be done as follows:
//! if (has(Temperature)) { myTemp = smartBattery.temperature(); }
class SmartBattery
@@ -211,10 +211,10 @@
};
-//! Prints the data the SmartBattery contains in a human-readable format
+//! Puts SmartBattery data into a human-readable string
std::string toString( const SmartBattery &b );
-//! Prints the data the SmartBattery contains in a machine-readable format (ASCII)
+//! Puts SmartBattery data into a machine-readable ASCII string
std::string toLogString( const SmartBattery &b );
}
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryacfr.dox
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryacfr.dox 2008-06-26 04:51:03 UTC (rev 219)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryacfr.dox 2008-06-26 04:55:29 UTC (rev 220)
@@ -15,11 +15,8 @@
@defgroup gbx_library_gbxsmartbatteryacfr GbxSmartBatteryAcfr
@brief A library to read data from a smart battery system
-This library provides a set of classes and functions to read data from a Smart Battery System (SBS). SBS is a specification for determining accurate battery readings.
+This library provides a set of classes and functions to read data from a Smart Battery System (SBS). SBS is a specification for determining accurate battery readings. The library also contains classes which are specialised to a battery system provided by OceanServer Technologies Inc.
-The library also contains classes which are specialised to a battery system provided by OceanServer Technologies Inc.
-
-
@par Header file
@verbatim
@@ -55,10 +52,11 @@
- The library is tailored to the OceanServer battery system.
- Has been tested with the following firmware: V2.10 (2007)
-@par OceanServer Battery Management Module Layout
+@par OceanServer Layout
-The battery number reported by the driver corresponds to the following connectors on the board:
+The battery number reported by the driver corresponds to the following connectors on the Battery Management Module board:
+@verbatim
Level 1 (lower level):
==================
| |
@@ -73,6 +71,7 @@
(J22) 8 | | 6 (J21)
(J17) 7 | | 5 (J12)
==================
+@endverbatim
Note that the lower level needs to be powered (at least one battery module needs to be plugged in) to be able to read from the serial port.
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.cpp
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.cpp 2008-06-26 04:51:03 UTC (rev 219)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.cpp 2008-06-26 04:55:29 UTC (rev 220)
@@ -8,7 +8,6 @@
*
*/
-#include <iostream>
#include <sstream>
#include <gbxsmartbatteryacfr/exceptions.h>
@@ -49,7 +48,7 @@
int readUnsignedInt16( const string &str )
{
if (str.size()!=4)
- throw ParsingException("ERROR(smartbatteryparsing.cpp): readUnsignedInt16 called with string size != 4");
+ throw ParsingException( ERROR_INFO, "readUnsignedInt16 called with string size != 4" );
return readUnsignedInt( str );
}
@@ -57,7 +56,7 @@
int readUnsignedInt8( const string &str )
{
if (str.size()!=2)
- throw ParsingException("ERROR(smartbatteryparsing.cpp): readUnsignedInt8 called with string size != 2");
+ throw ParsingException( ERROR_INFO, "readUnsignedInt8 called with string size != 2" );
return readUnsignedInt( str );
}
@@ -65,7 +64,7 @@
int16_t readSignedInt16( const string &str )
{
if (str.size()!=4)
- throw ParsingException("ERROR(smartbatteryparsing.cpp): readSignedInt16 called with string size != 4");
+ throw ParsingException( ERROR_INFO, "readSignedInt16 called with string size != 4" );
stringstream ss(str);
int value;
@@ -149,9 +148,8 @@
return readUnsignedInt16( str );
}
-bool
-isChecksumValid( const string &data,
- const string &expectedChecksumStr )
+bool isChecksumValid( const string &data,
+ const string &expectedChecksumStr )
{
int computedChecksum=0;
@@ -183,13 +181,13 @@
// make sure we have an equal number
if (fields.size()%2 != 0)
- throw ParsingException("ERROR(smartbatteryparsing.cpp): toKeyValuePairs: odd number of inputs");
+ throw ParsingException( ERROR_INFO, "toKeyValuePairs: odd number of inputs" );
unsigned int i=0;
while(true)
{
if (fields.size() <= i+1)
- throw ParsingException("ERROR(smartbatteryparsing.cpp): toKeyValuePairs: wrong number of inputs");
+ throw ParsingException( ERROR_INFO, "toKeyValuePairs: wrong number of inputs" );
pairs[fields[i]] = fields[i+1];
i=i+2;
if (fields.size()==i) break;
@@ -207,6 +205,7 @@
{
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiter, 0);
+
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiter, lastPos);
@@ -217,6 +216,7 @@
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiter, pos);
+
// Find next "non-delimiter"
pos = str.find_first_of(delimiter, lastPos);
}
@@ -227,7 +227,7 @@
vector<bool> &flags )
{
if (str.size()!=2)
- throw ParsingException("ERROR(smartbatteryparsing.cpp): readSingleByte called with string size != 2");
+ throw ParsingException( ERROR_INFO, "readSingleByte called with string size != 2" );
stringstream ss(str);
int allFlags;
Modified: gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.h
===================================================================
--- gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.h 2008-06-26 04:51:03 UTC (rev 219)
+++ gearbox/trunk/submitted/gbxsmartbatteryacfr/smartbatteryparsing.h 2008-06-26 04:55:29 UTC (rev 220)
@@ -8,10 +8,9 @@
*
*/
-#ifndef SMARTBATTERY_PARSING_H
-#define SMARTBATTERY_PARSING_H
+#ifndef GBX_SMARTBATTERY_PARSING_H
+#define GBX_SMARTBATTERY_PARSING_H
-#include <string>
#include <vector>
#include <map>
@@ -21,7 +20,7 @@
{
//!
-//! Functions to parse data using the smart battery data standard
+//! Functions to parse SmartBattery data
//! and some helper functions
//!
//! @author Tobias Kaupp
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|