[Ymodem]sy命令支持绝对路径传输

* 接收错误流程优化
This commit is contained in:
wdfk-prog 2023-01-10 20:01:46 +08:00 committed by Man, Jianting (Meco)
parent 3a5d1c17a1
commit da0c8a6d0a
2 changed files with 57 additions and 31 deletions

View File

@ -30,6 +30,16 @@ struct custom_ctx
char fpath[DFS_PATH_MAX];
};
static const char *_get_path_lastname(const char *path)
{
char *ptr;
if ((ptr = (char *)strrchr(path, '/')) == NULL)
return path;
/* skip the '/' then return */
return ++ptr;
}
static enum rym_code _rym_recv_begin(
struct rym_ctx *ctx,
rt_uint8_t *buf,
@ -125,7 +135,18 @@ static enum rym_code _rym_send_begin(
rt_kprintf("error open file.\n");
return RYM_ERR_FILE;
}
rt_sprintf((char *)buf, "%s%c%d", (char *) & (cctx->fpath[1]), insert_0, file_buf.st_size);
const char *fdst = _get_path_lastname(cctx->fpath);
if(fdst != cctx->fpath)
{
fdst = dfs_normalize_path(RT_NULL, fdst);
if (fdst == RT_NULL)
{
return RYM_ERR_FILE;
}
}
rt_sprintf((char *)buf, "%s%c%d", fdst, insert_0, file_buf.st_size);
return RYM_CODE_SOH;
}

View File

@ -1,5 +1,5 @@
/*
* COPYRIGHT (C) 2011-2022, Real-Thread Information Technology Ltd
* COPYRIGHT (C) 2011-2023, Real-Thread Information Technology Ltd
* All rights reserved
*
* SPDX-License-Identifier: Apache-2.0
@ -362,7 +362,7 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx)
_rym_putchar(ctx, RYM_CODE_ACK);
_rym_putchar(ctx, RYM_CODE_C);
ctx->stage = RYM_STAGE_ESTABLISHED;
rt_size_t errors;
rt_size_t errors = 0;
while (1)
{
@ -383,7 +383,16 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx)
case RYM_CODE_EOT:
return RT_EOK;
default:
return -RYM_ERR_CODE;
errors++;
if(errors > RYM_MAX_ERRORS)
{
return -RYM_ERR_CODE;/* Abort communication */
}
else
{
_rym_putchar(ctx, RYM_CODE_NAK);/* Ask for a packet */
continue;
}
};
err = _rym_trans_data(ctx, data_sz, &code);
@ -404,6 +413,7 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx)
{
errors = 0;
}
switch (code)
{
case RYM_CODE_CAN:
@ -586,11 +596,6 @@ static rt_err_t _rym_do_recv(
while (1)
{
err = _rym_do_trans(ctx);
if (err != RT_EOK)
{
rt_free(ctx->buf);
return err;
}
err = _rym_do_fin(ctx);
if (err != RT_EOK)