[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]; 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( static enum rym_code _rym_recv_begin(
struct rym_ctx *ctx, struct rym_ctx *ctx,
rt_uint8_t *buf, rt_uint8_t *buf,
@ -125,7 +135,18 @@ static enum rym_code _rym_send_begin(
rt_kprintf("error open file.\n"); rt_kprintf("error open file.\n");
return RYM_ERR_FILE; 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; 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 * All rights reserved
* *
* SPDX-License-Identifier: Apache-2.0 * 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_ACK);
_rym_putchar(ctx, RYM_CODE_C); _rym_putchar(ctx, RYM_CODE_C);
ctx->stage = RYM_STAGE_ESTABLISHED; ctx->stage = RYM_STAGE_ESTABLISHED;
rt_size_t errors; rt_size_t errors = 0;
while (1) while (1)
{ {
@ -374,16 +374,25 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx)
RYM_WAIT_PKG_TICK); RYM_WAIT_PKG_TICK);
switch (code) switch (code)
{ {
case RYM_CODE_SOH: case RYM_CODE_SOH:
data_sz = 128; data_sz = 128;
break; break;
case RYM_CODE_STX: case RYM_CODE_STX:
data_sz = 1024; data_sz = 1024;
break; break;
case RYM_CODE_EOT: case RYM_CODE_EOT:
return RT_EOK; return RT_EOK;
default: 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); err = _rym_trans_data(ctx, data_sz, &code);
@ -404,21 +413,22 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx)
{ {
errors = 0; errors = 0;
} }
switch (code) switch (code)
{ {
case RYM_CODE_CAN: case RYM_CODE_CAN:
/* the spec require multiple CAN */ /* the spec require multiple CAN */
for (i = 0; i < RYM_END_SESSION_SEND_CAN_NUM; i++) for (i = 0; i < RYM_END_SESSION_SEND_CAN_NUM; i++)
{ {
_rym_putchar(ctx, RYM_CODE_CAN); _rym_putchar(ctx, RYM_CODE_CAN);
} }
return -RYM_ERR_CAN; return -RYM_ERR_CAN;
case RYM_CODE_ACK: case RYM_CODE_ACK:
_rym_putchar(ctx, RYM_CODE_ACK); _rym_putchar(ctx, RYM_CODE_ACK);
break; break;
default: default:
// wrong code // wrong code
break; break;
}; };
} }
} }
@ -586,11 +596,6 @@ static rt_err_t _rym_do_recv(
while (1) while (1)
{ {
err = _rym_do_trans(ctx); err = _rym_do_trans(ctx);
if (err != RT_EOK)
{
rt_free(ctx->buf);
return err;
}
err = _rym_do_fin(ctx); err = _rym_do_fin(ctx);
if (err != RT_EOK) if (err != RT_EOK)