MeshCore.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #if BRIDGE_DEBUG && ARDUINO
  26. #define BRIDGE_DEBUG_PRINTLN(F, ...) Serial.printf("%s BRIDGE: " F, getLogDateTime(), ##__VA_ARGS__)
  27. #else
  28. #define BRIDGE_DEBUG_PRINTLN(...) {}
  29. #endif
  30. namespace mesh {
  31. #define BD_STARTUP_NORMAL 0 // getStartupReason() codes
  32. #define BD_STARTUP_RX_PACKET 1
  33. class MainBoard {
  34. public:
  35. virtual uint16_t getBattMilliVolts() = 0;
  36. virtual bool setAdcMultiplier(float multiplier) { return false; };
  37. virtual float getAdcMultiplier() const { return 0.0f; }
  38. virtual const char* getManufacturerName() const = 0;
  39. virtual void onBeforeTransmit() { }
  40. virtual void onAfterTransmit() { }
  41. virtual void reboot() = 0;
  42. virtual void powerOff() { /* no op */ }
  43. virtual uint32_t getGpio() { return 0; }
  44. virtual void setGpio(uint32_t values) {}
  45. virtual uint8_t getStartupReason() const = 0;
  46. virtual bool startOTAUpdate(const char* id, char reply[]) { return false; } // not supported
  47. };
  48. /**
  49. * An abstraction of the device's Realtime Clock.
  50. */
  51. class RTCClock {
  52. uint32_t last_unique;
  53. protected:
  54. RTCClock() { last_unique = 0; }
  55. public:
  56. /**
  57. * \returns the current time. in UNIX epoch seconds.
  58. */
  59. virtual uint32_t getCurrentTime() = 0;
  60. /**
  61. * \param time current time in UNIX epoch seconds.
  62. */
  63. virtual void setCurrentTime(uint32_t time) = 0;
  64. /**
  65. * override in classes that need to periodically update internal state
  66. */
  67. virtual void tick() { /* no op */}
  68. uint32_t getCurrentTimeUnique() {
  69. uint32_t t = getCurrentTime();
  70. if (t <= last_unique) {
  71. return ++last_unique;
  72. }
  73. return last_unique = t;
  74. }
  75. };
  76. }