diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 201d4fc9..1e5a092e 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -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(); diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index a607f202..d80b0d4b 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -789,6 +789,10 @@ public: radio_set_tx_power(power_dbm); } + void formatNeighborsReply(char *reply) override { + strcpy(reply, "not supported"); + } + void loop() { mesh::Mesh::loop(); diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index f3077afb..acf12574 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -161,6 +161,8 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch } else { strcpy(reply, "(ERR: clock cannot go backwards)"); } + } else if (memcmp(command, "neighbors", 9) == 0) { + _callbacks->formatNeighborsReply(reply); } else if (memcmp(command, "password ", 9) == 0) { // change admin password StrHelper::strncpy(_prefs->password, &command[9], sizeof(_prefs->password)); diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 50e5f8d6..27fd1c08 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -40,6 +40,7 @@ public: virtual void eraseLogFile() = 0; virtual void dumpLogFile() = 0; virtual void setTxPower(uint8_t power_dbm) = 0; + virtual void formatNeighborsReply(char *reply) = 0; }; class CommonCLI {