-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(ymodem): 修正发送 ACK 重试并统一异常清理 与串口V2在控制台下使用SY失败问题 #11162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |||||||||||||||||||||||
| * Date Author Notes | ||||||||||||||||||||||||
| * 2013-04-14 Grissiom initial implementation | ||||||||||||||||||||||||
| * 2019-12-09 Steven Liu add YMODEM send protocol | ||||||||||||||||||||||||
| * 2026-02-01 wdfk-prog update ymodem callbacks and error handling | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #include <rthw.h> | ||||||||||||||||||||||||
|
|
@@ -180,6 +181,27 @@ static rt_err_t _rym_send_packet( | |||||||||||||||||||||||
| return RT_EOK; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * @brief Finalize a transfer, record error state, invoke end callback, and free buffer. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @param ctx Transfer context. | ||||||||||||||||||||||||
| * @param err Transfer result (RT_EOK on success, negative on failure). | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| static void _rym_cleanup(struct rym_ctx *ctx, rt_err_t err) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| ctx->last_err = err; | ||||||||||||||||||||||||
| if (ctx->on_end && ctx->begin_called && !ctx->end_called) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| ctx->on_end(ctx, ctx->buf + 3, 128); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| ctx->on_end(ctx, ctx->buf + 3, 128); | |
| if ((err == RT_EOK) && (ctx->buf != RT_NULL)) | |
| { | |
| /* Successful transfer, pass metadata buffer to callback */ | |
| ctx->on_end(ctx, ctx->buf + 3, 128); | |
| } | |
| else | |
| { | |
| /* Failed or no valid buffer, callback inspects ctx->last_err */ | |
| ctx->on_end(ctx, RT_NULL, 0); | |
| } |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for callback return value / 缺少对回调返回值的错误处理
English: The code retrieves the callback return value at line 489 but doesn't check if it's an error code (like RYM_ERR_FILE) before attempting to send the packet. If the callback returns an error code such as RYM_ERR_FILE (0x77), it will be passed to _rym_send_packet which only handles RYM_CODE_SOH and RYM_CODE_STX in its switch statement, causing it to return -RT_ERROR. This should be handled explicitly by checking if the code is an error value before line 493.
中文:代码在第 489 行获取回调返回值,但在尝试发送数据包之前没有检查它是否是错误代码(如 RYM_ERR_FILE)。如果回调返回错误代码如 RYM_ERR_FILE (0x77),它将被传递给 _rym_send_packet,而该函数的 switch 语句只处理 RYM_CODE_SOH 和 RYM_CODE_STX,导致返回 -RT_ERROR。应该在第 493 行之前明确检查代码是否为错误值。
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing braces around multi-statement if block / 多语句 if 块缺少大括号
English: The if statement on line 501 should use braces for the return statement to follow RT-Thread coding standards. While the code is functionally correct, RT-Thread style guide requires braces on separate lines for control structures.
中文:第 501 行的 if 语句应该为 return 语句使用大括号,以遵循 RT-Thread 编码标准。虽然代码功能正确,但 RT-Thread 风格指南要求控制结构的大括号独占一行。
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing braces around multi-statement if block / 多语句 if 块缺少大括号
English: The if statement on line 504 should use braces for the return statement to follow RT-Thread coding standards. While the code is functionally correct, RT-Thread style guide requires braces on separate lines for control structures.
中文:第 504 行的 if 语句应该为 return 语句使用大括号,以遵循 RT-Thread 编码标准。虽然代码功能正确,但 RT-Thread 风格指南要求控制结构的大括号独占一行。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential breaking change for console device behavior / 控制台设备行为的潜在破坏性更改
English: This change removes the special handling for console devices in _serial_poll_tx. Previously, console devices would get CRLF conversion (CR insertion before LF) regardless of the STREAM flag. Now, CRLF conversion only happens when RT_DEVICE_FLAG_STREAM is set. While this fix correctly allows YMODEM to disable line ending conversion by clearing the STREAM flag, it could affect other code paths where console devices are used without explicitly setting the STREAM flag. Verify that all console device usage paths properly set the STREAM flag when CRLF conversion is expected.
中文:此更改删除了 _serial_poll_tx 中对控制台设备的特殊处理。以前,无论 STREAM 标志如何,控制台设备都会进行 CRLF 转换(在 LF 之前插入 CR)。现在,只有当设置了 RT_DEVICE_FLAG_STREAM 时才会进行 CRLF 转换。虽然此修复正确地允许 YMODEM 通过清除 STREAM 标志来禁用行尾转换,但它可能影响其他未明确设置 STREAM 标志的控制台设备使用路径。请验证所有控制台设备使用路径在需要 CRLF 转换时都正确设置了 STREAM 标志。