150 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			150 lines
		
	
	
		
			4.6 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_HOST_DISCOVERY_H
							 | 
						||
| 
								 | 
							
								#define IOT_CLI_HOST_DISCOVERY_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								#include "iot_utils_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_cli.h"
							 | 
						||
| 
								 | 
							
								#include "iot_config_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_cli_sg_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_plc_msg_sta_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#pragma pack(push)  /* save the pack status */
							 | 
						||
| 
								 | 
							
								#pragma pack(1)     /* 1 byte align */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if (IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define CLI_JOIN_NODE_DEFAULT_BAND      (1)
							 | 
						||
| 
								 | 
							
								#define CLI_JOIN_STA                    (0xFF)
							 | 
						||
| 
								 | 
							
								#define CLI_JOIN_NODE_SET_BAND_INYERVAL (30)
							 | 
						||
| 
								 | 
							
								#define CLI_DISCOVERY_MAX_DIS_NODE      (40)
							 | 
						||
| 
								 | 
							
								// max report discover node info interval time, unit: ms
							 | 
						||
| 
								 | 
							
								#define CLI_DISCOVERY_MAX_INTERVAL_TM   (10 * 1000)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _cli_discovery_node_rpt {
							 | 
						||
| 
								 | 
							
								    /** tei of the discovered node */
							 | 
						||
| 
								 | 
							
								    uint16_t            tei;
							 | 
						||
| 
								 | 
							
								    /** role of the discovered node. see IOT_PLC_DEV_ROLE_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t             role;
							 | 
						||
| 
								 | 
							
								    /** network ID of the discovered node */
							 | 
						||
| 
								 | 
							
								    uint32_t            nid;
							 | 
						||
| 
								 | 
							
								    /** logical phase of the discovered node. see IOT_PLC_PHASE_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t             phase;
							 | 
						||
| 
								 | 
							
								    /** rx snr of the discoverted node */
							 | 
						||
| 
								 | 
							
								    int8_t              rx_snr;
							 | 
						||
| 
								 | 
							
								    /** mac address of the discoverted node */
							 | 
						||
| 
								 | 
							
								    uint8_t             addr[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								    /** cco mac address of the discoverted node */
							 | 
						||
| 
								 | 
							
								    uint8_t             cco_addr[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								    uint8_t             band_id;
							 | 
						||
| 
								 | 
							
								} cli_discovery_node_rpt;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _cli_dis_node_info
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    uint32_t dis_node_num;
							 | 
						||
| 
								 | 
							
								    cli_discovery_node_rpt nodelist[CLI_DISCOVERY_MAX_DIS_NODE];
							 | 
						||
| 
								 | 
							
								    timer_id_t          rpt_timer;
							 | 
						||
| 
								 | 
							
								} cli_dis_node_info;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _cli_sg_device_info_ul {
							 | 
						||
| 
								 | 
							
								    /* software version */
							 | 
						||
| 
								 | 
							
								    uint16_t            sw_ver;
							 | 
						||
| 
								 | 
							
								    /* module vendor ID */
							 | 
						||
| 
								 | 
							
								    uint16_t            vendor_id;
							 | 
						||
| 
								 | 
							
								    /* reserved */
							 | 
						||
| 
								 | 
							
								    uint8_t             rsvd[32];
							 | 
						||
| 
								 | 
							
								} cli_sg_device_info_ul_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _cli_enable_discovery_mode_dl {
							 | 
						||
| 
								 | 
							
								    uint8_t             enabled;
							 | 
						||
| 
								 | 
							
								} cli_enable_discovery_mode_dl;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _cli_enable_discovery_mode_ack {
							 | 
						||
| 
								 | 
							
								    uint8_t             result;
							 | 
						||
| 
								 | 
							
								} cli_enable_discovery_mode_ack;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief cli_enable_discovery_mode - enable discovery mode
							 | 
						||
| 
								 | 
							
								 * @param buffer:       buffer with argument for enable command
							 | 
						||
| 
								 | 
							
								 * @param bufferlen:    length of the buffer
							 | 
						||
| 
								 | 
							
								 * @param src_mac:      source mac of cli msg
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void cli_enable_discovery_mode(
							 | 
						||
| 
								 | 
							
								    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief cli_disable_discovery_mode - disable discovery mode
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void cli_disable_discovery_mode();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief cli_local_device_info - query local device information
							 | 
						||
| 
								 | 
							
								 * @param buffer:       buffer with argument for enable command
							 | 
						||
| 
								 | 
							
								 * @param bufferlen:    length of the buffer
							 | 
						||
| 
								 | 
							
								 * @param src_mac:      source mac of cli msg
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void cli_local_device_info(uint8_t *buffer, uint32_t bufferlen,
							 | 
						||
| 
								 | 
							
								    uint8_t *src_mac);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief cli_join_node - join specific cco
							 | 
						||
| 
								 | 
							
								 * @param buffer:       buffer with argument for join command
							 | 
						||
| 
								 | 
							
								 * @param bufferlen:    length of the buffer
							 | 
						||
| 
								 | 
							
								 * @param src_mac:      source mac of cli msg
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void cli_join_node(
							 | 
						||
| 
								 | 
							
								    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief cli_node_is_ready - check if joined
							 | 
						||
| 
								 | 
							
								 * @param buffer:       buffer with argument for query ready command
							 | 
						||
| 
								 | 
							
								 * @param bufferlen:    length of the buffer
							 | 
						||
| 
								 | 
							
								 * @param src_mac:      source mac of cli msg
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void cli_node_is_ready(
							 | 
						||
| 
								 | 
							
								    uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief upload_dis_nod_info_list - collect and notify node list
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void upload_dis_nod_info_list();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief cli_discovery_init - cli discovery init
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void cli_discovery_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief cli_discovery_deinit - cli discovery deinit
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void cli_discovery_deinit();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void cli_discovery_node_notify(iot_plc_discovery_node_rpt_t *info);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#pragma pack(pop)   /* restore the pack status */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif
							 |