Skip to content

Commit 4bb16ef

Browse files
authored
Merge pull request #850 from liamcottle/fix/legacy-neighbours-cli
Backwards Compatibility: Legacy Neighbours CLI
2 parents 70ec996 + f8f5f00 commit 4bb16ef

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

examples/simple_repeater/MyMesh.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,24 @@ void MyMesh::formatNeighborsReply(char *reply) {
706706
char *dp = reply;
707707

708708
#if MAX_NEIGHBOURS
709-
for (int i = 0; i < MAX_NEIGHBOURS && dp - reply < 134; i++) {
710-
NeighbourInfo *neighbour = &neighbours[i];
711-
if (neighbour->heard_timestamp == 0) continue; // skip empty slots
709+
// create copy of neighbours list, skipping empty entries so we can sort it separately from main list
710+
int16_t neighbours_count = 0;
711+
NeighbourInfo* sorted_neighbours[MAX_NEIGHBOURS];
712+
for (int i = 0; i < MAX_NEIGHBOURS; i++) {
713+
auto neighbour = &neighbours[i];
714+
if (neighbour->heard_timestamp > 0) {
715+
sorted_neighbours[neighbours_count] = neighbour;
716+
neighbours_count++;
717+
}
718+
}
719+
720+
// sort neighbours newest to oldest
721+
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo* a, const NeighbourInfo* b) {
722+
return a->heard_timestamp > b->heard_timestamp; // desc
723+
});
724+
725+
for (int i = 0; i < neighbours_count && dp - reply < 134; i++) {
726+
NeighbourInfo *neighbour = sorted_neighbours[i];
712727

713728
// add new line if not first item
714729
if (i > 0) *dp++ = '\n';

0 commit comments

Comments
 (0)