增加restart功能#1
Open
ZiDXie wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
该 PR 为 EtherCAT 总线通信增加了 restart 能力,用于断电/掉线后的重连恢复,从而提升总线启动阶段的鲁棒性。
Changes:
- 在
EthercatBusBase中新增restart()公共接口,通过内部关闭 socket 并重新startup()来实现重连。 - 在
EthercatBusManagerBase::startupCommunication()中,当单条总线startup()失败时尝试调用restart()进行恢复。 - 对
EthercatBusManagerBase.cpp做了部分代码换行/格式调整。
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| soem_interface_rsl/src/soem_interface_rsl/EthercatBusManagerBase.cpp | 启动通信失败时增加一次重连尝试,并做了部分格式调整 |
| soem_interface_rsl/src/soem_interface_rsl/EthercatBusBase.cpp | 实现 restart():内部 shutdown/close 后重新 startup;增加对外包装函数 |
| soem_interface_rsl/include/soem_interface_rsl/EthercatBusBase.hpp | 声明并文档化新的 restart() API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+9
to
12
| ** The soem_interface_rsl is free software: you can redistribute it and/or | ||
| * modify | ||
| ** it under the terms of the GNU General Public License as published by | ||
| ** the Free Software Foundation, either version 3 of the License, or |
| ** You should have received a copy of the GNU General Public License | ||
| ** along with the soem_interface_rsl. If not, see <https://www.gnu.org/licenses/>. | ||
| ** along with the soem_interface_rsl. If not, see | ||
| * <https://www.gnu.org/licenses/>. |
Comment on lines
118
to
+126
| if (!bus.second->startup(true)) { | ||
| MELO_ERROR_STREAM("Failed to startup bus '" << bus.first << "'."); | ||
| return false; | ||
| MELO_WARN_STREAM("Attempting to reconnect bus '" | ||
| << bus.first << "' after startup failure."); | ||
| if (!bus.second->restart(true, 10)) { | ||
| MELO_ERROR_STREAM("Reconnect failed for bus '" << bus.first << "'."); | ||
| return false; | ||
| } | ||
| MELO_INFO_STREAM("Reconnect successful for bus '" << bus.first << "'."); |
Comment on lines
+388
to
+394
| if (ecatContext_.port != nullptr) { | ||
| MELO_INFO_STREAM("[soem_interface_rsl::" << name_ << "] Closing socket for restart ..."); | ||
| ecx_close(&ecatContext_); | ||
| soem_interface_rsl::threadSleep(0.2); | ||
| } | ||
| initlialized_ = false; | ||
| } |
Comment on lines
+1002
to
+1005
| bool EthercatBusBase::restart(bool sizeCheck, int maxDiscoverRetries) { | ||
| std::atomic<bool> tmpAtomicForStart{false}; | ||
| return pImpl_->restart(tmpAtomicForStart, sizeCheck, maxDiscoverRetries); | ||
| } |
Comment on lines
+142
to
+149
| /*! | ||
| * Restart the bus communication: shutdown internally and startup again. | ||
| * Unlike shutdown(), this preserves the bus object for reuse. | ||
| * @param sizeCheck perform a check of the Rx and Tx Pdo sizes | ||
| * @param maxDiscoverRetries number of retries for slave discovery | ||
| * @return True if successful. | ||
| */ | ||
| bool restart(bool sizeCheck = true, int maxDiscoverRetries = 10); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
增加restart功能用于断电重连