diff options
| author | wdfk-prog <[email protected]> | 2022-11-29 10:00:21 +0800 |
|---|---|---|
| committer | Man, Jianting (Meco) <[email protected]> | 2022-12-05 23:07:27 -0500 |
| commit | f54f2c2c917e6237567c4cc7a8d94dbba327747d (patch) | |
| tree | dac41a29ffdfa8047c33ecb4b84c8ead8192a7f8 | |
| parent | fa1f6c22e5d9309593b1d55c588bf2e3537da9ae (diff) | |
[ymodem]添加传输过程中的异常处理流程
| -rw-r--r-- | components/utilities/ymodem/ymodem.c | 20 | ||||
| -rw-r--r-- | components/utilities/ymodem/ymodem.h | 5 |
2 files changed, 23 insertions, 2 deletions
diff --git a/components/utilities/ymodem/ymodem.c b/components/utilities/ymodem/ymodem.c index 5a2d443d01..52f5e52692 100644 --- a/components/utilities/ymodem/ymodem.c +++ b/components/utilities/ymodem/ymodem.c @@ -1,5 +1,5 @@ /* - * COPYRIGHT (C) 2011-2021, Real-Thread Information Technology Ltd + * COPYRIGHT (C) 2011-2022, Real-Thread Information Technology Ltd * All rights reserved * * SPDX-License-Identifier: Apache-2.0 @@ -362,6 +362,7 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx) _rym_putchar(ctx, RYM_CODE_ACK); _rym_putchar(ctx, RYM_CODE_C); ctx->stage = RYM_STAGE_ESTABLISHED; + rt_size_t errors; while (1) { @@ -387,7 +388,22 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx) err = _rym_trans_data(ctx, data_sz, &code); if (err != RT_EOK) - return err; + { + errors++; + if(errors > RYM_MAX_ERRORS) + { + return err;/* Abort communication */ + } + else + { + _rym_putchar(ctx, RYM_CODE_NAK);/* Ask for a packet */ + continue; + } + } + else + { + errors = 0; + } switch (code) { case RYM_CODE_CAN: diff --git a/components/utilities/ymodem/ymodem.h b/components/utilities/ymodem/ymodem.h index 398e168dfa..25f05e9148 100644 --- a/components/utilities/ymodem/ymodem.h +++ b/components/utilities/ymodem/ymodem.h @@ -58,6 +58,11 @@ enum rym_code #define RYM_END_SESSION_SEND_CAN_NUM 0x07 #endif +/* how many retries were made when the error occurred */ +#ifndef RYM_MAX_ERRORS +#define RYM_MAX_ERRORS ((rt_size_t)5) +#endif + enum rym_stage { RYM_STAGE_NONE = 0, |
