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 <guozhanxin@rt-thread.com>
This commit is contained in:
parent
731bb8ba87
commit
de1d6dbc0e
|
@ -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(
|
||||||
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)
|
||||||
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;
|
||||||
|
|
Loading…
Reference in New Issue