From 08515d1167c24f0801fb755a780764291717e810 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 27 Jun 2024 18:34:45 +0200 Subject: [PATCH] unify decodeLastData usage, add raw logging to read cmd --- src/ebusd/bushandler.cpp | 14 ++++---- src/ebusd/mainloop.cpp | 33 ++++++++++++------- src/ebusd/mqtthandler.cpp | 4 +-- src/lib/ebus/data.cpp | 36 ++++++++++++++++++-- src/lib/ebus/data.h | 11 +++++++ src/lib/ebus/datatype.h | 3 ++ src/lib/ebus/message.cpp | 53 ++++++++++++------------------ src/lib/ebus/message.h | 23 +++---------- src/lib/ebus/test/test_message.cpp | 31 ++++++++++++++--- 9 files changed, 131 insertions(+), 77 deletions(-) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 93d24ef5..36ab8480 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -101,7 +101,7 @@ bool ScanRequest::notify(result_t result, const SlaveSymbolString& slave) { } if (result == RESULT_OK) { ostringstream output; - result = m_message->decodeLastData(true, nullptr, -1, OF_NONE, &output); // decode data + result = m_message->decodeLastData(pt_any, true, nullptr, -1, OF_NONE, &output); // decode data string str = output.str(); m_busHandler->setScanResult(dstAddress, m_notifyIndex+m_index, str); } @@ -403,7 +403,7 @@ void BusHandler::notifyProtocolMessage(MessageDirection direction, const MasterS result = message->storeLastData(0, idData); if (result == RESULT_OK) { ostringstream output; - result = message->decodeLastData(true, nullptr, -1, OF_NONE, &output); + result = message->decodeLastData(pt_any, true, nullptr, -1, OF_NONE, &output); if (result == RESULT_OK) { string str = output.str(); setScanResult(slaveAddress, 0, str); @@ -420,7 +420,7 @@ void BusHandler::notifyProtocolMessage(MessageDirection direction, const MasterS result_t result = message->storeLastData(command, response); if (result == RESULT_OK) { ostringstream output; - result = message->decodeLastData(true, nullptr, -1, OF_NONE, &output); + result = message->decodeLastData(pt_any, true, nullptr, -1, OF_NONE, &output); if (result == RESULT_OK) { string str = output.str(); setScanResult(dstAddress, 0, str); @@ -475,7 +475,7 @@ void BusHandler::notifyProtocolMessage(MessageDirection direction, const MasterS result_t result = message->storeLastData(command, response); ostringstream output; if (result == RESULT_OK) { - result = message->decodeLastData(false, nullptr, -1, OF_NONE, &output); + result = message->decodeLastData(pt_any, false, nullptr, -1, OF_NONE, &output); } if (result < RESULT_OK) { logError(lf_update, "unable to parse %s %s %s from %s / %s: %s", mode, circuit.c_str(), name.c_str(), @@ -639,7 +639,7 @@ void BusHandler::formatScanResult(ostringstream* output) const { *output << endl; } *output << hex << setw(2) << setfill('0') << static_cast(slave); - message->decodeLastData(true, nullptr, -1, OF_NONE, output); + message->decodeLastData(pt_any, true, nullptr, -1, OF_NONE, output); } } } @@ -680,7 +680,7 @@ void BusHandler::formatSeenInfo(ostringstream* output) const { if (message != nullptr && message->getLastUpdateTime() > 0) { // add detailed scan info: Manufacturer ID SW HW *output << " \""; - result_t result = message->decodeLastData(false, nullptr, -1, OF_NAMES, output); + result_t result = message->decodeLastData(pt_any, false, nullptr, -1, OF_NAMES, output); if (result != RESULT_OK) { *output << "\" error: " << getResultCode(result); } else { @@ -759,7 +759,7 @@ void BusHandler::formatUpdateInfo(ostringstream* output) const { Message* message = m_messages->getScanMessage(address); if (message != nullptr && message->getLastUpdateTime() > 0) { // add detailed scan info: Manufacturer ID SW HW - message->decodeLastData(true, nullptr, -1, OF_NAMES|OF_NUMERIC|OF_JSON|OF_SHORT, output); + message->decodeLastData(pt_any, true, nullptr, -1, OF_NAMES|OF_NUMERIC|OF_JSON|OF_SHORT, output); } } const vector& loadedFiles = m_messages->getLoadedFiles(address); diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 924b7a18..5c31433d 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -402,7 +402,7 @@ void MainLoop::run() { m_messages->findAll("", "", levels, false, true, true, true, true, true, since, now, true, &messages); for (const auto message : messages) { ostream << message->getCircuit() << " " << message->getName() << " = " << dec; - message->decodeLastData(false, nullptr, -1, reqMode.format, &ostream); + message->decodeLastData(pt_any, false, nullptr, -1, reqMode.format, &ostream); ostream << endl; } } @@ -648,8 +648,15 @@ result_t MainLoop::executeRead(const vector& args, const string& levels, } } else if (args[argPos] == "-vv") { verbosity |= VERBOSITY_2; - } else if (args[argPos] == "-vvv" || args[argPos] == "-V") { + } else if (args[argPos] == "-vvv") { verbosity |= VERBOSITY_3; + } else if (args[argPos] == "-V") { + if ((verbosity & VERBOSITY_4) == VERBOSITY_4) { + verbosity |= OF_RAWDATA; + } + verbosity |= VERBOSITY_4; + } else if (args[argPos] == "-VV") { + verbosity |= VERBOSITY_4 | OF_RAWDATA; } else if (args[argPos] == "-n") { verbosity = (verbosity & ~OF_VALUENAME) | OF_NUMERIC; } else if (args[argPos] == "-N") { @@ -723,7 +730,7 @@ result_t MainLoop::executeRead(const vector& args, const string& levels, " -d ZZ override destination address ZZ\n" " -p PRIO set the message poll priority (1-9)\n" " -v increase verbosity (include names/units/comments)\n" - " -V be very verbose (include names, units, and comments)\n" + " -V be very verbose (all attributes, plus raw data if given more than once)\n" " -n use numeric value of value=name pairs\n" " -N use numeric and named value of value=name pairs\n" " -i VALUE read additional message parameters from VALUE\n" @@ -785,7 +792,7 @@ result_t MainLoop::executeRead(const vector& args, const string& levels, ret = message->storeLastData(master, slave); ostringstream result; if (ret == RESULT_OK) { - ret = message->decodeLastData(false, nullptr, -1, OF_NONE, &result); + ret = message->decodeLastData(pt_any, false, nullptr, -1, OF_NONE, &result); } if (ret >= RESULT_OK) { logInfo(lf_main, "read hex %s %s cache update: %s", message->getCircuit().c_str(), message->getName().c_str(), @@ -855,7 +862,7 @@ result_t MainLoop::executeRead(const vector& args, const string& levels, if (verbosity & OF_NAMES) { *ostream << cacheMessage->getCircuit() << " " << cacheMessage->getName() << " "; } - ret = cacheMessage->decodeLastData(false, fieldIndex == -2 ? nullptr : fieldName.c_str(), fieldIndex, verbosity, + ret = cacheMessage->decodeLastData(pt_any, false, fieldIndex == -2 ? nullptr : fieldName.c_str(), fieldIndex, verbosity, ostream); if (ret != RESULT_OK) { if (ret < RESULT_OK) { @@ -888,7 +895,7 @@ result_t MainLoop::executeRead(const vector& args, const string& levels, if (verbosity & OF_NAMES) { *ostream << message->getCircuit() << " " << message->getName() << " "; } - ret = message->decodeLastData(false, false, fieldIndex == -2 ? nullptr : fieldName.c_str(), fieldIndex, verbosity, + ret = message->decodeLastData(pt_any, false, fieldIndex == -2 ? nullptr : fieldName.c_str(), fieldIndex, verbosity, ostream); if (ret < RESULT_OK) { logError(lf_main, "read %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(), @@ -1009,7 +1016,7 @@ result_t MainLoop::executeWrite(const vector& args, const string levels, ret = message->storeLastData(master, slave); ostringstream result; if (ret == RESULT_OK) { - ret = message->decodeLastData(false, nullptr, -1, OF_NONE, &result); + ret = message->decodeLastData(pt_any, false, nullptr, -1, OF_NONE, &result); } if (ret >= RESULT_OK) { logInfo(lf_main, "write hex %s %s cache update: %s", message->getCircuit().c_str(), @@ -1080,7 +1087,7 @@ result_t MainLoop::executeWrite(const vector& args, const string levels, return RESULT_OK; } - ret = message->decodeLastData(false, false, nullptr, -1, OF_NONE, ostream); // decode data + ret = message->decodeLastData(pt_any, false, nullptr, -1, OF_NONE, ostream); // decode data if (ret >= RESULT_OK && ostream->str().empty()) { logNotice(lf_main, "write %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(), getResultCode(ret)); @@ -1487,7 +1494,7 @@ result_t MainLoop::executeFind(const vector& args, const string& levels, } else if (hexFormat) { *ostream << message->getLastMasterData().getStr() << " / " << message->getLastSlaveData().getStr(); } else { - result_t ret = message->decodeLastData(false, nullptr, -1, verbosity, ostream); + result_t ret = message->decodeLastData(pt_any, false, nullptr, -1, verbosity, ostream); if (ret != RESULT_OK) { *ostream << " (" << getResultCode(ret) << " for " << message->getLastMasterData().getStr() @@ -2045,7 +2052,7 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri circuit = uri.substr(6, pos - 6); name = uri.substr(pos + 1); } - bool required = false, full = false, withWrite = false, raw = false; + bool required = false, full = false, withWrite = false; bool withDefinition = false; string newDefinition; OutputFormat verbosity = OF_NAMES; @@ -2099,7 +2106,9 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri } else if (qname == "write") { withWrite = parseBoolQuery(value); } else if (qname == "raw") { - raw = parseBoolQuery(value); + if (parseBoolQuery(value)) { + verbosity |= OF_RAWDATA; + } } else if (qname == "def") { withDefinition = parseBoolQuery(value); } else if (qname == "define") { @@ -2191,7 +2200,7 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri Message* next = *(it+1); same = next->getCircuit() == lastCircuit && next->getName() == name; } - message->decodeJson(!first, same, true, raw, verbosity, ostream); + message->decodeJson(!first, same, true, verbosity, ostream); lastName = name; first = false; } diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index b3204655..56ff1cab 100755 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -1178,7 +1178,7 @@ void MqttHandler::publishMessage(const Message* message, ostringstream* updates, } else if (m_staticTopic) { *updates << message->getCircuit() << UI_FIELD_SEPARATOR << message->getName() << UI_FIELD_SEPARATOR; } - result_t result = message->decodeLastData(false, nullptr, -1, outputFormat, updates); + result_t result = message->decodeLastData(pt_any, false, nullptr, -1, outputFormat, updates); if (result == RESULT_EMPTY) { publishEmptyTopic(getTopic(message)); // alternatively: , json ? "null" : ""); return; @@ -1206,7 +1206,7 @@ void MqttHandler::publishMessage(const Message* message, ostringstream* updates, publishEmptyTopic(getTopic(message, "", name)); // alternatively: , json ? "null" : ""); continue; } - result_t result = message->decodeLastData(false, nullptr, index, outputFormat, updates); + result_t result = message->decodeLastData(pt_any, false, nullptr, index, outputFormat, updates); if (result != RESULT_OK) { logOtherError("mqtt", "decode %s %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(), name.c_str(), getResultCode(result)); diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index 7fbbacf7..35a25805 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -412,6 +412,31 @@ const char* DataField::getDayName(int day) { return dayNames[day]; } +bool DataField::addRaw(size_t offset, size_t length, const SymbolString& input, bool isJson, ostream* output) { + size_t size = input.getDataSize(); + if (offset >= size) { + return false; + } + if (isJson) { + *output << ", \"raw\": ["; + for (size_t pos = 0; pos < length && offset+pos < size; pos++) { + if (pos > 0) { + *output << ", "; + } + *output << dec << static_cast(input.dataAt(offset+pos)); + } + *output << "]"; + } else { + *output << "["; + for (size_t pos = 0; pos < length && offset+pos < size; pos++) { + *output << setw(2) << hex + << setfill('0') << static_cast(input.dataAt(offset+pos)); + } + *output << "]"; + } + return true; +} + result_t SingleDataField::create(const string& name, const map& attributes, const DataType* dataType, PartType partType, size_t length, int divisor, const string& constantValue, @@ -547,7 +572,8 @@ result_t SingleDataField::read(const SymbolString& data, size_t offset, return RESULT_EMPTY; } bool shortFormat = outputFormat & OF_SHORT; - if (outputFormat & OF_JSON) { + bool isJson = outputFormat & OF_JSON; + if (isJson) { if (leadingSeparator) { *output << ","; } @@ -578,6 +604,9 @@ result_t SingleDataField::read(const SymbolString& data, size_t offset, } } + if (!shortFormat && (outputFormat & OF_RAWDATA) && !isJson) { + addRaw(offset, m_length, data, isJson, output); + } result_t result = readSymbols(data, offset, outputFormat, output); if (result != RESULT_OK) { return result; @@ -585,7 +614,10 @@ result_t SingleDataField::read(const SymbolString& data, size_t offset, if (!shortFormat) { appendAttributes(outputFormat, output); } - if (!shortFormat && (outputFormat & OF_JSON)) { + if (!shortFormat && isJson) { + if (outputFormat & OF_RAWDATA) { + addRaw(offset, m_length, data, isJson, output); + } *output << "}"; } return RESULT_OK; diff --git a/src/lib/ebus/data.h b/src/lib/ebus/data.h index 007877f8..e922529c 100755 --- a/src/lib/ebus/data.h +++ b/src/lib/ebus/data.h @@ -239,6 +239,17 @@ class DataField : public AttributedItem { */ static const char* getDayName(int day); + /** + * Add raw data to the output (excluding the length field). + * @param offset the offset in the data part of the @a SymbolString. + * @param length the maximum number of symbols to dump. + * @param input the @a SymbolString to dump from. + * @param isJson true for JSON format, false for text. + * @param output the ostream to append the raw data to. + * @return true when something was added to the output. + */ + static bool addRaw(size_t offset, size_t length, const SymbolString& input, bool isJson, ostream* output); + /** * Returns the length of this field (or contained fields) in bytes. * @param partType the message part of the contained fields to limit the length calculation to. diff --git a/src/lib/ebus/datatype.h b/src/lib/ebus/datatype.h index 8b6395ba..013d2f70 100755 --- a/src/lib/ebus/datatype.h +++ b/src/lib/ebus/datatype.h @@ -110,6 +110,9 @@ enum OutputFormat : OutputFormatBaseType { /** bit flag for @a OutputFormat: include message/field definition. */ OF_DEFINITION = 1 << 8, + + /** bit flag for @a OutputFormat: include raw data. */ + OF_RAWDATA = 1 << 9, }; constexpr inline enum OutputFormat operator| (enum OutputFormat self, enum OutputFormat other) { diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 2c496ce6..a3cb3fe7 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -769,36 +769,25 @@ result_t Message::storeLastData(size_t index, const SlaveSymbolString& data) { return RESULT_OK; } -result_t Message::decodeLastData(bool master, bool leadingSeparator, const char* fieldName, - ssize_t fieldIndex, OutputFormat outputFormat, ostream* output) const { - result_t result; - if (master) { +result_t Message::decodeLastData(PartType part, bool leadingSeparator, const char* fieldName, + ssize_t fieldIndex, const OutputFormat outputFormat, ostream* output) const { + if ((outputFormat & OF_RAWDATA) && !(outputFormat & OF_JSON)) { + *output << "[" << m_lastMasterData.getStr(2, 0, false) + << "/" << m_lastSlaveData.getStr(0, 0, false) + << "] "; + } + ostream::pos_type startPos = output->tellp(); + result_t result = RESULT_EMPTY; + bool skipSlaveData = part == pt_masterData; + if (part == pt_any || skipSlaveData) { result = m_data->read(m_lastMasterData, getIdLength(), leadingSeparator, fieldName, fieldIndex, outputFormat, -1, output); - } else { - result = m_data->read(m_lastSlaveData, 0, leadingSeparator, fieldName, fieldIndex, - outputFormat, -1, output); - } - if (result < RESULT_OK) { - return result; - } - if (result == RESULT_EMPTY && (fieldName != nullptr || fieldIndex >= 0)) { - return RESULT_ERR_NOTFOUND; - } - return result; -} - -result_t Message::decodeLastData(bool leadingSeparator, const char* fieldName, - ssize_t fieldIndex, const OutputFormat outputFormat, ostream* output) const { - ostream::pos_type startPos = output->tellp(); - result_t result = m_data->read(m_lastMasterData, getIdLength(), leadingSeparator, fieldName, fieldIndex, - outputFormat, -1, output); - if (result < RESULT_OK) { - return result; + if (result < RESULT_OK) { + return result; + } } bool empty = result == RESULT_EMPTY; - bool skipSlaveData = false; - if (fieldIndex >= 0) { + if (!skipSlaveData && fieldIndex >= 0) { fieldIndex -= m_data->getCount(pt_masterData, fieldName); if (fieldIndex < 0) { skipSlaveData = true; @@ -953,7 +942,7 @@ void Message::dumpField(const string& fieldName, bool withConditions, OutputForm dumpAttribute(false, outputFormat, fieldName, output); } -void Message::decodeJson(bool leadingSeparator, bool appendDirectionCondition, bool withData, bool addRaw, +void Message::decodeJson(bool leadingSeparator, bool appendDirectionCondition, bool withData, OutputFormat outputFormat, ostringstream* output) const { outputFormat |= OF_JSON; if (leadingSeparator) { @@ -1003,14 +992,14 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirectionCondition, b } appendAttributes(outputFormat, output); if (hasData) { - if (addRaw) { + if (outputFormat & OF_RAWDATA) { m_lastMasterData.dumpJson(true, output); m_lastSlaveData.dumpJson(true, output); *output << dec; } size_t pos = (size_t)output->tellp(); *output << ",\n \"fields\": {"; - result_t dret = decodeLastData(false, nullptr, -1, outputFormat, output); + result_t dret = decodeLastData(pt_any, false, nullptr, -1, outputFormat, output); if (dret == RESULT_OK) { *output << "\n }"; } else { @@ -1694,7 +1683,7 @@ void SimpleNumericCondition::dumpValuesJson(ostream* output) const { bool SimpleStringCondition::checkValue(const Message* message, const string& field) { ostringstream output; - result_t result = message->decodeLastData(false, field.length() == 0 ? nullptr : field.c_str(), -1, OF_NONE, &output); + result_t result = message->decodeLastData(pt_any, false, field.length() == 0 ? nullptr : field.c_str(), -1, OF_NONE, &output); if (result == RESULT_OK) { string value = output.str(); for (size_t i = 0; i < m_values.size(); i++) { @@ -2931,7 +2920,7 @@ void MessageMap::dump(bool withConditions, OutputFormat outputFormat, ostream* o } if (isJson) { ostringstream str; - message->decodeJson(false, false, false, false, outputFormat, &str); + message->decodeJson(false, false, false, outputFormat, &str); string add = str.str(); size_t pos = add.find('{'); *output << " {\n \"circuit\": \"" << message->getCircuit() << "\", " << add.substr(pos+1); @@ -2952,7 +2941,7 @@ void MessageMap::dump(bool withConditions, OutputFormat outputFormat, ostream* o } if (isJson) { ostringstream str; - message->decodeJson(!wasFirst, true, false, false, outputFormat, &str); + message->decodeJson(!wasFirst, true, false, outputFormat, &str); *output << str.str(); } else { message->dump(nullptr, withConditions, outputFormat, output); diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 5875e66b..ca862ee9 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -478,8 +478,8 @@ class Message : public AttributedItem { virtual result_t storeLastData(size_t index, const SlaveSymbolString& data); /** - * Decode the value from the last stored master or slave data. - * @param master true for decoding the master data, false for slave. + * Decode value(s) from the last stored data. + * @param part the part to decode. * @param leadingSeparator whether to prepend a separator before the formatted value. * @param fieldName the optional name of a field to limit the output to. * @param fieldIndex the optional index of the field to limit the output to (either named or overall), or -1. @@ -487,20 +487,8 @@ class Message : public AttributedItem { * @param output the @a ostream to append the formatted value to. * @return @a RESULT_OK on success, or an error code. */ - virtual result_t decodeLastData(bool master, bool leadingSeparator, const char* fieldName, - ssize_t fieldIndex, OutputFormat outputFormat, ostream* output) const; - - /** - * Decode the value from the last stored master and slave data. - * @param leadingSeparator whether to prepend a separator before the formatted value. - * @param fieldName the optional name of a field to limit the output to. - * @param fieldIndex the optional index of the field to limit the output to (either named or overall), or -1. - * @param outputFormat the @a OutputFormat options to use. - * @param output the @a ostream to append the formatted value to. - * @return @a RESULT_OK on success, or an error code. - */ - virtual result_t decodeLastData(bool leadingSeparator, const char* fieldName, - ssize_t fieldIndex, OutputFormat outputFormat, ostream* output) const; + virtual result_t decodeLastData(PartType part, bool leadingSeparator, const char* fieldName, + ssize_t fieldIndex, const OutputFormat outputFormat, ostream* output) const; /** * Decode a particular numeric field value from the last stored data. @@ -599,11 +587,10 @@ class Message : public AttributedItem { * @param leadingSeparator whether to prepend a separator before the first value. * @param appendDirectionCondition whether to append the direction and condition to the name key. * @param withData whether to add the last data as well. - * @param addRaw whether to add the raw symbols as well. * @param outputFormat the @a OutputFormat options to use. * @param output the @a ostringstream to append the decoded value(s) to. */ - virtual void decodeJson(bool leadingSeparator, bool appendDirectionCondition, bool withData, bool addRaw, + virtual void decodeJson(bool leadingSeparator, bool appendDirectionCondition, bool withData, OutputFormat outputFormat, ostringstream* output) const; protected: diff --git a/src/lib/ebus/test/test_message.cpp b/src/lib/ebus/test/test_message.cpp index 694919f2..323ae23c 100644 --- a/src/lib/ebus/test/test_message.cpp +++ b/src/lib/ebus/test/test_message.cpp @@ -184,6 +184,7 @@ int main() { {"", "19:00", "3110b51503000272", "00", "kd"}, {"*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", "r,cirCIRCUITcuit,naNAMEme,comCOMMENTment,ff,75,b509,0d0100,field,s,UCH,,,: [b5090d0100/2a] field=[2a]42", "ff75b509030d0100", "012a", "DNr"}, {"r,CIRCUIT,NAME,COMMENT,,,,0100,field,,UCH", " \"naNAMEme\": {\n" " \"name\": \"naNAMEme\",\n" @@ -194,13 +195,32 @@ int main() { " \"zz\": 117,\n" " \"id\": [181, 9, 13, 1, 0],\n" " \"fields\": {\n" - " \"0\": {\"name\": \"field\", \"value\": 42}\n" + " \"field\": {\"value\": 42}\n" " },\n" " \"fielddefs\": [\n" " { \"name\": \"field\", \"slave\": true, \"type\": \"UCH\", \"isbits\": false, \"length\": 1, \"unit\": \"\", \"comment\": \"\"}\n" " ]\n" " }: \n" " \"field\": {\"value\": 42}", "ff75b509030d0100", "012a", "jN"}, + {"r,CIRCUIT,NAME,COMMENT,,,,0100,field,,UCH", + " \"naNAMEme\": {\n" + " \"name\": \"naNAMEme\",\n" + " \"passive\": false,\n" + " \"write\": false,\n" + " \"lastup\": *,\n" + " \"qq\": 255,\n" + " \"zz\": 117,\n" + " \"id\": [181, 9, 13, 1, 0],\n" + " \"master\": [255, 117, 181, 9, 3, 13, 1, 0],\n" + " \"slave\": [1, 42],\n" + " \"fields\": {\n" + " \"field\": {\"value\": 42, \"raw\": [42]}\n" + " },\n" + " \"fielddefs\": [\n" + " { \"name\": \"field\", \"slave\": true, \"type\": \"UCH\", \"isbits\": false, \"length\": 1, \"unit\": \"\", \"comment\": \"\"}\n" + " ]\n" + " }: \n" + " \"field\": {\"value\": 42, \"raw\": [42]}", "ff75b509030d0100", "012a", "jNr"}, }; templates = new DataFieldTemplates(); unsigned int lineNo = 0; @@ -235,6 +255,10 @@ int main() { bool decodeVerbose = flags.find('D') != string::npos || flags.find('J') != string::npos; bool withMessageDump = flags.find('N') != string::npos; bool decode = decodeJson || decodeVerbose || (flags.find('d') != string::npos); + OutputFormat verbosity = (decodeVerbose?OF_NAMES|OF_UNITS|OF_COMMENTS:OF_NONE)|(decodeJson?OF_NAMES|OF_JSON:OF_NONE); + if (flags.find('r') != string::npos) { + verbosity |= OF_RAWDATA; + } bool failedPrepare = flags.find('p') != string::npos; bool failedPrepareMatch = flags.find('P') != string::npos; bool multi = flags.find('*') != string::npos; @@ -408,7 +432,7 @@ int main() { ostringstream output; if (withMessageDump) { if (decodeJson) { - message->decodeJson(false, false, true, false, OF_JSON|OF_DEFINITION, &output); + message->decodeJson(false, false, true, verbosity|OF_DEFINITION, &output); string str = output.str(); size_t start = str.find("\"lastup\": "); if (start != string::npos) { @@ -425,8 +449,7 @@ int main() { } output << ": "; } - result = message->decodeLastData(false, nullptr, -1, - (decodeVerbose?OF_NAMES|OF_UNITS|OF_COMMENTS:OF_NONE)|(decodeJson?OF_NAMES|OF_JSON:OF_NONE), &output); + result = message->decodeLastData(pt_any, false, nullptr, -1, verbosity, &output); if (result != RESULT_OK) { cout << " \"" << check[2] << "\" / \"" << check[3] << "\": decode error " << (message->isWrite() ? "write: " : "read: ") << getResultCode(result) << endl;