protocol.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /**
  2. * @file protocol.h
  3. * @brief declaration of fuction in protocol.c
  4. * @author qinlang
  5. * @date 2022.05.06
  6. * @par email:
  7. * @par email:qinlang.chen@tuya.com
  8. * @copyright HANGZHOU TUYA INFORMATION TECHNOLOGY CO.,LTD
  9. * @par company
  10. * http://www.tuya.com
  11. */
  12. #ifndef __PROTOCOL_H_
  13. #define __PROTOCOL_H_
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. #endif
  18. /******************************************************************************
  19. 配置产品类别须知:
  20. 1:根据实际设计电路板,设置产品SKU,必须修改参数“switchSKU”为对应产品类别
  21. 2:根据涂鸦ZigBee固件类别,需设置对应的宏定义
  22. OTA设置须知:
  23. 1.开启OTA(需先下载“BootLoader”程序),宏定义“SUPPORT_MCU_OTA”打开,并设置编译下载环境参数,IROM1:0x8003000,0x6800
  24. 2.关闭OTA, 注释宏定义“SUPPORT_MCU_OTA”,并设置编译下载环境参数:IROM1:0x8000000,0x20000
  25. ******************************************************************************/
  26. #define REALSE 1 //生产模式,看门狗打开
  27. //#define DOOR 1 //干触点开关
  28. #define switchSKU 0x04//产品SKU, 混合面板bit7=1;纯场景面板,bit3=1;
  29. //04:中山4键,
  30. //14:臣仕C4键,
  31. //chensir 4键系列
  32. //#define ZIGBEE_ZS_T4_CS 1//定义该开关为芯科4键开关-CHENSIR C
  33. //中山6键轻触系列 --通用定义
  34. #define ZIGBEE_ZS_T4 1//轻触4键开关
  35. /////////////////////////背光参数/////////////////////////////////////////////
  36. //臣仕C系列 --1-4键
  37. #if (defined ZIGBEE_ZS_T4_CS)
  38. #define mKeyLedWeaknight 1 //弱光1/120,按键灯夜晚背光,臣仕2
  39. #define mKeyLedWeakday 6 //弱光6/120,按键灯白天背光,臣仕5
  40. #define mKeyLedBrightLight 30 //强光 30/120,继电器触发,按键灯高亮,臣仕15
  41. #define mBLedWeaknight 10 //弱光10/100,氛围灯夜晚背光,臣仕10
  42. #define mBLedWeakday 20 //弱光20/100,氛围灯白天背光,臣仕20
  43. //中山高成本 --触摸按键1-4
  44. #elif (defined ZIGBEE_ZS_T4)
  45. #define mKeyLedWeaknight 8 //中山弱光8/120,按键灯夜晚背光,臣仕2
  46. #define mKeyLedWeakday 20 //中山弱光20/120,按键灯白天背光,臣仕5
  47. #define mKeyLedBrightLight 100 //强光 100/120,继电器触发,按键灯高亮,臣仕15
  48. #define mBLedWeaknight 40 //弱光40/100,氛围灯夜晚背光
  49. #define mBLedWeakday 70 //弱光70/100,氛围灯白天背光
  50. //以下为默认参数
  51. #else
  52. #define mKeyLedWeaknight 4 //弱光4/120,按键灯夜晚背光
  53. #define mKeyLedWeakday 10 //弱光10/120,按键灯白天背光
  54. #define mKeyLedBrightLight 50 //强光 50/120,继电器触发,按键灯高亮
  55. #define mBLedWeaknight 10 //弱光10/100,氛围灯夜晚背光
  56. #define mBLedWeakday 20 //弱光20/100,氛围灯白天背光
  57. #endif
  58. /////////////////////////背光参数/////////////////////////////////////////////
  59. ///< product INFORMATION
  60. ///< mcu version
  61. //#define MCU_VER "1.0.1" // MAX 3.3.15 BIT 7~0 XX.XX.XXXX
  62. #define PRODUCT_KEY "nkx3lalp" //开发平台创建产品后生成的16位字符产品唯一标识
  63. #define MCU_VER "1.0.0" // MAX 3.3.15 BIT 7~0 XX.XX.XXXX
  64. #define ZIGBEE_UART_QUEUE_LMT 256 // using to save data received from uart
  65. #define ZIGBEE_UART_RECV_BUF_LMT 128 //
  66. #define ZIGBEE_UART_SEND_BUF_LMT 128 //
  67. typedef enum
  68. {
  69. MCU_TYPE_DC_POWER = 1,
  70. MCU_TYPE_LOWER_POWER,
  71. MCU_TYPE_SCENE
  72. } MCU_TYPE_E;
  73. /**
  74. * if mcu need to support the time function, this macro definition should be opened
  75. * and need complete mcu_write_rtctime function
  76. *
  77. */
  78. //#define SUPPORT_MCU_RTC_CHECK //start time calibration
  79. /**
  80. * if mcu need to support OTA, this macro definition should be opened
  81. */
  82. #define SUPPORT_MCU_OTA //support mcu ota
  83. //modify by zzw 20221010 开启MCU OTA功能
  84. /**
  85. * if mcu need to support mcu type checking, this macro definition should be opened
  86. *
  87. */
  88. //#define CHECK_MCU_TYPE //support mcu type check
  89. /**
  90. * if mcu need to support zigbee network parameter setting, this macro definition should be opened
  91. *
  92. */
  93. //#define SET_ZIGBEE_NWK_PARAMETER //support zigbee nwk parameter setting
  94. /**
  95. * if mcu need to send a broadcast data, this macro definition should be opened
  96. *
  97. */
  98. //#define BROADCAST_DATA_SEND //support broadcast data sending
  99. /**
  100. * DP data list,this code will be generate by cloud platforms
  101. */
  102. /******************************************************************************
  103. 1:dp数据与涂鸦平台创建的产品对应
  104. **此为自动生成代码,如在开发平台有相关修改请重新下载MCU_SDK**
  105. ******************************************************************************/
  106. //备注:
  107. //开关(可下发可上报)
  108. //备注:
  109. #define DPID_SWITCH 1
  110. //工作模式(可下发可上报)
  111. //备注:
  112. #define DPID_MODE 2
  113. //工作状态(只上报)
  114. //备注:
  115. #define DPID_WORK_STATE 3
  116. //目标温度(可下发可上报)
  117. //备注:
  118. #define DPID_TEMP_SET 16
  119. //当前温度(只上报)
  120. //备注:
  121. #define DPID_TEMP_CURRENT 24
  122. //档位(可下发可上报)
  123. //备注:
  124. #define DPID_LEVEL 28
  125. //工作状态(可下发可上报)
  126. //备注:
  127. #define DPID_WORK_STATE1 101
  128. //地暖目标温度(可下发可上报)
  129. //备注:
  130. #define DPID_TEMP_DN 102
  131. //地暖开关(可下发可上报)
  132. //备注:
  133. #define DPID_SWITCH_FLOOR_HEAT 103
  134. //新风开关(可下发可上报)
  135. //备注:
  136. #define DPID_SWITCH_FAN 104
  137. //新风风速档位(可下发可上报)
  138. //备注:
  139. #define DPID_LEVEL_FAN 105
  140. void zigbee_notify_factory_new_hanlde(void);
  141. /**
  142. * @brief encapsulates a generic send function, developer should use their own function to completing this fuction
  143. * @param[in] {value} send signle data
  144. * @return void
  145. */
  146. void uart_transmit_output(unsigned char value);
  147. /**
  148. * @brief Upload all dp information of the system, and realize the synchronization of APP and muc data
  149. * @param[in] {void}
  150. * @return void
  151. */
  152. void all_data_update(void);
  153. /**
  154. * @brief mcu check local RTC time
  155. * @param[in] {time} timestamp
  156. * @return void
  157. */
  158. void mcu_write_rtctime(unsigned char time[]);
  159. /**
  160. * @brief Zigbee functional test feedback
  161. * @param[in] {void}
  162. * @return void
  163. */
  164. void zigbee_test_result(void);
  165. /**
  166. * @brief this function will handle uart received frame data
  167. * @param[in] {dpid} dp id
  168. * @param[in] {value} dp data
  169. * @param[in] {length} lenght of dp data
  170. * @return handle result
  171. */
  172. unsigned char dp_download_handle(unsigned char dpid, const unsigned char value[], unsigned short length);
  173. /**
  174. * @brief get received cmd total number
  175. * @param[in] {void}
  176. * @return received cmd total number
  177. */
  178. unsigned char get_download_cmd_total(void);
  179. /**
  180. * @brief received zigbee net_work state handle
  181. * @param[in] {zigbee_work_state} zigbee current network state
  182. * @return void
  183. */
  184. void zigbee_work_state_event(unsigned char zigbee_work_state);
  185. /**
  186. * @brief received reset zigbee response
  187. * @param[in] {state} response state
  188. * @return void
  189. */
  190. void mcu_reset_zigbee_event(unsigned char state);
  191. /**
  192. * @brief check mcu version response
  193. * @param[in] {void}
  194. * @return void
  195. */
  196. void response_mcu_ota_version_event(void);
  197. #ifdef SUPPORT_MCU_OTA
  198. /**
  199. * @brief mcu ota update notify response
  200. * @param[in] {offset} offset of file
  201. * @return void
  202. */
  203. void response_mcu_ota_notify_event(unsigned char offset);
  204. /**
  205. * @brief received mcu ota data request response
  206. * @param[in] {fw_offset} offset of file
  207. * @param[in] {data} received data
  208. * @return void
  209. */
  210. void reveived_mcu_ota_data_handle(unsigned int fw_offset, char *data);
  211. /**
  212. * @brief mcu send ota data request
  213. * @param[in] {offset} offset of file
  214. * @return void
  215. */
  216. void mcu_ota_fw_request_event(unsigned char offset);
  217. /**
  218. * @brief mcu ota data result notify
  219. * @param[in] {offset} offset of file
  220. * @return void
  221. */
  222. void mcu_ota_result_event(unsigned char offset);
  223. /**
  224. * @brief mcu ota data handle
  225. * @param[in] {fw_offset} frame offset
  226. * @param[in] {data} received data
  227. * @return void
  228. */
  229. void ota_fw_data_handle(unsigned int fw_offset, char *data, unsigned char data_len);
  230. #endif
  231. #ifdef BEACON_TEST
  232. /**
  233. * @brief beacon test notify,which used in testing
  234. * @param[in] {void}
  235. * @return void
  236. */
  237. void mcu_received_beacon_test_handle(void);
  238. #endif
  239. #ifdef CHECK_ZIGBEE_NETWORK
  240. /**
  241. * @brief check zigbee nwkstate,before start join nwk, check nwk if state is not 0x02,can start jion,
  242. * else delay 5s
  243. *
  244. * @param[in] {void}
  245. * @return void
  246. */
  247. void mcu_check_zigbee_nwk_state(void);
  248. #endif
  249. #ifdef READ_DP_DATA_NOTIFY
  250. /**
  251. * @brief when gateway repower or relink clould, or zigbee module join sucess, repower, this commod will notify
  252. * mcu, to sys dp data, mcu itself decide whether report.
  253. *
  254. * @param[in] {void}
  255. * @return void
  256. */
  257. void read_dp_data_notify_hanlde(void);
  258. #endif
  259. #ifdef __cplusplus
  260. }
  261. #endif
  262. #endif