moved readFromBus to BusHandler, fix for polling ChainedMessages, increased log level for loaded files and written messages, added error message for failed writes, derive all scan messages and store them, added all message counts to info result
This commit is contained in:
@@ -63,7 +63,7 @@ const char* getStateCode(BusState state) {
|
||||
result_t PollRequest::prepare(unsigned char ownMasterAddress)
|
||||
{
|
||||
istringstream input;
|
||||
result_t result = m_message->prepareMaster(ownMasterAddress, m_master, input, m_index);
|
||||
result_t result = m_message->prepareMaster(ownMasterAddress, m_master, input, UI_FIELD_SEPARATOR, SYN, m_index);
|
||||
if (result == RESULT_OK)
|
||||
logInfo(lf_bus, "poll cmd: %s", m_master.getDataStr().c_str());
|
||||
return result;
|
||||
@@ -75,7 +75,10 @@ bool PollRequest::notify(result_t result, SymbolString& slave)
|
||||
result = m_message->storeLastData(pt_slaveData, slave, m_index);
|
||||
if (result>=RESULT_OK && m_index+1 < m_message->getCount()) {
|
||||
m_index++;
|
||||
return true;
|
||||
result = prepare(m_master[0]);
|
||||
if (result >= RESULT_OK) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ostringstream output;
|
||||
@@ -115,6 +118,10 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
|
||||
m_message = message;
|
||||
m_message->storeLastData(pt_masterData, m_master, m_index); // expected to work since this is a clone
|
||||
}
|
||||
} else if (m_message->getDstAddress()==SYN) {
|
||||
m_message = m_message->derive(dstAddress, true);
|
||||
m_messageMap->add(m_message);
|
||||
m_message->storeLastData(pt_masterData, m_master, m_index); // expected to work since this is a clone
|
||||
}
|
||||
result = m_message->storeLastData(pt_slaveData, slave, m_index);
|
||||
if (result>=RESULT_OK && m_index+1 < m_message->getCount()) {
|
||||
@@ -212,6 +219,33 @@ result_t BusHandler::sendAndWait(SymbolString& master, SymbolString& slave)
|
||||
return result;
|
||||
}
|
||||
|
||||
result_t BusHandler::readFromBus(Message* message, string inputStr, const unsigned char dstAddress)
|
||||
{
|
||||
result_t ret = RESULT_EMPTY;
|
||||
SymbolString master(true);
|
||||
SymbolString slave(false);
|
||||
for (unsigned char index=0; index<message->getCount(); index++) {
|
||||
istringstream input(inputStr);
|
||||
ret = message->prepareMaster(m_ownMasterAddress, master, input, UI_FIELD_SEPARATOR, dstAddress, index);
|
||||
if (ret != RESULT_OK) {
|
||||
logError(lf_bus, "prepare message part %d: %s", index, getResultCode(ret));
|
||||
break;
|
||||
}
|
||||
// send message
|
||||
ret = sendAndWait(master, slave);
|
||||
if (ret != RESULT_OK) {
|
||||
logError(lf_bus, "send message part %d: %s", index, getResultCode(ret));
|
||||
break;
|
||||
}
|
||||
ret = message->storeLastData(pt_slaveData, slave, index);
|
||||
if (ret < RESULT_OK) {
|
||||
logError(lf_bus, "store message part %d: %s", index, getResultCode(ret));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void BusHandler::run()
|
||||
{
|
||||
unsigned int symCount = 0;
|
||||
@@ -269,9 +303,9 @@ result_t BusHandler::handleSymbol()
|
||||
break;
|
||||
|
||||
case bs_ready:
|
||||
if (m_currentRequest != NULL)
|
||||
if (m_currentRequest != NULL) {
|
||||
setState(bs_ready, RESULT_ERR_TIMEOUT); // just to be sure an old BusRequest is cleaned up
|
||||
if (m_remainLockCount == 0 && m_currentRequest == NULL) {
|
||||
} else if (m_remainLockCount == 0) {
|
||||
startRequest = m_nextRequests.peek();
|
||||
if (startRequest == NULL && m_pollInterval > 0) { // check for poll/scan
|
||||
time_t now;
|
||||
@@ -632,7 +666,7 @@ result_t BusHandler::handleSymbol()
|
||||
}
|
||||
if (message == NULL || message->isWrite())
|
||||
return setState(bs_skip, RESULT_ERR_INVALID_ARG); // don't know this request or definition has wrong direction, deny
|
||||
if (message == m_messages->getScanMessage()) {
|
||||
if (message == m_messages->getScanMessage(m_ownSlaveAddress)) {
|
||||
input.str(SCAN_ANSWER);
|
||||
}
|
||||
|
||||
@@ -858,7 +892,7 @@ void BusHandler::receiveCompleted()
|
||||
|
||||
result_t BusHandler::startScan(bool full)
|
||||
{
|
||||
deque<Message*> messages = m_messages->findAll("scan", "");
|
||||
deque<Message*> messages = m_messages->findAll("scan", "", true);
|
||||
for (deque<Message*>::iterator it = messages.begin(); it < messages.end(); it++) {
|
||||
Message* message = *it;
|
||||
if (message->getPrimaryCommand() == 0x07 && message->getSecondaryCommand() == 0x04)
|
||||
@@ -976,11 +1010,12 @@ void BusHandler::formatSeenInfo(ostringstream& output)
|
||||
if (message!=NULL && message->getLastUpdateTime()>0) {
|
||||
// add detailed scan info: Manufacturer ID SW HW
|
||||
output << " \"";
|
||||
result_t result = message->decodeLastData(output, OF_NAMES|OF_UNITS|OF_COMMENTS);
|
||||
if (result!=RESULT_OK)
|
||||
result_t result = message->decodeLastData(output, OF_NAMES);
|
||||
if (result!=RESULT_OK) {
|
||||
output << "\" error: " << getResultCode(result);
|
||||
else
|
||||
} else {
|
||||
output << "\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
string loadedFiles = m_messages->getLoadedFiles(address);
|
||||
|
||||
@@ -351,6 +351,15 @@ public:
|
||||
*/
|
||||
result_t sendAndWait(SymbolString& master, SymbolString& slave);
|
||||
|
||||
/**
|
||||
* Prepare the master part for the @a Message, send it to the bus and wait for the answer.
|
||||
* @param message the @a Message instance.
|
||||
* @param inputStr the input @a string from which to read master values (if any).
|
||||
* @param dstAddress the destination address to set, or @a SYN to keep the address defined during construction.
|
||||
* @return the result code.
|
||||
*/
|
||||
result_t readFromBus(Message* message, string inputStr, const unsigned char dstAddress=SYN);
|
||||
|
||||
/**
|
||||
* Main thread entry.
|
||||
*/
|
||||
|
||||
+14
-37
@@ -166,7 +166,7 @@ void MainLoop::run()
|
||||
string file;
|
||||
result_t result = loadScanConfigFile(m_messages, lastScanAddress, slave, file);
|
||||
if (result==RESULT_OK) {
|
||||
logInfo(lf_main, "scan config %2.2x: file %s loaded", lastScanAddress, file.c_str());
|
||||
logNotice(lf_main, "scan config %2.2x: file %s loaded", lastScanAddress, file.c_str());
|
||||
m_busHandler->setScanConfigLoaded(lastScanAddress, file);
|
||||
} else {
|
||||
m_busHandler->setScanConfigLoaded(lastScanAddress, "");
|
||||
@@ -337,33 +337,6 @@ result_t MainLoop::parseHexMaster(vector<string> &args, size_t argPos, SymbolStr
|
||||
return ret;
|
||||
}
|
||||
|
||||
result_t MainLoop::readFromBus(Message* message, string inputStr, const unsigned char dstAddress)
|
||||
{
|
||||
result_t ret = RESULT_EMPTY;
|
||||
SymbolString master(true);
|
||||
SymbolString slave(false);
|
||||
for (unsigned char index=0; index<message->getCount(); index++) {
|
||||
istringstream input(inputStr);
|
||||
ret = message->prepareMaster(m_address, master, input, UI_FIELD_SEPARATOR, dstAddress, index);
|
||||
if (ret != RESULT_OK) {
|
||||
logError(lf_main, "prepare message part %d: %s", index, getResultCode(ret));
|
||||
break;
|
||||
}
|
||||
// send message
|
||||
ret = m_busHandler->sendAndWait(master, slave);
|
||||
if (ret != RESULT_OK) {
|
||||
logError(lf_main, "send message part %d: %s", index, getResultCode(ret));
|
||||
break;
|
||||
}
|
||||
ret = message->storeLastData(pt_slaveData, slave, index);
|
||||
if (ret < RESULT_OK) {
|
||||
logError(lf_main, "store message part %d: %s", index, getResultCode(ret));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
string MainLoop::executeRead(vector<string> &args)
|
||||
{
|
||||
size_t argPos = 1;
|
||||
@@ -576,7 +549,7 @@ string MainLoop::executeRead(vector<string> &args)
|
||||
return getResultCode(RESULT_ERR_INVALID_ADDR);
|
||||
|
||||
// read directly from bus
|
||||
result_t ret = readFromBus(message, params, dstAddress);
|
||||
result_t ret = m_busHandler->readFromBus(message, params, dstAddress);
|
||||
if (ret != RESULT_OK)
|
||||
return getResultCode(ret);
|
||||
|
||||
@@ -698,14 +671,15 @@ string MainLoop::executeWrite(vector<string> &args)
|
||||
if (message->getDstAddress()==SYN && dstAddress==SYN)
|
||||
return getResultCode(RESULT_ERR_INVALID_ADDR);
|
||||
|
||||
result_t ret = readFromBus(message, args.size() == argPos + 1 ? "" : args[argPos + 1], dstAddress); // allow missing values
|
||||
if (ret != RESULT_OK)
|
||||
result_t ret = m_busHandler->readFromBus(message, args.size() == argPos + 1 ? "" : args[argPos + 1], dstAddress); // allow missing values
|
||||
if (ret != RESULT_OK) {
|
||||
logError(lf_main, "write %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(), getResultCode(ret));
|
||||
return getResultCode(ret);
|
||||
|
||||
}
|
||||
dstAddress = message->getLastMasterData()[1];
|
||||
ostringstream result;
|
||||
if (dstAddress == BROADCAST || isMaster(dstAddress)) {
|
||||
logInfo(lf_main, "write %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(), getResultCode(ret));
|
||||
logNotice(lf_main, "write %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(), getResultCode(ret));
|
||||
if (dstAddress == BROADCAST)
|
||||
return "done broadcast";
|
||||
return getResultCode(RESULT_OK);
|
||||
@@ -713,7 +687,7 @@ string MainLoop::executeWrite(vector<string> &args)
|
||||
|
||||
ret = message->decodeLastData(pt_slaveData, result); // decode data
|
||||
if (ret >= RESULT_OK && result.str().empty()) {
|
||||
logInfo(lf_main, "write %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(), getResultCode(ret));
|
||||
logNotice(lf_main, "write %s %s: decode %s", message->getCircuit().c_str(), message->getName().c_str(), getResultCode(ret));
|
||||
return getResultCode(RESULT_OK);
|
||||
}
|
||||
if (ret != RESULT_OK) {
|
||||
@@ -722,7 +696,7 @@ string MainLoop::executeWrite(vector<string> &args)
|
||||
result << getResultCode(ret) << " in decode";
|
||||
return result.str();
|
||||
}
|
||||
logInfo(lf_main, "write %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(), result.str().c_str());
|
||||
logNotice(lf_main, "write %s %s: %s", message->getCircuit().c_str(), message->getName().c_str(), result.str().c_str());
|
||||
return result.str();
|
||||
}
|
||||
|
||||
@@ -1162,7 +1136,10 @@ string MainLoop::executeInfo(vector<string> &args)
|
||||
result << "signal: no signal\n";
|
||||
}
|
||||
result << "masters: " << static_cast<unsigned>(m_busHandler->getMasterCount()) << "\n";
|
||||
result << "messages: " << static_cast<unsigned>(m_messages->size());
|
||||
result << "messages: " << static_cast<unsigned>(m_messages->size()) << "\n";
|
||||
result << "conditional: " << static_cast<unsigned>(m_messages->sizeConditional()) << "\n";
|
||||
result << "poll: " << static_cast<unsigned>(m_messages->sizePoll()) << "\n";
|
||||
result << "update: " << static_cast<unsigned>(m_messages->sizePassive()) << "\n";
|
||||
m_busHandler->formatSeenInfo(result);
|
||||
return result.str();
|
||||
}
|
||||
@@ -1280,7 +1257,7 @@ string MainLoop::executeGet(vector<string> &args, bool& connected)
|
||||
// read directly from bus
|
||||
if (message->isPassive())
|
||||
continue; // not possible to actively read this message
|
||||
if (readFromBus(message, "") != RESULT_OK)
|
||||
if (m_busHandler->readFromBus(message, "") != RESULT_OK)
|
||||
continue;
|
||||
lastup = message->getLastUpdateTime();
|
||||
} else {
|
||||
|
||||
@@ -47,6 +47,12 @@ public:
|
||||
*/
|
||||
~MainLoop();
|
||||
|
||||
/**
|
||||
* Get the @a BusHandler instance.
|
||||
* @return the created @a BusHandler instance.
|
||||
*/
|
||||
BusHandler* getBusHandler() { return m_busHandler; }
|
||||
|
||||
/**
|
||||
* Run the main loop.
|
||||
*/
|
||||
@@ -110,15 +116,6 @@ private:
|
||||
*/
|
||||
result_t parseHexMaster(vector<string> &args, size_t argPos, SymbolString& master);
|
||||
|
||||
/**
|
||||
* Prepare the master part for the @a Message, send it to the bus and wait for the answer.
|
||||
* @param message the @a Message instance.
|
||||
* @param inputStr the input @a string from which to read master values (if any).
|
||||
* @param dstAddress the destination address to set, or @a SYN to keep the address defined during construction.
|
||||
* @return the result code.
|
||||
*/
|
||||
result_t readFromBus(Message* message, string inputStr, const unsigned char dstAddress=SYN);
|
||||
|
||||
/**
|
||||
* Execute the read command.
|
||||
* @param args the arguments passed to the command (starting with the command itself), or empty for help.
|
||||
|
||||
Reference in New Issue
Block a user