You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

262 lines
7.9 KiB

  1. #ifndef __FUNK_PROTO_H__
  2. #define __FUNK_PROTO_H__
  3. #include <stdint.h>
  4. /* *********************************************************************** */
  5. /*
  6. * Protocol:
  7. * - sender will restransmit up to 3 times if no response/confirmation is received after 10ms
  8. * - receiver will ignore messages with corrupt headers/data
  9. * - messages have a seqnum, retransmissions are are detected by same seqnum
  10. * - response with cause "invalid seqnum"
  11. * - initiator increases seqnum and sends request again
  12. * - commands have 2bit req/resp/ind/conf encoding
  13. * - single window
  14. *
  15. * - firmware has modules, that communicate through "events"
  16. * - INPUT modules (button/quadencoder) send events to all other (!INPUT) modules
  17. * - WORK modules (dimming, store/restore) send event to all other (!INPUT && !WORK) modules
  18. * - OUTPUT modules (pwm channels, digital channels) send event to nobody
  19. * - communication receives all events and can send to anyone
  20. * - configuration in eeprom(?) to enable which events shall be send (and to who)
  21. *
  22. * - support to switch to bootloader
  23. * - support forward to mpm/twi
  24. *
  25. * - version request?
  26. * - multiple events in one message?
  27. * - analog values
  28. *
  29. *
  30. */
  31. #define MSG_TYPE_REQUEST 0x00 /* master -> slave req */
  32. #define MSG_TYPE_CONFIRMATION 0x40 /* master -> slave rsp */
  33. #define MSG_TYPE_INDICATION 0x80 /* slave -> master req */
  34. #define MSG_TYPE_RESPONSE 0xC0 /* slave -> master rsp */
  35. #define MSG_TYPE_MASK 0xC0
  36. #define MSG_CMD_MASK 0x3F
  37. #define MSG_CMD_STATUS_REQUEST (MSG_TYPE_REQUEST | 0x01) /* 0x01 */
  38. #define MSG_CMD_STATUS_RESPONSE (MSG_TYPE_RESPONSE | 0x01) /* 0xC1 */
  39. #define MSG_CMD_DESCRIPTION_REQUEST (MSG_TYPE_REQUEST | 0x02) /* 0x02 */
  40. #define MSG_CMD_DESCRIPTION_RESPONSE (MSG_TYPE_RESPONSE | 0x02) /* 0xC2 */
  41. #define MSG_CMD_CONTROL_REQUEST (MSG_TYPE_REQUEST | 0x03) /* 0x03 */
  42. #define MSG_CMD_CONTROL_RESPONSE (MSG_TYPE_RESPONSE | 0x03) /* 0xC3 */
  43. #define MSG_CMD_REGISTER_REQUEST (MSG_TYPE_REQUEST | 0x04) /* 0x04 */
  44. #define MSG_CMD_REGISTER_RESPONSE (MSG_TYPE_RESPONSE | 0x04) /* 0xC4 */
  45. #define MSG_CMD_EVENT_INDICATION (MSG_TYPE_INDICATION | 0x03) /* 0x83 */
  46. #define MSG_CMD_EVENT_CONFIRMATION (MSG_TYPE_CONFIRMATION | 0x03) /* 0x43 */
  47. #define MSG_CMD_SWITCHAPP_REQUEST (MSG_TYPE_REQUEST | 0x20)
  48. #define MSG_CMD_SWITCHAPP_RESPONSE (MSG_TYPE_RESPONSE | 0x20)
  49. #define MSG_CMD_VERSION_REQUEST (MSG_TYPE_REQUEST | 0x21)
  50. #define MSG_CMD_VERSION_RESPONSE (MSG_TYPE_RESPONSE | 0x21)
  51. #define MSG_CMD_CHIPINFO_REQUEST (MSG_TYPE_REQUEST | 0x22)
  52. #define MSG_CMD_CHIPINFO_RESPONSE (MSG_TYPE_RESPONSE | 0x22)
  53. #define MSG_CMD_READ_REQUEST (MSG_TYPE_REQUEST | 0x23)
  54. #define MSG_CMD_READ_RESPONSE (MSG_TYPE_RESPONSE | 0x23)
  55. #define MSG_CMD_WRITE_REQUEST (MSG_TYPE_REQUEST | 0x24)
  56. #define MSG_CMD_WRITE_RESPONSE (MSG_TYPE_RESPONSE | 0x24)
  57. #define CAUSE_SUCCESS 0x00
  58. #define CAUSE_NOT_SUPPORTED 0xF0
  59. #define CAUSE_INVALID_PARAMETER 0xF1
  60. #define CAUSE_UNSPECIFIED_ERROR 0xFF
  61. #define DESCRIPTION_TYPE_CONTROL 0x01
  62. #define DESCRIPTION_TYPE_EVENT 0x02
  63. #define BOOTMODE_BOOTLOADER 0x00
  64. #define BOOTMODE_APPLICATION 0x80
  65. #define MEMTYPE_FLASH 0x01
  66. #define MEMTYPE_EEPROM 0x02
  67. /* *********************************************************************** */
  68. /*
  69. * Send a Description Request to a Light
  70. * - type is "Control" or "Event"
  71. * - num is number of controls or events
  72. */
  73. struct _description_request
  74. {
  75. uint8_t type;
  76. uint8_t num;
  77. } __attribute__ ((__packed__));
  78. /*
  79. * Send a Description Response to the master
  80. * - type is Control or Event
  81. * - num is number of controls or event
  82. * - max_num is the max number of controls or events
  83. * - data_type is used in Control_req / Event_ind
  84. * - data_num is used in Control_req / Event_ind
  85. * - data_desc is short ASCII name of that control/event
  86. */
  87. struct _description_response
  88. {
  89. uint8_t type;
  90. uint8_t num;
  91. uint8_t max_num;
  92. uint8_t data_type;
  93. uint8_t data_num;
  94. uint8_t data_desc[16];
  95. } __attribute__ ((__packed__));
  96. /*
  97. * Send a Control Request to a Light
  98. * - data_type is "button_press", "abs_dim_value", "step_up/down"
  99. * - data_num is button_numer or channel ID of light
  100. * - data is for abs values, width is encoded in ctrl_type
  101. */
  102. struct _control_request
  103. {
  104. uint8_t data_type;
  105. uint8_t data_num;
  106. uint16_t data_value;
  107. } __attribute__ ((__packed__));
  108. /*
  109. * Response for Control Request
  110. * just repeat the type & num
  111. * cause is in header
  112. */
  113. struct _control_response
  114. {
  115. uint8_t data_type;
  116. uint8_t data_num;
  117. } __attribute__ ((__packed__));
  118. /*
  119. * Register a Event
  120. * - data_type is "button_press", "movement detected", "step up/down"
  121. * - data_num is button number or channel ID
  122. * - enable is true/false
  123. */
  124. struct _register_request
  125. {
  126. uint8_t data_type;
  127. uint8_t data_num;
  128. uint8_t enable;
  129. } __attribute__ ((__packed__));
  130. /*
  131. * Response for Register Request
  132. * - data_type is "button_press", "movement detected", "step up/down"
  133. * - data_num is button number or channel ID
  134. * - data_value is last known value
  135. */
  136. struct _register_response
  137. {
  138. uint8_t data_type;
  139. uint8_t data_num;
  140. uint16_t data_value;
  141. } __attribute__ ((__packed__));
  142. /*
  143. * Send a Event to Master
  144. * - data_type is "button_press", "movement detected", "step up/down"
  145. * - data_num is button number or channel ID
  146. * - data is for abs values, width is encoded in ctrl_type
  147. */
  148. struct _event_indication
  149. {
  150. uint8_t data_type;
  151. uint8_t data_num;
  152. uint16_t data_value;
  153. } __attribute__ ((__packed__));
  154. /*
  155. * Confirmation of event indication
  156. * just repeat the type & num
  157. * cause is in header
  158. */
  159. struct _event_confirmation
  160. {
  161. uint8_t data_type;
  162. uint8_t data_num;
  163. } __attribute__ ((__packed__));
  164. struct rfm12_msg
  165. {
  166. uint8_t command; /* MSG_CMD_* */
  167. uint8_t seqnum;
  168. uint8_t cause; /* CAUSE_* */
  169. union
  170. {
  171. /* application messages */
  172. /* MSG_CMD_DESCRIPTION_REQUEST */
  173. struct _description_request desc_req;
  174. /* MSG_CMD_DESCRIPTION_RESPONSE */
  175. struct _description_response desc_rsp;
  176. /* MSG_CMD_CONTROL_REQUEST */
  177. struct _control_request ctrl_req;
  178. /* MSG_CMD_CONTROL_RESPONSE */
  179. struct _control_response ctrl_rsp;
  180. /* MSG_CMD_REGISTER_REQUEST */
  181. struct _register_request reg_req;
  182. /* MSG_CMD_REGISTER_RESPONSE */
  183. struct _register_response reg_rsp;
  184. /* MSG_CMD_EVENT_INDICATION */
  185. struct _event_indication evt_ind;
  186. /* MSG_CMD_EVENT_CONFIRMATION */
  187. struct _event_confirmation evt_cnf;
  188. /* bootloader messages */
  189. struct { /* MSG_CMD_SWITCHAPP_REQUEST */
  190. uint8_t app;
  191. } switchapp;
  192. struct { /* MSG_CMD_VERSION_RESPONSE */
  193. uint8_t data[16];
  194. } version;
  195. struct { /* MSG_CMD_CHIPINFO_RESPONSE */
  196. uint8_t data[8];
  197. } chipinfo;
  198. struct { /* MSG_CMD_READ_REQUEST */
  199. uint16_t address;
  200. uint8_t mem_type;
  201. uint8_t size;
  202. } read_req;
  203. struct { /* MSG_CMD_READ_RESPONSE */
  204. uint8_t data[32];
  205. } read_rsp;
  206. struct { /* MSG_CMD_WRITE_REQUEST */
  207. uint16_t address;
  208. uint8_t mem_type;
  209. uint8_t size;
  210. uint8_t data[32];
  211. } write_req;
  212. } p;
  213. } __attribute__ ((__packed__));
  214. /* *********************************************************************** */
  215. #endif /* __FUNK_PROTO_H__ */