Merge pull request #1777 from zhaojuntao/ymodem-0906

[components][ymodem] 修复 ymodem 不支持 secureCRT 下 1024字节传输的问题
This commit is contained in:
Bernard Xiong 2018-09-07 06:41:24 +08:00 committed by GitHub
commit 6fcc5c5504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 5 deletions

View File

@ -122,6 +122,7 @@ static rt_err_t _rym_do_handshake(
enum rym_code code;
rt_size_t i;
rt_uint16_t recv_crc, cal_crc;
rt_size_t data_sz;
ctx->stage = RYM_STAGE_ESTABLISHING;
/* send C every second, so the sender could know we are waiting for it. */
@ -131,26 +132,36 @@ static rt_err_t _rym_do_handshake(
code = _rym_read_code(ctx,
RYM_CHD_INTV_TICK);
if (code == RYM_CODE_SOH)
{
data_sz = _RYM_SOH_PKG_SZ;
break;
}
else if(code == RYM_CODE_STX)
{
data_sz = _RYM_STX_PKG_SZ;
break;
}
}
if (i == tm_sec)
{
return -RYM_ERR_TMO;
}
i = _rym_read_data(ctx, _RYM_SOH_PKG_SZ-1);
if (i != (_RYM_SOH_PKG_SZ-1))
i = _rym_read_data(ctx, data_sz-1);
if (i != (data_sz-1))
return -RYM_ERR_DSZ;
/* sanity check */
if (ctx->buf[1] != 0 || ctx->buf[2] != 0xFF)
return -RYM_ERR_SEQ;
recv_crc = (rt_uint16_t)(*(ctx->buf+_RYM_SOH_PKG_SZ-2) << 8) | *(ctx->buf+_RYM_SOH_PKG_SZ-1);
cal_crc = CRC16(ctx->buf+3, _RYM_SOH_PKG_SZ-5);
recv_crc = (rt_uint16_t)(*(ctx->buf+data_sz-2) << 8) | *(ctx->buf+data_sz-1);
cal_crc = CRC16(ctx->buf+3, data_sz-5);
if (recv_crc != cal_crc)
return -RYM_ERR_CRC;
/* congratulations, check passed. */
if (ctx->on_begin && ctx->on_begin(ctx, ctx->buf+3, 128) != RYM_CODE_ACK)
if (ctx->on_begin && ctx->on_begin(ctx, ctx->buf+3, data_sz-5) != RYM_CODE_ACK)
return -RYM_ERR_CAN;
return RT_EOK;