修改Ymodem组件中MSH的ry命令,已便于自定义保存路径 (#6433)
* 修改ry命令,已便于自定义保存路径 * modified: components/utilities/ymodem/ry_sy.c
This commit is contained in:
parent
a4829b1c00
commit
a4bd223e20
|
@ -36,9 +36,21 @@ static enum rym_code _rym_recv_begin(
|
||||||
rt_size_t len)
|
rt_size_t len)
|
||||||
{
|
{
|
||||||
struct custom_ctx *cctx = (struct custom_ctx *)ctx;
|
struct custom_ctx *cctx = (struct custom_ctx *)ctx;
|
||||||
|
struct stat file_buf;
|
||||||
cctx->fpath[0] = '/';
|
char insert_0 = '\0';
|
||||||
rt_strncpy(&(cctx->fpath[1]), (const char *)buf, len - 1);
|
char *ret;
|
||||||
|
rt_err_t err;
|
||||||
|
ret = strchr(cctx->fpath,insert_0);
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
*ret = '/';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rt_kprintf("No end character\n");
|
||||||
|
return RYM_ERR_ACK;
|
||||||
|
}
|
||||||
|
rt_strncpy(ret + 1, (const char *)buf, len - 1);
|
||||||
cctx->fd = open(cctx->fpath, O_CREAT | O_WRONLY | O_TRUNC, 0);
|
cctx->fd = open(cctx->fpath, O_CREAT | O_WRONLY | O_TRUNC, 0);
|
||||||
if (cctx->fd < 0)
|
if (cctx->fd < 0)
|
||||||
{
|
{
|
||||||
|
@ -154,7 +166,7 @@ static enum rym_code _rym_send_end(
|
||||||
return RYM_CODE_SOH;
|
return RYM_CODE_SOH;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t rym_download_file(rt_device_t idev)
|
static rt_err_t rym_download_file(rt_device_t idev,const char *file_path)
|
||||||
{
|
{
|
||||||
rt_err_t res;
|
rt_err_t res;
|
||||||
struct custom_ctx *ctx = rt_calloc(1, sizeof(*ctx));
|
struct custom_ctx *ctx = rt_calloc(1, sizeof(*ctx));
|
||||||
|
@ -165,6 +177,7 @@ static rt_err_t rym_download_file(rt_device_t idev)
|
||||||
return RT_ENOMEM;
|
return RT_ENOMEM;
|
||||||
}
|
}
|
||||||
ctx->fd = -1;
|
ctx->fd = -1;
|
||||||
|
rt_strncpy(ctx->fpath, file_path, DFS_PATH_MAX);
|
||||||
RT_ASSERT(idev);
|
RT_ASSERT(idev);
|
||||||
res = rym_recv_on_device(&ctx->parent, idev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
|
res = rym_recv_on_device(&ctx->parent, idev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
|
||||||
_rym_recv_begin, _rym_recv_data, _rym_recv_end, 1000);
|
_rym_recv_begin, _rym_recv_data, _rym_recv_end, 1000);
|
||||||
|
@ -201,9 +214,15 @@ static rt_err_t ry(uint8_t argc, char **argv)
|
||||||
{
|
{
|
||||||
rt_err_t res;
|
rt_err_t res;
|
||||||
rt_device_t dev;
|
rt_device_t dev;
|
||||||
|
/* temporarily support 1 file*/
|
||||||
if (argc > 1)
|
const char *file_path;
|
||||||
dev = rt_device_find(argv[1]);
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
rt_kprintf("invalid file path.\n");
|
||||||
|
return -RT_ERROR;
|
||||||
|
}
|
||||||
|
if (argc > 2)
|
||||||
|
dev = rt_device_find(argv[2]);
|
||||||
else
|
else
|
||||||
dev = rt_console_get_device();
|
dev = rt_console_get_device();
|
||||||
if (!dev)
|
if (!dev)
|
||||||
|
@ -211,11 +230,12 @@ static rt_err_t ry(uint8_t argc, char **argv)
|
||||||
rt_kprintf("could not find device.\n");
|
rt_kprintf("could not find device.\n");
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
res = rym_download_file(dev);
|
file_path = argv[1];
|
||||||
|
res = rym_download_file(dev,file_path);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
MSH_CMD_EXPORT(ry, YMODEM Receive e.g: ry [uart0] default by console.);
|
MSH_CMD_EXPORT(ry, YMODEM Receive e.g: ry file_path [uart0] default by console.);
|
||||||
|
|
||||||
static rt_err_t sy(uint8_t argc, char **argv)
|
static rt_err_t sy(uint8_t argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue