fix m-m auto-answer response length and message search

This commit is contained in:
John
2024-03-09 10:11:41 +01:00
parent 393c9f81e5
commit f26c48eb49
3 changed files with 8 additions and 7 deletions
+6 -4
View File
@@ -442,15 +442,17 @@ void BusHandler::notifyProtocolMessage(MessageDirection direction, const MasterS
}
if (direction == md_answer) {
size_t idLen = command.getDataSize();
if (master && idLen >= response.size()) {
size_t resLen = response.getDataSize();
if (master && idLen >= resLen) {
// build MS auto-answer from MM with same ID
SlaveSymbolString answer;
answer.push_back(0); // room for length
idLen -= response.size();
for (size_t pos = idLen; pos < response.size(); pos++) {
idLen -= resLen;
for (size_t pos = idLen; pos < resLen; pos++) {
answer.push_back(command.dataAt(pos));
}
m_protocol->setAnswer(SYN, command[1], command[2], command[3], command.data() + 5, idLen, answer);
answer.adjustHeader();
m_protocol->setAnswer(SYN, getSlaveAddress(dstAddress), command[2], command[3], command.data() + 5, idLen, answer);
// TODO could use loaded messages for identifying MM/MS message pair
}
}
+1 -1
View File
@@ -1240,7 +1240,7 @@ result_t MainLoop::executeAnswer(const vector<string>& args, ostringstream* ostr
if (answer.size() > 16) {
return RESULT_ERR_INVALID_POS;
}
answer[0] = (symbol_t)(answer.size()-1);
answer.adjustHeader();
}
if (argPos < args.size()) {
argPos = 0; // print usage
+1 -2
View File
@@ -872,7 +872,7 @@ bool DirectProtocolHandler::getAnswer() {
if (it != m_answerByKey.end()) {
// found the answer
if (master) {
if (len+it->second.size() == m_command[4]) {
if (len+it->second.getDataSize() == m_command[4]) {
m_response = it->second; // copied for having the data size only
return true;
}
@@ -881,7 +881,6 @@ bool DirectProtocolHandler::getAnswer() {
m_response = it->second;
return true;
}
break;
}
if (len == 0) {
break;