crv2_esp_now.h 997 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef CRV2_ESP_NOW_H
  2. #define CRV2_ESP_NOW_H
  3. /* Protocol version will maybe help us in the future if we decide to redo the protocol
  4. * in a major way.
  5. */
  6. #define PROTOCOL_VERSION 1
  7. #include "configuration.h"
  8. typedef struct {
  9. int data_len;
  10. uint8_t mac_addr[19];
  11. uint8_t data[ESP_NOW_MAX_DATA_LEN+1];
  12. } receive_buffer_t;
  13. /* Send a message in an MBOX header */
  14. bool send_encapsulated(const uint8_t type, const uint8_t *data, const size_t len);
  15. /* Decapsulate a message and route it appropriately */
  16. void process_message(receive_buffer_t& incoming);
  17. /* Send raw data */
  18. bool send_broadcast(const uint8_t *data, const size_t len);
  19. receive_buffer_t *get_message();
  20. bool manageSlave();
  21. void initBroadcast();
  22. bool manageBroadcast();
  23. // callback when data is received
  24. void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len);
  25. // callback when data is sent
  26. void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status);
  27. #endif