Skip to content

Commit

Permalink
Merge 'origin/develop' into pr_621
Browse files Browse the repository at this point in the history
  • Loading branch information
julianoes committed Dec 13, 2018
2 parents edd10d5 + 85ff810 commit 41cb76e
Show file tree
Hide file tree
Showing 36 changed files with 946 additions and 281 deletions.
26 changes: 13 additions & 13 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pipeline {
stage('Ubuntu 16.04 Debug') {
agent {
docker {
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-10-01'
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-11-28'
args '-e LOCAL_USER_ID=user_id'
}
}
Expand All @@ -35,7 +35,7 @@ pipeline {
stage('Ubuntu 16.04 Release') {
agent {
docker {
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-10-01'
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-11-28'
}
}
steps {
Expand All @@ -52,7 +52,7 @@ pipeline {
stage('Ubuntu 18.04 Debug') {
agent {
docker {
image 'dronecode/dronecode-sdk-ubuntu-18.04:2018-10-01'
image 'dronecode/dronecode-sdk-ubuntu-18.04:2018-11-28'
}
}
steps {
Expand All @@ -69,7 +69,7 @@ pipeline {
stage('Ubuntu 18.04 Release') {
agent {
docker {
image 'dronecode/dronecode-sdk-ubuntu-18.04:2018-10-01'
image 'dronecode/dronecode-sdk-ubuntu-18.04:2018-11-28'
}
}
steps {
Expand All @@ -86,7 +86,7 @@ pipeline {
stage('Fedora 27 Debug') {
agent {
docker {
image 'dronecode/dronecode-sdk-fedora-27:2018-10-01'
image 'dronecode/dronecode-sdk-fedora-27:2018-11-28'
}
}
steps {
Expand All @@ -103,7 +103,7 @@ pipeline {
stage('Fedora 27 Release') {
agent {
docker {
image 'dronecode/dronecode-sdk-fedora-27:2018-10-01'
image 'dronecode/dronecode-sdk-fedora-27:2018-11-28'
}
}
steps {
Expand All @@ -120,7 +120,7 @@ pipeline {
stage('Fedora 28 Debug') {
agent {
docker {
image 'dronecode/dronecode-sdk-fedora-28:2018-10-01'
image 'dronecode/dronecode-sdk-fedora-28:2018-11-28'
}
}
steps {
Expand All @@ -137,7 +137,7 @@ pipeline {
stage('Fedora 28 Release') {
agent {
docker {
image 'dronecode/dronecode-sdk-fedora-28:2018-10-01'
image 'dronecode/dronecode-sdk-fedora-28:2018-11-28'
}
}
steps {
Expand All @@ -160,7 +160,7 @@ pipeline {
stage('check style') {
agent {
docker {
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-10-01'
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-11-28'
}
}
steps {
Expand All @@ -171,7 +171,7 @@ pipeline {
stage('example/takeoff_land') {
agent {
docker {
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-10-01'
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-11-28'
}
}
steps {
Expand All @@ -187,7 +187,7 @@ pipeline {
stage('example/fly_mission') {
agent {
docker {
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-10-01'
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-11-28'
}
}
steps {
Expand All @@ -203,7 +203,7 @@ pipeline {
stage('example/offboard_velocity') {
agent {
docker {
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-10-01'
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-11-28'
}
}
steps {
Expand All @@ -222,7 +222,7 @@ pipeline {
stage('Generate Docs') {
agent {
docker {
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-10-01'
image 'dronecode/dronecode-sdk-ubuntu-16.04:2018-11-28'
}
}
steps {
Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ endif
# Check for ninja and use it if available
NINJA_BUILD := $(shell ninja --version 2>/dev/null)

NPROCS := 1
OS := $(shell uname -s)

ifeq ($(OS),Linux)
NPROCS := $(shell grep -c ^processor /proc/cpuinfo)
endif
ifeq ($(OS),Darwin) #Mac OS
NPROCS := $(shell sysctl -n hw.ncpu || echo 1)
endif

ifdef NINJA_BUILD
CMAKE_GENERATOR ?= "Ninja"
MAKE = ninja
MAKE_ARGS =
else
CMAKE_GENERATOR ?= "Unix Makefiles"
MAKE = make
# Use 8 processes in parallel for the usual make
MAKE_ARGS = -j8
MAKE_ARGS = -j$(NPROCS)
endif

# Get additional arguments after target argument. (e.g. make release install)
Expand Down
2 changes: 1 addition & 1 deletion backend/proto
Submodule proto updated from b609b0 to d117c0
3 changes: 2 additions & 1 deletion backend/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.1)

set(COMPONENTS_LIST core action calibration camera mission telemetry)
set(COMPONENTS_LIST core action calibration camera mission telemetry info)

include(cmake/compile_proto.cmake)

Expand Down Expand Up @@ -43,6 +43,7 @@ target_link_libraries(backend
dronecode_sdk_camera
dronecode_sdk_mission
dronecode_sdk_telemetry
dronecode_sdk_info
gRPC::grpc++
)

Expand Down
2 changes: 1 addition & 1 deletion backend/src/core/core_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CoreServiceImpl final : public dronecode_sdk::rpc::core::CoreService::Serv
const rpc::core::ListRunningPluginsRequest * /* request */,
dronecode_sdk::rpc::core::ListRunningPluginsResponse *response) override
{
std::string plugin_names[3] = {"action", "mission", "telemetry"};
std::string plugin_names[4] = {"action", "mission", "telemetry", "info"};

for (const auto plugin_name : plugin_names) {
auto plugin_info = response->add_plugin_info();
Expand Down
1 change: 1 addition & 0 deletions backend/src/grpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void GRPCServer::run()
builder.RegisterService(&_camera_service);
builder.RegisterService(&_mission_service);
builder.RegisterService(&_telemetry_service);
builder.RegisterService(&_info_service);

_server = builder.BuildAndStart();
LogInfo() << "Server started";
Expand Down
7 changes: 6 additions & 1 deletion backend/src/grpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "plugins/mission/mission.h"
#include "mission/mission_service_impl.h"
#include "telemetry/telemetry_service_impl.h"
#include "info/info_service_impl.h"

namespace dronecode_sdk {
namespace backend {
Expand All @@ -32,7 +33,9 @@ class GRPCServer {
_mission(_dc.system()),
_mission_service(_mission),
_telemetry(_dc.system()),
_telemetry_service(_telemetry)
_telemetry_service(_telemetry),
_info(_dc.system()),
_info_service(_info)
{}

void run();
Expand All @@ -54,6 +57,8 @@ class GRPCServer {
MissionServiceImpl<> _mission_service;
Telemetry _telemetry;
TelemetryServiceImpl<> _telemetry_service;
Info _info;
InfoServiceImpl<> _info_service;

std::unique_ptr<grpc::Server> _server;
};
Expand Down
47 changes: 47 additions & 0 deletions backend/src/plugins/info/info_service_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "plugins/info/info.h"
#include "info/info.grpc.pb.h"

namespace dronecode_sdk {
namespace backend {

template<typename Info = Info>
class InfoServiceImpl final : public rpc::info::InfoService::Service {
public:
InfoServiceImpl(Info &info) : _info(info) {}

grpc::Status GetVersion(grpc::ServerContext * /* context */,
const rpc::info::GetVersionRequest * /* request */,
rpc::info::GetVersionResponse *response) override
{
if (response != nullptr) {
auto result_pair = _info.get_version();

auto *rpc_info_result = new rpc::info::InfoResult();
rpc_info_result->set_result(
static_cast<rpc::info::InfoResult::Result>(result_pair.first));
rpc_info_result->set_result_str(dronecode_sdk::Info::result_str(result_pair.first));

auto *rpc_version = new rpc::info::Version();
rpc_version->set_flight_sw_major(result_pair.second.flight_sw_major);
rpc_version->set_flight_sw_minor(result_pair.second.flight_sw_minor);
rpc_version->set_flight_sw_patch(result_pair.second.flight_sw_patch);
rpc_version->set_flight_sw_vendor_major(result_pair.second.flight_sw_vendor_major);
rpc_version->set_flight_sw_vendor_minor(result_pair.second.flight_sw_vendor_minor);
rpc_version->set_flight_sw_vendor_patch(result_pair.second.flight_sw_vendor_patch);
rpc_version->set_os_sw_major(result_pair.second.os_sw_major);
rpc_version->set_os_sw_minor(result_pair.second.os_sw_minor);
rpc_version->set_os_sw_patch(result_pair.second.os_sw_patch);

response->set_allocated_info_result(rpc_info_result);
response->set_allocated_version(rpc_version);
}

return grpc::Status::OK;
}

private:
Info &_info;
};

} // namespace backend
} // namespace dronecode_sdk
1 change: 1 addition & 0 deletions backend/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_executable(unit_tests_backend
core_service_impl_test.cpp
mission_service_impl_test.cpp
telemetry_service_impl_test.cpp
info_service_impl_test.cpp
)

set_target_properties(unit_tests_backend PROPERTIES COMPILE_FLAGS ${warnings})
Expand Down
108 changes: 108 additions & 0 deletions backend/test/info_service_impl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include <gmock/gmock.h>
#include <string>
#include <utility>
#include <vector>

#include "info/info_service_impl.h"
#include "info/mocks/info_mock.h"

namespace {

using testing::_;
using testing::NiceMock;
using testing::Return;

using MockInfo = NiceMock<dronecode_sdk::testing::MockInfo>;
using InfoServiceImpl = dronecode_sdk::backend::InfoServiceImpl<MockInfo>;

using InfoResult = dronecode_sdk::rpc::info::InfoResult;
using InputPair = std::pair<std::string, dronecode_sdk::Info::Result>;

static constexpr int ARBITRARY_SW_VERSION_MAJOR = 1;
static constexpr int ARBITRARY_SW_VERSION_MINOR = 2;
static constexpr int ARBITRARY_SW_VERSION_PATCH = 3;

static constexpr int ARBITRARY_SW_VERSION_VENDOR_MAJOR = 1;
static constexpr int ARBITRARY_SW_VERSION_VENDOR_MINOR = 2;
static constexpr int ARBITRARY_SW_VERSION_VENDOR_PATCH = 3;

static constexpr int ARBITRARY_SW_VERSION_OS_MAJOR = 4;
static constexpr int ARBITRARY_SW_VERSION_OS_MINOR = 5;
static constexpr int ARBITRARY_SW_VERSION_OS_PATCH = 6;

std::vector<InputPair> generateInputPairs();

class InfoServiceImplTest : public ::testing::TestWithParam<InputPair> {};

TEST_F(InfoServiceImplTest, getVersionCallsGetter)
{
MockInfo info;
InfoServiceImpl infoService(info);
EXPECT_CALL(info, get_version()).Times(1);
dronecode_sdk::rpc::info::GetVersionResponse response;

infoService.GetVersion(nullptr, nullptr, &response);
}

TEST_P(InfoServiceImplTest, getsCorrectVersion)
{
MockInfo info;
InfoServiceImpl infoService(info);

dronecode_sdk::Info::Version arbitrary_version;

arbitrary_version.flight_sw_major = ARBITRARY_SW_VERSION_MAJOR;
arbitrary_version.flight_sw_minor = ARBITRARY_SW_VERSION_MINOR;
arbitrary_version.flight_sw_patch = ARBITRARY_SW_VERSION_PATCH;
arbitrary_version.flight_sw_vendor_major = ARBITRARY_SW_VERSION_VENDOR_MAJOR;
arbitrary_version.flight_sw_vendor_minor = ARBITRARY_SW_VERSION_VENDOR_MINOR;
arbitrary_version.flight_sw_vendor_patch = ARBITRARY_SW_VERSION_VENDOR_PATCH;
arbitrary_version.os_sw_major = ARBITRARY_SW_VERSION_OS_MAJOR;
arbitrary_version.os_sw_minor = ARBITRARY_SW_VERSION_OS_MINOR;
arbitrary_version.os_sw_patch = ARBITRARY_SW_VERSION_OS_PATCH;

const auto expected_pair = std::make_pair<>(GetParam().second, arbitrary_version);
ON_CALL(info, get_version()).WillByDefault(Return(expected_pair));
dronecode_sdk::rpc::info::GetVersionResponse response;

infoService.GetVersion(nullptr, nullptr, &response);

EXPECT_EQ(GetParam().first, InfoResult::Result_Name(response.info_result().result()));
EXPECT_EQ(expected_pair.second.flight_sw_major, response.version().flight_sw_major());
EXPECT_EQ(expected_pair.second.flight_sw_minor, response.version().flight_sw_minor());
EXPECT_EQ(expected_pair.second.flight_sw_patch, response.version().flight_sw_patch());
EXPECT_EQ(expected_pair.second.flight_sw_vendor_major,
response.version().flight_sw_vendor_major());
EXPECT_EQ(expected_pair.second.flight_sw_vendor_minor,
response.version().flight_sw_vendor_minor());
EXPECT_EQ(expected_pair.second.flight_sw_vendor_patch,
response.version().flight_sw_vendor_patch());
EXPECT_EQ(expected_pair.second.os_sw_major, response.version().os_sw_major());
EXPECT_EQ(expected_pair.second.os_sw_minor, response.version().os_sw_minor());
EXPECT_EQ(expected_pair.second.os_sw_patch, response.version().os_sw_patch());
}

TEST_F(InfoServiceImplTest, getVersionDoesNotCrashWithNullResponse)
{
MockInfo info;
InfoServiceImpl infoService(info);

infoService.GetVersion(nullptr, nullptr, nullptr);
}

INSTANTIATE_TEST_CASE_P(InfoResultCorrespondences,
InfoServiceImplTest,
::testing::ValuesIn(generateInputPairs()));

std::vector<InputPair> generateInputPairs()
{
std::vector<InputPair> input_pairs;
input_pairs.push_back(std::make_pair("SUCCESS", dronecode_sdk::Info::Result::SUCCESS));
input_pairs.push_back(std::make_pair(
"INFORMATION_NOT_RECEIVED_YET", dronecode_sdk::Info::Result::INFORMATION_NOT_RECEIVED_YET));
input_pairs.push_back(std::make_pair("UNKNOWN", dronecode_sdk::Info::Result::UNKNOWN));

return input_pairs;
}

} // namespace
9 changes: 9 additions & 0 deletions core/mavlink_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ void MAVLinkParameters::do_work()
}
}

void MAVLinkParameters::remove_from_cache(const std::string &name)
{
const auto &it = _cache.find(name);
if (it == _cache.end()) {
return;
}
_cache.erase(it);
}

void MAVLinkParameters::reset_cache()
{
_cache.clear();
Expand Down
1 change: 1 addition & 0 deletions core/mavlink_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ class MAVLinkParameters {
void do_work();

void reset_cache();
void remove_from_cache(const std::string &name);

friend std::ostream &operator<<(std::ostream &, const ParamValue &);

Expand Down
Loading

0 comments on commit 41cb76e

Please sign in to comment.