store last value in Message with update time
This commit is contained in:
@@ -320,7 +320,7 @@ string BaseLoop::decodeMessage(const string& data)
|
|||||||
message = m_messages->find(cmd[1], cmd[2], false, true);
|
message = m_messages->find(cmd[1], cmd[2], false, true);
|
||||||
|
|
||||||
if (message != NULL) {
|
if (message != NULL) {
|
||||||
token = m_busHandler->getReceivedData(message);
|
token = message->getLastValue();
|
||||||
if (token.empty() == false) {
|
if (token.empty() == false) {
|
||||||
result << token;
|
result << token;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ Message::Message(const string clazz, const string name, const bool isSet,
|
|||||||
: m_class(clazz), m_name(name), m_isSet(isSet),
|
: m_class(clazz), m_name(name), m_isSet(isSet),
|
||||||
m_isPassive(isPassive), m_comment(comment),
|
m_isPassive(isPassive), m_comment(comment),
|
||||||
m_srcAddress(srcAddress), m_dstAddress(dstAddress),
|
m_srcAddress(srcAddress), m_dstAddress(dstAddress),
|
||||||
m_id(id), m_data(data), m_pollPriority(pollPriority)
|
m_id(id), m_data(data), m_pollPriority(pollPriority),
|
||||||
|
m_lastUpdateTime(0)
|
||||||
{
|
{
|
||||||
int exp = 7;
|
int exp = 7;
|
||||||
unsigned long long key = (unsigned long long)(id.size()-2) << (8 * exp + 5);
|
unsigned long long key = (unsigned long long)(id.size()-2) << (8 * exp + 5);
|
||||||
@@ -280,9 +281,14 @@ result_t Message::decode(const PartType partType, SymbolString& data,
|
|||||||
offset = m_id.size() - 2;
|
offset = m_id.size() - 2;
|
||||||
else
|
else
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
int startPos = output.str().length();
|
||||||
result_t result = m_data->read(partType, data, offset, output, leadingSeparator, false, separator);
|
result_t result = m_data->read(partType, data, offset, output, leadingSeparator, false, separator);
|
||||||
if (result != RESULT_OK)
|
time(&m_lastUpdateTime);
|
||||||
|
if (result != RESULT_OK) {
|
||||||
|
m_lastValue.clear();
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
m_lastValue = output.str().substr(startPos);
|
||||||
/*if (m_isPassive == false && answer == true) {
|
/*if (m_isPassive == false && answer == true) {
|
||||||
istringstream input; // TODO create input from database of internal variables
|
istringstream input; // TODO create input from database of internal variables
|
||||||
result_t result = m_data->write(input, masterData, m_id.size() - 2, slaveData, 0, separator);
|
result_t result = m_data->write(input, masterData, m_id.size() - 2, slaveData, 0, separator);
|
||||||
@@ -292,7 +298,6 @@ result_t Message::decode(const PartType partType, SymbolString& data,
|
|||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result_t MessageMap::add(Message* message)
|
result_t MessageMap::add(Message* message)
|
||||||
{
|
{
|
||||||
unsigned long long pkey = message->getKey();
|
unsigned long long pkey = message->getKey();
|
||||||
@@ -422,4 +427,3 @@ void MessageMap::clear()
|
|||||||
m_passiveMessagesByKey.clear();
|
m_passiveMessagesByKey.clear();
|
||||||
m_maxIdLength = 0;
|
m_maxIdLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-2
@@ -144,6 +144,18 @@ public:
|
|||||||
result_t decode(const PartType partType, SymbolString& data,
|
result_t decode(const PartType partType, SymbolString& data,
|
||||||
ostringstream& output, bool leadingSeparator=false, char separator=';');
|
ostringstream& output, bool leadingSeparator=false, char separator=';');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the last decoded value.
|
||||||
|
* @return the last decoded value, or the empty string if it was not successful.
|
||||||
|
*/
|
||||||
|
string getLastValue() { return m_lastValue; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the system time when @a m_lastValue was updated.
|
||||||
|
* @return the system time when @a m_lastValue was updated, or 0 if this message was not decoded yet.
|
||||||
|
*/
|
||||||
|
time_t getLastUpdateTime() { return m_lastUpdateTime; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** the optional device class. */
|
/** the optional device class. */
|
||||||
@@ -169,7 +181,10 @@ private:
|
|||||||
DataField* m_data;
|
DataField* m_data;
|
||||||
/** the priority for polling, or 0 for no polling at all. */
|
/** the priority for polling, or 0 for no polling at all. */
|
||||||
const unsigned char m_pollPriority;
|
const unsigned char m_pollPriority;
|
||||||
|
/** the last decoded value. */
|
||||||
|
string m_lastValue;
|
||||||
|
/** the system time when @a m_lastValue was updated. */
|
||||||
|
time_t m_lastUpdateTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -218,7 +233,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** the minimum ID length used by any of the known @a Message instances. */
|
/** the minimum ID length used by any of the known @a Message instances. */
|
||||||
|
|||||||
Reference in New Issue
Block a user