From 799f6307be4bdd3b281eabb47eb4498ecd2ae3cd Mon Sep 17 00:00:00 2001 From: john30 Date: Wed, 3 Oct 2018 10:51:57 +0200 Subject: [PATCH 1/5] corrected write testing and some test cases, added more tests for bit combinations --- src/lib/ebus/test/test_data.cpp | 82 ++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/src/lib/ebus/test/test_data.cpp b/src/lib/ebus/test/test_data.cpp index 00298ca0..c9373c4c 100755 --- a/src/lib/ebus/test/test_data.cpp +++ b/src/lib/ebus/test/test_data.cpp @@ -298,7 +298,7 @@ int main() { {"x,,hcd", "99999999", "10feffff0463636363", "00", ""}, {"x,,hcd", "100000000", "10feffff0463636363", "00", "Rw"}, {"x,,hcd", "", "10feffff0400006400", "00", "rw"}, - {"x,,str:16", "0123456789ABCDEF", "10feffff1130313233343536373839414243444546", "00", ""}, + {"x,,str:16", "0123456789ABCDEF", "10feffff1030313233343536373839414243444546", "00", ""}, {"x,,uch:17", "", "10feffff00", "00", "c"}, {"x,s,uch", "0", "1025ffff0310111213", "0300010203", "W"}, {"x,s,uch", "0", "1025ffff00", "0100", ""}, @@ -419,13 +419,13 @@ int main() { {"x,,exr", "-32.767", "10feffff04c2031168", "00", ""}, {"x,,exr,1000", "-0.000090000", "10feffff04bdb851ec", "00", ""}, {"x,,exr,-100", "-9", "10feffff04bdb851ec", "00", ""}, - {"x,,d2b", "18.004", "10fe0700090112", "00", ""}, + {"x,,d2b", "18.004", "10fe0700020112", "00", ""}, {"x,,d2b", "0.000", "10feffff020000", "00", ""}, {"x,,d2b", "-0.004", "10feffff02ffff", "00", ""}, {"x,,d2b", "-", "10feffff020080", "00", ""}, {"x,,d2b", "-127.996", "10feffff020180", "00", ""}, {"x,,d2b", "127.996", "10feffff02ff7f", "00", ""}, - {"x,,d2c", "288.06", "10fe0700090112", "00", ""}, + {"x,,d2c", "288.06", "10fe0700020112", "00", ""}, {"x,,d2c", "0.00", "10feffff020000", "00", ""}, {"x,,d2c", "-0.06", "10feffff02ffff", "00", ""}, {"x,,d2c", "-", "10feffff020080", "00", ""}, @@ -490,6 +490,15 @@ int main() { {"x,,bi3,,,,y,,bi7,,,,t,,uch", "0;0;9", "10feffff020009", "00", ""}, // bit combination {"x,,bi6:2,,,,y,,bi0:2,,,,t,,uch", "2;1;9", "10feffff03800109", "00", ""}, // bit combination {"x,,BI0;BI1;BI2;BI3;BI4;BI5;BI6;BI7", "0;0;1;0;0;0;0;0", "ff75b50900", "0104", ""}, // bits + {"x,,BI0;BI7;BI0", "0;0;0", "ff75b50900", "020000", ""}, // bits + {"x,,BI0;BI7;BI0", "0;0;1", "ff75b50900", "020001", ""}, // bits + {"x,,BI0;BI7;BI0", "0;1;0", "ff75b50900", "028000", ""}, // bits + {"x,,BI0;BI7;BI0", "0;1;1", "ff75b50900", "028001", ""}, // bits + {"x,m,BI0;BI1;BI2;BI3;BI4;BI5;BI6;BI7", "0;0;1;0;0;0;0;0", "ff75b5090104", "00", ""}, // bits + {"x,m,BI0;BI7;BI0", "0;0;0", "ff75b509020000", "00", ""}, // bits + {"x,m,BI0;BI7;BI0", "0;0;1", "ff75b509020001", "00", ""}, // bits + {"x,m,BI0;BI7;BI0", "0;1;0", "ff75b509028000", "00", ""}, // bits + {"x,m,BI0;BI7;BI0", "0;1;1", "ff75b509028001", "00", ""}, // bits {"temp,d2b,,°C,Aussentemperatur", "", "", "", "t"}, // template with relative pos {"x,,temp", "18.004", "10fe0700020112", "00", ""}, // reference to template {"x,,temp,10", "1.8004", "10fe0700020112", "00", ""}, // reference to template, valid divisor product @@ -613,42 +622,51 @@ int main() { cout << "\": create OK" << endl; ostringstream output; - MasterSymbolString writeMstr; - result = writeMstr.parseHex(mstr.getStr().substr(0, 10)); - if (result != RESULT_OK) { - cout << " parse \"" << mstr.getStr().substr(0, 10) << "\" error: " << getResultCode(result) << endl; - error = true; - } - SlaveSymbolString writeSstr; - result = writeSstr.parseHex(sstr.getStr().substr(0, 2)); - if (result != RESULT_OK) { - cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl; - error = true; - } - result = fields->read(mstr, 0, false, findName, findIndex, verbosity|(numeric?OF_NUMERIC:0), -1, &output); - if (result >= RESULT_OK) { - result = fields->read(sstr, 0, !output.str().empty(), findName, findIndex, verbosity|(numeric?OF_NUMERIC:0), -1, &output); - } - if (failedRead) { + { + MasterSymbolString writeMstr; + result = writeMstr.parseHex(mstr.getStr().substr(0, 10)); + if (result != RESULT_OK) { + cout << " parse \"" << mstr.getStr().substr(0, 10) << "\" error: " << getResultCode(result) << endl; + error = true; + } + SlaveSymbolString writeSstr; + result = writeSstr.parseHex(sstr.getStr().substr(0, 2)); + if (result != RESULT_OK) { + cout << " parse \"" << sstr.getStr().substr(0, 2) << "\" error: " << getResultCode(result) << endl; + error = true; + } + result = fields->read(mstr, 0, false, findName, findIndex, verbosity|(numeric?OF_NUMERIC:0), -1, &output); if (result >= RESULT_OK) { - cout << " failed read " << fields->getName(-1) << " >" << check[2] << " " << check[3] - << "< error: unexpectedly succeeded" << endl; + result = fields->read(sstr, 0, !output.str().empty(), findName, findIndex, verbosity|(numeric?OF_NUMERIC:0), -1, &output); + } + if (failedRead) { + if (result >= RESULT_OK) { + cout << " failed read " << fields->getName(-1) << " >" << check[2] << " " << check[3] + << "< error: unexpectedly succeeded" << endl; + error = true; + } else { + cout << " failed read " << fields->getName(-1) << " >" << check[2] << " " << check[3] + << "< OK" << endl; + } + } else if (result < RESULT_OK) { + cout << " read " << fields->getName(-1) << " >" << check[2] << " " << check[3] + << "< error: " << getResultCode(result) << endl; error = true; } else { - cout << " failed read " << fields->getName(-1) << " >" << check[2] << " " << check[3] - << "< OK" << endl; + bool match = strcasecmp(output.str().c_str(), expectStr.c_str()) == 0; + verify(failedReadMatch, "read", check[2], match, expectStr, output.str()); } - } else if (result < RESULT_OK) { - cout << " read " << fields->getName(-1) << " >" << 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()); } if (verbosity == 0) { istringstream input(expectStr); + MasterSymbolString writeMstr; + result = writeMstr.parseHex(mstr.getStr().substr(0, 8)); + if (result != RESULT_OK) { + cout << " parse \"" << mstr.getStr().substr(0, 8) << "\" error: " << getResultCode(result) << endl; + error = true; + } + SlaveSymbolString writeSstr; result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeMstr, nullptr); if (result >= RESULT_OK) { result = fields->write(UI_FIELD_SEPARATOR, 0, &input, &writeSstr, nullptr); @@ -667,6 +685,8 @@ int main() { << "< error: " << getResultCode(result) << endl; error = true; } else { + writeMstr.adjustHeader(); + writeSstr.adjustHeader(); bool match = mstr == writeMstr && sstr == writeSstr; verify(failedWriteMatch, "write", expectStr, match, mstr.getStr() + " " + sstr.getStr(), writeMstr.getStr() + " " + writeSstr.getStr()); From 6bd433af46747345bb5b8d3d8150b9c32ae1a04f Mon Sep 17 00:00:00 2001 From: john30 Date: Wed, 3 Oct 2018 10:53:38 +0200 Subject: [PATCH 2/5] fix for bit combinations during write to SymbolString --- src/lib/ebus/datatype.cpp | 2 +- src/lib/ebus/symbol.h | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/ebus/datatype.cpp b/src/lib/ebus/datatype.cpp index 2a55c61e..399cc6fd 100755 --- a/src/lib/ebus/datatype.cpp +++ b/src/lib/ebus/datatype.cpp @@ -781,7 +781,7 @@ result_t NumberDataType::writeRawValue(unsigned int value, size_t offset, size_t symbol = (value / exp) & 0xff; exp <<= 8; } - if (index == start && (m_bitCount % 8) != 0 && offset + index < output->getDataSize()) { + if (index == start && (m_bitCount % 8) != 0 && offset + index < output->getCalculatedDataSize()) { output->dataAt(offset + index) |= symbol; } else { output->dataAt(offset + index) = symbol; diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index e128e0f5..82c983fc 100755 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -249,7 +249,7 @@ class SymbolString { } else if (m_data.size() >= lengthOffset+255) { return false; } - m_data[lengthOffset] = (symbol_t)(m_data.size() - 1 - lengthOffset); + m_data[lengthOffset] = (symbol_t)(m_data.size() - lengthOffset - 1); return true; } @@ -272,6 +272,18 @@ class SymbolString { return m_data.size() < lengthOffset + 1 + ret ? m_data.size() - lengthOffset - 1 : ret; } + /** + * Return the calculated number of data bytes DD (nnot yet revealed in the length field). + * @return the calculated number of data bytes DD. + */ + size_t getCalculatedDataSize() const { + size_t lengthOffset = (m_isMaster ? 4 : 0); + if (m_data.size() <= lengthOffset) { + return 0; + } + return m_data.size() - lengthOffset - 1; + } + /** * Return the data byte at the specified index (within DD). * @param index the index of the data byte (within DD) to return. From 18bd21f23f9c38857c260ecce4fc63c26713aac3 Mon Sep 17 00:00:00 2001 From: john30 Date: Wed, 3 Oct 2018 10:53:38 +0200 Subject: [PATCH 3/5] fix for bit combinations during write to SymbolString (fixes #202) --- src/lib/ebus/test/test_message.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib/ebus/test/test_message.cpp b/src/lib/ebus/test/test_message.cpp index fab58926..b409ffab 100755 --- a/src/lib/ebus/test/test_message.cpp +++ b/src/lib/ebus/test/test_message.cpp @@ -159,6 +159,20 @@ int main() { {"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B60;B71", "ff08b509030d6a00", "0213bf", "d" }, {"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B61;B70", "ff08b509030d6a00", "02137f", "d" }, {"r,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B60;B70", "ff08b509030d6a00", "02133f", "d" }, + {"w,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B71;B61", "ff08b509060e6900138040", "00", "di" }, + {"w,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B71;B60", "ff08b509060e6900138000", "00", "di" }, + {"w,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B70;B61", "ff08b509060e6900130040", "00", "di" }, + {"w,,x,,,,,6900,,,UCH,10,bar,,Bit7,,BI7:1,0=B70;1=B71,,,Bit6,,BI6:1,0=B60;1=B61", "1.9;B70;B60", "ff08b509060e6900130000", "00", "di" }, + {"w,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B61;B71", "ff08b509050e6a0013c0", "00", "di" }, + {"w,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B60;B71", "ff08b509050e6a001380", "00", "di" }, + {"w,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B61;B70", "ff08b509050e6a001340", "00", "di" }, + {"w,,x,,,,,6a00,,,UCH,10,bar,,Bit6,,BI6:1,0=B60;1=B61,,,Bit7,,BI7:1,0=B70;1=B71", "1.9;B60;B70", "ff08b509050e6a001300", "00", "di" }, + {"w,,x,,,,,,,,IGN:1,,,,b0,,BI0:1,,,,b1,,BI1:1,,,,b2,,BI2:1,,,,,,IGN:1,,,,c0,,BI0:1,,,,c1,,BI1:1,,,,c2,,BI2:1", "1;1;1;0;0;0", "ff08b509050e00070000", "00", "di" }, + {"w,,x,,,,,,,,IGN:1,,,,b0,,BI0:1,,,,b1,,BI1:1,,,,b2,,BI2:1,,,,,,IGN:1,,,,c0,,BI0:1,,,,c1,,BI1:1,,,,c2,,BI2:1", "1;0;0;0;0;1", "ff08b509050e00010004", "00", "di" }, + {"w,,x,,,,,,,,IGN:1,,,,b0,,BI0:1,,,,b1,,BI1:1,,,,b2,,BI2:1,,,,,,IGN:1,,,,c0,,BI0:1,,,,c1,,BI1:1,,,,c2,,BI2:1", "0;0;1;0;1;1", "ff08b509050e00040006", "00", "di" }, + {"w,,x,,,,,,b0,,BI0:1,,,,b1,,BI1:1,,,,b2,,BI2:6,,,,c0,,BI0:1,,,,c1,,BI1:1,,,,c2,,BI2:1", "1;1;1;0;0;0", "ff08b509030e0700", "00", "di" }, + {"w,,x,,,,,,b0,,BI0:1,,,,b1,,BI1:1,,,,b2,,BI2:6,,,,c0,,BI0:1,,,,c1,,BI1:1,,,,c2,,BI2:1", "1;0;0;0;0;1", "ff08b509030e0104", "00", "di" }, + {"w,,x,,,,,,b0,,BI0:1,,,,b1,,BI1:1,,,,b2,,BI2:6,,,,c0,,BI0:1,,,,c1,,BI1:1,,,,c2,,BI2:1", "0;0;1;0;1;1", "ff08b509030e0406", "00", "di" }, {"*r,cir*cuit#level,na*me,com*ment,ff,75,b509,0d", "", "", "", "" }, {"r,CIRCUIT,NAME,COMMENT,,,,0100,field,,UCH", "r,cirCIRCUITcuit,naNAMEme,comCOMMENTment,ff,75,b509,0d0100,field,s,UCH,,,: field=42", "ff75b509030d0100", "012a", "DN"}, {"r,CIRCUIT,NAME,COMMENT,,,,0100,field,,UCH", From 45b9bad57e16ee432805f9effb1bc9d5f3a25a20 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 21 Oct 2018 14:42:00 +0200 Subject: [PATCH 4/5] missing include (fixes #212) --- src/lib/utils/tcpsocket.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/utils/tcpsocket.cpp b/src/lib/utils/tcpsocket.cpp index f6a752d7..d33dc709 100755 --- a/src/lib/utils/tcpsocket.cpp +++ b/src/lib/utils/tcpsocket.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef HAVE_PPOLL # include #endif From b608d809161fe101e35a929a48a9714795f8e36b Mon Sep 17 00:00:00 2001 From: John Date: Fri, 30 Nov 2018 07:43:53 +0100 Subject: [PATCH 5/5] wait for being online before starting --- contrib/debian/systemd/ebusd.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/debian/systemd/ebusd.service b/contrib/debian/systemd/ebusd.service index 66f4df81..ca93a24e 100644 --- a/contrib/debian/systemd/ebusd.service +++ b/contrib/debian/systemd/ebusd.service @@ -1,6 +1,6 @@ [Unit] Description=ebusd, the daemon for communication with eBUS heating systems. -After=network.target +After=network-online.target ConditionPathExists=/var/log [Service]