Skip to content

Commit

Permalink
fix m-m auto-answer response length and message search
Browse files Browse the repository at this point in the history
  • Loading branch information
john30 committed Mar 9, 2024
1 parent 393c9f8 commit f26c48e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/ebusd/bushandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ebusd/mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/lib/ebus/protocol_direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -881,7 +881,6 @@ bool DirectProtocolHandler::getAnswer() {
m_response = it->second;
return true;
}
break;
}
if (len == 0) {
break;
Expand Down

0 comments on commit f26c48e

Please sign in to comment.