neighbors.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef NEIGHBORS_H
  2. #define NEIGHBORS_H
  3. #include <Arduino.h>
  4. #include <esp_now.h>
  5. #include <stdio.h>
  6. #include "configuration.h"
  7. /** Convert hex mac address to uint64_t
  8. * @param[in] hwaddr hex mac address
  9. * @return mac address as uint64_t
  10. */
  11. uint64_t mac2int(const uint8_t macstr[]);
  12. void print_id(const uint64_t id);
  13. typedef struct {
  14. uint64_t id;
  15. unsigned long last_hello;
  16. bool agreement;
  17. } neighbor_t;
  18. class Neighbor_List {
  19. // Maintains a list of neighbors
  20. private:
  21. neighbor_t list[MAX_NEIGHBORS];
  22. uint64_t my_id;
  23. bool network_ready = false;
  24. bool sort_neighbors(void);
  25. public:
  26. Neighbor_List(void);
  27. bool ready(void);
  28. void beacon(void);
  29. void test_sort(void);
  30. void print_list(void);
  31. void set_agreement(const uint64_t neighbor_id, const bool agreement);
  32. bool add_neighbor(const uint64_t neighbor_id);
  33. bool process_discovery(const uint8_t neighbor[19], const uint8_t *data, const size_t len);
  34. };
  35. extern Neighbor_List NList;
  36. #endif