-
Notifications
You must be signed in to change notification settings - Fork 128
Tcp socket improvements #222
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
Changes from 3 commits
300410f
b623b00
524e564
bb9d17a
7639529
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 |
|---|---|---|
|
|
@@ -542,9 +542,8 @@ bool UrDriver::sendScript(const std::string& program) | |
| { | ||
| if (secondary_stream_ == nullptr) | ||
| { | ||
| throw std::runtime_error("Sending script to robot requested while there is no primary interface established. " | ||
| "This " | ||
| "should not happen."); | ||
| throw std::runtime_error("Sending script to robot requested while there is no secondary interface established. " | ||
| "This should not happen."); | ||
| } | ||
|
|
||
| // urscripts (snippets) must end with a newline, or otherwise the controller's runtime will | ||
|
|
@@ -562,6 +561,16 @@ bool UrDriver::sendScript(const std::string& program) | |
| return true; | ||
| } | ||
| URCL_LOG_ERROR("Could not send program to robot"); | ||
|
|
||
| URCL_LOG_INFO("Reconnecting secondary stream to retry sending program..."); | ||
| secondary_stream_->close(); | ||
| if (secondary_stream_->connect() && secondary_stream_->write(data, len, written)) | ||
| { | ||
| URCL_LOG_DEBUG("Sent program to robot:\n%s", program_with_newline.c_str()); | ||
| return true; | ||
| } | ||
| URCL_LOG_ERROR("Retry sending program failed!"); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also use the size_t num_tries = 0;
while( num_tries < 2)
{
if (secondary_stream_->write(data, len, written))
{
URCL_LOG_DEBUG("Sent program to robot:\n%s", program_with_newline.c_str());
return true;
}
URCL_LOG_ERROR("Could not send program to robot");
if (num_tries == 0)
{
URCL_LOG_INFO("Reconnecting secondary stream to retry sending program...");
reconnectSecondaryStream();
}
}
URCL_LOG_ERROR("Retry sending program failed!");
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair points about code duplication and reusing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had the same feeling and also had the thought that using a lambda function would make things prettier. Thank you for your solution, that looks nice! |
||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -578,6 +587,19 @@ bool UrDriver::sendRobotProgram() | |
| } | ||
| } | ||
|
|
||
| bool UrDriver::reconnectSecondaryStream() | ||
| { | ||
| URCL_LOG_DEBUG("Closing secondary stream..."); | ||
| secondary_stream_->close(); | ||
| if (secondary_stream_->connect()) | ||
| { | ||
| URCL_LOG_DEBUG("Secondary stream connected"); | ||
| return true; | ||
| } | ||
| URCL_LOG_ERROR("Failed to reconnect secodary stream!"); | ||
| return false; | ||
| } | ||
|
|
||
| std::vector<std::string> UrDriver::getRTDEOutputRecipe() | ||
| { | ||
| return rtde_client_->getOutputRecipe(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.