Skip to content

Commit 7d2af8e

Browse files
fix: batch confirmation message
1 parent 9af2c16 commit 7d2af8e

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

src/tasks/cli/commands/dispatch.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ using WireCommand = wire::Command;
1717

1818
namespace {
1919

20+
static void emitListBatchAckIfComplete(CliProtocol &proto, const char *cmdName,
21+
const wire::ListHeader &hdr) {
22+
if(hdr.B <= 0 || hdr.j != hdr.B - 1) {
23+
return;
24+
}
25+
proto.emitBatchAckRange(cmdName, 0, hdr.B - 1);
26+
}
27+
2028
static int batchMapAdd(std::vector<WireCommand> &cmds, size_t headerIdx,
2129
const wire::ListHeader &hdr, CliProtocol &proto) {
2230
for(int k = 1; k <= hdr.C; k++) {
@@ -30,7 +38,7 @@ static int batchMapAdd(std::vector<WireCommand> &cmds, size_t headerIdx,
3038
[](const MapPoint &a, const MapPoint &b) {
3139
return a.encoderMilimeters < b.encoderMilimeters;
3240
});
33-
proto.emitBatchAck("map_add", hdr.j);
41+
emitListBatchAckIfComplete(proto, "map_add", hdr);
3442
return CLI_SUCCESS;
3543
}
3644

@@ -46,7 +54,7 @@ static int batchParamSet(std::vector<WireCommand> &cmds, size_t headerIdx,
4654
if(!cli_param::paramSetPersistWireError(proto)) {
4755
return CLI_SUCCESS;
4856
}
49-
proto.emitBatchAck("param_set", hdr.j);
57+
emitListBatchAckIfComplete(proto, "param_set", hdr);
5058
return CLI_SUCCESS;
5159
}
5260

src/tasks/cli/tamanducli/wprotocol.hpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -759,17 +759,28 @@ template <size_t MessageSize = 256> class Protocol {
759759
/**
760760
* @brief Envia ACK de lote para coleta de listas no host.
761761
*
762-
* Formato: `nome(s,s,<messageIndex>,<messageIndex>,ok);`
762+
* Formato multi-mensagem: `nome(s,s,0,B-1,ok);` após a última mensagem.
763+
* Mensagem única (B=1): `nome(s,s,0,0,ok);`
763764
*
764765
* @param cmdName Nome do comando da lista.
766+
* @param lo Índice inclusive da primeira mensagem confirmada.
767+
* @param hi Índice inclusive da última mensagem confirmada.
768+
*/
769+
void emitBatchAckRange(const char *cmdName, int lo, int hi) const {
770+
char loBuf[16];
771+
char hiBuf[16];
772+
snprintf(loBuf, sizeof(loBuf), "%d", lo);
773+
snprintf(hiBuf, sizeof(hiBuf), "%d", hi);
774+
emitSingleResponse(cmdName, {loBuf, hiBuf, "ok"});
775+
}
776+
777+
/**
778+
* @brief Envia ACK para uma única mensagem de lote (`lo == hi == j`).
779+
* @param cmdName Nome do comando da lista.
765780
* @param messageIndex Índice `j` da mensagem confirmada.
766781
*/
767782
void emitBatchAck(const char *cmdName, int messageIndex) const {
768-
char lo[16];
769-
char hi[16];
770-
snprintf(lo, sizeof(lo), "%d", messageIndex);
771-
snprintf(hi, sizeof(hi), "%d", messageIndex);
772-
emitSingleResponse(cmdName, {lo, hi, "ok"});
783+
emitBatchAckRange(cmdName, messageIndex, messageIndex);
773784
}
774785

775786
/**

0 commit comments

Comments
 (0)