141 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			141 lines
		
	
	
		
			4.0 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 "iot_cli_host_interface.h"
 | |
| #include "iot_cli_msg.h"
 | |
| #include "iot_io.h"
 | |
| 
 | |
| #include "iot_cli_tput.h"
 | |
| #include "iot_tput.h"
 | |
| 
 | |
| #if IOT_TPUT_APP_ENABLE
 | |
| 
 | |
| extern iot_plc_host_config_t *host_config;
 | |
| extern iot_tput_global_t* p_iot_tput_glb;
 | |
| 
 | |
| uint32_t iot_cli_tput_interface_register( \
 | |
|     iot_cli_tput_interface_t *cli_interface)
 | |
| {
 | |
|     if (cli_interface == NULL) {
 | |
|         return IOT_CLI_TPUT_REGISTER_FAILURE;
 | |
|     }
 | |
| 
 | |
|     host_config->cli_tput_interface = cli_interface;
 | |
|     return IOT_CLI_TPUT_REGISTER_SUCCESS;
 | |
| }
 | |
| 
 | |
| static void iot_tput_cli_send_cmd(uint8_t req_id, uint8_t msg_id,
 | |
|     uint8_t *data, uint32_t data_len)
 | |
| {
 | |
|     iot_pkt_t *pkt = NULL;
 | |
|     uint8_t *data_ptr;
 | |
| 
 | |
|     iot_printf("[tput_dbg] %s\n", __FUNCTION__);
 | |
| 
 | |
|     if (host_config->cli_tput_interface == NULL) {
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     pkt = iot_pkt_alloc(data_len + sizeof(iot_cli_tput_msg_header_t), \
 | |
|         IOT_CLI_MID);
 | |
|     IOT_ASSERT(pkt);
 | |
| 
 | |
|     data_ptr = iot_pkt_reserve(pkt, sizeof(iot_cli_tput_msg_header_t));
 | |
| 
 | |
|     iot_cli_tput_msg_header_t *hd;
 | |
|     hd = (iot_cli_tput_msg_header_t *)iot_pkt_block_ptr(pkt, \
 | |
|         IOT_PKT_BLOCK_HEAD);
 | |
|     hd->msg_id = msg_id;
 | |
|     hd->req_id = req_id;
 | |
| 
 | |
|     if (data && data_len) {
 | |
|         iot_pkt_set_tail(pkt,
 | |
|             iot_pkt_block_ptr(pkt, IOT_PKT_BLOCK_DATA) + data_len);
 | |
|         os_mem_cpy(data_ptr, data, data_len);
 | |
|     }
 | |
| 
 | |
|     if (host_config->cli_tput_interface->recv) {
 | |
|         host_config->cli_tput_interface->recv(NULL, pkt);
 | |
|     }
 | |
|     else {
 | |
|         iot_printf("[tput_dbg] rece is not register\n");
 | |
|     }
 | |
| }
 | |
| 
 | |
| void cli_set_iot_tput_cfg(
 | |
|     uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
 | |
| {
 | |
|     iot_tput_cli_send_cmd(0, IOT_CLI_SG_MSG_TEST_TPUT, buffer, bufferlen);
 | |
|     // resport ack
 | |
|     iot_cli_tput_report_t rsp = { 0 };
 | |
|     rsp.test_id = 0;
 | |
|     iot_plc_host_send(CLI_MSGID_TPUT_CFG_ACK, (uint8_t*)&rsp,
 | |
|             sizeof(iot_cli_tput_report_t), src_mac);
 | |
| }
 | |
| 
 | |
| static void cli_send_tput_test_result(iot_cli_tput_report_t *rsp)
 | |
| {
 | |
|     iot_cli_tput_report_t result;
 | |
|     os_mem_cpy(&result, rsp, sizeof(iot_cli_tput_report_t));
 | |
| 
 | |
|     iot_plc_host_send(CLI_MSGID_TPUT_RLT, (uint8_t*)&result,
 | |
|             sizeof(iot_cli_tput_report_t), 0);
 | |
| }
 | |
| 
 | |
| void iot_cli_tput_send_data_to_cli_interface(iot_pkt_t *pkt)
 | |
| {
 | |
|     iot_task_msg_t *t_msg;
 | |
|     if (pkt == NULL) {
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     t_msg = iot_task_alloc_msg(host_config->host_task_h);
 | |
|     if (t_msg == NULL) {
 | |
|         iot_printf("cli_send_module_msg iot_task_alloc_msg fail\n");
 | |
|         IOT_ASSERT(0);
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     iot_cli_msg_t *msg = (iot_cli_msg_t *)t_msg;
 | |
| 
 | |
|     t_msg->type = IOT_CLI_MSG_TYPE;
 | |
|     t_msg->id = IOT_CLI_TPUT_MSG;
 | |
|     msg->data = pkt;
 | |
|     iot_task_queue_msg(host_config->host_task_h, t_msg, IOT_CLI_QUEUE_HOST);
 | |
| }
 | |
| 
 | |
| void iot_cli_tput_handle_msg(iot_pkt_t *pkt)
 | |
| {
 | |
|     iot_cli_tput_msg_header_t *hdr =
 | |
|         (iot_cli_tput_msg_header_t*)iot_pkt_block_ptr(pkt, \
 | |
|         IOT_PKT_BLOCK_HEAD);
 | |
|     switch (hdr->msg_id) {
 | |
|     case IOT_CLI_TPUT_REQ:
 | |
|     {
 | |
|         iot_cli_tput_report_t *rsp = \
 | |
|             (iot_cli_tput_report_t *)(iot_pkt_block_ptr(pkt, \
 | |
|             IOT_PKT_BLOCK_HEAD) + sizeof(iot_cli_tput_msg_header_t));
 | |
|         cli_send_tput_test_result(rsp);
 | |
|         break;
 | |
|     }
 | |
|     default:
 | |
|         IOT_ASSERT(0);
 | |
|     }
 | |
| 
 | |
|     iot_pkt_free(pkt);
 | |
|     return;
 | |
| }
 | |
| #endif
 |