190 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			190 lines
		
	
	
		
			5.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. | ||
|  | 
 | ||
|  | ****************************************************************************/ | ||
|  | #ifndef IOT_TPUT_H
 | ||
|  | #define IOT_TPUT_H
 | ||
|  | 
 | ||
|  | #include "iot_task_api.h"
 | ||
|  | #include "iot_utils_api.h"
 | ||
|  | #include "iot_plc_api.h"
 | ||
|  | #include "os_timer_api.h"
 | ||
|  | #include "iot_cli_sg_api.h"
 | ||
|  | #include "iot_cli_tput_api.h"
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | extern "C" { | ||
|  | #endif
 | ||
|  | 
 | ||
|  | /* define priorities for message to be handle */ | ||
|  | #define IOT_TPUT_TASK_QUEUE_HP                      0
 | ||
|  | #define IOT_TPUT_TASK_QUEUE_LP                      1
 | ||
|  | #define IOT_TPUT_TASK_QUEUE_MAX_PRIO                2
 | ||
|  | 
 | ||
|  | #define IOT_TPUT_TASK_LIKE_ID                       2
 | ||
|  | #define IOT_TPUT_TASK_POOL_SIZE                     128
 | ||
|  | 
 | ||
|  | /* msg type */ | ||
|  | #define IOT_TPUT_PLC_MSG                            0
 | ||
|  | #define IOT_TPUT_TIMER_MSG                          1
 | ||
|  | #define IOT_TPUT_CLI_MSG                            2
 | ||
|  | 
 | ||
|  | /* message id for TIMER_MSG */ | ||
|  | #define IOT_TIMER_SEND_PKT                          1
 | ||
|  | #define IOT_TIMER_REQ                               2
 | ||
|  | 
 | ||
|  | #define IOT_TPUT_NID                                1
 | ||
|  | 
 | ||
|  | /* tput send msdu len */ | ||
|  | #define IOT_TPUT_LEN_2032                           2032
 | ||
|  | #define IOT_TPUT_LEN_1024                           1024
 | ||
|  | #define IOT_TPUT_LEN_520                            520
 | ||
|  | #define IOT_TPUT_LEN_72                             72
 | ||
|  | 
 | ||
|  | #define IOT_SEQ_INVAILD                             0xFFFFFF
 | ||
|  | 
 | ||
|  | /* down link mode . cco -> sta */ | ||
|  | #define IOT_TPUT_DOWN_LINK                          1
 | ||
|  | /* up link mode . sta -> cco */ | ||
|  | #define IOT_TPUT_UP_LINK                            0
 | ||
|  | 
 | ||
|  | /* every 10ms send 1 pkt*/ | ||
|  | #define IOT_TPUT_SEND_PKT_DUR                       6        // 6ms
 | ||
|  | /* 10s a cycle */ | ||
|  | #define IOT_TPUT_STATIS_DUR                         10*1000   // 10 S
 | ||
|  | 
 | ||
|  | /* CCO trigger sta send pkt, 10 pkt */ | ||
|  | #define IOT_TPUT_STATIS_TG_DUR                      10*10     // 10 PKT
 | ||
|  | /* down mode sta resport receive cnt .
 | ||
|  |  * or up mode cco check receive pkt whether complete . | ||
|  |  * every 5s is reported once . | ||
|  |  */ | ||
|  | #define IOT_TPUT_STA_REQ_DUR                        5*1000     // 5s
 | ||
|  | 
 | ||
|  | #pragma pack(push)  // save the pack status
 | ||
|  | #pragma pack(1)     // 1 byte align
 | ||
|  | 
 | ||
|  | /* message used in iot_tput_task.
 | ||
|  |  */ | ||
|  | typedef struct _iot_tput_msg { | ||
|  |     /* standard iot_task message */ | ||
|  |     iot_task_msg_t  msg; | ||
|  |     /* pointer to message data */ | ||
|  |     void            *data; | ||
|  | }iot_tput_msg_t; | ||
|  | 
 | ||
|  | typedef struct iot_tput_device { | ||
|  |     /* Indicates if the remote device is ready. */ | ||
|  |     uint8_t         rmt_valid; | ||
|  |     /* link id used for sending msdu */ | ||
|  |     uint8_t         link_id; | ||
|  |     /* Indicates if this local device is ready. */ | ||
|  |     uint8_t         dev_ready; | ||
|  |     /* This local device role, CCO or STA ... */ | ||
|  |     uint8_t         dev_role; | ||
|  |     /* MAC of this local device. */ | ||
|  |     uint8_t         mac_addr[IOT_MAC_ADDR_LEN]; | ||
|  |     /* MAC of CCO in this topo. */ | ||
|  |     uint8_t         cco_addr[IOT_MAC_ADDR_LEN]; | ||
|  |     /* MAC of remote device wef */ | ||
|  |     uint8_t         rmt_addr[IOT_MAC_ADDR_LEN]; | ||
|  |     /* The network ID of this topo. */ | ||
|  |     uint32_t        nid; | ||
|  | } iot_tput_dev_t; | ||
|  | 
 | ||
|  | /** rate test param */ | ||
|  | typedef struct _iot_tput_cfg_info { | ||
|  |     uint32_t test_id; | ||
|  |     /** if downlink test */ | ||
|  |     uint8_t downlink; | ||
|  |     /** msdu size */ | ||
|  |     uint16_t msdu_size; | ||
|  |     /** send rate */ | ||
|  |     uint16_t send_rate; | ||
|  |     /** test duration */ | ||
|  |     uint16_t test_duration; | ||
|  |     /** test dst addr */ | ||
|  |     uint8_t dst[6]; | ||
|  | } iot_tput_cfg_info_t; | ||
|  | 
 | ||
|  | typedef struct _iot_tput_send_info { | ||
|  |     uint32_t seq; | ||
|  |     uint32_t statistics_cnt; | ||
|  | } iot_tput_send_info_t; | ||
|  | 
 | ||
|  | /* iot tput global descriptor */ | ||
|  | typedef struct _iot_tput_global { | ||
|  |     /* Task handle. */ | ||
|  |     iot_task_h          handle; | ||
|  |     /* Keep the task configuration. */ | ||
|  |     iot_task_config_t   cfg; | ||
|  |     /* a flag indicating if app registered successfully */ | ||
|  |     uint8_t             app_registered; | ||
|  | 
 | ||
|  |     /* handle of this app */ | ||
|  |     iot_plc_app_h       app_handle; | ||
|  |     /* timer to call api periodically */ | ||
|  |     timer_id_t          tput_send_timer; | ||
|  |     /* timer to statistics send cnt */ | ||
|  |     timer_id_t          tput_period_timer; | ||
|  |     /* timer to sta report cnt or cco check receive pkt over */ | ||
|  |     timer_id_t          tput_req_timer; | ||
|  |     /* tput device*/ | ||
|  |     iot_tput_dev_t      tput_dev; | ||
|  |     /* cli interface for smart grid */ | ||
|  |     iot_cli_tput_interface_t  cli_tput_interface; | ||
|  | 
 | ||
|  |     /* tput cfg info*/ | ||
|  |     iot_tput_cfg_info_t tput_cfg; | ||
|  | 
 | ||
|  |     /* sta receive cnt last */ | ||
|  |     uint32_t            sta_last_rece_cnt; | ||
|  |     /* receive cnt */ | ||
|  |     uint32_t            receive_cnt; | ||
|  |     /* tput reslut kpbs */ | ||
|  |     uint32_t            tput_kpbs; | ||
|  |     /* record send pkt cnt */ | ||
|  |     uint32_t            send_cnt; | ||
|  | 
 | ||
|  |     uint8_t             sta_send_flag       : 1, | ||
|  |                         cco_check_rece_flag : 1, | ||
|  |                         resv                : 6; | ||
|  | } iot_tput_global_t; | ||
|  | 
 | ||
|  | #pragma pack(pop)    // restore the pack status
 | ||
|  | 
 | ||
|  | #if IOT_TPUT_APP_ENABLE
 | ||
|  | 
 | ||
|  | uint32_t iot_tput_send_pkt(uint8_t *src_addr, uint8_t *dst_addr, | ||
|  |     uint32_t msdu_len); | ||
|  | 
 | ||
|  | uint32_t iot_tput_timer_start(timer_id_t timer_id, uint32_t dur); | ||
|  | 
 | ||
|  | uint32_t iot_tput_timer_stop(timer_id_t timer_id); | ||
|  | 
 | ||
|  | uint32_t iot_tput_sta_req(); | ||
|  | 
 | ||
|  | 
 | ||
|  | void iot_tput_report_rate_test(uint8_t *dst, uint8_t down_or_up_link, \ | ||
|  |     uint32_t rate_kpbs); | ||
|  | 
 | ||
|  | #endif
 | ||
|  | 
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | } | ||
|  | #endif
 | ||
|  | 
 | ||
|  | #endif
 | ||
|  | 
 |