Merge pull request #850 from liamcottle/fix/legacy-neighbours-cli
Backwards Compatibility: Legacy Neighbours CLI
This commit is contained in:
@@ -706,9 +706,24 @@ void MyMesh::formatNeighborsReply(char *reply) {
|
|||||||
char *dp = reply;
|
char *dp = reply;
|
||||||
|
|
||||||
#if MAX_NEIGHBOURS
|
#if MAX_NEIGHBOURS
|
||||||
for (int i = 0; i < MAX_NEIGHBOURS && dp - reply < 134; i++) {
|
// create copy of neighbours list, skipping empty entries so we can sort it separately from main list
|
||||||
NeighbourInfo *neighbour = &neighbours[i];
|
int16_t neighbours_count = 0;
|
||||||
if (neighbour->heard_timestamp == 0) continue; // skip empty slots
|
NeighbourInfo* sorted_neighbours[MAX_NEIGHBOURS];
|
||||||
|
for (int i = 0; i < MAX_NEIGHBOURS; i++) {
|
||||||
|
auto neighbour = &neighbours[i];
|
||||||
|
if (neighbour->heard_timestamp > 0) {
|
||||||
|
sorted_neighbours[neighbours_count] = neighbour;
|
||||||
|
neighbours_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort neighbours newest to oldest
|
||||||
|
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo* a, const NeighbourInfo* b) {
|
||||||
|
return a->heard_timestamp > b->heard_timestamp; // desc
|
||||||
|
});
|
||||||
|
|
||||||
|
for (int i = 0; i < neighbours_count && dp - reply < 134; i++) {
|
||||||
|
NeighbourInfo *neighbour = sorted_neighbours[i];
|
||||||
|
|
||||||
// add new line if not first item
|
// add new line if not first item
|
||||||
if (i > 0) *dp++ = '\n';
|
if (i > 0) *dp++ = '\n';
|
||||||
|
|||||||
Reference in New Issue
Block a user