protocol.c 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625
  1. /**
  2. * @file protocol.c
  3. * @brief this file contains protocol analysis and construct response function when received zigbee module send message
  4. * @author qinlang
  5. * @date 2022.05.06
  6. * @par email:qinlang.chen@tuya.com
  7. * @copyright HANGZHOU TUYA INFORMATION TECHNOLOGY CO.,LTD
  8. * @par company
  9. * http://www.tuya.com
  10. */
  11. #include <REGtenxTM52F1386.h>
  12. #include "TM52F1386_bsp.h"
  13. #include <intrins.h>
  14. #include "zigbee.h"
  15. #include "uart.h"
  16. #include "GLOBAL.h"
  17. #include "gpio_ctrl.h"
  18. #include "EEPROM.h"
  19. #include <string.h>
  20. #include "iap.h"
  21. #include <ctype.h>
  22. #include <stdio.h>
  23. #include "HLW8110.h"
  24. unsigned char string_H16_data[32]; // 16进制字符串
  25. unsigned char hex_data[32]; // 转换后的16进制字节数据
  26. /******************************************************************************
  27. 移植须知:
  28. 1:MCU必须在while中直接调用mcu_api.c内的zigbee_uart_service()函数
  29. 2:程序正常初始化完成后,建议不进行关串口中断,如必须关中断,关中断时间必须短,关中断会引起串口数据包丢失
  30. 3:请勿在中断/定时器中断内调用上报函数
  31. ******************************************************************************/
  32. /******************************************************************************
  33. 第一步:初始化
  34. 1:在需要使用到zigbee相关文件的文件中include "zigbee.h"
  35. 2:在MCU初始化中调用mcu_api.c文件中的zigbee_protocol_init()函数
  36. 3:将MCU串口单字节发送函数填入protocol.c文件中uart_transmit_output函数内,并删除#error
  37. 4:在MCU串口接收函数中调用mcu_api.c文件内的uart_receive_input函数,并将接收到的字节作为参数传入
  38. 5:单片机进入while循环后调用mcu_api.c文件内的zigbee_uart_service()函数
  39. 6:mcu何时开启zigbee模块配网,当zigbee模块查询到mcu的产品信息之后,或者zigbee模块发送了当前网络状态
  40. 给到mcu,查询pid信息会在上电5秒之后发送,对接部分zigbee老版本通用对接固件低功耗版本尤其需要注意不要
  41. 在第一次确认波特率的时候提前唤醒或者发送串口给zigbee模组,有概率导致zigbee模组波特率存储失败。
  42. 7:上电之后,mcu何时上报数据给网关合适,在收到网络状态为已配网,或者接收到读取dp数据的时候。
  43. 8: 在mcu ota过程中发送固件内容请求未收到zigbee模块的应答时,需要mcu端做好超时重新请求的处理,和存储image
  44. 处理,校验和可以自行设计或者使用参考。
  45. ******************************************************************************/
  46. /******************************************************************************
  47. 1:dp数据点序列类型对照表
  48. **此为自动生成代码,如在开发平台有相关修改请重新下载MCU_SDK**
  49. ******************************************************************************/
  50. ///> dp data list, this will be generated by cloud platform
  51. #if (defined ZIGBEE_ZTU_T3_SW) && (defined ZIGBEE_3SWITCH_SW)
  52. //#ifdef ZIGBEE_ZTU_T3_SW
  53. const DOWNLOAD_CMD_S download_cmd[] =
  54. {
  55. {DPID_SWITCH_1, DP_TYPE_BOOL},
  56. {DPID_SWITCH_2, DP_TYPE_BOOL},
  57. {DPID_SWITCH_3, DP_TYPE_BOOL},
  58. {DPID_RELAY_STATUS, DP_TYPE_ENUM},
  59. {DPID_SWITCH_INCHING, DP_TYPE_STRING},
  60. {DPID_ADD_ELE, DP_TYPE_VALUE},
  61. {DPID_CUR_CURRENT, DP_TYPE_VALUE},
  62. {DPID_CUR_POWER, DP_TYPE_VALUE},
  63. {DPID_CUR_VOLTAGE, DP_TYPE_VALUE},
  64. {DPID_RELAY_STATUS_1, DP_TYPE_ENUM},
  65. {DPID_RELAY_STATUS_2, DP_TYPE_ENUM},
  66. {DPID_RELAY_STATUS_3, DP_TYPE_ENUM},
  67. {DPID_LIGHT_LEVEL, DP_TYPE_ENUM},
  68. {DPID_CUR_CURRENT_2, DP_TYPE_VALUE},
  69. {DPID_CUR_POWER_2, DP_TYPE_VALUE},
  70. {DPID_ADD_ELE_2, DP_TYPE_VALUE},
  71. {DPID_CUR_CURRENT_3, DP_TYPE_VALUE},
  72. {DPID_CUR_POWER_3, DP_TYPE_VALUE},
  73. {DPID_ADD_ELE_3, DP_TYPE_VALUE},
  74. };
  75. #endif
  76. #ifdef ZIGBEE_ZTU_T2_SW
  77. const DOWNLOAD_CMD_S download_cmd[] =
  78. {
  79. {DPID_SWITCH_1, DP_TYPE_BOOL},
  80. {DPID_SWITCH_2, DP_TYPE_BOOL},
  81. {DPID_RELAY_STATUS, DP_TYPE_ENUM},
  82. {DPID_SWITCH_INCHING, DP_TYPE_STRING},
  83. {DPID_ADD_ELE, DP_TYPE_VALUE},
  84. {DPID_CUR_CURRENT, DP_TYPE_VALUE},
  85. {DPID_CUR_POWER, DP_TYPE_VALUE},
  86. {DPID_CUR_VOLTAGE, DP_TYPE_VALUE},
  87. {DPID_RELAY_STATUS_1, DP_TYPE_ENUM},
  88. {DPID_RELAY_STATUS_2, DP_TYPE_ENUM},
  89. {DPID_LIGHT_LEVEL, DP_TYPE_ENUM},
  90. {DPID_CUR_CURRENT_2, DP_TYPE_VALUE},
  91. {DPID_CUR_POWER_2, DP_TYPE_VALUE},
  92. {DPID_ADD_ELE_2, DP_TYPE_VALUE},
  93. };
  94. #endif
  95. #ifdef ZIGBEE_ZTU_T1_SW
  96. const DOWNLOAD_CMD_S download_cmd[] =
  97. {
  98. {DPID_SWITCH_1, DP_TYPE_BOOL},
  99. {DPID_RELAY_STATUS, DP_TYPE_ENUM},
  100. {DPID_SWITCH_INCHING, DP_TYPE_STRING},
  101. {DPID_ADD_ELE, DP_TYPE_VALUE},
  102. {DPID_CUR_CURRENT, DP_TYPE_VALUE},
  103. {DPID_CUR_POWER, DP_TYPE_VALUE},
  104. {DPID_CUR_VOLTAGE, DP_TYPE_VALUE},
  105. {DPID_RELAY_STATUS_1, DP_TYPE_ENUM},
  106. {DPID_RELAY_STATUS_2, DP_TYPE_ENUM},
  107. {DPID_RELAY_STATUS_3, DP_TYPE_ENUM},
  108. {DPID_LIGHT_LEVEL, DP_TYPE_ENUM},
  109. };
  110. #endif
  111. #ifdef ZIGBEE_ZTU_T6_SCENCE_SW
  112. const DOWNLOAD_CMD_S download_cmd[] =
  113. {
  114. {DPID_SCENE_1, DP_TYPE_ENUM},
  115. {DPID_SCENE_2, DP_TYPE_ENUM},
  116. {DPID_SCENE_3, DP_TYPE_ENUM},
  117. {DPID_SCENE_4, DP_TYPE_ENUM},
  118. {DPID_SCENE_5, DP_TYPE_ENUM},
  119. {DPID_SCENE_6, DP_TYPE_ENUM},
  120. {DPID_MODE_1, DP_TYPE_ENUM},
  121. {DPID_MODE_2, DP_TYPE_ENUM},
  122. {DPID_MODE_3, DP_TYPE_ENUM},
  123. {DPID_SWITCH_1, DP_TYPE_BOOL},
  124. {DPID_SWITCH_2, DP_TYPE_BOOL},
  125. {DPID_SWITCH_3, DP_TYPE_BOOL},
  126. {DPID_LIGHT_LEVEL, DP_TYPE_ENUM},
  127. {DPID_RELAY_STATUS, DP_TYPE_ENUM},
  128. {DPID_RELAY_STATUS_1, DP_TYPE_ENUM},
  129. {DPID_RELAY_STATUS_2, DP_TYPE_ENUM},
  130. {DPID_RELAY_STATUS_3, DP_TYPE_ENUM},
  131. {DPID_SWITCH_INCHING, DP_TYPE_STRING},
  132. {DPID_ADD_ELE, DP_TYPE_VALUE},
  133. {DPID_CUR_VOLTAGE, DP_TYPE_VALUE},
  134. {DPID_CUR_POWER, DP_TYPE_VALUE},
  135. {DPID_CUR_CURRENT, DP_TYPE_VALUE},
  136. {DPID_ADD_ELE_2, DP_TYPE_VALUE},
  137. {DPID_CUR_CURRENT_2, DP_TYPE_VALUE},
  138. {DPID_CUR_POWER_2, DP_TYPE_VALUE},
  139. {DPID_ADD_ELE_3, DP_TYPE_VALUE},
  140. {DPID_CUR_CURRENT_3, DP_TYPE_VALUE},
  141. {DPID_CUR_POWER_3, DP_TYPE_VALUE},
  142. };
  143. #endif
  144. /******************************************************************************
  145. 2:串口单字节发送函数
  146. 请将MCU串口发送函数填入该函数内,并将接收到的数据作为参数传入串口发送函数
  147. ******************************************************************************/
  148. static void report_mcu_ota_result(unsigned char res);
  149. /**
  150. * @brief encapsulates a generic send function, developer should use their own function to completing this fuction
  151. * @param[in] {value} send signle data
  152. * @return void
  153. */
  154. ////must modify
  155. void uart_transmit_output(unsigned char value)
  156. {
  157. // static unsigned char buf;
  158. // buf = value;
  159. // #error "please use your own uart send fuction complete this fuction, exmaple"
  160. /*
  161. * //demo:
  162. * extern void Uart_PutChar(unsigned char value);
  163. * Uart_PutChar(value);
  164. */
  165. UART0_send(value);
  166. }
  167. /******************************************************************************
  168. 第二步:实现具体用户函数
  169. 1:APP下发数据处理
  170. 2:数据上报处理
  171. ******************************************************************************/
  172. /******************************************************************************
  173. 1:所有数据上报处理
  174. 当前函数处理全部数据上报(包括可下发/可上报和只上报)
  175. 需要用户按照实际情况实现:
  176. 1:需要实现可下发/可上报数据点上报
  177. 2:需要实现只上报数据点上报
  178. 此函数为MCU内部必须调用
  179. 用户也可调用此函数实现全部数据上报
  180. ******************************************************************************/
  181. // 自动化生成数据上报函数
  182. /**
  183. * @brief Upload all dp information of the system, and realize the synchronization of APP and muc data
  184. * @param[in] {void}
  185. * @return void
  186. */
  187. #ifdef ZIGBEE_ZTU_T1_SW
  188. // #ifdef ZIGBEE_ZTU_T3_SW
  189. void all_data_update(void)
  190. {
  191. // #error "mcu must realize function internal function"
  192. /*
  193. * these fucntion will be generated by cloud platform, but when use these function must reference the function in mcu_api.c
  194. */
  195. u08 i = 0;
  196. mcu_dp_bool_update(DPID_SWITCH_2, switchState.SWITCH[1]); // BOOL型数据上报;
  197. // mcu_dp_bool_update(DPID_SWITCH_1, switchState.SWITCH[0]); // BOOL型数据上报;
  198. // mcu_dp_bool_update(DPID_BACKLIGHT_SWITCH, switchState.human); // BOOL型数据上报;
  199. mcu_dp_enum_update(DPID_RELAY_STATUS_1, switchState.relay_status[0]); // 枚举型数据上报;
  200. // mcu_dp_enum_update(DPID_RELAY_STATUS_2, switchState.relay_status[1]); // 枚举型数据上报;
  201. // mcu_dp_enum_update(DPID_LIGHT_MODE, switchState.led_level); // 枚举型数据上报;
  202. mcu_dp_enum_update(DPID_RELAY_STATUS, switchState.relay_allstatus); // 枚举型数据上报;
  203. /*
  204. mcu_dp_string_update(DPID_SWITCH_INCHING,当前点动开关(延时关)指针,当前点动开关(延时关)数据长度); //STRING型数据上报;
  205. */
  206. for (i = 0; i < 3; i++)
  207. {
  208. hex_data[i * 3] = 0xff;
  209. hex_data[i * 3 + 1] = 0xff;
  210. hex_data[i * 3 + 2] = 0xff;
  211. }
  212. hex_data[0 * 3] = switchState.plus_mod[1];
  213. hex_data[0 * 3 + 1] = (u08)((switchState.plus_auto_time[1] / 10) >> 8);
  214. hex_data[0 * 3 + 2] = (u08)((switchState.plus_auto_time[1] / 10) & 0x00ff); // 实际2号键做1号开关用
  215. HexToDisHex(string_H16_data, hex_data, 9); // 转回16进制字符串
  216. // mcu_dp_string_update(DPID_SWITCH_INCHING, string_H16_data, 18); // 点动开关(延时关)STRING型数据上报;
  217. }
  218. #endif
  219. #ifdef ZIGBEE_ZTU_T2_SW
  220. // #ifdef ZIGBEE_ZTU_T3_SW
  221. void all_data_update(void)
  222. {
  223. // #error "mcu must realize function internal function"
  224. /*
  225. * these fucntion will be generated by cloud platform, but when use these function must reference the function in mcu_api.c
  226. */
  227. u08 i = 0;
  228. mcu_dp_bool_update(DPID_SWITCH_3, switchState.SWITCH[0]); // BOOL型数据上报;
  229. //mcu_dp_bool_update(DPID_SWITCH_2, switchState.SWITCH[1]); // BOOL型数据上报;
  230. mcu_dp_bool_update(DPID_SWITCH_1, switchState.SWITCH[2]); // BOOL型数据上报;
  231. // mcu_dp_bool_update(DPID_BACKLIGHT_SWITCH, switchState.human); // BOOL型数据上报;
  232. mcu_dp_enum_update(DPID_RELAY_STATUS_1, switchState.relay_status[0]); // 枚举型数据上报;
  233. mcu_dp_enum_update(DPID_RELAY_STATUS_2, switchState.relay_status[1]); // 枚举型数据上报;
  234. //mcu_dp_enum_update(DPID_RELAY_STATUS_3, switchState.relay_status[2]); // 枚举型数据上报;
  235. // mcu_dp_enum_update(DPID_LIGHT_MODE, switchState.led_level); // 枚举型数据上报;
  236. mcu_dp_enum_update(DPID_RELAY_STATUS, switchState.relay_allstatus); // 枚举型数据上报;
  237. /*
  238. mcu_dp_string_update(DPID_SWITCH_INCHING,当前点动开关(延时关)指针,当前点动开关(延时关)数据长度); //STRING型数据上报;
  239. */
  240. for (i = 0; i < 3; i++)
  241. {
  242. hex_data[i * 3] = 0xff;
  243. hex_data[i * 3 + 1] = 0xff;
  244. hex_data[i * 3 + 2] = 0xff;
  245. }
  246. hex_data[0 * 3] = switchState.plus_mod[0];
  247. hex_data[0 * 3 + 1] = (u08)((switchState.plus_auto_time[0] / 10) >> 8);
  248. hex_data[0 * 3 + 2] = (u08)((switchState.plus_auto_time[0] / 10) & 0x00ff); // 实际3号键做2号开关用
  249. hex_data[1 * 3] = switchState.plus_mod[2];
  250. hex_data[1 * 3 + 1] = (u08)((switchState.plus_auto_time[2] / 10) >> 8);
  251. hex_data[1 * 3 + 2] = (u08)((switchState.plus_auto_time[2] / 10) & 0x00ff); // 实际3号键做2号开关用
  252. HexToDisHex(string_H16_data, hex_data, 9); // 转回16进制字符串
  253. // mcu_dp_string_update(DPID_SWITCH_INCHING, string_H16_data, 18); // 点动开关(延时关)STRING型数据上报;
  254. }
  255. #endif
  256. #if (defined ZIGBEE_ZTU_T3_SW) && (defined ZIGBEE_3SWITCH_SW)
  257. //#ifdef ZIGBEE_ZTU_T3_SW
  258. void all_data_update(void)
  259. {
  260. // #error "mcu must realize function internal function"
  261. /*
  262. * these fucntion will be generated by cloud platform, but when use these function must reference the function in mcu_api.c
  263. */
  264. u08 i = 0;
  265. mcu_dp_bool_update(DPID_SWITCH_3, switchState.SWITCH[0]); // BOOL型数据上报;
  266. mcu_dp_bool_update(DPID_SWITCH_2, switchState.SWITCH[1]); // BOOL型数据上报;
  267. mcu_dp_bool_update(DPID_SWITCH_1, switchState.SWITCH[2]); // BOOL型数据上报;
  268. // mcu_dp_bool_update(DPID_BACKLIGHT_SWITCH, switchState.human); // BOOL型数据上报;
  269. mcu_dp_enum_update(DPID_RELAY_STATUS_1, switchState.relay_status[0]); // 枚举型数据上报;
  270. mcu_dp_enum_update(DPID_RELAY_STATUS_2, switchState.relay_status[1]); // 枚举型数据上报;
  271. mcu_dp_enum_update(DPID_RELAY_STATUS_3, switchState.relay_status[2]); // 枚举型数据上报;
  272. //mcu_dp_enum_update(DPID_LIGHT_MODE, switchState.led_level); // 枚举型数据上报;
  273. mcu_dp_enum_update(DPID_RELAY_STATUS, switchState.relay_allstatus); // 枚举型数据上报;
  274. /*
  275. mcu_dp_string_update(DPID_SWITCH_INCHING,当前点动开关(延时关)指针,当前点动开关(延时关)数据长度); //STRING型数据上报;
  276. */
  277. for (i = 0; i < 3; i++)
  278. {
  279. hex_data[i * 3] = switchState.plus_mod[i];
  280. hex_data[i * 3 + 1] = (u08)((switchState.plus_auto_time[i] / 10) >> 8);
  281. hex_data[i * 3 + 2] = (u08)((switchState.plus_auto_time[i] / 10) & 0x00ff);
  282. }
  283. HexToDisHex(string_H16_data, hex_data, 9); // 转回16进制字符串
  284. //mcu_dp_string_update(DPID_SWITCH_INCHING, string_H16_data, 18); // 点动开关(延时关)STRING型数据上报;
  285. }
  286. #endif
  287. #ifdef ZIGBEE_ZTU_T6_SCENCE_SW
  288. void all_data_update(void)
  289. {
  290. // #error "mcu must realize function internal function"
  291. /*
  292. * these fucntion will be generated by cloud platform, but when use these function must reference the function in mcu_api.c
  293. */
  294. u08 i = 0;
  295. mcu_dp_enum_update(DPID_RELAY_STATUS_1, switchState.relay_status[0]); // 枚举型数据上报;
  296. mcu_dp_enum_update(DPID_RELAY_STATUS_2, switchState.relay_status[1]); // 枚举型数据上报;
  297. mcu_dp_enum_update(DPID_RELAY_STATUS_3, switchState.relay_status[2]); // 枚举型数据上报;
  298. // mcu_dp_enum_update(DPID_LIGHT_MODE, switchState.led_level); // 枚举型数据上报;
  299. mcu_dp_enum_update(DPID_RELAY_STATUS, switchState.relay_allstatus); // 枚举型数据上报;
  300. mcu_dp_enum_update(DPID_MODE_1, switchState.mod[0]); // 枚举型数据上报;
  301. mcu_dp_enum_update(DPID_MODE_2, switchState.mod[1]); // 枚举型数据上报;
  302. mcu_dp_enum_update(DPID_MODE_3, switchState.mod[2]); // 枚举型数据上报;
  303. if (switchState.mod[2] == 0)
  304. mcu_dp_bool_update(DPID_SWITCH_3, switchState.SWITCH[0]); // BOOL型数据上报;
  305. if (switchState.mod[1] == 0)
  306. mcu_dp_bool_update(DPID_SWITCH_2, switchState.SWITCH[1]); // BOOL型数据上报;
  307. if (switchState.mod[0] == 0)
  308. mcu_dp_bool_update(DPID_SWITCH_1, switchState.SWITCH[2]); // BOOL型数据上报;
  309. // 场景不需要主动上报,APP不需要查询状态
  310. /*
  311. mcu_dp_enum_update(DPID_SCENE_1,当前场景1); //枚举型数据上报;
  312. mcu_dp_enum_update(DPID_SCENE_2,当前场景2); //枚举型数据上报;
  313. mcu_dp_enum_update(DPID_SCENE_3,当前场景3); //枚举型数据上报;
  314. mcu_dp_enum_update(DPID_SCENE_4,当前场景4); //枚举型数据上报;
  315. mcu_dp_enum_update(DPID_SCENE_5,当前场景5); //枚举型数据上报;
  316. mcu_dp_enum_update(DPID_SCENE_6,当前场景6); //枚举型数据上报;
  317. */
  318. /*
  319. mcu_dp_string_update(DPID_SWITCH_INCHING,当前点动开关(延时关)指针,当前点动开关(延时关)数据长度); //STRING型数据上报;
  320. */
  321. // switchState.plus_mod[0] = 1;
  322. // switchState.plus_auto_time[0] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  323. for (i = 0; i < 3; i++)
  324. {
  325. hex_data[i * 3] = switchState.plus_mod[i];
  326. hex_data[i * 3 + 1] = (u08)((switchState.plus_auto_time[i] / 10) >> 8);
  327. hex_data[i * 3 + 2] = (u08)((switchState.plus_auto_time[i] / 10) & 0x00ff);
  328. }
  329. HexToDisHex(string_H16_data, hex_data, 9); // 转回16进制字符串
  330. // mcu_dp_string_update(DPID_SWITCH_INCHING, string_H16_data, 18); // 点动开关(延时关)STRING型数据上报;
  331. }
  332. #endif
  333. void all_power_data_update(void) //电量数据上报函数
  334. {
  335. char i;
  336. //test
  337. // switchState.dp_add_ele = 100*100;//100 kW·h
  338. // switchState.dp_cur_current = 1000;//1000mA
  339. // switchState.dp_cur_power = 330*10;//330w
  340. // switchState.dp_cur_voltage = 220*10;//220v
  341. #ifdef ZIGBEE_ZTU_T1_SW
  342. // if((switchState.dp_add_ele[0] !=0)&&((switchState.dp_add_ele[0] - data_dp_add_ele[0])>=1))
  343. // {
  344. mcu_dp_value_update(DPID_ADD_ELE,switchState.dp_add_ele[0]); //VALUE型数据上报;
  345. if(data_dp_add_ele[0] != switchState.dp_add_ele[0])
  346. {
  347. Save_data_ele_flag = 1;
  348. }
  349. data_dp_add_ele[0] = switchState.dp_add_ele[0];
  350. // }
  351. // if((switchState.dp_cur_current[0] != 0)&&(switchState.dp_cur_current[0] != data_dp_cur_current[0])&&(switchState.dp_cur_current[0]<100000))
  352. // {
  353. // data_dp_cur_current[0] = switchState.dp_cur_current[0];
  354. mcu_dp_value_update(DPID_CUR_CURRENT,switchState.dp_cur_current[0]); //VALUE型数据上报;
  355. // }
  356. // if((switchState.dp_cur_power[0] != 0)&&(switchState.dp_cur_power[0] != data_dp_cur_power[0])&&(switchState.dp_cur_power[0]<22000))
  357. // {
  358. // data_dp_cur_power[0] = switchState.dp_cur_power[0];
  359. mcu_dp_value_update(DPID_CUR_POWER,switchState.dp_cur_power[0]); //VALUE型数据上报;
  360. // }
  361. if((switchState.dp_cur_voltage != 0)&&(switchState.dp_cur_voltage != data_dp_cur_voltage)&&(switchState.dp_cur_voltage<2500))
  362. {
  363. data_dp_cur_voltage = switchState.dp_cur_voltage;
  364. mcu_dp_value_update(DPID_CUR_VOLTAGE,switchState.dp_cur_voltage); //VALUE型数据上报;
  365. }
  366. #endif
  367. #ifdef ZIGBEE_ZTU_T2_SW
  368. //第一路数据
  369. // if((switchState.dp_add_ele[0] !=0)&&((switchState.dp_add_ele[0] - data_dp_add_ele[0])>=1))
  370. // {
  371. mcu_dp_value_update(DPID_ADD_ELE,switchState.dp_add_ele[0]); //VALUE型数据上报;
  372. if(data_dp_add_ele[0] != switchState.dp_add_ele[0])
  373. {
  374. Save_data_ele_flag = 1;
  375. }
  376. data_dp_add_ele[0] = switchState.dp_add_ele[0];
  377. // }
  378. // if((switchState.dp_cur_current[0] != 0)&&(switchState.dp_cur_current[0] != data_dp_cur_current[0])&&(switchState.dp_cur_current[0]<100000))
  379. // {
  380. // data_dp_cur_current[0] = switchState.dp_cur_current[0];
  381. mcu_dp_value_update(DPID_CUR_CURRENT,switchState.dp_cur_current[0]); //VALUE型数据上报;
  382. // }
  383. // if((switchState.dp_cur_power[0] != 0)&&(switchState.dp_cur_power[0] != data_dp_cur_power[0])&&(switchState.dp_cur_power[0]<22000))
  384. // {
  385. // data_dp_cur_power[0] = switchState.dp_cur_power[0];
  386. mcu_dp_value_update(DPID_CUR_POWER,switchState.dp_cur_power[0]); //VALUE型数据上报;
  387. // }
  388. if((switchState.dp_cur_voltage != 0)&&(switchState.dp_cur_voltage != data_dp_cur_voltage)&&(switchState.dp_cur_voltage<2500))
  389. {
  390. data_dp_cur_voltage = switchState.dp_cur_voltage;
  391. mcu_dp_value_update(DPID_CUR_VOLTAGE,switchState.dp_cur_voltage); //VALUE型数据上报;
  392. }
  393. //第二路数据
  394. // if((switchState.dp_add_ele[1] !=0)&&((switchState.dp_add_ele[1] - data_dp_add_ele[1])>=1))
  395. // {
  396. mcu_dp_value_update(DPID_ADD_ELE_2,switchState.dp_add_ele[1]); //VALUE型数据上报;
  397. if(data_dp_add_ele[1] != switchState.dp_add_ele[1])
  398. {
  399. Save_data_ele_flag = 1;
  400. }
  401. data_dp_add_ele[1] = switchState.dp_add_ele[1];
  402. // }
  403. // if((switchState.dp_cur_current[1] != 0)&&(switchState.dp_cur_current[1] != data_dp_cur_current[1])&&(switchState.dp_cur_current[1]<100000))
  404. // {
  405. // data_dp_cur_current[1] = switchState.dp_cur_current[1];
  406. mcu_dp_value_update(DPID_CUR_CURRENT_2,switchState.dp_cur_current[1]); //VALUE型数据上报;
  407. // }
  408. // if((switchState.dp_cur_power[1] != 0)&&(switchState.dp_cur_power[1] != data_dp_cur_power[1])&&(switchState.dp_cur_power[1]<22000))
  409. // {
  410. // data_dp_cur_power[1] = switchState.dp_cur_power[1];
  411. mcu_dp_value_update(DPID_CUR_POWER_2,switchState.dp_cur_power[1]); //VALUE型数据上报;
  412. // }
  413. #endif
  414. #ifdef ZIGBEE_ZTU_T3_SW
  415. //第一路数据
  416. // if((switchState.dp_add_ele[0] !=0)&&((switchState.dp_add_ele[0] - data_dp_add_ele[0])>=1))
  417. // {
  418. mcu_dp_value_update(DPID_ADD_ELE,switchState.dp_add_ele[0]); //VALUE型数据上报;
  419. if(data_dp_add_ele[0] != switchState.dp_add_ele[0])
  420. {
  421. Save_data_ele_flag = 1;
  422. }
  423. data_dp_add_ele[0] = switchState.dp_add_ele[0];
  424. // }
  425. // if((switchState.dp_cur_current[0] != 0)&&(switchState.dp_cur_current[0] != data_dp_cur_current[0])&&(switchState.dp_cur_current[0]<100000))
  426. // {
  427. // data_dp_cur_current[0] = switchState.dp_cur_current[0];
  428. mcu_dp_value_update(DPID_CUR_CURRENT,switchState.dp_cur_current[0]); //VALUE型数据上报;
  429. // }
  430. // if((switchState.dp_cur_power[0] != 0)&&(switchState.dp_cur_power[0] != data_dp_cur_power[0])&&(switchState.dp_cur_power[0]<22000))
  431. // {
  432. // data_dp_cur_power[0] = switchState.dp_cur_power[0];
  433. mcu_dp_value_update(DPID_CUR_POWER,switchState.dp_cur_power[0]); //VALUE型数据上报;
  434. // }
  435. if((switchState.dp_cur_voltage != 0)&&(switchState.dp_cur_voltage != data_dp_cur_voltage)&&(switchState.dp_cur_voltage<2500))
  436. {
  437. data_dp_cur_voltage = switchState.dp_cur_voltage;
  438. mcu_dp_value_update(DPID_CUR_VOLTAGE,switchState.dp_cur_voltage); //VALUE型数据上报;
  439. }
  440. //第二路数据
  441. // if((switchState.dp_add_ele[1] !=0)&&((switchState.dp_add_ele[1] - data_dp_add_ele[1])>=1))
  442. // {
  443. mcu_dp_value_update(DPID_ADD_ELE_2,switchState.dp_add_ele[1]); //VALUE型数据上报;
  444. if(data_dp_add_ele[1] != switchState.dp_add_ele[1])
  445. {
  446. Save_data_ele_flag = 1;
  447. }
  448. data_dp_add_ele[1] = switchState.dp_add_ele[1];
  449. // }
  450. // if((switchState.dp_cur_current[1] != 0)&&(switchState.dp_cur_current[1] != data_dp_cur_current[1])&&(switchState.dp_cur_current[1]<100000))
  451. // {
  452. // data_dp_cur_current[1] = switchState.dp_cur_current[1];
  453. mcu_dp_value_update(DPID_CUR_CURRENT_2,switchState.dp_cur_current[1]); //VALUE型数据上报;
  454. // }
  455. // if((switchState.dp_cur_power[1] != 0)&&(switchState.dp_cur_power[1] != data_dp_cur_power[1])&&(switchState.dp_cur_power[1]<22000))
  456. // {
  457. // data_dp_cur_power[1] = switchState.dp_cur_power[1];
  458. mcu_dp_value_update(DPID_CUR_POWER_2,switchState.dp_cur_power[1]); //VALUE型数据上报;
  459. // }
  460. //第三路数据
  461. // if((switchState.dp_add_ele[2] !=0)&&((switchState.dp_add_ele[2] - data_dp_add_ele[2])>=1))
  462. // {
  463. mcu_dp_value_update(DPID_ADD_ELE_3,switchState.dp_add_ele[2]); //VALUE型数据上报;
  464. if(data_dp_add_ele[2] != switchState.dp_add_ele[2])
  465. {
  466. Save_data_ele_flag = 1;
  467. }
  468. data_dp_add_ele[2] = switchState.dp_add_ele[2];
  469. // }
  470. // if((switchState.dp_cur_current[2] != 0)&&(switchState.dp_cur_current[2] != data_dp_cur_current[2])&&(switchState.dp_cur_current[2]<100000))
  471. // {
  472. // data_dp_cur_current[2] = switchState.dp_cur_current[2];
  473. mcu_dp_value_update(DPID_CUR_CURRENT_3,switchState.dp_cur_current[2]); //VALUE型数据上报;
  474. // }
  475. // if((switchState.dp_cur_power[2] != 0)&&(switchState.dp_cur_power[2] != data_dp_cur_power[2])&&(switchState.dp_cur_power[2]<22000))
  476. // {
  477. // data_dp_cur_power[2] = switchState.dp_cur_power[2];
  478. mcu_dp_value_update(DPID_CUR_POWER_3,switchState.dp_cur_power[2]); //VALUE型数据上报;
  479. // }
  480. #endif
  481. }
  482. /******************************************************************************
  483. WARNING!!!
  484. 2:所有数据上报处理
  485. 自动化代码模板函数,具体请用户自行实现数据处理
  486. ******************************************************************************/
  487. ///> this will realize by cloud platform
  488. #ifdef ZIGBEE_ZTU_T6_SCENCE_SW
  489. /*****************************************************************************
  490. 函数名称 : dp_download_scene_1_handle
  491. 功能描述 : 针对DPID_SCENE_1的处理函数
  492. 输入参数 : value:数据源数据
  493. : length:数据长度
  494. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  495. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  496. *****************************************************************************/
  497. static unsigned char dp_download_scene_1_handle(const unsigned char value[], unsigned short length)
  498. {
  499. // 示例:当前DP类型为ENUM
  500. unsigned char ret;
  501. unsigned char scene_1;
  502. scene_1 = mcu_get_dp_download_enum(value, length);
  503. switch (scene_1)
  504. {
  505. case 0:
  506. break;
  507. default:
  508. break;
  509. }
  510. // There should be a report after processing the DP
  511. ret = mcu_dp_enum_update(DPID_SCENE_1, scene_1);
  512. if (ret == SUCCESS)
  513. return SUCCESS;
  514. else
  515. return ERROR;
  516. }
  517. /*****************************************************************************
  518. 函数名称 : dp_download_scene_2_handle
  519. 功能描述 : 针对DPID_SCENE_2的处理函数
  520. 输入参数 : value:数据源数据
  521. : length:数据长度
  522. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  523. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  524. *****************************************************************************/
  525. static unsigned char dp_download_scene_2_handle(const unsigned char value[], unsigned short length)
  526. {
  527. // 示例:当前DP类型为ENUM
  528. unsigned char ret;
  529. unsigned char scene_2;
  530. scene_2 = mcu_get_dp_download_enum(value, length);
  531. switch (scene_2)
  532. {
  533. case 0:
  534. break;
  535. default:
  536. break;
  537. }
  538. // There should be a report after processing the DP
  539. ret = mcu_dp_enum_update(DPID_SCENE_2, scene_2);
  540. if (ret == SUCCESS)
  541. return SUCCESS;
  542. else
  543. return ERROR;
  544. }
  545. /*****************************************************************************
  546. 函数名称 : dp_download_scene_3_handle
  547. 功能描述 : 针对DPID_SCENE_3的处理函数
  548. 输入参数 : value:数据源数据
  549. : length:数据长度
  550. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  551. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  552. *****************************************************************************/
  553. static unsigned char dp_download_scene_3_handle(const unsigned char value[], unsigned short length)
  554. {
  555. // 示例:当前DP类型为ENUM
  556. unsigned char ret;
  557. unsigned char scene_3;
  558. scene_3 = mcu_get_dp_download_enum(value, length);
  559. switch (scene_3)
  560. {
  561. case 0:
  562. break;
  563. default:
  564. break;
  565. }
  566. // There should be a report after processing the DP
  567. ret = mcu_dp_enum_update(DPID_SCENE_3, scene_3);
  568. if (ret == SUCCESS)
  569. return SUCCESS;
  570. else
  571. return ERROR;
  572. }
  573. /*****************************************************************************
  574. 函数名称 : dp_download_scene_4_handle
  575. 功能描述 : 针对DPID_SCENE_4的处理函数
  576. 输入参数 : value:数据源数据
  577. : length:数据长度
  578. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  579. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  580. *****************************************************************************/
  581. static unsigned char dp_download_scene_4_handle(const unsigned char value[], unsigned short length)
  582. {
  583. // 示例:当前DP类型为ENUM
  584. unsigned char ret;
  585. unsigned char scene_4;
  586. scene_4 = mcu_get_dp_download_enum(value, length);
  587. switch (scene_4)
  588. {
  589. case 0:
  590. break;
  591. default:
  592. break;
  593. }
  594. // There should be a report after processing the DP
  595. ret = mcu_dp_enum_update(DPID_SCENE_4, scene_4);
  596. if (ret == SUCCESS)
  597. return SUCCESS;
  598. else
  599. return ERROR;
  600. }
  601. /*****************************************************************************
  602. 函数名称 : dp_download_scene_5_handle
  603. 功能描述 : 针对DPID_SCENE_5的处理函数
  604. 输入参数 : value:数据源数据
  605. : length:数据长度
  606. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  607. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  608. *****************************************************************************/
  609. static unsigned char dp_download_scene_5_handle(const unsigned char value[], unsigned short length)
  610. {
  611. // 示例:当前DP类型为ENUM
  612. unsigned char ret;
  613. unsigned char scene_5;
  614. scene_5 = mcu_get_dp_download_enum(value, length);
  615. switch (scene_5)
  616. {
  617. case 0:
  618. break;
  619. default:
  620. break;
  621. }
  622. // There should be a report after processing the DP
  623. ret = mcu_dp_enum_update(DPID_SCENE_5, scene_5);
  624. if (ret == SUCCESS)
  625. return SUCCESS;
  626. else
  627. return ERROR;
  628. }
  629. /*****************************************************************************
  630. 函数名称 : dp_download_scene_6_handle
  631. 功能描述 : 针对DPID_SCENE_6的处理函数
  632. 输入参数 : value:数据源数据
  633. : length:数据长度
  634. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  635. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  636. *****************************************************************************/
  637. static unsigned char dp_download_scene_6_handle(const unsigned char value[], unsigned short length)
  638. {
  639. // 示例:当前DP类型为ENUM
  640. unsigned char ret;
  641. unsigned char scene_6;
  642. scene_6 = mcu_get_dp_download_enum(value, length);
  643. switch (scene_6)
  644. {
  645. case 0:
  646. break;
  647. default:
  648. break;
  649. }
  650. // There should be a report after processing the DP
  651. ret = mcu_dp_enum_update(DPID_SCENE_6, scene_6);
  652. if (ret == SUCCESS)
  653. return SUCCESS;
  654. else
  655. return ERROR;
  656. }
  657. /*****************************************************************************
  658. 函数名称 : dp_download_mode_1_handle
  659. 功能描述 : 针对DPID_MODE_1的处理函数
  660. 输入参数 : value:数据源数据
  661. : length:数据长度
  662. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  663. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  664. *****************************************************************************/
  665. static unsigned char dp_download_mode_1_handle(const unsigned char value[], unsigned short length)
  666. {
  667. // 示例:当前DP类型为ENUM
  668. unsigned char ret;
  669. unsigned char mode_1;
  670. mode_1 = mcu_get_dp_download_enum(value, length);
  671. switch (mode_1)
  672. {
  673. case 0:
  674. break;
  675. case 1:
  676. break;
  677. default:
  678. break;
  679. }
  680. // add by zzw 20240304
  681. switchState.mod[0] = mode_1; // 开关、场景设置
  682. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  683. write_mileage[6] = switchState.mod[0];
  684. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  685. // add by zzw 20240304
  686. // add by zzw 20240312 增加eeprom参数配置区
  687. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  688. write_mileage_backup[6] = switchState.mod[0];
  689. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  690. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  691. if (read_mileage_backup[6] != switchState.mod[0]) // 再次读取不相等,则再次写入
  692. {
  693. read_mileage_backup[6] = switchState.mod[0];
  694. iap_eeprom_write_backup(0, read_mileage_backup, 30); // 写入1字节
  695. }
  696. // add by zzw 20240312 增加eeprom参数配置区
  697. // There should be a report after processing the DP
  698. ret = mcu_dp_enum_update(DPID_MODE_1, mode_1);
  699. if (ret == SUCCESS)
  700. return SUCCESS;
  701. else
  702. return ERROR;
  703. }
  704. /*****************************************************************************
  705. 函数名称 : dp_download_mode_2_handle
  706. 功能描述 : 针对DPID_MODE_2的处理函数
  707. 输入参数 : value:数据源数据
  708. : length:数据长度
  709. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  710. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  711. *****************************************************************************/
  712. static unsigned char dp_download_mode_2_handle(const unsigned char value[], unsigned short length)
  713. {
  714. // 示例:当前DP类型为ENUM
  715. unsigned char ret;
  716. unsigned char mode_2;
  717. mode_2 = mcu_get_dp_download_enum(value, length);
  718. switch (mode_2)
  719. {
  720. case 0:
  721. break;
  722. case 1:
  723. break;
  724. default:
  725. break;
  726. }
  727. // add by zzw 20240304
  728. switchState.mod[1] = mode_2; // 开关、场景设置
  729. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  730. write_mileage[7] = switchState.mod[1];
  731. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  732. // add by zzw 20240304
  733. // add by zzw 20240312 增加eeprom参数配置区
  734. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  735. write_mileage_backup[7] = switchState.mod[1];
  736. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  737. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  738. if (read_mileage_backup[7] != switchState.mod[1]) // 再次读取不相等,则再次写入
  739. {
  740. read_mileage_backup[7] = switchState.mod[1];
  741. iap_eeprom_write_backup(0, read_mileage_backup, 30); // 写入1字节
  742. }
  743. // add by zzw 20240312 增加eeprom参数配置区
  744. // There should be a report after processing the DP
  745. ret = mcu_dp_enum_update(DPID_MODE_2, mode_2);
  746. if (ret == SUCCESS)
  747. return SUCCESS;
  748. else
  749. return ERROR;
  750. }
  751. /*****************************************************************************
  752. 函数名称 : dp_download_mode_3_handle
  753. 功能描述 : 针对DPID_MODE_3的处理函数
  754. 输入参数 : value:数据源数据
  755. : length:数据长度
  756. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  757. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  758. *****************************************************************************/
  759. static unsigned char dp_download_mode_3_handle(const unsigned char value[], unsigned short length)
  760. {
  761. // 示例:当前DP类型为ENUM
  762. unsigned char ret;
  763. unsigned char mode_3;
  764. mode_3 = mcu_get_dp_download_enum(value, length);
  765. switch (mode_3)
  766. {
  767. case 0:
  768. break;
  769. case 1:
  770. break;
  771. default:
  772. break;
  773. }
  774. // add by zzw 20240304
  775. switchState.mod[2] = mode_3; // 开关、场景设置
  776. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  777. write_mileage[8] = switchState.mod[2];
  778. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  779. // add by zzw 20240304
  780. // add by zzw 20240312 增加eeprom参数配置区
  781. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  782. write_mileage_backup[8] = switchState.mod[2];
  783. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  784. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  785. if (read_mileage_backup[8] != switchState.mod[2]) // 再次读取不相等,则再次写入
  786. {
  787. read_mileage_backup[8] = switchState.mod[2];
  788. iap_eeprom_write_backup(0, read_mileage_backup, 30); // 写入1字节
  789. }
  790. // add by zzw 20240312 增加eeprom参数配置区
  791. // There should be a report after processing the DP
  792. ret = mcu_dp_enum_update(DPID_MODE_3, mode_3);
  793. if (ret == SUCCESS)
  794. return SUCCESS;
  795. else
  796. return ERROR;
  797. }
  798. #endif
  799. /*****************************************************************************
  800. 函数名称 : dp_download_switch_1_handle
  801. 功能描述 : 针对DPID_SWITCH_1的处理函数
  802. 输入参数 : value:数据源数据
  803. : length:数据长度
  804. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  805. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  806. *****************************************************************************/
  807. static unsigned char dp_download_switch_1_handle(const unsigned char value[], unsigned short length)
  808. {
  809. // 示例:当前DP类型为BOOL
  810. unsigned char ret;
  811. // 0:off/1:on
  812. unsigned char switch_1;
  813. switch_1 = mcu_get_dp_download_bool(value, length);
  814. if (switch_1 == 0)
  815. {
  816. // bool off
  817. gRelayOnOff &= (~0x01);
  818. gLedState = gLedState & (~0x01); // 按键1清除
  819. }
  820. else
  821. {
  822. // bool on
  823. gRelayOnOff |= (0x01);
  824. gLedState = gLedState | 0x01; // 按键1设置
  825. if (appControlLedEnable) // add by zzw 开灯点亮按键背光10秒
  826. {
  827. gRadarKeepTimer = 100; // 10s
  828. }
  829. if (switchState.plus_mod[0] == 0x01) // 点动开启
  830. {
  831. switchState.plus_en[0] = 0x01;
  832. switchState.plus_counter[0] = switchState.plus_auto_time[0];
  833. // write_mileage[0] = switchState.plus_en;
  834. // iap_eeprom_write(14, write_mileage, 1); // 写入1字节
  835. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  836. write_mileage[14] = switchState.plus_en[0];
  837. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  838. }
  839. }
  840. // There should be a report after processing the DP
  841. ret = mcu_dp_bool_update(DPID_SWITCH_3, switch_1);
  842. if (ret == SUCCESS)
  843. return SUCCESS;
  844. else
  845. return ERROR;
  846. }
  847. /*****************************************************************************
  848. 函数名称 : dp_download_switch_2_handle
  849. 功能描述 : 针对DPID_SWITCH_2的处理函数
  850. 输入参数 : value:数据源数据
  851. : length:数据长度
  852. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  853. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  854. *****************************************************************************/
  855. static unsigned char dp_download_switch_2_handle(const unsigned char value[], unsigned short length)
  856. {
  857. // 示例:当前DP类型为BOOL
  858. unsigned char ret;
  859. // 0:off/1:on
  860. unsigned char switch_2;
  861. switch_2 = mcu_get_dp_download_bool(value, length);
  862. if (switch_2 == 0)
  863. {
  864. // bool off
  865. gRelayOnOff &= (~0x02);
  866. gLedState = gLedState & (~0x02); // 按键1清除
  867. }
  868. else
  869. {
  870. // bool on
  871. gRelayOnOff |= (0x02);
  872. gLedState = gLedState | 0x02; // 按键2设置
  873. if (appControlLedEnable) // add by zzw 开灯点亮按键背光10秒
  874. {
  875. gRadarKeepTimer = 100; // 10s
  876. }
  877. if (switchState.plus_mod[1] == 0x01) // 点动开启
  878. {
  879. switchState.plus_en[1] = 0x01;
  880. switchState.plus_counter[1] = switchState.plus_auto_time[1];
  881. // write_mileage[1] = switchState.plus_en;
  882. // iap_eeprom_write(15, write_mileage, 1); // 写入1字节
  883. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  884. write_mileage[15] = switchState.plus_en[1];
  885. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  886. }
  887. }
  888. // There should be a report after processing the DP
  889. ret = mcu_dp_bool_update(DPID_SWITCH_2, switch_2);
  890. if (ret == SUCCESS)
  891. return SUCCESS;
  892. else
  893. return ERROR;
  894. }
  895. /*****************************************************************************
  896. 函数名称 : dp_download_switch_3_handle
  897. 功能描述 : 针对DPID_SWITCH_3的处理函数
  898. 输入参数 : value:数据源数据
  899. : length:数据长度
  900. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  901. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  902. *****************************************************************************/
  903. static unsigned char dp_download_switch_3_handle(const unsigned char value[], unsigned short length)
  904. {
  905. // 示例:当前DP类型为BOOL
  906. unsigned char ret;
  907. // 0:off/1:on
  908. unsigned char switch_3;
  909. switch_3 = mcu_get_dp_download_bool(value, length);
  910. if (switch_3 == 0)
  911. {
  912. // bool off
  913. gRelayOnOff &= (~0x04);
  914. gLedState = gLedState & (~0x04); // 按键3清除
  915. }
  916. else
  917. {
  918. // bool on
  919. gRelayOnOff |= (0x04);
  920. gLedState = gLedState | 0x04; // 按键3设置
  921. if (appControlLedEnable) // add by zzw 开灯点亮按键背光10秒
  922. {
  923. gRadarKeepTimer = 100; // 10s
  924. }
  925. if (switchState.plus_mod[2] == 0x01) // 点动开启
  926. {
  927. switchState.plus_en[2] = 0x01;
  928. switchState.plus_counter[2] = switchState.plus_auto_time[2];
  929. // write_mileage[2] = switchState.plus_en;
  930. // iap_eeprom_write(16, write_mileage, 1); // 写入1字节
  931. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  932. write_mileage[16] = switchState.plus_en[2];
  933. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  934. }
  935. }
  936. // There should be a report after processing the DP
  937. ret = mcu_dp_bool_update(DPID_SWITCH_1, switch_3);
  938. if (ret == SUCCESS)
  939. return SUCCESS;
  940. else
  941. return ERROR;
  942. }
  943. /*****************************************************************************
  944. 函数名称 : dp_download_relay_status_handle
  945. 功能描述 : 针对DPID_RELAY_STATUS的处理函数
  946. 输入参数 : value:数据源数据
  947. : length:数据长度
  948. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  949. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  950. *****************************************************************************/
  951. static unsigned char dp_download_relay_status_handle(const unsigned char value[], unsigned short length)
  952. {
  953. // 示例:当前DP类型为ENUM
  954. unsigned char ret;
  955. unsigned char relay_status;
  956. relay_status = mcu_get_dp_download_enum(value, length);
  957. switch (relay_status) // 全局设置3路的状态
  958. {
  959. case 0:
  960. break;
  961. case 1:
  962. break;
  963. case 2:
  964. break;
  965. default:
  966. break;
  967. }
  968. // add by zzw 20240302
  969. switchState.relay_allstatus = relay_status;
  970. switchState.relay_status[0] = relay_status;
  971. switchState.relay_status[1] = relay_status;
  972. switchState.relay_status[2] = relay_status;
  973. // iap_eeprom_write(1, write_mileage, 4); // 写入4字节
  974. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  975. write_mileage[1] = relay_status;
  976. write_mileage[2] = relay_status;
  977. write_mileage[3] = relay_status;
  978. write_mileage[4] = relay_status;
  979. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  980. // add by zzw 20240302
  981. // add by zzw 20240312 增加eeprom参数配置区
  982. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  983. write_mileage_backup[1] = relay_status;
  984. write_mileage_backup[2] = relay_status;
  985. write_mileage_backup[3] = relay_status;
  986. write_mileage_backup[4] = relay_status;
  987. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  988. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  989. if (read_mileage_backup[1] != relay_status) // 再次读取不相等,则再次写入
  990. {
  991. read_mileage_backup[1] = relay_status;
  992. read_mileage_backup[2] = relay_status;
  993. read_mileage_backup[3] = relay_status;
  994. read_mileage_backup[4] = relay_status;
  995. iap_eeprom_write_backup(0, read_mileage_backup, 30); // 写入1字节
  996. }
  997. // add by zzw 20240312 增加eeprom参数配置区
  998. // There should be a report after processing the DP
  999. ret = mcu_dp_enum_update(DPID_RELAY_STATUS, relay_status);
  1000. if (ret == SUCCESS)
  1001. return SUCCESS;
  1002. else
  1003. return ERROR;
  1004. }
  1005. /*****************************************************************************
  1006. 函数名称 : dp_download_light_mode_handle
  1007. 功能描述 : 针对DPID_LIGHT_MODE的处理函数
  1008. 输入参数 : value:数据源数据
  1009. : length:数据长度
  1010. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  1011. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  1012. *****************************************************************************/
  1013. static unsigned char dp_download_light_mode_handle(const unsigned char value[], unsigned short length)
  1014. {
  1015. // 示例:当前DP类型为ENUM
  1016. unsigned char ret;
  1017. unsigned char light_mode;
  1018. light_mode = mcu_get_dp_download_enum(value, length);
  1019. switch (light_mode) // 枚举范围:Level1,Level2,Level3
  1020. {
  1021. case 0:
  1022. switchState.led_level = 0;
  1023. break;
  1024. case 1:
  1025. switchState.led_level = 1;
  1026. break;
  1027. case 2:
  1028. switchState.led_level = 2;
  1029. break;
  1030. default:
  1031. break;
  1032. }
  1033. switchState.led_level = light_mode ;
  1034. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  1035. write_mileage[5] = switchState.led_level;
  1036. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  1037. // add by zzw 20240312 增加eeprom参数配置区
  1038. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  1039. write_mileage_backup[5] = switchState.led_level;
  1040. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  1041. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  1042. if (read_mileage_backup[5] != switchState.led_level) // 再次读取不相等,则再次写入
  1043. {
  1044. read_mileage_backup[5] = switchState.led_level;
  1045. iap_eeprom_write_backup(0, read_mileage_backup, 30); // 写入1字节
  1046. }
  1047. // add by zzw 20240312 增加eeprom参数配置区
  1048. // There should be a report after processing the DP
  1049. ret = mcu_dp_enum_update(DPID_LIGHT_LEVEL, light_mode);
  1050. if (ret == SUCCESS)
  1051. return SUCCESS;
  1052. else
  1053. return ERROR;
  1054. }
  1055. /*****************************************************************************
  1056. 函数名称 : dp_download_backlight_switch_handle
  1057. 功能描述 : 针对DPID_BACKLIGHT_SWITCH的处理函数
  1058. 输入参数 : value:数据源数据
  1059. : length:数据长度
  1060. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  1061. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  1062. *****************************************************************************/
  1063. static unsigned char dp_download_backlight_switch_handle(const unsigned char value[], unsigned short length)
  1064. {
  1065. // 示例:当前DP类型为BOOL
  1066. unsigned char ret;
  1067. // 0:off/1:on
  1068. unsigned char backlight_switch;
  1069. backlight_switch = mcu_get_dp_download_bool(value, length);
  1070. if (backlight_switch == 0)
  1071. {
  1072. // bool off
  1073. // switchState.bluelight = 0;
  1074. switchState.human = 0;
  1075. }
  1076. else
  1077. {
  1078. // bool on
  1079. // switchState.bluelight = 1;
  1080. switchState.human = 1;
  1081. }
  1082. // add by zzy 20240309
  1083. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  1084. // switchState.led_level = write_mileage[5];//重新读取刷新背光亮度值
  1085. write_mileage[9] = switchState.human;
  1086. iap_eeprom_write(0, write_mileage, 30); // 先读,在写入1字节
  1087. // add by zzy 20240309
  1088. // add by zzw 20240312 增加eeprom参数配置区
  1089. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  1090. switchState.led_level = write_mileage_backup[5]; // 重新读取刷新背光亮度值
  1091. write_mileage_backup[9] = switchState.human;
  1092. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  1093. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  1094. if (read_mileage_backup[9] != switchState.human) // 再次读取不相等,则再次写入
  1095. {
  1096. read_mileage_backup[9] = switchState.human;
  1097. iap_eeprom_write_backup(0, read_mileage_backup, 30); // 写入1字节
  1098. }
  1099. // add by zzw 20240312 增加eeprom参数配置区
  1100. // There should be a report after processing the DP
  1101. // ret = mcu_dp_bool_update(DPID_BACKLIGHT_SWITCH, backlight_switch);
  1102. if (ret == SUCCESS)
  1103. return SUCCESS;
  1104. else
  1105. return ERROR;
  1106. }
  1107. /*****************************************************************************
  1108. 函数名称 : dp_download_switch_inching_handle
  1109. 功能描述 : 针对DPID_SWITCH_INCHING的处理函数
  1110. 输入参数 : value:数据源数据
  1111. : length:数据长度
  1112. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  1113. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  1114. *****************************************************************************/
  1115. static unsigned char dp_download_switch_inching_handle(const unsigned char value[], unsigned short length)
  1116. {
  1117. // 示例:当前DP类型为STRING
  1118. unsigned char ret;
  1119. int i = 0;
  1120. int j = 0;
  1121. // 后面两位表示秒数,前面的1字节的0位表示开/关,1开,0关,bit7-bit1表示通道号
  1122. // length=0,表示全部删除
  1123. //"AQAF"的Base64解码结果是01,00,05
  1124. //"AwAF"的Base64解码结果是03,00,05
  1125. //"BQAF"的Base64解码结果是05, 00, 05
  1126. // STRING type data processing
  1127. unsigned char string_H16_data[32]; // 16进制字符串
  1128. unsigned char string_base64_data[32]; // base64标码字符串
  1129. unsigned char hex_data[32]; // 转换后的16进制字节数据
  1130. if (length > 12) // 自定义协议,一共18字节
  1131. {
  1132. // 010001ffffff000002,字符串下来就是,1号灯1秒后关,2号没有延时关,3号使能关闭延时时间是2秒
  1133. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  1134. write_mileage_backup[20] = 0;
  1135. write_mileage_backup[21] = 0;
  1136. write_mileage_backup[22] = 0;
  1137. write_mileage_backup[23] = 0;
  1138. write_mileage_backup[24] = 0;
  1139. write_mileage_backup[25] = 0;
  1140. write_mileage_backup[26] = 0;
  1141. write_mileage_backup[27] = 0;
  1142. write_mileage_backup[28] = 0; // 每次清空数据,重新赋值
  1143. switchState.plus_mod[0] = 0;
  1144. switchState.plus_mod[1] = 0;
  1145. switchState.plus_mod[2] = 0; // 每次清空数据,重新赋值
  1146. DisHexToHex(hex_data, value, 9); // 字符串转16进制数组
  1147. #ifdef ZIGBEE_ZTU_T1_SW // 希智账户,3键零火开关
  1148. if (hex_data[0] == 0x01) // 开关2使能
  1149. {
  1150. switchState.plus_mod[1] = 1;
  1151. switchState.plus_auto_time[1] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  1152. write_mileage_backup[23] = switchState.plus_mod[1];
  1153. write_mileage_backup[24] = hex_data[1];
  1154. write_mileage_backup[25] = hex_data[2];
  1155. }
  1156. else if (hex_data[0] == 0x00) // 开关2关闭
  1157. {
  1158. switchState.plus_mod[1] = 0;
  1159. switchState.plus_auto_time[1] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  1160. write_mileage_backup[23] = switchState.plus_mod[1];
  1161. write_mileage_backup[24] = hex_data[1];
  1162. write_mileage_backup[25] = hex_data[2];
  1163. }
  1164. else
  1165. {
  1166. switchState.plus_mod[1] = 0xff; // 清除
  1167. write_mileage_backup[23] = switchState.plus_mod[1];
  1168. write_mileage_backup[24] = 0xff;
  1169. write_mileage_backup[25] = 0xff;
  1170. }
  1171. #endif
  1172. #ifdef ZIGBEE_ZTU_T2_SW // 希智账户,3键零火开关
  1173. if (hex_data[0] == 0x01) // 开关1使能
  1174. {
  1175. switchState.plus_mod[0] = 1;
  1176. switchState.plus_auto_time[0] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  1177. write_mileage_backup[20] = switchState.plus_mod[0];
  1178. write_mileage_backup[21] = hex_data[1];
  1179. write_mileage_backup[22] = hex_data[2];
  1180. }
  1181. else if (hex_data[0] == 0x00) // 开关1关闭
  1182. {
  1183. switchState.plus_mod[0] = 0;
  1184. switchState.plus_auto_time[0] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  1185. write_mileage_backup[20] = switchState.plus_mod[0];
  1186. write_mileage_backup[21] = hex_data[1];
  1187. write_mileage_backup[22] = hex_data[2];
  1188. }
  1189. else
  1190. {
  1191. switchState.plus_mod[0] = 0xff; // 清除
  1192. write_mileage_backup[20] = switchState.plus_mod[0];
  1193. write_mileage_backup[21] = 0xff;
  1194. write_mileage_backup[22] = 0xff;
  1195. }
  1196. if (hex_data[3] == 0x01) // 开关3使能
  1197. {
  1198. switchState.plus_mod[2] = 1;
  1199. switchState.plus_auto_time[2] = (hex_data[4] * 256 + hex_data[5]) * 10; // 高字节在前,秒转100ms为基数
  1200. write_mileage_backup[26] = switchState.plus_mod[2];
  1201. write_mileage_backup[27] = hex_data[4];
  1202. write_mileage_backup[28] = hex_data[5];
  1203. }
  1204. else if (hex_data[3] == 0x00) // 开关3关闭
  1205. {
  1206. switchState.plus_mod[2] = 0;
  1207. switchState.plus_auto_time[2] = (hex_data[4] * 256 + hex_data[5]) * 10; // 高字节在前,秒转100ms为基数
  1208. write_mileage_backup[26] = switchState.plus_mod[2];
  1209. write_mileage_backup[27] = hex_data[4];
  1210. write_mileage_backup[28] = hex_data[5];
  1211. }
  1212. else
  1213. {
  1214. switchState.plus_mod[2] = 0xff; // 清除
  1215. write_mileage_backup[26] = switchState.plus_mod[2];
  1216. write_mileage_backup[27] = 0xff;
  1217. write_mileage_backup[28] = 0xff;
  1218. }
  1219. #endif
  1220. #if (defined ZIGBEE_ZTU_T3_SW) || (defined ZIGBEE_ZTU_T6_SCENCE_SW)
  1221. if (hex_data[0] == 0x01) // 开关1使能
  1222. {
  1223. switchState.plus_mod[0] = 1;
  1224. switchState.plus_auto_time[0] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  1225. write_mileage_backup[20] = switchState.plus_mod[0];
  1226. write_mileage_backup[21] = hex_data[1];
  1227. write_mileage_backup[22] = hex_data[2];
  1228. }
  1229. else if (hex_data[0] == 0x00) // 开关1关闭
  1230. {
  1231. switchState.plus_mod[0] = 0;
  1232. switchState.plus_auto_time[0] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  1233. write_mileage_backup[20] = switchState.plus_mod[0];
  1234. write_mileage_backup[21] = hex_data[1];
  1235. write_mileage_backup[22] = hex_data[2];
  1236. }
  1237. else
  1238. {
  1239. switchState.plus_mod[0] = 0xff; // 清除
  1240. write_mileage_backup[20] = switchState.plus_mod[0];
  1241. write_mileage_backup[21] = 0xff;
  1242. write_mileage_backup[22] = 0xff;
  1243. }
  1244. if (hex_data[3] == 0x01) // 开关2使能
  1245. {
  1246. switchState.plus_mod[1] = 1;
  1247. switchState.plus_auto_time[1] = (hex_data[4] * 256 + hex_data[5]) * 10; // 高字节在前,秒转100ms为基数
  1248. write_mileage_backup[23] = switchState.plus_mod[1];
  1249. write_mileage_backup[24] = hex_data[4];
  1250. write_mileage_backup[25] = hex_data[5];
  1251. }
  1252. else if (hex_data[3] == 0x00) // 开关2关闭
  1253. {
  1254. switchState.plus_mod[1] = 0;
  1255. switchState.plus_auto_time[1] = (hex_data[4] * 256 + hex_data[5]) * 10; // 高字节在前,秒转100ms为基数
  1256. write_mileage_backup[23] = switchState.plus_mod[1];
  1257. write_mileage_backup[24] = hex_data[4];
  1258. write_mileage_backup[25] = hex_data[5];
  1259. }
  1260. else
  1261. {
  1262. switchState.plus_mod[1] = 0xff; // 清除
  1263. write_mileage_backup[23] = switchState.plus_mod[1];
  1264. write_mileage_backup[24] = 0xff;
  1265. write_mileage_backup[25] = 0xff;
  1266. }
  1267. if (hex_data[6] == 0x01) // 开关3使能
  1268. {
  1269. switchState.plus_mod[2] = 1;
  1270. switchState.plus_auto_time[2] = (hex_data[7] * 256 + hex_data[8]) * 10; // 高字节在前,秒转100ms为基数
  1271. write_mileage_backup[26] = switchState.plus_mod[2];
  1272. write_mileage_backup[27] = hex_data[7];
  1273. write_mileage_backup[28] = hex_data[8];
  1274. }
  1275. else if (hex_data[6] == 0x00) // 开关3关闭
  1276. {
  1277. switchState.plus_mod[2] = 0;
  1278. switchState.plus_auto_time[2] = (hex_data[7] * 256 + hex_data[8]) * 10; // 高字节在前,秒转100ms为基数
  1279. write_mileage_backup[26] = switchState.plus_mod[2];
  1280. write_mileage_backup[27] = hex_data[7];
  1281. write_mileage_backup[28] = hex_data[8];
  1282. }
  1283. else
  1284. {
  1285. switchState.plus_mod[2] = 0xff; // 清除
  1286. write_mileage_backup[26] = switchState.plus_mod[2];
  1287. write_mileage_backup[27] = 0xff;
  1288. write_mileage_backup[28] = 0xff;
  1289. }
  1290. #endif
  1291. }
  1292. else // 涂鸦官方标准协议,最大12字节
  1293. {
  1294. // char source[32] = "abc";
  1295. // char dest[32];
  1296. /*将字符串abc进行base64编码*/
  1297. // Base64Encode(dest, source, strlen(source));
  1298. // printf("%s\n", dest);
  1299. /*将字符串abc的编码字符串解码,还原成abc*/
  1300. // Base64Decode(source, dest, strlen(dest));
  1301. // printf("%s\n", source);
  1302. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  1303. write_mileage_backup[20] = 0;
  1304. write_mileage_backup[21] = 0;
  1305. write_mileage_backup[22] = 0;
  1306. write_mileage_backup[23] = 0;
  1307. write_mileage_backup[24] = 0;
  1308. write_mileage_backup[25] = 0;
  1309. write_mileage_backup[26] = 0;
  1310. write_mileage_backup[27] = 0;
  1311. write_mileage_backup[28] = 0; // 每次清空数据,重新赋值
  1312. switchState.plus_mod[0] = 0;
  1313. switchState.plus_mod[1] = 0;
  1314. switchState.plus_mod[2] = 0;
  1315. if (length == 0) // 清空点动开关
  1316. {
  1317. switchState.plus_mod[0] = 0;
  1318. switchState.plus_mod[1] = 0;
  1319. switchState.plus_mod[2] = 0;
  1320. }
  1321. else
  1322. {
  1323. for (i = 0; i < (length / 4); i++) // 4字符一个数据集
  1324. {
  1325. for (j = 0; j < 4; j++) // 4个字符转换一次
  1326. {
  1327. string_base64_data[j] = value[i * 4 + j];
  1328. }
  1329. // base64_decode_three_bytes(string_base64_data, hex_data);
  1330. Base64Decode(hex_data, string_base64_data, strlen(string_base64_data));
  1331. if (hex_data[0] == 0x01) // 开关1使能
  1332. {
  1333. switchState.plus_mod[0] = 1;
  1334. switchState.plus_auto_time[0] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  1335. write_mileage_backup[20] = switchState.plus_mod[0];
  1336. write_mileage_backup[21] = hex_data[1];
  1337. write_mileage_backup[22] = hex_data[2];
  1338. }
  1339. else if (hex_data[0] == 0x00) // 开关1关闭
  1340. {
  1341. switchState.plus_mod[0] = 0;
  1342. write_mileage_backup[20] = switchState.plus_mod[0];
  1343. write_mileage_backup[21] = 0;
  1344. write_mileage_backup[22] = 0;
  1345. }
  1346. else if (hex_data[0] == 0x03) // 开关2使能
  1347. {
  1348. switchState.plus_mod[1] = 1;
  1349. switchState.plus_auto_time[1] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  1350. write_mileage_backup[23] = switchState.plus_mod[1];
  1351. write_mileage_backup[24] = hex_data[1];
  1352. write_mileage_backup[25] = hex_data[2];
  1353. }
  1354. else if (hex_data[0] == 0x02) // 开关2关闭
  1355. {
  1356. switchState.plus_mod[1] = 0;
  1357. write_mileage_backup[23] = switchState.plus_mod[1];
  1358. write_mileage_backup[24] = 0;
  1359. write_mileage_backup[25] = 0;
  1360. }
  1361. else if (hex_data[0] == 0x05) // 开关3使能
  1362. {
  1363. switchState.plus_mod[2] = 1;
  1364. switchState.plus_auto_time[2] = (hex_data[1] * 256 + hex_data[2]) * 10; // 高字节在前,秒转100ms为基数
  1365. write_mileage_backup[26] = switchState.plus_mod[2];
  1366. write_mileage_backup[27] = hex_data[1];
  1367. write_mileage_backup[28] = hex_data[2];
  1368. }
  1369. else if (hex_data[0] == 0x04) // 开关3关闭
  1370. {
  1371. switchState.plus_mod[2] = 0;
  1372. write_mileage_backup[26] = switchState.plus_mod[2];
  1373. write_mileage_backup[27] = 0;
  1374. write_mileage_backup[28] = 0;
  1375. }
  1376. }
  1377. }
  1378. }
  1379. // add by zzw 20240313 增加eeprom参数配置区
  1380. // 点动开关2个字节(使能1,时间2)-20-21-22,-23-24-25,-26-27-28
  1381. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  1382. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  1383. if (read_mileage_backup[20] != switchState.plus_mod[0]) // 再次读取不相等,则再次写入
  1384. {
  1385. iap_eeprom_write_backup(0, write_mileage_backup, 30); //
  1386. }
  1387. // add by zzw 20240313 增加eeprom参数配置区
  1388. // There should be a report after processing the DP
  1389. ret = mcu_dp_string_update(DPID_SWITCH_INCHING, value, length);
  1390. if (ret == SUCCESS)
  1391. return SUCCESS;
  1392. else
  1393. return ERROR;
  1394. }
  1395. /*****************************************************************************
  1396. 函数名称 : dp_download_relay_status_1_handle
  1397. 功能描述 : 针对DPID_RELAY_STATUS_1的处理函数
  1398. 输入参数 : value:数据源数据
  1399. : length:数据长度
  1400. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  1401. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  1402. *****************************************************************************/
  1403. static unsigned char dp_download_relay_status_1_handle(const unsigned char value[], unsigned short length)
  1404. {
  1405. // 示例:当前DP类型为ENUM
  1406. unsigned char ret;
  1407. unsigned char relay_status_1;
  1408. relay_status_1 = mcu_get_dp_download_enum(value, length);
  1409. switch (relay_status_1)
  1410. {
  1411. case 0: // 断电
  1412. // switchState.relay_status[0]=0;
  1413. break;
  1414. case 1: // 通电
  1415. // switchState.relay_status[0]=1;
  1416. break;
  1417. case 2: // 断电记忆
  1418. // switchState.relay_status[0]=2;
  1419. break;
  1420. default:
  1421. break;
  1422. }
  1423. // add by zzw 20240207
  1424. switchState.relay_status[0] = relay_status_1;
  1425. // add by zzw 20240207
  1426. // add by zzy 20240309
  1427. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  1428. write_mileage[2] = switchState.relay_status[0];
  1429. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  1430. // add by zzy 20240309
  1431. // add by zzw 20240312 增加eeprom参数配置区
  1432. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  1433. write_mileage_backup[2] = switchState.relay_status[0];
  1434. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  1435. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  1436. if (read_mileage_backup[2] != switchState.relay_status[0]) // 再次读取不相等,则再次写入
  1437. {
  1438. read_mileage_backup[2] = switchState.relay_status[0];
  1439. iap_eeprom_write_backup(0, read_mileage_backup, 30); // 写入1字节
  1440. }
  1441. // add by zzw 20240312 增加eeprom参数配置区
  1442. // There should be a report after processing the DP
  1443. ret = mcu_dp_enum_update(DPID_RELAY_STATUS_1, relay_status_1);
  1444. if (ret == SUCCESS)
  1445. return SUCCESS;
  1446. else
  1447. return ERROR;
  1448. }
  1449. /*****************************************************************************
  1450. 函数名称 : dp_download_relay_status_2_handle
  1451. 功能描述 : 针对DPID_RELAY_STATUS_2的处理函数
  1452. 输入参数 : value:数据源数据
  1453. : length:数据长度
  1454. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  1455. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  1456. *****************************************************************************/
  1457. static unsigned char dp_download_relay_status_2_handle(const unsigned char value[], unsigned short length)
  1458. {
  1459. // 示例:当前DP类型为ENUM
  1460. unsigned char ret;
  1461. unsigned char relay_status_2;
  1462. relay_status_2 = mcu_get_dp_download_enum(value, length);
  1463. switch (relay_status_2)
  1464. {
  1465. case 0:
  1466. break;
  1467. case 1:
  1468. break;
  1469. case 2:
  1470. break;
  1471. default:
  1472. break;
  1473. }
  1474. // add by zzw 20240207
  1475. switchState.relay_status[1] = relay_status_2;
  1476. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  1477. write_mileage[3] = switchState.relay_status[1];
  1478. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  1479. // add by zzw 20240207
  1480. // add by zzw 20240312 增加eeprom参数配置区
  1481. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  1482. write_mileage_backup[3] = switchState.relay_status[1];
  1483. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  1484. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  1485. if (read_mileage_backup[3] != switchState.relay_status[1]) // 再次读取不相等,则再次写入
  1486. {
  1487. read_mileage_backup[3] = switchState.relay_status[1];
  1488. iap_eeprom_write_backup(0, read_mileage_backup, 30); // 写入1字节
  1489. }
  1490. // add by zzw 20240312 增加eeprom参数配置区
  1491. // There should be a report after processing the DP
  1492. ret = mcu_dp_enum_update(DPID_RELAY_STATUS_2, relay_status_2);
  1493. if (ret == SUCCESS)
  1494. return SUCCESS;
  1495. else
  1496. return ERROR;
  1497. }
  1498. /*****************************************************************************
  1499. 函数名称 : dp_download_relay_status_3_handle
  1500. 功能描述 : 针对DPID_RELAY_STATUS_3的处理函数
  1501. 输入参数 : value:数据源数据
  1502. : length:数据长度
  1503. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  1504. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  1505. *****************************************************************************/
  1506. static unsigned char dp_download_relay_status_3_handle(const unsigned char value[], unsigned short length)
  1507. {
  1508. // 示例:当前DP类型为ENUM
  1509. unsigned char ret;
  1510. unsigned char relay_status_3;
  1511. relay_status_3 = mcu_get_dp_download_enum(value, length);
  1512. switch (relay_status_3)
  1513. {
  1514. case 0:
  1515. break;
  1516. case 1:
  1517. break;
  1518. case 2:
  1519. break;
  1520. default:
  1521. break;
  1522. }
  1523. // add by zzw 20240207
  1524. switchState.relay_status[2] = relay_status_3;
  1525. iap_eeprom_read(0, write_mileage, 30); // 读取30字节
  1526. write_mileage[4] = switchState.relay_status[2];
  1527. iap_eeprom_write(0, write_mileage, 30); // 写入1字节
  1528. // add by zzw 20240207
  1529. // add by zzw 20240312 增加eeprom参数配置区
  1530. iap_eeprom_read_backup(0, write_mileage_backup, 30); // 读取30字节
  1531. write_mileage_backup[4] = switchState.relay_status[2];
  1532. iap_eeprom_write_backup(0, write_mileage_backup, 30); // 写入1字节
  1533. iap_eeprom_read_backup(0, read_mileage_backup, 30); // 读取30字节
  1534. if (read_mileage_backup[4] != switchState.relay_status[2]) // 再次读取不相等,则再次写入
  1535. {
  1536. read_mileage_backup[4] = switchState.relay_status[2];
  1537. iap_eeprom_write_backup(0, read_mileage_backup, 30); // 写入1字节
  1538. }
  1539. // add by zzw 20240312 增加eeprom参数配置区
  1540. // There should be a report after processing the DP
  1541. ret = mcu_dp_enum_update(DPID_RELAY_STATUS_3, relay_status_3);
  1542. if (ret == SUCCESS)
  1543. return SUCCESS;
  1544. else
  1545. return ERROR;
  1546. }
  1547. /*****************************************************************************
  1548. 函数名称 : dp_download_add_ele_handle
  1549. 功能描述 : 针对DPID_ADD_ELE的处理函数
  1550. 输入参数 : value:数据源数据
  1551. : length:数据长度
  1552. 返回参数 : 成功返回:SUCCESS/失败返回:ERROR
  1553. 使用说明 : 可下发可上报类型,需要在处理完数据后上报处理结果至app
  1554. *****************************************************************************/
  1555. static unsigned char dp_download_add_ele_handle(const unsigned char value[], unsigned short length)
  1556. {
  1557. //示例:当前DP类型为VALUE
  1558. unsigned char ret;
  1559. unsigned long add_ele;
  1560. add_ele = mcu_get_dp_download_value(value,length);
  1561. /*
  1562. //VALUE type data processing
  1563. */
  1564. // switchState.dp_add_ele=value[1]<<8+value[0];//100倍,去除小数的值
  1565. //实际值,需要/100,带小数的
  1566. //There should be a report after processing the DP
  1567. ret = mcu_dp_value_update(DPID_ADD_ELE,add_ele);
  1568. if(ret == SUCCESS)
  1569. return SUCCESS;
  1570. else
  1571. return ERROR;
  1572. }
  1573. #ifdef SUPPORT_MCU_RTC_CHECK
  1574. /**
  1575. * @brief mcu check local RTC time
  1576. * @param[in] {time} timestamp
  1577. * @return void
  1578. */
  1579. void mcu_write_rtctime(unsigned char time[])
  1580. {
  1581. // #error "mcu should realize RTC time wtriting fuction, and delete this line"
  1582. /*
  1583. time[0]~time[3]:standard time
  1584. time[4]~time[7]: Local time
  1585. */
  1586. my_memcpy((void *)timestamp, (const char *)time, 4); // get timestamp
  1587. zigbee_timestamp_to_time();
  1588. /*
  1589. year = _time.w_year; //year
  1590. month = _time.w_month; //month
  1591. date = _time.w_date; //date
  1592. hour = _time.hour + 8; //hour(8:BeiJing time)
  1593. min = _time.min; //minute
  1594. sec = _time.sec; //second
  1595. */
  1596. }
  1597. #endif
  1598. /**
  1599. * @brief Zigbee functional test feedback
  1600. * @param[in] {void}
  1601. * @return void
  1602. */
  1603. void zigbee_test_result(void)
  1604. {
  1605. // #error "this test is makesure the rf fuction of zigbee module, if test pass or not should do something, mcu should realize"
  1606. unsigned char rssi = zigbee_uart_rx_buf[DATA_START + 1];
  1607. if (zigbee_uart_rx_buf[DATA_START] == 0x01)
  1608. {
  1609. if (rssi > 0x3C)
  1610. {
  1611. // test sucess the range of rssi is 0% ~ 100%
  1612. }
  1613. else
  1614. {
  1615. // test failure
  1616. }
  1617. }
  1618. else
  1619. {
  1620. // test failure
  1621. }
  1622. }
  1623. /******************************************************************************
  1624. WARNING!!!
  1625. 以下函数用户请勿修改!!
  1626. ******************************************************************************/
  1627. /**
  1628. * @brief this function will handle uart received frame data
  1629. * @param[in] {dpid} dp id
  1630. * @param[in] {value} dp data
  1631. * @param[in] {length} lenght of dp data
  1632. * @return handle result
  1633. */
  1634. #ifdef ZIGBEE_ZTU_T1_SW
  1635. unsigned char dp_download_handle(unsigned char dpid, const unsigned char value[], unsigned short length)
  1636. {
  1637. /* only list of function, mcu need realize these fuction*/
  1638. unsigned char ret;
  1639. // 可收到控制信号,说明配网肯定成功
  1640. ZG_JoinCounter = 18000; // 入网成功,入网计数器置最大值,180秒
  1641. switchState.zigbee_work_state = 1;
  1642. // 可收到控制信号,说明配网肯定成功
  1643. switch (dpid)
  1644. {
  1645. case DPID_SWITCH_1:
  1646. // case DPID_SWITCH_2:
  1647. // 开关 2处理函数
  1648. ret = dp_download_switch_2_handle(value, length);
  1649. break;
  1650. case DPID_SWITCH_3:
  1651. // 开关 3处理函数
  1652. ret = dp_download_switch_3_handle(value, length);
  1653. break;
  1654. case DPID_RELAY_STATUS:
  1655. // 上电状态设置处理函数
  1656. ret = dp_download_relay_status_handle(value, length);
  1657. break;
  1658. case DPID_LIGHT_LEVEL:
  1659. // 指示灯状态设置处理函数
  1660. ret = dp_download_light_mode_handle(value, length);
  1661. break;
  1662. case DPID_BACKLIGHT_SWITCH:
  1663. // 背光开关处理函数
  1664. ret = dp_download_backlight_switch_handle(value, length);
  1665. break;
  1666. case DPID_SWITCH_INCHING:
  1667. // 点动开关(延时关)处理函数
  1668. ret = dp_download_switch_inching_handle(value, length);
  1669. break;
  1670. case DPID_RELAY_STATUS_1:
  1671. // 开关1上电状态设置处理函数
  1672. ret = dp_download_relay_status_1_handle(value, length);
  1673. break;
  1674. case DPID_RELAY_STATUS_2:
  1675. // 开关2上电状态设置处理函数
  1676. ret = dp_download_relay_status_2_handle(value, length);
  1677. break;
  1678. case DPID_RELAY_STATUS_3:
  1679. // 开关3上电状态设置处理函数
  1680. ret = dp_download_relay_status_3_handle(value, length);
  1681. break;
  1682. default:
  1683. break;
  1684. }
  1685. return ret;
  1686. }
  1687. #endif
  1688. #ifdef ZIGBEE_ZTU_T2_SW
  1689. unsigned char dp_download_handle(unsigned char dpid, const unsigned char value[], unsigned short length)
  1690. {
  1691. /* only list of function, mcu need realize these fuction*/
  1692. unsigned char ret;
  1693. // 可收到控制信号,说明配网肯定成功
  1694. ZG_JoinCounter = 18000; // 入网成功,入网计数器置最大值,180秒
  1695. switchState.zigbee_work_state = 1;
  1696. // 可收到控制信号,说明配网肯定成功
  1697. switch (dpid)
  1698. {
  1699. case DPID_SWITCH_1:
  1700. // 开关 1处理函数
  1701. ret = dp_download_switch_3_handle(value, length);
  1702. break;
  1703. case DPID_SWITCH_2:
  1704. //case DPID_SWITCH_3:
  1705. // 开关 3处理函数
  1706. ret = dp_download_switch_1_handle(value, length);
  1707. break;
  1708. case DPID_RELAY_STATUS:
  1709. // 上电状态设置处理函数
  1710. ret = dp_download_relay_status_handle(value, length);
  1711. break;
  1712. case DPID_LIGHT_LEVEL:
  1713. // 指示灯状态设置处理函数
  1714. ret = dp_download_light_mode_handle(value, length);
  1715. break;
  1716. case DPID_BACKLIGHT_SWITCH:
  1717. // 背光开关处理函数
  1718. ret = dp_download_backlight_switch_handle(value, length);
  1719. break;
  1720. case DPID_SWITCH_INCHING:
  1721. // 点动开关(延时关)处理函数
  1722. ret = dp_download_switch_inching_handle(value, length);
  1723. break;
  1724. case DPID_RELAY_STATUS_1:
  1725. // 开关1上电状态设置处理函数
  1726. ret = dp_download_relay_status_1_handle(value, length);
  1727. break;
  1728. case DPID_RELAY_STATUS_2:
  1729. // 开关2上电状态设置处理函数
  1730. ret = dp_download_relay_status_2_handle(value, length);
  1731. break;
  1732. case DPID_RELAY_STATUS_3:
  1733. // 开关3上电状态设置处理函数
  1734. ret = dp_download_relay_status_3_handle(value, length);
  1735. break;
  1736. default:
  1737. break;
  1738. }
  1739. return ret;
  1740. }
  1741. #endif
  1742. //#ifdef ZIGBEE_ZTU_T3_SW
  1743. #if (defined ZIGBEE_ZTU_T3_SW) && (defined ZIGBEE_3SWITCH_SW)
  1744. unsigned char dp_download_handle(unsigned char dpid, const unsigned char value[], unsigned short length)
  1745. {
  1746. /* only list of function, mcu need realize these fuction*/
  1747. unsigned char ret;
  1748. // 可收到控制信号,说明配网肯定成功
  1749. ZG_JoinCounter = 18000; // 入网成功,入网计数器置最大值,180秒
  1750. switchState.zigbee_work_state = 1;
  1751. // 可收到控制信号,说明配网肯定成功
  1752. switch (dpid)
  1753. {
  1754. case DPID_SWITCH_1:
  1755. // 开关 1处理函数
  1756. ret = dp_download_switch_3_handle(value, length);
  1757. break;
  1758. case DPID_SWITCH_2:
  1759. // 开关 2处理函数
  1760. ret = dp_download_switch_2_handle(value, length);
  1761. break;
  1762. case DPID_SWITCH_3:
  1763. // 开关 3处理函数
  1764. ret = dp_download_switch_1_handle(value, length);
  1765. break;
  1766. case DPID_RELAY_STATUS:
  1767. // 上电状态设置处理函数
  1768. ret = dp_download_relay_status_handle(value, length);
  1769. break;
  1770. case DPID_LIGHT_LEVEL:
  1771. // 指示灯状态设置处理函数
  1772. ret = dp_download_light_mode_handle(value, length);
  1773. break;
  1774. case DPID_BACKLIGHT_SWITCH:
  1775. // 背光开关处理函数
  1776. ret = dp_download_backlight_switch_handle(value, length);
  1777. break;
  1778. case DPID_SWITCH_INCHING:
  1779. // 点动开关(延时关)处理函数
  1780. ret = dp_download_switch_inching_handle(value, length);
  1781. break;
  1782. case DPID_RELAY_STATUS_1:
  1783. // 开关1上电状态设置处理函数
  1784. ret = dp_download_relay_status_1_handle(value, length);
  1785. break;
  1786. case DPID_RELAY_STATUS_2:
  1787. // 开关2上电状态设置处理函数
  1788. ret = dp_download_relay_status_2_handle(value, length);
  1789. break;
  1790. case DPID_RELAY_STATUS_3:
  1791. // 开关3上电状态设置处理函数
  1792. ret = dp_download_relay_status_3_handle(value, length);
  1793. break;
  1794. case DPID_ADD_ELE:
  1795. //增加电量处理函数
  1796. ret = dp_download_add_ele_handle(value,length);
  1797. default:
  1798. break;
  1799. }
  1800. return ret;
  1801. }
  1802. #endif
  1803. #ifdef ZIGBEE_ZTU_T6_SCENCE_SW
  1804. unsigned char dp_download_handle(unsigned char dpid, const unsigned char value[], unsigned short length)
  1805. {
  1806. /* only list of function, mcu need realize these fuction*/
  1807. unsigned char ret;
  1808. // 可收到控制信号,说明配网肯定成功
  1809. ZG_JoinCounter = 18000; // 入网成功,入网计数器置最大值,180秒
  1810. switchState.zigbee_work_state = 1; // 有dp控制指令,说明设备肯定在线//add by zzw
  1811. switch (dpid)
  1812. {
  1813. case DPID_SCENE_1:
  1814. //场景1处理函数
  1815. ret = dp_download_scene_1_handle(value,length);
  1816. break;
  1817. case DPID_SCENE_2:
  1818. //场景2处理函数
  1819. ret = dp_download_scene_2_handle(value,length);
  1820. break;
  1821. case DPID_SCENE_3:
  1822. //场景3处理函数
  1823. ret = dp_download_scene_3_handle(value,length);
  1824. break;
  1825. case DPID_SCENE_4:
  1826. //场景4处理函数
  1827. ret = dp_download_scene_4_handle(value,length);
  1828. break;
  1829. case DPID_SCENE_5:
  1830. //场景5处理函数
  1831. ret = dp_download_scene_5_handle(value,length);
  1832. break;
  1833. case DPID_SCENE_6:
  1834. //场景6处理函数
  1835. ret = dp_download_scene_6_handle(value,length);
  1836. break;
  1837. case DPID_MODE_1:
  1838. //模式1处理函数
  1839. ret = dp_download_mode_1_handle(value,length);
  1840. break;
  1841. case DPID_MODE_2:
  1842. //模式2处理函数
  1843. ret = dp_download_mode_2_handle(value,length);
  1844. break;
  1845. case DPID_MODE_3:
  1846. //模式3处理函数
  1847. ret = dp_download_mode_3_handle(value,length);
  1848. break;
  1849. case DPID_SWITCH_1:
  1850. //开关1处理函数
  1851. ret = dp_download_switch_3_handle(value,length);
  1852. break;
  1853. case DPID_SWITCH_2:
  1854. //开关2处理函数
  1855. ret = dp_download_switch_2_handle(value,length);
  1856. break;
  1857. case DPID_SWITCH_3:
  1858. //开关3处理函数
  1859. ret = dp_download_switch_1_handle(value,length);
  1860. break;
  1861. case DPID_LIGHT_LEVEL:
  1862. //指示灯亮度处理函数
  1863. ret = dp_download_light_mode_handle(value,length);
  1864. break;
  1865. case DPID_RELAY_STATUS:
  1866. //上电状态设置处理函数
  1867. ret = dp_download_relay_status_handle(value,length);
  1868. break;
  1869. case DPID_RELAY_STATUS_1:
  1870. //开关1上电状态设置处理函数
  1871. ret = dp_download_relay_status_1_handle(value,length);
  1872. break;
  1873. case DPID_RELAY_STATUS_2:
  1874. //开关2上电状态设置处理函数
  1875. ret = dp_download_relay_status_2_handle(value,length);
  1876. break;
  1877. case DPID_RELAY_STATUS_3:
  1878. //开关3上电状态设置处理函数
  1879. ret = dp_download_relay_status_3_handle(value,length);
  1880. break;
  1881. case DPID_SWITCH_INCHING:
  1882. //点动开关(延时关)处理函数
  1883. ret = dp_download_switch_inching_handle(value,length);
  1884. break;
  1885. case DPID_ADD_ELE:
  1886. //增加电量处理函数
  1887. break;
  1888. default:
  1889. break;
  1890. }
  1891. return ret;
  1892. }
  1893. #endif
  1894. /**
  1895. * @brief get received cmd total number
  1896. * @param[in] {void}
  1897. * @return received cmd total number
  1898. */
  1899. unsigned char get_download_cmd_total(void)
  1900. {
  1901. return (sizeof(download_cmd) / sizeof(download_cmd[0]));
  1902. }
  1903. /**
  1904. * @brief received zigbee net_work state handle
  1905. * @param[in] {zigbee_work_state} zigbee current network state
  1906. * @return void
  1907. */
  1908. void zigbee_work_state_event(unsigned char zigbee_work_state)
  1909. {
  1910. unsigned short length = 0;
  1911. zigbee_uart_write_frame(ZIGBEE_STATE_CMD, length);
  1912. switch (zigbee_work_state)
  1913. {
  1914. case ZIGBEE_NOT_JION: // 设备从在线切换到不在线则报警,脱网报警(离线状态) 慢闪60s 3s一闪烁
  1915. if (ZG_Joining == CONDITION_JOINGING_TO_NORMAL) // 入网前几入网阶段不进入报警闪烁,防止入网指令发送后的自动脱网导致闪烁混乱
  1916. {
  1917. switchState.zigbee_work_state = 2; // 脱网报警启动
  1918. switchState.time = 6000; // 60秒
  1919. ledSetParam(150, 300); // 3s一闪烁
  1920. }
  1921. break;
  1922. case ZIGBEE_JOIN_GATEWAY: // 新设备入网成功
  1923. ZG_JoinCounter = 18000; // 入网成功,入网计数器置最大值,180秒
  1924. switchState.zigbee_work_state = 1;
  1925. break;
  1926. case ZIGBEE_JOIN_ERROR: // 已经入网设备,发起再次入网,会进入这里
  1927. // 配网超时3分钟,触发误触重连,只要APP不操作添加设备确定按键,设备重新回连至上一个账号下
  1928. // ZG_JoinCounter = 18000; // 配网结束,入网计数器置最大值,180秒
  1929. // switchState.zigbee_work_state = 1;
  1930. break;
  1931. case ZIGBEE_JOINING:
  1932. break;
  1933. default:
  1934. break;
  1935. }
  1936. }
  1937. /**
  1938. * @brief received reset zigbee response
  1939. * @param[in] {state} response state
  1940. * @return void
  1941. */
  1942. void mcu_reset_zigbee_event(unsigned char state)
  1943. {
  1944. switch (state)
  1945. {
  1946. case RESET_ZIGBEE_OK:
  1947. break;
  1948. case RESET_ZIGBEE_ERROR:
  1949. break;
  1950. default:
  1951. break;
  1952. }
  1953. }
  1954. /**
  1955. * @brief check mcu version response
  1956. * @param[in] {void}
  1957. * @return void
  1958. */
  1959. void response_mcu_ota_version_event(void)
  1960. {
  1961. unsigned short length = 0;
  1962. length = set_zigbee_uart_byte(length, get_current_mcu_fw_ver()); // current fw version
  1963. zigbee_uart_write_frame(MCU_OTA_VERSION_CMD, length);
  1964. }
  1965. #ifdef SUPPORT_MCU_OTA
  1966. /**
  1967. * @brief mcu ota update notify response
  1968. * @param[in] {offset} data offset
  1969. * @return void
  1970. */
  1971. void response_mcu_ota_notify_event(unsigned char offset)
  1972. {
  1973. unsigned char i = 0;
  1974. unsigned short length = 0;
  1975. unsigned char update = 0;
  1976. unsigned long app_newcode_add = 0;
  1977. unsigned char j = 0;
  1978. current_mcu_fw_pid(); // current PID
  1979. while (i < 8)
  1980. {
  1981. ota_fw_info.mcu_ota_pid[i] = zigbee_uart_rx_buf[offset + DATA_START + i]; // ota fw PID
  1982. i++;
  1983. }
  1984. ota_fw_info.mcu_ota_ver = zigbee_uart_rx_buf[offset + DATA_START + 8]; // ota fw version
  1985. ota_fw_info.mcu_ota_fw_size = zigbee_uart_rx_buf[offset + DATA_START + 9] << 24 |
  1986. zigbee_uart_rx_buf[offset + DATA_START + 10] << 16 |
  1987. zigbee_uart_rx_buf[offset + DATA_START + 11] << 8 |
  1988. zigbee_uart_rx_buf[offset + DATA_START + 12]; // ota fw size
  1989. ota_fw_info.mcu_ota_checksum = zigbee_uart_rx_buf[offset + DATA_START + 13] << 24 |
  1990. zigbee_uart_rx_buf[offset + DATA_START + 14] << 16 |
  1991. zigbee_uart_rx_buf[offset + DATA_START + 15] << 8 |
  1992. zigbee_uart_rx_buf[offset + DATA_START + 16]; // ota fw checksum
  1993. if ((!strcmp_barry(&ota_fw_info.mcu_ota_pid[0], &current_mcu_pid[0], 8)) &&
  1994. (ota_fw_info.mcu_ota_ver > get_current_mcu_fw_ver() &&
  1995. ota_fw_info.mcu_ota_fw_size > 0))
  1996. { // check fw pid and fw version and fw size
  1997. length = set_zigbee_uart_byte(length, 0x00); // OK
  1998. update = 1; // 校验通过,可进行固件升级
  1999. }
  2000. else
  2001. {
  2002. length = set_zigbee_uart_byte(length, 0x01); // error
  2003. }
  2004. ota_fw_info.mcu_current_offset = 0;
  2005. zigbee_uart_write_frame(MCU_OTA_NOTIFY_CMD, length); // 校验PID一致性,版本号大于当前版本则可执行升级,并给zigbee应答01或00
  2006. // add by zzw 升级通知接收成功,第一次调用接收固件命令
  2007. if (update)
  2008. {
  2009. // zzw ota must add 20240326 OTA 存入标志位
  2010. // mcu_ota_fw_request(); // 固件升级,取消直接升级,进入boot升级
  2011. // TM52的特性决定了,需要跳转到BOOT去接收OTA数据
  2012. update = 0;
  2013. // 先写入升级的标志再跳转到UBOOT
  2014. // INFO5地址存储升级标志0x55、0xaa、0x5a
  2015. CheckBuf[0] = 0x55;
  2016. CheckBuf[1] = 0xaa;
  2017. CheckBuf[2] = 0x5a;
  2018. for (i = 0; i < 8; i++)
  2019. {
  2020. CheckBuf[3 + i] = ota_fw_info.mcu_ota_pid[i];
  2021. }
  2022. CheckBuf[11] = ota_fw_info.mcu_ota_ver;
  2023. for (i = 0; i < 8; i++)
  2024. {
  2025. CheckBuf[12 + i] = zigbee_uart_rx_buf[offset + DATA_START + 9 + i];
  2026. }
  2027. // user_write_INFO_byte(INFO5_ADDR, CheckBuf, 20);
  2028. // while (!com0send_over); //等待uart回复帧发送结束再执行跳转指令
  2029. // com0send_over = 0;
  2030. bsp_delay_ms(5); // 延时5ms等待串口应答结束
  2031. EA = 0; // 关闭中断
  2032. BOOTV = 0x04; // 设置热复位后跳转到uboot
  2033. SWCMD = 0x56; // 软件复位
  2034. // TM52的特性决定了,需要跳转到BOOT去接收OTA数据
  2035. }
  2036. }
  2037. /**
  2038. * @brief received mcu ota data request response
  2039. * @param[in] {fw_offset} offset of file
  2040. * @param[in] {data} received data
  2041. * @return void
  2042. */
  2043. /*void reveived_mcu_ota_data_handle(unsigned int fw_offset, char *data)
  2044. {
  2045. //#error "received frame data, should save in flash, mcu should realize this fuction, and delete this line "
  2046. //未使用
  2047. }*/
  2048. /**
  2049. * @brief mcu send ota data request
  2050. * @param[in] {void}
  2051. * @return void
  2052. */
  2053. void mcu_ota_fw_request_event(unsigned char offset)
  2054. {
  2055. unsigned int fw_offset = 0;
  2056. char fw_data[FW_SINGLE_PACKET_SIZE] = {-1}; //
  2057. unsigned char i = 0;
  2058. unsigned char last_package_len = 0;
  2059. static unsigned int current_checksum = 0;
  2060. if (zigbee_uart_rx_buf[offset + DATA_START] == 0x01) // status check
  2061. return;
  2062. while (i < 8)
  2063. {
  2064. if (current_mcu_pid[i] != zigbee_uart_rx_buf[offset + DATA_START + 1 + i]) // pid check
  2065. return;
  2066. i++;
  2067. }
  2068. if (ota_fw_info.mcu_ota_ver != zigbee_uart_rx_buf[offset + DATA_START + 9]) // version check
  2069. return;
  2070. i = 0;
  2071. while (i < 4)
  2072. {
  2073. fw_offset |= (zigbee_uart_rx_buf[offset + DATA_START + 10 + i] << (24 - i * 8)); // offset
  2074. i++;
  2075. }
  2076. i = 0;
  2077. if (ota_fw_info.mcu_current_offset == fw_offset)
  2078. {
  2079. // if ((ota_fw_info.mcu_ota_fw_size - fw_offset) / FW_SINGLE_PACKET_SIZE != 0)
  2080. if (((ota_fw_info.mcu_ota_fw_size - fw_offset) / FW_SINGLE_PACKET_SIZE != 0) && (ota_fw_info.mcu_ota_fw_size != (fw_offset + FW_SINGLE_PACKET_SIZE)))
  2081. // if (((ota_fw_info.mcu_ota_fw_size - fw_offset) / FW_SINGLE_PACKET_SIZE != 0)&&((ota_fw_info.mcu_ota_fw_size - fw_offset) % FW_SINGLE_PACKET_SIZE != 0))
  2082. {
  2083. if (ota_fw_info.mcu_current_offset == 0)
  2084. {
  2085. current_checksum = 0;
  2086. }
  2087. while (i < FW_SINGLE_PACKET_SIZE)
  2088. {
  2089. fw_data[i] = zigbee_uart_rx_buf[offset + DATA_START + 14 + i]; // fw data
  2090. current_checksum += fw_data[i];
  2091. i++;
  2092. }
  2093. ota_fw_info.mcu_current_offset += FW_SINGLE_PACKET_SIZE;
  2094. ota_fw_data_handle(fw_offset, &fw_data[0], FW_SINGLE_PACKET_SIZE); // OTA paket data handle
  2095. }
  2096. else
  2097. {
  2098. i = 0;
  2099. // last_package_len = ota_fw_info.mcu_ota_fw_size - fw_offset;
  2100. if ((ota_fw_info.mcu_ota_fw_size - fw_offset) % FW_SINGLE_PACKET_SIZE != 0)
  2101. {
  2102. last_package_len = ota_fw_info.mcu_ota_fw_size - fw_offset;
  2103. }
  2104. else
  2105. {
  2106. last_package_len = FW_SINGLE_PACKET_SIZE;
  2107. }
  2108. while (i < last_package_len)
  2109. {
  2110. fw_data[i] = zigbee_uart_rx_buf[offset + DATA_START + 14 + i];
  2111. current_checksum += fw_data[i];
  2112. i++;
  2113. }
  2114. ota_fw_info.mcu_current_offset += last_package_len;
  2115. if (ota_fw_info.mcu_ota_checksum != current_checksum)
  2116. {
  2117. // ota failure report ota failure and clear ota struct
  2118. mcu_ota_result_report(1); // failed
  2119. }
  2120. else
  2121. {
  2122. // ota sucess
  2123. mcu_ota_result_report(0); // seccess
  2124. }
  2125. ota_fw_data_handle(fw_offset, &fw_data[0], last_package_len); // OTA paket data handle
  2126. current_checksum = 0;
  2127. }
  2128. }
  2129. else
  2130. {
  2131. // ota request timeout, then restart ota request from ota_fw_info.mcu_ota_fw_size
  2132. }
  2133. }
  2134. static void report_mcu_ota_result(unsigned char res)
  2135. {
  2136. unsigned short length;
  2137. if ((res == 0) || (res == 1))
  2138. {
  2139. length = set_zigbee_uart_byte(length, res);
  2140. zigbee_uart_write_frame(MCU_OTA_NOTIFY_CMD, length);
  2141. }
  2142. }
  2143. /**
  2144. * @brief mcu ota data result notify
  2145. * @param[in] {void}
  2146. * @return void
  2147. */
  2148. void mcu_ota_result_event(unsigned char offset)
  2149. {
  2150. unsigned short k, Ret;
  2151. u32 temp_buff[256];
  2152. unsigned char status = zigbee_uart_rx_buf[offset + DATA_START];
  2153. if (status == 0x00)
  2154. {
  2155. // 升级成功,用户提示
  2156. IAPUpdateFlag = 1;
  2157. // zzw ota must add
  2158. /* for (k = 0; k < 256; k++)
  2159. {
  2160. temp_buff[k] = flash_word_read(OTA_STATE_DATA_ADD + (4 * k)); // 1.取出程序运行区代码数据
  2161. }
  2162. temp_buff[0] = IAPUpdateFlag;
  2163. delay_1ms(10);
  2164. Ret = flash_page_write(OTA_STATE_DATA_ADD, temp_buff); // 2.将取出的运行区代码写入临时区
  2165. delay_1ms(20);
  2166. flash_word_write (OTA_STATE_DATA_ADD,IAPUpdateFlag);
  2167. delay_1ms(500);
  2168. NVIC_SystemReset(); // add by zzw 系统复位函数
  2169. */
  2170. }
  2171. else if (status == 0x01)
  2172. {
  2173. }
  2174. }
  2175. /**
  2176. * @brief mcu ota data handle
  2177. * @param[in] {fw_offset} frame offset
  2178. * @param[in] {data} received data
  2179. * @return void
  2180. */
  2181. void ota_fw_data_handle(unsigned int fw_offset, char *data1, unsigned char data_len)
  2182. {
  2183. unsigned short i = 0;
  2184. unsigned short update = 1;
  2185. unsigned long app_newcode_add = 0; // 读flash的时候的地址变量,新代码区
  2186. unsigned short temp = 0;
  2187. unsigned long write_data;
  2188. //"请在该函数处理固件包数据"
  2189. //"received frame data, should save in flash, mcu should realize this fuction, and delete this line "
  2190. // 取出数据存入falsh,建议延用‘ota_fw_info’全局变量,不需定义其他全局变量,可维护数据包长度等
  2191. if (fw_offset == 0)
  2192. {
  2193. // zzw ota must add
  2194. /*app_newcode_add = OTA_NEW_CODE_START_ADD;
  2195. fmc_unlock();
  2196. for (i = 0; i < 26; i++)
  2197. {
  2198. fmc_page_erase(app_newcode_add + i * 1024);
  2199. }
  2200. fmc_lock();*/
  2201. }
  2202. OTA_Reciv_Datalen = OTA_Reciv_Datalen + data_len;
  2203. // zzw ota must add
  2204. // app_newcode_add = OTA_NEW_CODE_START_ADD + fw_offset;
  2205. if (data_len == FW_SINGLE_PACKET_SIZE) // 整包数据
  2206. {
  2207. // zzw ota must add
  2208. /* for (i = 0; i < (FW_SINGLE_PACKET_SIZE / 4); i++)
  2209. {
  2210. write_data = 0;
  2211. write_data = data[i * 4 + 3];
  2212. write_data = (write_data << 8) + data[i * 4 + 2];
  2213. write_data = (write_data << 8) + data[i * 4 + 1];
  2214. write_data = (write_data << 8) + data[i * 4];
  2215. flash_word_write(app_newcode_add, write_data);
  2216. app_newcode_add = app_newcode_add + 4;
  2217. }*/
  2218. }
  2219. else // 最后一包非整包数据
  2220. {
  2221. temp = data_len % 4;
  2222. if (temp == 0)
  2223. {
  2224. // zzw ota must add
  2225. /*for (i = 0; i < (data_len / 4); i++)
  2226. {
  2227. write_data = 0;
  2228. write_data = data[i * 4 + 3];
  2229. write_data = (write_data << 8) + data[i * 4 + 2];
  2230. write_data = (write_data << 8) + data[i * 4 + 1];
  2231. write_data = (write_data << 8) + data[i * 4];
  2232. flash_word_write(app_newcode_add, write_data);
  2233. app_newcode_add = app_newcode_add + 4;
  2234. }*/
  2235. }
  2236. }
  2237. // if(OTA_Reciv_Datalen == ota_fw_info.mcu_ota_fw_size) //接收数据完成停止获取
  2238. // {
  2239. // update = 0;
  2240. // }
  2241. if (update) // 数据存储完毕,继续调用获取数据命令
  2242. {
  2243. mcu_ota_fw_request(); // 固件升级
  2244. }
  2245. // #error "请在该函数处理固件包数据,并删除该行"
  2246. }
  2247. #endif
  2248. #ifdef BEACON_TEST
  2249. /**
  2250. * @brief beacon test notify,which used in testing
  2251. * @param[in] {void}
  2252. * @return void
  2253. */
  2254. void mcu_received_beacon_test_handle(void)
  2255. {
  2256. unsigned short length = 0;
  2257. length = set_zigbee_uart_byte(length, 0x00);
  2258. zigbee_uart_write_frame(SEND_BEACON_NOTIFY_CMD, length);
  2259. // then start test
  2260. // add by zzw 产测
  2261. /*if(burn_in_test_timeout<=300)//开机30S内
  2262. {
  2263. burn_in_test_start=1;
  2264. //burn_in_test_counter=0;
  2265. }*/
  2266. }
  2267. #endif
  2268. #ifdef CHECK_ZIGBEE_NETWORK
  2269. /**
  2270. * @brief check zigbee nwkstate,before start join nwk, check nwk if state is not 0x02,can start jion,
  2271. * else delay 5s
  2272. *
  2273. * @param[in] {void}
  2274. * @return void
  2275. */
  2276. void mcu_check_zigbee_nwk_state(void)
  2277. {
  2278. unsigned short length = 0;
  2279. zigbee_uart_write_frame(CHECK_ZIGBEE_NETWORK_CMD, length);
  2280. // then start test
  2281. }
  2282. #endif
  2283. void zigbee_notify_factory_new_hanlde(void) //app操作删除设备并清理数据
  2284. {
  2285. unsigned short length = 0;
  2286. unsigned short i;
  2287. length = set_zigbee_uart_byte(length, 0x01);
  2288. zigbee_uart_write_frame(ZIGBEE_FACTORY_NEW_CMD, length);
  2289. // then start test
  2290. // add by zzw 20240207 APP删除设备后自动入网开启
  2291. ZG_Joining = CONDITION_BEFOR_JOINING_TO_JOINING; // 配网倒计时
  2292. ZG_JoinCounter = 0;
  2293. ledSetParam(6, 12); // 高速闪烁,所有指示灯8Hz闪烁(表现为三位开关三个指示灯都闪烁)
  2294. // mcu_join_zigbee(); // 发送入网指令
  2295. switchState.zigbee_work_state = 0; // 设备被删除
  2296. //此处增加删除电量历史数据
  2297. for(i = 0; i < 20; i++)
  2298. {
  2299. power_data[i] = 0xFF;
  2300. }
  2301. user_write_INFO_byte(INFO6_ADDR, power_data, 20);
  2302. // user_write_INFO_byte(INFO7_ADDR, power_data, 20);
  2303. }
  2304. #ifdef READ_DP_DATA_NOTIFY
  2305. /**
  2306. * @brief when gateway repower or relink clould, or zigbee module join sucess, repower, this commod will notify
  2307. * mcu, to sys dp data, mcu itself decide whether report.
  2308. *
  2309. * @param[in] {void}
  2310. * @return void
  2311. */
  2312. void read_dp_data_notify_hanlde(void)
  2313. {
  2314. unsigned short length = 0;
  2315. length = set_zigbee_uart_byte(length, 0x01);
  2316. zigbee_uart_write_frame(ZIGBEE_FACTORY_NEW_CMD, length);
  2317. // then start test
  2318. }
  2319. #endif
  2320. /*
  2321. * 函数:HexToDisHex
  2322. * 功能:将十六进制数转换成十六进制字符形式
  2323. * pbDest:存放目标十六进制字符串
  2324. * pbSrc:被转化的十六进制数
  2325. * nLen:被转化的十六进制数的长度
  2326. */
  2327. void HexToDisHex(unsigned char *pbDest, unsigned char *pbSrc, int nLen)
  2328. {
  2329. unsigned char c0, c1;
  2330. unsigned char buf[2];
  2331. unsigned char *dst = pbDest;
  2332. unsigned char *src = pbSrc;
  2333. int index;
  2334. for (index = 0; index < nLen; index++)
  2335. {
  2336. c0 = *src >> 4;
  2337. if (c0 >= 0x0 && c0 <= 0x9)
  2338. {
  2339. buf[0] = c0 - 0 + '0';
  2340. }
  2341. else
  2342. {
  2343. buf[0] = c0 - 10 + 'a';
  2344. }
  2345. c1 = *src++ & 0x0F;
  2346. if (c1 >= 0x0 && c1 <= 0x9)
  2347. {
  2348. buf[1] = c1 - 0 + '0';
  2349. }
  2350. else
  2351. {
  2352. buf[1] = c1 - 10 + 'a';
  2353. }
  2354. *dst = buf[0];
  2355. dst++;
  2356. *dst = buf[1];
  2357. dst++;
  2358. }
  2359. }
  2360. /*
  2361. * DisHexToHex
  2362. * 功能:将字符串形式的十六进制数转换成十六进制
  2363. * pbDest:存放转换后的十六进制数
  2364. * pbSrc:源字符数组,存放要转换的十六进制字符串形式的数据
  2365. * nLen:被转化的十六进制数字符串数据的长度
  2366. */
  2367. void DisHexToHex(unsigned char *pbDest, unsigned char *pbSrc, int nLen)
  2368. {
  2369. unsigned char *dst = pbDest;
  2370. unsigned char *src = pbSrc;
  2371. unsigned char h1, h2;
  2372. unsigned char s1, s2;
  2373. int i;
  2374. for (i = 0; i < nLen; i++)
  2375. {
  2376. h1 = src[2 * i];
  2377. h2 = src[2 * i + 1];
  2378. s1 = toupper(h1) - 0x30;
  2379. if (s1 > 9)
  2380. s1 -= 7;
  2381. s2 = toupper(h2) - 0x30;
  2382. if (s2 > 9)
  2383. s2 -= 7;
  2384. *dst = (s1 << 4) + s2;
  2385. dst++;
  2386. }
  2387. }