+601
-284
File diff suppressed because it is too large
Load Diff
+274
-88
@@ -28,6 +28,7 @@
|
||||
|
||||
/** the message part in which a data field is stored. */
|
||||
enum PartType {
|
||||
pt_template, // special part type for templates (relative offset)
|
||||
pt_masterData, // stored in master data
|
||||
pt_slaveData, // stored in slave data
|
||||
};
|
||||
@@ -42,71 +43,156 @@ enum BaseType {
|
||||
};
|
||||
|
||||
/** flags for dataType_t. */
|
||||
const unsigned int ADJ = 0x01; // adjustable length, numBytes 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 REV = 0x04; // reverted binary representation (most significant byte first)
|
||||
const unsigned int SIG = 0x08; // signed value
|
||||
const unsigned int LST = 0x10; // value list is possible (without applied divisor)
|
||||
const unsigned int DAY = 0x20; // default value list is week days
|
||||
const unsigned int DAY = 0x20; // forced value list defaulting to week days
|
||||
|
||||
/** the structure for defining field types with their properties. */
|
||||
typedef struct {
|
||||
const char* name; // field identifier
|
||||
const unsigned int numBytes; // number of bytes (maximum length if ADJ flag is set)
|
||||
const BaseType type; // base data type
|
||||
const unsigned int flags; // flags (e.g. BCD)
|
||||
const unsigned int replacement; // replacement value (fill-up value for bt_str/bt_hexstr)
|
||||
const unsigned int minValueOrLength; // minimum binary value (minimum length of string for StringDataField)
|
||||
const unsigned int maxValueOrLength; // maximum binary value (maximum length of string for StringDataField)
|
||||
const unsigned int divisor; // divisor for bt_number values (or 0 for non-numeric)
|
||||
const char* name; // field identifier
|
||||
const unsigned int numBits; // number of bits (maximum length if ADJ flag is set, must be multiple of 8 with flag BCD)
|
||||
const BaseType type; // base data type
|
||||
const unsigned int flags; // flags (e.g. BCD)
|
||||
const unsigned int replacement; // replacement value (fill-up value for bt_str/bt_hexstr, no replacement if equal to minValueOrLength for bt_num)
|
||||
const unsigned int minValueOrLength; // minimum binary value (minimum length of string for StringDataField)
|
||||
const unsigned int maxValueOrLength; // maximum binary value (maximum length of string for StringDataField)
|
||||
const unsigned int divisor; // bt_number: divisor
|
||||
const unsigned char precisionOrFirstBit; // bt_number: precision for formatting or offset to first bit if (numBits%8)!=0
|
||||
} dataType_t;
|
||||
|
||||
|
||||
class SingleDataField;
|
||||
|
||||
/**
|
||||
* @brief Base class for all kinds of data fields.
|
||||
*/
|
||||
class DataField
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructs a new instance.
|
||||
* @param name the field name.
|
||||
* @param partType the message part in which the field is stored.
|
||||
* @param offset the offset to the first symbol in the message part in which the field is stored.
|
||||
* @param length the number of symbols in the message part in which the field is stored.
|
||||
* @param dataType the data type definition.
|
||||
* @param unit the value unit.
|
||||
* @param comment the field comment.
|
||||
*/
|
||||
DataField(const std::string name, const PartType partType,
|
||||
const unsigned char offset, const unsigned char length,
|
||||
const dataType_t dataType, const std::string unit,
|
||||
const std::string comment)
|
||||
: m_name(name), m_partType(partType), m_offset(offset),
|
||||
m_length(length), m_dataType(dataType), m_unit(unit),
|
||||
m_comment(comment) {}
|
||||
DataField(const std::string name, const std::string comment)
|
||||
: m_name(name), m_comment(comment) {}
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~DataField() {}
|
||||
|
||||
/**
|
||||
* @brief Factory method for creating a new instance.
|
||||
* @param dstAddress the destination bus address.
|
||||
* @param isSetMessage whether the field is part of a set message.
|
||||
* @brief Factory method for creating new instances.
|
||||
* @param it the iterator to traverse for the definition parts.
|
||||
* @param end the iterator pointing to the end of the definition parts.
|
||||
* @param predefined a map of predefined DataFields to be referenced by name.
|
||||
* @param templates a map of DataField templates to be referenced by name.
|
||||
* @param fields the vector to which created instances are added.
|
||||
* @param nextPos the variable holding the next subsequent position.
|
||||
* @param isSetMessage whether the field is part of a set message (default false).
|
||||
* @param dstAddress the destination bus address (default @a SYN for creating a template DataFields).
|
||||
* @return RESULT_OK on success, RESULT_ERR_EOF if the iterator is empty, or an error code.
|
||||
* Note: the caller needs to cleanup created instances.
|
||||
*/
|
||||
static result_t create(const unsigned char dstAddress, const bool isSetMessage,
|
||||
std::vector<std::string>::iterator& it, const std::vector<std::string>::iterator end,
|
||||
const std::map<std::string, DataField*> predefined, std::vector<DataField*>& fields,
|
||||
unsigned char& nextPos);
|
||||
static result_t create(std::vector<std::string>::iterator& it, const std::vector<std::string>::iterator end,
|
||||
const std::map< std::string, DataField*> templates, DataField*& fields,
|
||||
const bool isSetMessage=false, const unsigned char dstAddress=SYN);
|
||||
/**
|
||||
* @brief Returns the offset to the first symbol in the message part for a field following this field.
|
||||
* @return the offset to the first symbol in the message part for a field following this field.
|
||||
*/
|
||||
virtual unsigned char getNextOffset() = 0;
|
||||
/**
|
||||
* @brief Derives a new DataField from this field.
|
||||
* @param name the field name.
|
||||
* @param comment the field comment, or empty to use this fields comment.
|
||||
* @param unit the value unit, or empty to use this fields unit (if applicable).
|
||||
* @param partType the message part in which the field is stored.
|
||||
* @param offset the (additional) offset to the first symbol in the message part in which the field is stored.
|
||||
* @param divisor the extra divisor to apply on the value, or 1 for none (if applicable).
|
||||
* @param values the value=text assignments, or empty to use this fields assignments (if applicable).
|
||||
*/
|
||||
virtual result_t derive(std::string name, std::string comment,
|
||||
std::string unit, const PartType partType, unsigned char offset,
|
||||
unsigned int divisor, std::map<unsigned int, std::string> values,
|
||||
std::vector<SingleDataField*>& fields) = 0;
|
||||
/**
|
||||
* @brief Get the field name.
|
||||
* @return the field name.
|
||||
*/
|
||||
const std::string getName() { return m_name; }
|
||||
/**
|
||||
* @brief Get the field comment.
|
||||
* @return the field comment.
|
||||
*/
|
||||
const std::string getComment() { return m_comment; }
|
||||
/**
|
||||
* @brief Reads the value from the master or slave @a SymbolString.
|
||||
* @param masterData the unescaped master data @a SymbolString for reading binary data.
|
||||
* @param slaveData the unescaped slave data @a SymbolString for reading binary data.
|
||||
* @param output the ostringstream to append the formatted value to.
|
||||
* @param verbose whether to prepend the name, append the unit (if present), and append
|
||||
* the comment in square brackets (if present).
|
||||
* @param separator the separator character between multiple fields.
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t read(SymbolString& masterData, SymbolString& slaveData, std::ostringstream& output,
|
||||
bool verbose=false, char separator=';') = 0;
|
||||
/**
|
||||
* @brief Writes the value to the master or slave @a SymbolString.
|
||||
* @param input the istringstream to parse the formatted value from.
|
||||
* @param masterData the unescaped master data @a SymbolString for writing binary data.
|
||||
* @param slaveData the unescaped slave data @a SymbolString for writing binary data.
|
||||
* @param separator the separator character between multiple fields.
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t write(std::istringstream& input, SymbolString& masterData, SymbolString& slaveData,
|
||||
char separator=';') = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/** the field name. */
|
||||
const std::string m_name;
|
||||
/** the field comment. */
|
||||
const std::string m_comment;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief A single DataField.
|
||||
*/
|
||||
class SingleDataField : public DataField
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructs a new instance.
|
||||
* @param name the field name.
|
||||
* @param comment the field comment.
|
||||
* @param unit the value unit.
|
||||
* @param dataType the data type definition.
|
||||
* @param partType the message part in which the field is stored.
|
||||
* @param offset the offset to the first symbol in the message part in which the field is stored.
|
||||
* @param length the number of symbols in the message part in which the field is stored.
|
||||
*/
|
||||
SingleDataField(const std::string name, const std::string comment,
|
||||
const std::string unit, const dataType_t dataType, const PartType partType,
|
||||
const unsigned char offset, const unsigned char length)
|
||||
: DataField(name, comment),
|
||||
m_unit(unit), m_dataType(dataType), m_partType(partType),
|
||||
m_offset(offset), m_length(length) {}
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~SingleDataField() {}
|
||||
/**
|
||||
* @brief Get the value unit.
|
||||
* @return the value unit.
|
||||
*/
|
||||
const std::string getUnit() { return m_unit; }
|
||||
virtual unsigned char getNextOffset();
|
||||
/**
|
||||
* @brief Reads the value from the master or slave @a SymbolString.
|
||||
* @param masterData the unescaped master data @a SymbolString for reading binary data.
|
||||
@@ -116,79 +202,83 @@ public:
|
||||
* the comment in square brackets (if present).
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t read(SymbolString& masterData, SymbolString& slaveData, std::ostringstream& output,
|
||||
bool verbose=false);
|
||||
virtual result_t read(SymbolString& masterData, SymbolString& slaveData, std::ostringstream& output,
|
||||
bool verbose=false, char separator=';');
|
||||
/**
|
||||
* @brief Writes the value to the master or slave @a SymbolString.
|
||||
* @param input the istringstream to parse the formatted value from.
|
||||
* @param masterData the unescaped master data @a SymbolString for writing binary data.
|
||||
* @param slaveData the unescaped slave data @a SymbolString for writing binary data.
|
||||
* @param value the formatted value as string.
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t write(const std::string& value, SymbolString& masterData, SymbolString& slaveData);
|
||||
virtual result_t write(std::istringstream& input, SymbolString& masterData, SymbolString& slaveData,
|
||||
char separator=';');
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief Internal method for reading the field from a @a SymbolString.
|
||||
* @param input the unescaped @a SymbolString to read the binary value from.
|
||||
* @param output the ostringstream to append the formatted value to.
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t readSymbols(SymbolString& input, std::ostringstream& output) = 0;
|
||||
virtual result_t readSymbols(SymbolString& input, unsigned char baseOffset, std::ostringstream& output) = 0;
|
||||
/**
|
||||
* @brief Internal method for writing the field to a @a SymbolString.
|
||||
* @param input the istringstream to parse the formatted value from.
|
||||
* @param output the unescaped @a SymbolString to write the binary value to.
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t writeSymbols(std::istringstream& input, SymbolString& output) = 0;
|
||||
virtual result_t writeSymbols(std::istringstream& input, unsigned char baseOffset, SymbolString& output) = 0;
|
||||
|
||||
/** the field name. */
|
||||
const std::string m_name;
|
||||
/** the value unit. */
|
||||
const std::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 offset to the first symbol in the message part in which the field is stored. */
|
||||
/** the relative offset to the first symbol in the message part in which the field is stored. */
|
||||
const unsigned char m_offset;
|
||||
/** the number of symbols in the message part in which the field is stored. */
|
||||
const unsigned char m_length;
|
||||
/** the data type definition. */
|
||||
const dataType_t m_dataType;
|
||||
/** the value unit. */
|
||||
const std::string m_unit;
|
||||
/** the field comment. */
|
||||
const std::string m_comment;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Base class for all string based data fields.
|
||||
*/
|
||||
class StringDataField : public DataField
|
||||
class StringDataField : public SingleDataField
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructs a new instance.
|
||||
* @param name the field name.
|
||||
* @param comment the field comment.
|
||||
* @param unit the value unit.
|
||||
* @param dataType the data type definition.
|
||||
* @param partType the message part in which the field is stored.
|
||||
* @param offset the offset to the first symbol in the message part in which the field is stored.
|
||||
* @param length the number of symbols in the message part in which the field is stored.
|
||||
* @param dataType the data type definition.
|
||||
* @param unit the value unit.
|
||||
* @param comment the field comment.
|
||||
*/
|
||||
StringDataField(const std::string name, const PartType partType,
|
||||
const unsigned char offset, const unsigned char length,
|
||||
const dataType_t dataType, const std::string unit,
|
||||
const std::string comment)
|
||||
: DataField(name, partType, offset, length, dataType, unit, comment) {}
|
||||
StringDataField(const std::string name, const std::string comment,
|
||||
const std::string unit, const dataType_t dataType, const PartType partType,
|
||||
const unsigned char offset, const unsigned char length)
|
||||
: SingleDataField(name, comment, unit, dataType, partType, offset, length) {}
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~StringDataField() {}
|
||||
virtual result_t derive(std::string name, std::string comment,
|
||||
std::string unit, const PartType partType, unsigned char offset,
|
||||
unsigned int divisor, std::map<unsigned int, std::string> values,
|
||||
std::vector<SingleDataField*>& fields);
|
||||
|
||||
protected:
|
||||
virtual result_t readSymbols(SymbolString& input, std::ostringstream& output);
|
||||
virtual result_t writeSymbols(std::istringstream& input, SymbolString& output);
|
||||
|
||||
virtual result_t readSymbols(SymbolString& input, unsigned char baseOffset, std::ostringstream& output);
|
||||
virtual result_t writeSymbols(std::istringstream& input, unsigned char baseOffset, SymbolString& output);
|
||||
|
||||
};
|
||||
|
||||
@@ -196,119 +286,215 @@ protected:
|
||||
/**
|
||||
* @brief Base class for all numeric data fields.
|
||||
*/
|
||||
class NumericDataField : public DataField
|
||||
class NumericDataField : public SingleDataField
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructs a new instance.
|
||||
* @param name the field name.
|
||||
* @param comment the field comment.
|
||||
* @param unit the value unit.
|
||||
* @param dataType the data type definition.
|
||||
* @param partType the message part in which the field is stored.
|
||||
* @param offset the offset to the first symbol in the message part in which the field is stored.
|
||||
* @param length the number of symbols in the message part in which the field is stored.
|
||||
* @param dataType the data type definition.
|
||||
* @param unit the value unit.
|
||||
* @param comment the field comment.
|
||||
* @param bitOffset the offset to the first bit in the binary value.
|
||||
*/
|
||||
NumericDataField(const std::string name, const PartType partType,
|
||||
NumericDataField(const std::string name, const std::string comment,
|
||||
const std::string unit, const dataType_t dataType, const PartType partType,
|
||||
const unsigned char offset, const unsigned char length,
|
||||
const dataType_t dataType, const std::string unit,
|
||||
const std::string comment)
|
||||
: DataField(name, partType, offset, length, dataType, unit, comment) {}
|
||||
const unsigned char bitOffset)
|
||||
: SingleDataField(name, comment, unit, dataType, partType, offset, length),
|
||||
m_bitOffset(bitOffset) {}
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~NumericDataField() {}
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief Internal method for reading the raw value from a @a SymbolString.
|
||||
* @param input the unescaped @a SymbolString to read the binary value from.
|
||||
* @param value the variable in which to store the raw value.
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t readRawValue(SymbolString& input, unsigned int& value);
|
||||
result_t readRawValue(SymbolString& input, unsigned char baseOffset, unsigned int& value);
|
||||
/**
|
||||
* @brief Internal method for writing the raw value to a @a SymbolString.
|
||||
* @param value the raw value to write.
|
||||
* @param output the unescaped @a SymbolString to write the binary value to.
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t writeRawValue(unsigned int value, SymbolString& output);
|
||||
result_t writeRawValue(unsigned int value, unsigned char baseOffset, SymbolString& output);
|
||||
|
||||
/** the offset to the first bit in the binary value. */
|
||||
const unsigned char m_bitOffset;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Base class for all numeric data fields with a number representation.
|
||||
*/
|
||||
class NumberDataField : public NumericDataField
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructs a new instance.
|
||||
* @param name the field name.
|
||||
* @param comment the field comment.
|
||||
* @param unit the value unit.
|
||||
* @param dataType the data type definition.
|
||||
* @param partType the message part in which the field is stored.
|
||||
* @param offset the offset to the first symbol in the message part in which the field is stored.
|
||||
* @param length the number of symbols in the message part in which the field is stored.
|
||||
* @param dataType the data type definition.
|
||||
* @param unit the value unit.
|
||||
* @param comment the field comment.
|
||||
* @param divisor the extra divisor to apply on the value, or 1 for none.
|
||||
*/
|
||||
NumberDataField(const std::string name, const PartType partType,
|
||||
NumberDataField(const std::string name, const std::string comment,
|
||||
const std::string unit, const dataType_t dataType, const PartType partType,
|
||||
const unsigned char offset, const unsigned char length,
|
||||
const dataType_t dataType, const std::string unit,
|
||||
const std::string comment, const unsigned int divisor)
|
||||
: NumericDataField(name, partType, offset, length, dataType, unit, comment),
|
||||
m_divisor(divisor * dataType.divisor) {}
|
||||
const unsigned int divisor)
|
||||
: NumericDataField(name, comment, unit, dataType, partType, offset, length,
|
||||
(dataType.numBits%8) != 0 ? dataType.precisionOrFirstBit : 0),
|
||||
m_divisor(divisor) {}
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~NumberDataField() {}
|
||||
|
||||
protected:
|
||||
virtual result_t readSymbols(SymbolString& input, std::ostringstream& output);
|
||||
virtual result_t writeSymbols(std::istringstream& input, SymbolString& output);
|
||||
|
||||
virtual result_t derive(std::string name, std::string comment,
|
||||
std::string unit, const PartType partType, unsigned char offset,
|
||||
unsigned int divisor, std::map<unsigned int, std::string> values,
|
||||
std::vector<SingleDataField*>& fields);
|
||||
virtual result_t readSymbols(SymbolString& input, unsigned char baseOffset, std::ostringstream& output);
|
||||
virtual result_t writeSymbols(std::istringstream& input, unsigned char baseOffset, SymbolString& output);
|
||||
|
||||
/** the combined divisor to apply on the value, or 1 for none. */
|
||||
const unsigned int m_divisor;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief A numeric data field with a list of value=text assignments and a string representation.
|
||||
*/
|
||||
class ValueListDataField : public NumericDataField
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructs a new instance.
|
||||
* @param name the field name.
|
||||
* @param comment the field comment.
|
||||
* @param unit the value unit.
|
||||
* @param dataType the data type definition.
|
||||
* @param partType the message part in which the field is stored.
|
||||
* @param offset the offset to the first symbol in the message part in which the field is stored.
|
||||
* @param length the number of symbols in the message part in which the field is stored.
|
||||
* @param dataType the data type definition.
|
||||
* @param unit the value unit.
|
||||
* @param comment the field comment.
|
||||
* @param values the value=text assignments.
|
||||
*/
|
||||
ValueListDataField(const std::string name, const PartType partType,
|
||||
ValueListDataField(const std::string name, const std::string comment,
|
||||
const std::string unit, const dataType_t dataType, const PartType partType,
|
||||
const unsigned char offset, const unsigned char length,
|
||||
const dataType_t dataType, const std::string unit,
|
||||
const std::string comment, const std::map<unsigned int, std::string> values)
|
||||
: NumericDataField(name, partType, offset, length, dataType, unit, comment),
|
||||
m_values(values) {}
|
||||
const std::map<unsigned int, std::string> values)
|
||||
: NumericDataField(name, comment, unit, dataType, partType, offset, length,
|
||||
(dataType.numBits%8) != 0 ? dataType.precisionOrFirstBit : 0),
|
||||
m_values(values) {}
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~ValueListDataField() {}
|
||||
|
||||
protected:
|
||||
virtual result_t readSymbols(SymbolString& input, std::ostringstream& output);
|
||||
virtual result_t writeSymbols(std::istringstream& input, SymbolString& output);
|
||||
|
||||
virtual result_t derive(std::string name, std::string comment,
|
||||
std::string unit, const PartType partType, unsigned char offset,
|
||||
unsigned int divisor, std::map<unsigned int, std::string> values,
|
||||
std::vector<SingleDataField*>& fields);
|
||||
virtual result_t readSymbols(SymbolString& input, unsigned char baseOffset, std::ostringstream& output);
|
||||
virtual result_t writeSymbols(std::istringstream& input, unsigned char baseOffset, SymbolString& output);
|
||||
|
||||
/** the value=text assignments. */
|
||||
std::map<unsigned int, std::string> m_values;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief A set of DataFields.
|
||||
*/
|
||||
class DataFieldSet : public DataField
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructs a new instance.
|
||||
* @param name the field name.
|
||||
* @param comment the field comment.
|
||||
* @param fields the list of SingleDataFields part of this set.
|
||||
*/
|
||||
DataFieldSet(const std::string name, const std::string comment,
|
||||
const std::vector<SingleDataField*> fields)
|
||||
: DataField(name, comment),
|
||||
m_fields(fields) {}
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~DataFieldSet();
|
||||
virtual unsigned char getNextOffset();
|
||||
virtual result_t derive(std::string name, std::string comment,
|
||||
std::string unit, const PartType partType, unsigned char offset,
|
||||
unsigned int divisor, std::map<unsigned int, std::string> values,
|
||||
std::vector<SingleDataField*>& fields);
|
||||
/**
|
||||
* @brief Returns the SingleDataField at the specified index.
|
||||
* @param index the index of the SingleDataField to return.
|
||||
* @return the 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 SingleDataField at the specified index.
|
||||
* @param index the index of the SingleDataField to return.
|
||||
* @return the 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 SingleDataFields in this set.
|
||||
* @return the number of available SingleDataField.
|
||||
*/
|
||||
size_t size() const { return m_fields.size(); }
|
||||
/**
|
||||
* @brief Reads the values from the master and/or slave @a SymbolString.
|
||||
* @param masterData the unescaped master data @a SymbolString for reading binary data.
|
||||
* @param slaveData the unescaped slave data @a SymbolString for reading binary data.
|
||||
* @param output the ostringstream to append the formatted value to.
|
||||
* @param vervose whether to prepend the name, append the unit (if present), and append
|
||||
* the comment in square brackets (if present).
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t read(SymbolString& masterData, SymbolString& slaveData, std::ostringstream& output,
|
||||
bool verbose=false, char separator=';');
|
||||
/**
|
||||
* @brief Writes the values to the master and/or slave @a SymbolString.
|
||||
* @param input the istringstream to parse the formatted value from.
|
||||
* @param masterData the unescaped master data @a SymbolString for writing binary data.
|
||||
* @param slaveData the unescaped slave data @a SymbolString for writing binary data.
|
||||
* @return RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t write(std::istringstream& input, SymbolString& masterData, SymbolString& slaveData,
|
||||
char separator=';');
|
||||
|
||||
protected:
|
||||
|
||||
/** the list of SingleDataFields part of this set. */
|
||||
std::vector<SingleDataField*> m_fields;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // LIBEBUS_DATA_H_
|
||||
|
||||
+241
-84
@@ -21,116 +21,273 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
int main ()
|
||||
void verify(bool expectFailMatch, std::string type, std::string input,
|
||||
bool match, std::string expectStr, std::string gotStr)
|
||||
{
|
||||
std::string checks[][4] = {
|
||||
//name;position(s);type;factor;unit;comment
|
||||
// {"temp;1;d2b;;°C;Aussentemperatur","temp=18.004 °C [Aussentemperatur]","10fe070009019258042126100714cc", "00"},
|
||||
// {"zeit;1;ttm;2;Uhr;","zeit=22:40 Uhr","10feffff0188", "00"},
|
||||
{"x;1-10;hex","53 70 65 69 63 68 65 72 20 20", "10fe07000a53706569636865722020", "00"},
|
||||
{"x;;bti","21:04:58","10fe070009580421", "00"},
|
||||
{"x;;bda","26.10.2014","10fe07000926100714", "00"},
|
||||
{"x;1-3;bda","26.10.2014","10fe070003261014", "00"},
|
||||
{"x;;hdy","Sun","10fe07000307", "00"},
|
||||
{"x;;bdy","Sun","10fe07000306", "00"},
|
||||
{"x;;d2b","18.004","10fe0700090112", "00"},
|
||||
{"x;;d2c","288.062","10fe0700090112", "00"},
|
||||
{"x;;ttm","22:40","10feffff0188", "00"},
|
||||
{"x;;bcd","26","10feffff0126", "00"},
|
||||
{"x;;bcd","-","10feffff01ff", "00"},
|
||||
{"x;;uch","38","10feffff0126", "00"},
|
||||
{"x;;sch","-90","10feffff01a6", "00"},
|
||||
{"x;;d1b","-90","10feffff01a6", "00"},
|
||||
{"x;;d1c","19.500","10feffff0127", "00"},
|
||||
{"x;;uin","38","10feffff022600", "00"},
|
||||
{"x;;sin","-90","10feffff02a6ff", "00"},
|
||||
{"x;;ulg","38","10feffff0426000000", "00"},
|
||||
{"x;;slg","-90","10feffff04a6ffffff", "00"},
|
||||
{"x;;flt","-0.090","10feffff02a6ff", "00"},
|
||||
{"x;1-9;str","hallo Du!","10feffff0868616c6c6f20447521", "00"},
|
||||
{"x;1-9;str","hallo Du ","10feffff0868616c6c6f20447520", "00"},
|
||||
{"new;1;uch;1=test,2=high,3=off,4=on","on","10feffff0104", "00"},
|
||||
if (expectFailMatch == true) {
|
||||
if (match == true)
|
||||
std::cout << " failed " << type << " match >" << input
|
||||
<< "< error: unexpectedly succeeded" << std::endl;
|
||||
else
|
||||
std::cout << " failed " << type << " match >" << input << "< OK"
|
||||
<< std::endl;
|
||||
}
|
||||
else if (match == true)
|
||||
std::cout << " " << type << " >" << input << "< OK" << std::endl;
|
||||
else
|
||||
std::cout << " " << type << " >" << input << "< error: got >" << gotStr
|
||||
<< "<, expected >" << expectStr << "<" << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string checks[][5] = {
|
||||
//name;[pos];type[;[divisor|values][;[unit][;[comment]]]], decoded value, master, slave, flags
|
||||
{"x;1-10;str", "Hallo, Du!", "10fe07000a48616c6c6f2c20447521", "00", ""},
|
||||
{"x;1-10;str", "Hallo, Du ", "10fe07000a48616c6c6f2c20447520", "00", ""},
|
||||
{"x;1-10;str", " ", "10fe07000a20202020202020202020", "00", ""},
|
||||
{"x;1-11;str", "", "10fe07000a20202020202020202020", "00", "rW"},
|
||||
{"x;;hex", "20", "10fe07000120", "00", ""},
|
||||
{"x;1-10;hex", "48 61 6c 6c 6f 2c 20 44 75 21", "10fe07000a48616c6c6f2c20447521", "00", ""},
|
||||
{"x;1-11;hex", "", "10fe07000a48616c6c6f2c20447521", "00", "rW"},
|
||||
{"x;;bda", "26.10.2014","10fe07000426100014", "00", ""},
|
||||
{"x;;bda", "01.01.2000","10fe07000401010000", "00", ""},
|
||||
{"x;;bda", "31.12.2099","10fe07000431120099", "00", ""},
|
||||
{"x;;bda", "", "10fe07000432100014", "00", "rw"},
|
||||
{"x;1-3;bda","26.10.2014","10fe070003261014", "00", ""},
|
||||
{"x;1-3;bda","01.01.2000","10fe070003010100", "00", ""},
|
||||
{"x;1-3;bda","31.12.2099","10fe070003311299", "00", ""},
|
||||
{"x;1-3;bda","", "10fe070003321299", "00", "rw"},
|
||||
{"x;;bti", "21:04:58", "10fe070003580421", "00", ""},
|
||||
{"x;;bti", "00:00:00", "10fe070003000000", "00", ""},
|
||||
{"x;;bti", "23:59:59", "10fe070003595923", "00", ""},
|
||||
{"x;;bti", "", "10fe070003605923", "00", "rw"},
|
||||
{"x;;htm", "21:04", "10fe0700021504", "00", ""},
|
||||
{"x;;htm", "00:00", "10fe0700020000", "00", ""},
|
||||
{"x;;htm", "23:59", "10fe070002173b", "00", ""},
|
||||
{"x;;htm", "24:00", "10fe0700021800", "00", ""},
|
||||
{"x;;htm", "", "10fe070002183b", "00", "rw"},
|
||||
{"x;;htm", "24:01", "10fe0700021801", "00", "rw"},
|
||||
{"x;;ttm", "22:40", "10fe07000188", "00", ""},
|
||||
{"x;;ttm", "00:00", "10fe07000100", "00", ""},
|
||||
{"x;;ttm", "23:50", "10fe0700018f", "00", ""},
|
||||
{"x;;ttm", "24:00", "10fe07000190", "00", ""},
|
||||
{"x;;ttm", "", "10fe07000191", "00", "rw"},
|
||||
{"x;;bdy", "Mon", "10fe07000300", "00", ""},
|
||||
{"x;;bdy", "Sun", "10fe07000306", "00", ""},
|
||||
{"x;;bdy", "", "10fe07000308", "00", "rw"},
|
||||
{"x;;hdy", "Mon", "10fe07000301", "00", ""},
|
||||
{"x;;hdy", "Sun", "10fe07000307", "00", ""},
|
||||
{"x;;hdy", "", "10fe07000308", "00", "rw"},
|
||||
{"x;;bcd", "26", "10feffff0126", "00", ""},
|
||||
{"x;;bcd", "0", "10feffff0100", "00", ""},
|
||||
{"x;;bcd", "99", "10feffff0199", "00", ""},
|
||||
{"x;;bcd", "-", "10feffff01ff", "00", ""},
|
||||
{"x;;bcd", "", "10feffff019a", "00", "rw"},
|
||||
{"x;;uch", "38", "10feffff0126", "00", ""},
|
||||
{"x;;uch", "0", "10feffff0100", "00", ""},
|
||||
{"x;;uch", "254", "10feffff01fe", "00", ""},
|
||||
{"x;;uch", "-", "10feffff01ff", "00", ""},
|
||||
{"x;;sch", "-90", "10feffff01a6", "00", ""},
|
||||
{"x;;sch", "0", "10feffff0100", "00", ""},
|
||||
{"x;;sch", "-1", "10feffff01ff", "00", ""},
|
||||
{"x;;sch", "-", "10feffff0180", "00", ""},
|
||||
{"x;;sch", "-127", "10feffff0181", "00", ""},
|
||||
{"x;;sch", "127", "10feffff017f", "00", ""},
|
||||
{"x;;d1b", "-90", "10feffff01a6", "00", ""},
|
||||
{"x;;d1b", "0", "10feffff0100", "00", ""},
|
||||
{"x;;d1b", "-1", "10feffff01ff", "00", ""},
|
||||
{"x;;d1b", "-", "10feffff0180", "00", ""},
|
||||
{"x;;d1b", "-127", "10feffff0181", "00", ""},
|
||||
{"x;;d1b", "127", "10feffff017f", "00", ""},
|
||||
{"x;;d1c", "19.5", "10feffff0127", "00", ""},
|
||||
{"x;;d1c", "0.0", "10feffff0100", "00", ""},
|
||||
{"x;;d1c", "100.0", "10feffff01c8", "00", ""},
|
||||
{"x;;d1c", "-", "10feffff01ff", "00", ""},
|
||||
{"x;;uin", "38", "10feffff022600", "00", ""},
|
||||
{"x;;uin", "0", "10feffff020000", "00", ""},
|
||||
{"x;;uin", "65534", "10feffff02feff", "00", ""},
|
||||
{"x;;uin", "-", "10feffff02ffff", "00", ""},
|
||||
{"x;;sin", "-90", "10feffff02a6ff", "00", ""},
|
||||
{"x;;sin", "0", "10feffff020000", "00", ""},
|
||||
{"x;;sin", "-1", "10feffff02ffff", "00", ""},
|
||||
{"x;;sin", "-", "10feffff020080", "00", ""},
|
||||
{"x;;sin", "-32767", "10feffff020180", "00", ""},
|
||||
{"x;;sin", "32767", "10feffff02ff7f", "00", ""},
|
||||
{"x;;flt", "-0.090", "10feffff02a6ff", "00", ""},
|
||||
{"x;;flt", "0.000", "10feffff020000", "00", ""},
|
||||
{"x;;flt", "-0.001", "10feffff02ffff", "00", ""},
|
||||
{"x;;flt", "-", "10feffff020080", "00", ""},
|
||||
{"x;;flt","-32.767", "10feffff020180", "00", ""},
|
||||
{"x;;flt", "32.767", "10feffff02ff7f", "00", ""},
|
||||
{"x;;d2b", "18.004", "10fe0700090112", "00", ""},
|
||||
{"x;;d2b", "0.000", "10feffff020000", "00", ""},
|
||||
{"x;;d2b", "-0.004", "10feffff02ffff", "00", ""},
|
||||
{"x;;d2b", "-", "10feffff020080", "00", ""},
|
||||
{"x;;d2b","-127.996","10feffff020180", "00", ""},
|
||||
{"x;;d2b", "127.996","10feffff02ff7f", "00", ""},
|
||||
{"x;;d2c", "288.06", "10fe0700090112", "00", ""},
|
||||
{"x;;d2c", "0.00", "10feffff020000", "00", ""},
|
||||
{"x;;d2c", "-0.06", "10feffff02ffff", "00", ""},
|
||||
{"x;;d2c", "-", "10feffff020080", "00", ""},
|
||||
{"x;;d2c","-2047.94","10feffff020180", "00", ""},
|
||||
{"x;;d2c", "2047.94","10feffff02ff7f", "00", ""},
|
||||
{"x;;ulg", "38", "10feffff0426000000", "00", ""},
|
||||
{"x;;ulg", "0", "10feffff0400000000", "00", ""},
|
||||
{"x;;ulg", "4294967294", "10feffff04feffffff", "00", ""},
|
||||
{"x;;ulg", "-", "10feffff04ffffffff", "00", ""},
|
||||
{"x;;slg", "-90", "10feffff04a6ffffff", "00", ""},
|
||||
{"x;;slg", "0", "10feffff0400000000", "00", ""},
|
||||
{"x;;slg", "-1", "10feffff04ffffffff", "00", ""},
|
||||
{"x;;bi3", "1", "10feffff0108", "00", ""},
|
||||
{"x;;bi3", "-", "10feffff0100", "00", ""},
|
||||
{"x;;bi3;0=off,1=on","on", "10feffff0108", "00", ""},
|
||||
{"x;;bi3;0=off,1=on","off","10feffff0100", "00", ""},
|
||||
{"x;;b34", "1", "10feffff0108", "00", ""},
|
||||
{"x;;b34", "-", "10feffff0100", "00", ""},
|
||||
{"x;;b34", "3", "10feffff0118", "00", ""},
|
||||
{"x;;b34;1=on","on", "10feffff0108", "00", ""},
|
||||
{"x;;b34;1=on","-", "10feffff0100", "00", ""},
|
||||
{"x;;b34;0=off,1=on,2=auto,3=eco","auto", "10feffff0110", "00", ""},
|
||||
{"x;;b34;0=off,1=on","on", "10feffff0108", "00", ""},
|
||||
{"x;;b34;0=off,1=on","off","10feffff0100", "00", ""},
|
||||
{"x;;uch;1=test,2=high,3=off,4=on","on","10feffff0104", "00", ""},
|
||||
{"x;s3;uch","3","1050ffff00", "03000003", ""},
|
||||
{"x;s3;uch","3","1050ffff00", "020000", "rW"},
|
||||
{"x;;d2b;;°C;Aussentemperatur","x=18.004 °C [Aussentemperatur]","10fe0700090112", "00", "v"},
|
||||
{"x;;bti;;;;y;;bda;;;;z;6;bdy", "21:04:58;26.10.2014;Sun","10fe07000758042126100614", "00", ""}, // combination
|
||||
{"x;;bi3;;;;y;;bi5", "1;-", "10feffff0108", "00", ""}, // bit combination
|
||||
{"x;;bi3;;;;y;;bi5", "1;1", "10feffff0128", "00", ""}, // bit combination
|
||||
{"x;;bi3;;;;y;;bi5", "-;1", "10feffff0120", "00", ""}, // bit combination
|
||||
{"x;;bi3;;;;y;;bi5", "-;-", "10feffff0100", "00", ""}, // bit combination
|
||||
{"x;;bi3;;;;y;;bi7;;;;t;;uch", "-;-;9","10feffff020009", "00", ""}, // bit combination, auto pos incr
|
||||
{"x;;bi3;;;;y;;bi5;;;;t;;uch", "-;-;9","10feffff020009", "00", "RW"}, // bit combination
|
||||
{"temp;;d2b;;°C;Aussentemperatur","","", "", "t"}, // template with relative pos
|
||||
{"x;;temp","18.004","10fe0700020112", "00", ""}, // reference to template
|
||||
{"tempoff;2;d2b;;°C;Aussentemperatur","","", "", "t"},// template with offset pos
|
||||
{"x;;tempoff","18.004","10fe070002ff0112", "00", "W"}, // reference to template
|
||||
{"relrel;;d2b;;;;y;;d1c","","", "", "t"}, // template struct with relative pos
|
||||
{"x;2;relrel","18.004;9.5","10fe070004ff011213", "00", "W"}, // reference to template struct
|
||||
{"reloff;;d2b;;;;y;1;d1c","","", "", "t"}, // template struct with relative+offset pos
|
||||
{"x;2;reloff","18.004;0.5","10fe070003130112", "00", "W"}, // reference to template struct
|
||||
{"offrel;2;d2b;;;;y;;d1c","","", "", "t"}, // template struct with offset+relative pos
|
||||
{"x;2;offrel","18.004;9.5","10fe070005fffe011213", "00", "W"}, // reference to template struct
|
||||
{"offoff;2;d2b;;;;y;1;d1c","","", "", "t"}, // template struct with offset pos
|
||||
{"x;2;offoff","18.004;9.5","10fe070004ff130112", "00", "W"}, // reference to template struct
|
||||
{"trelrel;;temp,temp","","", "", "t"}, // template struct with relative pos and ref to templates
|
||||
{"x;;trelrel","18.004;19.008","10fe07000401120213", "00", ""}, // reference to template struct
|
||||
{"x;2;trelrel","18.004;19.008","10fe070005ff01120213", "00", "W"}, // reference to template struct
|
||||
{"treloff;;temp,tempoff","","", "", "t"}, // template struct with relative+offset pos
|
||||
{"x;2;treloff","18.004;19.008","10fe070006ff0112fe0213", "00", "W"}, // reference to template struct
|
||||
{"toffrel;1;tempoff,temp","","", "", "t"}, // template struct with offset+relative pos
|
||||
{"x;2;toffrel","18.004;19.008","10fe070003fffe01120213", "00", "W"}, // reference to template struct
|
||||
{"toffoff;1;tempoff,tempoff","","", "", "t"}, // template struct with offset pos
|
||||
{"x;2;toffoff","18.004;19.008","10fe070003fffe0112fd0213", "00", "W"}, // reference to template struct
|
||||
};
|
||||
std::map<std::string, DataField*> predefined;
|
||||
std::vector<DataField*> fields;
|
||||
unsigned char nextPos;
|
||||
for (size_t i = 0; i < sizeof(checks)/sizeof(checks[0]); i++) {
|
||||
std::istringstream isstr(checks[i][0]);
|
||||
std::string expectStr = checks[i][1];
|
||||
SymbolString mstr = SymbolString(checks[i][2], false);
|
||||
SymbolString sstr = SymbolString(checks[i][3], false);
|
||||
std::map<std::string, DataField*> templates;
|
||||
DataField* fields = NULL;
|
||||
for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
|
||||
std::string check[5] = checks[i];
|
||||
std::istringstream isstr(check[0]);
|
||||
std::string expectStr = check[1];
|
||||
SymbolString mstr = SymbolString(check[2], false);
|
||||
SymbolString sstr = SymbolString(check[3], false);
|
||||
std::string flags = check[4];
|
||||
bool isSet = flags.find('s') != std::string::npos;
|
||||
bool failedRead = flags.find('r') != std::string::npos;
|
||||
bool failedReadMatch = flags.find('R') != std::string::npos;
|
||||
bool failedWrite = flags.find('w') != std::string::npos;
|
||||
bool failedWriteMatch = flags.find('W') != std::string::npos;
|
||||
bool verbose = flags.find('v') != std::string::npos;
|
||||
bool isTemplate = flags.find('t') != std::string::npos;
|
||||
std::string item;
|
||||
std::vector<std::string> entries;
|
||||
|
||||
while (std::getline(isstr, item, ';') != 0)
|
||||
entries.push_back(item);
|
||||
|
||||
if (fields != NULL) {
|
||||
delete fields;
|
||||
fields = NULL;
|
||||
}
|
||||
std::vector<std::string>::iterator it = entries.begin();
|
||||
nextPos = 0;
|
||||
result_t result = DataField::create(mstr[1], false, it, entries.end(), predefined, fields, nextPos);
|
||||
result_t result = DataField::create(it, entries.end(), templates, fields, isSet, isTemplate ? SYN : mstr[1]);
|
||||
|
||||
if (result != RESULT_OK) {
|
||||
std::cout << "create \"" << checks[i][0] << "\" failed: " << getResultCode(result) << std::endl;
|
||||
std::cout << "\"" << check[0] << "\": create error: "
|
||||
<< getResultCode(result) << std::endl;
|
||||
continue;
|
||||
}
|
||||
if (fields.empty() == true) {
|
||||
std::cout << "create \"" << checks[i][0] << "\" failed: empty" << std::endl;
|
||||
if (fields == NULL) {
|
||||
std::cout << "\"" << check[0] << "\": create error: empty" << std::endl;
|
||||
continue;
|
||||
}
|
||||
if (it != entries.end()) {
|
||||
std::cout << "\"" << check[0] << "\": create error: non-empty" << std::endl;
|
||||
continue;
|
||||
}
|
||||
std::cout << "\"" << check[0] << "\": create OK" << std::endl;
|
||||
if (isTemplate) {
|
||||
// store new template
|
||||
std::string name = fields->getName();
|
||||
std::map<std::string, DataField*>::iterator current = templates.find(name);
|
||||
if (current == templates.end()) {
|
||||
templates[name] = fields;
|
||||
} else {
|
||||
delete current->second;
|
||||
current->second = fields;
|
||||
}
|
||||
fields = NULL;
|
||||
continue;
|
||||
}
|
||||
std::cout << "create \"" << checks[i][0] << "\" successful" << std::endl;
|
||||
|
||||
DataField* field = fields.back();
|
||||
fields.pop_back();
|
||||
std::ostringstream output;
|
||||
result = field->read(mstr, sstr, output);
|
||||
if (result != RESULT_OK) {
|
||||
std::cout << "read \"" << checks[i][0] << "\" failed: " << getResultCode(result) << std::endl;
|
||||
SymbolString writeMstr = SymbolString(mstr.getDataStr().substr(0, 10), false);
|
||||
SymbolString writeSstr = SymbolString(sstr.getDataStr().substr(0, 2), false);
|
||||
result = fields->read(mstr, sstr, output, verbose);
|
||||
if (failedRead == true)
|
||||
if (result == RESULT_OK)
|
||||
std::cout << " failed read " << fields->getName() << " >"
|
||||
<< check[2] << "< error: unexpectedly succeeded" << std::endl;
|
||||
else
|
||||
std::cout << " failed read " << fields->getName() << " >"
|
||||
<< check[2] << "< OK" << std::endl;
|
||||
else if (result != RESULT_OK) {
|
||||
std::cout << " read " << fields->getName() << " >" << check[2] << "< error: "
|
||||
<< getResultCode(result) << std::endl;
|
||||
}
|
||||
else {
|
||||
std::string gotStr = output.str();
|
||||
bool match = strcasecmp(output.str().c_str(), expectStr.c_str()) == 0;
|
||||
verify(failedReadMatch, "read", check[2], match, expectStr, output.str());
|
||||
}
|
||||
|
||||
if (strcasecmp(gotStr.c_str(), expectStr.c_str()) == 0)
|
||||
std::cout << "read successful: " << gotStr << std::endl;
|
||||
else
|
||||
std::cout << "read invalid: got " << gotStr
|
||||
<< ", expected " << expectStr << std::endl;
|
||||
|
||||
SymbolString writeMstr = SymbolString(mstr.getDataStr().substr(0, 10), false);
|
||||
SymbolString writeSstr = SymbolString(sstr.getDataStr().substr(0, 2), false);
|
||||
|
||||
if (result != RESULT_OK) {
|
||||
std::cout << "create \"" << checks[i][0] << "\" failed: " << getResultCode(result) << std::endl;
|
||||
return 1;
|
||||
if (verbose == false) {
|
||||
std::istringstream input(expectStr);
|
||||
result = fields->write(input, writeMstr, writeSstr);
|
||||
if (failedWrite == true) {
|
||||
if (result == RESULT_OK)
|
||||
std::cout << " failed write " << fields->getName() << " >"
|
||||
<< expectStr << "< error: unexpectedly succeeded" << std::endl;
|
||||
else
|
||||
std::cout << " failed write " << fields->getName() << " >"
|
||||
<< expectStr << "< OK" << std::endl;
|
||||
}
|
||||
result = field->write(gotStr, writeMstr, writeSstr);
|
||||
if (result != RESULT_OK) {
|
||||
std::cout << "write \"" << checks[i][0] << "\" failed: " << getResultCode(result) << std::endl;
|
||||
else if (result != RESULT_OK) {
|
||||
std::cout << " write " << fields->getName() << " >"
|
||||
<< expectStr << "< error: " << getResultCode(result) << std::endl;
|
||||
}
|
||||
else {
|
||||
if (mstr == writeMstr && sstr == writeSstr)
|
||||
std::cout << "write successful" << std::endl;
|
||||
else {
|
||||
std::cout << "write invalid: ";
|
||||
if (mstr == writeMstr)
|
||||
std::cout << "master OK";
|
||||
else
|
||||
std::cout << "master got " << writeMstr.getDataStr() << ", expected " << mstr.getDataStr();
|
||||
|
||||
if (sstr == writeSstr)
|
||||
std::cout << ", slave OK";
|
||||
else
|
||||
std::cout << ", slave got " << writeSstr.getDataStr() << ", expected " << sstr.getDataStr();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
bool match = mstr == writeMstr && sstr == writeSstr;
|
||||
verify(failedWriteMatch, "write", expectStr, match, mstr.getDataStr() + " " + sstr.getDataStr(), writeMstr.getDataStr() + " " + writeSstr.getDataStr());
|
||||
}
|
||||
}
|
||||
delete field;
|
||||
while (fields.empty() == false) {
|
||||
field = fields.back();
|
||||
fields.pop_back();
|
||||
delete field; // TODO use me
|
||||
}
|
||||
delete fields;
|
||||
fields = NULL;
|
||||
}
|
||||
|
||||
for (std::map<std::string, DataField*>::iterator it = templates.begin(); it != templates.end(); it++)
|
||||
delete it->second;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user