Skip to content

[component][net][at] at_client增加deInit接口 #10598

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Ryan-CW-Code
Copy link
Contributor

@Ryan-CW-Code Ryan-CW-Code commented Aug 11, 2025

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

你的解决方案是什么 (what is your solution)

请提供验证的bsp和config (provide the config and bsp)

V2版本的串口,已在at_socket没有使用deinit测试3天,ppp拨号中每隔3分钟deinit一次测试4天。
V1版本的串口,在at_socket测试一个小时。
已知待解决:at_device软件包中直接访问at_client的lock变量需要修改一下,合并后就准备给at_device提PR

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/workflows/bsp_buildings.yml 详细请参考链接BSP自查

Copy link

github-actions bot commented Aug 11, 2025

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: Maihuanyi

Changed Files (Click to expand)
  • components/net/at/include/at.h
  • components/net/at/src/at_client.c

🏷️ Tag: components_net_at

Reviewers: Ryan-CW-Code lizhen9880

Changed Files (Click to expand)
  • components/net/at/include/at.h
  • components/net/at/src/at_client.c

📊 Current Review Status (Last Updated: 2025-08-11 20:20 CST)

  • Maihuanyi Pending Review
  • Ryan-CW-Code Pending Review
  • lizhen9880 Pending Review

📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@Ryan-CW-Code
Copy link
Contributor Author

Ryan-CW-Code commented Aug 11, 2025

上面实现中,at_client_rx_ind使用了rt_deviceuser_data,大佬们可以给点意见看合适不合适。
不合适的话就改回轮询方式

更新: 已修改为轮询方式

@Ryan-CW-Code Ryan-CW-Code reopened this Aug 11, 2025
@Ryan-CW-Code
Copy link
Contributor Author

CI错误都是at_device软件包的报错,合并此PR后会对at_device提PR

@Rbb666 Rbb666 requested a review from Copilot August 11, 2025 12:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a deInit interface to the at_client component, enabling proper cleanup and deinitialization of AT clients. The implementation refactors the client management from a static array to a dynamic linked list structure and modernizes synchronization mechanisms.

  • Replaces static client array with dynamic linked list for better memory management
  • Migrates from semaphore-based to event-based synchronization for improved efficiency
  • Adds at_client_deInit() function to properly clean up AT client resources

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
components/net/at/src/at_client.c Implements deInit functionality, converts to linked list management, and updates synchronization mechanisms
components/net/at/include/at.h Updates client struct to use events/mutexes and declares deInit function


if (client == RT_NULL)
{
LOG_E("input AT client object is NULL, please create or get AT Client object!");
return -RT_ERROR;
}

resp = at_create_resp(64, 0, rt_tick_from_millisecond(300));
resp = at_create_resp(64, 0, rt_tick_from_millisecond(1000));
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout value was changed from 300ms to 1000ms without explanation. This magic number should be documented or defined as a constant to explain the reasoning for this specific timeout value.

Suggested change
resp = at_create_resp(64, 0, rt_tick_from_millisecond(1000));
resp = at_create_resp(64, 0, rt_tick_from_millisecond(AT_CLIENT_CONN_RESP_TIMEOUT_MS));

Copilot uses AI. Check for mistakes.

(void (*)(void *parameter))client_parser,
client,
1024 + 512,
9,
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thread priority was changed from a calculated value to a hardcoded '9'. This magic number should be defined as a constant or the calculation should be restored with proper documentation explaining why this specific priority is chosen.

Suggested change
9,
AT_CLIENT_THREAD_PRIORITY,

Copilot uses AI. Check for mistakes.

{
is_full = RT_TRUE;
rt_event_send(&client->event, at_client_deInit_over_event);
rt_thread_delete(rt_thread_self());
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling rt_thread_delete() on the current thread (rt_thread_self()) is generally unsafe and can lead to undefined behavior. Consider using rt_thread_exit() or restructuring the code to allow the thread to terminate naturally.

Suggested change
rt_thread_delete(rt_thread_self());
rt_thread_exit();

Copilot uses AI. Check for mistakes.


return &at_client_table[0];
rt_base_t level = rt_hw_interrupt_disable();
client = rt_slist_first_entry(&g_at_client_list, struct at_client, list);
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will crash if the list is empty because rt_slist_first_entry() doesn't check for an empty list. Add a check using rt_slist_isempty() before calling rt_slist_first_entry().

Suggested change
client = rt_slist_first_entry(&g_at_client_list, struct at_client, list);
if (!rt_slist_isempty(&g_at_client_list))
{
client = rt_slist_first_entry(&g_at_client_list, struct at_client, list);
}

Copilot uses AI. Check for mistakes.

Comment on lines 711 to 716
break;
}
}
rt_hw_interrupt_enable(level);

return RT_NULL;
return client;
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop may exit with client pointing to the last entry even if no match was found. The function should set client to RT_NULL when no match is found, or return RT_NULL explicitly in the else case.

Copilot uses AI. Check for mistakes.

return -RT_EFULL;
}

// Since the buffer state is uncertain, we proactively clear it; the overhead is negligible.
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment uses '//' style which is inconsistent with the existing C-style '/* */' comments used throughout the file. Consider using consistent comment style.

Suggested change
// Since the buffer state is uncertain, we proactively clear it; the overhead is negligible.
/* Since the buffer state is uncertain, we proactively clear it; the overhead is negligible. */

Copilot uses AI. Check for mistakes.

}
else
{
/* log_d("unrecognized line: %.*s", client->recv_line_len, client->recv_line_buf);*/
// rt_kprintf("unrecognized line: %.*s", client->recv_line_len, client->recv_line_buf);
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented-out debug code should be removed or replaced with a proper logging mechanism if debugging is needed.

Suggested change
// rt_kprintf("unrecognized line: %.*s", client->recv_line_len, client->recv_line_buf);
LOG_D("unrecognized line: %.*s", client->recv_line_len, client->recv_line_buf);

Copilot uses AI. Check for mistakes.

@Ryan-CW-Code
Copy link
Contributor Author

@Rbb666
AI审查真的很有用,建议把coderabbitai也加上,开源项目免费

@Rbb666
Copy link
Member

Rbb666 commented Aug 11, 2025

@Rbb666 AI审查真的很有用,建议把coderabbitai也加上,开源项目免费

我研究下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants