9ceb218f80
Co-authored-by: Cursor <cursoragent@cursor.com>
177 lines
5.1 KiB
C
177 lines
5.1 KiB
C
/**
|
|
* @file debug_files.h
|
|
* @brief 文件类业务:FileOperations (FATFS) + FirmwareUpgrade (Flash IAP) — 阶段2合并
|
|
*
|
|
* 合并自:system_filectrl.h、system_filetransfer.h
|
|
*/
|
|
|
|
#ifndef DEBUG_FILES_H
|
|
#define DEBUG_FILES_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* ========== FileOperations (FATFS) ========== */
|
|
|
|
#define FILE_OP_SUBCMD_QUERY "Query"
|
|
#define FILE_OP_SUBCMD_DELETE "Delete"
|
|
#define FILE_OP_SUBCMD_DOWNLOAD "Download"
|
|
#define FILE_OP_SUBCMD_UPLOAD "Upload"
|
|
|
|
#define FILE_OP_STATUS_SUCCESS 0
|
|
#define FILE_OP_STATUS_FAILED 1
|
|
#define FILE_OP_STATUS_IN_PROGRESS 2
|
|
#define FILE_OP_STATUS_NOT_FOUND 3
|
|
#define FILE_OP_STATUS_NO_SPACE 4
|
|
#define FILE_OP_STATUS_PERMISSION_DENIED 5
|
|
|
|
#define FILE_TYPE_REGULAR 0
|
|
#define FILE_TYPE_DIRECTORY 1
|
|
#define FILE_TYPE_SYSTEM 2
|
|
|
|
typedef struct {
|
|
char name[128];
|
|
uint8_t type;
|
|
uint32_t size;
|
|
char modified_time[32];
|
|
char created_time[32];
|
|
} file_info_t;
|
|
|
|
typedef struct {
|
|
char path[256];
|
|
uint8_t recursive;
|
|
} file_query_request_t;
|
|
|
|
typedef struct {
|
|
char path[256];
|
|
uint16_t file_count;
|
|
uint16_t dir_count;
|
|
uint32_t total_size;
|
|
file_info_t *files;
|
|
} file_query_response_t;
|
|
|
|
typedef struct {
|
|
char path[256];
|
|
uint8_t force;
|
|
} file_delete_request_t;
|
|
|
|
typedef struct {
|
|
char path[256];
|
|
uint8_t status;
|
|
char message[128];
|
|
} file_delete_response_t;
|
|
|
|
typedef struct {
|
|
char path[256];
|
|
uint32_t offset;
|
|
uint32_t chunk_size;
|
|
} file_download_request_t;
|
|
|
|
typedef struct {
|
|
char path[256];
|
|
uint32_t file_size;
|
|
uint32_t offset;
|
|
uint32_t chunk_size;
|
|
uint32_t data_len;
|
|
uint8_t *data;
|
|
uint8_t is_last_chunk;
|
|
} file_download_response_t;
|
|
|
|
typedef struct {
|
|
char path[256];
|
|
uint32_t file_size;
|
|
uint32_t chunk_size;
|
|
uint32_t offset;
|
|
uint32_t data_len;
|
|
uint8_t *data;
|
|
uint8_t is_last_chunk;
|
|
} file_upload_request_t;
|
|
|
|
typedef struct {
|
|
char path[256];
|
|
uint32_t received_size;
|
|
uint32_t total_size;
|
|
uint8_t status;
|
|
char message[128];
|
|
} file_upload_response_t;
|
|
|
|
typedef struct {
|
|
char subCommand[32];
|
|
union {
|
|
file_query_request_t query;
|
|
file_delete_request_t delete;
|
|
file_download_request_t download;
|
|
file_upload_request_t upload;
|
|
} request;
|
|
union {
|
|
file_query_response_t query;
|
|
file_delete_response_t delete;
|
|
file_download_response_t download;
|
|
file_upload_response_t upload;
|
|
} response;
|
|
} file_operation_data_t;
|
|
|
|
int system_filectrl_init(void);
|
|
int system_filectrl_process_query(const file_query_request_t *request, file_query_response_t *response);
|
|
int system_filectrl_process_delete(const file_delete_request_t *request, file_delete_response_t *response);
|
|
int system_filectrl_process_download(const file_download_request_t *request, file_download_response_t *response);
|
|
int system_filectrl_process_upload(const file_upload_request_t *request, file_upload_response_t *response);
|
|
void system_filectrl_free_query_response(file_query_response_t *response);
|
|
void system_filectrl_free_download_response(file_download_response_t *response);
|
|
void system_filectrl_free_upload_request(file_upload_request_t *request);
|
|
int system_filectrl_get_filesystem_info(uint32_t *total_space, uint32_t *free_space);
|
|
int system_filectrl_file_exists(const char *path);
|
|
int system_filectrl_get_file_info(const char *path, file_info_t *info);
|
|
|
|
#ifndef TCP_DEBUG_FILE_AVAILABLE
|
|
#define TCP_DEBUG_FILE_AVAILABLE 0
|
|
#endif
|
|
|
|
/* ========== FirmwareUpgrade (Flash IAP) ========== */
|
|
|
|
typedef enum {
|
|
FILE_TRANSFER_IDLE = 0,
|
|
FILE_TRANSFER_STARTED,
|
|
FILE_TRANSFER_RECEIVING,
|
|
FILE_TRANSFER_COMPLETED,
|
|
FILE_TRANSFER_FAILED
|
|
} file_transfer_state_t;
|
|
|
|
typedef struct {
|
|
file_transfer_state_t state;
|
|
uint32_t file_size;
|
|
uint32_t total_packets;
|
|
uint32_t packet_size;
|
|
uint32_t received_packets;
|
|
uint32_t received_bytes;
|
|
char firmware_version[32];
|
|
uint32_t crc32;
|
|
uint8_t *buffer;
|
|
} firmware_upgrade_context_t;
|
|
|
|
int system_filetransfer_init(void);
|
|
int system_filetransfer_start_firmware_upgrade(uint32_t file_size, uint32_t total_packets,
|
|
uint32_t packet_size, const char *firmware_version);
|
|
/** 应答 Start 后执行:擦除升级区并写升级头(可能阻塞数秒) */
|
|
int system_filetransfer_commit_firmware_start(void);
|
|
int system_filetransfer_receive_firmware_packet(uint32_t packet_index, const uint8_t *data,
|
|
uint32_t data_len, uint32_t crc);
|
|
int system_filetransfer_end_firmware_upgrade(uint8_t status, const char *error_message);
|
|
int system_filetransfer_is_reboot_pending(void);
|
|
void system_filetransfer_clear_reboot_pending(void);
|
|
int system_filetransfer_get_firmware_status(firmware_upgrade_context_t *context);
|
|
int system_filetransfer_is_active(void);
|
|
int system_filetransfer_get_expected_packet_bytes(uint32_t packet_index, uint32_t *out_len);
|
|
void system_filetransfer_touch_activity_on_rx(void);
|
|
void system_filetransfer_poll_idle_timeout(void);
|
|
void system_filetransfer_reset(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* DEBUG_FILES_H */
|