Conflicts:
	src/ebusd/baseloop.h
	src/lib/ebus/data.h
	src/lib/ebus/message.h
	src/lib/ebus/result.h
	src/lib/ebus/symbol.h
This commit is contained in:
john30
2014-12-15 20:26:58 +01:00
4 changed files with 108 additions and 5 deletions
+54 -1
View File
@@ -85,7 +85,6 @@ typedef struct {
const unsigned char precisionOrFirstBit; //!< @a bt_number: precision for formatting or offset to first bit if (@a numBits%8)!=0
} dataType_t;
/**
* @brief Parse an unsigned int value.
* @param str the string to parse.
@@ -127,10 +126,12 @@ public:
*/
DataField(const string name, const string comment)
: m_name(name), m_comment(comment) {}
/**
* @brief Destructor.
*/
virtual ~DataField() {}
/**
* @brief Factory method for creating new instances.
* @param it the iterator to traverse for the definition parts.
@@ -145,12 +146,14 @@ public:
static result_t create(vector<string>::iterator& it, const vector<string>::iterator end,
DataFieldTemplates* templates, DataField*& returnField,
const bool isSetMessage=false, const unsigned char dstAddress=SYN);
/**
* @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.
* @return the length of this field (or contained fields) in bytes.
*/
virtual unsigned char getLength(PartType partType) = 0;
/**
* @brief Derives a new DataField from this field.
* @param name the field name.
@@ -166,21 +169,25 @@ public:
string unit, const PartType partType,
unsigned int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields) = 0;
/**
* @brief Get the field name.
* @return the field name.
*/
string getName() const { return m_name; }
/**
* @brief Get the field comment.
* @return the field comment.
*/
string getComment() const { return m_comment; }
/**
* @brief Dump the field settings to the output.
* @param output the @a ostream to dump to.
*/
virtual void dump(ostream& output) = 0;
/**
* @brief Reads the value from the @a SymbolString.
* @param partType the @a PartType of the data.
@@ -201,6 +208,7 @@ public:
ostringstream& output, bool leadingSeparator=false,
bool verbose=false, const char* filterName=NULL,
char separator=UI_FIELD_SEPARATOR) = 0;
/**
* @brief Writes the value to the master or slave @a SymbolString.
* @param input the @a istringstream to parse the formatted value from.
@@ -218,6 +226,7 @@ protected:
/** the field name. */
const string m_name;
/** the field comment. */
const string m_comment;
@@ -246,28 +255,34 @@ public:
: DataField(name, comment),
m_unit(unit), m_dataType(dataType), m_partType(partType),
m_length(length) {}
/**
* @brief Destructor.
*/
virtual ~SingleDataField() {}
/**
* @brief Get the value unit.
* @return the value unit.
*/
string getUnit() const { return m_unit; }
/**
* @brief Get whether this field is ignored.
* @return whether this field is ignored.
*/
bool isIgnored() const { return (m_dataType.flags & IGN) != 0; }
/**
* @brief Get 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; }
// @copydoc
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
/**
* @brief Get whether this field uses a full byte offset.
* @param after @p true to check after consuming the bits, false to check before.
@@ -275,14 +290,17 @@ public:
* only consumes a part of a byte and a subsequent field may re-use the same offset.
*/
virtual bool hasFullByteOffset(bool after) { return true; }
// @copydoc
virtual void dump(ostream& output);
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, bool leadingSeparator=false,
bool verbose=false, const char* filterName=NULL,
char separator=UI_FIELD_SEPARATOR);
// @copydoc
virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data,
@@ -298,6 +316,7 @@ protected:
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output) = 0;
/**
* @brief Internal method for writing the field to a @a SymbolString.
* @param input the @a istringstream to parse the formatted value from.
@@ -311,10 +330,13 @@ protected:
/** the value unit. */
const string m_unit;
/** the data type definition. */
const dataType_t m_dataType;
/** the message part in which the field is stored. */
const PartType m_partType;
/** the number of symbols in the message part in which the field is stored. */
const unsigned char m_length;
@@ -341,15 +363,18 @@ public:
const string unit, const dataType_t dataType, const PartType partType,
const unsigned char length)
: SingleDataField(name, comment, unit, dataType, partType, length) {}
/**
* @brief Destructor.
*/
virtual ~StringDataField() {}
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType,
unsigned int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields);
// @copydoc
virtual void dump(ostream& output);
@@ -357,6 +382,7 @@ protected:
// @copydoc
virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output);
// @copydoc
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
@@ -386,12 +412,15 @@ public:
const unsigned char length, const unsigned char bitCount, const unsigned char bitOffset)
: SingleDataField(name, comment, unit, dataType, partType, length),
m_bitCount(bitCount), m_bitOffset(bitOffset) {}
/**
* @brief Destructor.
*/
virtual ~NumericDataField() {}
// @copydoc
virtual bool hasFullByteOffset(bool after);
// @copydoc
virtual void dump(ostream& output);
@@ -405,6 +434,7 @@ protected:
* @return @a RESULT_OK on success, or an error code.
*/
result_t readRawValue(SymbolString& input, const unsigned char offset, unsigned int& value);
/**
* @brief Internal method for writing the raw value to a @a SymbolString.
* @param value the raw value to write.
@@ -448,15 +478,18 @@ public:
: NumericDataField(name, comment, unit, dataType, partType, length, bitCount,
(dataType.maxBits < 8) ? dataType.precisionOrFirstBit : 0),
m_divisor(divisor) {}
/**
* @brief Destructor.
*/
virtual ~NumberDataField() {}
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType,
unsigned int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields);
// @copydoc
virtual void dump(ostream& output);
@@ -464,6 +497,7 @@ protected:
// @copydoc
virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output);
// @copydoc
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
@@ -500,15 +534,18 @@ public:
: NumericDataField(name, comment, unit, dataType, partType, length, bitCount,
(dataType.maxBits < 8) ? dataType.precisionOrFirstBit : 0),
m_values(values) {}
/**
* @brief Destructor.
*/
virtual ~ValueListDataField() {}
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType, unsigned int divisor,
map<unsigned int, string> values,
vector<SingleDataField*>& fields);
// @copydoc
virtual void dump(ostream& output);
@@ -516,6 +553,7 @@ protected:
// @copydoc
virtual result_t readSymbols(SymbolString& input, const unsigned char offset, ostringstream& output);
// @copydoc
virtual result_t writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output);
@@ -539,6 +577,7 @@ public:
* @return the @a DataFieldSet for parsing the identification message.
*/
static DataFieldSet* createIdentFields();
/**
* @brief Constructs a new instance.
* @param name the field name.
@@ -549,42 +588,51 @@ public:
const vector<SingleDataField*> fields)
: DataField(name, comment),
m_fields(fields) {}
/**
* @brief Destructor.
*/
virtual ~DataFieldSet();
// @copydoc
virtual unsigned char getLength(PartType partType);
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType,
unsigned int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields);
/**
* @brief Returns the @a SingleDataField at the specified index.
* @param index the index of the @a SingleDataField to return.
* @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]; }
/**
* @brief Returns the @a SingleDataField at the specified index.
* @param index the index of the @a SingleDataField to return.
* @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]; }
/**
* @brief Returns the number of @a SingleDataFields instances in this set.
* @return the number of available @a SingleDataField instances.
*/
size_t size() const { return m_fields.size(); }
// @copydoc
virtual void dump(ostream& output);
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, bool leadingSeparator=false,
bool verbose=false, const char* filterName=NULL,
char separator=UI_FIELD_SEPARATOR);
// @copydoc
virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data,
@@ -609,14 +657,17 @@ public:
* @brief Constructs a new instance.
*/
DataFieldTemplates() : FileReader<void*>::FileReader(false) {}
/**
* @brief Destructor.
*/
virtual ~DataFieldTemplates() { clear(); }
/**
* @brief Removes all @a DataField instances.
*/
void clear();
/**
* @brief Adds a template @a DataField instance to this map.
* @param field the @a DataField instance to add.
@@ -625,8 +676,10 @@ public:
* Note: the caller may not free the added instance on success.
*/
result_t add(DataField* field, bool replace=false);
// @copydoc
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.
* @param name the name of the template to get.