/*================================================================ Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved. Quectel Wireless Solution Proprietary and Confidential. =================================================================*/ /*================================================================= EDIT HISTORY FOR MODULE This section contains comments describing changes made to the module. Notice that changes are listed in reverse chronological order. WHEN WHO WHAT, WHERE, WHY ------------ ------- ------------------------------------------------------------------------------- =================================================================*/ #include #include #include #include "ql_api_osi.h" #include "ql_api_nw.h" #include "ql_log.h" #include "ql_api_datacall.h" #include "ql_ftp_client.h" #include "ql_fs.h" #include "ql_ssl.h" #define QL_FTP_LOG_LEVEL QL_LOG_LEVEL_INFO #define QL_FTP_LOG(msg, ...) QL_LOG(QL_FTP_LOG_LEVEL, "ql_FTP", msg, ##__VA_ARGS__) #define QL_FTP_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_FTP", msg, ##__VA_ARGS__) static ql_task_t ftp_task = NULL; #define PRINT_BUF_SIZE 65 #define MAX_PATH_SIZE 256 int ftp_app_net_datacall_fxn(uint8_t nSim,int profile_idx) { int ret = 0; int i = 0; ql_data_call_info_s info; char ip4_addr_str[16] = {0}; memset(&info, 0x00, sizeof(ql_data_call_info_s)); while((ret = ql_network_register_wait(nSim, 120)) != 0 && i < 10) { i++; QL_FTP_LOG("wait network register count: %d",i); ql_rtos_task_sleep_s(1); } if(ret != 0) { QL_FTP_LOG("network register failure!"); return -1; } QL_FTP_LOG("network register sucess nSim = %d,i = %d",nSim,i); ret = ql_set_data_call_asyn_mode(nSim, profile_idx, 0); QL_FTP_LOG("network datacall asyn mode ret =%d",ret); ret = ql_start_data_call(nSim, profile_idx, QL_PDP_TYPE_IP, "uninet", NULL, NULL, 0); QL_FTP_LOG("network datacall sucess ret =%d",ret); if(ret != 0){ QL_FTP_LOG("data call failure!"); } if(ql_get_data_call_info(nSim, profile_idx, &info) != 0){ QL_FTP_LOG("get datacall info ret: %d", ret); ql_stop_data_call(nSim, profile_idx); return -1; } QL_FTP_LOG("info->profile_idx: %d", info.profile_idx); QL_FTP_LOG("info->ip_version: %d", info.ip_version); QL_FTP_LOG("info->v4.state: %d", info.v4.state); inet_ntop(AF_INET, &info.v4.addr.ip, ip4_addr_str, sizeof(ip4_addr_str)); QL_FTP_LOG("info.v4.addr.ip: %s\r\n", ip4_addr_str); inet_ntop(AF_INET, &info.v4.addr.pri_dns, ip4_addr_str, sizeof(ip4_addr_str)); QL_FTP_LOG("info.v4.addr.pri_dns: %s\r\n", ip4_addr_str); inet_ntop(AF_INET, &info.v4.addr.sec_dns, ip4_addr_str, sizeof(ip4_addr_str)); QL_FTP_LOG("info.v4.addr.sec_dns: %s\r\n", ip4_addr_str); return 0; } char hostname[64]="120.27.243.131"; char username[]="qx"; char password[]="qx900"; char get_filename[] = "4G04/MCU/test_7.3-1.txt"; #if 0 size_t mcu_data_write_callback(void *ptr, size_t size, size_t nmemb, void *stream) { QL_FTP_LOG("********** fota_ftp_write_cb **********"); int ret = 0; QFILE fd = -1; fota_ftp_client_t *user_data; user_data = (fota_ftp_client_t *)stream; //"ab" 打开或新建一个二进制文件,只允许在文件末尾追写 fd = ql_fopen("U:4G04/MCU/test_7.3.txt", "ab"); //回写数据前将状态置为中断,ql_fwrite出现异常无法继续执行下去时,将会一直保持此状态,再次调用FTP FOTA线程时,将使用本次的断点信息继续下载 user_data->down_state = DOWN_INTR; ret = ql_fwrite(ptr, size, nmemb, fd); QL_FTP_LOG("ql_fwrite ret = %d",ret); ql_fclose(fd); } #endif static void ftp_app_thread(void * arg) { int ret = 0; void * client = NULL; int profile_idx = 1; uint8_t nSim = 0; uint16_t sim_cid; ql_rtos_task_sleep_s(10); QL_FTP_LOG("=========================== ftp demo2 start =============================="); if(QL_DATACALL_SUCCESS != ql_bind_sim_and_profile(nSim, profile_idx, &sim_cid)) { QL_FTP_LOG("nSim or profile_idx is invalid!!!!"); ret = -1; goto exit; } if(ftp_app_net_datacall_fxn(nSim, profile_idx) != 0) { QL_FTP_LOG("net datacall failed!"); goto exit; } client = ql_ftp_client_new(); ql_ftp_client_setopt(client, QL_FTP_CLIENT_SIM_CID, sim_cid); ql_ftp_client_setopt(client, QL_FTP_CLIENT_OPT_PDP_CID,1); ql_ftp_client_setopt(client, QL_FTP_CLIENT_OPT_START_POS,0); ret=ql_ftp_client_open(client,hostname,username,password); QL_FTP_LOG("ftp open[%s] ret = %d",hostname,ret); QL_FTP_LOG("=====================ftp_client_test[]======================"); uint8 i = 1; while(client) { QL_FTP_LOG("=====================[get test start]============>>>>>>>>>"); if(0 == i) { ql_rtos_task_sleep_s(5); continue; } int i = 0; QL_FTP_CLIENT_FILE_INFO_T ql_list_file[5]={0}; ret=ql_ftp_client_list(client,"/4G04/MCU","HC32_4G04_08_10_17_43.bin",ql_list_file, 5); QL_FTP_LOG("\nql_ftp_client_list[/] ret=%d\n",ret); for(i=0;i>>>>>>>>"); ql_rtos_task_sleep_s(5); } ql_ftp_client_release(client); exit: ql_rtos_task_delete(ftp_task); return; } int ql_ftp_app_demo_init(void) { QlOSStatus err = QL_OSI_SUCCESS; QL_FTP_LOG("ftp_app_demo init"); err = ql_rtos_task_create(&ftp_task, 16*1024, APP_PRIORITY_ABOVE_NORMAL, "QftpApp2", ftp_app_thread, NULL, 5); if(err != QL_OSI_SUCCESS) { QL_FTP_LOG("ftp_app_demo init failed"); } else { QL_FTP_LOG("ftp_app_demo init ok"); } return err; }