19 changed files with 475 additions and 119 deletions
-
1.cproject
-
2.settings/language.settings.xml
-
7.vscode/settings.json
-
2Core
-
81FATFS/App/fatfs.c
-
2FATFS/Target/ffconf.h
-
2README.md
-
114USB_HOST/App/usb_host.c
-
7uappbase/apphal/apphal.cpp
-
158usrc/fileoperation/zusb_file_operator.cpp
-
21usrc/fileoperation/zusb_file_operator.hpp
-
2usrc/project_configs.h
-
32usrc/service/app_core.cpp
-
30usrc/service/valve_state_ctrl_service.cpp
-
46usrc/uicontroler/page/mupage/MuAcidDistMgrPage.cpp
-
60usrc/uicontroler/page/mupage/muAcidUseMgr_page.cpp
-
9usrc/uicontroler/page/mupage/muCHSetting_page.cpp
-
16usrc/uicontroler/page/mupage/muUsrMgr_page.cpp
-
2usrc/uicontroler/ui_controler.cpp
@ -1 +1 @@ |
|||
Subproject commit 41922cfe8ea480cafe9b982f2f204a07ee88a9a7 |
|||
Subproject commit aaf909385c23f3ed678ad802aa9850f3be487922 |
@ -0,0 +1,158 @@ |
|||
#include "zusb_file_operator.hpp"
|
|||
|
|||
extern "C" { |
|||
#include "FatFs.h"
|
|||
#include "USB_HOST\App\usb_host.h"
|
|||
#include "main.h"
|
|||
#include "stdio.h"
|
|||
#include "stm32basic\basic\zlog.h"
|
|||
} |
|||
|
|||
using namespace iflytop; |
|||
|
|||
#define TAG "ZUSBFileOperator"
|
|||
|
|||
#define User_Sector 512 /*用户存储设备扇区字节数*/
|
|||
#define USBHFatFS USBHFatFS /*用户存储设备FatFs对象*/
|
|||
#define USBHPath USBHPath /*用户存储设备卷路径*/
|
|||
#define User_FatType FM_FAT32 /*用户存储设备初始化类型*/
|
|||
|
|||
static char m_errorInfo[128]; |
|||
static bool m_operationSuc; |
|||
|
|||
static FIL m_file; |
|||
static bool openSunc; |
|||
|
|||
extern "C" { |
|||
extern ApplicationTypeDef Appli_state; |
|||
} |
|||
|
|||
static const char* FRESULT_TO_STR(FRESULT result) { |
|||
switch (result) { |
|||
case FR_OK: |
|||
return "成功"; |
|||
case FR_DISK_ERR: |
|||
return "硬件错误"; |
|||
case FR_INT_ERR: |
|||
return "断言失败"; |
|||
case FR_NOT_READY: |
|||
return "物理驱动器无法工作"; |
|||
case FR_NO_FILE: |
|||
return "找不到文件"; |
|||
case FR_NO_PATH: |
|||
return "找不到路径"; |
|||
case FR_INVALID_NAME: |
|||
return "路径名格式无效"; |
|||
case FR_DENIED: |
|||
return "由于禁止访问或目录已满而拒绝访问"; |
|||
case FR_EXIST: |
|||
return "由于禁止访问而拒绝访问"; |
|||
case FR_INVALID_OBJECT: |
|||
return "文件/目录对象无效"; |
|||
case FR_WRITE_PROTECTED: |
|||
return "物理驱动器受写保护"; |
|||
case FR_INVALID_DRIVE: |
|||
return "逻辑驱动器号无效"; |
|||
case FR_NOT_ENABLED: |
|||
return "卷没有工作区"; |
|||
case FR_NO_FILESYSTEM: |
|||
return "磁盘未格式化成FAT文件系统"; |
|||
case FR_MKFS_ABORTED: |
|||
return "由于任何问题,f_mkfs()中止"; |
|||
case FR_TIMEOUT: |
|||
return "无法在定义的时间段内获得访问卷的授权"; |
|||
case FR_LOCKED: |
|||
return "根据文件共享策略拒绝操作"; |
|||
case FR_NOT_ENOUGH_CORE: |
|||
return "无法分配LFN工作缓冲区"; |
|||
case FR_TOO_MANY_OPEN_FILES: |
|||
return "打开文件数>_FS_LOCK"; |
|||
case FR_INVALID_PARAMETER: |
|||
return "给定参数无效"; |
|||
default: |
|||
return "未知错误"; |
|||
} |
|||
} |
|||
|
|||
static void setErrorInfo(bool suc, const char* info) { |
|||
memset(m_errorInfo, 0, sizeof(m_errorInfo)); |
|||
strncpy(m_errorInfo, info, sizeof(m_errorInfo)); |
|||
} |
|||
|
|||
void ZUSBFileOperator::mount() { |
|||
if (Appli_state != APPLICATION_READY) { |
|||
ZLOGE(TAG, "USB not ready"); |
|||
setErrorInfo(false, "请插入U盘"); |
|||
return; |
|||
} |
|||
|
|||
FRESULT retUSER = f_mount(&USBHFatFS, USBHPath, 1); |
|||
if (retUSER != FR_OK) { |
|||
ZLOGE(TAG, "file system mount fail, error code:%d(%s)", retUSER, FRESULT_TO_STR(retUSER)); |
|||
setErrorInfo(false, FRESULT_TO_STR(retUSER)); |
|||
return; |
|||
} |
|||
setErrorInfo(true, FRESULT_TO_STR(FR_OK)); |
|||
ZLOGI(TAG, "file system mount success"); |
|||
return; |
|||
} |
|||
void ZUSBFileOperator::unmount() { |
|||
FRESULT retUSER = f_mount(NULL, USBHPath, 1); |
|||
if (retUSER != FR_OK) { |
|||
ZLOGE(TAG, "file system unmount fail, error code:%d(%s)", retUSER, FRESULT_TO_STR(retUSER)); |
|||
setErrorInfo(false, FRESULT_TO_STR(retUSER)); |
|||
return; |
|||
} |
|||
setErrorInfo(true, FRESULT_TO_STR(FR_OK)); |
|||
ZLOGI(TAG, "file system unmount success"); |
|||
return; |
|||
} |
|||
|
|||
void ZUSBFileOperator::openNew(const char* filename, ...) { |
|||
char path[128] = {0}; |
|||
va_list args; |
|||
va_start(args, filename); |
|||
vsnprintf(path, sizeof(path), filename, args); |
|||
va_end(args); |
|||
|
|||
ZLOGI(TAG, "openNew filename:%s", path); |
|||
FRESULT result = f_open(&m_file, path, FA_CREATE_ALWAYS | FA_WRITE); |
|||
if (result != FR_OK) { |
|||
ZLOGE(TAG, "open file fail, error code:%d(%s)", result, FRESULT_TO_STR(result)); |
|||
setErrorInfo(false, FRESULT_TO_STR(result)); |
|||
return; |
|||
} |
|||
openSunc = true; |
|||
setErrorInfo(true, FRESULT_TO_STR(FR_OK)); |
|||
} |
|||
void ZUSBFileOperator::close() { |
|||
ZLOGI(TAG, "close"); |
|||
if (openSunc) f_close(&m_file); |
|||
} |
|||
int ZUSBFileOperator::write(const char* fmt, ...) { |
|||
static char buf[256]; |
|||
va_list args; |
|||
va_start(args, fmt); |
|||
vsnprintf(buf, sizeof(buf), fmt, args); |
|||
va_end(args); |
|||
return write((uint8_t*)buf, strlen(buf)); |
|||
} |
|||
|
|||
int ZUSBFileOperator::write(uint8_t* buf, uint32_t len) { |
|||
if (!openSunc) { |
|||
setErrorInfo(false, "file not open"); |
|||
return -1; |
|||
} |
|||
UINT bw; |
|||
FRESULT result = f_write(&m_file, buf, len, &bw); |
|||
if (result != FR_OK) { |
|||
ZLOGE(TAG, "write file fail, error code:%d(%s)", result, FRESULT_TO_STR(result)); |
|||
setErrorInfo(false, FRESULT_TO_STR(result)); |
|||
return -1; |
|||
} |
|||
setErrorInfo(true, FRESULT_TO_STR(FR_OK)); |
|||
return bw; |
|||
} |
|||
|
|||
bool ZUSBFileOperator::getOperationStatus() { return m_operationSuc; } |
|||
const char* ZUSBFileOperator::getErrorInfo() { return m_errorInfo; } |
@ -0,0 +1,21 @@ |
|||
#pragma once
|
|||
#include <stdbool.h>
|
|||
#include <stdint.h>
|
|||
namespace iflytop { |
|||
|
|||
class ZUSBFileOperator { |
|||
public: |
|||
static void mount(); |
|||
static void unmount(); |
|||
|
|||
static void openNew(const char* filename, ...); |
|||
static void close(); |
|||
|
|||
static int write(uint8_t* buf, uint32_t len); |
|||
static int write(const char* fmt,...); |
|||
|
|||
static bool getOperationStatus(); |
|||
static const char* getErrorInfo(); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue