|
@@ -0,0 +1,805 @@
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 1
|
|
|
+
|
|
|
+
|
|
|
+C51 COMPILER V9.53.0.0, COMPILATION OF MODULE SYSTEM
|
|
|
+OBJECT MODULE PLACED IN .\Objects\system.obj
|
|
|
+COMPILER INVOKED BY: D:\Keil_c51\C51\BIN\C51.EXE system.c LARGE OPTIMIZE(8,SPEED) BROWSE INCDIR(..\..\..\Drivers) DEBUG
|
|
|
+ -OBJECTEXTEND PRINT(.\Listings\system.lst) TABS(2) OBJECT(.\Objects\system.obj)
|
|
|
+
|
|
|
+line level source
|
|
|
+
|
|
|
+ 1 /**
|
|
|
+ 2 * @file system.c
|
|
|
+ 3 * @brief this file contains frame analysis of communication between MCU and zigbee
|
|
|
+ 4 * and construct these functions which used send data in a frame format
|
|
|
+ 5 * @author qinlang
|
|
|
+ 6 * @date 2022.05.06
|
|
|
+ 7 * @par email:
|
|
|
+ 8 * @par email:qinlang.chen@tuya.com
|
|
|
+ 9 * @copyright HANGZHOU TUYA INFORMATION TECHNOLOGY CO.,LTD
|
|
|
+ 10 * @par company
|
|
|
+ 11 * http://www.tuya.com
|
|
|
+ 12 */
|
|
|
+ 13
|
|
|
+ 14
|
|
|
+ 15 #define SYSTEM_GLOBAL
|
|
|
+ 16
|
|
|
+ 17 #include "zigbee.h"
|
|
|
+ 18 #include "iap.h"
|
|
|
+ 19 #include "HLW8110.h"
|
|
|
+*** WARNING C318 IN LINE 3 OF HLW8110.h: can't open file 'sys.h'
|
|
|
+*** WARNING C318 IN LINE 4 OF HLW8110.h: can't open file 'core_cm3.h'
|
|
|
+ 20
|
|
|
+ 21 extern const DOWNLOAD_CMD_S download_cmd[];
|
|
|
+ 22
|
|
|
+ 23
|
|
|
+ 24 #ifdef SUPPORT_MCU_RTC_CHECK
|
|
|
+ const unsigned char mon_table[12]={31,28,31,30,31,30,31,31,30,31,30,31};
|
|
|
+ #endif
|
|
|
+ 27
|
|
|
+ 28 #ifdef CHECK_MCU_TYPE
|
|
|
+ MCU_TYPE_E mcu_type = MCU_TYPE_DC_POWER;
|
|
|
+ #endif
|
|
|
+ 31
|
|
|
+ 32
|
|
|
+ 33 static volatile unsigned short global_seq_num;
|
|
|
+ 34
|
|
|
+ 35 #ifdef CHECK_MCU_TYPE
|
|
|
+ static void response_mcu_type(void);
|
|
|
+ #endif
|
|
|
+ 38
|
|
|
+ 39
|
|
|
+ 40 #ifdef SET_ZIGBEE_NWK_PARAMETER
|
|
|
+ nwk_parameter_t nwk_paremeter;
|
|
|
+ #endif
|
|
|
+ 43
|
|
|
+ 44
|
|
|
+ 45
|
|
|
+ 46 #ifdef SET_ZIGBEE_NWK_PARAMETER
|
|
|
+ void init_nwk_paremeter(void)
|
|
|
+ {
|
|
|
+ #error "please call this fuction in main init"
|
|
|
+ nwk_paremeter.fast_poll_period = 0xfffe;
|
|
|
+ nwk_paremeter.heart_period = 0xfffe;
|
|
|
+ nwk_paremeter.join_nwk_time = 0xfffe;
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 2
|
|
|
+
|
|
|
+ nwk_paremeter.rejion_period = 0xfffe;
|
|
|
+ nwk_paremeter.poll_period = 0xfffe;
|
|
|
+ nwk_paremeter.fast_poll_period = 0xfffe;
|
|
|
+ nwk_paremeter.poll_failure_times = 0xfe;
|
|
|
+ nwk_paremeter.rejoin_try_times = 0xfe;
|
|
|
+ nwk_paremeter.app_trigger_rejoin = 0xfe;
|
|
|
+ nwk_paremeter.rf_send_power = 0xfe;
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ 62
|
|
|
+ 63 /**
|
|
|
+ 64 * @brief get frame seq_num
|
|
|
+ 65 * @param[in] {void}
|
|
|
+ 66 * @return seq_num
|
|
|
+ 67 */
|
|
|
+ 68 static unsigned short seq_num_get(void)
|
|
|
+ 69 {
|
|
|
+ 70 1 global_seq_num ++;
|
|
|
+ 71 1 if(global_seq_num > 0xfff0){
|
|
|
+ 72 2 global_seq_num = 1;
|
|
|
+ 73 2 }
|
|
|
+ 74 1 return global_seq_num;
|
|
|
+ 75 1 }
|
|
|
+ 76
|
|
|
+ 77 /**
|
|
|
+ 78 * @brief padding a byte in send buf base on dest
|
|
|
+ 79 * @param[in] {dest} the location of padding byte
|
|
|
+ 80 * @param[in] {byte} padding byte
|
|
|
+ 81 * @return sum of frame after this operation
|
|
|
+ 82 */
|
|
|
+ 83 unsigned short set_zigbee_uart_byte(unsigned short dest, unsigned char byte)
|
|
|
+ 84 {
|
|
|
+ 85 1 unsigned char *obj = (unsigned char *)zigbee_uart_tx_buf + DATA_START + dest;
|
|
|
+ 86 1
|
|
|
+ 87 1 *obj = byte;
|
|
|
+ 88 1 dest += 1;
|
|
|
+ 89 1
|
|
|
+ 90 1 return dest;
|
|
|
+ 91 1 }
|
|
|
+ 92
|
|
|
+ 93 /**
|
|
|
+ 94 * @brief padding buf in send buf base on dest
|
|
|
+ 95 * @param[in] {dest} the location of padding
|
|
|
+ 96 * @param[in] {src} the head address of padding buf
|
|
|
+ 97 * @param[in] {len} the length of padding buf
|
|
|
+ 98 * @return sum of frame after this operation
|
|
|
+ 99 */
|
|
|
+ 100 unsigned short set_zigbee_uart_buffer(unsigned short dest, unsigned char *src, unsigned short len)
|
|
|
+ 101 {
|
|
|
+ 102 1 unsigned char *obj = (unsigned char *)zigbee_uart_tx_buf + DATA_START + dest;
|
|
|
+ 103 1
|
|
|
+ 104 1 my_memcpy(obj,src,len);
|
|
|
+ 105 1
|
|
|
+ 106 1 dest += len;
|
|
|
+ 107 1 return dest;
|
|
|
+ 108 1 }
|
|
|
+ 109
|
|
|
+ 110 /**
|
|
|
+ 111 * @brief send len bytes data
|
|
|
+ 112 * @param[in] {in} the head address of send data
|
|
|
+ 113 * @param[in] {len} the length of send data
|
|
|
+ 114 * @return void
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 3
|
|
|
+
|
|
|
+ 115 */
|
|
|
+ 116 void zigbee_uart_write_data(unsigned char *in, unsigned short len)
|
|
|
+ 117 {
|
|
|
+ 118 1 if((NULL == in) || (0 == len)){
|
|
|
+ 119 2 return;
|
|
|
+ 120 2 }
|
|
|
+ 121 1
|
|
|
+ 122 1 while(len --){
|
|
|
+ 123 2 uart_transmit_output(*in);
|
|
|
+ 124 2 in ++;
|
|
|
+ 125 2 }
|
|
|
+ 126 1 }
|
|
|
+ 127
|
|
|
+ 128 /**
|
|
|
+ 129 * @brief calculate the sum of the array
|
|
|
+ 130 * @param[in] {pack} the head address of array
|
|
|
+ 131 * @param[in] {pack_len} the length of array
|
|
|
+ 132 * @return sum
|
|
|
+ 133 */
|
|
|
+ 134 unsigned char get_check_sum(unsigned char *pack, unsigned short pack_len)
|
|
|
+ 135 {
|
|
|
+ 136 1 unsigned short i;
|
|
|
+ 137 1 unsigned char check_sum = 0;
|
|
|
+ 138 1
|
|
|
+ 139 1 for(i = 0; i < pack_len; i ++){
|
|
|
+ 140 2 check_sum += *pack ++;
|
|
|
+ 141 2 }
|
|
|
+ 142 1
|
|
|
+ 143 1 return check_sum;
|
|
|
+ 144 1 }
|
|
|
+ 145
|
|
|
+ 146 /**
|
|
|
+ 147 * @brief send a frame data
|
|
|
+ 148 * @param[in] {fr_cmd} frame cmd id
|
|
|
+ 149 * @param[in] {len} len of frame data
|
|
|
+ 150 * @return void
|
|
|
+ 151 */
|
|
|
+ 152 void zigbee_uart_write_frame(unsigned char fr_cmd, unsigned short len)
|
|
|
+ 153 {
|
|
|
+ 154 1 unsigned char check_sum = 0;
|
|
|
+ 155 1 unsigned short seq;
|
|
|
+ 156 1
|
|
|
+ 157 1 zigbee_uart_tx_buf[HEAD_FIRST] = FIRST_FRAME_HEAD;
|
|
|
+ 158 1 zigbee_uart_tx_buf[HEAD_SECOND] = SECOND_FRAME_HEAD;
|
|
|
+ 159 1 zigbee_uart_tx_buf[PROTOCOL_VERSION] = SERIAL_PROTOCOL_VER;
|
|
|
+ 160 1
|
|
|
+ 161 1
|
|
|
+ 162 1 seq = seq_num_get();
|
|
|
+ 163 1 zigbee_uart_tx_buf[SEQ_HIGH] = (seq << 8);
|
|
|
+ 164 1 zigbee_uart_tx_buf[SEQ_LOW] = (seq & 0xff);
|
|
|
+ 165 1
|
|
|
+ 166 1
|
|
|
+ 167 1 zigbee_uart_tx_buf[FRAME_TYPE] = fr_cmd;
|
|
|
+ 168 1 zigbee_uart_tx_buf[LENGTH_HIGH] = len >> 8;
|
|
|
+ 169 1 zigbee_uart_tx_buf[LENGTH_LOW] = len & 0xff;
|
|
|
+ 170 1
|
|
|
+ 171 1 len += PROTOCOL_HEAD;
|
|
|
+ 172 1
|
|
|
+ 173 1 check_sum = get_check_sum((unsigned char *)zigbee_uart_tx_buf, len-1);
|
|
|
+ 174 1 zigbee_uart_tx_buf[len -1] = check_sum;
|
|
|
+ 175 1
|
|
|
+ 176 1 zigbee_uart_write_data((unsigned char *)zigbee_uart_tx_buf, len);
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 4
|
|
|
+
|
|
|
+ 177 1 }
|
|
|
+ 178
|
|
|
+ 179 /**
|
|
|
+ 180 * @brief send product info and mcu version
|
|
|
+ 181 * @param[in] {void}
|
|
|
+ 182 * @return void
|
|
|
+ 183 */
|
|
|
+ 184 static void product_info_update(void)
|
|
|
+ 185 {
|
|
|
+ 186 1 unsigned short length = 0;
|
|
|
+ 187 1 length = set_zigbee_uart_buffer(length, "{\"p\":\"", my_strlen("{\"p\":\""));
|
|
|
+ 188 1 length = set_zigbee_uart_buffer(length,(unsigned char *)PRODUCT_KEY,my_strlen((unsigned char *)PRODUCT_K
|
|
|
+ -EY));
|
|
|
+ 189 1 length = set_zigbee_uart_buffer(length, "\",\"v\":\"", my_strlen("\",\"v\":\""));
|
|
|
+ 190 1 length = set_zigbee_uart_buffer(length,(unsigned char *)MCU_VER,my_strlen((unsigned char *)MCU_VER));
|
|
|
+ 191 1 length = set_zigbee_uart_buffer(length, "\"}", my_strlen("\"}"));
|
|
|
+ 192 1 zigbee_uart_write_frame(PRODUCT_INFO_CMD, length);
|
|
|
+ 193 1 }
|
|
|
+ 194
|
|
|
+ 195 /**
|
|
|
+ 196 * @brief get the serial number of dpid in dp array
|
|
|
+ 197 * @param[in] {dpid} dp id
|
|
|
+ 198 * @return serial number of dp
|
|
|
+ 199 */
|
|
|
+ 200 static unsigned char get_dowmload_dpid_index(unsigned char dpid)
|
|
|
+ 201 {
|
|
|
+ 202 1 unsigned char index;
|
|
|
+ 203 1 unsigned char total = get_download_cmd_total();
|
|
|
+ 204 1
|
|
|
+ 205 1 for(index = 0; index < total; index ++){
|
|
|
+ 206 2 if(download_cmd[index].dp_id == dpid){
|
|
|
+ 207 3 break;
|
|
|
+ 208 3 }
|
|
|
+ 209 2 }
|
|
|
+ 210 1 return index;
|
|
|
+ 211 1 }
|
|
|
+ 212
|
|
|
+ 213 /**
|
|
|
+ 214 * @brief handle received dp data from zigbee module
|
|
|
+ 215 * @param[in] {value} dp data
|
|
|
+ 216 * @return result of handle
|
|
|
+ 217 */
|
|
|
+ 218 static unsigned char zigbee_data_point_handle(const unsigned char value[])
|
|
|
+ 219 {
|
|
|
+ 220 1 unsigned char dp_id,index;
|
|
|
+ 221 1 unsigned char dp_type;
|
|
|
+ 222 1 unsigned char ret;
|
|
|
+ 223 1 unsigned short dp_len;
|
|
|
+ 224 1
|
|
|
+ 225 1 dp_id = value[0];
|
|
|
+ 226 1 dp_type = value[1];
|
|
|
+ 227 1 dp_len = value[2] * 0x100;
|
|
|
+ 228 1 dp_len += value[3];
|
|
|
+ 229 1
|
|
|
+ 230 1
|
|
|
+ 231 1 index = get_dowmload_dpid_index(dp_id);
|
|
|
+ 232 1
|
|
|
+ 233 1 if(dp_type != download_cmd[index].dp_type){
|
|
|
+ 234 2 return FALSE;
|
|
|
+ 235 2 }
|
|
|
+ 236 1 else{
|
|
|
+ 237 2 ret = dp_download_handle(dp_id,value + 4,dp_len);
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 5
|
|
|
+
|
|
|
+ 238 2 }
|
|
|
+ 239 1
|
|
|
+ 240 1 return ret;
|
|
|
+ 241 1 }
|
|
|
+ 242
|
|
|
+ 243 /**
|
|
|
+ 244 * @brief handle received frame from zigbee module baseon frame cmd id
|
|
|
+ 245 * @param[in] {void}
|
|
|
+ 246 * @return result of handle
|
|
|
+ 247 */
|
|
|
+ 248 int data_handle(unsigned short offset)
|
|
|
+ 249 {
|
|
|
+ 250 1 unsigned char cmd_type = 0;
|
|
|
+ 251 1 unsigned short total_len = 0, seq_num = 0;
|
|
|
+ 252 1 unsigned short dp_len;
|
|
|
+ 253 1 unsigned char ret;
|
|
|
+ 254 1 unsigned short i;
|
|
|
+ 255 1
|
|
|
+ 256 1 cmd_type = zigbee_uart_rx_buf[offset + FRAME_TYPE];
|
|
|
+ 257 1
|
|
|
+ 258 1 total_len = zigbee_uart_rx_buf[offset + LENGTH_HIGH] * 0x100;
|
|
|
+ 259 1 total_len += zigbee_uart_rx_buf[offset + LENGTH_LOW];
|
|
|
+ 260 1
|
|
|
+ 261 1 seq_num = zigbee_uart_rx_buf[offset + SEQ_HIGH] << 8;
|
|
|
+ 262 1 seq_num += zigbee_uart_rx_buf[offset + SEQ_LOW];
|
|
|
+ 263 1
|
|
|
+ 264 1 switch(cmd_type)
|
|
|
+ 265 1 {
|
|
|
+ 266 2 case ZIGBEE_FACTORY_NEW_CMD:{
|
|
|
+ 267 3 zigbee_notify_factory_new_hanlde(); // response,APP删除设备,这里确认是否恢复出厂设置
|
|
|
+*** WARNING C206 IN LINE 267 OF system.c: 'zigbee_notify_factory_new_hanlde': missing function-prototype
|
|
|
+ 268 3 }
|
|
|
+ 269 2 break;
|
|
|
+ 270 2
|
|
|
+ 271 2 case PRODUCT_INFO_CMD:{
|
|
|
+ 272 3 product_info_update();
|
|
|
+ 273 3 }
|
|
|
+ 274 2 break;
|
|
|
+ 275 2
|
|
|
+ 276 2 case ZIGBEE_STATE_CMD:{
|
|
|
+ 277 3 unsigned char current_state = zigbee_uart_rx_buf[offset + DATA_START];
|
|
|
+ 278 3 zigbee_work_state_event(current_state);
|
|
|
+ 279 3 }
|
|
|
+ 280 2 break;
|
|
|
+ 281 2
|
|
|
+ 282 2 case ZIGBEE_CFG_CMD:{
|
|
|
+ 283 3 mcu_reset_zigbee_event(zigbee_uart_rx_buf[offset + DATA_START]);
|
|
|
+ 284 3 }
|
|
|
+ 285 2 break;
|
|
|
+ 286 2
|
|
|
+ 287 2 case ZIGBEE_DATA_REQ_CMD:{
|
|
|
+ 288 3 for(i = 0;i < total_len;){
|
|
|
+ 289 4 dp_len = zigbee_uart_rx_buf[offset + DATA_START + i + 2] * 0x100;
|
|
|
+ 290 4 dp_len += zigbee_uart_rx_buf[offset + DATA_START + i + 3];
|
|
|
+ 291 4 ret = zigbee_data_point_handle((unsigned char *)zigbee_uart_rx_buf + offset + DATA_START + i);
|
|
|
+ 292 4
|
|
|
+ 293 4 if(SUCCESS == ret){
|
|
|
+ 294 5
|
|
|
+ 295 5 }
|
|
|
+ 296 4 else{
|
|
|
+ 297 5
|
|
|
+ 298 5 }
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 6
|
|
|
+
|
|
|
+ 299 4 i += (dp_len + 4);
|
|
|
+ 300 4 }
|
|
|
+ 301 3 }
|
|
|
+ 302 2 break;
|
|
|
+ 303 2 case DATA_DATA_RES_CMD:{
|
|
|
+ 304 3
|
|
|
+ 305 3 }
|
|
|
+ 306 2 case DATA_REPORT_CMD:{
|
|
|
+ 307 3
|
|
|
+ 308 3 }
|
|
|
+ 309 2 break;
|
|
|
+ 310 2
|
|
|
+ 311 2 case QUERY_KEY_INFO_CMD:{
|
|
|
+ 312 3
|
|
|
+ 313 3 }
|
|
|
+ 314 2 break;
|
|
|
+ 315 2
|
|
|
+ 316 2 case CALL_SCENE_CMD:{
|
|
|
+ 317 3
|
|
|
+ 318 3 }
|
|
|
+ 319 2 break;
|
|
|
+ 320 2
|
|
|
+ 321 2 case ZIGBEE_RF_TEST_CMD:{
|
|
|
+ 322 3
|
|
|
+ 323 3 }
|
|
|
+ 324 2 break;
|
|
|
+ 325 2
|
|
|
+ 326 2 case MCU_OTA_VERSION_CMD:{
|
|
|
+ 327 3 response_mcu_ota_version_event();
|
|
|
+ 328 3 }
|
|
|
+ 329 2 break;
|
|
|
+ 330 2 #ifdef SUPPORT_MCU_OTA
|
|
|
+ 331 2 case MCU_OTA_NOTIFY_CMD:{
|
|
|
+ 332 3 response_mcu_ota_notify_event(offset);
|
|
|
+ 333 3 }
|
|
|
+ 334 2 break;
|
|
|
+ 335 2
|
|
|
+ 336 2 case MCU_OTA_DATA_REQUEST_CMD:{
|
|
|
+ 337 3 mcu_ota_fw_request_event(offset);
|
|
|
+ 338 3 }
|
|
|
+ 339 2 break;
|
|
|
+ 340 2
|
|
|
+ 341 2 case MCU_OTA_RESULT_CMD:{
|
|
|
+ 342 3 mcu_ota_result_event(offset);
|
|
|
+ 343 3 }
|
|
|
+ 344 2 break;
|
|
|
+ 345 2 #endif
|
|
|
+ 346 2 case CHECK_MCU_TYPE_CMD:
|
|
|
+ 347 2 {
|
|
|
+ 348 3 #ifdef CHECK_MCU_TYPE
|
|
|
+ response_mcu_type();
|
|
|
+ #endif
|
|
|
+ 351 3 }
|
|
|
+ 352 2 break;
|
|
|
+ 353 2
|
|
|
+ 354 2 case TIME_GET_CMD:{
|
|
|
+ 355 3 #ifdef SUPPORT_MCU_RTC_CHECK
|
|
|
+ mcu_write_rtctime((unsigned char *)(zigbee_uart_rx_buf + offset + DATA_START));
|
|
|
+ #endif
|
|
|
+ 358 3 }
|
|
|
+ 359 2 break;
|
|
|
+ 360 2
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 7
|
|
|
+
|
|
|
+ 361 2 #ifdef BEACON_TEST
|
|
|
+ case SEND_BEACON_NOTIFY_CMD:{
|
|
|
+ mcu_received_beacon_test_handle();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ #endif
|
|
|
+ 367 2
|
|
|
+ 368 2 case READ_MCU_DP_DATA_CMD:{ // gw read DP
|
|
|
+ 369 3 all_data_update();
|
|
|
+ 370 3 }
|
|
|
+ 371 2 break;
|
|
|
+ 372 2
|
|
|
+ 373 2 default:
|
|
|
+ 374 2 return 0;
|
|
|
+ 375 2 }
|
|
|
+ 376 1 return 1;
|
|
|
+ 377 1 }
|
|
|
+ 378
|
|
|
+ 379 /**
|
|
|
+ 380 * @brief mcu send a cmd which used to making zigbee module reset
|
|
|
+ 381 * @param[in] {void}
|
|
|
+ 382 * @return void
|
|
|
+ 383 */
|
|
|
+ 384 void mcu_exit_zigbee(void)
|
|
|
+ 385 {
|
|
|
+ 386 1 unsigned short length = 0;
|
|
|
+ 387 1 length = set_zigbee_uart_byte(length,0x00);
|
|
|
+ 388 1 zigbee_uart_write_frame(ZIGBEE_CFG_CMD, length);
|
|
|
+ 389 1 }
|
|
|
+ 390
|
|
|
+ 391 /**
|
|
|
+ 392 * @brief mcu send this commond starting zigbee module join network
|
|
|
+ 393 * this commond must be call after reveived checking proudect info, or after get zigbee network info
|
|
|
+ 394 * @param[in] {void}
|
|
|
+ 395 * @return void
|
|
|
+ 396 */
|
|
|
+ 397 void mcu_join_zigbee(void)
|
|
|
+ 398 {
|
|
|
+ 399 1 unsigned short length = 0;
|
|
|
+ 400 1 length = set_zigbee_uart_byte(length,0x01);
|
|
|
+ 401 1 zigbee_uart_write_frame(ZIGBEE_CFG_CMD, length);
|
|
|
+ 402 1 }
|
|
|
+ 403
|
|
|
+ 404 /**
|
|
|
+ 405 * @brief mcu send a cmd which used to getting zigbee network state
|
|
|
+ 406 * @param[in] {void}
|
|
|
+ 407 * @return void
|
|
|
+ 408 */
|
|
|
+ 409 void mcu_get_zigbee_state(void)
|
|
|
+ 410 {
|
|
|
+ 411 1 zigbee_uart_write_frame(ZIGBEE_STATE_CMD, 0);
|
|
|
+ 412 1 }
|
|
|
+ 413
|
|
|
+ 414
|
|
|
+ 415 #ifdef CHECK_MCU_TYPE
|
|
|
+ /**
|
|
|
+ * @brief response zigbee check mcu type cmd
|
|
|
+ * @param[in] {void}
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ static void response_mcu_type(void)
|
|
|
+ {
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 8
|
|
|
+
|
|
|
+ unsigned short length = 0;
|
|
|
+ length = set_zigbee_uart_byte(length,mcu_type);
|
|
|
+ zigbee_uart_write_frame(CHECK_MCU_TYPE_CMD, length);
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ 428
|
|
|
+ 429
|
|
|
+ 430
|
|
|
+ 431 #ifdef SUPPORT_MCU_RTC_CHECK
|
|
|
+ /**
|
|
|
+ * @brief mcu send a cmd which used to getting timestamp
|
|
|
+ * @param[in] {void}
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ void mcu_get_system_time(void)
|
|
|
+ {
|
|
|
+ zigbee_uart_write_frame(TIME_GET_CMD,0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief is a leap year
|
|
|
+ * @param[in] {pyear}
|
|
|
+ * @return leap year return 1
|
|
|
+ */
|
|
|
+ static unsigned char Is_Leap_Year(unsigned int pyear)
|
|
|
+ {
|
|
|
+ if(0 == (pyear%4)) {
|
|
|
+ if(0 == (pyear%100)){
|
|
|
+ if(0 == (pyear%400))
|
|
|
+ return 1;
|
|
|
+ else
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief get calendar time from timestamp
|
|
|
+ * @param[in] {secCount} input timestamp
|
|
|
+ * @param[out] {calendar} output calendar
|
|
|
+ * @return result of changing
|
|
|
+ */
|
|
|
+ static unsigned char RTC_Get(unsigned int secCount,_calendar_obj *calendar)
|
|
|
+ {
|
|
|
+ static unsigned int dayCount=0;
|
|
|
+ unsigned int tmp=0;
|
|
|
+ unsigned int tmp1=0;
|
|
|
+
|
|
|
+ tmp=secCount/86400;
|
|
|
+
|
|
|
+ if(dayCount!=tmp){
|
|
|
+ dayCount=tmp;
|
|
|
+ tmp1=1970;
|
|
|
+
|
|
|
+ while(tmp>=365){
|
|
|
+ if(Is_Leap_Year(tmp1)){
|
|
|
+ if(tmp>=366)
|
|
|
+ tmp-=366;
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 9
|
|
|
+
|
|
|
+ else{
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ tmp-=365;
|
|
|
+ tmp1++;
|
|
|
+ }
|
|
|
+ calendar->w_year=tmp1;
|
|
|
+ tmp1=0;
|
|
|
+
|
|
|
+ while(tmp>=28){
|
|
|
+ if(Is_Leap_Year(calendar->w_year)&&tmp1==1){
|
|
|
+ if(tmp>=29)
|
|
|
+ tmp-=29;
|
|
|
+ else
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ if(tmp>=mon_table[tmp1])
|
|
|
+ tmp-=mon_table[tmp1];
|
|
|
+ else
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ tmp1++;
|
|
|
+ }
|
|
|
+ calendar->w_month=tmp1+1;
|
|
|
+ calendar->w_date=tmp+1;
|
|
|
+ }
|
|
|
+
|
|
|
+ tmp=secCount%86400;
|
|
|
+ calendar->hour=tmp/3600;
|
|
|
+ calendar->min=(tmp%3600)/60;
|
|
|
+ calendar->sec=(tmp%3600)%60;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief calculta time from frame
|
|
|
+ * @param[in] {void}
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ void zigbee_timestamp_to_time(void)
|
|
|
+ {
|
|
|
+ unsigned int time_stamp = byte_to_int(timestamp);
|
|
|
+ RTC_Get(time_stamp,&_time);
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ 534
|
|
|
+ 535 #ifdef BROADCAST_DATA_SEND
|
|
|
+ /**
|
|
|
+ * @brief mcu can send a broadcast data in zigbee network
|
|
|
+ * @param[in] {buf} array of buf which to be sended
|
|
|
+ * @param[in] {buf_len} send buf length
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ void mcu_send_broadcast_data(unsigned char buf[], unsigned char buf_len)
|
|
|
+ {
|
|
|
+ unsigned short length = 0;
|
|
|
+ length = set_zigbee_uart_buffer(length,(unsigned char *)buf, buf_len);
|
|
|
+ zigbee_uart_write_frame(SEND_BROADCAST_DATA_CMD,length);
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 10
|
|
|
+
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ 549
|
|
|
+ 550 #ifdef SET_ZIGBEE_NWK_PARAMETER
|
|
|
+ /**
|
|
|
+ * @brief mcu can set zigbee nwk parameter
|
|
|
+ * @param[in] {parameter_t *}
|
|
|
+ * @param
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ void mcu_set_zigbee_nwk_parameter(nwk_parameter_t *Pparameter)
|
|
|
+ {
|
|
|
+ unsigned short length = 0;
|
|
|
+ #error "please set network parameter in here, when zigbee received this message, it will start reboot"
|
|
|
+ //Pparameter->app_trigger_rejoin = 0x00;
|
|
|
+ //Pparameter->fast_poll_period = 0x00;
|
|
|
+
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->heart_period >>8));
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->heart_period));
|
|
|
+
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->join_nwk_time >>8));
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->join_nwk_time));
|
|
|
+
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->rejion_period >>8));
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->rejion_period));
|
|
|
+
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->poll_period >>8));
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->poll_period));
|
|
|
+
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->fast_poll_period >>8));
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->fast_poll_period));
|
|
|
+
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->poll_failure_times));
|
|
|
+
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->app_trigger_rejoin));
|
|
|
+
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->rejoin_try_times));
|
|
|
+
|
|
|
+ length = set_zigbee_uart_byte(length,(Pparameter->rf_send_power));
|
|
|
+ zigbee_uart_write_frame(SET_ZIGBEE_NEK_PARAMETER_CMD,length);
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ 589
|
|
|
+ 590 /**
|
|
|
+ 591 * @brief mcu version string to char
|
|
|
+ 592 * @param[in] {void}
|
|
|
+ 593 * @return result of version
|
|
|
+ 594 */
|
|
|
+ 595 unsigned char get_current_mcu_fw_ver(void)
|
|
|
+ 596 {
|
|
|
+ 597 1 /*unsigned char *fw_ver = (unsigned char*) MCU_VER; //Current version
|
|
|
+ 598 1 unsigned char current_mcu_fw_ver = 0;
|
|
|
+ 599 1 if(assic_to_hex(fw_ver[5]) == -1){ // 3 number
|
|
|
+ 600 1 current_mcu_fw_ver = (assic_to_hex(fw_ver[0]) & 0x03) << 6; //high ver
|
|
|
+ 601 1 current_mcu_fw_ver |= (assic_to_hex(fw_ver[2]) & 0x03) << 4; //mid ver
|
|
|
+ 602 1 current_mcu_fw_ver |= (assic_to_hex(fw_ver[4]) & 0x0F); //low ver
|
|
|
+ 603 1 }
|
|
|
+ 604 1 else{ // 4 number
|
|
|
+ 605 1 current_mcu_fw_ver = (assic_to_hex(fw_ver[0]) & 0x03) << 6; //high ver
|
|
|
+ 606 1 current_mcu_fw_ver |= (assic_to_hex(fw_ver[2]) & 0x03) << 4; //mid ver
|
|
|
+ 607 1 current_mcu_fw_ver |= ((assic_to_hex(fw_ver[4])*10 + assic_to_hex(fw_ver[5])) & 0x0F); //low ver
|
|
|
+ 608 1 }
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 11
|
|
|
+
|
|
|
+ 609 1 return current_mcu_fw_ver;*/
|
|
|
+ 610 1 //modified by zzw 优化版本查询函数
|
|
|
+ 611 1 //unsigned char *fw_ver = (unsigned char*) MCU_VER; //Current version
|
|
|
+ 612 1 unsigned char fw_ver[10];//modified by zzw 20240326
|
|
|
+ 613 1 unsigned char current_mcu_fw_ver = 0;
|
|
|
+ 614 1
|
|
|
+ 615 1 my_memcpy(fw_ver, (unsigned char *)MCU_VER,my_strlen((unsigned char *)MCU_VER));
|
|
|
+ 616 1
|
|
|
+ 617 1
|
|
|
+ 618 1 if(my_strlen((unsigned char *)MCU_VER)<=5)//1.0.1,5个字节
|
|
|
+ 619 1 {
|
|
|
+ 620 2 // 3 number
|
|
|
+ 621 2 current_mcu_fw_ver = (assic_to_hex(fw_ver[0]) & 0x03) << 6; //high ver
|
|
|
+ 622 2 current_mcu_fw_ver |= (assic_to_hex(fw_ver[2]) & 0x03) << 4; //mid ver
|
|
|
+ 623 2 current_mcu_fw_ver |= (assic_to_hex(fw_ver[4]) & 0x0F); //low ver
|
|
|
+ 624 2 }
|
|
|
+ 625 1 else
|
|
|
+ 626 1 {
|
|
|
+ 627 2 // 4 number
|
|
|
+ 628 2 current_mcu_fw_ver = (assic_to_hex(fw_ver[0]) & 0x03) << 6; //high ver
|
|
|
+ 629 2 current_mcu_fw_ver |= (assic_to_hex(fw_ver[2]) & 0x03) << 4; //mid ver
|
|
|
+ 630 2 current_mcu_fw_ver |= ((assic_to_hex(fw_ver[4])*10 + assic_to_hex(fw_ver[5])) & 0x0F); //low ver
|
|
|
+ 631 2
|
|
|
+ 632 2 }
|
|
|
+ 633 1
|
|
|
+ 634 1 /*if((fw_ver[4] >= 0x30)&&(fw_ver[5] >= 0x30))
|
|
|
+ 635 1 { // 4 number
|
|
|
+ 636 1 current_mcu_fw_ver = (assic_to_hex(fw_ver[0]) & 0x03) << 6; //high ver
|
|
|
+ 637 1 current_mcu_fw_ver |= (assic_to_hex(fw_ver[2]) & 0x03) << 4; //mid ver
|
|
|
+ 638 1 current_mcu_fw_ver |= ((assic_to_hex(fw_ver[4])*10 + assic_to_hex(fw_ver[5])) & 0x0F); //low ver
|
|
|
+ 639 1
|
|
|
+ 640 1 }
|
|
|
+ 641 1 else
|
|
|
+ 642 1 { // 3 number
|
|
|
+ 643 1 current_mcu_fw_ver = (assic_to_hex(fw_ver[0]) & 0x03) << 6; //high ver
|
|
|
+ 644 1 current_mcu_fw_ver |= (assic_to_hex(fw_ver[2]) & 0x03) << 4; //mid ver
|
|
|
+ 645 1 current_mcu_fw_ver |= (assic_to_hex(fw_ver[4]) & 0x0F); //low ver
|
|
|
+ 646 1 }*/
|
|
|
+ 647 1 return current_mcu_fw_ver;
|
|
|
+ 648 1 }
|
|
|
+ 649
|
|
|
+ 650 #ifdef SUPPORT_MCU_OTA
|
|
|
+ 651 /**
|
|
|
+ 652 * @brief get mcu pid data saved in current_mcu_pid
|
|
|
+ 653 * @param[in] {void}
|
|
|
+ 654 * @return result of handle
|
|
|
+ 655 */
|
|
|
+ 656 void current_mcu_fw_pid(void)
|
|
|
+ 657 {
|
|
|
+ 658 1 unsigned char i = 0;
|
|
|
+ 659 1 //unsigned char *fw_pid = (unsigned char*) PRODUCT_KEY;
|
|
|
+ 660 1 unsigned char fw_pid[10];//modified by zzw 20240326
|
|
|
+ 661 1
|
|
|
+ 662 1
|
|
|
+ 663 1 my_memcpy(fw_pid,(unsigned char *)PRODUCT_KEY,my_strlen((unsigned char *)PRODUCT_KEY));
|
|
|
+ 664 1 while(i < 8){
|
|
|
+ 665 2 current_mcu_pid[i] = fw_pid[i];
|
|
|
+ 666 2 i++;
|
|
|
+ 667 2 }
|
|
|
+ 668 1 }
|
|
|
+ 669
|
|
|
+ 670 /**
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 12
|
|
|
+
|
|
|
+ 671 * @brief mcu ota offset requset
|
|
|
+ 672 * @param[in] {packet_offset} packet offset
|
|
|
+ 673 * @return viod
|
|
|
+ 674 */
|
|
|
+ 675 //when call this function, should set timeout event, if not received zigbee send response should res
|
|
|
+ 676 void mcu_ota_fw_request(void)
|
|
|
+ 677 {
|
|
|
+ 678 1 unsigned char i = 0;
|
|
|
+ 679 1 unsigned short length = 0;
|
|
|
+ 680 1
|
|
|
+ 681 1 if(ota_fw_info.mcu_current_offset >= ota_fw_info.mcu_ota_fw_size) //outside
|
|
|
+ 682 1 return;
|
|
|
+ 683 1 while(i < 8){
|
|
|
+ 684 2 length = set_zigbee_uart_byte(length,ota_fw_info.mcu_ota_pid[i]); //ota fw pid
|
|
|
+ 685 2 i++;
|
|
|
+ 686 2 }
|
|
|
+ 687 1 length = set_zigbee_uart_byte(length,ota_fw_info.mcu_ota_ver); //ota fw version
|
|
|
+ 688 1 i = 0;
|
|
|
+ 689 1 while(i < 4){
|
|
|
+ 690 2 length = set_zigbee_uart_byte(length , ota_fw_info.mcu_current_offset >> (24 - i * 8)); //pakage offset
|
|
|
+ -request
|
|
|
+ 691 2 i++;
|
|
|
+ 692 2 }
|
|
|
+ 693 1 length = set_zigbee_uart_byte(length ,FW_SINGLE_PACKET_SIZE); // packet size request
|
|
|
+ 694 1
|
|
|
+ 695 1 zigbee_uart_write_frame(MCU_OTA_DATA_REQUEST_CMD,length);
|
|
|
+ 696 1 }
|
|
|
+ 697
|
|
|
+ 698 /**
|
|
|
+ 699 * @brief mcu ota result report
|
|
|
+ 700 * @param[in] {status} result of mcu ota
|
|
|
+ 701 * @return void
|
|
|
+ 702 */
|
|
|
+ 703 void mcu_ota_result_report(unsigned char status)
|
|
|
+ 704 {
|
|
|
+ 705 1 unsigned short length = 0;
|
|
|
+ 706 1 unsigned char i = 0;
|
|
|
+ 707 1
|
|
|
+ 708 1 length = set_zigbee_uart_byte(length,status); //upgrade result status(0x00:ota success;0x01:ota failed)
|
|
|
+ 709 1 while(i < 8){
|
|
|
+ 710 2 length = set_zigbee_uart_byte(length,ota_fw_info.mcu_ota_pid[i]); //PID
|
|
|
+ 711 2 i++;
|
|
|
+ 712 2 }
|
|
|
+ 713 1 length = set_zigbee_uart_byte(length,ota_fw_info.mcu_ota_ver); //ota fw version
|
|
|
+ 714 1
|
|
|
+ 715 1 zigbee_uart_write_frame(MCU_OTA_RESULT_CMD,length); //response
|
|
|
+ 716 1 }
|
|
|
+ 717
|
|
|
+ 718 #endif
|
|
|
+ 719
|
|
|
+ 720 /**
|
|
|
+ 721 * @brief compare str1 and str2
|
|
|
+ 722 * @param[in] {str1} str1
|
|
|
+ 723 * @param[in] {str2} str2
|
|
|
+ 724 * @param[in] {len} len
|
|
|
+ 725 * @return equal return 0 else return -1
|
|
|
+ 726 */
|
|
|
+ 727 int strcmp_barry(unsigned char *str1,unsigned char *str2,unsigned char len)
|
|
|
+ 728 {
|
|
|
+ 729 1 unsigned char i;
|
|
|
+ 730 1 for(i = 0; i < len; i++){
|
|
|
+ 731 2 if(str1[i] < str2[i]){
|
|
|
+C51 COMPILER V9.53.0.0 SYSTEM 10/28/2024 12:44:26 PAGE 13
|
|
|
+
|
|
|
+ 732 3 return -1; //str1 < str2
|
|
|
+ 733 3 }
|
|
|
+ 734 2 else if(str1[i] > str2[i]){
|
|
|
+ 735 3 return 1; //str1 > str2
|
|
|
+ 736 3 }
|
|
|
+ 737 2 }
|
|
|
+ 738 1 return 0; //str1 == str2
|
|
|
+ 739 1 }
|
|
|
+ 740
|
|
|
+ 741 /**
|
|
|
+ 742 * @brief translate assic to hex
|
|
|
+ 743 * @param[in] {assic_num} assic number
|
|
|
+ 744 * @return hex data
|
|
|
+ 745 */
|
|
|
+ 746 char assic_to_hex(unsigned char assic_num)
|
|
|
+ 747 {
|
|
|
+ 748 1 if(assic_num<0x30 || assic_num > 0x39) //0~9
|
|
|
+ 749 1 return -1;
|
|
|
+ 750 1 else
|
|
|
+ 751 1 return assic_num % 0x30;
|
|
|
+ 752 1 }
|
|
|
+
|
|
|
+
|
|
|
+MODULE INFORMATION: STATIC OVERLAYABLE
|
|
|
+ CODE SIZE = 1975 ----
|
|
|
+ CONSTANT SIZE = 33 ----
|
|
|
+ XDATA SIZE = 578 72
|
|
|
+ PDATA SIZE = ---- ----
|
|
|
+ DATA SIZE = ---- ----
|
|
|
+ IDATA SIZE = ---- ----
|
|
|
+ BIT SIZE = ---- ----
|
|
|
+END OF MODULE INFORMATION.
|
|
|
+
|
|
|
+
|
|
|
+C51 COMPILATION COMPLETE. 3 WARNING(S), 0 ERROR(S)
|