Skip to content

Commit

Permalink
backend: add connection URL as arg to backend_bin
Browse files Browse the repository at this point in the history
This allows backend_bin to accept the connection URL as an argument, as
well as -h or --help to show the usage.
  • Loading branch information
julianoes authored and JonasVautherin committed Apr 28, 2019
1 parent 96f8ba7 commit 7d75c16
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion backend/src/dronecode_sdk_server.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
#include "backend_api.h"
#include <iostream>
#include <string>

static void usage();

static auto constexpr default_connection = "udp://:14540";

int main(int argc, char **argv)
{
runBackend("udp://14540", nullptr, nullptr);
if (argc > 2) {
usage();
return 1;
}

if (argc == 2) {
const std::string positional_arg = argv[1];
if (positional_arg.compare("-h") == 0 || positional_arg.compare("--help") == 0) {
usage();
return 0;
}
runBackend(positional_arg.c_str(), nullptr, nullptr);
}

runBackend(default_connection, nullptr, nullptr);
}

void usage()
{
std::cout << "Usage: backend_bin [-h | --help]" << std::endl
<< " backend_bin [Connection URL]" << std::endl
<< std::endl
<< "Connection URL format should be:" << std::endl
<< " Serial: serial:///path/to/serial/dev[:baudrate]" << std::endl
<< " UDP: udp://[bind_host][:bind_port]" << std::endl
<< " TCP: tcp://[server_host][:server_port]" << std::endl
<< std::endl
<< "For example to connect to SITL use: udp://:14540" << std::endl
<< std::endl
<< "Options:" << std::endl
<< " -h | --help : show this help" << std::endl;
}

0 comments on commit 7d75c16

Please sign in to comment.