190 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			190 lines
		
	
	
		
			6.1 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. | ||
|  | 
 | ||
|  | ****************************************************************************/ | ||
|  | 
 | ||
|  | #ifndef IOT_CLI_H
 | ||
|  | #define IOT_CLI_H
 | ||
|  | 
 | ||
|  | /* os shim includes */ | ||
|  | #include "os_types.h"
 | ||
|  | #include "os_lock.h"
 | ||
|  | #include "os_task.h"
 | ||
|  | #include "os_event.h"
 | ||
|  | 
 | ||
|  | #include "iot_config.h"
 | ||
|  | #include "iot_queue.h"
 | ||
|  | #include "iot_mem_pool.h"
 | ||
|  | #include "iot_task.h"
 | ||
|  | #include "iot_dbglog.h"
 | ||
|  | #include "iot_pkt_api.h"
 | ||
|  | 
 | ||
|  | #include "communicator.h"
 | ||
|  | 
 | ||
|  | #include "iot_cli_type_definition.h"
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | extern "C" { | ||
|  | #endif
 | ||
|  | 
 | ||
|  | typedef struct _cli_mini_mode_data | ||
|  | { | ||
|  |     void *buffer; | ||
|  |     uint32_t len; | ||
|  | } cli_mini_mode_data; | ||
|  | 
 | ||
|  | typedef struct _cli_cvg_inf | ||
|  | { | ||
|  |     uint8_t cvg_role; //the role of the cvg
 | ||
|  | } cli_cvg_info_t; | ||
|  | 
 | ||
|  | typedef struct _iot_cli_entry | ||
|  | { | ||
|  |     commnucator_t commu; | ||
|  |     dbglog_info_t *dbglog; | ||
|  |     iot_task_h cli_task_h; | ||
|  |     cli_cvg_info_t local_info; | ||
|  |     uint8_t need_download_cli_to_flash : 1, | ||
|  |     /* enable commnucator */ | ||
|  |             enable_commu               : 1, | ||
|  |     /* reserved for further use */ | ||
|  |             rsvd                       : 6; | ||
|  | } iot_cli_t; | ||
|  | 
 | ||
|  | iot_task_msg_t *iot_cli_create_cli_msg( | ||
|  |     uint16_t id, iot_pkt_t *pkt); | ||
|  | 
 | ||
|  | uint32_t iot_cli_init(uint8_t interface_type, uint8_t ftm_mode); | ||
|  | 
 | ||
|  | /* pack for the structures in the whole file */ | ||
|  | #pragma pack(push)  // save the pack status
 | ||
|  | #pragma pack(1)     // 1 byte align
 | ||
|  | #if HW_PLATFORM == HW_PLATFORM_SIMU
 | ||
|  | 
 | ||
|  | typedef struct _snr_info | ||
|  | { | ||
|  |     uint32_t ip_addr; | ||
|  |     uint32_t snr; | ||
|  |     uint32_t phase; | ||
|  |     uint32_t src_phase; | ||
|  | } snr_info_t; | ||
|  | 
 | ||
|  | typedef struct _snr_hdr | ||
|  | { | ||
|  |     uint32_t dest_addr; | ||
|  |     uint32_t num; | ||
|  |     uint32_t mode; //0:rf, 1:plc
 | ||
|  | }snr_hdr_t; | ||
|  | #endif
 | ||
|  | 
 | ||
|  | /*
 | ||
|  |  *the buffer is alloced by cli mode, and consided that some up-level mode need | ||
|  |  *access the buffer at another task, so give a param to tell if cli need free | ||
|  |  *the buffer or not, if need cli free the iot_pkt, please set the need_free | ||
|  |  * to true, by default the value of bool param is true | ||
|  |  */ | ||
|  | typedef void(*FTM_MSG_HANDLER)(int msgid, iot_pkt_t* buffer, bool_t* need_free); | ||
|  | 
 | ||
|  | typedef void(*PT_BOARD_MSG_HANDLER)(int msgid, iot_pkt_t* buffer); | ||
|  | 
 | ||
|  | typedef void(*IC_TOOL_MSG_HANDLER)(int msgid, iot_pkt_t* buffer, uint32_t len); | ||
|  | 
 | ||
|  | typedef void(*CLI_REGULAR_LOG)(); | ||
|  | 
 | ||
|  | void register_regular_log(CLI_REGULAR_LOG cb); | ||
|  | 
 | ||
|  | void register_ftm_recv_cb(FTM_MSG_HANDLER cb); | ||
|  | 
 | ||
|  | void register_pd_board_recv_cb(PT_BOARD_MSG_HANDLER cb); | ||
|  | 
 | ||
|  | void register_ic_tool_recv_cb(IC_TOOL_MSG_HANDLER cb); | ||
|  | 
 | ||
|  | void register_ic_rf_tool_recv_cb(IC_TOOL_MSG_HANDLER cb); | ||
|  | 
 | ||
|  | void cli_send_module_msg_with_sn(uint32_t moduleid, uint32_t msgid, | ||
|  |     uint8_t *buffer, uint32_t bufferlen, uint16_t sn, uint8_t *src_mac); | ||
|  | void cli_send_module_msg(uint32_t moduleid, uint32_t msgid, | ||
|  |     uint8_t *buffer, uint32_t bufferlen); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief iot_cli_pre_handle_data() - cli module pre handle communicator data. | ||
|  |  * @param buffer:            communicator received data ptr. | ||
|  |  * @param len:               data length. | ||
|  |  * @param type:              communicator type , see - COMMUNICATOR_XXX. | ||
|  |  * @retval:                  ERR_OK - handle is ok. | ||
|  |  *                           others - handle is fail. | ||
|  |  */ | ||
|  | uint32_t iot_cli_pre_handle_data(void *buffer, uint32_t len, | ||
|  |     interface_type_t type); | ||
|  | 
 | ||
|  | #define IOT_CLI_MSG_TYPE        1
 | ||
|  | 
 | ||
|  | #define IOT_CLI_SEND_MSG        1   /* send messages */
 | ||
|  | #define IOT_CLI_REV_MSG         3   /* cli rx msg */
 | ||
|  | #define IOT_CLI_HOST_MSG        4   /* cli host msg */
 | ||
|  | #define IOT_CLI_LOG_TIMER       5   /* cli log timer */
 | ||
|  | #define IOT_CLI_UPGRADE_TIMER   6   /* cli upgrade timer */
 | ||
|  | #define IOT_CLI_SG_MSG          7   /* cli and smart grid msg */
 | ||
|  | #define IOT_CLI_RATE_TEST_TIMER 8   /* cli rate test timer */
 | ||
|  | #define IOT_CLI_SET_TIMER       9   /* cli set timer */
 | ||
|  | #define IOT_CLI_ALIVE_TIMER     10  /* cli alive timer */
 | ||
|  | #define IOT_CLI_ADA_MSG         11  /* cli ada msg */
 | ||
|  | #define IOT_CLI_TPUT_MSG        12  /* cli handle tput msg */
 | ||
|  | #define IOT_CLI_DUMP_TIMER      13  /* cli dump timer */
 | ||
|  | #define IOT_CLI_UL_BUF_TIMER    14  /* cli ul buf timer */
 | ||
|  | #define IOT_CLI_QUERY_HW_TIMER  15  /* cli query hw ver timer */
 | ||
|  | #define IOT_CLI_MINI_UART_RECV  16  /* cli mini uart recv */
 | ||
|  | #define IOT_CLI_RPT_TOPO_TIMER  17  /* cli rpt topo data timer */
 | ||
|  | #define IOT_CLI_RX_APP_DATA_MSG 18  /* cli received data from app */
 | ||
|  | #define IOT_CLI_BCAST_TX_DONE   19  /* cli upgrade bcast tx done */
 | ||
|  | 
 | ||
|  | #define IOT_CLI_QUEUE_TX        0
 | ||
|  | #define IOT_CLI_QUEUE_RX        1
 | ||
|  | #define IOT_CLI_QUEUE_HOST      2
 | ||
|  | #define IOT_CLI_QUEUE_TIMER     3
 | ||
|  | 
 | ||
|  | #define MAC_IS_EMPTY(mac) \
 | ||
|  |     ((!mac[0]) && (!mac[1]) && (!mac[2]) && \ | ||
|  |     (!mac[3]) && (!mac[4]) && (!mac[5])) | ||
|  | 
 | ||
|  | #pragma pack(pop)   // restore the pack status
 | ||
|  | 
 | ||
|  | /* iot_cli_queue_data - post a msg to iot_cli task with these data
 | ||
|  |  * @buffer:     buffer containing data | ||
|  |  * @len:        length of the buffer | ||
|  |  */ | ||
|  | void iot_cli_queue_data(void *buffer, uint32_t len); | ||
|  | 
 | ||
|  | void send_tx_msg_to_cli_task(iot_pkt_t* data); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_add_msg_header() - fillwith cli packet. | ||
|  |  * @param input_buffer:         src cli data ptr. | ||
|  |  * @param buffer_len:           src cli data length. | ||
|  |  * @param moduleid:             cli hdr moduleid. | ||
|  |  * @param msgid:                cli hdr msgid. | ||
|  |  * @param sn:                   cli hdr sn. | ||
|  |  * @param output_buffer:        desc cli data ptr. | ||
|  |  * @param out_len:              fillwithed cli data total length. | ||
|  |  * @param src_mac:              cli src mac. | ||
|  |  */ | ||
|  | void cli_add_msg_header(void* input_buffer, uint32_t buffer_len, | ||
|  |     uint32_t moduleid, uint32_t msgid, uint16_t sn, | ||
|  |     uint8_t** output_buffer, uint32_t *out_len, uint8_t *src_mac); | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | } | ||
|  | #endif
 | ||
|  | 
 | ||
|  | #endif
 |