documentation for doxygen corrected.

This commit is contained in:
Roland Jax
2014-12-15 12:12:38 +01:00
parent b13e597602
commit 105f5e6e7d
8 changed files with 184 additions and 73 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ public:
/** /**
* @brief Create a log message for a received/sent raw data byte. * @brief Create a log message for a received/sent raw data byte.
* @param param byte the raw data byte. * @param byte the raw data byte.
* @param received true if the byte was received, false if it was sent. * @param received true if the byte was received, false if it was sent.
*/ */
static void logRaw(const unsigned char byte, bool received); static void logRaw(const unsigned char byte, bool received);
-2
View File
@@ -114,7 +114,6 @@ public:
/** /**
* @brief Constructor. * @brief Constructor.
* @param slave the slave data @a SymbolString received.
* @param message the associated @a Message. * @param message the associated @a Message.
*/ */
PollRequest(Message* message) PollRequest(Message* message)
@@ -156,7 +155,6 @@ public:
/** /**
* @brief Constructor. * @brief Constructor.
* @param slave the slave data @a SymbolString received.
* @param message the primary query @a Message. * @param message the primary query @a Message.
* @param messages the optional secondary query @a Message instances (to be queried only when the primary was successful). * @param messages the optional secondary query @a Message instances (to be queried only when the primary was successful).
* @param scanResults the map in which to store the formatted scan result by slave address. * @param scanResults the map in which to store the formatted scan result by slave address.
+82 -27
View File
@@ -32,6 +32,8 @@
using namespace std; using namespace std;
/** \file data.h */
/** the separator character used between multiple values (in CSV only). */ /** the separator character used between multiple values (in CSV only). */
#define VALUE_SEPARATOR ';' #define VALUE_SEPARATOR ';'
@@ -46,41 +48,41 @@ using namespace std;
/** the message part in which a data field is stored. */ /** the message part in which a data field is stored. */
enum PartType { enum PartType {
pt_any, // stored in any data (master or slave) pt_any, /*!< stored in any data (master or slave) */
pt_masterData, // stored in master data pt_masterData, /*!< stored in master data */
pt_slaveData, // stored in slave data pt_slaveData, /*!< stored in slave data */
}; };
/** the available base data types. */ /** the available base data types. */
enum BaseType { enum BaseType {
bt_str, // text string in a @a StringDataField bt_str, /*!< text string in a @a StringDataField */
bt_hexstr, // hex digit string in a @a StringDataField bt_hexstr, /*!< hex digit string in a @a StringDataField */
bt_dat, // date in a @a StringDataField bt_dat, /*!< date in a @a StringDataField */
bt_tim, // time in a @a StringDataField bt_tim, /*!< time in a @a StringDataField */
bt_num, // numeric value in a @a NumericDataField bt_num, /*!< numeric value in a @a NumericDataField */
}; };
/** flags for dataType_t. */ /** flags for dataType_t. */
const unsigned int ADJ = 0x01; // adjustable length, numBits is maximum length const unsigned int ADJ = 0x01; /*!< adjustable length, numBits is maximum length */
const unsigned int BCD = 0x02; // binary representation is BCD const unsigned int BCD = 0x02; /*!< binary representation is BCD */
const unsigned int REV = 0x04; // reverted binary representation (most significant byte first) const unsigned int REV = 0x04; /*!< reverted binary representation (most significant byte first) */
const unsigned int SIG = 0x08; // signed value const unsigned int SIG = 0x08; /*!< signed value */
const unsigned int LST = 0x10; // value list is possible (without applied divisor) const unsigned int LST = 0x10; /*!< value list is possible (without applied divisor) */
const unsigned int DAY = 0x20; // forced value list defaulting to week days const unsigned int DAY = 0x20; /*!< forced value list defaulting to week days */
const unsigned int IGN = 0x40; // ignore value during read and write const unsigned int IGN = 0x40; /*!< ignore value during read and write */
const unsigned int FIX = 0x80; // fixed width formatting const unsigned int FIX = 0x80; /*!< fixed width formatting */
/** the structure for defining field types with their properties. */ /** the structure for defining field types with their properties. */
typedef struct { typedef struct {
const char* name; // field identifier const char* name; /*!< field identifier */
const unsigned int maxBits; // number of bits (maximum length if @a ADJ flag is set, must be multiple of 8 with flag @a BCD) const unsigned int maxBits; /*!< number of bits (maximum length if @a ADJ flag is set, must be multiple of 8 with flag @a BCD) */
const BaseType type; // base data type const BaseType type; /*!< base data type */
const unsigned int flags; // flags (e.g. @a BCD) const unsigned int flags; /*!< flags (e.g. @a BCD) */
const unsigned int replacement; // replacement value (fill-up value for @a bt_str / @a bt_hexstr, no replacement if equal to @a minValueOrLength for @a bt_num) const unsigned int replacement; /*!< replacement value (fill-up value for @a bt_str / @a bt_hexstr, no replacement if equal to @a minValueOrLength for @a bt_num) */
const unsigned int minValueOrLength; // minimum binary value (minimum length of string for @a StringDataField) const unsigned int minValueOrLength; /*!< minimum binary value (minimum length of string for @a StringDataField) */
const unsigned int maxValueOrLength; // maximum binary value (maximum length of string for @a StringDataField) const unsigned int maxValueOrLength; /*!< maximum binary value (maximum length of string for @a StringDataField) */
const unsigned int divisor; // @a bt_number: divisor const unsigned int divisor; /*!< @a bt_number: divisor */
const unsigned char precisionOrFirstBit; // @a bt_number: precision for formatting or offset to first bit if (@a numBits%8)!=0 const unsigned char precisionOrFirstBit; /*!< @a bt_number: precision for formatting or offset to first bit if (@a numBits%8)!=0 */
} dataType_t; } dataType_t;
@@ -100,7 +102,6 @@ unsigned int parseInt(const char* str, int base, const unsigned int minValue, co
* @param begin the iterator to the beginning of the items. * @param begin the iterator to the beginning of the items.
* @param end the iterator to the end of the items. * @param end the iterator to the end of the items.
* @param pos the iterator with the erroneous position. * @param pos the iterator with the erroneous position.
* @param separator the character to place between items.
*/ */
void printErrorPos(vector<string>::iterator begin, const vector<string>::iterator end, vector<string>::iterator pos, string filename, size_t lineNo, result_t result); void printErrorPos(vector<string>::iterator begin, const vector<string>::iterator end, vector<string>::iterator pos, string filename, size_t lineNo, result_t result);
@@ -122,10 +123,12 @@ public:
*/ */
DataField(const string name, const string comment) DataField(const string name, const string comment)
: m_name(name), m_comment(comment) {} : m_name(name), m_comment(comment) {}
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~DataField() {} virtual ~DataField() {}
/** /**
* @brief Factory method for creating new instances. * @brief Factory method for creating new instances.
* @param it the iterator to traverse for the definition parts. * @param it the iterator to traverse for the definition parts.
@@ -140,12 +143,14 @@ public:
static result_t create(vector<string>::iterator& it, const vector<string>::iterator end, static result_t create(vector<string>::iterator& it, const vector<string>::iterator end,
DataFieldTemplates* templates, DataField*& returnField, DataFieldTemplates* templates, DataField*& returnField,
const bool isSetMessage=false, const unsigned char dstAddress=SYN); const bool isSetMessage=false, const unsigned char dstAddress=SYN);
/** /**
* @brief Returns the length of this field (or contained fields) in bytes. * @brief Returns the length of this field (or contained fields) in bytes.
* @param partType the message part of the contained fields to limit the length calculation to. * @param partType the message part of the contained fields to limit the length calculation to.
* @return the length of this field (or contained fields) in bytes. * @return the length of this field (or contained fields) in bytes.
*/ */
virtual unsigned char getLength(PartType partType) = 0; virtual unsigned char getLength(PartType partType) = 0;
/** /**
* @brief Derives a new DataField from this field. * @brief Derives a new DataField from this field.
* @param name the field name. * @param name the field name.
@@ -160,21 +165,25 @@ public:
string unit, const PartType partType, string unit, const PartType partType,
unsigned int divisor, map<unsigned int, string> values, unsigned int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields) = 0; vector<SingleDataField*>& fields) = 0;
/** /**
* @brief Get the field name. * @brief Get the field name.
* @return the field name. * @return the field name.
*/ */
string getName() const { return m_name; } string getName() const { return m_name; }
/** /**
* @brief Get the field comment. * @brief Get the field comment.
* @return the field comment. * @return the field comment.
*/ */
string getComment() const { return m_comment; } string getComment() const { return m_comment; }
/** /**
* @brief Dump the field settings to the output. * @brief Dump the field settings to the output.
* @param output the @a ostream to dump to. * @param output the @a ostream to dump to.
*/ */
virtual void dump(ostream& output) = 0; virtual void dump(ostream& output) = 0;
/** /**
* @brief Reads the value from the @a SymbolString. * @brief Reads the value from the @a SymbolString.
* @param partType the @a PartType of the data. * @param partType the @a PartType of the data.
@@ -195,6 +204,7 @@ public:
ostringstream& output, bool leadingSeparator=false, ostringstream& output, bool leadingSeparator=false,
bool verbose=false, const char* filterName=NULL, bool verbose=false, const char* filterName=NULL,
char separator=UI_FIELD_SEPARATOR) = 0; char separator=UI_FIELD_SEPARATOR) = 0;
/** /**
* @brief Writes the value to the master or slave @a SymbolString. * @brief Writes the value to the master or slave @a SymbolString.
* @param input the @a istringstream to parse the formatted value from. * @param input the @a istringstream to parse the formatted value from.
@@ -212,6 +222,7 @@ protected:
/** the field name. */ /** the field name. */
const string m_name; const string m_name;
/** the field comment. */ /** the field comment. */
const string m_comment; const string m_comment;
@@ -240,28 +251,34 @@ public:
: DataField(name, comment), : DataField(name, comment),
m_unit(unit), m_dataType(dataType), m_partType(partType), m_unit(unit), m_dataType(dataType), m_partType(partType),
m_length(length) {} m_length(length) {}
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~SingleDataField() {} virtual ~SingleDataField() {}
/** /**
* @brief Get the value unit. * @brief Get the value unit.
* @return the value unit. * @return the value unit.
*/ */
string getUnit() const { return m_unit; } string getUnit() const { return m_unit; }
/** /**
* @brief Get whether this field is ignored. * @brief Get whether this field is ignored.
* @return whether this field is ignored. * @return whether this field is ignored.
*/ */
bool isIgnored() const { return (m_dataType.flags & IGN) != 0; } bool isIgnored() const { return (m_dataType.flags & IGN) != 0; }
/** /**
* @brief Get the message part in which the field is stored. * @brief Get the message part in which the field is stored.
* @return the message part in which the field is stored. * @return the message part in which the field is stored.
*/ */
PartType getPartType() const { return m_partType; } PartType getPartType() const { return m_partType; }
// @copydoc // @copydoc
virtual unsigned char getLength(PartType partType) { return partType == m_partType ? m_length : 0; }; virtual unsigned char getLength(PartType partType) { return partType == m_partType ? m_length : 0; };
// re-use same position as previous field as not all bits of fully consumed yet // re-use same position as previous field as not all bits of fully consumed yet
/** /**
* @brief Get whether this field uses a full byte offset. * @brief Get whether this field uses a full byte offset.
* @param after @p true to check after consuming the bits, false to check before. * @param after @p true to check after consuming the bits, false to check before.
@@ -269,14 +286,17 @@ public:
* only consumes a part of a byte and a subsequent field may re-use the same offset. * only consumes a part of a byte and a subsequent field may re-use the same offset.
*/ */
virtual bool hasFullByteOffset(bool after) { return true; } virtual bool hasFullByteOffset(bool after) { return true; }
// @copydoc // @copydoc
virtual void dump(ostream& output); virtual void dump(ostream& output);
// @copydoc // @copydoc
virtual result_t read(const PartType partType, virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset, SymbolString& data, unsigned char offset,
ostringstream& output, bool leadingSeparator=false, ostringstream& output, bool leadingSeparator=false,
bool verbose=false, const char* filterName=NULL, bool verbose=false, const char* filterName=NULL,
char separator=UI_FIELD_SEPARATOR); char separator=UI_FIELD_SEPARATOR);
// @copydoc // @copydoc
virtual result_t write(istringstream& input, virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data, const PartType partType, SymbolString& data,
@@ -292,6 +312,7 @@ protected:
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output) = 0; virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output) = 0;
/** /**
* @brief Internal method for writing the field to a @a SymbolString. * @brief Internal method for writing the field to a @a SymbolString.
* @param input the @a istringstream to parse the formatted value from. * @param input the @a istringstream to parse the formatted value from.
@@ -305,10 +326,13 @@ protected:
/** the value unit. */ /** the value unit. */
const string m_unit; const string m_unit;
/** the data type definition. */ /** the data type definition. */
const dataType_t m_dataType; const dataType_t m_dataType;
/** the message part in which the field is stored. */ /** the message part in which the field is stored. */
const PartType m_partType; const PartType m_partType;
/** the number of symbols in the message part in which the field is stored. */ /** the number of symbols in the message part in which the field is stored. */
const unsigned char m_length; const unsigned char m_length;
@@ -335,15 +359,18 @@ public:
const string unit, const dataType_t dataType, const PartType partType, const string unit, const dataType_t dataType, const PartType partType,
const unsigned char length) const unsigned char length)
: SingleDataField(name, comment, unit, dataType, partType, length) {} : SingleDataField(name, comment, unit, dataType, partType, length) {}
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~StringDataField() {} virtual ~StringDataField() {}
// @copydoc // @copydoc
virtual result_t derive(string name, string comment, virtual result_t derive(string name, string comment,
string unit, const PartType partType, string unit, const PartType partType,
unsigned int divisor, map<unsigned int, string> values, unsigned int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields); vector<SingleDataField*>& fields);
// @copydoc // @copydoc
virtual void dump(ostream& output); virtual void dump(ostream& output);
@@ -351,6 +378,7 @@ protected:
// @copydoc // @copydoc
virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output); virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output);
// @copydoc // @copydoc
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output); virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
@@ -380,12 +408,15 @@ public:
const unsigned char length, const unsigned char bitCount, const unsigned char bitOffset) const unsigned char length, const unsigned char bitCount, const unsigned char bitOffset)
: SingleDataField(name, comment, unit, dataType, partType, length), : SingleDataField(name, comment, unit, dataType, partType, length),
m_bitCount(bitCount), m_bitOffset(bitOffset) {} m_bitCount(bitCount), m_bitOffset(bitOffset) {}
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~NumericDataField() {} virtual ~NumericDataField() {}
// @copydoc // @copydoc
virtual bool hasFullByteOffset(bool after); virtual bool hasFullByteOffset(bool after);
// @copydoc // @copydoc
virtual void dump(ostream& output); virtual void dump(ostream& output);
@@ -399,6 +430,7 @@ protected:
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
result_t readRawValue(SymbolString& input, const unsigned char offset, unsigned int& value); result_t readRawValue(SymbolString& input, const unsigned char offset, unsigned int& value);
/** /**
* @brief Internal method for writing the raw value to a @a SymbolString. * @brief Internal method for writing the raw value to a @a SymbolString.
* @param value the raw value to write. * @param value the raw value to write.
@@ -441,15 +473,18 @@ public:
: NumericDataField(name, comment, unit, dataType, partType, length, bitCount, : NumericDataField(name, comment, unit, dataType, partType, length, bitCount,
(dataType.maxBits < 8) ? dataType.precisionOrFirstBit : 0), (dataType.maxBits < 8) ? dataType.precisionOrFirstBit : 0),
m_divisor(divisor) {} m_divisor(divisor) {}
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~NumberDataField() {} virtual ~NumberDataField() {}
// @copydoc // @copydoc
virtual result_t derive(string name, string comment, virtual result_t derive(string name, string comment,
string unit, const PartType partType, string unit, const PartType partType,
unsigned int divisor, map<unsigned int, string> values, unsigned int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields); vector<SingleDataField*>& fields);
// @copydoc // @copydoc
virtual void dump(ostream& output); virtual void dump(ostream& output);
@@ -457,6 +492,7 @@ protected:
// @copydoc // @copydoc
virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output); virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output);
// @copydoc // @copydoc
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output); virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
@@ -492,15 +528,18 @@ public:
: NumericDataField(name, comment, unit, dataType, partType, length, bitCount, : NumericDataField(name, comment, unit, dataType, partType, length, bitCount,
(dataType.maxBits < 8) ? dataType.precisionOrFirstBit : 0), (dataType.maxBits < 8) ? dataType.precisionOrFirstBit : 0),
m_values(values) {} m_values(values) {}
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~ValueListDataField() {} virtual ~ValueListDataField() {}
// @copydoc // @copydoc
virtual result_t derive(string name, string comment, virtual result_t derive(string name, string comment,
string unit, const PartType partType, unsigned int divisor, string unit, const PartType partType, unsigned int divisor,
map<unsigned int, string> values, map<unsigned int, string> values,
vector<SingleDataField*>& fields); vector<SingleDataField*>& fields);
// @copydoc // @copydoc
virtual void dump(ostream& output); virtual void dump(ostream& output);
@@ -508,6 +547,7 @@ protected:
// @copydoc // @copydoc
virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output); virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output);
// @copydoc // @copydoc
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output); virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
@@ -531,6 +571,7 @@ public:
* @return the @a DataFieldSet for parsing the identification message. * @return the @a DataFieldSet for parsing the identification message.
*/ */
static DataFieldSet* createIdentFields(); static DataFieldSet* createIdentFields();
/** /**
* @brief Constructs a new instance. * @brief Constructs a new instance.
* @param name the field name. * @param name the field name.
@@ -541,42 +582,51 @@ public:
const vector<SingleDataField*> fields) const vector<SingleDataField*> fields)
: DataField(name, comment), : DataField(name, comment),
m_fields(fields) {} m_fields(fields) {}
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~DataFieldSet(); virtual ~DataFieldSet();
// @copydoc // @copydoc
virtual unsigned char getLength(PartType partType); virtual unsigned char getLength(PartType partType);
// @copydoc // @copydoc
virtual result_t derive(string name, string comment, virtual result_t derive(string name, string comment,
string unit, const PartType partType, string unit, const PartType partType,
unsigned int divisor, map<unsigned int, string> values, unsigned int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields); vector<SingleDataField*>& fields);
/** /**
* @brief Returns the @a SingleDataField at the specified index. * @brief Returns the @a SingleDataField at the specified index.
* @param index the index of the @a SingleDataField to return. * @param index the index of the @a SingleDataField to return.
* @return the @a SingleDataField at the specified index, or NULL. * @return the @a SingleDataField at the specified index, or NULL.
*/ */
SingleDataField* operator[](const size_t index) { if (index >= m_fields.size()) return NULL; return m_fields[index]; } SingleDataField* operator[](const size_t index) { if (index >= m_fields.size()) return NULL; return m_fields[index]; }
/** /**
* @brief Returns the @a SingleDataField at the specified index. * @brief Returns the @a SingleDataField at the specified index.
* @param index the index of the @a SingleDataField to return. * @param index the index of the @a SingleDataField to return.
* @return the @a SingleDataField at the specified index, or NULL. * @return the @a SingleDataField at the specified index, or NULL.
*/ */
const SingleDataField* operator[](const size_t index) const { if (index >= m_fields.size()) return NULL; return m_fields[index]; } const SingleDataField* operator[](const size_t index) const { if (index >= m_fields.size()) return NULL; return m_fields[index]; }
/** /**
* @brief Returns the number of @a SingleDataFields instances in this set. * @brief Returns the number of @a SingleDataFields instances in this set.
* @return the number of available @a SingleDataField instances. * @return the number of available @a SingleDataField instances.
*/ */
size_t size() const { return m_fields.size(); } size_t size() const { return m_fields.size(); }
// @copydoc // @copydoc
virtual void dump(ostream& output); virtual void dump(ostream& output);
// @copydoc // @copydoc
virtual result_t read(const PartType partType, virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset, SymbolString& data, unsigned char offset,
ostringstream& output, bool leadingSeparator=false, ostringstream& output, bool leadingSeparator=false,
bool verbose=false, const char* filterName=NULL, bool verbose=false, const char* filterName=NULL,
char separator=UI_FIELD_SEPARATOR); char separator=UI_FIELD_SEPARATOR);
// @copydoc // @copydoc
virtual result_t write(istringstream& input, virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data, const PartType partType, SymbolString& data,
@@ -601,24 +651,29 @@ public:
* @brief Constructs a new instance. * @brief Constructs a new instance.
*/ */
DataFieldTemplates() : FileReader(false) {} DataFieldTemplates() : FileReader(false) {}
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~DataFieldTemplates() { clear(); } virtual ~DataFieldTemplates() { clear(); }
/** /**
* @brief Removes all @a DataField instances. * @brief Removes all @a DataField instances.
*/ */
void clear(); void clear();
/** /**
* @brief Adds a template @a DataField instance to this map. * @brief Adds a template @a DataField instance to this map.
* @param field the @a DataField instance to add. * @param message the @a DataField instance to add.
* @param replace whether replacing an already stored instance is allowed. * @param replace whether replacing an already stored instance is allowed.
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
* Note: the caller may not free the added instance on success. * Note: the caller may not free the added instance on success.
*/ */
result_t add(DataField* message, bool replace=false); result_t add(DataField* message, bool replace=false);
// @copydoc // @copydoc
virtual result_t addFromFile(vector<string>& row, void* arg, vector< vector<string> >* defaults, const string& filename, unsigned int lineNo); virtual result_t addFromFile(vector<string>& row, void* arg, vector< vector<string> >* defaults, const string& filename, unsigned int lineNo);
/** /**
* @brief Gets the template @a DataField instance with the specified name. * @brief Gets the template @a DataField instance with the specified name.
* @return the template @a DataField instance, or NULL. * @return the template @a DataField instance, or NULL.
+41 -5
View File
@@ -42,7 +42,7 @@ public:
/** /**
* @brief Construct a new instance. * @brief Construct a new instance.
* @param class the optional device class. * @param clazz the optional device class.
* @param name the message name (unique within the same class and type). * @param name the message name (unique within the same class and type).
* @param isSet whether this is a set message. * @param isSet whether this is a set message.
* @param isPassive true if message can only be initiated by a participant other than us, * @param isPassive true if message can only be initiated by a participant other than us,
@@ -59,6 +59,7 @@ public:
const unsigned char srcAddress, const unsigned char dstAddress, const unsigned char srcAddress, const unsigned char dstAddress,
const vector<unsigned char> id, DataField* data, const vector<unsigned char> id, DataField* data,
const unsigned int pollPriority); const unsigned int pollPriority);
/** /**
* @brief Construct a new temporary instance. * @brief Construct a new temporary instance.
* @param isSet whether this is a set message. * @param isSet whether this is a set message.
@@ -71,10 +72,12 @@ public:
Message(const bool isSet, const bool isPassive, Message(const bool isSet, const bool isPassive,
const unsigned char pb, const unsigned char sb, const unsigned char pb, const unsigned char sb,
DataField* data); DataField* data);
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~Message() { delete m_data; } virtual ~Message() { delete m_data; }
/** /**
* @brief Factory method for creating a new instance. * @brief Factory method for creating a new instance.
* @param it the iterator to traverse for the definition parts. * @param it the iterator to traverse for the definition parts.
@@ -88,52 +91,62 @@ public:
static result_t create(vector<string>::iterator& it, const vector<string>::iterator end, static result_t create(vector<string>::iterator& it, const vector<string>::iterator end,
vector< vector<string> >* defaultsRows, vector< vector<string> >* defaultsRows,
DataFieldTemplates* templates, Message*& returnValue); DataFieldTemplates* templates, Message*& returnValue);
/** /**
* @brief Get the optional device class. * @brief Get the optional device class.
* @return the optional device class. * @return the optional device class.
*/ */
string getClass() const { return m_class; } string getClass() const { return m_class; }
/** /**
* @brief Get the message name (unique within the same class and type). * @brief Get the message name (unique within the same class and type).
* @return the message name (unique within the same class and type). * @return the message name (unique within the same class and type).
*/ */
string getName() const { return m_name; } string getName() const { return m_name; }
/** /**
* @brief Get whether this is a set message. * @brief Get whether this is a set message.
* @return whether this is a set message. * @return whether this is a set message.
*/ */
bool isSet() const { return m_isSet; } bool isSet() const { return m_isSet; }
/** /**
* @brief Get whether message can be initiated only by a participant other than us. * @brief Get whether message can be initiated only by a participant other than us.
* @return true if message can only be initiated by a participant other than us, * @return true if message can only be initiated by a participant other than us,
* false if message can be initiated by any participant. * false if message can be initiated by any participant.
*/ */
bool isPassive() const { return m_isPassive; } bool isPassive() const { return m_isPassive; }
/** /**
* @brief Get the comment. * @brief Get the comment.
* @return the comment. * @return the comment.
*/ */
string getComment() const { return m_comment; } string getComment() const { return m_comment; }
/** /**
* @brief Get the source address. * @brief Get the source address.
* @return the source address, or @a SYN for any. * @return the source address, or @a SYN for any.
*/ */
unsigned char getSrcAddress() const { return m_srcAddress; } unsigned char getSrcAddress() const { return m_srcAddress; }
/** /**
* @brief Get the destination address. * @brief Get the destination address.
* @return the destination address, or @a SYN for any. * @return the destination address, or @a SYN for any.
*/ */
unsigned char getDstAddress() const { return m_dstAddress; } unsigned char getDstAddress() const { return m_dstAddress; }
/** /**
* @brief Get the command ID bytes. * @brief Get the command ID bytes.
* @return the primary, secondary, and optionally further command ID bytes. * @return the primary, secondary, and optionally further command ID bytes.
*/ */
vector<unsigned char> getId() const { return m_id; } vector<unsigned char> getId() const { return m_id; }
/** /**
* @brief Return the key for storing in @a MessageSet. * @brief Return the key for storing in @a MessageSet.
* @return the key for storing in @a MessageSet. * @return the key for storing in @a MessageSet.
*/ */
unsigned long long getKey() { return m_key; } unsigned long long getKey() { return m_key; }
/** /**
* @brief Get the polling priority, or 0 for no polling at all. * @brief Get the polling priority, or 0 for no polling at all.
* @return the polling priority, or 0 for no polling at all. * @return the polling priority, or 0 for no polling at all.
@@ -158,7 +171,7 @@ public:
* @param slaveData the slave data @a SymbolString for writing symbols to. * @param slaveData the slave data @a SymbolString for writing symbols to.
* @return @a RESULT_OK on success, or an error code. * @return @a RESULT_OK on success, or an error code.
*/ */
result_t prepareSlave(SymbolString& masterData); result_t prepareSlave(SymbolString& slaveData);
/** /**
* @brief Decode a received message. * @brief Decode a received message.
@@ -204,35 +217,49 @@ public:
private: private:
/** the optional device class. */ /** the optional device class. */
const string m_class; const string m_class;
/** the message name (unique within the same class and type). */ /** the message name (unique within the same class and type). */
const string m_name; const string m_name;
/** whether this is a set message. */ /** whether this is a set message. */
const bool m_isSet; const bool m_isSet;
/** true if message can only be initiated by a participant other than us, /** true if message can only be initiated by a participant other than us,
* false if message can be initiated by any participant. */ * false if message can be initiated by any participant. */
const bool m_isPassive; const bool m_isPassive;
/** the comment. */ /** the comment. */
const string m_comment; const string m_comment;
/** the source address, or @a SYN for any (only relevant if passive). */ /** the source address, or @a SYN for any (only relevant if passive). */
const unsigned char m_srcAddress; const unsigned char m_srcAddress;
/** the destination address. */ /** the destination address. */
const unsigned char m_dstAddress; const unsigned char m_dstAddress;
/** the primary, secondary, and optionally further command ID bytes. */ /** the primary, secondary, and optionally further command ID bytes. */
vector<unsigned char> m_id; vector<unsigned char> m_id;
/** the key for storing in @a MessageSet. */ /** the key for storing in @a MessageSet. */
unsigned long long m_key; unsigned long long m_key;
/** the @a DataField for encoding/decoding the message. */ /** the @a DataField for encoding/decoding the message. */
DataField* m_data; DataField* m_data;
/** the priority for polling, or 0 for no polling at all. */ /** the priority for polling, or 0 for no polling at all. */
const unsigned char m_pollPriority; const unsigned char m_pollPriority;
/** the last decoded value. */ /** the last decoded value. */
string m_lastValue; string m_lastValue;
/** the system time when @a m_lastValue was updated, 0 for never. */ /** the system time when @a m_lastValue was updated, 0 for never. */
time_t m_lastUpdateTime; time_t m_lastUpdateTime;
/** the number of times this messages was already polled for. */ /** the number of times this messages was already polled for. */
unsigned int m_pollCount; unsigned int m_pollCount;
/** the system time when this message was last polled for, 0 for never. */ /** the system time when this message was last polled for, 0 for never. */
time_t m_lastPollTime; time_t m_lastPollTime;
@@ -258,10 +285,12 @@ public:
* @brief Construct a new instance. * @brief Construct a new instance.
*/ */
MessageMap() : FileReader(true), m_minIdLength(4), m_maxIdLength(0), m_messageCount(0) {} MessageMap() : FileReader(true), m_minIdLength(4), m_maxIdLength(0), m_messageCount(0) {}
/** /**
* @brief Destructor. * @brief Destructor.
*/ */
virtual ~MessageMap() { clear(); } virtual ~MessageMap() { clear(); }
/** /**
* @brief Add a @a Message instance to this set. * @brief Add a @a Message instance to this set.
* @param message the @a Message instance to add. * @param message the @a Message instance to add.
@@ -270,10 +299,11 @@ public:
*/ */
result_t add(Message* message); result_t add(Message* message);
// @copydoc // @copydoc
virtual result_t addFromFile(vector<string>& row, DataFieldTemplates* arg, vector< vector<string> >* defaults, const string& filename, unsigned int lineNo); virtual result_t addFromFile(vector<string>& row, DataFieldTemplates* arg, vector< vector<string> >* defaults, const string& filename, unsigned int lineNo);
/** /**
* @brief Find the @a Message instance for the specified class and name. * @brief Find the @a Message instance for the specified class and name.
* @param class the optional device class. * @param clazz the optional device class.
* @param name the message name. * @param name the message name.
* @param isSet whether this is a set message. * @param isSet whether this is a set message.
* @param isPassive whether this is a passive message. * @param isPassive whether this is a passive message.
@@ -281,15 +311,17 @@ public:
* Note: the caller may not free the returned instance. * Note: the caller may not free the returned instance.
*/ */
Message* find(const string& clazz, const string& name, const bool isSet, const bool isPassive=false); Message* find(const string& clazz, const string& name, const bool isSet, const bool isPassive=false);
/** /**
* @brief Find all active get @a Message instances for the specified class and name. * @brief Find all active get @a Message instances for the specified class and name.
* @param class the device class, or empty for any. * @param clazz the device class, or empty for any.
* @param name the message name, or empty for any. * @param name the message name, or empty for any.
* @param pb the primary ID byte, or -1 for any. * @param pb the primary ID byte, or -1 for any.
* @return the found @a Message instances. * @return the found @a Message instances.
* Note: the caller may not free the returned instances. * Note: the caller may not free the returned instances.
*/ */
deque<Message*> findAll(const string& clazz, const string& name, const short pb); deque<Message*> findAll(const string& clazz, const string& name, const short pb);
/** /**
* @brief Find the @a Message instance for the specified master data. * @brief Find the @a Message instance for the specified master data.
* @param master the master @a SymbolString for identifying the @a Message. * @param master the master @a SymbolString for identifying the @a Message.
@@ -297,21 +329,25 @@ public:
* Note: the caller may not free the returned instance. * Note: the caller may not free the returned instance.
*/ */
Message* find(SymbolString& master); Message* find(SymbolString& master);
/** /**
* @brief Removes all @a Message instances. * @brief Removes all @a Message instances.
*/ */
void clear(); void clear();
/** /**
* @brief Get the number of stored @a Message instances. * @brief Get the number of stored @a Message instances.
* @param passiveOnly true to count only passive messages, false to count all messages. * @param passiveOnly true to count only passive messages, false to count all messages.
* @return the the number of stored @a Message instances. * @return the the number of stored @a Message instances.
*/ */
int size(const bool passiveOnly=false) { return passiveOnly ? m_passiveMessagesByKey.size() : m_messageCount; } int size(const bool passiveOnly=false) { return passiveOnly ? m_passiveMessagesByKey.size() : m_messageCount; }
/** /**
* @brief Get the number of stored @a Message instances with a poll priority. * @brief Get the number of stored @a Message instances with a poll priority.
* @return the the number of stored @a Message instances with a poll priority. * @return the the number of stored @a Message instances with a poll priority.
*/ */
int sizePoll() { return m_pollMessages.size(); } int sizePoll() { return m_pollMessages.size(); }
/** /**
* @brief Get the next @a Message to poll. * @brief Get the next @a Message to poll.
* @return the next @a Message to poll, or NULL. * @return the next @a Message to poll, or NULL.
+1 -1
View File
@@ -271,7 +271,7 @@ public:
/** /**
* @brief Enable or disable logging of raw data. * @brief Enable or disable logging of raw data.
* @param logRawData true to enable logging of raw data, false to disable it. * @param logRaw true to enable logging of raw data, false to disable it.
*/ */
void setLogRaw(bool logRaw=true) { m_logRaw = logRaw; } void setLogRaw(bool logRaw=true) { m_logRaw = logRaw; }
+26 -27
View File
@@ -20,34 +20,33 @@
#ifndef LIBEBUS_RESULT_H_ #ifndef LIBEBUS_RESULT_H_
#define LIBEBUS_RESULT_H_ #define LIBEBUS_RESULT_H_
static const int RESULT_OK = 0; // success /** \file result.h */
static const int RESULT_IN_ESC = 1; // start of escape sequence received /** types for result_t. */
static const int RESULT_SYN = 2; // regular SYN after message received static const int RESULT_OK = 0; /*!< success */
static const int RESULT_EMPTY = 3; // empty result static const int RESULT_IN_ESC = 1; /*!< start of escape sequence received */
static const int RESULT_SYN = 2; /*!< regular SYN after message received */
static const int RESULT_ERR_GENERIC_IO = -1; // generic I/O error (usually fatal) static const int RESULT_EMPTY = 3; /*!< empty result */
static const int RESULT_ERR_DEVICE = -2; // generic device error (usually fatal) static const int RESULT_ERR_GENERIC_IO = -1; /*!< generic I/O error (usually fatal) */
static const int RESULT_ERR_SEND = -3; // send error static const int RESULT_ERR_DEVICE = -2; /*!< generic device error (usually fatal) */
static const int RESULT_ERR_ESC = -4; // invalid escape sequence static const int RESULT_ERR_SEND = -3; /*!< send error */
static const int RESULT_ERR_TIMEOUT = -5; // read timeout static const int RESULT_ERR_ESC = -4; /*!< invalid escape sequence */
static const int RESULT_ERR_TIMEOUT = -5; /*!< read timeout */
static const int RESULT_ERR_NOTFOUND = -6; // file/element not found or not readable static const int RESULT_ERR_NOTFOUND = -6; /*!< file/element not found or not readable */
static const int RESULT_ERR_EOF = -7; // end of input reached static const int RESULT_ERR_EOF = -7; /*!< end of input reached */
static const int RESULT_ERR_INVALID_ARG = -8; // invalid argument static const int RESULT_ERR_INVALID_ARG = -8; /*!< invalid argument */
static const int RESULT_ERR_INVALID_NUM = -9; // invalid numeric argument static const int RESULT_ERR_INVALID_NUM = -9; /*!< invalid numeric argument */
static const int RESULT_ERR_INVALID_ADDR = -10; // invalid address static const int RESULT_ERR_INVALID_ADDR = -10; /*!< invalid address */
static const int RESULT_ERR_INVALID_POS = -11; // invalid position static const int RESULT_ERR_INVALID_POS = -11; /*!< invalid position */
static const int RESULT_ERR_OUT_OF_RANGE = -12; // argument value out of valid range static const int RESULT_ERR_OUT_OF_RANGE = -12; /*!< argument value out of valid range */
static const int RESULT_ERR_INVALID_PART = -13; // invalid part type value static const int RESULT_ERR_INVALID_PART = -13; /*!< invalid part type value */
static const int RESULT_ERR_MISSING_TYPE = -14; // missing data type static const int RESULT_ERR_MISSING_TYPE = -14; /*!< missing data type */
static const int RESULT_ERR_INVALID_LIST = -15; // invalid value list static const int RESULT_ERR_INVALID_LIST = -15; /*!< invalid value list */
static const int RESULT_ERR_DUPLICATE = -16; // duplicate entry static const int RESULT_ERR_DUPLICATE = -16; /*!< duplicate entry */
static const int RESULT_ERR_BUS_LOST = -17; /*!< arbitration lost */
static const int RESULT_ERR_BUS_LOST = -17; // arbitration lost static const int RESULT_ERR_CRC = -18; /*!< CRC error */
static const int RESULT_ERR_CRC = -18; // CRC error static const int RESULT_ERR_ACK = -19; /*!< ACK error */
static const int RESULT_ERR_ACK = -19; // ACK error static const int RESULT_ERR_NAK = -20; /*!< NAK received */
static const int RESULT_ERR_NAK = -20; // NAK received
/** type for result code. */ /** type for result code. */
typedef int result_t; typedef int result_t;
+29 -6
View File
@@ -28,11 +28,21 @@
using namespace std; using namespace std;
static const unsigned char ESC = 0xA9; // escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA
static const unsigned char SYN = 0xAA; // synchronization symbol /** escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA */
static const unsigned char ACK = 0x00; // positive acknowledge static const unsigned char ESC = 0xA9;
static const unsigned char NAK = 0xFF; // negative acknowledge
static const unsigned char BROADCAST = 0xFE; // the broadcast destination address /** synchronization symbol */
static const unsigned char SYN = 0xAA;
/** positive acknowledge */
static const unsigned char ACK = 0x00;
/** negative acknowledge */
static const unsigned char NAK = 0xFF;
/** the broadcast destination address */
static const unsigned char BROADCAST = 0xFE;
/** /**
@@ -46,40 +56,47 @@ public:
* @brief Creates a new unescaped empty instance. * @brief Creates a new unescaped empty instance.
*/ */
SymbolString() : m_unescapeState(1), m_crc(0) {} SymbolString() : m_unescapeState(1), m_crc(0) {}
/** /**
* @brief Creates a new escaped instance from an unescaped hex string and adds the calculated CRC. * @brief Creates a new escaped instance from an unescaped hex string and adds the calculated CRC.
* @param str the unescaped hex string. * @param str the unescaped hex string.
*/ */
SymbolString(const string& str); SymbolString(const string& str);
/** /**
* @brief Creates a new escaped or unescaped instance from another @a SymbolString and adds the calculated CRC. * @brief Creates a new escaped or unescaped instance from another @a SymbolString and adds the calculated CRC.
* @param str the @a SymbolString top copy from. * @param str the @a SymbolString top copy from.
*/ */
SymbolString(const SymbolString& str, const bool escape, const bool addCrc=true); SymbolString(const SymbolString& str, const bool escape, const bool addCrc=true);
/** /**
* @brief Creates a new unescaped instance from a hex string. * @brief Creates a new unescaped instance from a hex string.
* @param isEscaped whether the hex string is escaped and shall be unescaped. * @param isEscaped whether the hex string is escaped and shall be unescaped.
* @param str the hex string. * @param str the hex string.
*/ */
SymbolString(const string& str, const bool isEscaped); SymbolString(const string& str, const bool isEscaped);
/** /**
* @brief Returns the symbols as hex string. * @brief Returns the symbols as hex string.
* @param unescape whether to unescape an escaped instance. * @param unescape whether to unescape an escaped instance.
* @return the symbols as hex string. * @return the symbols as hex string.
*/ */
const string getDataStr(const bool unescape=true); const string getDataStr(const bool unescape=true);
/** /**
* @brief Returns a reference to the symbol at the specified index. * @brief Returns a reference to the symbol at the specified index.
* @param index the index of the symbol to return. * @param index the index of the symbol to return.
* @return the reference to the symbol at the specified index. * @return the reference to the symbol at the specified index.
*/ */
unsigned char& operator[](const size_t index) { if (index >= m_data.size()) m_data.resize(index+1, 0); return m_data[index]; } unsigned char& operator[](const size_t index) { if (index >= m_data.size()) m_data.resize(index+1, 0); return m_data[index]; }
/** /**
* @brief Returns the symbol at the specified index. * @brief Returns the symbol at the specified index.
* @param index the index of the symbol to return. * @param index the index of the symbol to return.
* @return the symbol at the specified index. * @return the symbol at the specified index.
*/ */
const unsigned char& operator[](const size_t index) const { return m_data[index]; } const unsigned char& operator[](const size_t index) const { return m_data[index]; }
/** /**
* @brief Returns whether this instance is equal to the other instance. * @brief Returns whether this instance is equal to the other instance.
* @param other the other instance. * @param other the other instance.
@@ -99,26 +116,30 @@ public:
cout<<"["<<static_cast<unsigned>(other.m_unescapeState)<<"]"<<endl; cout<<"["<<static_cast<unsigned>(other.m_unescapeState)<<"]"<<endl;
return ret;*/ return ret;*/
} }
/** /**
* @brief Appends a the symbol to the end of the symbol string and escapes/unescapes it if necessary. * @brief Appends a the symbol to the end of the symbol string and escapes/unescapes it if necessary.
* @param value the symbol to append. * @param value the symbol to append.
* @param isEscaped whether the symbol is escaped. * @param isEscaped whether the symbol is escaped.
* @param updateCrc whether to update the calculated CRC in @a m_crc. * @param updateCRC whether to update the calculated CRC in @a m_crc.
* @return RESULT_OK if another symbol was appended, * @return RESULT_OK if another symbol was appended,
* RESULT_IN_ESC if this is an unescaped instance and the symbol is escaped and the start of the escape sequence was received, * RESULT_IN_ESC if this is an unescaped instance and the symbol is escaped and the start of the escape sequence was received,
* RESULT_ERR_ESC if this is an unescaped instance and an invalid escaped sequence was detected. * RESULT_ERR_ESC if this is an unescaped instance and an invalid escaped sequence was detected.
*/ */
result_t push_back(const unsigned char value, const bool isEscaped=true, const bool updateCRC=true); result_t push_back(const unsigned char value, const bool isEscaped=true, const bool updateCRC=true);
/** /**
* @brief Returns the number of symbols in this symbol string. * @brief Returns the number of symbols in this symbol string.
* @return the number of available symbols. * @return the number of available symbols.
*/ */
unsigned char size() const { return (unsigned char)m_data.size(); } unsigned char size() const { return (unsigned char)m_data.size(); }
/** /**
* @brief Returns the calculated CRC. * @brief Returns the calculated CRC.
* @return the calculated CRC. * @return the calculated CRC.
*/ */
unsigned char getCRC() const { return m_crc; } unsigned char getCRC() const { return m_crc; }
/** /**
* @brief Clears the symbols. * @brief Clears the symbols.
*/ */
@@ -143,12 +164,14 @@ private:
* @brief the string of bus symbols. * @brief the string of bus symbols.
*/ */
vector<unsigned char> m_data; vector<unsigned char> m_data;
/** /**
* @brief 0 if the symbols in @a m_data are escaped, * @brief 0 if the symbols in @a m_data are escaped,
* 1 if the symbols in @a m_data are unescaped and the last symbol passed to @a push_back was a normal symbol, * 1 if the symbols in @a m_data are unescaped and the last symbol passed to @a push_back was a normal symbol,
* 2 if the symbols in @a m_data are unescaped and the last symbol passed to @a push_back was the escape symbol. * 2 if the symbols in @a m_data are unescaped and the last symbol passed to @a push_back was the escape symbol.
*/ */
int m_unescapeState; int m_unescapeState;
/** /**
* @brief the calculated CRC. * @brief the calculated CRC.
*/ */
+4 -4
View File
@@ -129,7 +129,7 @@ class LogSink : public Thread
public: public:
/** /**
* @brief creates a virtual logging sink. * @brief creates a virtual logging sink.
* @param areas the logging area mask. * @param areaMask the logging area mask.
* @param level the logging level. * @param level the logging level.
*/ */
LogSink(const int areaMask, const int level) : m_areaMask(areaMask), m_level(level) {} LogSink(const int areaMask, const int level) : m_areaMask(areaMask), m_level(level) {}
@@ -153,7 +153,7 @@ public:
/** /**
* @brief set the logging area mask. * @brief set the logging area mask.
* @param areas the logging area mask. * @param areaMask the logging area mask.
*/ */
void setAreaMask(const int& areaMask) { m_areaMask = areaMask; } void setAreaMask(const int& areaMask) { m_areaMask = areaMask; }
@@ -197,7 +197,7 @@ class LogConsole : public LogSink
public: public:
/** /**
* @brief creates a console logging sink. * @brief creates a console logging sink.
* @param areas the logging area mask. * @param areaMask the logging area mask.
* @param level the logging level. * @param level the logging level.
* @param name the thread name for logging sink. * @param name the thread name for logging sink.
*/ */
@@ -222,7 +222,7 @@ class LogFile : public LogSink
public: public:
/** /**
* @brief creates a log file logging sink. * @brief creates a log file logging sink.
* @param areas the logging area mask. * @param areaMask the logging area mask.
* @param level the logging level. * @param level the logging level.
* @param name the thread name for logging sink. * @param name the thread name for logging sink.
* @param file the log file. * @param file the log file.