From f26c48eb49a5de4e821aa04a32e5e86e5879a948 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 9 Mar 2024 10:11:41 +0100 Subject: [PATCH] fix m-m auto-answer response length and message search --- src/ebusd/bushandler.cpp | 10 ++++++---- src/ebusd/mainloop.cpp | 2 +- src/lib/ebus/protocol_direct.cpp | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 20757f4f..93d24ef5 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -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 } } diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 0b006390..b7d0be1a 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -1240,7 +1240,7 @@ result_t MainLoop::executeAnswer(const vector& 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 diff --git a/src/lib/ebus/protocol_direct.cpp b/src/lib/ebus/protocol_direct.cpp index d9fa0e30..24e97386 100644 --- a/src/lib/ebus/protocol_direct.cpp +++ b/src/lib/ebus/protocol_direct.cpp @@ -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;