neither update last found timestamp nor empty last found value if decoding failed, added decode() for combined master/slave decoding
This commit is contained in:
@@ -315,13 +315,12 @@ result_t Message::decode(const PartType partType, SymbolString& data,
|
||||
offset = m_id.size() - 2;
|
||||
else
|
||||
offset = 0;
|
||||
int startPos = output.str().length();
|
||||
size_t startPos = output.str().length();
|
||||
result_t result = m_data->read(partType, data, offset, output, leadingSeparator, verbose, filterName, separator);
|
||||
time(&m_lastUpdateTime);
|
||||
if (result < RESULT_OK) {
|
||||
m_lastValue.clear();
|
||||
return result;
|
||||
}
|
||||
time(&m_lastUpdateTime);
|
||||
m_lastValue = output.str().substr(startPos);
|
||||
/*if (m_isPassive == false && answer == true) {
|
||||
istringstream input; // TODO create input from database of internal variables
|
||||
@@ -332,6 +331,28 @@ result_t Message::decode(const PartType partType, SymbolString& data,
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
result_t Message::decode(SymbolString& masterData, SymbolString& slaveData,
|
||||
ostringstream& output, bool leadingSeparator,
|
||||
bool verbose, const char* filterName,
|
||||
char separator)
|
||||
{
|
||||
unsigned char offset = m_id.size() - 2;
|
||||
size_t startPos = output.str().length();
|
||||
result_t result = m_data->read(pt_masterData, masterData, offset, output, leadingSeparator, verbose, filterName, separator);
|
||||
if (result < RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
offset = 0;
|
||||
leadingSeparator = output.str().length() > startPos;
|
||||
result = m_data->read(pt_slaveData, slaveData, offset, output, leadingSeparator, verbose, filterName, separator);
|
||||
if (result < RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
time(&m_lastUpdateTime);
|
||||
m_lastValue = output.str().substr(startPos);
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
bool Message::isLessPollWeight(const Message* other)
|
||||
{
|
||||
unsigned int tw = m_pollPriority * m_pollCount;
|
||||
|
||||
+18
-1
@@ -176,7 +176,7 @@ public:
|
||||
result_t prepareSlave(SymbolString& slaveData);
|
||||
|
||||
/**
|
||||
* @brief Decode a received message.
|
||||
* @brief Decode a singular part of a received message.
|
||||
* @param partType the @a PartType of the data.
|
||||
* @param data the unescaped data @a SymbolString for reading binary data.
|
||||
* @param output the @a ostringstream to append the formatted value to.
|
||||
@@ -192,6 +192,23 @@ public:
|
||||
bool verbose=false, const char* filterName=NULL,
|
||||
char separator=UI_FIELD_SEPARATOR);
|
||||
|
||||
/**
|
||||
* @brief Decode all parts of a received message.
|
||||
* @param masterData the unescaped master data @a SymbolString to decode.
|
||||
* @param slaveData the unescaped slave data @a SymbolString to decode.
|
||||
* @param output the @a ostringstream to append the formatted value to.
|
||||
* @param leadingSeparator whether to prepend a separator before the formatted value.
|
||||
* @param verbose whether to prepend the name, append the unit (if present), and append
|
||||
* the comment in square brackets (if present).
|
||||
* @param filterName the optional name of a field to limit the output to.
|
||||
* @param separator the separator character between multiple fields.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t decode(SymbolString& masterData, SymbolString& slaveData,
|
||||
ostringstream& output, bool leadingSeparator=false,
|
||||
bool verbose=false, const char* filterName=NULL,
|
||||
char separator=UI_FIELD_SEPARATOR);
|
||||
|
||||
/**
|
||||
* @brief Get the last decoded value.
|
||||
* @return the last decoded value, or the empty string if it was not successful.
|
||||
|
||||
@@ -151,9 +151,7 @@ int main()
|
||||
SymbolString writeMstr;
|
||||
if (message->isPassive() == true) {
|
||||
ostringstream output;
|
||||
result = message->decode(pt_masterData, mstr, output);
|
||||
if (result == RESULT_OK)
|
||||
result = message->decode(pt_slaveData, sstr, output, output.str().empty() == false);
|
||||
result = message->decode(mstr, sstr, output);
|
||||
if (result != RESULT_OK) {
|
||||
cout << " \"" << inputStr << "\": decode error: "
|
||||
<< getResultCode(result) << endl;
|
||||
|
||||
Reference in New Issue
Block a user