82 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 | 
						|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | 
						|
be copied by any method or incorporated into another program without
 | 
						|
the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
liability for its use in any way and conveys no license or title under
 | 
						|
any patent or copyright and makes no representation or warranty that this
 | 
						|
Information is free from patent or copyright infringement.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
 | 
						|
#include "app_uart.h"
 | 
						|
#include "app_common.h"
 | 
						|
#include "app_main_task.h"
 | 
						|
#include "app_proto_dlt645.h"
 | 
						|
#include "app_main_dlt645.h"
 | 
						|
#include "proto_645.h"
 | 
						|
#include "app_dlt645_di_def.h"
 | 
						|
 | 
						|
#define APP_DLT645_CCO_REBOOT_DELAY_MS          1000
 | 
						|
 | 
						|
static uint32_t dlt645_get_sw_ver_handle(proto_645_header_t *frame,
 | 
						|
    uint8_t * out_buf,  uint16_t *out_len)
 | 
						|
{
 | 
						|
    uint32_t di = PROTO_645_2007_EXT_READ_SW_VER;
 | 
						|
    uint32_t err_code = ERR_OK;
 | 
						|
    uint16_t cnt = 0;
 | 
						|
 | 
						|
    proto_645_2007_di_to_byte(di, out_buf);
 | 
						|
    cnt = PROTO_645_2007_DI_LEN;
 | 
						|
    out_buf[cnt++] = iot_version_major();
 | 
						|
    out_buf[cnt++] = iot_version_minor();
 | 
						|
    out_buf[cnt++] = iot_version_micro();
 | 
						|
    out_buf[cnt++] = iot_version_build() & 0x3F;
 | 
						|
    *out_len = cnt;
 | 
						|
 | 
						|
    return err_code;
 | 
						|
}
 | 
						|
 | 
						|
#if PLC_SUPPORT_STA_ROLE
 | 
						|
#else   /* PLC_SUPPORT_STA_ROLE */
 | 
						|
 | 
						|
static uint32_t dlt645_cco_reboot_handle(proto_645_header_t *frame,
 | 
						|
    uint8_t * out_buf, uint16_t *out_len)
 | 
						|
{
 | 
						|
    uint32_t di = PROTO_645_2007_EXT_RESET_CCO;
 | 
						|
    uint32_t err_code = ERR_OK;
 | 
						|
 | 
						|
    app_timer_start(APP_TIMER_ID_REBOOT, APP_DLT645_CCO_REBOOT_DELAY_MS,
 | 
						|
        TIMER_TYPE_ONCE);
 | 
						|
 | 
						|
    proto_645_2007_di_to_byte(di, out_buf);
 | 
						|
    *out_len = PROTO_645_2007_DI_LEN;
 | 
						|
 | 
						|
    return err_code;
 | 
						|
}
 | 
						|
#endif  /* PLC_SUPPORT_STA_ROLE */
 | 
						|
 | 
						|
/* dlt645 local handle list for main task. */
 | 
						|
static proto_dlt645_proc_func_pair g_main_task_dlt645_handle_list[] = {
 | 
						|
    {PROTO_645_2007_FN_READ_DATA,   PROTO_645_2007_EXT_READ_SW_VER,      dlt645_get_sw_ver_handle},
 | 
						|
#if PLC_SUPPORT_STA_ROLE
 | 
						|
 | 
						|
#else   /* PLC_SUPPORT_STA_ROLE */
 | 
						|
    {PROTO_645_2007_FN_WRITE_DATA,  PROTO_645_2007_EXT_RESET_CCO,      dlt645_cco_reboot_handle},
 | 
						|
 | 
						|
#endif  /* PLC_SUPPORT_STA_ROLE */
 | 
						|
};
 | 
						|
 | 
						|
void iot_main_dlt645_local_handle_register(void)
 | 
						|
{
 | 
						|
    if (app_dlt645_local_handle_list_register(APP_TASK_MAIN,
 | 
						|
        g_main_task_dlt645_handle_list,
 | 
						|
        APP_ARRAY_COUNT(g_main_task_dlt645_handle_list)) != ERR_OK) {
 | 
						|
            APP_PRINTF("[ERR] MAIN TASK DLT645 HANDLE INIT FAILED !!");
 | 
						|
    }
 | 
						|
}
 |