Skip to content

Commit

Permalink
Add support for controlling the DroneServer ip address so we can talk…
Browse files Browse the repository at this point in the history
… to it across machines.
  • Loading branch information
lovettchris committed Feb 17, 2017
1 parent 88d0b6e commit 7c0bb3f
Show file tree
Hide file tree
Showing 7 changed files with 627 additions and 513 deletions.
2 changes: 1 addition & 1 deletion AirLib/include/control/RpcLibServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace msr { namespace airlib {

class RpcLibServer : ControlServerBase {
public:
RpcLibServer(DroneControlServer* drone, uint16_t port = 41451);
RpcLibServer(DroneControlServer* drone, string server_address, uint16_t port = 41451);
virtual void start(bool block = false) override;
virtual void stop() override;
virtual ~RpcLibServer() override;
Expand Down
8 changes: 4 additions & 4 deletions AirLib/src/control/RpcLibServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ STRICT_MODE_ON
namespace msr { namespace airlib {

struct RpcLibServer::impl {
impl(uint16_t port)
: server(port)
impl(string server_address, uint16_t port)
: server(server_address, port)
{}

rpc::server server;
};

typedef msr::airlib_rpclib::RpcLibAdapators RpcLibAdapators;

RpcLibServer::RpcLibServer(DroneControlServer* drone, uint16_t port)
RpcLibServer::RpcLibServer(DroneControlServer* drone, string server_address, uint16_t port)
: drone_(drone)
{
pimpl_.reset(new impl(port));
pimpl_.reset(new impl(server_address, port));
pimpl_->server.bind("armDisarm", [&](bool arm) -> bool { return drone_->armDisarm(arm); });
pimpl_->server.bind("requestControl", [&]() -> bool { return drone_->requestControl(); });
pimpl_->server.bind("releaseControl", [&]() -> bool { return drone_->releaseControl(); });
Expand Down
49 changes: 43 additions & 6 deletions DroneServer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,61 @@
// Licensed under the MIT License.

#include <iostream>
#include <string>
#include "control/RpcLibServer.hpp"
#include "control/MavLinkDroneControl.hpp"

using namespace std;
using namespace msr::airlib;

int main()
std::string server_address("127.0.0.1");

bool parseCommandLine(int argc, const char* argv[])
{
// parse command line
for (int i = 1; i < argc; i++)
{
const char* arg = argv[i];
if (arg[0] == '-' || arg[0] == '/')
{
std::string name = arg + 1;
if (name == "ipaddress" && i + 1 < argc)
{
server_address = argv[++i];
}
else {
return false;
}
}
else {
return false;
}
}
return true;
}

void printUsage() {
cout << "Usage: DroneServer [-ipaddress 127.0.0.1]" << endl;
}

int main(int argc, const char* argv[])
{
using namespace msr::airlib;
if (!parseCommandLine(argc, argv)) {
printUsage();
return 1;
}

MavLinkDroneControl::Parameters params;
params.udpAddress = server_address;
MavLinkDroneControl mav(params);
DroneControlServer server_wrapper(&mav);
msr::airlib::RpcLibServer server(&server_wrapper);
msr::airlib::RpcLibServer server(&server_wrapper, server_address);

auto v = vector<msr::airlib::uint8_t>{ 5, 4, 3 };
auto v = std::vector<msr::airlib::uint8_t>{ 5, 4, 3 };
server_wrapper.setImageForCamera(3, DroneControlBase::ImageType::Depth, v);
server_wrapper.setImageForCamera(4, DroneControlBase::ImageType::Scene, vector<msr::airlib::uint8_t>{6, 5, 4, 3, 2});
server_wrapper.setImageForCamera(4, DroneControlBase::ImageType::Scene, std::vector<msr::airlib::uint8_t>{6, 5, 4, 3, 2});

std::cout << "Server started" << std::endl;
std::cout << "Server started at " << server_address << ":" << params.udpPort << std::endl;
server.start(true);
return 0;
}
Loading

0 comments on commit 7c0bb3f

Please sign in to comment.