KT24-1110_65E-HA-651B/apps/soundbox/smartbox/file_transfer/dev_format.c

91 lines
2.5 KiB
C
Raw Normal View History

2024-11-10 10:44:17 +00:00
#include "dev_format.h"
#include "smartbox/smartbox.h"
#include "system/fs/fs.h"
#include "dev_manager.h"
#if (SMART_BOX_EN && TCFG_DEV_MANAGER_ENABLE)
enum {
DEV_FORMAT_ERR_NONE = 0,
DEV_FORMAT_ERR_OFFLINE,
DEV_FORMAT_ERR_FAIL,
};
void (*end_cbk)(void) = NULL;
//*----------------------------------------------------------------------------*/
/**@brief 设备格式化初始化(手机客户端发指令)
@param
@return
@note
*/
/*----------------------------------------------------------------------------*/
void dev_format_init(void (*end_callback)(void))
{
end_cbk = end_callback;
}
//*----------------------------------------------------------------------------*/
/**@brief 设备格式化退出
@param
@return
@note
*/
/*----------------------------------------------------------------------------*/
static void dev_format_close(void)
{
if (end_cbk) {
end_cbk();
}
}
//*----------------------------------------------------------------------------*/
/**@brief 设备格式化处理响应(手机客户端发指令)
@param
@return
@note
*/
/*----------------------------------------------------------------------------*/
void dev_format_start(u8 OpCode_SN, u8 *data, u16 len)
{
u8 reason = DEV_FORMAT_ERR_NONE;
u32 dev_handle = READ_BIG_U32(data);
char *logo = smartbox_browser_dev_remap(dev_handle);
if (logo == NULL) {
reason = DEV_FORMAT_ERR_FAIL ;
JL_CMD_response_send(JL_OPCODE_DEVICE_FORMAT, JL_PRO_STATUS_FAIL, OpCode_SN, &reason, 1);
dev_format_close();
return ;
}
char *root_path = dev_manager_get_root_path_by_logo(logo);
if (root_path) {
wdt_disable();
int err = f_format(root_path, "fat", 32 * 1024);
wdt_enable();
if (err) {
reason = DEV_FORMAT_ERR_FAIL ;
JL_CMD_response_send(JL_OPCODE_DEVICE_FORMAT, JL_PRO_STATUS_FAIL, OpCode_SN, &reason, 1);
} else {
printf("dev format ok\n");
JL_CMD_response_send(JL_OPCODE_DEVICE_FORMAT, JL_PRO_STATUS_SUCCESS, OpCode_SN, &reason, 1);
dev_format_close();
return ;
}
} else {
reason = DEV_FORMAT_ERR_OFFLINE ;
JL_CMD_response_send(JL_OPCODE_DEVICE_FORMAT, JL_PRO_STATUS_FAIL, OpCode_SN, &reason, 1);
}
dev_format_close();
printf("dev format fail\n");
}
#else
void dev_format_init(void (*end_callback)(void))
{
}
void dev_format_start(u8 OpCode_SN, u8 *data, u16 len)
{
}
#endif