introduced symbol_t, added SymbolString::dataAt() and ::isMaster(), renamed SymbolString::getDataStr() to getStr(), use size_t/ssize_t where appropriate, simplified by use of new SymbolString methods, corrected broadcast scan conversion, use override declaration

This commit is contained in:
john30
2017-03-04 14:01:20 +01:00
parent dfa0e6e08f
commit 18fc12499b
25 changed files with 806 additions and 862 deletions
+7 -7
View File
@@ -39,7 +39,7 @@ void contrib_tem_register() {
DataTypeList::getInstance()->add(new TemParamDataType("TEM_P"));
}
result_t TemParamDataType::derive(int divisor, unsigned char bitCount, NumberDataType* &derived) {
result_t TemParamDataType::derive(int divisor, size_t bitCount, NumberDataType* &derived) {
if (divisor == 0) {
divisor = 1;
}
@@ -53,8 +53,8 @@ result_t TemParamDataType::derive(int divisor, unsigned char bitCount, NumberDat
return RESULT_ERR_INVALID_ARG;
}
result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
result_t TemParamDataType::readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) {
unsigned int value = 0;
@@ -72,7 +72,7 @@ result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster,
return RESULT_OK;
}
int grp = 0, num = 0;
if (isMaster) {
if (input.isMaster()) {
grp = (value & 0x1f); // grp in bits 0...5
num = ((value >> 8) & 0x7f); // num in bits 8...13
} else {
@@ -91,8 +91,8 @@ result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster,
}
result_t TemParamDataType::writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
unsigned int value;
int grp, num;
string token;
@@ -128,7 +128,7 @@ result_t TemParamDataType::writeSymbols(istringstream& input,
if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
if (isMaster) {
if (output.isMaster()) {
value = grp | (num << 8); // grp in bits 0...5, num in bits 8...13
} else {
value = (grp << 7) | num; // grp in bits 7...11, num in bits 0...6
+6 -6
View File
@@ -50,17 +50,17 @@ class TemParamDataType : public NumberDataType {
: NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {}
// @copydoc
virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived);
virtual result_t derive(int divisor, size_t bitCount, NumberDataType* &derived) override;
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) override;
};
/**
+10 -12
View File
@@ -131,22 +131,20 @@ int main() {
ostringstream output;
MasterSymbolString writeMstr;
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
result = writeMstr.parseHex(mstr.getStr().substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << mstr.getStr().substr(0, 10) << "\" error: " << getResultCode(result) << endl;
error = true;
}
SlaveSymbolString writeSstr;
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
result = writeSstr.parseHex(sstr.getStr().substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl;
error = true;
}
result = fields->read(pt_masterData, mstr, 0, output, 0, -1, false);
result = fields->read(mstr, 0, output, 0, -1, false);
if (result >= RESULT_OK) {
result = fields->read(pt_slaveData, sstr, 0, output, 0, -1, !output.str().empty());
result = fields->read(sstr, 0, output, 0, -1, !output.str().empty());
}
if (failedRead) {
if (result >= RESULT_OK) {
@@ -167,9 +165,9 @@ int main() {
}
istringstream input(expectStr);
result = fields->write(input, pt_masterData, writeMstr, 0);
result = fields->write(input, writeMstr, 0);
if (result >= RESULT_OK) {
result = fields->write(input, pt_slaveData, writeSstr, 0);
result = fields->write(input, writeSstr, 0);
}
if (failedWrite) {
if (result >= RESULT_OK) {
@@ -186,8 +184,8 @@ int main() {
error = true;
} else {
bool match = mstr == writeMstr && sstr == writeSstr;
verify(failedWriteMatch, "write", expectStr, match, mstr.getDataStr() + " "
+ sstr.getDataStr(), writeMstr.getDataStr() + " " + writeSstr.getDataStr());
verify(failedWriteMatch, "write", expectStr, match, mstr.getStr() + " " + sstr.getStr(),
writeMstr.getStr() + " " + writeSstr.getStr());
}
delete fields;
fields = NULL;
+79 -104
View File
@@ -44,7 +44,7 @@ result_t DataField::create(vector<string>::iterator& it,
DataFieldTemplates* templates, DataField*& returnField,
const bool isWriteMessage,
const bool isTemplate, const bool isBroadcastOrMasterDestination,
const unsigned char maxFieldLength) {
const size_t maxFieldLength) {
vector<SingleDataField*> fields;
string firstName, firstComment;
result_t result = RESULT_OK;
@@ -188,7 +188,7 @@ result_t DataField::create(vector<string>::iterator& it,
templ = templates->get(token.substr(0, pos));
}
if (templ == NULL) { // basetype[:len]
unsigned char length;
size_t length;
string typeName;
if (pos == string::npos) {
length = 0; // no length specified
@@ -197,7 +197,7 @@ result_t DataField::create(vector<string>::iterator& it,
if (pos+2 == token.length() && token[pos+1] == '*') {
length = REMAIN_LEN;
} else {
length = (unsigned char)parseInt(token.substr(pos+1).c_str(), 10, 1, maxFieldLength, result);
length = (size_t)parseInt(token.substr(pos+1).c_str(), 10, 1, (unsigned int)maxFieldLength, result);
if (result != RESULT_OK) {
break;
}
@@ -271,16 +271,16 @@ string DataField::getDayName(int day) {
return dayNames[day];
}
result_t SingleDataField::create(const string id, const unsigned char length,
result_t SingleDataField::create(const string id, const size_t length,
const string name, const string comment, const string unit,
const PartType partType, int divisor, map<unsigned int, string> values,
const string constantValue, const bool verifyValue, SingleDataField* &returnField) {
DataType* dataType = DataTypeList::getInstance()->get(id, length == REMAIN_LEN ? (unsigned char)0 : length);
DataType* dataType = DataTypeList::getInstance()->get(id, length == REMAIN_LEN ? 0 : length);
if (!dataType) {
return RESULT_ERR_NOTFOUND;
}
unsigned char bitCount = dataType->getBitCount();
unsigned char byteCount = (unsigned char)((bitCount + 7) / 8);
size_t bitCount = dataType->getBitCount();
size_t byteCount = (bitCount + 7) / 8;
if (dataType->isAdjustableLength()) {
// check length
if ((bitCount % 8) != 0) {
@@ -291,7 +291,7 @@ result_t SingleDataField::create(const string id, const unsigned char length,
} else {
return RESULT_ERR_OUT_OF_RANGE; // invalid length
}
byteCount = (unsigned char)((bitCount + 7) / 8);
byteCount = (bitCount + 7) / 8;
} else if (length == 0) {
byteCount = 1; // default byte count: 1 byte
} else if (length <= byteCount || length == REMAIN_LEN) {
@@ -348,24 +348,16 @@ void SingleDataField::dump(ostream& output) {
}
result_t SingleDataField::read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName, signed char fieldIndex) {
if (partType != m_partType) {
return RESULT_EMPTY;
}
switch (m_partType) {
case pt_masterData:
offset = (unsigned char)(offset + 5); // skip QQ ZZ PB SB NN
break;
case pt_slaveData:
offset++; // skip NN
break;
default:
result_t SingleDataField::read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName, ssize_t fieldIndex) {
if (m_partType == pt_any) {
return RESULT_ERR_INVALID_PART;
}
if ((data.isMaster() ? pt_masterData : pt_slaveData) != m_partType) {
return RESULT_EMPTY;
}
bool remainder = m_length == REMAIN_LEN && m_dataType->isAdjustableLength();
if (offset + (remainder?1:m_length) > data.size()) {
if (offset + (remainder?1:m_length) > data.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
if (isIgnored() || (fieldName != NULL && (m_name != fieldName || fieldIndex > 0))) {
@@ -374,25 +366,17 @@ result_t SingleDataField::read(const PartType partType,
return m_dataType->readRawValue(data, offset, m_length, output);
}
result_t SingleDataField::read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
if (partType != m_partType) {
return RESULT_OK;
}
switch (m_partType) {
case pt_masterData:
offset = (unsigned char)(offset + 5); // skip QQ ZZ PB SB NN
break;
case pt_slaveData:
offset++; // skip NN
break;
default:
result_t SingleDataField::read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex,
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
if (m_partType == pt_any) {
return RESULT_ERR_INVALID_PART;
}
if ((data.isMaster() ? pt_masterData : pt_slaveData) != m_partType) {
return RESULT_OK;
}
bool remainder = m_length == REMAIN_LEN && m_dataType->isAdjustableLength();
if (offset + (remainder?1:m_length) > data.size()) {
if (offset + (remainder?1:m_length) > data.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
if (isIgnored() || (fieldName != NULL && (m_name != fieldName || fieldIndex > 0))) {
@@ -418,7 +402,7 @@ result_t SingleDataField::read(const PartType partType,
}
}
result_t result = readSymbols(data, m_partType == pt_masterData, offset, output, outputFormat);
result_t result = readSymbols(data, offset, output, outputFormat);
if (result != RESULT_OK) {
return result;
}
@@ -442,35 +426,27 @@ result_t SingleDataField::read(const PartType partType,
return RESULT_OK;
}
result_t SingleDataField::write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator, unsigned char* length) {
if (partType != m_partType) {
return RESULT_OK;
}
switch (m_partType) {
case pt_masterData:
offset = (unsigned char)(offset + 5); // skip QQ ZZ PB SB NN
break;
case pt_slaveData:
offset++; // skip NN
break;
default:
result_t SingleDataField::write(istringstream& input, SymbolString& data,
size_t offset, char separator, size_t* length) {
if (m_partType == pt_any) {
return RESULT_ERR_INVALID_PART;
}
return writeSymbols(input, (const unsigned char)offset, data, m_partType == pt_masterData, length);
if ((data.isMaster() ? pt_masterData : pt_slaveData) != m_partType) {
return RESULT_OK;
}
return writeSymbols(input, (const size_t)offset, data, length);
}
result_t SingleDataField::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
result_t SingleDataField::readSymbols(SymbolString& input,
const size_t offset,
ostringstream& output, OutputFormat outputFormat) {
return m_dataType->readSymbols(input, isMaster, offset, m_length, output, outputFormat);
return m_dataType->readSymbols(input, offset, m_length, output, outputFormat);
}
result_t SingleDataField::writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
return m_dataType->writeSymbols(input, offset, m_length, output, isMaster, usedLength);
const size_t offset,
SymbolString& output, size_t* usedLength) {
return m_dataType->writeSymbols(input, offset, m_length, output, usedLength);
}
SingleDataField* SingleDataField::clone() {
@@ -522,9 +498,9 @@ bool SingleDataField::hasField(const char* fieldName, bool numeric) {
return numeric == numericType && (fieldName == NULL || fieldName == m_name);
}
unsigned char SingleDataField::getLength(PartType partType, unsigned char maxLength) {
size_t SingleDataField::getLength(PartType partType, size_t maxLength) {
if (partType != m_partType) {
return (unsigned char)0;
return 0;
}
bool remainder = m_length == REMAIN_LEN && m_dataType->isAdjustableLength();
return remainder ? maxLength : m_length;
@@ -601,8 +577,8 @@ void ValueListDataField::dump(ostream& output) {
dumpString(output, m_comment);
}
result_t ValueListDataField::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
result_t ValueListDataField::readSymbols(SymbolString& input,
const size_t offset,
ostringstream& output, OutputFormat outputFormat) {
unsigned int value = 0;
@@ -633,8 +609,8 @@ result_t ValueListDataField::readSymbols(SymbolString& input, const bool isMaste
}
result_t ValueListDataField::writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
const size_t offset,
SymbolString& output, size_t* usedLength) {
NumberDataType* numType = reinterpret_cast<NumberDataType*>(m_dataType);
if (isIgnored()) {
// replacement value
@@ -711,11 +687,11 @@ void ConstantDataField::dump(ostream& output) {
dumpString(output, m_comment);
}
result_t ConstantDataField::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
result_t ConstantDataField::readSymbols(SymbolString& input,
const size_t offset,
ostringstream& output, OutputFormat outputFormat) {
ostringstream coutput;
result_t result = SingleDataField::readSymbols(input, isMaster, offset, coutput, 0);
result_t result = SingleDataField::readSymbols(input, offset, coutput, 0);
if (result != RESULT_OK) {
return result;
}
@@ -730,10 +706,10 @@ result_t ConstantDataField::readSymbols(SymbolString& input, const bool isMaster
}
result_t ConstantDataField::writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
const size_t offset,
SymbolString& output, size_t* usedLength) {
istringstream cinput(m_value);
return SingleDataField::writeSymbols(cinput, offset, output, isMaster, usedLength);
return SingleDataField::writeSymbols(cinput, offset, output, usedLength);
}
@@ -795,8 +771,8 @@ DataFieldSet* DataFieldSet::clone() {
return new DataFieldSet(m_name, m_comment, fields);
}
unsigned char DataFieldSet::getLength(PartType partType, unsigned char maxLength) {
unsigned char length = 0;
size_t DataFieldSet::getLength(PartType partType, size_t maxLength) {
size_t length = 0;
bool previousFullByteOffset[] = { true, true, true, true };
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
@@ -805,13 +781,13 @@ unsigned char DataFieldSet::getLength(PartType partType, unsigned char maxLength
if (!previousFullByteOffset[partType] && !field->hasFullByteOffset(false)) {
length--;
}
unsigned char fieldLength = field->getLength(partType, maxLength);
size_t fieldLength = field->getLength(partType, maxLength);
if (fieldLength >= maxLength) {
maxLength = 0;
} else {
maxLength = (unsigned char)(maxLength-fieldLength);
maxLength = maxLength - fieldLength;
}
length = (unsigned char)(length + fieldLength);
length = length + fieldLength;
previousFullByteOffset[partType] = field->hasFullByteOffset(true);
}
@@ -820,11 +796,11 @@ unsigned char DataFieldSet::getLength(PartType partType, unsigned char maxLength
return length;
}
string DataFieldSet::getName(signed char fieldIndex) {
string DataFieldSet::getName(ssize_t fieldIndex) {
if (fieldIndex < 0) {
return m_name;
}
if ((unsigned char)fieldIndex >= m_fields.size()) {
if ((size_t)fieldIndex >= m_fields.size()) {
return "";
}
if (m_uniqueNames) {
@@ -876,23 +852,23 @@ void DataFieldSet::dump(ostream& output) {
}
}
result_t DataFieldSet::read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName, signed char fieldIndex) {
result_t DataFieldSet::read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName, ssize_t fieldIndex) {
bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0;
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
SingleDataField* field = *it;
if (partType != pt_any && field->getPartType() != partType) {
if (field->getPartType() != partType) {
continue;
}
if (!previousFullByteOffset && !field->hasFullByteOffset(false)) {
offset--;
}
result_t result = field->read(partType, data, offset, output, fieldName, fieldIndex);
result_t result = field->read(data, offset, output, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
offset = (unsigned char)(offset + field->getLength(partType, (unsigned char)(data.size()-offset)));
offset += field->getLength(partType, data.getDataSize()-offset);
previousFullByteOffset = field->hasFullByteOffset(true);
if (result != RESULT_EMPTY) {
found = true;
@@ -915,17 +891,17 @@ result_t DataFieldSet::read(const PartType partType,
return RESULT_OK;
}
result_t DataFieldSet::read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
result_t DataFieldSet::read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex,
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0;
if (!m_uniqueNames && outputIndex < 0) {
outputIndex = 0;
}
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
SingleDataField* field = *it;
if (partType != pt_any && field->getPartType() != partType) {
if (field->getPartType() != partType) {
if (outputIndex >= 0 && !field->isIgnored()) {
outputIndex++;
}
@@ -934,12 +910,12 @@ result_t DataFieldSet::read(const PartType partType,
if (!previousFullByteOffset && !field->hasFullByteOffset(false)) {
offset--;
}
result_t result = field->read(partType, data, offset, output, outputFormat, outputIndex, leadingSeparator,
result_t result = field->read(data, offset, output, outputFormat, outputIndex, leadingSeparator,
fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
offset = (unsigned char)(offset + field->getLength(partType, (unsigned char)(data.size()-offset)));
offset += field->getLength(partType, data.getDataSize()-offset);
previousFullByteOffset = field->hasFullByteOffset(true);
if (result != RESULT_EMPTY) {
found = true;
@@ -973,23 +949,22 @@ result_t DataFieldSet::read(const PartType partType,
return RESULT_OK;
}
result_t DataFieldSet::write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator, unsigned char* length) {
result_t DataFieldSet::write(istringstream& input, SymbolString& data,
size_t offset, char separator, size_t* length) {
string token;
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
bool previousFullByteOffset = true;
unsigned char baseOffset = offset;
size_t baseOffset = offset;
for (vector<SingleDataField*>::iterator it = m_fields.begin(); it < m_fields.end(); it++) {
SingleDataField* field = *it;
if (partType != pt_any && field->getPartType() != partType) {
if (field->getPartType() != partType) {
continue;
}
if (!previousFullByteOffset && !field->hasFullByteOffset(false)) {
offset--;
}
result_t result;
unsigned char fieldLength;
size_t fieldLength;
if (m_fields.size() > 1) {
if (field->isIgnored()) {
token.clear();
@@ -997,19 +972,19 @@ result_t DataFieldSet::write(istringstream& input,
token.clear();
}
istringstream single(token);
result = (*it)->write(single, partType, data, offset, separator, &fieldLength);
result = (*it)->write(single, data, offset, separator, &fieldLength);
} else {
result = (*it)->write(input, partType, data, offset, separator, &fieldLength);
result = (*it)->write(input, data, offset, separator, &fieldLength);
}
if (result != RESULT_OK) {
return result;
}
offset = (unsigned char)(offset+fieldLength);
offset += fieldLength;
previousFullByteOffset = field->hasFullByteOffset(true);
}
if (length != NULL) {
*length = (unsigned char)(offset-baseOffset);
*length = offset-baseOffset;
}
return RESULT_OK;
}
+59 -77
View File
@@ -92,7 +92,7 @@ class DataField {
DataFieldTemplates* templates, DataField*& returnField,
const bool isWriteMessage,
const bool isTemplate, const bool isBroadcastOrMasterDestination,
const unsigned char maxFieldLength = MAX_POS);
const size_t maxFieldLength = MAX_POS);
/**
* Dump the @a string optionally embedded in @a TEXT_SEPARATOR to the output.
@@ -115,7 +115,7 @@ class DataField {
* @param maxLength the maximum length for calculating remainder of input.
* @return the length of this field (or contained fields) in bytes.
*/
virtual unsigned char getLength(PartType partType, unsigned char maxLength = MAX_LEN) = 0;
virtual size_t getLength(PartType partType, size_t maxLength = MAX_LEN) = 0;
/**
* Derive a new @a DataField from this field.
@@ -138,7 +138,7 @@ class DataField {
* @param fieldIndex the index of the field, or -1 for this.
* @return the field name, or the index as string if not unique or not available.
*/
virtual string getName(signed char fieldIndex = -1) { return m_name; }
virtual string getName(ssize_t fieldIndex = -1) { return m_name; }
/**
* Get the field comment.
@@ -162,7 +162,6 @@ class DataField {
/**
* Reads the numeric value from the @a SymbolString.
* @param partType the @a PartType of the data.
* @param data the data @a SymbolString for reading binary data.
* @param offset the additional offset to add for reading binary data.
* @param output the variable in which to store the numeric value.
@@ -173,13 +172,11 @@ class DataField {
* not match or ignored, or due to @a fieldName or @a fieldIndex),
* or an error code.
*/
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName = NULL, signed char fieldIndex = -1) = 0;
virtual result_t read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName = NULL, ssize_t fieldIndex = -1) = 0;
/**
* Reads the value from the @a SymbolString.
* @param partType the @a PartType of the data.
* @param data the data @a SymbolString for reading binary data.
* @param offset the additional offset to add for reading binary data.
* @param output the @a ostringstream to append the formatted value to.
@@ -192,24 +189,21 @@ class DataField {
* or @a RESULT_EMPTY if the field was skipped (either ignored or due to @a fieldName or @a fieldIndex),
* or an error code.
*/
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1) = 0;
virtual result_t read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1) = 0;
/**
* Writes the value to the master or slave @a SymbolString.
* @param input the @a istringstream to parse the formatted value from.
* @param partType the @a PartType of the data.
* @param data the unescaped data @a SymbolString for writing binary data.
* @param offset the additional offset to add for writing binary data.
* @param separator the separator character between multiple fields.
* @param length the variable in which to store the used length in bytes, or NULL.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator = UI_FIELD_SEPARATOR, unsigned char* length = NULL) = 0;
virtual result_t write(istringstream& input, SymbolString& data,
size_t offset, char separator = UI_FIELD_SEPARATOR, size_t* length = NULL) = 0;
protected:
@@ -237,7 +231,7 @@ class SingleDataField : public DataField {
*/
SingleDataField(const string name, const string comment,
const string unit, DataType* dataType, const PartType partType,
const unsigned char length)
const size_t length)
: DataField(name, comment),
m_unit(unit), m_dataType(dataType), m_partType(partType),
m_length(length) {}
@@ -248,7 +242,7 @@ class SingleDataField : public DataField {
virtual ~SingleDataField() {}
// @copydoc
virtual SingleDataField* clone();
virtual SingleDataField* clone() override;
/**
* Factory method for creating a new @a SingleDataField instance derived from a base type.
@@ -266,7 +260,7 @@ class SingleDataField : public DataField {
* @return @a RESULT_OK on success, or an error code.
* Note: the caller needs to free the created instance.
*/
static result_t create(const string id, const unsigned char length,
static result_t create(const string id, const size_t length,
const string name, const string comment, const string unit,
const PartType partType, int divisor, map<unsigned int, string> values,
const string constantValue, const bool verifyValue, SingleDataField* &returnField);
@@ -290,13 +284,13 @@ class SingleDataField : public DataField {
PartType getPartType() const { return m_partType; }
// @copydoc
virtual unsigned char getLength(PartType partType, unsigned char maxLength = MAX_LEN);
virtual size_t getLength(PartType partType, size_t maxLength = MAX_LEN) override;
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType,
int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields);
vector<SingleDataField*>& fields) override;
/**
* Get whether this field uses a full byte offset.
@@ -307,40 +301,36 @@ class SingleDataField : public DataField {
bool hasFullByteOffset(bool after);
// @copydoc
virtual void dump(ostream& output);
virtual void dump(ostream& output) override;
// @copydoc
virtual bool hasField(const char* fieldName, bool numeric);
virtual bool hasField(const char* fieldName, bool numeric) override;
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName = NULL, signed char fieldIndex = -1);
virtual result_t read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName = NULL, ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
virtual result_t read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator = UI_FIELD_SEPARATOR, unsigned char* length = NULL);
virtual result_t write(istringstream& input, SymbolString& data,
size_t offset, char separator = UI_FIELD_SEPARATOR, size_t* length = NULL) override;
protected:
/**
* Internal method for reading the field from a @a SymbolString.
* @param input the @a SymbolString to read the binary value from.
* @param isMaster whether the @a SymbolString is the master part.
* @param offset the offset in the @a SymbolString.
* @param output the ostringstream to append the formatted value to.
* @param outputFormat the @a OutputFormat options to use.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
virtual result_t readSymbols(SymbolString& input,
const size_t offset,
ostringstream& output, OutputFormat outputFormat);
/**
@@ -348,13 +338,12 @@ class SingleDataField : public DataField {
* @param input the @a istringstream to parse the formatted value from.
* @param offset the offset in the @a SymbolString.
* @param output the @a SymbolString to write the binary value to.
* @param isMaster whether the @a SymbolString is the master part.
* @param usedLength the variable in which to store the used length in bytes, or NULL.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset,
SymbolString& output, size_t* usedLength);
/** the value unit. */
const string m_unit;
@@ -366,7 +355,7 @@ class SingleDataField : public DataField {
const PartType m_partType;
/** the number of symbols in the message part in which the field is stored. */
const unsigned char m_length;
const size_t m_length;
};
@@ -387,7 +376,7 @@ class ValueListDataField : public SingleDataField {
*/
ValueListDataField(const string name, const string comment,
const string unit, NumberDataType* dataType, const PartType partType,
const unsigned char length, const map<unsigned int, string> values)
const size_t length, const map<unsigned int, string> values)
: SingleDataField(name, comment, unit, dataType, partType, length),
m_values(values) {}
@@ -397,28 +386,26 @@ class ValueListDataField : public SingleDataField {
virtual ~ValueListDataField() {}
// @copydoc
virtual ValueListDataField* clone();
virtual ValueListDataField* clone() override;
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType, int divisor,
map<unsigned int, string> values,
vector<SingleDataField*>& fields);
vector<SingleDataField*>& fields) override;
// @copydoc
virtual void dump(ostream& output);
virtual void dump(ostream& output) override;
protected:
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input, const size_t offset,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
virtual result_t writeSymbols(istringstream& input, const size_t offset,
SymbolString& output, size_t* usedLength) override;
private:
@@ -445,7 +432,7 @@ class ConstantDataField : public SingleDataField {
*/
ConstantDataField(const string name, const string comment,
const string unit, DataType* dataType, const PartType partType,
const unsigned char length, const string value, const bool verify)
const size_t length, const string value, const bool verify)
: SingleDataField(name, comment, unit, dataType, partType, length),
m_value(value), m_verify(verify) {}
@@ -455,28 +442,26 @@ class ConstantDataField : public SingleDataField {
virtual ~ConstantDataField() {}
// @copydoc
virtual ConstantDataField* clone();
virtual ConstantDataField* clone() override;
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType, int divisor,
map<unsigned int, string> values,
vector<SingleDataField*>& fields);
vector<SingleDataField*>& fields) override;
// @copydoc
virtual void dump(ostream& output);
virtual void dump(ostream& output) override;
protected:
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input, const size_t offset,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
virtual result_t writeSymbols(istringstream& input, const size_t offset,
SymbolString& output, size_t* usedLength) override;
private:
@@ -538,19 +523,19 @@ class DataFieldSet : public DataField {
virtual ~DataFieldSet();
// @copydoc
virtual DataFieldSet* clone();
virtual DataFieldSet* clone() override;
// @copydoc
virtual unsigned char getLength(PartType partType, unsigned char maxLength = MAX_LEN);
virtual size_t getLength(PartType partType, size_t maxLength = MAX_LEN) override;
// @copydoc
virtual string getName(signed char fieldIndex = -1);
virtual string getName(ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t derive(string name, string comment,
string unit, const PartType partType,
int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields);
vector<SingleDataField*>& fields) override;
/**
* Returns the @a SingleDataField at the specified index.
@@ -583,26 +568,23 @@ class DataFieldSet : public DataField {
size_t size() const { return m_fields.size(); }
// @copydoc
virtual bool hasField(const char* fieldName, bool numeric);
virtual bool hasField(const char* fieldName, bool numeric) override;
// @copydoc
virtual void dump(ostream& output);
virtual void dump(ostream& output) override;
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
unsigned int& output, const char* fieldName = NULL, signed char fieldIndex = -1);
virtual result_t read(SymbolString& data, size_t offset,
unsigned int& output, const char* fieldName = NULL, ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t read(const PartType partType,
SymbolString& data, unsigned char offset,
ostringstream& output, OutputFormat outputFormat, signed char outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
virtual result_t read(SymbolString& data, size_t offset,
ostringstream& output, OutputFormat outputFormat, ssize_t outputIndex = -1,
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1) override;
// @copydoc
virtual result_t write(istringstream& input,
const PartType partType, SymbolString& data,
unsigned char offset, char separator = UI_FIELD_SEPARATOR, unsigned char* length = NULL);
virtual result_t write(istringstream& input, SymbolString& data,
size_t offset, char separator = UI_FIELD_SEPARATOR, size_t* length = NULL) override;
private:
@@ -658,7 +640,7 @@ class DataFieldTemplates : public FileReader {
// @copydoc
virtual result_t addFromFile(vector<string>::iterator& begin, const vector<string>::iterator end,
vector< vector<string> >* defaults, const string& defaultDest, const string& defaultCircuit,
const string& defaultSuffix, const string& filename, unsigned int lineNo);
const string& defaultSuffix, const string& filename, unsigned int lineNo) override;
/**
* Gets the template @a DataField instance with the specified name.
+118 -118
View File
@@ -91,7 +91,7 @@ void printErrorPos(ostream& out, vector<string>::iterator begin, const vector<st
}
bool DataType::dump(ostream& output, const unsigned char length, const bool appendSeparatorDivisor) const {
bool DataType::dump(ostream& output, const size_t length, const bool appendSeparatorDivisor) const {
output << m_id;
if (isAdjustableLength()) {
if (length == REMAIN_LEN) {
@@ -107,21 +107,21 @@ bool DataType::dump(ostream& output, const unsigned char length, const bool appe
}
result_t StringDataType::readRawValue(SymbolString& input, const unsigned char offset,
const unsigned char length, unsigned int& value) {
result_t StringDataType::readRawValue(SymbolString& input, const size_t offset,
const size_t length, unsigned int& value) {
return RESULT_EMPTY;
}
result_t StringDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char baseOffset, const unsigned char length,
result_t StringDataType::readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) {
size_t start = 0, count = length;
int incr = 1;
unsigned char ch;
symbol_t symbol;
bool terminated = false;
if (count == REMAIN_LEN && input.size() > baseOffset) {
count = input.size()-baseOffset;
} else if (baseOffset + count > input.size()) {
if (count == REMAIN_LEN && input.getDataSize() > offset) {
count = input.getDataSize() - offset;
} else if (offset + count > input.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
if (hasFlag(REV)) { // reverted binary representation (most significant byte first)
@@ -133,27 +133,27 @@ result_t StringDataType::readSymbols(SymbolString& input, const bool isMaster,
output << '"';
}
output << setfill('0') << (m_isHex ? hex : dec);
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
ch = input[baseOffset + offset];
for (size_t index = start, i = 0; i < count; index += incr, i++) {
symbol = input.dataAt(offset + index);
if (m_isHex) {
if (i > 0) {
output << ' ';
}
output << setw(2) << static_cast<unsigned>(ch);
output << setw(2) << static_cast<unsigned>(symbol);
} else {
if (ch == 0x00) {
if (symbol == 0x00) {
terminated = true;
} else if (!terminated) {
if (ch < 0x20) {
ch = (unsigned char)m_replacement;
} else if (!isprint(ch)) {
ch = '?';
if (symbol < 0x20) {
symbol = (symbol_t)m_replacement;
} else if (!isprint(symbol)) {
symbol = '?';
} else if (outputFormat & OF_JSON) {
if (ch == '"' || ch == '\\') {
if (symbol == '"' || symbol == '\\') {
output << '\\'; // escape
}
}
output << static_cast<char>(ch);
output << static_cast<char>(symbol);
}
}
}
@@ -164,8 +164,8 @@ result_t StringDataType::readSymbols(SymbolString& input, const bool isMaster,
}
result_t StringDataType::writeSymbols(istringstream& input,
unsigned char baseOffset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
size_t start = 0, count = length;
bool remainder = count == REMAIN_LEN && hasFlag(ADJ);
int incr = 1;
@@ -180,17 +180,17 @@ result_t StringDataType::writeSymbols(istringstream& input,
if (remainder) {
count = 1;
}
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
output[baseOffset + offset] = (unsigned char)m_replacement; // fill up with replacement
for (size_t index = start, i = 0; i < count; index += incr, i++) {
output.dataAt(offset + index) = (symbol_t)m_replacement; // fill up with replacement
}
if (usedLength != NULL) {
*usedLength = (unsigned char)count;
*usedLength = count;
}
return RESULT_OK;
}
result_t result;
size_t i = 0, offset;
for (offset = start; i < count; offset += incr, i++) {
size_t i = 0, index;
for (index = start; i < count; index += incr, i++) {
if (m_isHex) {
while (!input.eof() && input.peek() == ' ') {
input.get();
@@ -199,11 +199,11 @@ result_t StringDataType::writeSymbols(istringstream& input,
value = m_replacement; // fill up with replacement
} else {
token.clear();
token.push_back((unsigned char)input.get());
token.push_back((symbol_t)input.get());
if (input.eof()) {
return RESULT_ERR_INVALID_NUM; // too short hex value
}
token.push_back((unsigned char)input.get());
token.push_back((symbol_t)input.get());
if (input.eof()) {
return RESULT_ERR_INVALID_NUM; // too short hex value
}
@@ -224,41 +224,41 @@ result_t StringDataType::writeSymbols(istringstream& input,
}
if (remainder && input.eof() && i > 0) {
if (value == 0x00 && !m_isHex) {
output[baseOffset + offset] = 0;
offset += incr;
output.dataAt(offset + index) = 0;
index += incr;
}
break;
}
if (value > 0xff) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
output[baseOffset + offset] = (unsigned char)value;
output.dataAt(offset + index) = (symbol_t)value;
}
if (!remainder && i < count) {
return RESULT_ERR_EOF; // input too short
}
if (usedLength != NULL) {
*usedLength = (unsigned char)((offset-start)*incr);
*usedLength = (index-start)*incr;
}
return RESULT_OK;
}
result_t DateTimeDataType::readRawValue(SymbolString& input, const unsigned char offset,
const unsigned char length, unsigned int& value) {
result_t DateTimeDataType::readRawValue(SymbolString& input, const size_t offset,
const size_t length, unsigned int& value) {
return RESULT_EMPTY;
}
result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char baseOffset, const unsigned char length,
result_t DateTimeDataType::readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) {
size_t start = 0, count = length;
int incr = 1;
unsigned char ch, last = 0, hour = 0;
if (count == REMAIN_LEN && input.size() > baseOffset) {
count = input.size()-baseOffset;
} else if (baseOffset + count > input.size()) {
symbol_t symbol, last = 0, hour = 0;
if (count == REMAIN_LEN && input.getDataSize() > offset) {
count = input.getDataSize() - offset;
} else if (offset + count > input.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
if (hasFlag(REV)) { // reverted binary representation (most significant byte first)
@@ -270,20 +270,20 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
output << '"';
}
int type = (m_hasDate?2:0) | (m_hasTime?1:0);
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
for (size_t index = start, i = 0; i < count; index += incr, i++) {
if (length == 4 && i == 2 && m_hasDate) {
continue; // skip weekday in between
}
ch = input[baseOffset + offset];
if (hasFlag(BCD) && (hasFlag(REQ) || ch != m_replacement)) {
if ((ch & 0xf0) > 0x90 || (ch & 0x0f) > 0x09) {
symbol = input.dataAt(offset + index);
if (hasFlag(BCD) && (hasFlag(REQ) || symbol != m_replacement)) {
if ((symbol & 0xf0) > 0x90 || (symbol & 0x0f) > 0x09) {
return RESULT_ERR_OUT_OF_RANGE; // invalid BCD
}
ch = (unsigned char)((ch >> 4) * 10 + (ch & 0x0f));
symbol = (symbol_t)((symbol >> 4) * 10 + (symbol & 0x0f));
}
switch (type) {
case 2: // date only
if (!hasFlag(REQ) && ch == m_replacement) {
if (!hasFlag(REQ) && symbol == m_replacement) {
if (i + 1 != length) {
output << NULL_VALUE << ".";
break;
@@ -299,7 +299,7 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
if (i == 0) {
break;
}
int mjd = last + ch*256 + 15020; // 01.01.1900
int mjd = last + symbol*256 + 15020; // 01.01.1900
int y = static_cast<int>((mjd-15078.2)/365.25);
int m = static_cast<int>((mjd-14956.1-static_cast<int>(y*365.25))/30.6001);
int d = mjd-14956-static_cast<int>(y*365.25)-static_cast<int>(m*30.6001);
@@ -313,16 +313,16 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
break;
}
if (i + 1 == length) {
output << (2000 + ch);
} else if (ch < 1 || (i == 0 && ch > 31) || (i == 1 && ch > 12)) {
output << (2000 + symbol);
} else if (symbol < 1 || (i == 0 && symbol > 31) || (i == 1 && symbol > 12)) {
return RESULT_ERR_OUT_OF_RANGE; // invalid date
} else {
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(ch) << ".";
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(symbol) << ".";
}
break;
case 1: // time only
if (!hasFlag(REQ) && ch == m_replacement) {
if (!hasFlag(REQ) && symbol == m_replacement) {
if (length == 1) { // truncated time
output << NULL_VALUE << ":" << NULL_VALUE;
break;
@@ -335,10 +335,10 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
}
if (hasFlag(SPE)) { // minutes since midnight
if (i == 0) {
last = ch;
last = symbol;
continue;
}
int minutes = ch*256 + last;
int minutes = symbol*256 + last;
if (minutes > 24*60) {
return RESULT_ERR_OUT_OF_RANGE; // invalid value
}
@@ -347,31 +347,31 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
return RESULT_ERR_OUT_OF_RANGE; // invalid hour
}
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(hour);
ch = (unsigned char)(minutes % 60);
symbol = (symbol_t)(minutes % 60);
} else if (length == 1) { // truncated time
if (i == 0) {
ch = (unsigned char)(ch/(60/m_resolution)); // convert to hours
offset -= incr; // repeat for minutes
symbol = (symbol_t)(symbol/(60/m_resolution)); // convert to hours
index -= incr; // repeat for minutes
count++;
} else {
ch = (unsigned char)((ch % (60/m_resolution)) * m_resolution); // convert to minutes
symbol = (symbol_t)((symbol % (60/m_resolution)) * m_resolution); // convert to minutes
}
}
if (i == 0) {
if (ch > 24) {
if (symbol > 24) {
return RESULT_ERR_OUT_OF_RANGE; // invalid hour
}
hour = ch;
} else if (ch > 59 || (hour == 24 && ch > 0)) {
hour = symbol;
} else if (symbol > 59 || (hour == 24 && symbol > 0)) {
return RESULT_ERR_OUT_OF_RANGE; // invalid time
}
if (i > 0) {
output << ":";
}
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(ch);
output << setw(2) << dec << setfill('0') << static_cast<unsigned>(symbol);
break;
}
last = ch;
last = symbol;
}
if (outputFormat & OF_JSON) {
output << '"';
@@ -380,8 +380,8 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
}
result_t DateTimeDataType::writeSymbols(istringstream& input,
unsigned char baseOffset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
size_t start = 0, count = length;
bool remainder = count == REMAIN_LEN && hasFlag(ADJ);
int incr = 1;
@@ -396,19 +396,19 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
if (remainder) {
count = 1;
}
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
output[baseOffset + offset] = (unsigned char)m_replacement; // fill up with replacement
for (size_t index = start, i = 0; i < count; index += incr, i++) {
output.dataAt(offset + index) = (symbol_t)m_replacement; // fill up with replacement
}
if (usedLength != NULL) {
*usedLength = (unsigned char)count;
*usedLength = count;
}
return RESULT_OK;
}
result_t result;
size_t i = 0, offset;
size_t i = 0, index;
int type = (m_hasDate?2:0) | (m_hasTime?1:0);
bool skip = false;
for (offset = start; i < count; offset += skip ? 0 : incr, i++) {
for (index = start; i < count; index += skip ? 0 : incr, i++) {
skip = false;
switch (type) {
case 2: // date only
@@ -435,9 +435,9 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
int l = last <= 2 ? 1 : 0;
int mjd = 14956 + lastLast + static_cast<int>((y-l)*365.25) + static_cast<int>((last+1+l*12)*30.6001);
value = mjd - 15020; // 01.01.1900
output[baseOffset + offset] = (unsigned char)(value&0xff);
output.dataAt(offset + index) = (symbol_t)(value&0xff);
value >>= 8;
offset += incr;
index += incr;
skip = false;
break;
}
@@ -450,10 +450,10 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
int mjd = 14956 + lastLast + static_cast<int>((y-l)*365.25) + static_cast<int>((last+1+l*12)*30.6001);
int daysSinceSunday = (mjd+3) % 7; // Sun=0
if (hasFlag(BCD)) {
output[baseOffset + offset - incr] = (unsigned char)((6+daysSinceSunday) % 7); // Sun=0x06
output.dataAt(offset + index - incr) = (symbol_t)((6+daysSinceSunday) % 7); // Sun=0x06
} else {
// Sun=0x07
output[baseOffset + offset - incr] = (unsigned char)(daysSinceSunday == 0 ? 7 : daysSinceSunday);
output.dataAt(offset + index - incr) = (symbol_t)(daysSinceSunday == 0 ? 7 : daysSinceSunday);
}
}
if (value >= 2000) {
@@ -498,9 +498,9 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
break;
}
value += last*60;
output[baseOffset + offset] = (unsigned char)(value&0xff);
output.dataAt(offset + index) = (symbol_t)(value&0xff);
value >>= 8;
offset += incr;
index += incr;
} else if (length == 1) { // truncated time
if (i == 0) {
skip = true; // repeat for minutes
@@ -526,7 +526,7 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
if (value > 0xff) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
output[baseOffset + offset] = (unsigned char)value;
output.dataAt(offset + index) = (symbol_t)value;
}
}
@@ -534,14 +534,14 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
return RESULT_ERR_EOF; // input too short
}
if (usedLength != NULL) {
*usedLength = (unsigned char)((offset-start)*incr);
*usedLength = (index-start)*incr;
}
return RESULT_OK;
}
unsigned char NumberDataType::calcPrecision(const int divisor) {
unsigned char precision = 0;
size_t NumberDataType::calcPrecision(const int divisor) {
size_t precision = 0;
if (divisor > 1) {
for (unsigned int exp = 1; exp < MAX_DIVISOR; exp *= 10, precision++) {
if (exp >= (unsigned int)divisor) {
@@ -552,7 +552,7 @@ unsigned char NumberDataType::calcPrecision(const int divisor) {
return precision;
}
bool NumberDataType::dump(ostream& output, unsigned char length, const bool appendSeparatorDivisor) const {
bool NumberDataType::dump(ostream& output, size_t length, const bool appendSeparatorDivisor) const {
if (m_bitCount < 8) {
DataType::dump(output, m_bitCount, appendSeparatorDivisor);
} else {
@@ -573,7 +573,7 @@ bool NumberDataType::dump(ostream& output, unsigned char length, const bool appe
return false;
}
result_t NumberDataType::derive(int divisor, unsigned char bitCount, NumberDataType* &derived) {
result_t NumberDataType::derive(int divisor, size_t bitCount, NumberDataType* &derived) {
if (divisor == 0) {
divisor = 1;
}
@@ -627,13 +627,13 @@ result_t NumberDataType::derive(int divisor, unsigned char bitCount, NumberDataT
}
result_t NumberDataType::readRawValue(SymbolString& input,
unsigned char baseOffset, const unsigned char length,
size_t offset, const size_t length,
unsigned int& value) {
size_t start = 0, count = length;
int incr = 1;
unsigned char ch;
symbol_t symbol;
if (baseOffset + length > input.size()) {
if (offset + length > input.getDataSize()) {
return RESULT_ERR_INVALID_POS; // not enough data available
}
if (hasFlag(REV)) { // reverted binary representation (most significant byte first)
@@ -643,25 +643,25 @@ result_t NumberDataType::readRawValue(SymbolString& input,
value = 0;
unsigned int exp = 1;
for (size_t offset = start, i = 0; i < count; offset += incr, i++) {
ch = input[baseOffset + offset];
for (size_t index = start, i = 0; i < count; index += incr, i++) {
symbol = input.dataAt(offset + index);
if (hasFlag(BCD)) {
if (!hasFlag(REQ) && ch == (m_replacement & 0xff)) {
if (!hasFlag(REQ) && symbol == (m_replacement & 0xff)) {
value = m_replacement;
return RESULT_OK;
}
if (!hasFlag(HCD)) {
if ((ch & 0xf0) > 0x90 || (ch & 0x0f) > 0x09) {
if ((symbol & 0xf0) > 0x90 || (symbol & 0x0f) > 0x09) {
return RESULT_ERR_OUT_OF_RANGE; // invalid BCD
}
ch = (unsigned char)((ch >> 4) * 10 + (ch & 0x0f));
} else if (ch > 0x63) {
symbol = (symbol_t)((symbol >> 4) * 10 + (symbol & 0x0f));
} else if (symbol > 0x63) {
return RESULT_ERR_OUT_OF_RANGE; // invalid HCD
}
value += ch * exp;
value += symbol * exp;
exp *= 100;
} else {
value |= ch * exp;
value |= symbol * exp;
exp <<= 8;
}
}
@@ -675,13 +675,13 @@ result_t NumberDataType::readRawValue(SymbolString& input,
return RESULT_OK;
}
result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char baseOffset, const unsigned char length,
result_t NumberDataType::readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) {
unsigned int value = 0;
int signedValue;
result_t result = readRawValue(input, baseOffset, length, value);
result_t result = readRawValue(input, offset, length, value);
if (result != RESULT_OK) {
return result;
}
@@ -718,7 +718,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
# if HAVE_DIRECT_FLOAT_FORMAT == 2
value = __builtin_bswap32(value);
# endif
unsigned char* pval = (unsigned char*)&value;
symbol_t* pval = reinterpret_cast<symbol_t*>(&value);
val = *reinterpret_cast<float*>(pval);
#else
int exp = (value >> 23) & 0xff; // 8 bits, signed
@@ -741,7 +741,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
}
}
if (m_precision != 0) {
output << fixed << setprecision(m_precision+6);
output << fixed << setprecision(static_cast<int>(m_precision+6));
} else if (val == 0) {
output << fixed << setprecision(1);
}
@@ -754,7 +754,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
} else if (m_divisor <= 1) {
output << static_cast<unsigned>(value);
} else {
output << setprecision(m_precision)
output << setprecision(static_cast<int>(m_precision))
<< fixed << (static_cast<float>(value) / static_cast<float>(m_divisor));
}
return RESULT_OK;
@@ -772,27 +772,27 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
if (hasFlag(FIX) && hasFlag(BCD)) {
if (outputFormat & OF_JSON) {
output << '"';
output << setw(length * 2) << setfill('0');
output << setw(static_cast<int>(length * 2)) << setfill('0');
output << static_cast<signed>(signedValue) << setw(0);
output << '"';
return RESULT_OK;
}
output << setw(length * 2) << setfill('0');
output << setw(static_cast<int>(length * 2)) << setfill('0');
}
output << static_cast<signed>(signedValue) << setw(0);
} else {
output << setprecision(m_precision)
output << setprecision(static_cast<int>(m_precision))
<< fixed << (static_cast<float>(signedValue) / static_cast<float>(m_divisor));
}
return RESULT_OK;
}
result_t NumberDataType::writeRawValue(unsigned int value,
const unsigned char baseOffset, const unsigned char length,
SymbolString& output, unsigned char* usedLength) {
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
size_t start = 0, count = length;
int incr = 1;
unsigned char ch;
symbol_t symbol;
if (m_bitCount < 8 && (value & ~((1 << m_bitCount) - 1)) != 0) {
return RESULT_ERR_OUT_OF_RANGE;
@@ -806,25 +806,25 @@ result_t NumberDataType::writeRawValue(unsigned int value,
incr = -1;
}
for (size_t offset = start, i = 0, exp = 1; i < count; offset += incr, i++) {
for (size_t index = start, i = 0, exp = 1; i < count; index += incr, i++) {
if (hasFlag(BCD)) {
if (!hasFlag(REQ) && value == m_replacement) {
ch = m_replacement & 0xff;
symbol = m_replacement & 0xff;
} else {
ch = (unsigned char)((value / exp) % 100);
symbol = (symbol_t)((value / exp) % 100);
if (!hasFlag(HCD)) {
ch = (unsigned char)(((ch / 10) << 4) | (ch % 10));
symbol = (symbol_t)(((symbol / 10) << 4) | (symbol % 10));
}
}
exp *= 100;
} else {
ch = (value / exp) & 0xff;
symbol = (value / exp) & 0xff;
exp <<= 8;
}
if (offset == start && (m_bitCount % 8) != 0 && baseOffset + offset < output.size()) {
output[baseOffset + offset] |= ch;
if (index == start && (m_bitCount % 8) != 0 && offset + index < output.getDataSize()) {
output.dataAt(offset + index) |= symbol;
} else {
output[baseOffset + offset] = ch;
output.dataAt(offset + index) = symbol;
}
}
if (usedLength != NULL) {
@@ -834,8 +834,8 @@ result_t NumberDataType::writeRawValue(unsigned int value,
}
result_t NumberDataType::writeSymbols(istringstream& input,
const unsigned char baseOffset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) {
unsigned int value;
const char* str = input.str().c_str();
@@ -856,7 +856,7 @@ result_t NumberDataType::writeSymbols(istringstream& input,
}
#ifdef HAVE_DIRECT_FLOAT_FORMAT
float val = static_cast<float>(dvalue);
unsigned char* pval = (unsigned char*)&val;
symbol_t* pval = reinterpret_cast<symbol_t*>(&val);
value = *reinterpret_cast<int32_t*>(pval);
# if HAVE_DIRECT_FLOAT_FORMAT == 2
value = __builtin_bswap32(value);
@@ -938,7 +938,7 @@ result_t NumberDataType::writeSymbols(istringstream& input,
}
}
return writeRawValue(value, baseOffset, length, output, usedLength);
return writeRawValue(value, offset, length, output, usedLength);
}
@@ -1067,7 +1067,7 @@ void DataTypeList::clear() {
result_t DataTypeList::add(DataType* dataType) {
if (!dataType->isAdjustableLength()) {
ostringstream str;
unsigned char bitCount = dataType->getBitCount();
size_t bitCount = dataType->getBitCount();
str << dataType->getId() << LENGTH_SEPARATOR << static_cast<unsigned>(bitCount >= 8?bitCount/8:bitCount);
map<string, DataType*>::iterator it = m_typesByIdLength.find(str.str());
if (it != m_typesByIdLength.end()) {
@@ -1086,7 +1086,7 @@ result_t DataTypeList::add(DataType* dataType) {
return RESULT_OK;
}
DataType* DataTypeList::get(const string id, const unsigned char length) {
DataType* DataTypeList::get(const string id, const size_t length) {
DataType* dataType = NULL;
if (length > 0) {
ostringstream str;
+43 -45
View File
@@ -170,7 +170,7 @@ class DataType {
* @param replacement the replacement value (fill-up value for @a StringDataType, no replacement if equal to
* @a NumberDataType#minValue).
*/
DataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement)
DataType(const string id, const size_t bitCount, const uint16_t flags, const unsigned int replacement)
: m_id(id), m_bitCount(bitCount), m_flags(flags), m_replacement(replacement) {}
/**
@@ -186,7 +186,7 @@ class DataType {
/**
* @return the number of bits (maximum length if #ADJ flag is set).
*/
unsigned char getBitCount() const { return m_bitCount; }
size_t getBitCount() const { return m_bitCount; }
/**
* Check whether a flag is set.
@@ -224,7 +224,7 @@ class DataType {
* @param appendSeparatorDivisor whether to append a @a FIELD_SEPARATOR followed by the divisor (if available).
* @return true when a non-default divisor was written to the output.
*/
virtual bool dump(ostream& output, const unsigned char length, const bool appendSeparatorDivisor = true) const;
virtual bool dump(ostream& output, const size_t length, const bool appendSeparatorDivisor = true) const;
/**
* Internal method for reading the numeric raw value from a @a SymbolString.
@@ -235,21 +235,20 @@ class DataType {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t readRawValue(SymbolString& input,
const unsigned char offset, const unsigned char length,
const size_t offset, const size_t length,
unsigned int& value) = 0;
/**
* Internal method for reading the field from a @a SymbolString.
* @param input the @a SymbolString to read the binary value from.
* @param isMaster whether the @a SymbolString is the master part.
* @param offset the offset in the @a SymbolString.
* @param offset the offset in the data of the @a SymbolString.
* @param length the number of symbols to read.
* @param output the ostringstream to append the formatted value to.
* @param outputFormat the @a OutputFormat options to use.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) = 0;
/**
@@ -258,13 +257,12 @@ class DataType {
* @param offset the offset in the @a SymbolString.
* @param length the number of symbols to write, or @a REMAIN_LEN.
* @param output the @a SymbolString to write the binary value to.
* @param isMaster whether the @a SymbolString is the master part.
* @param usedLength the variable in which to store the used length in bytes, or NULL.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) = 0;
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) = 0;
protected:
@@ -272,7 +270,7 @@ class DataType {
const string m_id;
/** the number of bits (maximum length if #ADJ flag is set, must be multiple of 8 with flag #BCD). */
const unsigned char m_bitCount;
const size_t m_bitCount;
/** the combination of flags (like #BCD). */
const uint16_t m_flags;
@@ -296,7 +294,7 @@ class StringDataType : public DataType {
* @param replacement the replacement value (fill-up value).
* @param isHex true for hex digits instead of characters.
*/
StringDataType(const string id, const unsigned char bitCount, const uint16_t flags,
StringDataType(const string id, const size_t bitCount, const uint16_t flags,
const unsigned int replacement, bool isHex = false)
: DataType(id, bitCount, flags, replacement), m_isHex(isHex) {}
@@ -307,18 +305,18 @@ class StringDataType : public DataType {
// @copydoc
virtual result_t readRawValue(SymbolString& input,
const unsigned char offset, const unsigned char length,
unsigned int& value);
const size_t offset, const size_t length,
unsigned int& value) override;
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) override;
private:
@@ -342,7 +340,7 @@ class DateTimeDataType : public DataType {
* @param hasTime true if time part is present.
* @param resolution the the resolution in minutes for time types, or 1.
*/
DateTimeDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement,
DateTimeDataType(const string id, const size_t bitCount, const uint16_t flags, const unsigned int replacement,
const bool hasDate, const bool hasTime, const int16_t resolution)
: DataType(id, bitCount, flags, replacement), m_hasDate(hasDate), m_hasTime(hasTime),
m_resolution(resolution == 0 ? 1 : resolution) {}
@@ -369,18 +367,18 @@ class DateTimeDataType : public DataType {
// @copydoc
virtual result_t readRawValue(SymbolString& input,
const unsigned char offset, const unsigned char length,
unsigned int& value);
const size_t offset, const size_t length,
unsigned int& value) override;
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) override;
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) override;
private:
@@ -410,7 +408,7 @@ class NumberDataType : public DataType {
* @param maxValue the maximum raw value.
* @param divisor the divisor (negative for reciprocal).
*/
NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement,
NumberDataType(const string id, const size_t bitCount, const uint16_t flags, const unsigned int replacement,
const unsigned int minValue, const unsigned int maxValue, const int divisor)
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(minValue), m_maxValue(maxValue), m_divisor(divisor),
m_precision(calcPrecision(divisor)), m_firstBit(0), m_baseType(NULL) {}
@@ -424,7 +422,7 @@ class NumberDataType : public DataType {
* @param firstBit the offset to the first bit.
* @param divisor the divisor (negative for reciprocal).
*/
NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement,
NumberDataType(const string id, const size_t bitCount, const uint16_t flags, const unsigned int replacement,
const int16_t firstBit, const int divisor)
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1 << bitCount)-1), m_divisor(divisor),
m_precision(0), m_firstBit(firstBit), m_baseType(NULL) {}
@@ -440,10 +438,10 @@ class NumberDataType : public DataType {
* @param divisor the divisor (negative for reciprocal).
* @return the precision for formatting the value.
*/
static unsigned char calcPrecision(const int divisor);
static size_t calcPrecision(const int divisor);
// @copydoc
virtual bool dump(ostream& output, const unsigned char length, const bool appendSeparatorDivisor = true) const;
virtual bool dump(ostream& output, const size_t length, const bool appendSeparatorDivisor = true) const override;
/**
* Derive a new @a NumberDataType from this.
@@ -455,7 +453,7 @@ class NumberDataType : public DataType {
* not necessary.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived);
virtual result_t derive(int divisor, size_t bitCount, NumberDataType* &derived);
/**
* @return the minimum raw value.
@@ -475,7 +473,7 @@ class NumberDataType : public DataType {
/**
* @return the precision for formatting the value.
*/
unsigned char getPrecision() const { return m_precision; }
size_t getPrecision() const { return m_precision; }
/**
* @return the offset to the first bit.
@@ -484,13 +482,13 @@ class NumberDataType : public DataType {
// @copydoc
virtual result_t readRawValue(SymbolString& input,
const unsigned char offset, const unsigned char length,
unsigned int& value);
const size_t offset, const size_t length,
unsigned int& value) override;
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
virtual result_t readSymbols(SymbolString& input,
const size_t offset, const size_t length,
ostringstream& output, OutputFormat outputFormat) override;
/**
* Internal method for writing the numeric raw value to a @a SymbolString.
@@ -503,13 +501,13 @@ class NumberDataType : public DataType {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t writeRawValue(unsigned int value,
const unsigned char offset, const unsigned char length,
SymbolString& output, unsigned char* usedLength = NULL);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength = NULL);
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
const size_t offset, const size_t length,
SymbolString& output, size_t* usedLength) override;
private:
@@ -523,7 +521,7 @@ class NumberDataType : public DataType {
const int m_divisor;
/** the precision for formatting the value. */
const unsigned char m_precision;
const size_t m_precision;
/** the offset to the first bit. */
const int16_t m_firstBit;
@@ -582,7 +580,7 @@ class DataTypeList {
* @return the @a DataType instance, or NULL if not available.
* Note: the caller may not free the instance.
*/
DataType* get(const string id, const unsigned char length = 0);
DataType* get(const string id, const size_t length = 0);
/**
* Returns an iterator pointing to the first ID/@a DataType pair.
+9 -9
View File
@@ -98,7 +98,7 @@ bool Device::isValid() {
return m_fd != -1;
}
result_t Device::send(const unsigned char value) {
result_t Device::send(const symbol_t value) {
if (!isValid()) {
return RESULT_ERR_DEVICE;
}
@@ -111,7 +111,7 @@ result_t Device::send(const unsigned char value) {
return RESULT_OK;
}
result_t Device::recv(const unsigned int timeout, unsigned char& value) {
result_t Device::recv(const unsigned int timeout, symbol_t& value) {
if (!isValid()) {
return RESULT_ERR_DEVICE;
}
@@ -268,13 +268,13 @@ result_t NetworkDevice::open() {
int cnt;
if (ioctl(m_fd, FIONREAD, &cnt) >= 0 && cnt > 1) {
// skip buffered input
unsigned char buf[256];
symbol_t buf[256];
while (::read(m_fd, &buf, 256) > 0) {
}
}
if (m_bufSize == 0) {
m_bufSize = MAX_LEN+1;
m_buffer = (unsigned char*)malloc(m_bufSize);
m_buffer = reinterpret_cast<symbol_t*>(malloc(m_bufSize));
if (!m_buffer) {
m_bufSize = 0;
}
@@ -287,7 +287,7 @@ result_t NetworkDevice::open() {
}
void NetworkDevice::checkDevice() {
unsigned char value;
symbol_t value;
ssize_t c = ::recv(m_fd, &value, 1, MSG_PEEK | MSG_DONTWAIT);
if (c == 0 || (c < 0 && errno != EAGAIN)) {
m_bufLen = 0; // flush read buffer
@@ -299,15 +299,15 @@ bool NetworkDevice::available() {
return m_buffer && m_bufLen > 0;
}
ssize_t NetworkDevice::write(const unsigned char value) {
ssize_t NetworkDevice::write(const symbol_t value) {
m_bufLen = 0; // flush read buffer
return Device::write(value);
}
ssize_t NetworkDevice::read(unsigned char& value) {
ssize_t NetworkDevice::read(symbol_t& value) {
if (available()) {
value = m_buffer[m_bufPos];
m_bufPos = (unsigned char)((m_bufPos+1)%m_bufSize);
m_bufPos = (m_bufPos+1)%m_bufSize;
m_bufLen--;
return 1;
}
@@ -318,7 +318,7 @@ ssize_t NetworkDevice::read(unsigned char& value) {
}
value = m_buffer[0];
m_bufPos = 1;
m_bufLen = (unsigned char)(size-1);
m_bufLen = size-1;
return size;
}
return Device::read(value);
+21 -20
View File
@@ -26,6 +26,7 @@
#include <iostream>
#include <fstream>
#include "lib/ebus/result.h"
#include "lib/ebus/symbol.h"
namespace ebusd {
@@ -49,11 +50,11 @@ class DeviceListener {
virtual ~DeviceListener() {}
/**
* Listener method that is called when a data byte was received/sent.
* @param byte the data byte received/sent.
* Listener method that is called when a symbol was received/sent.
* @param symbol the received/sent symbol.
* @param received @a true on reception, @a false on sending.
*/
virtual void notifyDeviceData(const unsigned char byte, bool received) = 0; // abstract
virtual void notifyDeviceData(const symbol_t symbol, bool received) = 0; // abstract
};
@@ -112,7 +113,7 @@ class Device {
* @param value the byte value to write.
* @return the @a result_t code.
*/
result_t send(const unsigned char value);
result_t send(const symbol_t value);
/**
* Read a single byte from the device.
@@ -120,7 +121,7 @@ class Device {
* @param value the reference in which the received byte value is stored.
* @return the result_t code.
*/
result_t recv(const unsigned int timeout, unsigned char& value);
result_t recv(const unsigned int timeout, symbol_t& value);
/**
* Return the device name.
@@ -164,14 +165,14 @@ class Device {
* @param value the byte value to write.
* @return the number of bytes written, or -1 on error.
*/
virtual ssize_t write(const unsigned char value) { return ::write(m_fd, &value, 1); }
virtual ssize_t write(const symbol_t value) { return ::write(m_fd, &value, 1); }
/**
* Read a single byte.
* @param value the reference in which the read byte value is stored.
* @return the number of bytes read, or -1 on error.
*/
virtual ssize_t read(unsigned char& value) { return ::read(m_fd, &value, 1); }
virtual ssize_t read(symbol_t& value) { return ::read(m_fd, &value, 1); }
/** the device name (e.g. "/dev/ttyUSB0" for serial, "127.0.0.1:1234" for network). */
const char* m_name;
@@ -210,15 +211,15 @@ class SerialDevice : public Device {
: Device(name, checkDevice, readOnly, initialSend) {}
// @copydoc
virtual result_t open();
virtual result_t open() override;
// @copydoc
virtual void close();
virtual void close() override;
protected:
// @copydoc
virtual void checkDevice();
virtual void checkDevice() override;
private:
@@ -245,24 +246,24 @@ class NetworkDevice : public Device {
m_buffer(NULL), m_bufSize(0), m_bufLen(0), m_bufPos(0) {}
// @copydoc
virtual unsigned int getLatency() const { return 10000; }
virtual unsigned int getLatency() const override { return 10000; }
// @copydoc
virtual result_t open();
virtual result_t open() override;
protected:
// @copydoc
virtual void checkDevice();
virtual void checkDevice() override;
// @copydoc
virtual bool available();
virtual bool available() override;
// @copydoc
virtual ssize_t write(const unsigned char value);
virtual ssize_t write(const symbol_t value) override;
// @copydoc
virtual ssize_t read(unsigned char& value);
virtual ssize_t read(symbol_t& value) override;
private:
@@ -273,16 +274,16 @@ class NetworkDevice : public Device {
const bool m_udp;
/** the buffer memory, or NULL. */
unsigned char* m_buffer;
symbol_t* m_buffer;
/** the buffer size. */
unsigned char m_bufSize;
size_t m_bufSize;
/** the buffer fill length. */
unsigned char m_bufLen;
size_t m_bufLen;
/** the buffer read position. */
unsigned char m_bufPos;
size_t m_bufPos;
};
} // namespace ebusd
+4 -4
View File
@@ -66,7 +66,7 @@ extern void printErrorPos(ostream& out, vector<string>::iterator begin, const ve
vector<string>::iterator pos, string filename, size_t lineNo, result_t result);
extern unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue,
result_t& result, unsigned int* length);
result_t& result, size_t* length);
/**
* An abstract class that support reading definitions from a file.
@@ -105,7 +105,7 @@ class FileReader {
if (lastSep != string::npos) { // potential destination address, matches "^ZZ."
// extract defaultDest, defaultCircuit, defaultSuffix from filename:
// ZZ.IDENT[.CIRCUIT][.SUFFIX].*csv
unsigned char checkDest;
symbol_t checkDest;
string checkIdent, useCircuit, useSuffix;
unsigned int checkSw, checkHw;
if (extractDefaultsFromFilename(filename.substr(lastSep+1), checkDest, checkIdent, useCircuit, useSuffix,
@@ -320,7 +320,7 @@ class FileReader {
* @param hardware the hardware version part HWXXXX (BCD digits, set to @a UINT_MAX if not present).
* @return true if at least the address and the identification part were extracted, false otherwise.
*/
static bool extractDefaultsFromFilename(string name, unsigned char& dest, string& ident, string& circuit,
static bool extractDefaultsFromFilename(string name, symbol_t& dest, string& ident, string& circuit,
string& suffix, unsigned int& software, unsigned int& hardware) {
ident = circuit = suffix = "";
software = hardware = UINT_MAX;
@@ -332,7 +332,7 @@ class FileReader {
return false; // missing "ZZ."
}
result_t result = RESULT_OK;
dest = (unsigned char)parseInt(name.substr(0, pos).c_str(), 16, 0, 0xff, result, NULL);
dest = (symbol_t)parseInt(name.substr(0, pos).c_str(), 16, 0, 0xff, result, NULL);
if (result != RESULT_OK || !isValidAddress(dest)) {
return false; // invalid "ZZ"
}
+132 -128
View File
@@ -60,10 +60,10 @@ extern DataFieldTemplates* getTemplates(const string filename);
Message::Message(const string circuit, const string level, const string name,
const bool isWrite, const bool isPassive, const string comment,
const unsigned char srcAddress, const unsigned char dstAddress,
const vector<unsigned char> id,
const symbol_t srcAddress, const symbol_t dstAddress,
const vector<symbol_t> id,
DataField* data, const bool deleteData,
const unsigned char pollPriority,
const size_t pollPriority,
Condition* condition)
: m_circuit(circuit), m_level(level), m_name(name), m_isWrite(isWrite),
m_isPassive(isPassive), m_comment(comment),
@@ -81,7 +81,7 @@ Message::Message(const string circuit, const string level, const string name,
Message::Message(const string circuit, const string level, const string name,
const bool isWrite, const bool isPassive,
const unsigned char pb, const unsigned char sb,
const symbol_t pb, const symbol_t sb,
DataField* data, const bool deleteData)
: m_circuit(circuit), m_level(level), m_name(name), m_isWrite(isWrite),
m_isPassive(isPassive), m_comment(),
@@ -135,9 +135,9 @@ string getDefault(const string value, vector<string>* defaults, size_t pos, bool
return defaultStr.substr(0, insertPos)+value+defaultStr.substr(insertPos+1);
}
uint64_t Message::createKey(const vector<unsigned char> id,
uint64_t Message::createKey(const vector<symbol_t> id,
const bool isWrite, const bool isPassive,
const unsigned char srcAddress, const unsigned char dstAddress) {
const symbol_t srcAddress, const symbol_t dstAddress) {
uint64_t key = (uint64_t)(id.size()-2) << (8 * 7 + 5);
if (isPassive) {
key |= (uint64_t)getMasterNumber(srcAddress) << (8 * 7); // 0..25
@@ -146,7 +146,7 @@ uint64_t Message::createKey(const vector<unsigned char> id,
}
key |= (uint64_t)dstAddress << (8 * 6);
int exp = 5;
for (vector<unsigned char>::const_iterator it = id.begin(); it < id.end(); it++) {
for (vector<symbol_t>::const_iterator it = id.begin(); it < id.end(); it++) {
key ^= (uint64_t)*it << (8 * exp--);
if (exp == 0) {
exp = 3;
@@ -155,15 +155,15 @@ uint64_t Message::createKey(const vector<unsigned char> id,
return key;
}
uint64_t Message::createKey(MasterSymbolString& master, unsigned char maxIdLength, bool anyDestination) {
uint64_t Message::createKey(MasterSymbolString& master, size_t maxIdLength, bool anyDestination) {
if (master.size() < 5) {
return INVALID_KEY;
}
unsigned char idLength = master[4];
size_t idLength = master.getDataSize();
if (maxIdLength < idLength) {
idLength = maxIdLength;
}
if (master.size() < 5+idLength) {
if (master.getDataSize() < idLength) {
return INVALID_KEY;
}
uint64_t key = (uint64_t)idLength << (8 * 7 + 5);
@@ -172,8 +172,8 @@ uint64_t Message::createKey(MasterSymbolString& master, unsigned char maxIdLengt
key |= (uint64_t)master[2] << (8 * 5); // PB
key |= (uint64_t)master[3] << (8 * 4); // SB
int exp = 3;
for (unsigned char i = 0; i < idLength; i++) {
key ^= (uint64_t)master[5 + i] << (8 * exp--);
for (size_t i = 0; i < idLength; i++) {
key ^= (uint64_t)master.dataAt(i) << (8 * exp--);
if (exp == 0) {
exp = 3;
}
@@ -181,7 +181,7 @@ uint64_t Message::createKey(MasterSymbolString& master, unsigned char maxIdLengt
return key;
}
result_t Message::parseId(string input, vector<unsigned char>& id) {
result_t Message::parseId(string input, vector<symbol_t>& id) {
istringstream in(input);
while (!in.eof()) {
while (in.peek() == ' ') {
@@ -198,7 +198,7 @@ result_t Message::parseId(string input, vector<unsigned char>& id) {
input.push_back(static_cast<char>(in.get()));
result_t result;
unsigned char value = (unsigned char)parseInt(input.c_str(), 16, 0, 0xff, result);
symbol_t value = (symbol_t)parseInt(input.c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result; // invalid hex value
}
@@ -214,7 +214,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
result_t result;
bool isWrite = false, isPassive = false;
string defaultName;
unsigned char pollPriority = 0;
size_t pollPriority = 0;
size_t defaultPos = 1;
if (it == end) {
return RESULT_ERR_EOF;
@@ -233,7 +233,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
if (type == 'r' || type == 'R') { // active read
char poll = str[1];
if (poll >= '0' && poll <= '9') { // poll priority (=active read)
pollPriority = (unsigned char)(poll - '0');
pollPriority = poll - '0';
defaultName.erase(1, 1); // cut off priority digit
}
} else if (type == 'w' || type == 'W') { // active write
@@ -281,11 +281,11 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
if (it == end) {
return RESULT_ERR_EOF;
}
unsigned char srcAddress;
symbol_t srcAddress;
if (*str == 0) {
srcAddress = SYN; // no specific source
} else {
srcAddress = (unsigned char)parseInt(str, 16, 0, 0xff, result);
srcAddress = (symbol_t)parseInt(str, 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -298,7 +298,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
if (it == end) {
return RESULT_ERR_EOF;
}
vector<unsigned char> dstAddresses;
vector<symbol_t> dstAddresses;
bool isBroadcastOrMasterDestination = false;
if (*str == 0) {
dstAddresses.push_back(SYN); // no specific destination
@@ -308,7 +308,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
bool first = true;
while (getline(stream, token, VALUE_SEPARATOR)) {
FileReader::trim(token);
unsigned char dstAddress = (unsigned char)parseInt(token.c_str(), 16, 0, 0xff, result);
symbol_t dstAddress = (symbol_t)parseInt(token.c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -326,7 +326,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
}
}
vector<unsigned char> id;
vector<symbol_t> id;
string token = *it++; // [PBSB]
bool useDefaults = token.empty();
if (useDefaults) {
@@ -350,8 +350,8 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
defaultIdPrefix = getDefault("", defaults, defaultPos);
}
defaultPos++;
vector< vector<unsigned char> > chainIds;
vector<unsigned char> chainLengths;
vector< vector<symbol_t> > chainIds;
vector<size_t> chainLengths;
istringstream stream(token);
size_t maxLength = MAX_POS;
size_t chainLength = 16;
@@ -369,7 +369,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
}
token.resize(lengthPos);
}
vector<unsigned char> chainId = id;
vector<symbol_t> chainId = id;
result = parseId(token, chainId);
if (result != RESULT_OK) {
return result;
@@ -378,12 +378,12 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
return RESULT_ERR_INVALID_LIST;
}
chainIds.push_back(chainId);
chainLengths.push_back((unsigned char)chainLength);
chainLengths.push_back((symbol_t)chainLength);
if (first) {
chainPrefixLength = chainId.size();
maxLength = 0;
} else if (chainPrefixLength > 2) {
vector<unsigned char>& front = chainIds.front();
vector<symbol_t>& front = chainIds.front();
for (size_t pos = 2; pos < chainPrefixLength; pos++) {
if (chainId[pos] != front[pos]) {
chainPrefixLength = pos;
@@ -439,13 +439,13 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
data = new DataFieldSet("", "", fields);
} else {
result = DataField::create(it, realEnd, templates, data, isWrite, false, isBroadcastOrMasterDestination,
(unsigned char)maxLength);
maxLength);
if (result != RESULT_OK) {
return result;
}
}
if (id.size() + data->getLength(pt_masterData, (unsigned char)maxLength) > 2 + maxLength
|| data->getLength(pt_slaveData, (unsigned char)maxLength) > maxLength) {
if (id.size() + data->getLength(pt_masterData, maxLength) > 2 + maxLength
|| data->getLength(pt_slaveData, maxLength) > maxLength) {
// max NN exceeded
delete data;
return RESULT_ERR_INVALID_POS;
@@ -453,8 +453,8 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
unsigned int index = 0;
bool multiple = dstAddresses.size() > 1;
char num[10];
for (vector<unsigned char>::iterator it = dstAddresses.begin(); it != dstAddresses.end(); it++, index++) {
unsigned char dstAddress = *it;
for (vector<symbol_t>::iterator it = dstAddresses.begin(); it != dstAddresses.end(); it++, index++) {
symbol_t dstAddress = *it;
string useCircuit = circuit;
if (multiple) {
snprintf(num, sizeof(num), ".%d", index);
@@ -477,7 +477,7 @@ Message* Message::createScanMessage() {
return new Message("scan", "", "", false, false, 0x07, 0x04, DataFieldSet::getIdentFields(), true);
}
Message* Message::derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit) {
Message* Message::derive(const symbol_t dstAddress, const symbol_t srcAddress, const string circuit) {
Message* result = new Message(circuit.length() == 0 ? m_circuit : circuit, m_level, m_name,
m_isWrite, m_isPassive, m_comment,
srcAddress == SYN ? m_srcAddress : srcAddress, dstAddress,
@@ -489,7 +489,7 @@ Message* Message::derive(const unsigned char dstAddress, const unsigned char src
return result;
}
Message* Message::derive(const unsigned char dstAddress, const bool extendCircuit) {
Message* Message::derive(const symbol_t dstAddress, const bool extendCircuit) {
if (extendCircuit) {
ostringstream out;
out << m_circuit << '.' << hex << setw(2) << setfill('0') << static_cast<unsigned>(dstAddress);
@@ -520,7 +520,7 @@ bool Message::checkLevel(const string level, const string checkLevels) {
}
return false;
}
bool Message::checkIdPrefix(vector<unsigned char>& id) {
bool Message::checkIdPrefix(vector<symbol_t>& id) {
if (id.size() > m_id.size()) {
return false;
}
@@ -532,13 +532,13 @@ bool Message::checkIdPrefix(vector<unsigned char>& id) {
return true;
}
bool Message::checkId(MasterSymbolString& master, unsigned char* index) {
unsigned char idLen = getIdLength();
if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN
bool Message::checkId(MasterSymbolString& master, size_t* index) {
size_t idLen = getIdLength();
if (master.getDataSize() < idLen) {
return false;
}
for (unsigned char pos = 0; pos < idLen; pos++) {
if (m_id[2+pos] != master[5+pos]) {
for (size_t pos = 0; pos < idLen; pos++) {
if (m_id[2+pos] != master.dataAt(pos)) {
return false;
}
}
@@ -549,18 +549,18 @@ bool Message::checkId(MasterSymbolString& master, unsigned char* index) {
}
bool Message::checkId(Message& other) {
unsigned char idLen = getIdLength();
size_t idLen = getIdLength();
if (idLen != other.getIdLength() || getCount() > 1) { // only equal for non-chained messages
return false;
}
return other.checkIdPrefix(m_id);
}
uint64_t Message::getDerivedKey(const unsigned char dstAddress) {
uint64_t Message::getDerivedKey(const symbol_t dstAddress) {
return (m_key & ~(0xffLL << (8*6))) | (uint64_t)dstAddress << (8*6);
}
bool Message::setPollPriority(unsigned char priority) {
bool Message::setPollPriority(size_t priority) {
if (priority == m_pollPriority || m_isPassive || isScanMessage() || m_dstAddress == SYN) {
return false;
}
@@ -590,9 +590,9 @@ bool Message::hasField(const char* fieldName, bool numeric) {
return m_data->hasField(fieldName, numeric);
}
result_t Message::prepareMaster(const unsigned char srcAddress, MasterSymbolString& master,
result_t Message::prepareMaster(const symbol_t srcAddress, MasterSymbolString& master,
istringstream& input, char separator,
const unsigned char dstAddress, unsigned char index) {
const symbol_t dstAddress, size_t index) {
if (m_isPassive) {
return RESULT_ERR_INVALID_ARG; // prepare not possible
}
@@ -620,20 +620,20 @@ result_t Message::prepareMaster(const unsigned char srcAddress, MasterSymbolStri
}
result_t Message::prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index) {
size_t index) {
if (index != 0) {
return RESULT_ERR_NOTFOUND;
}
unsigned char pos = master.size();
size_t pos = master.size();
master.push_back(0); // length, will be set later
for (size_t i = 2; i < m_id.size(); i++) {
master.push_back(m_id[i]);
}
result_t result = m_data->write(input, pt_masterData, master, getIdLength(), separator);
result_t result = m_data->write(input, master, getIdLength(), separator);
if (result != RESULT_OK) {
return result;
}
master[pos] = (unsigned char)(master.size()-pos-1);
master[pos] = (symbol_t)(master.size()-pos-1);
return result;
}
@@ -643,11 +643,11 @@ result_t Message::prepareSlave(istringstream& input, SlaveSymbolString& slave) {
}
slave.clear();
slave.push_back(0); // length, will be set later
result_t result = m_data->write(input, pt_slaveData, slave, 0);
result_t result = m_data->write(input, slave, 0);
if (result != RESULT_OK) {
return result;
}
slave[0] = (unsigned char)(slave.size()-1);
slave[0] = (symbol_t)(slave.size()-1);
time(&m_lastUpdateTime);
if (slave != m_lastSlaveData) {
m_lastChangeTime = m_lastUpdateTime;
@@ -664,7 +664,7 @@ result_t Message::storeLastData(MasterSymbolString& master, SlaveSymbolString& s
return result;
}
result_t Message::storeLastData(MasterSymbolString& data, unsigned char index) {
result_t Message::storeLastData(MasterSymbolString& data, size_t index) {
if (data.size() > 0
&& (m_isWrite || this->m_dstAddress == BROADCAST || isMaster(this->m_dstAddress))) {
time(&m_lastUpdateTime);
@@ -681,7 +681,7 @@ result_t Message::storeLastData(MasterSymbolString& data, unsigned char index) {
return RESULT_OK;
}
result_t Message::storeLastData(SlaveSymbolString& data, unsigned char index) {
result_t Message::storeLastData(SlaveSymbolString& data, size_t index) {
if (data.size() > 0) {
time(&m_lastUpdateTime);
}
@@ -693,9 +693,9 @@ result_t Message::storeLastData(SlaveSymbolString& data, unsigned char index) {
}
result_t Message::decodeLastMasterData(ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
unsigned char offset = (unsigned char)(m_id.size() - 2);
result_t result = m_data->read(pt_masterData, m_lastMasterData, offset,
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
size_t offset = m_id.size() - 2;
result_t result = m_data->read(m_lastMasterData, offset,
output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
@@ -707,8 +707,8 @@ result_t Message::decodeLastMasterData(ostringstream& output, OutputFormat outpu
}
result_t Message::decodeLastSlaveData(ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
result_t result = m_data->read(pt_slaveData, m_lastSlaveData, 0,
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
result_t result = m_data->read(m_lastSlaveData, 0,
output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
@@ -720,17 +720,16 @@ result_t Message::decodeLastSlaveData(ostringstream& output, OutputFormat output
}
result_t Message::decodeLastData(ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator, const char* fieldName, signed char fieldIndex) {
bool leadingSeparator, const char* fieldName, ssize_t fieldIndex) {
size_t startPos = output.str().length();
result_t result = m_data->read(pt_masterData, m_lastMasterData, getIdLength(), output, outputFormat, -1,
result_t result = m_data->read(m_lastMasterData, getIdLength(), output, outputFormat, -1,
leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
bool empty = result == RESULT_EMPTY;
leadingSeparator |= output.str().length() > startPos;
result = m_data->read(pt_slaveData, m_lastSlaveData, 0, output, outputFormat, -1, leadingSeparator, fieldName,
fieldIndex);
result = m_data->read(m_lastSlaveData, 0, output, outputFormat, -1, leadingSeparator, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
@@ -742,13 +741,13 @@ result_t Message::decodeLastData(ostringstream& output, OutputFormat outputForma
return result;
}
result_t Message::decodeLastDataNumField(unsigned int& output, const char* fieldName, signed char fieldIndex) {
result_t result = m_data->read(pt_masterData, m_lastMasterData, getIdLength(), output, fieldName, fieldIndex);
result_t Message::decodeLastDataNumField(unsigned int& output, const char* fieldName, ssize_t fieldIndex) {
result_t result = m_data->read(m_lastMasterData, getIdLength(), output, fieldName, fieldIndex);
if (result < RESULT_OK) {
return result;
}
if (result == RESULT_EMPTY) {
result = m_data->read(pt_slaveData, m_lastSlaveData, 0, output, fieldName, fieldIndex);
result = m_data->read(m_lastSlaveData, 0, output, fieldName, fieldIndex);
}
if (result < RESULT_OK) {
return result;
@@ -760,10 +759,10 @@ result_t Message::decodeLastDataNumField(unsigned int& output, const char* field
}
bool Message::isLessPollWeight(const Message* other) {
unsigned char tprio = m_pollPriority;
unsigned char oprio = other->m_pollPriority;
unsigned int tw = tprio * m_pollCount;
unsigned int ow = oprio * other->m_pollCount;
size_t tprio = m_pollPriority;
size_t oprio = other->m_pollPriority;
size_t tw = tprio * m_pollCount;
size_t ow = oprio * other->m_pollCount;
if (tw > ow) {
return true;
}
@@ -851,12 +850,12 @@ void Message::dumpColumn(ostream& output, column_t column, bool withConditions)
}
break;
case COLUMN_PBSB:
for (vector<unsigned char>::const_iterator it = m_id.begin(); it < m_id.begin()+2 && it < m_id.end(); it++) {
for (vector<symbol_t>::const_iterator it = m_id.begin(); it < m_id.begin()+2 && it < m_id.end(); it++) {
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
}
break;
case COLUMN_ID:
for (vector<unsigned char>::const_iterator it = m_id.begin()+2; it < m_id.end(); it++) {
for (vector<symbol_t>::const_iterator it = m_id.begin()+2; it < m_id.end(); it++) {
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
}
break;
@@ -872,11 +871,11 @@ void Message::dumpColumn(ostream& output, column_t column, bool withConditions)
ChainedMessage::ChainedMessage(const string circuit, const string level, const string name,
const bool isWrite, const string comment,
const unsigned char srcAddress, const unsigned char dstAddress,
const vector<unsigned char> id,
vector< vector<unsigned char> > ids, vector<unsigned char> lengths,
const symbol_t srcAddress, const symbol_t dstAddress,
const vector<symbol_t> id,
vector< vector<symbol_t> > ids, vector<size_t> lengths,
DataField* data, const bool deleteData,
const unsigned char pollPriority,
const size_t pollPriority,
Condition* condition)
: Message(circuit, level, name, isWrite, false, comment,
srcAddress, dstAddress, id,
@@ -895,7 +894,7 @@ ChainedMessage::ChainedMessage(const string circuit, const string level, const s
}
ChainedMessage::~ChainedMessage() {
for (unsigned char index = 0; index < m_ids.size(); index++) {
for (size_t index = 0; index < m_ids.size(); index++) {
delete m_lastMasterDatas[index];
m_lastMasterDatas[index] = NULL;
delete m_lastSlaveDatas[index];
@@ -907,7 +906,7 @@ ChainedMessage::~ChainedMessage() {
free(m_lastSlaveUpdateTimes);
}
Message* ChainedMessage::derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit) {
Message* ChainedMessage::derive(const symbol_t dstAddress, const symbol_t srcAddress, const string circuit) {
ChainedMessage* result = new ChainedMessage(circuit.length() == 0 ? m_circuit : circuit, m_level, m_name,
m_isWrite, m_comment,
srcAddress == SYN ? m_srcAddress : srcAddress, dstAddress,
@@ -919,22 +918,22 @@ Message* ChainedMessage::derive(const unsigned char dstAddress, const unsigned c
return result;
}
bool ChainedMessage::checkId(MasterSymbolString& master, unsigned char* index) {
unsigned char idLen = getIdLength();
if (master.size() < 5+idLen) { // QQ, ZZ, PB, SB, NN
bool ChainedMessage::checkId(MasterSymbolString& master, size_t* index) {
size_t idLen = getIdLength();
if (master.getDataSize() < idLen) {
return false;
}
unsigned char chainPrefixLength = Message::getIdLength();
for (unsigned char pos = 0; pos < chainPrefixLength; pos++) {
if (m_id[2+pos] != master[5+pos]) {
size_t chainPrefixLength = Message::getIdLength();
for (size_t pos = 0; pos < chainPrefixLength; pos++) {
if (m_id[2+pos] != master.dataAt(pos)) {
return false; // chain prefix mismatch
}
}
for (unsigned char checkIndex = 0; checkIndex < m_ids.size(); checkIndex++) { // check suffix for each part
vector<unsigned char> id = m_ids[checkIndex];
for (size_t checkIndex = 0; checkIndex < m_ids.size(); checkIndex++) { // check suffix for each part
vector<symbol_t> id = m_ids[checkIndex];
bool found = false;
for (unsigned char pos = chainPrefixLength; pos < idLen; pos++) {
if (id[2+pos] != master[5+pos]) {
for (size_t pos = chainPrefixLength; pos < idLen; pos++) {
if (id[2+pos] != master.dataAt(pos)) {
found = false;
break;
}
@@ -951,21 +950,21 @@ bool ChainedMessage::checkId(MasterSymbolString& master, unsigned char* index) {
}
bool ChainedMessage::checkId(Message& other) {
unsigned char idLen = getIdLength();
size_t idLen = getIdLength();
if (idLen != other.getIdLength() || other.getCount() == 1) { // only equal for chained messages
return false;
}
if (!other.checkIdPrefix(m_id)) {
return false; // chain prefix mismatch
}
vector< vector<unsigned char> > otherIds = ((ChainedMessage&)other).m_ids;
unsigned char chainPrefixLength = Message::getIdLength();
for (unsigned char checkIndex = 0; checkIndex < m_ids.size(); checkIndex++) { // check suffix for each part
vector<unsigned char> id = m_ids[checkIndex];
for (unsigned char otherIndex = 0; otherIndex < otherIds.size(); otherIndex++) {
vector<unsigned char> otherId = otherIds[otherIndex];
vector< vector<symbol_t> > otherIds = ((ChainedMessage&)other).m_ids;
size_t chainPrefixLength = Message::getIdLength();
for (size_t checkIndex = 0; checkIndex < m_ids.size(); checkIndex++) { // check suffix for each part
vector<symbol_t> id = m_ids[checkIndex];
for (size_t otherIndex = 0; otherIndex < otherIds.size(); otherIndex++) {
vector<symbol_t> otherId = otherIds[otherIndex];
bool found = false;
for (unsigned char pos = chainPrefixLength; pos < idLen; pos++) {
for (size_t pos = chainPrefixLength; pos < idLen; pos++) {
if (id[2+pos] != otherId[2+pos]) {
found = false;
break;
@@ -981,13 +980,13 @@ bool ChainedMessage::checkId(Message& other) {
}
result_t ChainedMessage::prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index) {
size_t index) {
size_t cnt = getCount();
if (index >= cnt) {
return RESULT_ERR_NOTFOUND;
}
MasterSymbolString allData;
result_t result = m_data->write(input, pt_masterData, allData, 0, separator);
result_t result = m_data->write(input, allData, 0, separator);
if (result != RESULT_OK) {
return result;
}
@@ -999,16 +998,16 @@ result_t ChainedMessage::prepareMasterPart(MasterSymbolString& master, istringst
addData = m_lengths[i+1];
}
}
if (pos+addData > allData.size()) {
if (pos+addData > allData.getDataSize()) {
return RESULT_ERR_INVALID_POS;
}
vector<unsigned char> id = m_ids[index];
master.push_back((unsigned char)(id.size()-2+addData)); // NN
vector<symbol_t> id = m_ids[index];
master.push_back((symbol_t)(id.size()-2+addData)); // NN
for (size_t i = 2; i < id.size(); i++) {
master.push_back(id[i]);
}
for (size_t i = 0; i < addData; i++) {
master.push_back(allData[pos+i]);
master.push_back(allData.dataAt(pos+i));
}
if (index == 0) {
for (size_t i = 0; i < cnt; i++) {
@@ -1020,7 +1019,7 @@ result_t ChainedMessage::prepareMasterPart(MasterSymbolString& master, istringst
result_t ChainedMessage::storeLastData(MasterSymbolString& master, SlaveSymbolString& slave) {
// determine index from master ID
unsigned char index = 0;
size_t index = 0;
if (checkId(master, &index)) {
result_t result = storeLastData(master, index);
if (result >= RESULT_OK) {
@@ -1031,7 +1030,7 @@ result_t ChainedMessage::storeLastData(MasterSymbolString& master, SlaveSymbolSt
return RESULT_ERR_INVALID_ARG;
}
result_t ChainedMessage::storeLastData(MasterSymbolString& data, unsigned char index) {
result_t ChainedMessage::storeLastData(MasterSymbolString& data, size_t index) {
if (index >= m_ids.size()) {
return RESULT_ERR_INVALID_ARG;
}
@@ -1047,7 +1046,7 @@ result_t ChainedMessage::storeLastData(MasterSymbolString& data, unsigned char i
return combineLastParts();
}
result_t ChainedMessage::storeLastData(SlaveSymbolString& data, unsigned char index) {
result_t ChainedMessage::storeLastData(SlaveSymbolString& data, size_t index) {
if (index >= m_ids.size()) {
return RESULT_ERR_INVALID_ARG;
}
@@ -1061,7 +1060,7 @@ result_t ChainedMessage::storeLastData(SlaveSymbolString& data, unsigned char in
result_t ChainedMessage::combineLastParts() {
// check arrival time of all parts
time_t minTime = 0, maxTime = 0;
for (unsigned char index = 0; index < m_ids.size(); index++) {
for (size_t index = 0; index < m_ids.size(); index++) {
if (index == 0) {
minTime = maxTime = m_lastMasterUpdateTimes[index];
} else {
@@ -1085,25 +1084,30 @@ result_t ChainedMessage::combineLastParts() {
// everything was completely retrieved in short time
MasterSymbolString master;
SlaveSymbolString slave;
size_t offset = 5+(m_ids[0].size()-2); // skip QQ, ZZ, PB, SB, NN
for (unsigned char index = 0; index < m_ids.size(); index++) {
SymbolString* add = m_lastMasterDatas[index];
size_t end = 5+(*add)[4];
for (size_t pos = index == 0 ? 0 : offset; pos < end; pos++) {
master.push_back((*add)[pos]);
size_t offset = m_ids[0].size()-2;
SymbolString* add = m_lastMasterDatas[0];
for (size_t pos = 0; pos < 5+offset; pos++) {
master.push_back((*add)[pos]); // copy header
}
slave.push_back(0); // NN, set later
for (size_t index = 0; index < m_ids.size(); index++) {
add = m_lastMasterDatas[index];
size_t end = add->getDataSize();
for (size_t pos = offset; pos < end; pos++) {
master.push_back(add->dataAt(pos));
}
add = m_lastSlaveDatas[index];
end = 1+(*add)[0];
for (size_t pos = index == 0 ? 0 : 1; pos < end; pos++) {
slave.push_back((*add)[pos]);
end = add->getDataSize();
for (size_t pos = 0; pos < end; pos++) {
slave.push_back(add->dataAt(pos));
}
}
// adjust NN
if (master.size()-5 > 255 || slave.size()-1 > 255) {
return RESULT_ERR_INVALID_POS;
}
master[4] = (unsigned char)(master.size()-5);
slave[0] = (unsigned char)(slave.size()-1);
master[4] = (symbol_t)(master.size()-5);
slave[0] = (symbol_t)(slave.size()-1);
result_t result = Message::storeLastData(master, 0);
if (result == RESULT_OK) {
result = Message::storeLastData(slave, 0);
@@ -1118,8 +1122,8 @@ void ChainedMessage::dumpColumn(ostream& output, column_t column, bool withCondi
}
bool first = true;
for (size_t index = 0; index < m_ids.size(); index++) {
vector<unsigned char> id = m_ids[index];
for (vector<unsigned char>::const_iterator it = id.begin()+2; it < id.end(); it++) {
vector<symbol_t> id = m_ids[index];
for (vector<symbol_t>::const_iterator it = id.begin()+2; it < id.end(); it++) {
if (first) {
first = false;
} else {
@@ -1258,13 +1262,13 @@ result_t Condition::create(const string condName, vector<string>::iterator& it,
}
string field = it == end ? "" : *(it++); // fieldname
string zz = it == end ? "" : *(it++); // ZZ
unsigned char dstAddress = SYN;
symbol_t dstAddress = SYN;
result_t result = RESULT_OK;
if (zz.length() == 0) {
zz = defaultDest;
}
if (zz.length() > 0) {
dstAddress = (unsigned char)parseInt(zz.c_str(), 16, 0, 0xff, result);
dstAddress = (symbol_t)parseInt(zz.c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -1556,7 +1560,7 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log, Cond
log << (isSingleton() ? "loaded \"" : "included \"") << m_filename << "\" for \"" << getDestination() << "\"";
if (isSingleton() && !m_defaultDest.empty()) {
result_t temp;
unsigned char address = (unsigned char)parseInt(m_defaultDest.c_str(), 16, 0, 0xff, temp);
symbol_t address = (symbol_t)parseInt(m_defaultDest.c_str(), 16, 0, 0xff, temp);
if (temp == RESULT_OK) {
size_t pos = m_filename.find_last_of('/');
string filename;
@@ -1640,7 +1644,7 @@ result_t MessageMap::add(Message* message, bool storeByName) {
}
addPollMessage(message);
}
unsigned char idLength = message->getIdLength();
size_t idLength = message->getIdLength();
if (idLength > m_maxIdLength) {
m_maxIdLength = idLength;
}
@@ -1825,7 +1829,7 @@ result_t MessageMap::addFromFile(vector<string>::iterator& begin, const vector<s
return result;
}
Message* MessageMap::getScanMessage(const unsigned char dstAddress) {
Message* MessageMap::getScanMessage(const symbol_t dstAddress) {
if (dstAddress == SYN) {
return m_scanMessage;
}
@@ -1931,7 +1935,7 @@ result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageF
return overallResult;
}
void MessageMap::addLoadedFile(unsigned char address, string file, string comment) {
void MessageMap::addLoadedFile(symbol_t address, string file, string comment) {
if (!file.empty()) {
string fileComment = "\""+file+"\"";
if (!comment.empty()) {
@@ -1945,7 +1949,7 @@ void MessageMap::addLoadedFile(unsigned char address, string file, string commen
}
}
string MessageMap::getLoadedFiles(unsigned char address) {
string MessageMap::getLoadedFiles(symbol_t address) {
if (m_loadedFiles.find(address) == m_loadedFiles.end()) {
return "";
}
@@ -2062,16 +2066,16 @@ Message* MessageMap::find(MasterSymbolString& master, bool anyDestination,
if (baseKey == INVALID_KEY) {
return NULL;
}
unsigned char maxIdLength = Message::getKeyLength(baseKey);
for (unsigned char idLength = maxIdLength; true; idLength--) {
size_t maxIdLength = Message::getKeyLength(baseKey);
for (size_t idLength = maxIdLength; true; idLength--) {
uint64_t key = baseKey;
if (idLength == maxIdLength) {
baseKey &= ~ID_LENGTH_AND_IDS_MASK;
} else {
key |= (uint64_t)idLength << (8 * 7 + 5);
int exp = 3;
for (unsigned char i = 0; i < idLength; i++) {
key ^= (uint64_t)master[5 + i] << (8 * exp--);
for (size_t i = 0; i < idLength; i++) {
key ^= (uint64_t)master.dataAt(i) << (8 * exp--);
if (exp == 0) {
exp = 3;
}
+77 -77
View File
@@ -125,10 +125,10 @@ class Message {
*/
Message(const string circuit, const string level, const string name,
const bool isWrite, const bool isPassive, const string comment,
const unsigned char srcAddress, const unsigned char dstAddress,
const vector<unsigned char> id,
const symbol_t srcAddress, const symbol_t dstAddress,
const vector<symbol_t> id,
DataField* data, const bool deleteData,
const unsigned char pollPriority = 0,
const size_t pollPriority = 0,
Condition* condition = NULL);
@@ -148,7 +148,7 @@ class Message {
*/
Message(const string circuit, const string level, const string name,
const bool isWrite, const bool isPassive,
const unsigned char pb, const unsigned char sb,
const symbol_t pb, const symbol_t sb,
DataField* data, const bool deleteData);
@@ -168,9 +168,9 @@ class Message {
* @param dstAddress the destination address, or @a SYN for any (set later).
* @return the key for the ID.
*/
static uint64_t createKey(const vector<unsigned char> id,
static uint64_t createKey(const vector<symbol_t> id,
const bool isWrite, const bool isPassive,
const unsigned char srcAddress, const unsigned char dstAddress);
const symbol_t srcAddress, const symbol_t dstAddress);
/**
* Calculate the key for the @a MasterSymbolString.
@@ -180,14 +180,14 @@ class Message {
* @return the key for the ID, or -1LL if the data is invalid.
*/
static uint64_t createKey(MasterSymbolString& master,
unsigned char maxIdLength, bool anyDestination = false);
size_t maxIdLength, bool anyDestination = false);
/**
* Get the length field from the key.
* @param key the key.
* @return the length field from the key.
*/
static unsigned char getKeyLength(uint64_t key) { return (unsigned char)(key >> (8 * 7 + 5)); }
static size_t getKeyLength(uint64_t key) { return key >> (8 * 7 + 5); }
/**
* Parse an ID part from the input @a string.
@@ -195,7 +195,7 @@ class Message {
* @param id the vector to which to add the parsed values.
* @return @a RESULT_OK on success, or an error code.
*/
static result_t parseId(string input, vector<unsigned char>& id);
static result_t parseId(string input, vector<symbol_t>& id);
/**
* Factory method for creating new instances.
@@ -236,7 +236,7 @@ class Message {
* @param circuit the new circuit name, or empty to use the current circuit name.
* @return the derived @a Message instance.
*/
virtual Message* derive(const unsigned char dstAddress, const unsigned char srcAddress = SYN,
virtual Message* derive(const symbol_t dstAddress, const symbol_t srcAddress = SYN,
const string circuit = "");
/**
@@ -245,7 +245,7 @@ class Message {
* @param extendCircuit whether to extend the current circuit name with a dot and the new destination address in hex.
* @return the derived @a ScanMessage instance.
*/
Message* derive(const unsigned char dstAddress, const bool extendCircuit);
Message* derive(const symbol_t dstAddress, const bool extendCircuit);
/**
* Get the optional circuit name.
@@ -289,7 +289,7 @@ class Message {
* @param fieldIndex the index of the field.
* @return the field name, or the index as string if not unique or not available.
*/
virtual string getFieldName(signed char fieldIndex) const { return m_data->getName(fieldIndex); }
virtual string getFieldName(ssize_t fieldIndex) const { return m_data->getName(fieldIndex); }
/**
* Get whether this is a write message.
@@ -314,38 +314,38 @@ class Message {
* Get the source address.
* @return the source address, or @a SYN for any.
*/
unsigned char getSrcAddress() const { return m_srcAddress; }
symbol_t getSrcAddress() const { return m_srcAddress; }
/**
* Get the destination address.
* @return the destination address, or @a SYN for any.
*/
unsigned char getDstAddress() const { return m_dstAddress; }
symbol_t getDstAddress() const { return m_dstAddress; }
/**
* Get the primary command byte.
* @return the primary command byte.
*/
unsigned char getPrimaryCommand() const { return m_id[0]; }
symbol_t getPrimaryCommand() const { return m_id[0]; }
/**
* Get the secondary command byte.
* @return the secondary command byte.
*/
unsigned char getSecondaryCommand() const { return m_id[1]; }
symbol_t getSecondaryCommand() const { return m_id[1]; }
/**
* Get the length of the ID bytes (without primary and secondary command bytes).
* @return the length of the ID bytes (without primary and secondary command bytes).
*/
virtual unsigned char getIdLength() const { return (unsigned char)(m_id.size() - 2); }
virtual size_t getIdLength() const { return m_id.size() - 2; }
/**
* Check if the full command ID starts with the given value.
* @param id the ID bytes to check against.
* @return true if the full command ID starts with the given value.
*/
bool checkIdPrefix(vector<unsigned char>& id);
bool checkIdPrefix(vector<symbol_t>& id);
/**
* Check the ID against the master @a SymbolString data.
@@ -353,7 +353,7 @@ class Message {
* @param index the variable in which to store the message part index, or NULL to ignore.
* @return true if the ID matches, false otherwise.
*/
virtual bool checkId(MasterSymbolString& master, unsigned char* index = NULL);
virtual bool checkId(MasterSymbolString& master, size_t* index = NULL);
/**
* Check the ID against the other @a Message.
@@ -373,20 +373,20 @@ class Message {
* @param dstAddress the destination address for the derivation.
* @return the derived key for storing in @a MessageMap.
*/
uint64_t getDerivedKey(const unsigned char dstAddress);
uint64_t getDerivedKey(const symbol_t dstAddress);
/**
* Get the polling priority, or 0 for no polling at all.
* @return the polling priority, or 0 for no polling at all.
*/
unsigned char getPollPriority() const { return m_pollPriority; }
size_t getPollPriority() const { return m_pollPriority; }
/**
* Set the polling priority.
* @param priority the polling priority, or 0 for no polling at all.
* @return true when the priority was changed and polling was not enabled before, false otherwise.
*/
bool setPollPriority(unsigned char priority);
bool setPollPriority(size_t priority);
/**
* Set the poll priority suitable for resolving a @a Condition.
@@ -416,7 +416,7 @@ class Message {
/**
* @return the number of parts this message is composed of.
*/
virtual unsigned char getCount() { return 1; }
virtual size_t getCount() { return 1; }
/**
* Prepare the master @a SymbolString for sending a query or command to the bus.
@@ -428,9 +428,9 @@ class Message {
* @param index the index of the part to prepare.
* @return @a RESULT_OK on success, or an error code.
*/
result_t prepareMaster(const unsigned char srcAddress, MasterSymbolString& master,
result_t prepareMaster(const symbol_t srcAddress, MasterSymbolString& master,
istringstream& input, char separator = UI_FIELD_SEPARATOR,
const unsigned char dstAddress = SYN, unsigned char index = 0);
const symbol_t dstAddress = SYN, size_t index = 0);
protected:
@@ -443,7 +443,7 @@ class Message {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index);
size_t index);
public:
@@ -469,7 +469,7 @@ class Message {
* @param index the index of the part to store.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t storeLastData(MasterSymbolString& data, unsigned char index);
virtual result_t storeLastData(MasterSymbolString& data, size_t index);
/**
* Store last seen slave data.
@@ -477,7 +477,7 @@ class Message {
* @param index the index of the part to store.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t storeLastData(SlaveSymbolString& data, unsigned char index);
virtual result_t storeLastData(SlaveSymbolString& data, size_t index);
/**
* Decode the value from the last stored master data.
@@ -489,7 +489,7 @@ class Message {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t decodeLastMasterData(ostringstream& output, OutputFormat outputFormat = 0,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1);
/**
* Decode the value from the last stored slave data.
@@ -501,7 +501,7 @@ class Message {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t decodeLastSlaveData(ostringstream& output, OutputFormat outputFormat = 0,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1);
/**
* Decode the value from the last stored data.
@@ -513,7 +513,7 @@ class Message {
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t decodeLastData(ostringstream& output, OutputFormat outputFormat = 0,
bool leadingSeparator = false, const char* fieldName = NULL, signed char fieldIndex = -1);
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1);
/**
* Decode a particular numeric field value from the last stored data.
@@ -522,7 +522,7 @@ class Message {
* @param fieldIndex the optional index of the named field, or -1.
* @return @a RESULT_OK on success, or an error code.
*/
virtual result_t decodeLastDataNumField(unsigned int& output, const char* fieldName, signed char fieldIndex = -1);
virtual result_t decodeLastDataNumField(unsigned int& output, const char* fieldName, ssize_t fieldIndex = -1);
/**
* Get the last seen master data.
@@ -599,13 +599,13 @@ class Message {
const string m_comment;
/** the source address, or @a SYN for any (only relevant if passive). */
const unsigned char m_srcAddress;
const symbol_t m_srcAddress;
/** the destination address, or @a SYN for any (only for temporary scan messages). */
const unsigned char m_dstAddress;
const symbol_t m_dstAddress;
/** the primary, secondary, and optionally further command ID bytes. */
vector<unsigned char> m_id;
vector<symbol_t> m_id;
/**
* the key for storing in @a MessageMap.
@@ -637,7 +637,7 @@ class Message {
const bool m_deleteData;
/** the priority for polling, or 0 for no polling at all. */
unsigned char m_pollPriority;
size_t m_pollPriority;
/** whether this message is used by a @a Condition. */
bool m_usedByCondition;
@@ -692,47 +692,47 @@ class ChainedMessage : public Message {
*/
ChainedMessage(const string circuit, const string level, const string name,
const bool isWrite, const string comment,
const unsigned char srcAddress, const unsigned char dstAddress,
const vector<unsigned char> id,
vector< vector<unsigned char> > ids, vector<unsigned char> lengths,
const symbol_t srcAddress, const symbol_t dstAddress,
const vector<symbol_t> id,
vector< vector<symbol_t> > ids, vector<size_t> lengths,
DataField* data, const bool deleteData,
const unsigned char pollPriority,
const size_t pollPriority,
Condition* condition = NULL);
virtual ~ChainedMessage();
// @copydoc
virtual Message* derive(const unsigned char dstAddress, const unsigned char srcAddress = SYN,
const string circuit = "");
virtual Message* derive(const symbol_t dstAddress, const symbol_t srcAddress = SYN,
const string circuit = "") override;
// @copydoc
virtual unsigned char getIdLength() const { return (unsigned char)(m_ids[0].size() - 2); }
virtual size_t getIdLength() const override { return m_ids[0].size() - 2; }
// @copydoc
virtual bool checkId(MasterSymbolString& master, unsigned char* index = NULL);
virtual bool checkId(MasterSymbolString& master, size_t* index = NULL) override;
// @copydoc
virtual bool checkId(Message& other);
virtual bool checkId(Message& other) override;
// @copydoc
virtual unsigned char getCount() { return (unsigned char)m_ids.size(); }
virtual size_t getCount() override { return m_ids.size(); }
protected:
// @copydoc
virtual result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
unsigned char index);
size_t index) override;
public:
// @copydoc
virtual result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave);
virtual result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave) override;
// @copydoc
virtual result_t storeLastData(MasterSymbolString& data, unsigned char index);
virtual result_t storeLastData(MasterSymbolString& data, size_t index) override;
// @copydoc
virtual result_t storeLastData(SlaveSymbolString& data, unsigned char index);
virtual result_t storeLastData(SlaveSymbolString& data, size_t index) override;
/**
* Combine all last stored data.
@@ -742,15 +742,15 @@ class ChainedMessage : public Message {
protected:
// @copydoc
virtual void dumpColumn(ostream& output, column_t column, bool withConditions = false);
virtual void dumpColumn(ostream& output, column_t column, bool withConditions = false) override;
private:
/** the primary, secondary, and optional further ID bytes for each part of the chain. */
const vector< vector<unsigned char> > m_ids;
const vector< vector<symbol_t> > m_ids;
/** the data length for each part of the chain. */
const vector<unsigned char> m_lengths;
const vector<size_t> m_lengths;
/** the maximum allowed time difference of any data pair. */
const time_t m_maxTimeDiff;
@@ -899,7 +899,7 @@ class SimpleCondition : public Condition {
* @param hasValues whether a value has to be checked against.
*/
SimpleCondition(const string condName, const string refName, const string circuit, const string level,
const string name, const unsigned char dstAddress, const string field, const bool hasValues = false)
const string name, const symbol_t dstAddress, const string field, const bool hasValues = false)
: Condition(),
m_condName(condName), m_refName(refName), m_circuit(circuit), m_level(level), m_name(name),
m_dstAddress(dstAddress), m_field(field), m_hasValues(hasValues), m_message(NULL) { }
@@ -910,20 +910,20 @@ class SimpleCondition : public Condition {
virtual ~SimpleCondition() {}
// @copydoc
virtual SimpleCondition* derive(string valueList);
virtual SimpleCondition* derive(string valueList) override;
// @copydoc
virtual void dump(ostream& output, bool matched = false);
virtual void dump(ostream& output, bool matched = false) override;
// @copydoc
virtual CombinedCondition* combineAnd(Condition* other);
virtual CombinedCondition* combineAnd(Condition* other) override;
// @copydoc
virtual result_t resolve(MessageMap* messages, ostringstream& errorMessage,
void (*readMessageFunc)(Message* message) = NULL);
void (*readMessageFunc)(Message* message) = NULL) override;
// @copydoc
virtual bool isTrue();
virtual bool isTrue() override;
/**
* Return whether the condition is based on a numeric value.
@@ -963,7 +963,7 @@ class SimpleCondition : public Condition {
/** the override destination address, or @a SYN (only for @a Message without specific destination as well as scan
* message). */
const unsigned char m_dstAddress;
const symbol_t m_dstAddress;
/** the field name, or empty for first field. */
const string m_field;
@@ -993,7 +993,7 @@ class SimpleNumericCondition : public SimpleCondition {
* @param valueRanges the valid value ranges (pairs of from/to inclusive), empty for @a m_message seen check.
*/
SimpleNumericCondition(const string condName, const string refName, const string circuit, const string level,
const string name, const unsigned char dstAddress, const string field, const vector<unsigned int> valueRanges)
const string name, const symbol_t dstAddress, const string field, const vector<unsigned int> valueRanges)
: SimpleCondition(condName, refName, circuit, level, name, dstAddress, field, true),
m_valueRanges(valueRanges) { }
@@ -1005,7 +1005,7 @@ class SimpleNumericCondition : public SimpleCondition {
protected:
// @copydoc
virtual bool checkValue(Message* message, const string field);
virtual bool checkValue(Message* message, const string field) override;
private:
@@ -1031,7 +1031,7 @@ class SimpleStringCondition : public SimpleCondition {
* @param values the valid values.
*/
SimpleStringCondition(const string condName, const string refName, const string circuit, const string level,
const string name, const unsigned char dstAddress, const string field, const vector<string> values)
const string name, const symbol_t dstAddress, const string field, const vector<string> values)
: SimpleCondition(condName, refName, circuit, level, name, dstAddress, field, true),
m_values(values) { }
@@ -1041,12 +1041,12 @@ class SimpleStringCondition : public SimpleCondition {
virtual ~SimpleStringCondition() {}
// @copydoc
virtual bool isNumeric() { return false; }
virtual bool isNumeric() override { return false; }
protected:
// @copydoc
virtual bool checkValue(Message* message, const string field);
virtual bool checkValue(Message* message, const string field) override;
private:
@@ -1072,17 +1072,17 @@ class CombinedCondition : public Condition {
virtual ~CombinedCondition() {}
// @copydoc
virtual void dump(ostream& output, bool matched = false);
virtual void dump(ostream& output, bool matched = false) override;
// @copydoc
virtual CombinedCondition* combineAnd(Condition* other) { m_conditions.push_back(other); return this; }
virtual CombinedCondition* combineAnd(Condition* other) override { m_conditions.push_back(other); return this; }
// @copydoc
virtual result_t resolve(MessageMap* messages, ostringstream& errorMessage,
void (*readMessageFunc)(Message* message) = NULL);
void (*readMessageFunc)(Message* message) = NULL) override;
// @copydoc
virtual bool isTrue();
virtual bool isTrue() override;
private:
@@ -1209,7 +1209,7 @@ class LoadInstruction : public Instruction {
virtual ~LoadInstruction() { }
// @copydoc
virtual result_t execute(MessageMap* messages, ostringstream& log, Condition* condition);
virtual result_t execute(MessageMap* messages, ostringstream& log, Condition* condition) override;
private:
@@ -1252,7 +1252,7 @@ class MessageMap : public FileReader {
// @copydoc
virtual result_t addDefaultFromFile(vector< vector<string> >& defaults, vector<string>& row,
vector<string>::iterator& begin, string defaultDest, string defaultCircuit, string defaultSuffix,
const string& filename, unsigned int lineNo);
const string& filename, unsigned int lineNo) override;
/**
* Read the @a Condition instance(s) from the types field.
@@ -1266,14 +1266,14 @@ class MessageMap : public FileReader {
// @copydoc
virtual result_t addFromFile(vector<string>::iterator& begin, const vector<string>::iterator end,
vector< vector<string> >* defaults, const string& defaultDest, const string& defaultCircuit,
const string& defaultSuffix, const string& filename, unsigned int lineNo);
const string& defaultSuffix, const string& filename, unsigned int lineNo) override;
/**
* Get the scan @a Message instance for the specified address.
* @param dstAddress the destination address, or @a SYN for the base scan @a Message.
* @return the scan @a Message instance, or NULL if the dstAddress is no slave.
*/
Message* getScanMessage(const unsigned char dstAddress = SYN);
Message* getScanMessage(const symbol_t dstAddress = SYN);
/**
* Resolve all @a Condition instances.
@@ -1305,7 +1305,7 @@ class MessageMap : public FileReader {
* @param file the name of the file from which a configuration part was loaded for the participant.
* @param comment an optional comment.
*/
void addLoadedFile(unsigned char address, string file, string comment);
void addLoadedFile(symbol_t address, string file, string comment);
/**
* Get the loaded files for a participant.
@@ -1313,7 +1313,7 @@ class MessageMap : public FileReader {
* @return the name of the file(s) loaded for the participant (separated by comma and enclosed in double quotes),
* or empty.
*/
string getLoadedFiles(unsigned char address);
string getLoadedFiles(symbol_t address);
/**
* Get the stored @a Message instances for the key.
@@ -1452,10 +1452,10 @@ class MessageMap : public FileReader {
Message* m_scanMessage;
/** the loaded configuration files by slave address. */
map<unsigned char, string> m_loadedFiles;
map<symbol_t, string> m_loadedFiles;
/** the maximum ID length used by any of the known @a Message instances. */
unsigned char m_maxIdLength;
size_t m_maxIdLength;
/** the number of distinct @a Message instances stored in @a m_messagesByName. */
size_t m_messageCount;
+24 -25
View File
@@ -34,7 +34,7 @@ using std::setfill;
/**
* CRC8 lookup table for the polynom 0x9b = x^8 + x^7 + x^4 + x^3 + x^1 + 1.
*/
static const unsigned char CRC_LOOKUP_TABLE[] = {
static const symbol_t CRC_LOOKUP_TABLE[] = {
0x00, 0x9b, 0xad, 0x36, 0xc1, 0x5a, 0x6c, 0xf7, 0x19, 0x82, 0xb4, 0x2f, 0xd8, 0x43, 0x75, 0xee,
0x32, 0xa9, 0x9f, 0x04, 0xf3, 0x68, 0x5e, 0xc5, 0x2b, 0xb0, 0x86, 0x1d, 0xea, 0x71, 0x47, 0xdc,
0x64, 0xff, 0xc9, 0x52, 0xa5, 0x3e, 0x08, 0x93, 0x7d, 0xe6, 0xd0, 0x4b, 0xbc, 0x27, 0x11, 0x8a,
@@ -55,7 +55,7 @@ static const unsigned char CRC_LOOKUP_TABLE[] = {
unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue,
result_t& result, unsigned int* length) {
result_t& result, size_t* length) {
char* strEnd = NULL;
unsigned long ret = strtoul(str, &strEnd, base);
@@ -77,7 +77,7 @@ unsigned int parseInt(const char* str, int base, const unsigned int minValue, co
}
int parseSignedInt(const char* str, int base, const int minValue, const int maxValue, result_t& result,
unsigned int* length) {
size_t* length) {
char* strEnd = NULL;
long ret = strtol(str, &strEnd, base);
@@ -99,14 +99,14 @@ int parseSignedInt(const char* str, int base, const int minValue, const int maxV
}
void SymbolString::updateCrc(unsigned char& crc, const unsigned char value) {
void SymbolString::updateCrc(symbol_t& crc, const symbol_t value) {
crc = CRC_LOOKUP_TABLE[crc]^value;
}
result_t SymbolString::parseHex(const string& str) {
result_t result;
for (size_t i = 0; i < str.size(); i += 2) {
unsigned char value = (unsigned char)parseInt(str.substr(i, 2).c_str(), 16, 0, 0xff, result);
symbol_t value = (symbol_t)parseInt(str.substr(i, 2).c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -119,7 +119,7 @@ result_t SymbolString::parseHexEscaped(const string& str) {
result_t result;
bool inEscape = false;
for (size_t i = 0; i < str.size(); i += 2) {
unsigned char value = (unsigned char)parseInt(str.substr(i, 2).c_str(), 16, 0, 0xff, result);
symbol_t value = (symbol_t)parseInt(str.substr(i, 2).c_str(), 16, 0, 0xff, result);
if (result != RESULT_OK) {
return result;
}
@@ -144,24 +144,23 @@ result_t SymbolString::parseHexEscaped(const string& str) {
return inEscape ? RESULT_ERR_ESC : RESULT_OK;
}
const string SymbolString::getDataStr(unsigned char skipFirstSymbols) {
const string SymbolString::getStr(size_t skipFirstSymbols) {
ostringstream sstr;
for (size_t i = 0; i < m_data.size(); i++) {
if (skipFirstSymbols > 0) {
skipFirstSymbols--;
} else {
unsigned char value = m_data[i];
sstr << nouppercase << setw(2) << hex
<< setfill('0') << static_cast<unsigned>(value);
<< setfill('0') << static_cast<unsigned>(m_data[i]);
}
}
return sstr.str();
}
unsigned char SymbolString::calcCrc() const {
unsigned char crc = 0;
symbol_t SymbolString::calcCrc() const {
symbol_t crc = 0;
for (size_t i = 0; i < m_data.size(); i++) {
unsigned char value = m_data[i];
symbol_t value = m_data[i];
if (value == ESC) {
updateCrc(crc, ESC);
updateCrc(crc, 0x00);
@@ -181,7 +180,7 @@ unsigned char SymbolString::calcCrc() const {
* @param bits the upper or lower 4 bits of the address.
* @return the 1-based index of the upper or lower 4 bits of a master address (1 to 5), or 0.
*/
unsigned char getMasterPartIndex(unsigned char bits) {
unsigned int getMasterPartIndex(symbol_t bits) {
switch (bits) {
case 0x0:
return 1;
@@ -198,18 +197,18 @@ unsigned char getMasterPartIndex(unsigned char bits) {
}
}
bool isMaster(unsigned char addr) {
bool isMaster(symbol_t addr) {
return getMasterPartIndex(addr & 0x0F) > 0
&& getMasterPartIndex((addr & 0xF0)>>4) > 0;
}
bool isSlaveMaster(unsigned char addr) {
return isMaster((unsigned char)(addr+256-5));
bool isSlaveMaster(symbol_t addr) {
return isMaster((symbol_t)(addr+256-5));
}
unsigned char getSlaveAddress(unsigned char addr) {
symbol_t getSlaveAddress(symbol_t addr) {
if (isMaster(addr)) {
return (unsigned char)(addr+5);
return (symbol_t)(addr+5);
}
if (isValidAddress(addr, false)) {
return addr;
@@ -217,30 +216,30 @@ unsigned char getSlaveAddress(unsigned char addr) {
return SYN;
}
unsigned char getMasterAddress(unsigned char addr) {
symbol_t getMasterAddress(symbol_t addr) {
if (isMaster(addr)) {
return addr;
}
addr = (unsigned char)(addr+256-5);
addr = (symbol_t)(addr+256-5);
if (isMaster(addr)) {
return addr;
}
return SYN;
}
unsigned char getMasterNumber(unsigned char addr) {
unsigned char priority = getMasterPartIndex(addr & 0x0F);
unsigned int getMasterNumber(symbol_t addr) {
unsigned int priority = getMasterPartIndex(addr & 0x0F);
if (priority == 0) {
return 0;
}
unsigned char index = getMasterPartIndex((addr & 0xF0) >> 4);
unsigned int index = getMasterPartIndex((addr & 0xF0) >> 4);
if (index == 0) {
return 0;
}
return (unsigned char)(5*(priority-1) + index);
return 5*(priority-1) + index;
}
bool isValidAddress(unsigned char addr, bool allowBroadcast) {
bool isValidAddress(symbol_t addr, bool allowBroadcast) {
return addr != SYN && addr != ESC && (allowBroadcast || addr != BROADCAST);
}
+46 -30
View File
@@ -68,6 +68,9 @@ namespace ebusd {
using std::string;
using std::vector;
/** the base type for symbols sent to/from the eBUS. */
typedef unsigned char symbol_t;
/** escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA. */
#define ESC 0xA9
@@ -94,7 +97,7 @@ using std::vector;
* @return the parsed value.
*/
unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue,
result_t& result, unsigned int* length = NULL);
result_t& result, size_t* length = NULL);
/**
* Parse a signed int value.
@@ -107,7 +110,7 @@ unsigned int parseInt(const char* str, int base, const unsigned int minValue, co
* @return the parsed value.
*/
int parseSignedInt(const char* str, int base, const int minValue, const int maxValue, result_t& result,
unsigned int* length = NULL);
size_t* length = NULL);
/**
* A string of unescaped bus symbols.
@@ -126,7 +129,13 @@ class SymbolString {
* @param crc the current CRC to update.
* @param value the escaped value to add to the current CRC.
*/
static void updateCrc(unsigned char& crc, const unsigned char value);
static void updateCrc(symbol_t& crc, const symbol_t value);
/**
* Return whether this instance if for the master part.
* @return whether this instance if for the master part.
*/
bool isMaster() const { return m_isMaster; }
/**
* Parse the hex @a string and add all symbols.
@@ -147,14 +156,14 @@ class SymbolString {
* @param skipFirstSymbols the number of first symbols to skip.
* @return the symbols as hex string.
*/
const string getDataStr(unsigned char skipFirstSymbols = 0);
const string getStr(size_t skipFirstSymbols = 0);
/**
* Return a reference to the symbol at the specified index.
* @param index the index of the symbol to return.
* @return the reference to the symbol at the specified index.
*/
unsigned char& operator[](const size_t index) {
symbol_t& operator[](const size_t index) {
if (index >= m_data.size()) {
m_data.resize(index+1, 0);
}
@@ -209,37 +218,44 @@ class SymbolString {
* Append a symbol to the end of the symbol string.
* @param value the symbol to append.
*/
void push_back(const unsigned char value) { m_data.push_back(value); }
void push_back(const symbol_t value) { m_data.push_back(value); }
/**
* Return the number of symbols in this symbol string.
* @return the number of available symbols.
*/
unsigned char size() const { return (unsigned char)m_data.size(); }
size_t size() const { return m_data.size(); }
/**
* Return the offset to the first data byte DD.
* @return the offset to the first data byte DD.
*/
unsigned char getDataOffset() const { return m_isMaster ? 5 : 1; }
size_t getDataOffset() const { return m_isMaster ? 5 : 1; }
/**
* Return the number of data bytes DD.
* @return the number of data bytes DD.
* Return the number of effectively available data bytes DD.
* @return the number of effectively available data bytes DD.
*/
unsigned char getDataSize() const { return m_data.size() > (m_isMaster ? 4 : 0) ? m_data[m_isMaster ? 4 : 0] : 0; }
/**
* Return the data byte at the specified index (within DD).
* @param index the index of the data byte to return (0 up to NN excluding).
* @return the data byte at the specified index, or @a SYN if not available.
*/
unsigned char getDataAt(const size_t index) {
size_t offset = m_isMaster ? 5 : 1;
if (offset+index >= m_data.size()) {
return SYN;
size_t getDataSize() const {
size_t lengthOffset = (m_isMaster ? 4 : 0);
if (m_data.size() <= lengthOffset) {
return 0;
}
return m_data[offset+index];
size_t ret = m_data[lengthOffset];
return m_data.size() < lengthOffset + 1 + ret ? m_data.size() - lengthOffset - 1 : ret;
}
/**
* Return a reference to the data byte at the specified index (within DD).
* @param index the index of the data byte (within DD) to return.
* @return the reference to the data byte at the specified index.
*/
symbol_t& dataAt(const size_t index) {
size_t offset = (m_isMaster ? 5 : 1) + index;
if (offset >= m_data.size()) {
m_data.resize(offset+1, 0);
}
return m_data[offset];
}
/**
@@ -258,7 +274,7 @@ class SymbolString {
* Calculate the CRC.
* @return the calculated CRC.
*/
unsigned char calcCrc() const;
symbol_t calcCrc() const;
/**
* Clear the symbols.
@@ -275,7 +291,7 @@ class SymbolString {
: m_data(str.m_data), m_isMaster(str.m_isMaster) {}
/** the string of unescaped symbols. */
vector<unsigned char> m_data;
vector<symbol_t> m_data;
/** whether this instance if for the master part. */
bool m_isMaster;
@@ -311,14 +327,14 @@ class SlaveSymbolString : public SymbolString {
* @param addr the address to check.
* @return <code>true</code> if the specified address is a master address.
*/
bool isMaster(unsigned char addr);
bool isMaster(symbol_t addr);
/**
* Return whether the address is a slave address of one of the 25 masters.
* @param addr the address to check.
* @return <code>true</code> if the specified address is a slave address of a master.
*/
bool isSlaveMaster(unsigned char addr);
bool isSlaveMaster(symbol_t addr);
/**
* Return the slave address associated with the specified address (master or slave).
@@ -326,7 +342,7 @@ bool isSlaveMaster(unsigned char addr);
* @return the slave address, or SYN if the specified address is neither a master address nor a slave address of a
* master.
*/
unsigned char getSlaveAddress(unsigned char addr);
symbol_t getSlaveAddress(symbol_t addr);
/**
* Return the master address associated with the specified address (master or slave).
@@ -334,14 +350,14 @@ unsigned char getSlaveAddress(unsigned char addr);
* @return the master address, or SYN if the specified address is neither a master address nor a slave address of a
* master.
*/
unsigned char getMasterAddress(unsigned char addr);
symbol_t getMasterAddress(symbol_t addr);
/**
* Return the number of the master if the address is a valid bus address.
* @param addr the bus address.
* @return the number of the master if the address is a valid bus address (1 to 25), or 0.
*/
unsigned char getMasterNumber(unsigned char addr);
unsigned int getMasterNumber(symbol_t addr);
/**
* Return whether the address is a valid bus address.
@@ -349,7 +365,7 @@ unsigned char getMasterNumber(unsigned char addr);
* @param allowBroadcast whether to also allow @a addr to be the broadcast address (default true).
* @return <code>true</code> if the specified address is a valid bus address.
*/
bool isValidAddress(unsigned char addr, bool allowBroadcast = true);
bool isValidAddress(symbol_t addr, bool allowBroadcast = true);
} // namespace ebusd
+10 -13
View File
@@ -564,22 +564,20 @@ int main() {
ostringstream output;
MasterSymbolString writeMstr;
result = writeMstr.parseHex(mstr.getDataStr().substr(0, 10));
result = writeMstr.parseHex(mstr.getStr().substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr().substr(0, 10) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << mstr.getStr().substr(0, 10) << "\" error: " << getResultCode(result) << endl;
error = true;
}
SlaveSymbolString writeSstr;
result = writeSstr.parseHex(sstr.getDataStr().substr(0, 2));
result = writeSstr.parseHex(sstr.getStr().substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr().substr(0, 2) << "\" error: " << getResultCode(result)
<< endl;
cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl;
error = true;
}
result = fields->read(pt_masterData, mstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1, false);
result = fields->read(mstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1, false);
if (result >= RESULT_OK) {
result = fields->read(pt_slaveData, sstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1,
result = fields->read(sstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1,
!output.str().empty());
}
if (failedRead) {
@@ -602,9 +600,9 @@ int main() {
if (verbosity == 0) {
istringstream input(expectStr);
result = fields->write(input, pt_masterData, writeMstr, 0);
result = fields->write(input, writeMstr, 0);
if (result >= RESULT_OK) {
result = fields->write(input, pt_slaveData, writeSstr, 0);
result = fields->write(input, writeSstr, 0);
}
if (failedWrite) {
if (result >= RESULT_OK) {
@@ -621,9 +619,8 @@ int main() {
error = true;
} else {
bool match = mstr == writeMstr && sstr == writeSstr;
verify(failedWriteMatch, "write", expectStr, match, mstr.getDataStr() + " "
+ sstr.getDataStr(), writeMstr.getDataStr() + " "
+ writeSstr.getDataStr());
verify(failedWriteMatch, "write", expectStr, match, mstr.getStr() + " " + sstr.getStr(),
writeMstr.getStr() + " " + writeSstr.getStr());
}
}
delete fields;
+1 -1
View File
@@ -39,7 +39,7 @@ int main() {
int count = 0;
while (1) {
unsigned char byte = 0;
symbol_t byte = 0;
result = device->recv(0, byte);
if (result == RESULT_OK) {
+2 -3
View File
@@ -399,7 +399,7 @@ int main() {
if (message->isPassive() || decode) {
ostringstream output;
for (unsigned char index = 0; index < message->getCount(); index++) {
for (size_t index = 0; index < message->getCount(); index++) {
message->storeLastData(*mstrs[index], *sstrs[index]);
}
if (withMessageDump && !decodeJson) {
@@ -438,8 +438,7 @@ int main() {
cout << " \"" << inputStr << "\": prepare OK" << endl;
bool match = writeMstr == *mstrs[0];
verify(failedPrepareMatch, "prepare", inputStr, match, mstrs[0]->getDataStr(),
writeMstr.getDataStr());
verify(failedPrepareMatch, "prepare", inputStr, match, mstrs[0]->getStr(), writeMstr.getStr());
}
}
+5 -5
View File
@@ -59,7 +59,7 @@ int main(int argc, char** argv) {
if (result != RESULT_OK) {
cout << "parse escaped error: " << getResultCode(result) << endl;
} else {
unsigned char gotCrc = mstr.calcCrc();
symbol_t gotCrc = mstr.calcCrc();
cout << "calculated CRC: 0x"
<< nouppercase << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(gotCrc) << endl;
@@ -73,9 +73,9 @@ int main(int argc, char** argv) {
cout << "parse unescaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
gotStr = mstr.getStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse unescaped", "10feb5050427a915aa", true, expectStr, gotStr);
unsigned char gotCrc = mstr.calcCrc(), expectCrc = 0x77;
symbol_t gotCrc = mstr.calcCrc(), expectCrc = 0x77;
ostringstream ostr;
ostr << nouppercase << setw(2) << hex << setfill('0') << static_cast<unsigned>(expectCrc);
expectStr = ostr.str();
@@ -91,7 +91,7 @@ int main(int argc, char** argv) {
cout << "parse escaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = mstr.getDataStr(), expectStr = "10feb5050427a915aa";
gotStr = mstr.getStr(), expectStr = "10feb5050427a915aa";
verify(false, "parse escaped", "10feb5050427a90015a901", true, expectStr, gotStr);
ostringstream ostr;
ostr << dec << static_cast<unsigned>(4);
@@ -108,7 +108,7 @@ int main(int argc, char** argv) {
cout << "parse escaped error: " << getResultCode(result) << endl;
error = true;
} else {
gotStr = sstr.getDataStr(), expectStr = "0427a915aa";
gotStr = sstr.getStr(), expectStr = "0427a915aa";
verify(false, "parse escaped", "0427a90015a901", true, expectStr, gotStr);
ostringstream ostr;
ostr << dec << static_cast<unsigned>(4);