* refactor: "neighbors" command

This commit is contained in:
Scott Powell 2025-04-30 21:41:09 +10:00
parent 056bcf83d9
commit 8a8e89f282
4 changed files with 30 additions and 21 deletions

View file

@ -480,27 +480,6 @@ protected:
char *reply = (char *) &temp[5];
if (is_retry) {
*reply = 0;
#if MAX_NEIGHBOURS
} else if (memcmp(command, "neighbors", 9) == 0) {
char *dp = reply;
for (int i = 0; i < MAX_NEIGHBOURS && dp - reply < 136; i++) {
NeighbourInfo* neighbour = &neighbours[i];
if (neighbour->heard_timestamp == 0) continue; // skip empty slots
// add new line if not first item
if (i > 0) *dp++ = '\n';
char hex[10];
// get 4 bytes of neighbour id as hex
mesh::Utils::toHex(hex, neighbour->id.pub_key, 4);
// add next neighbour
sprintf(dp, "%s:%d:%d", hex, neighbour->advert_timestamp, neighbour->snr);
while (*dp) dp++; // find end of string
}
*dp = 0; // null terminator
#endif
} else {
_cli.handleCommand(sender_timestamp, command, reply);
}
@ -664,6 +643,29 @@ public:
radio_set_tx_power(power_dbm);
}
void formatNeighborsReply(char *reply) override {
char *dp = reply;
#if MAX_NEIGHBOURS
for (int i = 0; i < MAX_NEIGHBOURS && dp - reply < 134; i++) {
NeighbourInfo* neighbour = &neighbours[i];
if (neighbour->heard_timestamp == 0) continue; // skip empty slots
// add new line if not first item
if (i > 0) *dp++ = '\n';
char hex[10];
// get 4 bytes of neighbour id as hex
mesh::Utils::toHex(hex, neighbour->id.pub_key, 4);
// add next neighbour
sprintf(dp, "%s:%d:%d", hex, neighbour->advert_timestamp, neighbour->snr);
while (*dp) dp++; // find end of string
}
#endif
*dp = 0; // null terminator
}
void loop() {
mesh::Mesh::loop();