Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
544 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <iostream> | ||
#include <functional> | ||
#include <memory> | ||
#include <atomic> | ||
#include "integration_test_helper.h" | ||
#include "dronecode_sdk.h" | ||
#include "plugins/telemetry/telemetry.h" | ||
#include "plugins/geofence/geofence.h" | ||
|
||
using namespace dronecode_sdk; | ||
using namespace std::placeholders; // for `_1` | ||
|
||
static void receive_send_geofence_result(Geofence::Result result); | ||
|
||
static Geofence::Polygon::Point add_point(double latitude_deg, double longitude_deg); | ||
static std::atomic<bool> _got_result{false}; | ||
|
||
TEST_F(SitlTest, GeofenceInclusion) | ||
{ | ||
DronecodeSDK dl; | ||
|
||
ConnectionResult ret = dl.add_udp_connection(); | ||
ASSERT_EQ(ret, ConnectionResult::SUCCESS); | ||
|
||
// Wait for system to connect via heartbeat. | ||
sleep(2); | ||
|
||
System &system = dl.system(); | ||
ASSERT_TRUE(system.has_autopilot()); | ||
auto telemetry = std::make_shared<Telemetry>(system); | ||
auto geofence = std::make_shared<Geofence>(system); | ||
|
||
while (!telemetry->health_all_ok()) { | ||
LogInfo() << "waiting for system to be ready"; | ||
sleep(1); | ||
} | ||
|
||
LogInfo() << "System ready, let's start"; | ||
|
||
std::vector<Geofence::Polygon::Point> points; | ||
points.push_back(add_point(47.39929240, 8.54296524)); | ||
points.push_back(add_point(47.39696482, 8.54161340)); | ||
points.push_back(add_point(47.39626761, 8.54527193)); | ||
points.push_back(add_point(47.39980072, 8.54736050)); | ||
|
||
std::vector<std::shared_ptr<Geofence::Polygon>> polygons; | ||
std::shared_ptr<Geofence::Polygon> new_polygon(new Geofence::Polygon()); | ||
new_polygon->type = Geofence::Polygon::Type::INCLUSION; | ||
new_polygon->points = points; | ||
|
||
polygons.push_back(new_polygon); | ||
|
||
geofence->send_geofence_async(polygons, std::bind(&receive_send_geofence_result, _1)); | ||
|
||
for (unsigned i = 0; i < 5; ++i) { | ||
if (_got_result) { | ||
break; | ||
} | ||
sleep(1); | ||
} | ||
|
||
EXPECT_TRUE(_got_result); | ||
} | ||
|
||
void receive_send_geofence_result(Geofence::Result result) | ||
{ | ||
EXPECT_EQ(result, Geofence::Result::SUCCESS); | ||
|
||
_got_result = true; | ||
} | ||
|
||
Geofence::Polygon::Point add_point(double latitude_deg, double longitude_deg) | ||
{ | ||
Geofence::Polygon::Point new_point; | ||
new_point.latitude_deg = latitude_deg; | ||
new_point.longitude_deg = longitude_deg; | ||
return new_point; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
add_library(dronecode_sdk_geofence ${PLUGIN_LIBRARY_TYPE} | ||
geofence.cpp | ||
geofence_impl.cpp | ||
) | ||
|
||
target_link_libraries(dronecode_sdk_geofence | ||
dronecode_sdk | ||
) | ||
|
||
set_target_properties(dronecode_sdk_geofence | ||
PROPERTIES COMPILE_FLAGS ${warnings} | ||
) | ||
|
||
install(FILES | ||
include/plugins/geofence/geofence.h | ||
DESTINATION ${dronecode_sdk_install_include_dir} | ||
) | ||
|
||
install(TARGETS dronecode_sdk_geofence | ||
#EXPORT dronecode_sdk-targets | ||
DESTINATION ${dronecode_sdk_install_lib_dir} | ||
) | ||
|
||
target_include_directories(dronecode_sdk_geofence | ||
PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "plugins/geofence/geofence.h" | ||
#include "geofence_impl.h" | ||
#include <vector> | ||
|
||
namespace dronecode_sdk { | ||
|
||
Geofence::Geofence(System &system) : PluginBase(), _impl{new GeofenceImpl(system)} {} | ||
|
||
Geofence::~Geofence() {} | ||
|
||
Geofence::Polygon::Polygon() : points(), type(Polygon::Type::INCLUSION) {} | ||
|
||
Geofence::Polygon::~Polygon() | ||
{ | ||
points.clear(); | ||
} | ||
|
||
void Geofence::send_geofence_async(const std::vector<std::shared_ptr<Geofence::Polygon>> &polygons, | ||
result_callback_t callback) | ||
{ | ||
_impl->send_geofence_async(polygons, callback); | ||
} | ||
|
||
const char *Geofence::result_str(Result result) | ||
{ | ||
switch (result) { | ||
case Result::SUCCESS: | ||
return "Success"; | ||
case Result::BUSY: | ||
return "Busy"; | ||
case Result::ERROR: | ||
return "Error"; | ||
case Result::TOO_MANY_GEOFENCE_ITEMS: | ||
return "Too many geofence items"; | ||
case Result::INVALID_ARGUMENT: | ||
return "Invalid argument"; | ||
case Result::TIMEOUT: | ||
return "Timeout"; | ||
case Result::UNKNOWN: | ||
default: | ||
return "Unknown"; | ||
} | ||
} | ||
|
||
} // namespace dronecode_sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <memory> | ||
#include <functional> | ||
#include "plugin_base.h" | ||
|
||
namespace dronecode_sdk { | ||
|
||
class GeofenceImpl; | ||
class System; | ||
|
||
class Geofence : public PluginBase { | ||
public: | ||
explicit Geofence(System &system); | ||
~Geofence(); | ||
|
||
enum class Result { | ||
SUCCESS = 0, | ||
ERROR, | ||
TOO_MANY_GEOFENCE_ITEMS, | ||
BUSY, | ||
TIMEOUT, | ||
INVALID_ARGUMENT, | ||
UNKNOWN | ||
}; | ||
|
||
static const char *result_str(Result result); | ||
|
||
typedef std::function<void(Result)> result_callback_t; | ||
|
||
struct Polygon { | ||
struct Point { | ||
double latitude_deg; | ||
double longitude_deg; | ||
}; | ||
|
||
enum class Type { INCLUSION, EXCLUSION }; | ||
|
||
std::vector<Point> points; | ||
Type type; | ||
|
||
explicit Polygon(); | ||
~Polygon(); | ||
}; | ||
|
||
void send_geofence_async(const std::vector<std::shared_ptr<Polygon>> &polygons, | ||
result_callback_t callback); | ||
|
||
// Non-copyable | ||
Geofence(const Geofence &) = delete; | ||
const Geofence &operator=(const Geofence &) = delete; | ||
|
||
private: | ||
// Underlying implementation, set at instantiation | ||
GeofenceImpl *_impl; | ||
}; | ||
|
||
} // namespace dronecode_sdk |
Oops, something went wrong.