| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749 |
- ///*
- // * Copyright (c) 2006-2021, RT-Thread Development Team
- // *
- // * SPDX-License-Identifier: Apache-2.0
- // *
- // * Change Logs:
- // * Date Author Notes
- // * 2026-01-17 RuoFeng the first version
- // */
- //#include "ftp_up.h"
- //#include "zFTP.h"
- //#include "ch376_driver.h"
- //#include "bsp_csv.h"
- //#include <fal.h>
- //#include <string.h>
- //#include <rtdevice.h>
- //#include "rtthread.h"
- //
- //#define DBG_ENABLE
- //#define DBG_SECTION_NAME "FTP_APP"
- //#define DBG_LEVEL DBG_INFO
- //#include <rtdbg.h>
- //
- //#define FTP_APP_CONFIG_SERVER_ADDR "www.yfzhwlw.com"
- //#define FTP_APP_CONFIG_USERNAME "updateuser"
- //#define FTP_APP_CONFIG_PASSWORD "123456"
- //#define FTP_APP_CONFIG_CSV_PATH "/qxz_csv"
- //
- //static ftp_app_result_t upload_ecode_csv(void);
- //
- //static struct
- //{
- // uint8_t busy_flag;
- // uint8_t initialized;
- // char last_error[64];
- // uint32_t total_transferred;
- //
- // char current_local_file[32];
- // char current_remote_file[64];
- // uint32_t current_file_size;
- //
- // uint8_t first_block_buffer[FTP_APP_UPLOAD_BUFFER_SIZE];
- // uint32_t first_block_size;
- // uint8_t first_block_ready;
- //} ftp_state = {0};
- //
- //static struct rt_mutex ftp_mutex;
- //
- //static int csv_read_callback(void *handle, char *remote_filename, rt_uint8_t *buf,
- // rt_uint32_t len, rt_uint32_t pos,
- // rt_uint32_t *read_len, rt_uint32_t *total_len)
- //{
- // ch376_result_t result;
- // uint32_t actual_read = 0;
- // static uint32_t call_count = 0;
- // uint32_t this_call = ++call_count;
- //
- // LOG_D("[CSV-%lu] Callback: pos=%lu, len=%lu, cached=%d",
- // this_call, pos, len, ftp_state.first_block_ready);
- //
- // if (!buf || !read_len || !total_len)
- // {
- // LOG_E("[CSV-%lu] Invalid parameters", this_call);
- // return -RT_ERROR;
- // }
- //
- // if (ftp_state.current_local_file[0] == '\0' || ftp_state.current_file_size == 0)
- // {
- // LOG_E("[CSV-%lu] No file prepared!", this_call);
- // *read_len = 0;
- // *total_len = 0;
- // return -RT_ERROR;
- // }
- //
- // *total_len = ftp_state.current_file_size;
- // *read_len = 0;
- //
- // if (pos >= ftp_state.current_file_size)
- // {
- // LOG_D("[CSV-%lu] End of file reached", this_call);
- // return RT_EOK;
- // }
- //
- // if (pos == 0 && ftp_state.first_block_ready && ftp_state.first_block_size > 0)
- // {
- // LOG_D("[CSV-%lu] Using cached first block: %lu bytes",
- // this_call, ftp_state.first_block_size);
- //
- // uint32_t to_copy = ftp_state.first_block_size;
- // if (to_copy > len) to_copy = len;
- //
- // memcpy(buf, ftp_state.first_block_buffer, to_copy);
- // *read_len = to_copy;
- //
- // LOG_D("[CSV-%lu] Returned cached data immediately", this_call);
- // return RT_EOK;
- // }
- //
- // uint32_t to_read = ftp_state.current_file_size - pos;
- // if (to_read > len) to_read = len;
- // if (to_read > FTP_APP_UPLOAD_BUFFER_SIZE) to_read = FTP_APP_UPLOAD_BUFFER_SIZE;
- //
- // LOG_D("[CSV-%lu] Reading %lu bytes from pos %lu", this_call, to_read, pos);
- //
- // result = ch376.init();
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // LOG_E("[CSV-%lu] CH376 init failed: %d", this_call, result);
- // return -RT_ERROR;
- // }
- //
- // result = ch376.switch_mode(CH376_MODE_SD_CARD);
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // ch376.deinit();
- // LOG_E("[CSV-%lu] Switch to SD mode failed: %d", this_call, result);
- // return -RT_ERROR;
- // }
- //
- // result = ch376.file_open(ftp_state.current_local_file);
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // ch376.deinit();
- // LOG_E("[CSV-%lu] Cannot open file: %s", this_call, ftp_state.current_local_file);
- // return -RT_ERROR;
- // }
- //
- // result = ch376.file_seek(pos);
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // ch376.file_close();
- // ch376.deinit();
- // LOG_E("[CSV-%lu] Seek failed: pos=%lu", this_call, pos);
- // return -RT_ERROR;
- // }
- //
- // result = ch376.file_read(buf, to_read, &actual_read);
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // ch376.file_close();
- // ch376.deinit();
- // LOG_E("[CSV-%lu] Read failed: pos=%lu", this_call, pos);
- // return -RT_ERROR;
- // }
- //
- // ch376.file_close();
- // ch376.deinit();
- //
- // *read_len = actual_read;
- //
- // LOG_D("[CSV-%lu] Read successful: %lu bytes", this_call, actual_read);
- //
- // return RT_EOK;
- //}
- //
- //static void set_last_error(const char *error)
- //{
- // if (error)
- // {
- // strncpy(ftp_state.last_error, error, sizeof(ftp_state.last_error) - 1);
- // ftp_state.last_error[sizeof(ftp_state.last_error) - 1] = '\0';
- // LOG_E("Error: %s", error);
- // }
- //}
- //
- //static uint8_t acquire_operation_lock(void)
- //{
- // if (rt_mutex_take(&ftp_mutex, 3000) != RT_EOK)
- // {
- // return 0;
- // }
- //
- // if (ftp_state.busy_flag)
- // {
- // rt_mutex_release(&ftp_mutex);
- // return 0;
- // }
- //
- // ftp_state.busy_flag = 1;
- // memset(ftp_state.last_error, 0, sizeof(ftp_state.last_error));
- // ftp_state.total_transferred = 0;
- //
- // memset(ftp_state.current_local_file, 0, sizeof(ftp_state.current_local_file));
- // memset(ftp_state.current_remote_file, 0, sizeof(ftp_state.current_remote_file));
- // ftp_state.current_file_size = 0;
- // ftp_state.first_block_size = 0;
- // ftp_state.first_block_ready = 0;
- //
- // return 1;
- //}
- //
- //static void release_operation_lock(void)
- //{
- // ftp_state.busy_flag = 0;
- // rt_mutex_release(&ftp_mutex);
- //}
- //
- //static ftp_app_result_t ftp_connect(zftp_client **ftp)
- //{
- // *ftp = zFTP_login(FTP_APP_CONFIG_USERNAME, FTP_APP_CONFIG_PASSWORD,
- // FTP_APP_CONFIG_SERVER_ADDR);
- // if (*ftp == RT_NULL)
- // {
- // LOG_E("FTP login failed");
- // return FTP_APP_RESULT_CONNECT_FAILED;
- // }
- //
- // LOG_I("FTP connected");
- // return FTP_APP_RESULT_SUCCESS;
- //}
- //
- //static void ftp_disconnect(zftp_client *ftp)
- //{
- // if (ftp)
- // {
- // zFTP_quit(ftp);
- // }
- //}
- //
- //static ftp_app_result_t ensure_remote_path(zftp_client *ftp, const char *path)
- //{
- // int retry;
- //
- // for (retry = 0; retry < 3; retry++)
- // {
- // if (zFTP_change_path(ftp, path) == RT_EOK)
- // {
- // return FTP_APP_RESULT_SUCCESS;
- // }
- // if (retry < 2)
- // {
- // rt_thread_mdelay(100);
- // }
- // }
- //
- // LOG_E("Cannot access path: %s", path);
- // return FTP_APP_RESULT_PATH_ERROR;
- //}
- //
- //static ftp_app_result_t prepare_file_for_upload(const char *local_filename)
- //{
- // ch376_result_t result;
- // uint32_t file_size = 0;
- //
- // LOG_I("Preparing file: %s", local_filename);
- //
- // memset(ftp_state.current_local_file, 0, sizeof(ftp_state.current_local_file));
- // memset(ftp_state.current_remote_file, 0, sizeof(ftp_state.current_remote_file));
- // ftp_state.current_file_size = 0;
- // ftp_state.first_block_size = 0;
- // ftp_state.first_block_ready = 0;
- //
- // result = ch376.init();
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // LOG_E("CH376 init failed: %d", result);
- // return FTP_APP_RESULT_DISK_NOT_READY;
- // }
- //
- // result = ch376.switch_mode(CH376_MODE_SD_CARD);
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // ch376.deinit();
- // LOG_E("Switch to SD mode failed: %d", result);
- // return FTP_APP_RESULT_DISK_NOT_READY;
- // }
- //
- // result = ch376.file_exists(local_filename);
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // ch376.deinit();
- // LOG_E("File not found: %s", local_filename);
- // return FTP_APP_RESULT_FILE_NOT_FOUND;
- // }
- //
- // result = ch376.file_open(local_filename);
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // ch376.deinit();
- // LOG_E("Cannot open file: %s", local_filename);
- // return FTP_APP_RESULT_ERROR;
- // }
- //
- // result = ch376.file_getsize(&file_size);
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // ch376.file_close();
- // ch376.deinit();
- // LOG_E("Cannot get file size: %s", local_filename);
- // return FTP_APP_RESULT_ERROR;
- // }
- //
- // LOG_I("File size: %lu bytes", file_size);
- //
- // if (file_size > 0)
- // {
- // uint32_t to_read = FTP_APP_UPLOAD_BUFFER_SIZE;
- // if (to_read > file_size)
- // {
- // to_read = file_size;
- // }
- //
- // result = ch376.file_read(ftp_state.first_block_buffer, to_read, &ftp_state.first_block_size);
- // if (result != CH376_RESULT_SUCCESS)
- // {
- // LOG_E("Failed to read first block");
- // ftp_state.first_block_size = 0;
- // }
- // else
- // {
- // ftp_state.first_block_ready = 1;
- // LOG_I("First %lu bytes cached for immediate response", ftp_state.first_block_size);
- // }
- // }
- //
- // ch376.file_close();
- // ch376.deinit();
- //
- // strncpy(ftp_state.current_local_file, local_filename,
- // sizeof(ftp_state.current_local_file) - 1);
- // ftp_state.current_local_file[sizeof(ftp_state.current_local_file) - 1] = '\0';
- //
- // ftp_state.current_file_size = file_size;
- //
- // const char *basename = local_filename;
- // if (local_filename[0] == '/')
- // {
- // basename = local_filename + 1;
- // }
- // snprintf(ftp_state.current_remote_file, sizeof(ftp_state.current_remote_file),
- // "%s_%s", qxz.Param.device_sn, basename);
- //
- // LOG_I("File prepared: %s -> %s (%lu bytes)",
- // ftp_state.current_local_file, ftp_state.current_remote_file,
- // ftp_state.current_file_size);
- //
- // return FTP_APP_RESULT_SUCCESS;
- //}
- //
- //static ftp_app_result_t upload_single_csv(const char *local_filename, zftp_client *ftp)
- //{
- // LOG_I("Starting upload: %s", local_filename);
- //
- // ftp_app_result_t result = prepare_file_for_upload(local_filename);
- // if (result != FTP_APP_RESULT_SUCCESS)
- // {
- // return result;
- // }
- //
- // zFTP_set_callback(ftp, RT_NULL, csv_read_callback, RT_NULL);
- //
- // if (ensure_remote_path(ftp, FTP_APP_CONFIG_CSV_PATH) != FTP_APP_RESULT_SUCCESS)
- // {
- // LOG_E("Cannot change to CSV path");
- // return FTP_APP_RESULT_PATH_ERROR;
- // }
- //
- // LOG_I("Waiting 200ms for FTP server stabilization...");
- // rt_thread_mdelay(200);
- //
- // LOG_I("Uploading to FTP: %s", ftp_state.current_remote_file);
- //
- // int retry_count;
- // for (retry_count = 0; retry_count < 10; retry_count++)
- // {
- // if (retry_count > 0)
- // {
- // LOG_W("Retry attempt %d for %s", retry_count, ftp_state.current_remote_file);
- // rt_thread_mdelay(200 * retry_count);
- // }
- //
- // uint32_t start_time = rt_tick_get();
- //
- // if (zFTP_upload_file(ftp, ftp_state.current_remote_file) == RT_EOK)
- // {
- // uint32_t end_time = rt_tick_get();
- // uint32_t duration = (end_time - start_time) * 1000 / RT_TICK_PER_SECOND;
- //
- // ftp_state.total_transferred += ftp_state.current_file_size;
- // LOG_I("Upload completed: %s -> %s (%lu bytes, took %lu ms, retry=%d)",
- // ftp_state.current_local_file, ftp_state.current_remote_file,
- // ftp_state.current_file_size, duration, retry_count);
- //
- // memset(ftp_state.current_local_file, 0, sizeof(ftp_state.current_local_file));
- // memset(ftp_state.current_remote_file, 0, sizeof(ftp_state.current_remote_file));
- // ftp_state.current_file_size = 0;
- // ftp_state.first_block_size = 0;
- // ftp_state.first_block_ready = 0;
- //
- // return FTP_APP_RESULT_SUCCESS;
- // }
- // else
- // {
- // uint32_t elapsed = (rt_tick_get() - start_time) * 1000 / RT_TICK_PER_SECOND;
- // LOG_W("Upload attempt %d failed after %lu ms", retry_count + 1, elapsed);
- // }
- // }
- //
- // LOG_E("All upload attempts failed for: %s", ftp_state.current_remote_file);
- // return FTP_APP_RESULT_ERROR;
- //}
- //
- //static ftp_app_result_t upload_all_csv(void)
- //{
- // if (!acquire_operation_lock())
- // {
- // return FTP_APP_RESULT_ERROR;
- // }
- //
- // LOG_I("Starting CSV upload...");
- //
- // zftp_client *ftp = NULL;
- // ftp_app_result_t result;
- // int success_count = 0;
- //
- // result = ftp_connect(&ftp);
- // if (result != FTP_APP_RESULT_SUCCESS)
- // {
- // release_operation_lock();
- // return result;
- // }
- //
- // csv_bitmap_init();
- //
- // time_t now = time(NULL);
- // struct tm current_tm;
- // struct tm *p = localtime(&now);
- // if (!p)
- // {
- // ftp_disconnect(ftp);
- // release_operation_lock();
- // return FTP_APP_RESULT_ERROR;
- // }
- // current_tm = *p;
- //
- // int today_offset = calc_day_offset_from_tm(¤t_tm);
- // for (int offset = 0; offset <= today_offset; offset++)
- // {
- // if (!csv_bitmap_is_exist_by_offset(offset))
- // {
- // continue;
- // }
- //
- // struct tm file_tm;
- // if (offset_to_date(offset, &file_tm) != 0)
- // {
- // continue;
- // }
- //
- // int yy = file_tm.tm_year % 100;
- // int mm = file_tm.tm_mon + 1;
- // int dd = file_tm.tm_mday;
- //
- // char local_filename[13];
- // snprintf(local_filename, sizeof(local_filename), "/%02d%02d%02d.CSV", yy, mm, dd);
- //
- // LOG_I("[%d] Uploading: %s", success_count + 1, local_filename);
- //
- // if (upload_single_csv(local_filename, ftp) == FTP_APP_RESULT_SUCCESS)
- // {
- // success_count++;
- // }
- //
- // rt_thread_mdelay(50);
- // }
- //
- // result = (success_count > 0) ? FTP_APP_RESULT_SUCCESS : FTP_APP_RESULT_ERROR;
- //
- // ftp_disconnect(ftp);
- // release_operation_lock();
- //
- // LOG_I("CSV upload complete: %d files", success_count);
- // return result;
- //}
- //
- //static ftp_app_result_t upload_csv_by_date(int year, int month, int day)
- //{
- // if (!acquire_operation_lock())
- // {
- // return FTP_APP_RESULT_ERROR;
- // }
- //
- // char local_filename[13];
- // snprintf(local_filename, sizeof(local_filename), "/%02d%02d%02d.CSV", year, month, day);
- //
- // LOG_I("Uploading by date: %s", local_filename);
- //
- // zftp_client *ftp = NULL;
- // ftp_app_result_t result;
- //
- // result = ftp_connect(&ftp);
- // if (result != FTP_APP_RESULT_SUCCESS)
- // {
- // release_operation_lock();
- // return result;
- // }
- //
- // result = upload_single_csv(local_filename, ftp);
- //
- // ftp_disconnect(ftp);
- // release_operation_lock();
- //
- // return result;
- //}
- //
- //static ftp_app_result_t upload_csv_file(const char *filename)
- //{
- // if (!filename)
- // {
- // return FTP_APP_RESULT_ERROR;
- // }
- //
- // if (!acquire_operation_lock())
- // {
- // return FTP_APP_RESULT_ERROR;
- // }
- //
- // LOG_I("Uploading file: %s", filename);
- //
- // zftp_client *ftp = NULL;
- // ftp_app_result_t result;
- //
- // result = ftp_connect(&ftp);
- // if (result != FTP_APP_RESULT_SUCCESS)
- // {
- // release_operation_lock();
- // return result;
- // }
- //
- // result = upload_single_csv(filename, ftp);
- //
- // ftp_disconnect(ftp);
- // release_operation_lock();
- //
- // return result;
- //}
- //
- //static ftp_app_result_t test_connection(void)
- //{
- // if (!acquire_operation_lock())
- // {
- // return FTP_APP_RESULT_ERROR;
- // }
- //
- // LOG_I("Testing FTP connection...");
- //
- // zftp_client *ftp = NULL;
- // ftp_app_result_t result = ftp_connect(&ftp);
- //
- // if (result == FTP_APP_RESULT_SUCCESS)
- // {
- // LOG_I("FTP connection OK");
- // ftp_disconnect(ftp);
- // }
- // else
- // {
- // LOG_E("FTP connection failed");
- // }
- //
- // release_operation_lock();
- // return result;
- //}
- //
- //static uint8_t is_busy(void)
- //{
- // return ftp_state.busy_flag;
- //}
- //
- //static const char *get_last_error(void)
- //{
- // return ftp_state.last_error;
- //}
- //
- //static uint32_t get_total_transferred(void)
- //{
- // return ftp_state.total_transferred;
- //}
- //
- //ftp_app_ops_t ftp_app = {
- // .upload_all_csv = upload_all_csv,
- // .upload_csv_by_date = upload_csv_by_date,
- // .upload_ecode_csv = upload_ecode_csv,
- // .upload_csv_file = upload_csv_file,
- // .test_connection = test_connection,
- // .is_busy = is_busy,
- // .get_last_error = get_last_error,
- // .get_total_transferred = get_total_transferred
- //};
- //
- //static int ftp_app_init(void)
- //{
- // rt_mutex_init(&ftp_mutex, "ftp_app", RT_IPC_FLAG_FIFO);
- // csv_bitmap_init();
- // ftp_state.initialized = 1;
- // LOG_I("FTP app initialized");
- // return RT_EOK;
- //}
- //INIT_APP_EXPORT(ftp_app_init);
- //
- //#ifdef FINSH_USING_MSH
- //#include <finsh.h>
- //
- //void upload_all_CSV(void)
- //{
- // ftp_app_result_t result = ftp_app.upload_all_csv();
- // if (result == FTP_APP_RESULT_SUCCESS)
- // {
- // rt_kprintf("CSV upload completed successfully\n");
- // }
- // else
- // {
- // rt_kprintf("CSV upload failed: %s\n", ftp_app.get_last_error());
- // }
- //}
- //MSH_CMD_EXPORT(upload_all_CSV, Upload all CSV files via FTP);
- //
- //void ftp_test(void)
- //{
- // ftp_app_result_t result = ftp_app.test_connection();
- // if (result == FTP_APP_RESULT_SUCCESS)
- // {
- // rt_kprintf("FTP connection test: SUCCESS\n");
- // }
- // else
- // {
- // rt_kprintf("FTP connection test: FAILED\n");
- // }
- //}
- //MSH_CMD_EXPORT(ftp_test, Test FTP connection);
- //
- //#endif
- //
- //static ftp_app_result_t upload_ecode_csv_internal(const char *local_filename, zftp_client *ftp)
- //{
- // LOG_I("Starting ECODE upload: %s", local_filename);
- //
- // ftp_app_result_t result = prepare_file_for_upload(local_filename);
- // if (result != FTP_APP_RESULT_SUCCESS)
- // {
- // return result;
- // }
- //
- // zFTP_set_callback(ftp, RT_NULL, csv_read_callback, RT_NULL);
- //
- // if (ensure_remote_path(ftp, FTP_APP_CONFIG_CSV_PATH) != FTP_APP_RESULT_SUCCESS)
- // {
- // LOG_E("Cannot change to CSV path");
- // return FTP_APP_RESULT_PATH_ERROR;
- // }
- //
- // char remote_ecode_filename[64];
- // snprintf(remote_ecode_filename, sizeof(remote_ecode_filename),
- // "%s_ECODE.CSV", qxz.Param.device_sn);
- //
- // LOG_I("Waiting 200ms for FTP server stabilization...");
- // rt_thread_mdelay(200);
- //
- // LOG_I("Uploading ECODE to FTP: %s -> %s",
- // ftp_state.current_local_file, remote_ecode_filename);
- //
- // int retry_count;
- // for (retry_count = 0; retry_count < 3; retry_count++)
- // {
- // if (retry_count > 0)
- // {
- // LOG_W("Retry attempt %d for ECODE", retry_count);
- // rt_thread_mdelay(200 * retry_count);
- // }
- //
- // uint32_t start_time = rt_tick_get();
- //
- // if (zFTP_upload_file(ftp, remote_ecode_filename) == RT_EOK)
- // {
- // uint32_t end_time = rt_tick_get();
- // uint32_t duration = (end_time - start_time) * 1000 / RT_TICK_PER_SECOND;
- //
- // ftp_state.total_transferred += ftp_state.current_file_size;
- // LOG_I("ECODE upload completed: %s -> %s (%lu bytes, took %lu ms, retry=%d)",
- // ftp_state.current_local_file, remote_ecode_filename,
- // ftp_state.current_file_size, duration, retry_count);
- //
- // memset(ftp_state.current_local_file, 0, sizeof(ftp_state.current_local_file));
- // memset(ftp_state.current_remote_file, 0, sizeof(ftp_state.current_remote_file));
- // ftp_state.current_file_size = 0;
- // ftp_state.first_block_size = 0;
- // ftp_state.first_block_ready = 0;
- //
- // return FTP_APP_RESULT_SUCCESS;
- // }
- // else
- // {
- // uint32_t elapsed = (rt_tick_get() - start_time) * 1000 / RT_TICK_PER_SECOND;
- // LOG_W("ECODE upload attempt %d failed after %lu ms", retry_count + 1, elapsed);
- // }
- // }
- //
- // LOG_E("All ECODE upload attempts failed");
- // return FTP_APP_RESULT_ERROR;
- //}
- //
- //static ftp_app_result_t upload_ecode_csv(void)
- //{
- // if (!acquire_operation_lock())
- // {
- // return FTP_APP_RESULT_ERROR;
- // }
- //
- // LOG_I("Starting ECODE.CSV upload...");
- //
- // zftp_client *ftp = NULL;
- // ftp_app_result_t result;
- //
- // result = ftp_connect(&ftp);
- // if (result != FTP_APP_RESULT_SUCCESS)
- // {
- // release_operation_lock();
- // return result;
- // }
- //
- // result = upload_ecode_csv_internal("/ECODE.CSV", ftp);
- //
- // ftp_disconnect(ftp);
- // release_operation_lock();
- //
- // if (result == FTP_APP_RESULT_SUCCESS)
- // {
- // LOG_I("ECODE.CSV upload completed successfully");
- // }
- // else
- // {
- // LOG_E("ECODE.CSV upload failed");
- // }
- //
- // return result;
- //}
- //
- //void upload_ecode(void)
- //{
- // ftp_app_result_t result = ftp_app.upload_ecode_csv();
- // if (result == FTP_APP_RESULT_SUCCESS)
- // {
- // rt_kprintf("ECODE.CSV upload completed successfully\n");
- // }
- // else
- // {
- // rt_kprintf("ECODE.CSV upload failed: %s\n", ftp_app.get_last_error());
- // }
- //}
- //MSH_CMD_EXPORT(upload_ecode, Upload ECODE.CSV file via FTP);
|