store received data

This commit is contained in:
john30
2014-12-06 23:42:41 +01:00
parent c0c1cf3966
commit 5bbdcac5d4
2 changed files with 33 additions and 7 deletions
+23 -7
View File
@@ -463,16 +463,21 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
void BusHandler::receiveCompleted()
{
Message* msg = m_messages->find(m_command);
if (msg != NULL) {
Message* message = m_messages->find(m_command);
if (message != NULL) {
string clazz = message->getClass();
string name = message->getName();
ostringstream output;
result_t result = msg->decode(pt_masterData, m_command, output);
result_t result = message->decode(pt_masterData, m_command, output);
if (result == RESULT_OK)
result = msg->decode(pt_slaveData, m_response, output);
result = message->decode(pt_slaveData, m_response, output, output.str().empty() == false);
if (result != RESULT_OK)
L.log(bus, error, "unable to parse %s %s from %s / %s: %s", msg->getClass().c_str(), msg->getName().c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result));
else
L.log(bus, trace, "%s %s: %s", msg->getClass().c_str(), msg->getName().c_str(), output.str().c_str());
L.log(bus, error, "unable to parse %s %s from %s / %s: %s", clazz.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result));
else {
string data = output.str();
L.log(bus, trace, "%s %s: %s", clazz.c_str(), name.c_str(), data.c_str());
m_receivedData[clazz+";"+name] = data;
}
return;
}
if (m_command[1] == BROADCAST)
@@ -482,3 +487,14 @@ void BusHandler::receiveCompleted()
else
L.log(bus, trace, "received master-slave %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str());
}
string BusHandler::getReceivedData(Message* message) {
if (message == NULL)
return NULL;
string clazz = message->getClass();
string name = message->getName();
map<string, string>::iterator it = m_receivedData.find(clazz+";"+name);
if (it == m_receivedData.end())
return NULL;
return it->second;
}
+10
View File
@@ -178,6 +178,13 @@ public:
*/
virtual void run();
/**
* @brief Get the last received data for the @a Message.
* @param message the @a Message instance.
* @return the last received data for the @a Message, or the empty string if not available.
*/
string getReceivedData(Message* message);
private:
/**
@@ -258,6 +265,9 @@ private:
/** whether the response CRC is valid. */
bool m_responseCrcValid;
/** the last received data by "class;name". */
map<string, string> m_receivedData;
};