MeshCore.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #include <stdint.h>
  3. #include <math.h>
  4. #define MAX_HASH_SIZE 8
  5. #define PUB_KEY_SIZE 32
  6. #define PRV_KEY_SIZE 64
  7. #define SEED_SIZE 32
  8. #define SIGNATURE_SIZE 64
  9. #define MAX_ADVERT_DATA_SIZE 32
  10. #define CIPHER_KEY_SIZE 16
  11. #define CIPHER_BLOCK_SIZE 16
  12. // V1
  13. #define CIPHER_MAC_SIZE 2
  14. #define PATH_HASH_SIZE 1
  15. #define MAX_PACKET_PAYLOAD 184
  16. #define MAX_PATH_SIZE 64
  17. #define MAX_TRANS_UNIT 255
  18. #if MESH_DEBUG && ARDUINO
  19. #include <Arduino.h>
  20. #define MESH_DEBUG_PRINT(F, ...) Serial.printf("DEBUG: " F, ##__VA_ARGS__)
  21. #define MESH_DEBUG_PRINTLN(F, ...) Serial.printf("DEBUG: " F "\n", ##__VA_ARGS__)
  22. #else
  23. #define MESH_DEBUG_PRINT(...) {}
  24. #define MESH_DEBUG_PRINTLN(...) {}
  25. #endif
  26. #if BRIDGE_DEBUG && ARDUINO
  27. #define BRIDGE_DEBUG_PRINTLN(F, ...) Serial.printf("%s BRIDGE: " F, getLogDateTime(), ##__VA_ARGS__)
  28. #else
  29. #define BRIDGE_DEBUG_PRINTLN(...) {}
  30. #endif
  31. namespace mesh {
  32. #define BD_STARTUP_NORMAL 0 // getStartupReason() codes
  33. #define BD_STARTUP_RX_PACKET 1
  34. class MainBoard {
  35. public:
  36. virtual uint16_t getBattMilliVolts() = 0;
  37. virtual float getMCUTemperature() { return NAN; }
  38. virtual bool setAdcMultiplier(float multiplier) { return false; };
  39. virtual float getAdcMultiplier() const { return 0.0f; }
  40. virtual const char* getManufacturerName() const = 0;
  41. virtual void onBeforeTransmit() { }
  42. virtual void onAfterTransmit() { }
  43. virtual void reboot() = 0;
  44. virtual void powerOff() { /* no op */ }
  45. virtual void sleep(uint32_t secs) { /* no op */ }
  46. virtual uint32_t getGpio() { return 0; }
  47. virtual void setGpio(uint32_t values) {}
  48. virtual uint8_t getStartupReason() const = 0;
  49. virtual bool getBootloaderVersion(char* version, size_t max_len) { return false; }
  50. virtual bool startOTAUpdate(const char* id, char reply[]) { return false; } // not supported
  51. // Power management interface (boards with power management override these)
  52. virtual bool isExternalPowered() { return false; }
  53. virtual uint16_t getBootVoltage() { return 0; }
  54. virtual uint32_t getResetReason() const { return 0; }
  55. virtual const char* getResetReasonString(uint32_t reason) { return "Not available"; }
  56. virtual uint8_t getShutdownReason() const { return 0; }
  57. virtual const char* getShutdownReasonString(uint8_t reason) { return "Not available"; }
  58. };
  59. /**
  60. * An abstraction of the device's Realtime Clock.
  61. */
  62. class RTCClock {
  63. uint32_t last_unique;
  64. protected:
  65. RTCClock() { last_unique = 0; }
  66. public:
  67. /**
  68. * \returns the current time. in UNIX epoch seconds.
  69. */
  70. virtual uint32_t getCurrentTime() = 0;
  71. /**
  72. * \param time current time in UNIX epoch seconds.
  73. */
  74. virtual void setCurrentTime(uint32_t time) = 0;
  75. /**
  76. * override in classes that need to periodically update internal state
  77. */
  78. virtual void tick() { /* no op */}
  79. uint32_t getCurrentTimeUnique() {
  80. uint32_t t = getCurrentTime();
  81. if (t <= last_unique) {
  82. return ++last_unique;
  83. }
  84. return last_unique = t;
  85. }
  86. };
  87. }