Skip to content

Commit

Permalink
core, integration_tests: Address review commets mavlink#310
Browse files Browse the repository at this point in the history
1. Make `camera_id` to start from 0.
2. Minor changes to multi-comp integration test.
  • Loading branch information
Shakthi Prashanth M committed Apr 4, 2018
1 parent 8cc3aca commit de4ea6b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions core/mavlink_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ bool MAVLinkSystem::is_camera(uint8_t comp_id)
&& (comp_id <= MAV_COMP_ID_CAMERA6);
}

bool MAVLinkSystem::has_camera(uint8_t camera_id) const
bool MAVLinkSystem::has_camera(int camera_id) const
{
uint8_t camera_comp_id = (camera_id == 0) ?
camera_id : (MAV_COMP_ID_CAMERA + (camera_id - 1));
int camera_comp_id = (camera_id == -1) ?
camera_id : (MAV_COMP_ID_CAMERA + camera_id);

if (camera_comp_id == 0) { // Check whether the system has any camera.
if (camera_comp_id == -1) { // Check whether the system has any camera.
for (auto compid : _components) {
if (is_camera(compid)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion core/mavlink_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class MAVLinkSystem

bool is_standalone() const;
bool has_autopilot() const;
bool has_camera(uint8_t camera_id = 0) const;
bool has_camera(int camera_id = -1) const;
bool has_gimbal() const;

uint64_t get_uuid() const;
Expand Down
2 changes: 1 addition & 1 deletion core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool System::has_autopilot() const
return _mavlink_system->has_autopilot();
}

bool System::has_camera(uint8_t camera_id) const
bool System::has_camera(int camera_id) const
{
return _mavlink_system->has_camera(camera_id);
}
Expand Down
6 changes: 3 additions & 3 deletions core/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ class System
/**
* @brief Checks whether the system has a camera with the given camera ID.
*
* A System may have several cameras with ID starting from 1.
* A System may have several cameras with ID starting from 0.
* When called without passing camera ID, it checks whether the system has
* any camera.
* @param camera_id ID of the camera starting from 1 onwards.
* @param camera_id ID of the camera starting from 0 onwards.
* @return true if camera with the given camera ID is found, false otherwise.
*/
bool has_camera(uint8_t camera_id = 0) const;
bool has_camera(int camera_id = -1) const;

/**
* @brief Checks whether the system has a gimbal.
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/multi_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ TEST_F(SitlTest, MultiComponentDiscovery)
auto has_gimbal = system.has_gimbal();

if (has_autopilot && has_camera && !has_gimbal) {
std::cout << "Its an Autopilot with a Camera." << '\n';
std::cout << "Its an autopilot with camera(s)." << '\n';
} else if (is_standalone && has_camera) {
std::cout << "Its a Standalone camera." << '\n';
std::cout << "Its a standalone camera." << '\n';
} else if (has_autopilot && !has_camera) {
std::cout << "Its an Autopilot alone." << '\n';
std::cout << "Its an autopilot alone." << '\n';
}
}
}

0 comments on commit de4ea6b

Please sign in to comment.