未验证 提交 de1d6dbc 编写于 作者: M Maihuanyi 提交者: GitHub

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: Nguo <guozhanxin@rt-thread.com>
上级 731bb8ba
...@@ -153,6 +153,10 @@ static enum rym_code _rym_send_data( ...@@ -153,6 +153,10 @@ static enum rym_code _rym_send_data(
ctx->stage = RYM_STAGE_FINISHING; ctx->stage = RYM_STAGE_FINISHING;
} }
if (read_size > 128)
{
return RYM_CODE_STX;
}
return RYM_CODE_SOH; return RYM_CODE_SOH;
} }
......
...@@ -149,20 +149,33 @@ static rt_err_t _rym_send_packet( ...@@ -149,20 +149,33 @@ static rt_err_t _rym_send_packet(
rt_uint16_t send_crc; rt_uint16_t send_crc;
rt_uint8_t index_inv = ~index; rt_uint8_t index_inv = ~index;
rt_size_t writelen = 0; 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[0] = code;
ctx->buf[1] = index; ctx->buf[1] = index;
ctx->buf[2] = index_inv; ctx->buf[2] = index_inv;
ctx->buf[131] = (rt_uint8_t)(send_crc >> 8); ctx->buf[packetlen - 2] = (rt_uint8_t)(send_crc >> 8);
ctx->buf[132] = (rt_uint8_t)send_crc & 0xff; ctx->buf[packetlen - 1] = (rt_uint8_t)send_crc & 0xff;
do do
{ {
writelen += rt_device_write(ctx->dev, 0, ctx->buf + writelen, 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; return RT_EOK;
} }
...@@ -402,21 +415,20 @@ static rt_err_t _rym_do_send_trans(struct rym_ctx *ctx) ...@@ -402,21 +415,20 @@ static rt_err_t _rym_do_send_trans(struct rym_ctx *ctx)
rt_uint32_t index = 1; rt_uint32_t index = 1;
rt_uint8_t getc_ack; rt_uint8_t getc_ack;
data_sz = _RYM_SOH_PKG_SZ; data_sz = _RYM_STX_PKG_SZ;
while (1) 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; 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); _rym_send_packet(ctx, code, index);
index++; index++;
rt_device_set_rx_indicate(ctx->dev, _rym_rx_ind); rt_device_set_rx_indicate(ctx->dev, _rym_rx_ind);
getc_ack = _rym_getchar(ctx); getc_ack = _rym_getchar(ctx);
if (getc_ack != RYM_CODE_ACK) if (getc_ack != RYM_CODE_ACK)
{ {
return -RYM_ERR_ACK; return -RYM_ERR_ACK;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册