From de40346c6b516c18a98c3584701918e20ef5764a Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 19 Feb 2017 10:46:56 +0100 Subject: [PATCH] added skipFirstSymbols param to getDataStr() --- src/lib/ebus/symbol.cpp | 12 ++++++++---- src/lib/ebus/symbol.h | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp index b7e0b9aa..28bd23f9 100644 --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -88,14 +88,16 @@ result_t SymbolString::parseHex(const string& str, const bool isEscaped) { return RESULT_OK; } -const string SymbolString::getDataStr(const bool unescape, const bool skipLastSymbol) { - ostringstream sstr; +const string SymbolString::getDataStr(const bool unescape, const bool skipLastSymbol, + unsigned char skipFirstSymbols) { bool previousEscape = false; - + ostringstream sstr; for (size_t i = 0; i < m_data.size(); i++) { unsigned char value = m_data[i]; if (m_unescapeState == 0 && unescape && previousEscape) { - if (!skipLastSymbol || i+1 < m_data.size()) { + if (skipFirstSymbols > 0) { + skipFirstSymbols--; + } else if (!skipLastSymbol || i+1 < m_data.size()) { if (value == 0x00) { sstr << "a9"; // ESC } else if (value == 0x01) { @@ -107,6 +109,8 @@ const string SymbolString::getDataStr(const bool unescape, const bool skipLastSy previousEscape = false; } else if (m_unescapeState == 0 && unescape && value == ESC) { previousEscape = true; // escape sequence not yet finished + } else if (skipFirstSymbols > 0) { + skipFirstSymbols--; } else if (!skipLastSymbol || i+1 < m_data.size()) { sstr << nouppercase << setw(2) << hex << setfill('0') << static_cast(value); diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index 0eadcd23..30d511e0 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -108,7 +108,8 @@ class SymbolString { * @param skipLastSymbol whether to skip the last symbol (probably the CRC). * @return the symbols as hex string. */ - const string getDataStr(const bool unescape = true, const bool skipLastSymbol = true); + const string getDataStr(const bool unescape = true, const bool skipLastSymbol = true, + unsigned char skipFirstSymbols = 0); /** * Return a reference to the symbol at the specified index.