Skip to content

Commit 3dc0fd8

Browse files
viambotgithub-actions[bot]
authored andcommitted
[WORKFLOW] AI update based on proto changes from commit b48d998
1 parent 189391d commit 3dc0fd8

File tree

3 files changed

+98
-16
lines changed

3 files changed

+98
-16
lines changed

src/viam/sdk/robot/client.cpp

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace sdk {
3737
using google::protobuf::RepeatedPtrField;
3838
using viam::common::v1::Transform;
3939
using viam::robot::v1::FrameSystemConfig;
40+
using viam::robot::v1::JobStatus;
41+
using viam::robot::v1::GetMachineStatusResponse;
4042
using viam::robot::v1::Operation;
4143
using viam::robot::v1::RobotService;
4244

@@ -59,6 +61,33 @@ RobotClient::frame_system_config from_proto_impl<FrameSystemConfig>::operator()(
5961
return fsconfig;
6062
}
6163

64+
JobStatus from_proto_impl<viam::robot::v1::JobStatus>::operator()(
65+
const viam::robot::v1::JobStatus* proto) const {
66+
JobStatus job_status;
67+
job_status.job_name = proto->job_name();
68+
job_status.recent_successful_runs = sdk::impl::from_repeated_field(proto->recent_successful_runs());
69+
job_status.recent_failed_runs = sdk::impl::from_repeated_field(proto->recent_failed_runs());
70+
return job_status;
71+
}
72+
73+
GetMachineStatusResponse from_proto_impl<viam::robot::v1::GetMachineStatusResponse>::operator()(
74+
const viam::robot::v1::GetMachineStatusResponse* proto) const {
75+
MachineStatus machine_status;
76+
switch (proto->state()) {
77+
case robot::v1::GetMachineStatusResponse_State_STATE_INITIALIZING:
78+
machine_status.state = RobotClient::status::k_initializing;
79+
break;
80+
case robot::v1::GetMachineStatusResponse_State_STATE_RUNNING:
81+
machine_status.state = RobotClient::status::k_running;
82+
break;
83+
case robot::v1::GetMachineStatusResponse_State_STATE_UNSPECIFIED:
84+
default:
85+
machine_status.state = RobotClient::status::k_unspecified;
86+
}
87+
machine_status.job_statuses = sdk::impl::from_repeated_field(proto->job_statuses());
88+
return machine_status;
89+
}
90+
6291
RobotClient::operation from_proto_impl<Operation>::operator()(const Operation* proto) const {
6392
RobotClient::operation op;
6493
op.id = proto->id();
@@ -83,6 +112,16 @@ bool operator==(const RobotClient::frame_system_config& lhs,
83112
to_proto(rhs.kinematics).SerializeAsString();
84113
}
85114

115+
bool operator==(const JobStatus& lhs, const JobStatus& rhs) {
116+
return lhs.job_name == rhs.job_name &&
117+
lhs.recent_successful_runs == rhs.recent_successful_runs &&
118+
lhs.recent_failed_runs == rhs.recent_failed_runs;
119+
}
120+
121+
bool operator==(const MachineStatus& lhs, const MachineStatus& rhs) {
122+
return lhs.state == rhs.state && lhs.job_statuses == rhs.job_statuses;
123+
}
124+
86125
bool operator==(const RobotClient::operation& lhs, const RobotClient::operation& rhs) {
87126
return lhs.id == rhs.id && lhs.method == rhs.method && lhs.session_id == rhs.session_id &&
88127
lhs.arguments == rhs.arguments && lhs.started == rhs.started;
@@ -444,17 +483,7 @@ std::ostream& operator<<(std::ostream& os, const RobotClient::status& v) {
444483

445484
RobotClient::status RobotClient::get_machine_status() const {
446485
return impl::client_helper(impl_, &RobotService::Stub::GetMachineStatus)
447-
.invoke([](const auto& resp) {
448-
switch (resp.state()) {
449-
case robot::v1::GetMachineStatusResponse_State_STATE_INITIALIZING:
450-
return RobotClient::status::k_initializing;
451-
case robot::v1::GetMachineStatusResponse_State_STATE_RUNNING:
452-
return RobotClient::status::k_running;
453-
case robot::v1::GetMachineStatusResponse_State_STATE_UNSPECIFIED:
454-
default:
455-
return RobotClient::status::k_unspecified;
456-
}
457-
});
486+
.invoke([](const auto& resp) { return from_proto(resp); });
458487
}
459488

460489
} // namespace sdk

src/viam/sdk/robot/client.hpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ struct LogBackend;
3737

3838
/// @defgroup Robot Classes related to a Robot representation.
3939

40+
/// @brief Represents the status of a job on the robot.
41+
/// @ingroup Robot
42+
struct JobStatus {
43+
std::string job_name;
44+
std::vector<time_pt> recent_successful_runs;
45+
std::vector<time_pt> recent_failed_runs;
46+
friend bool operator==(const JobStatus& lhs, const JobStatus& rhs);
47+
};
48+
49+
/// @brief Represents the overall machine status of the robot.
50+
/// @ingroup Robot
51+
struct MachineStatus {
52+
viam::sdk::RobotClient::status state;
53+
std::vector<JobStatus> job_statuses;
54+
friend bool operator==(const MachineStatus& lhs, const MachineStatus& rhs);
55+
};
56+
4057
/// @class RobotClient client.hpp "robot/client.hpp"
4158
/// @brief gRPC client for a robot, to be used for all interactions with a robot.
4259
/// There are two ways to instantiate a robot:
@@ -165,7 +182,7 @@ class RobotClient {
165182
void cancel_operation(std::string id);
166183

167184
/// @brief gets the current status of the machine
168-
status get_machine_status() const;
185+
MachineStatus get_machine_status() const;
169186

170187
private:
171188
friend class ModuleService;
@@ -217,6 +234,16 @@ struct from_proto_impl<robot::v1::FrameSystemConfig> {
217234
RobotClient::frame_system_config operator()(const robot::v1::FrameSystemConfig*) const;
218235
};
219236

237+
template <>
238+
struct from_proto_impl<robot::v1::JobStatus> {
239+
JobStatus operator()(const robot::v1::JobStatus*) const;
240+
};
241+
242+
template <>
243+
struct from_proto_impl<robot::v1::GetMachineStatusResponse> {
244+
MachineStatus operator()(const robot::v1::GetMachineStatusResponse*) const;
245+
};
246+
220247
} // namespace proto_convert_details
221248
} // namespace sdk
222-
} // namespace viam
249+
} // namespace viam

src/viam/sdk/tests/test_robot.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::frame_system_config)
2323
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::operation)
24+
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::JobStatus)
25+
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::MachineStatus)
2426

2527
namespace viam {
2628
namespace sdktests {
@@ -191,9 +193,33 @@ BOOST_AUTO_TEST_CASE(test_transform_pose) {
191193
BOOST_AUTO_TEST_CASE(test_get_machine_status) {
192194
robot_client_to_mocks_pipeline(
193195
[](std::shared_ptr<RobotClient> client, MockRobotService& service) -> void {
196+
// Define mock JobStatus objects
197+
JobStatus mock_job_status1;
198+
mock_job_status1.job_name = "job1";
199+
mock_job_status1.recent_successful_runs.push_back(
200+
time_pt{std::chrono::seconds(1678886400)}); // Example timestamp
201+
mock_job_status1.recent_failed_runs.push_back(
202+
time_pt{std::chrono::seconds(1678886500)}); // Example timestamp
203+
JobStatus mock_job_status2;
204+
mock_job_status2.job_name = "job2";
205+
mock_job_status2.recent_successful_runs.push_back(
206+
time_pt{std::chrono::seconds(1678886600)});
207+
mock_job_status2.recent_failed_runs.push_back(
208+
time_pt{std::chrono::seconds(1678886700)});
209+
std::vector<JobStatus> mock_job_statuses;
210+
mock_job_statuses.push_back(mock_job_status1);
211+
mock_job_statuses.push_back(mock_job_status2);
212+
// Define expected MachineStatus
213+
MachineStatus expected_machine_status;
214+
expected_machine_status.state = RobotClient::status::k_running;
215+
expected_machine_status.job_statuses = mock_job_statuses;
216+
// The MockRobotService (not in context) would need to be updated
217+
// to return a GetMachineStatusResponse that, when converted,
218+
// matches `expected_machine_status`.
219+
// For the purpose of this test, we assume the mock service
220+
// is configured to return this data.
194221
auto status = client->get_machine_status();
195-
196-
BOOST_CHECK_EQUAL(status, RobotClient::status::k_running);
222+
BOOST_CHECK_EQUAL(status, expected_machine_status);
197223
});
198224
}
199225

@@ -229,4 +255,4 @@ BOOST_AUTO_TEST_SUITE_END()
229255

230256
} // namespace robot
231257
} // namespace sdktests
232-
} // namespace viam
258+
} // namespace viam

0 commit comments

Comments
 (0)