Skip to content

Commit a131a32

Browse files
authored
Add check to make sure that program name and save path is specified w… (#447)
…hen downloading program. Also renamed the input parameter for clarity
1 parent 4297120 commit a131a32

7 files changed

Lines changed: 29 additions & 11 deletions

include/ur_client_library/ur/dashboard_client.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,12 +758,13 @@ class DashboardClient
758758
/*!
759759
* \brief Download a program from the robot
760760
*
761-
* \param filename The name of the program file on the robot. This is the name as returned by
762-
* commandGetProgramListWithResponse. \param save_path The path where the program file should be saved on the machine
763-
* where the dashboard client is running.
761+
* \param program_name The name of the program file on the robot. This is the name as returned by
762+
* commandGetProgramListWithResponse.
763+
* \param save_path The path where the program file should be saved on the machine where the
764+
* dashboard client is running.
764765
*
765766
*/
766-
DashboardResponse commandDownloadProgramWithResponse(const std::string& filename, const std::string& save_path);
767+
DashboardResponse commandDownloadProgramWithResponse(const std::string& program_name, const std::string& save_path);
767768

768769
/*!
769770
* \brief Makes sure that the dashboard_server's version is above the required version

include/ur_client_library/ur/dashboard_client_implementation_g5.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class DashboardClientImplG5 : public DashboardClientImpl, comm::TCPSocket
163163
DashboardResponse commandGetProgramList() override;
164164
DashboardResponse commandUploadProgram(const std::string& file_path) override;
165165
DashboardResponse commandUpdateProgram(const std::string& file_path) override;
166-
DashboardResponse commandDownloadProgram(const std::string& filename, const std::string& save_path) override;
166+
DashboardResponse commandDownloadProgram(const std::string& program_name, const std::string& save_path) override;
167167

168168
void setReceiveTimeout(const timeval& timeout) override
169169
{

include/ur_client_library/ur/dashboard_client_implementation_x.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class DashboardClientImplX : public DashboardClientImpl
160160
DashboardResponse commandGetProgramList() override;
161161
DashboardResponse commandUploadProgram(const std::string& file_path) override;
162162
DashboardResponse commandUpdateProgram(const std::string& file_path) override;
163-
DashboardResponse commandDownloadProgram(const std::string& filename, const std::string& save_path) override;
163+
DashboardResponse commandDownloadProgram(const std::string& program_name, const std::string& save_path) override;
164164

165165
void setReceiveTimeout([[maybe_unused]] const timeval& timeout) override
166166
{

src/ur/dashboard_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,10 @@ DashboardResponse DashboardClient::commandUpdateProgramWithResponse(const std::s
562562
return impl_->commandUpdateProgram(file_path);
563563
}
564564

565-
DashboardResponse DashboardClient::commandDownloadProgramWithResponse(const std::string& filename,
565+
DashboardResponse DashboardClient::commandDownloadProgramWithResponse(const std::string& program_name,
566566
const std::string& save_path)
567567
{
568-
return impl_->commandDownloadProgram(filename, save_path);
568+
return impl_->commandDownloadProgram(program_name, save_path);
569569
}
570570

571571
void DashboardClient::assertVersion(const std::string& e_series_min_ver, const std::string& cb3_min_ver,

src/ur/dashboard_client_implementation_g5.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ DashboardResponse DashboardClientImplG5::commandUpdateProgram([[maybe_unused]] c
12041204
". It is supported from PolyScope 10.12.0 onwards.");
12051205
}
12061206

1207-
DashboardResponse DashboardClientImplG5::commandDownloadProgram([[maybe_unused]] const std::string& program_file_name,
1207+
DashboardResponse DashboardClientImplG5::commandDownloadProgram([[maybe_unused]] const std::string& program_name,
12081208
[[maybe_unused]] const std::string& destination_path)
12091209
{
12101210
throw NotImplementedException("commandDownloadProgram is not available for PolyScope " +

src/ur/dashboard_client_implementation_x.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,26 @@ DashboardResponse DashboardClientImplX::commandUpdateProgram(const std::string&
486486
file_path, [this](const std::string& e, const httplib::UploadFormDataItems& f) { return put(e, f); });
487487
}
488488

489-
DashboardResponse DashboardClientImplX::commandDownloadProgram(const std::string& filename,
489+
DashboardResponse DashboardClientImplX::commandDownloadProgram(const std::string& program_name,
490490
const std::string& save_path)
491491
{
492492
if (robot_api_version_ < VersionInformation::fromString("3.1.4"))
493493
{
494494
throw NotImplementedException("commandDownloadProgram is not implemented for Robot API version < 3.1.4. Please "
495495
"upgrade the robot to PolyScope 10.12.0 or higher to use this command.");
496496
}
497-
auto response = get("/programs/v1/" + filename, false); // The json response is pretty long. Don't print it.
497+
if (program_name.size() == 0 || save_path.size() == 0)
498+
{
499+
std::string error = "Both program_name and save_path parameters should be populated.";
500+
error += program_name.size() == 0 ? " Program name is empty." : "";
501+
error += save_path.size() == 0 ? " Save path is empty." : "";
502+
URCL_LOG_ERROR(error.c_str());
503+
DashboardResponse response;
504+
response.ok = false;
505+
response.message = error;
506+
return response;
507+
}
508+
auto response = get("/programs/v1/" + program_name, false); // The json response is pretty long. Don't print it.
498509
if (response.ok)
499510
{
500511
std::ofstream save_file(save_path, std::ios_base::out);

tests/test_dashboard_client_x.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ TEST_F(DashboardClientTestX, download_program)
442442

443443
response = dashboard_client_->commandDownloadProgram("test upload", "/non_existent_dir/downloaded.urpx");
444444
ASSERT_FALSE(response.ok);
445+
446+
response = dashboard_client_->commandDownloadProgram("", "/tmp/downloaded.urpx");
447+
ASSERT_FALSE(response.ok);
448+
449+
response = dashboard_client_->commandDownloadProgram("test upload", "");
450+
ASSERT_FALSE(response.ok);
445451
}
446452
}
447453

0 commit comments

Comments
 (0)