Skip to content

增加restart功能#1

Open
ZiDXie wants to merge 3 commits into
gdut-dynamic-x:masterfrom
ZiDXie:feature/reconnect
Open

增加restart功能#1
ZiDXie wants to merge 3 commits into
gdut-dynamic-x:masterfrom
ZiDXie:feature/reconnect

Conversation

@ZiDXie
Copy link
Copy Markdown

@ZiDXie ZiDXie commented May 5, 2026

增加restart功能用于断电重连

Copilot AI review requested due to automatic review settings May 5, 2026 14:03
Copy link
Copy Markdown

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

该 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);
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

Successfully merging this pull request may close these issues.

2 participants