MeshCore.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #include <stdint.h>
  3. #define MAX_HASH_SIZE 8
  4. #define PUB_KEY_SIZE 32
  5. #define PRV_KEY_SIZE 64
  6. #define SEED_SIZE 32
  7. #define SIGNATURE_SIZE 64
  8. #define MAX_ADVERT_DATA_SIZE 32
  9. #define CIPHER_KEY_SIZE 16
  10. #define CIPHER_BLOCK_SIZE 16
  11. // V1
  12. #define CIPHER_MAC_SIZE 2
  13. #define PATH_HASH_SIZE 1
  14. #define MAX_PACKET_PAYLOAD 184
  15. #define MAX_PATH_SIZE 64
  16. #define MAX_TRANS_UNIT 255
  17. #if MESH_DEBUG && ARDUINO
  18. #include <Arduino.h>
  19. #define MESH_DEBUG_PRINT(F, ...) Serial.printf("DEBUG: " F, ##__VA_ARGS__)
  20. #define MESH_DEBUG_PRINTLN(F, ...) Serial.printf("DEBUG: " F "\n", ##__VA_ARGS__)
  21. #else
  22. #define MESH_DEBUG_PRINT(...) {}
  23. #define MESH_DEBUG_PRINTLN(...) {}
  24. #endif
  25. namespace mesh {
  26. #define BD_STARTUP_NORMAL 0 // getStartupReason() codes
  27. #define BD_STARTUP_RX_PACKET 1
  28. class MainBoard {
  29. public:
  30. virtual uint16_t getBattMilliVolts() = 0;
  31. virtual const char* getManufacturerName() const = 0;
  32. virtual void onBeforeTransmit() { }
  33. virtual void onAfterTransmit() { }
  34. virtual void reboot() = 0;
  35. virtual void powerOff() { /* no op */ }
  36. virtual uint32_t getGpio() { return 0; }
  37. virtual void setGpio(uint32_t values) {}
  38. virtual uint8_t getStartupReason() const = 0;
  39. virtual bool startOTAUpdate(const char* id, char reply[]) { return false; } // not supported
  40. };
  41. /**
  42. * An abstraction of the device's Realtime Clock.
  43. */
  44. class RTCClock {
  45. uint32_t last_unique;
  46. protected:
  47. RTCClock() { last_unique = 0; }
  48. public:
  49. /**
  50. * \returns the current time. in UNIX epoch seconds.
  51. */
  52. virtual uint32_t getCurrentTime() = 0;
  53. /**
  54. * \param time current time in UNIX epoch seconds.
  55. */
  56. virtual void setCurrentTime(uint32_t time) = 0;
  57. uint32_t getCurrentTimeUnique() {
  58. uint32_t t = getCurrentTime();
  59. if (t <= last_unique) {
  60. return ++last_unique;
  61. }
  62. return last_unique = t;
  63. }
  64. };
  65. }