From de1d6dbc0e17899516572b90954a99d645d91b22 Mon Sep 17 00:00:00 2001 From: Maihuanyi <70518174+Maihuanyi@users.noreply.github.com> Date: Mon, 24 Oct 2022 10:33:31 +0800 Subject: [PATCH] ymodem of send error (#6535) * modified ymodem.c to solve ymodem send file error * modified ry_sy.c to solve send file error of file data * Update ry_sy.c Co-authored-by: guo --- components/utilities/ymodem/ry_sy.c | 4 ++++ components/utilities/ymodem/ymodem.c | 34 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/components/utilities/ymodem/ry_sy.c b/components/utilities/ymodem/ry_sy.c index 0d22c48faa..a66a0579e7 100644 --- a/components/utilities/ymodem/ry_sy.c +++ b/components/utilities/ymodem/ry_sy.c @@ -153,6 +153,10 @@ static enum rym_code _rym_send_data( ctx->stage = RYM_STAGE_FINISHING; } + if (read_size > 128) + { + return RYM_CODE_STX; + } return RYM_CODE_SOH; } diff --git a/components/utilities/ymodem/ymodem.c b/components/utilities/ymodem/ymodem.c index 51b0578d44..5a2d443d01 100644 --- a/components/utilities/ymodem/ymodem.c +++ b/components/utilities/ymodem/ymodem.c @@ -149,20 +149,33 @@ static rt_err_t _rym_send_packet( rt_uint16_t send_crc; rt_uint8_t index_inv = ~index; rt_size_t writelen = 0; + rt_size_t packetlen = 0; - send_crc = CRC16(ctx->buf + 3, _RYM_SOH_PKG_SZ - 5); + switch(code) + { + case RYM_CODE_SOH: + packetlen = _RYM_SOH_PKG_SZ; + break; + case RYM_CODE_STX: + packetlen = _RYM_STX_PKG_SZ; + break; + default: + return -RT_ERROR; + } + + send_crc = CRC16(ctx->buf + 3, packetlen - 5); ctx->buf[0] = code; ctx->buf[1] = index; ctx->buf[2] = index_inv; - ctx->buf[131] = (rt_uint8_t)(send_crc >> 8); - ctx->buf[132] = (rt_uint8_t)send_crc & 0xff; + ctx->buf[packetlen - 2] = (rt_uint8_t)(send_crc >> 8); + ctx->buf[packetlen - 1] = (rt_uint8_t)send_crc & 0xff; do { writelen += rt_device_write(ctx->dev, 0, ctx->buf + writelen, - _RYM_SOH_PKG_SZ - writelen); + packetlen - writelen); } - while (writelen < _RYM_SOH_PKG_SZ); + while (writelen < packetlen); return RT_EOK; } @@ -402,21 +415,20 @@ static rt_err_t _rym_do_send_trans(struct rym_ctx *ctx) rt_uint32_t index = 1; rt_uint8_t getc_ack; - data_sz = _RYM_SOH_PKG_SZ; - + data_sz = _RYM_STX_PKG_SZ; while (1) { - if (ctx->on_data && ctx->on_data(ctx, ctx->buf + 3, data_sz - 5) != RYM_CODE_SOH) + if (!ctx->on_data) + { return -RYM_ERR_CODE; - - code = RYM_CODE_SOH; + } + code = ctx->on_data(ctx, ctx->buf + 3, data_sz - 5); _rym_send_packet(ctx, code, index); index++; rt_device_set_rx_indicate(ctx->dev, _rym_rx_ind); getc_ack = _rym_getchar(ctx); - if (getc_ack != RYM_CODE_ACK) { return -RYM_ERR_ACK; -- GitLab