Skip to content
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

不知道是不是有问题的函数 (AEGHB-877) #131

Open
3 tasks done
WzxKB opened this issue Nov 15, 2024 · 2 comments
Open
3 tasks done

不知道是不是有问题的函数 (AEGHB-877) #131

WzxKB opened this issue Nov 15, 2024 · 2 comments

Comments

@WzxKB
Copy link

WzxKB commented Nov 15, 2024

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate.
  • Provided a clear description of your suggestion.
  • Included any relevant context or examples.

Issue or Suggestion Description

这里的移除函数的处理是否有问题呢?在control组件中,有一个esp_err_t espnow_ctrl_responder_remove_bindlist(const espnow_ctrl_bind_info_t *info)函数,是这样的
esp_err_t espnow_ctrl_responder_remove_bindlist(const espnow_ctrl_bind_info_t *info)
{
espnow_load_bindlist();
for (int i = 0; i < g_bindlist.size; ++i)
{
if (!memcmp(g_bindlist.data + i, info, sizeof(espnow_ctrl_bind_info_t)))
{
g_bindlist.size--;

    if (g_bindlist.size > 0)
    {
        g_bindlist.data[g_bindlist.size].initiator_attribute = info->initiator_attribute;
        memcpy(g_bindlist.data[g_bindlist.size].mac, info->mac, 6);
    }

    espnow_storage_set("bindlist", &g_bindlist, sizeof(g_bindlist));
    break;
}

}

return ESP_OK;
}
其中 if (g_bindlist.size > 0)
{
g_bindlist.data[g_bindlist.size].initiator_attribute = info->initiator_attribute;
memcpy(g_bindlist.data[g_bindlist.size].mac, info->mac, 6);
}
是不是不太对,这里是将最后一位的值改变为移除的值,感觉不太对,应该是把移除位置的值改变为最后一位的值,是这样吗? memcpy(g_bindlist.data + i, g_bindlist.data + g_bindlist.size, sizeof(espnow_ctrl_bind_info_t));这里一直想不太懂,希望能解答一下

@github-actions github-actions bot changed the title 不知道是不是有问题的函数 不知道是不是有问题的函数 (AEGHB-877) Nov 15, 2024
@WzxKB
Copy link
Author

WzxKB commented Nov 15, 2024

在底下看到取消配对的代码是这样写的,remove之后的位都向前移动,这样会好一些吗
g_bindlist.size--;

            for (int j = i; j < g_bindlist.size; j++)
            {
                g_bindlist.data[j].initiator_attribute = g_bindlist.data[j + 1].initiator_attribute;
                memcpy(g_bindlist.data[j].mac, g_bindlist.data[j + 1].mac, 6);
            }
            g_bindlist.data[g_bindlist.size].initiator_attribute = 0;
            memset(g_bindlist.data[g_bindlist.size].mac, 0, 6);

@bubblesnake
Copy link
Contributor

是的,应该和取消配对的代码一样处理。修复好了会合并进去。谢谢!

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

No branches or pull requests

2 participants