use spaces instead of tab

This commit is contained in:
john30
2017-01-14 18:01:37 +01:00
parent 917414a6f8
commit ebcb260d5f
47 changed files with 13575 additions and 13575 deletions
+2 -2
View File
@@ -22,8 +22,8 @@
namespace ebusd {
bool libebus_contrib_register() {
contrib_tem_register();
return true;
contrib_tem_register();
return true;
}
} // namespace ebusd
+91 -91
View File
@@ -17,7 +17,7 @@
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
# include <config.h>
#endif
#include "tem.h"
@@ -36,108 +36,108 @@ using std::setw;
using std::dec;
void contrib_tem_register() {
DataTypeList::getInstance()->add(new TemParamDataType("TEM_P"));
DataTypeList::getInstance()->add(new TemParamDataType("TEM_P"));
}
result_t TemParamDataType::derive(int divisor, unsigned char bitCount, NumberDataType* &derived) {
if (divisor == 0) {
divisor = 1;
}
if (bitCount == 0) {
bitCount = m_bitCount;
}
if (divisor == 1 && bitCount == 16) {
derived = this;
return RESULT_OK;
}
return RESULT_ERR_INVALID_ARG;
if (divisor == 0) {
divisor = 1;
}
if (bitCount == 0) {
bitCount = m_bitCount;
}
if (divisor == 1 && bitCount == 16) {
derived = this;
return RESULT_OK;
}
return RESULT_ERR_INVALID_ARG;
}
result_t TemParamDataType::readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat) {
unsigned int value = 0;
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat) {
unsigned int value = 0;
result_t result = readRawValue(input, offset, length, value);
if (result != RESULT_OK) {
return result;
}
result_t result = readRawValue(input, offset, length, value);
if (result != RESULT_OK) {
return result;
}
if (value == m_replacement) {
if (outputFormat & OF_JSON) {
output << "null";
} else {
output << NULL_VALUE;
}
return RESULT_OK;
}
int grp = 0, num = 0;
if (isMaster) {
grp = (value & 0x1f); // grp in bits 0...5
num = ((value >> 8) & 0x7f); // num in bits 8...13
} else {
grp = ((value >> 7) & 0x1f); // grp in bits 7...11
num = (value & 0x7f); // num in bits 0...6
}
if (outputFormat & OF_JSON) {
output << '"';
}
output << setfill('0') << setw(2) << dec << static_cast<int>(grp) << '-' << setw(3) << static_cast<int>(num);
if (outputFormat & OF_JSON) {
output << '"';
}
output << setfill(' ') << setw(0); // reset
return RESULT_OK;
if (value == m_replacement) {
if (outputFormat & OF_JSON) {
output << "null";
} else {
output << NULL_VALUE;
}
return RESULT_OK;
}
int grp = 0, num = 0;
if (isMaster) {
grp = (value & 0x1f); // grp in bits 0...5
num = ((value >> 8) & 0x7f); // num in bits 8...13
} else {
grp = ((value >> 7) & 0x1f); // grp in bits 7...11
num = (value & 0x7f); // num in bits 0...6
}
if (outputFormat & OF_JSON) {
output << '"';
}
output << setfill('0') << setw(2) << dec << static_cast<int>(grp) << '-' << setw(3) << static_cast<int>(num);
if (outputFormat & OF_JSON) {
output << '"';
}
output << setfill(' ') << setw(0); // reset
return RESULT_OK;
}
result_t TemParamDataType::writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
unsigned int value;
int grp, num;
string token;
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength) {
unsigned int value;
int grp, num;
string token;
const char* str = input.str().c_str();
if (strcasecmp(str, NULL_VALUE) == 0) {
value = m_replacement; // replacement value
} else {
if (input.eof() || !getline(input, token, '-')) {
return RESULT_ERR_EOF; // incomplete
}
str = token.c_str();
if (str == NULL || *str == 0) {
return RESULT_ERR_EOF; // input too short
}
char* strEnd = NULL;
grp = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
return RESULT_ERR_INVALID_NUM; // invalid value
}
if (input.eof() || !getline(input, token, '-')) {
return RESULT_ERR_EOF; // incomplete
}
str = token.c_str();
if (str == NULL || *str == 0) {
return RESULT_ERR_EOF; // input too short
}
strEnd = NULL;
num = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
return RESULT_ERR_INVALID_NUM; // invalid value
}
if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
if (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
}
}
if (value < getMinValue() || value > getMaxValue()) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
return writeRawValue(value, offset, length, output, usedLength);
const char* str = input.str().c_str();
if (strcasecmp(str, NULL_VALUE) == 0) {
value = m_replacement; // replacement value
} else {
if (input.eof() || !getline(input, token, '-')) {
return RESULT_ERR_EOF; // incomplete
}
str = token.c_str();
if (str == NULL || *str == 0) {
return RESULT_ERR_EOF; // input too short
}
char* strEnd = NULL;
grp = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
return RESULT_ERR_INVALID_NUM; // invalid value
}
if (input.eof() || !getline(input, token, '-')) {
return RESULT_ERR_EOF; // incomplete
}
str = token.c_str();
if (str == NULL || *str == 0) {
return RESULT_ERR_EOF; // input too short
}
strEnd = NULL;
num = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || strEnd == str || *strEnd != 0) {
return RESULT_ERR_INVALID_NUM; // invalid value
}
if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
if (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
}
}
if (value < getMinValue() || value > getMaxValue()) {
return RESULT_ERR_OUT_OF_RANGE; // value out of range
}
return writeRawValue(value, offset, length, output, usedLength);
}
} // namespace ebusd
+17 -17
View File
@@ -41,26 +41,26 @@ namespace ebusd {
* data.
*/
class TemParamDataType : public NumberDataType {
public:
/**
* Constructs a new instance.
* @param id the type identifier.
*/
explicit TemParamDataType(const string id)
: NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {}
public:
/**
* Constructs a new instance.
* @param id the type identifier.
*/
explicit TemParamDataType(const string id)
: NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {}
// @copydoc
virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived);
// @copydoc
virtual result_t derive(int divisor, unsigned char bitCount, NumberDataType* &derived);
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
// @copydoc
virtual result_t readSymbols(SymbolString& input, const bool isMaster,
const unsigned char offset, const unsigned char length,
ostringstream& output, OutputFormat outputFormat);
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
// @copydoc
virtual result_t writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char length,
SymbolString& output, const bool isMaster, unsigned char* usedLength);
};
/**
+153 -153
View File
@@ -28,167 +28,167 @@ using namespace ebusd;
static bool error = false;
void verify(bool expectFailMatch, string type, string input,
bool match, string expectStr, string gotStr) {
match = match && expectStr == gotStr;
if (expectFailMatch) {
if (match) {
cout << " failed " << type << " match >" << input
<< "< error: unexpectedly succeeded" << endl;
error = true;
} else {
cout << " failed " << type << " match >" << input << "< OK" << endl;
}
} else if (match) {
cout << " " << type << " match >" << input << "< OK" << endl;
} else {
cout << " " << type << " match >" << input << "< error: got >"
<< gotStr << "<, expected >" << expectStr << "<" << endl;
error = true;
}
bool match, string expectStr, string gotStr) {
match = match && expectStr == gotStr;
if (expectFailMatch) {
if (match) {
cout << " failed " << type << " match >" << input
<< "< error: unexpectedly succeeded" << endl;
error = true;
} else {
cout << " failed " << type << " match >" << input << "< OK" << endl;
}
} else if (match) {
cout << " " << type << " match >" << input << "< OK" << endl;
} else {
cout << " " << type << " match >" << input << "< error: got >"
<< gotStr << "<, expected >" << expectStr << "<" << endl;
error = true;
}
}
int main() {
DataType* type = DataTypeList::getInstance()->get("TEM_P");
if (type == NULL) {
cout << "datatype not registered" << endl;
return 1;
}
DataType* type = DataTypeList::getInstance()->get("TEM_P");
if (type == NULL) {
cout << "datatype not registered" << endl;
return 1;
}
string checks[][5] = {
// entry: definition, decoded value, master data, slave data, flags
// definition: name,part,type[:len][,[divisor|values][,[unit][,[comment]]]]
{"x,,TEM_P", "04-033", "10fe0700020421", "00", ""},
{"x,,TEM_P", "00-000", "10fe0700020000", "00", ""},
{"x,,TEM_P", "31-127", "10fe0700021f7f", "00", ""},
{"x,,TEM_P", "-", "10fe070002ffff", "00", ""},
{"x,,TEM_P", "32-000", "10fe0700022000", "00", "Rw"},
{"x,,TEM_P", "00-128", "10fe0700020080", "00", "Rw"},
string checks[][5] = {
// entry: definition, decoded value, master data, slave data, flags
// definition: name,part,type[:len][,[divisor|values][,[unit][,[comment]]]]
{"x,,TEM_P", "04-033", "10fe0700020421", "00", ""},
{"x,,TEM_P", "00-000", "10fe0700020000", "00", ""},
{"x,,TEM_P", "31-127", "10fe0700021f7f", "00", ""},
{"x,,TEM_P", "-", "10fe070002ffff", "00", ""},
{"x,,TEM_P", "32-000", "10fe0700022000", "00", "Rw"},
{"x,,TEM_P", "00-128", "10fe0700020080", "00", "Rw"},
{"x,,TEM_P", "04-033", "1015070000", "022102", ""},
{"x,,TEM_P", "00-000", "1015070000", "020000", ""},
{"x,,TEM_P", "31-127", "1015070000", "02ff0f", ""},
{"x,,TEM_P", "-", "1015070000", "02ffff", ""},
{"x,,TEM_P", "32-000", "1015070000", "022000", "Rw"},
{"x,,TEM_P", "00-128", "1015070000", "020080", "Rw"},
};
DataFieldTemplates* templates = new DataFieldTemplates();
DataField* fields = NULL;
for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
string check[5] = checks[i];
istringstream isstr(check[0]);
string expectStr = check[1];
SymbolString mstr(false);
result_t result = mstr.parseHex(check[2]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
error = true;
continue;
}
SymbolString sstr(false);
result = sstr.parseHex(check[3]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
error = true;
continue;
}
string flags = check[4];
bool isSet = flags.find('s') != string::npos;
bool failedRead = flags.find('r') != string::npos;
bool failedReadMatch = flags.find('R') != string::npos;
bool failedWrite = flags.find('w') != string::npos;
bool failedWriteMatch = flags.find('W') != string::npos;
string item;
vector<string> entries;
{"x,,TEM_P", "04-033", "1015070000", "022102", ""},
{"x,,TEM_P", "00-000", "1015070000", "020000", ""},
{"x,,TEM_P", "31-127", "1015070000", "02ff0f", ""},
{"x,,TEM_P", "-", "1015070000", "02ffff", ""},
{"x,,TEM_P", "32-000", "1015070000", "022000", "Rw"},
{"x,,TEM_P", "00-128", "1015070000", "020080", "Rw"},
};
DataFieldTemplates* templates = new DataFieldTemplates();
DataField* fields = NULL;
for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
string check[5] = checks[i];
istringstream isstr(check[0]);
string expectStr = check[1];
SymbolString mstr(false);
result_t result = mstr.parseHex(check[2]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[2] << "\" error: " << getResultCode(result) << endl;
error = true;
continue;
}
SymbolString sstr(false);
result = sstr.parseHex(check[3]);
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": parse \"" << check[3] << "\" error: " << getResultCode(result) << endl;
error = true;
continue;
}
string flags = check[4];
bool isSet = flags.find('s') != string::npos;
bool failedRead = flags.find('r') != string::npos;
bool failedReadMatch = flags.find('R') != string::npos;
bool failedWrite = flags.find('w') != string::npos;
bool failedWriteMatch = flags.find('W') != string::npos;
string item;
vector<string> entries;
while (getline(isstr, item, FIELD_SEPARATOR))
entries.push_back(item);
while (getline(isstr, item, FIELD_SEPARATOR))
entries.push_back(item);
if (fields != NULL) {
delete fields;
fields = NULL;
}
vector<string>::iterator it = entries.begin();
result = DataField::create(it, entries.end(), templates, fields, isSet, false, (mstr[1] == BROADCAST || isMaster(mstr[1])));
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": create error: " << getResultCode(result) << endl;
error = true;
continue;
}
if (fields == NULL) {
cout << "\"" << check[0] << "\": create error: NULL" << endl;
error = true;
continue;
}
if (it != entries.end()) {
cout << "\"" << check[0] << "\": create error: trailing input" << endl;
error = true;
continue;
}
cout << "\"" << check[0] << "\"=\"";
fields->dump(cout);
cout << "\": create OK" << endl;
if (fields != NULL) {
delete fields;
fields = NULL;
}
vector<string>::iterator it = entries.begin();
result = DataField::create(it, entries.end(), templates, fields, isSet, false, (mstr[1] == BROADCAST || isMaster(mstr[1])));
if (result != RESULT_OK) {
cout << "\"" << check[0] << "\": create error: " << getResultCode(result) << endl;
error = true;
continue;
}
if (fields == NULL) {
cout << "\"" << check[0] << "\": create error: NULL" << endl;
error = true;
continue;
}
if (it != entries.end()) {
cout << "\"" << check[0] << "\": create error: trailing input" << endl;
error = true;
continue;
}
cout << "\"" << check[0] << "\"=\"";
fields->dump(cout);
cout << "\": create OK" << endl;
ostringstream output;
SymbolString writeMstr(false);
result = writeMstr.parseHex(mstr.getDataStr(true, false).substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr(true, false).substr(0, 10) << "\" error: " << getResultCode(result) << endl;
error = true;
}
SymbolString writeSstr(false);
result = writeSstr.parseHex(sstr.getDataStr(true, false).substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr(true, false).substr(0, 2) << "\" error: " << getResultCode(result) << endl;
error = true;
}
result = fields->read(pt_masterData, mstr, 0, output, 0, -1, false);
if (result >= RESULT_OK) {
result = fields->read(pt_slaveData, sstr, 0, output, 0, -1, !output.str().empty());
}
if (failedRead) {
if (result >= RESULT_OK) {
cout << " failed read " << fields->getName() << " >" << check[2] << " " << check[3]
<< "< error: unexpectedly succeeded" << endl;
error = true;
} else {
cout << " failed read " << fields->getName() << " >" << check[2] << " " << check[3]
<< "< OK" << endl;
}
} else if (result < RESULT_OK) {
cout << " read " << fields->getName() << " >" << check[2] << " " << check[3]
<< "< error: " << getResultCode(result) << endl;
error = true;
} else {
bool match = strcasecmp(output.str().c_str(), expectStr.c_str()) == 0;
verify(failedReadMatch, "read", check[2], match, expectStr, output.str());
}
ostringstream output;
SymbolString writeMstr(false);
result = writeMstr.parseHex(mstr.getDataStr(true, false).substr(0, 10));
if (result != RESULT_OK) {
cout << " parse \"" << mstr.getDataStr(true, false).substr(0, 10) << "\" error: " << getResultCode(result) << endl;
error = true;
}
SymbolString writeSstr(false);
result = writeSstr.parseHex(sstr.getDataStr(true, false).substr(0, 2));
if (result != RESULT_OK) {
cout << " parse \"" << sstr.getDataStr(true, false).substr(0, 2) << "\" error: " << getResultCode(result) << endl;
error = true;
}
result = fields->read(pt_masterData, mstr, 0, output, 0, -1, false);
if (result >= RESULT_OK) {
result = fields->read(pt_slaveData, sstr, 0, output, 0, -1, !output.str().empty());
}
if (failedRead) {
if (result >= RESULT_OK) {
cout << " failed read " << fields->getName() << " >" << check[2] << " " << check[3]
<< "< error: unexpectedly succeeded" << endl;
error = true;
} else {
cout << " failed read " << fields->getName() << " >" << check[2] << " " << check[3]
<< "< OK" << endl;
}
} else if (result < RESULT_OK) {
cout << " read " << fields->getName() << " >" << check[2] << " " << check[3]
<< "< error: " << getResultCode(result) << endl;
error = true;
} else {
bool match = strcasecmp(output.str().c_str(), expectStr.c_str()) == 0;
verify(failedReadMatch, "read", check[2], match, expectStr, output.str());
}
istringstream input(expectStr);
result = fields->write(input, pt_masterData, writeMstr, 0);
if (result >= RESULT_OK) {
result = fields->write(input, pt_slaveData, writeSstr, 0);
}
if (failedWrite) {
if (result >= RESULT_OK) {
cout << " failed write " << fields->getName() << " >"
<< expectStr << "< error: unexpectedly succeeded" << endl;
error = true;
} else {
cout << " failed write " << fields->getName() << " >"
<< expectStr << "< OK" << endl;
}
} else if (result < RESULT_OK) {
cout << " write " << fields->getName() << " >" << expectStr
<< "< error: " << getResultCode(result) << endl;
error = true;
} else {
bool match = mstr == writeMstr && sstr == writeSstr;
verify(failedWriteMatch, "write", expectStr, match, mstr.getDataStr(true, false) + " " + sstr.getDataStr(true, false), writeMstr.getDataStr(true, false) + " " + writeSstr.getDataStr(true, false));
}
delete fields;
fields = NULL;
}
istringstream input(expectStr);
result = fields->write(input, pt_masterData, writeMstr, 0);
if (result >= RESULT_OK) {
result = fields->write(input, pt_slaveData, writeSstr, 0);
}
if (failedWrite) {
if (result >= RESULT_OK) {
cout << " failed write " << fields->getName() << " >"
<< expectStr << "< error: unexpectedly succeeded" << endl;
error = true;
} else {
cout << " failed write " << fields->getName() << " >"
<< expectStr << "< OK" << endl;
}
} else if (result < RESULT_OK) {
cout << " write " << fields->getName() << " >" << expectStr
<< "< error: " << getResultCode(result) << endl;
error = true;
} else {
bool match = mstr == writeMstr && sstr == writeSstr;
verify(failedWriteMatch, "write", expectStr, match, mstr.getDataStr(true, false) + " " + sstr.getDataStr(true, false), writeMstr.getDataStr(true, false) + " " + writeSstr.getDataStr(true, false));
}
delete fields;
fields = NULL;
}
delete templates;
return error ? 1 : 0;
delete templates;
return error ? 1 : 0;
}