added conditional messages to find command with "-a" option and include condition prefix for CSV format
also allow passing scan messages with --checkconfig and --scanconfig (without --inject) be more verbose on errors in configuration files improved code style
This commit is contained in:
@@ -53,34 +53,34 @@ class TestReader : public MappedFileReader {
|
||||
TestReader(DataFieldTemplates* templates, bool isSet, bool isMasterDest)
|
||||
: MappedFileReader::MappedFileReader(true), m_templates(templates), m_isSet(isSet), m_isMasterDest(isMasterDest),
|
||||
m_fields(NULL) {}
|
||||
result_t getFieldMap(vector<string>& row, string& errorDescription, const string preferLanguage) const override {
|
||||
if (row.empty()) {
|
||||
row.push_back("*name");
|
||||
row.push_back("part");
|
||||
row.push_back("type");
|
||||
row.push_back("divisor/values");
|
||||
row.push_back("unit");
|
||||
row.push_back("comment");
|
||||
result_t getFieldMap(const string& preferLanguage, vector<string>* row, string* errorDescription) const override {
|
||||
if (row->empty()) {
|
||||
row->push_back("*name");
|
||||
row->push_back("part");
|
||||
row->push_back("type");
|
||||
row->push_back("divisor/values");
|
||||
row->push_back("unit");
|
||||
row->push_back("comment");
|
||||
return RESULT_OK;
|
||||
}
|
||||
if (row[0][0] != '*') {
|
||||
if ((*row)[0][0] != '*') {
|
||||
return RESULT_ERR_INVALID_ARG;
|
||||
}
|
||||
return RESULT_OK; // leave it to DataField::create
|
||||
}
|
||||
result_t addFromFile(map<string, string>& row, vector< map<string, string> >& subRows,
|
||||
string& errorDescription, const string filename, unsigned int lineNo) override {
|
||||
if (!row.empty() || subRows.empty()) {
|
||||
result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
|
||||
vector< map<string, string> >* subRows, string* errorDescription) override {
|
||||
if (!row->empty() || subRows->empty()) {
|
||||
cout << "read line " << static_cast<unsigned>(lineNo) << ": read error: got "
|
||||
<< static_cast<unsigned>(row.size()) << "/0 main, " << static_cast<unsigned>(subRows.size())
|
||||
<< static_cast<unsigned>(row->size()) << "/0 main, " << static_cast<unsigned>(subRows->size())
|
||||
<< "/>=3 sub" << endl;
|
||||
return RESULT_ERR_EOF;
|
||||
}
|
||||
cout << "read line " << static_cast<unsigned>(lineNo) << ": read OK" << endl;
|
||||
return DataField::create(subRows, errorDescription, m_templates, m_fields, m_isSet, false, m_isMasterDest);
|
||||
return DataField::create(m_isSet, false, m_isMasterDest, MAX_POS, m_templates, subRows, errorDescription, &m_fields);
|
||||
}
|
||||
private:
|
||||
DataFieldTemplates* m_templates;
|
||||
const DataFieldTemplates* m_templates;
|
||||
const bool m_isSet;
|
||||
const bool m_isMasterDest;
|
||||
public:
|
||||
@@ -508,7 +508,7 @@ int main() {
|
||||
istringstream dummystr("#");
|
||||
string errorDescription;
|
||||
vector<string> row;
|
||||
templates->readLineFromStream(dummystr, errorDescription, __FILE__, lineNo, row);
|
||||
templates->readLineFromStream(__FILE__, false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
const DataField* fields = NULL;
|
||||
for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {
|
||||
string check[5] = checks[i];
|
||||
@@ -558,7 +558,7 @@ int main() {
|
||||
}
|
||||
if (isTemplate) {
|
||||
lineNo = baseLine + i;
|
||||
result = templates->readLineFromStream(isstr, errorDescription, __FILE__, lineNo, row, false);
|
||||
result = templates->readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", "
|
||||
<< errorDescription << endl;
|
||||
@@ -570,7 +570,7 @@ int main() {
|
||||
lineNo = 0;
|
||||
dummystr.clear();
|
||||
dummystr.str("#");
|
||||
result = reader.readLineFromStream(dummystr, errorDescription, __FILE__, lineNo, row);
|
||||
result = reader.readLineFromStream(__FILE__, false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": reader header error: " << getResultCode(result) << ", " << errorDescription
|
||||
<< endl;
|
||||
@@ -578,7 +578,7 @@ int main() {
|
||||
continue;
|
||||
}
|
||||
lineNo = baseLine + i;
|
||||
result = reader.readLineFromStream(isstr, errorDescription, "", lineNo, row);
|
||||
result = reader.readLineFromStream("", false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
fields = reader.m_fields;
|
||||
if (failedCreate) {
|
||||
if (result == RESULT_OK) {
|
||||
@@ -600,7 +600,7 @@ int main() {
|
||||
continue;
|
||||
}
|
||||
cout << "\"" << check[0] << "\"=\"";
|
||||
fields->dump(cout);
|
||||
fields->dump(&cout);
|
||||
cout << "\": create OK" << endl;
|
||||
|
||||
ostringstream output;
|
||||
@@ -616,22 +616,21 @@ int main() {
|
||||
cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
}
|
||||
result = fields->read(mstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1, false);
|
||||
result = fields->read(mstr, 0, false, NULL, -1, verbosity|(numeric?OF_NUMERIC:0), -1, &output);
|
||||
if (result >= RESULT_OK) {
|
||||
result = fields->read(sstr, 0, output, verbosity|(numeric?OF_NUMERIC:0), -1,
|
||||
!output.str().empty());
|
||||
result = fields->read(sstr, 0, !output.str().empty(), NULL, -1, verbosity|(numeric?OF_NUMERIC:0), -1, &output);
|
||||
}
|
||||
if (failedRead) {
|
||||
if (result >= RESULT_OK) {
|
||||
cout << " failed read " << fields->getName() << " >" << check[2] << " " << check[3]
|
||||
cout << " failed read " << fields->getName(-1) << " >" << check[2] << " " << check[3]
|
||||
<< "< error: unexpectedly succeeded" << endl;
|
||||
error = true;
|
||||
} else {
|
||||
cout << " failed read " << fields->getName() << " >" << check[2] << " " << check[3]
|
||||
cout << " failed read " << fields->getName(-1) << " >" << check[2] << " " << check[3]
|
||||
<< "< OK" << endl;
|
||||
}
|
||||
} else if (result < RESULT_OK) {
|
||||
cout << " read " << fields->getName() << " >" << check[2] << " " << check[3]
|
||||
cout << " read " << fields->getName(-1) << " >" << check[2] << " " << check[3]
|
||||
<< "< error: " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
} else {
|
||||
@@ -641,21 +640,21 @@ int main() {
|
||||
|
||||
if (verbosity == 0) {
|
||||
istringstream input(expectStr);
|
||||
result = fields->write(input, writeMstr, 0);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeMstr, NULL);
|
||||
if (result >= RESULT_OK) {
|
||||
result = fields->write(input, writeSstr, 0);
|
||||
result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeSstr, NULL);
|
||||
}
|
||||
if (failedWrite) {
|
||||
if (result >= RESULT_OK) {
|
||||
cout << " failed write " << fields->getName() << " >"
|
||||
cout << " failed write " << fields->getName(-1) << " >"
|
||||
<< expectStr << "< error: unexpectedly succeeded" << endl;
|
||||
error = true;
|
||||
} else {
|
||||
cout << " failed write " << fields->getName() << " >"
|
||||
cout << " failed write " << fields->getName(-1) << " >"
|
||||
<< expectStr << "< OK" << endl;
|
||||
}
|
||||
} else if (result < RESULT_OK) {
|
||||
cout << " write " << fields->getName() << " >" << expectStr
|
||||
cout << " write " << fields->getName(-1) << " >" << expectStr
|
||||
<< "< error: " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
} else {
|
||||
|
||||
@@ -40,7 +40,7 @@ int main() {
|
||||
|
||||
while (1) {
|
||||
symbol_t byte = 0;
|
||||
result = device->recv(0, byte);
|
||||
result = device->recv(0, &byte);
|
||||
|
||||
if (result == RESULT_OK) {
|
||||
cout << hex << setw(2) << setfill('0')
|
||||
|
||||
@@ -73,8 +73,8 @@ static unsigned int baseLine = 0;
|
||||
|
||||
class NoopReader : public FileReader {
|
||||
public:
|
||||
result_t addFromFile(vector<string>& row, string& errorDescription,
|
||||
const string filename, unsigned int lineNo) override {
|
||||
result_t addFromFile(const string& filename, unsigned int lineNo, vector<string>* row,
|
||||
string* errorDescription) override {
|
||||
return RESULT_OK;
|
||||
}
|
||||
};
|
||||
@@ -83,25 +83,25 @@ class TestReader : public MappedFileReader {
|
||||
public:
|
||||
TestReader(size_t expectedCols, size_t langCols)
|
||||
: MappedFileReader::MappedFileReader(false, ""), m_expectedCols(expectedCols), m_langCols(langCols) {}
|
||||
result_t getFieldMap(vector<string>& row, string& errorDescription, const string preferLanguage) const override {
|
||||
if (row.size() == m_expectedCols+m_langCols) {
|
||||
result_t getFieldMap(const string& preferLanguage, vector<string>* row, string* errorDescription) const override {
|
||||
if (row->size() == m_expectedCols+m_langCols) {
|
||||
cout << "get field map: split OK" << endl;
|
||||
if (m_langCols == 1) {
|
||||
row[0] = SKIP_COLUMN;
|
||||
size_t pos = row[1].find_last_of('.');
|
||||
row[1] = row[1].substr(0, pos);
|
||||
(*row)[0] = SKIP_COLUMN;
|
||||
size_t pos = (*row)[1].find_last_of('.');
|
||||
(*row)[1] = (*row)[1].substr(0, pos);
|
||||
}
|
||||
return RESULT_OK;
|
||||
}
|
||||
cout << "get field map: error got " << static_cast<unsigned>(row.size()) << " columns, expected " <<
|
||||
cout << "get field map: error got " << static_cast<unsigned>(row->size()) << " columns, expected " <<
|
||||
static_cast<unsigned>(m_expectedCols+m_langCols) << endl;
|
||||
return RESULT_ERR_EOF;
|
||||
}
|
||||
result_t addFromFile(map<string, string>& row, vector< map<string, string> >& subRows,
|
||||
string& errorDescription, const string filename, unsigned int lineNo) override {
|
||||
if (row.empty() || (m_expectedCols == 3) != subRows.empty()) {
|
||||
result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
|
||||
vector< map<string, string> >* subRows, string* errorDescription) override {
|
||||
if (row->empty() || (m_expectedCols == 3) != subRows->empty()) {
|
||||
cout << "read line " << static_cast<unsigned>(baseLine + lineNo) << ": read error: got "
|
||||
<< static_cast<unsigned>(row.size()) << "/3 main, " << static_cast<unsigned>(subRows.size())
|
||||
<< static_cast<unsigned>(row->size()) << "/3 main, " << static_cast<unsigned>(subRows->size())
|
||||
<< (m_expectedCols == 3 ? "/0 sub" : "/>0 sub") << endl;
|
||||
return RESULT_ERR_EOF;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class TestReader : public MappedFileReader {
|
||||
}
|
||||
cout << "read line " << static_cast<unsigned>(baseLine + lineNo) << ": split OK" << endl;
|
||||
string resultline[3] = resultlines[lineNo - 1];
|
||||
if (row.empty()) {
|
||||
if (row->empty()) {
|
||||
cout << " result empty";
|
||||
if (resultline[0] == "") {
|
||||
cout << ": OK" << endl;
|
||||
@@ -127,7 +127,7 @@ class TestReader : public MappedFileReader {
|
||||
map<string, string>& defaults = getDefaults()[""];
|
||||
for (size_t colIdx = 0; colIdx < 3; colIdx++) {
|
||||
string col = colnames[colIdx];
|
||||
string got = row[col] + defaults[col];
|
||||
string got = (*row)[col] + defaults[col];
|
||||
string expect = resultline[colIdx];
|
||||
ostringstream type;
|
||||
type << "line " << static_cast<unsigned>(baseLine + lineNo) << " column \"" << col << "\"";
|
||||
@@ -137,17 +137,17 @@ class TestReader : public MappedFileReader {
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
if (row.size() > 3) {
|
||||
if (row->size() > 3) {
|
||||
ostringstream type;
|
||||
type << "line " << static_cast<unsigned>(baseLine + lineNo);
|
||||
verify(false, type.str(), "", false, "", "extra column");
|
||||
error = true;
|
||||
}
|
||||
|
||||
for (size_t subIdx = 0; subIdx < subRows.size(); subIdx++) {
|
||||
for (size_t subIdx = 0; subIdx < subRows->size(); subIdx++) {
|
||||
string resultsubline[4] = resultsublines[lineNo - 1][subIdx];
|
||||
row = subRows[subIdx];
|
||||
if (row.empty()) {
|
||||
*row = (*subRows)[subIdx];
|
||||
if (row->empty()) {
|
||||
cout << " sub " << subIdx << " result empty";
|
||||
if (resultline[0] == "") {
|
||||
cout << ": OK" << endl;
|
||||
@@ -161,7 +161,7 @@ class TestReader : public MappedFileReader {
|
||||
vector< map<string, string> >& subDefaults = getSubDefaults()[""];
|
||||
for (size_t colIdx = 0; colIdx < 2; colIdx++) {
|
||||
string col = resultsubline[colIdx*2];
|
||||
string got = row[col];
|
||||
string got = (*row)[col];
|
||||
if (subIdx < subDefaults.size()) {
|
||||
got += subDefaults[subIdx][col];
|
||||
}
|
||||
@@ -174,7 +174,7 @@ class TestReader : public MappedFileReader {
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
if (row.size() > 2) {
|
||||
if (row->size() > 2) {
|
||||
ostringstream type;
|
||||
type << "line " << static_cast<unsigned>(baseLine + lineNo) << " sub " << subIdx;
|
||||
verify(false, type.str(), "", false, "", "extra sub column");
|
||||
@@ -196,14 +196,14 @@ int main(int argc, char** argv) {
|
||||
size_t hash = 0, size = 0;
|
||||
time_t time = 0;
|
||||
string errorDescription;
|
||||
result_t result = reader.readFromFile(argv[argpos], errorDescription, false, NULL, &hash, &size, &time);
|
||||
result_t result = reader.readFromFile(argv[argpos], false, NULL, &errorDescription, &hash, &size, &time);
|
||||
cout << argv[argpos] << " ";
|
||||
if (result != RESULT_OK) {
|
||||
cout << getResultCode(result) << ", " << errorDescription << endl;
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
FileReader::formatHash(hash, cout);
|
||||
FileReader::formatHash(hash, &cout);
|
||||
cout << " " << size << " " << time << endl;
|
||||
}
|
||||
return error ? 1 : 0;
|
||||
@@ -226,7 +226,7 @@ int main(int argc, char** argv) {
|
||||
string errorDescription;
|
||||
while (ifs.peek() != EOF) {
|
||||
istringstream str;
|
||||
result_t result = reader.readLineFromStream(ifs, errorDescription, "", lineNo, row, true, &hash, &size);
|
||||
result_t result = reader.readLineFromStream("", true, &ifs, &lineNo, &row, &errorDescription, &hash, &size);
|
||||
if (result != RESULT_OK) {
|
||||
cout << " error " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
@@ -267,7 +267,7 @@ int main(int argc, char** argv) {
|
||||
subDefaults[0]["subcol 2"] = ";default of sub 0 subcol 2";
|
||||
while (ifs.peek() != EOF) {
|
||||
istringstream str;
|
||||
result_t result = reader2.readLineFromStream(ifs, errorDescription, "", lineNo, row, true, &hash, &size);
|
||||
result_t result = reader2.readLineFromStream("", true, &ifs, &lineNo, &row, &errorDescription, &hash, &size);
|
||||
if (result != RESULT_OK) {
|
||||
cout << " error " << getResultCode(result) << endl;
|
||||
error = true;
|
||||
|
||||
@@ -54,7 +54,7 @@ DataFieldTemplates* templates = NULL;
|
||||
|
||||
namespace ebusd {
|
||||
|
||||
DataFieldTemplates* getTemplates(const string filename) {
|
||||
DataFieldTemplates* getTemplates(const string& filename) {
|
||||
if (filename == "") { // avoid compiler warning
|
||||
return templates;
|
||||
}
|
||||
@@ -71,7 +71,9 @@ int main() {
|
||||
unsigned int baseLine = __LINE__+1;
|
||||
string checks[][5] = {
|
||||
{"date,HDA:3,,,Datum", "", "", "", "template"},
|
||||
{"bdate:date,BDA,,,Datum", "", "", "", "template"},
|
||||
{"time,VTI,,,", "", "", "", "template"},
|
||||
{"btime:time,BTI,,,Uhrzeit", "", "", "", "template"},
|
||||
{"dcfstate,UCH,0=nosignal;1=ok;2=sync;3=valid,,", "", "", "", "template"},
|
||||
{"temp,D2C,,°C,Temperatur", "", "", "", "template"},
|
||||
{"temp1,D1C,,°C,Temperatur", "", "", "", "template"},
|
||||
@@ -93,6 +95,8 @@ int main() {
|
||||
{"r,cir,name,,,25,B509,0d28,,m,sensorc,,,,,,temp", "-14.00", "ff25b509030d2855", "0220ff", ""},
|
||||
{"u,cir,first,,,fe,0700,,x,,bda", "26.10.2014", "fffe07000426100614", "00", "p"},
|
||||
{"u,broadcast,hwStatus,,,fe,b505,27,,,UCH,,,,,,UCH,,,,,,UCH,,,", "0;19;0", "10feb505042700130097", "00", ""},
|
||||
{"u,broadcast,datetime,Datum/Uhrzeit,,fe,0700,,outsidetemp,,temp2,,°C,Aussentemperatur,time,,btime,,,,date,,BDA,,,Datum", "outsidetemp=14.500 °C [Aussentemperatur];time=12:25:01 [Uhrzeit];date=01.05.2017 [Datum]", "10fe070009800e01251201050017", "", "D"},
|
||||
{"u,broadcast,datetime,Datum Uhrzeit,,fe,0700,,,,temp2;btime;bdate", "temp2=14.500 °C [Temperatur];time=12:25:01 [Uhrzeit];date=01.05.2017 [Datum]", "10fe070009800e01251201050017", "", "D"},
|
||||
{"w,cir,first,,,15,b509,0400,date,,bda", "26.10.2014", "ff15b50906040026100614", "00", ""},
|
||||
{"w,cir,first,,,15,b509", "", "ff15b50900", "00", ""},
|
||||
{"*w,,,,,,b505,2d", "", "", "", ""},
|
||||
@@ -147,12 +151,12 @@ int main() {
|
||||
istringstream dummystr("#");
|
||||
string errorDescription;
|
||||
vector<string> row;
|
||||
templates->readLineFromStream(dummystr, errorDescription, __FILE__, lineNo, row, false);
|
||||
templates->readLineFromStream(__FILE__, false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
lineNo = 0;
|
||||
MessageMap* messages = new MessageMap("");
|
||||
dummystr.clear();
|
||||
dummystr.str("#");
|
||||
messages->readLineFromStream(dummystr, errorDescription, __FILE__, lineNo, row, false);
|
||||
messages->readLineFromStream(__FILE__, false, &dummystr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
vector< vector<string> > defaultsRows;
|
||||
Message* message = NULL;
|
||||
vector<MasterSymbolString*> mstrs;
|
||||
@@ -183,7 +187,7 @@ int main() {
|
||||
lineNo = baseLine + i;
|
||||
cout << "line " << (lineNo+1) << " ";
|
||||
if (isTemplate) {
|
||||
result = templates->readLineFromStream(isstr, errorDescription, __FILE__, lineNo, row);
|
||||
result = templates->readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": template read error: " << getResultCode(result) << ", " << errorDescription
|
||||
<< endl;
|
||||
@@ -197,7 +201,7 @@ int main() {
|
||||
}
|
||||
if (isstr.peek() == '*') {
|
||||
// store defaults or condition
|
||||
result = messages->readLineFromStream(isstr, errorDescription, __FILE__, lineNo, row);
|
||||
result = messages->readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
if (result != RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": default read error: " << getResultCode(result) << ", " << errorDescription << endl;
|
||||
error = true;
|
||||
@@ -279,7 +283,7 @@ int main() {
|
||||
}
|
||||
cout << "\"" << check[2] << "\": find OK" << endl;
|
||||
} else {
|
||||
result = messages->readLineFromStream(isstr, errorDescription, __FILE__, lineNo, row);
|
||||
result = messages->readLineFromStream(__FILE__, false, &isstr, &lineNo, &row, &errorDescription, NULL, NULL);
|
||||
if (failedCreate) {
|
||||
if (result == RESULT_OK) {
|
||||
cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl;
|
||||
@@ -345,11 +349,11 @@ int main() {
|
||||
}
|
||||
ostringstream output;
|
||||
if (withMessageDump && !decodeJson) {
|
||||
message->dump(output, NULL, true);
|
||||
message->dump(NULL, true, &output);
|
||||
output << ": ";
|
||||
}
|
||||
result = message->decodeLastData(output,
|
||||
(decodeVerbose?OF_NAMES|OF_UNITS|OF_COMMENTS:0)|(decodeJson?OF_NAMES|OF_JSON:0), false);
|
||||
result = message->decodeLastData(false, NULL, -1,
|
||||
(decodeVerbose?OF_NAMES|OF_UNITS|OF_COMMENTS:0)|(decodeJson?OF_NAMES|OF_JSON:0), &output);
|
||||
if (result != RESULT_OK) {
|
||||
cout << " \"" << check[2] << "\" / \"" << check[3] << "\": decode error: "
|
||||
<< getResultCode(result) << endl;
|
||||
@@ -385,7 +389,7 @@ int main() {
|
||||
if (!message->isPassive() && (withInput || !decode)) {
|
||||
istringstream input(inputStr);
|
||||
MasterSymbolString writeMstr;
|
||||
result = message->prepareMaster(0xff, writeMstr, input);
|
||||
result = message->prepareMaster(0, 0xff, SYN, UI_FIELD_SEPARATOR, &input, &writeMstr);
|
||||
if (failedPrepare) {
|
||||
if (result == RESULT_OK) {
|
||||
cout << " \"" << inputStr << "\": failed prepare error: unexpectedly succeeded" << endl;
|
||||
|
||||
Reference in New Issue
Block a user