remote.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef REMOTE_H_
  2. #define REMOTE_H_
  3. #include <stdint.h>
  4. #include <avr/pgmspace.h>
  5. enum remote_message_id {
  6. MSG_INVALID = 0, /* Discard me */
  7. MSG_ERROR,
  8. MSG_LOGMESSAGE,
  9. MSG_PING,
  10. MSG_PONG,
  11. MSG_GET_CURRENT_PRESSURE,
  12. MSG_CURRENT_PRESSURE,
  13. MSG_GET_DESIRED_PRESSURE,
  14. MSG_DESIRED_PRESSURE,
  15. MSG_SET_DESIRED_PRESSURE,
  16. MSG_GET_HYSTERESIS,
  17. MSG_HYSTERESIS,
  18. MSG_SET_HYSTERESIS,
  19. MSG_GET_CONFIG_FLAGS,
  20. MSG_CONFIG_FLAGS,
  21. MSG_SET_CONFIG_FLAGS,
  22. MSG_SET_VALVE,
  23. MSG_RESTARTED,
  24. MSG_SHUTDOWN,
  25. MSG_TURNON,
  26. MSG_GET_MAXIMA,
  27. MSG_MAXIMA,
  28. MSG_ID_MASK = 0x3F,
  29. MSG_FLAG_QOVERFLOW = 0x40, /* TX queue overflow */
  30. MSG_FLAG_REQ_ERRCODE = 0x80, /* Error code is requested */
  31. };
  32. enum remote_message_error {
  33. MSG_ERR_NONE = 0, /* No error */
  34. MSG_ERR_CHKSUM, /* Checksum error */
  35. MSG_ERR_NOCMD, /* Unknown command */
  36. MSG_ERR_BUSY, /* Busy */
  37. MSG_ERR_INVAL, /* Invalid argument */
  38. };
  39. enum remote_message_config_flags {
  40. CFG_FLAG_AUTOADJUST_ENABLE = 0,
  41. };
  42. struct remote_message {
  43. uint8_t id;
  44. union {
  45. struct {
  46. uint8_t code;
  47. } __attribute__((packed)) error;
  48. struct {
  49. char str[4];
  50. } __attribute__((packed)) logmessage;
  51. struct {
  52. uint16_t mbar[2];
  53. } __attribute__((packed)) pressure;
  54. struct {
  55. uint8_t island; /* Valve island */
  56. uint16_t mbar;
  57. } __attribute__((packed)) setpressure;
  58. struct {
  59. uint8_t flags[2];
  60. } __attribute__((packed)) config;
  61. struct {
  62. uint8_t island; /* Valve island */
  63. uint8_t flags;
  64. } __attribute__((packed)) setconfig;
  65. struct {
  66. uint8_t island; /* Valve island */
  67. uint8_t nr; /* Valve ID in the island */
  68. uint8_t state;
  69. } __attribute__((packed)) valve;
  70. struct {
  71. uint8_t island; /* Valve island */
  72. } __attribute__((packed)) getmaxima;
  73. struct {
  74. uint16_t pressure;
  75. uint16_t hysteresis;
  76. } __attribute__((packed)) maxima;
  77. uint8_t __padding[4];
  78. } __attribute__((packed));
  79. uint8_t crc;
  80. } __attribute__((packed));
  81. void print_sram(const char *msg);
  82. void print_pgm(const char __flash *msg);
  83. #define print(string_literal) print_pgm(PSTR(string_literal))
  84. void print_dec(uint16_t number);
  85. void print_dec_signed(int16_t number);
  86. void print_hex(uint8_t number);
  87. void remote_pressure_change_notification(uint16_t xy_mbar, uint16_t z_mbar);
  88. void remote_notify_restart(void);
  89. void remote_work(void);
  90. void remote_init(void);
  91. #endif /* REMOTE_H_ */