1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2016/07/05
|
---|
6 | // filename: main.cpp
|
---|
7 | //
|
---|
8 | // author: Thomas Fuhrmann
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: main for the mavlink controller
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "FrameworkManager.h"
|
---|
19 | #include "Mavlink_test.h"
|
---|
20 | #include <stdio.h>
|
---|
21 | #include <tclap/CmdLine.h>
|
---|
22 |
|
---|
23 | using namespace TCLAP;
|
---|
24 | using namespace std;
|
---|
25 | using namespace flair::core;
|
---|
26 | using namespace flair::sensor;
|
---|
27 |
|
---|
28 | string receiverAddress;
|
---|
29 | int receiverPort;
|
---|
30 | int port;
|
---|
31 | string xml_file;
|
---|
32 |
|
---|
33 | void parseOptions(int argc, char **argv);
|
---|
34 |
|
---|
35 | int main(int argc, char *argv[]) {
|
---|
36 | parseOptions(argc, argv);
|
---|
37 |
|
---|
38 | FrameworkManager *manager;
|
---|
39 | Mavlink *mavlink_handler;
|
---|
40 |
|
---|
41 | manager = new FrameworkManager("mavlink");
|
---|
42 | manager->SetupConnection("127.0.0.1", port);
|
---|
43 | manager->SetupUserInterface(xml_file);
|
---|
44 |
|
---|
45 | mavlink_handler = new Mavlink(manager, "mavlink", receiverAddress,
|
---|
46 | receiverPort);
|
---|
47 |
|
---|
48 | if (!manager->ErrorOccured()) {
|
---|
49 | mavlink_handler->Start();
|
---|
50 | mavlink_handler->Join();
|
---|
51 | }
|
---|
52 |
|
---|
53 | delete manager;
|
---|
54 | }
|
---|
55 |
|
---|
56 | void parseOptions(int argc, char **argv) {
|
---|
57 | try {
|
---|
58 | CmdLine cmd("Command description message", ' ', "0.1");
|
---|
59 |
|
---|
60 | ValueArg<string> addressArg("a", "address",
|
---|
61 | "data receiver address (ex: uav)", true,
|
---|
62 | "127.0.0.1:20000", "string");
|
---|
63 | cmd.add(addressArg);
|
---|
64 |
|
---|
65 | ValueArg<int> portArg("p", "port",
|
---|
66 | "local port used to connect to the ground station",
|
---|
67 | false, 9000, "int");
|
---|
68 | cmd.add(portArg);
|
---|
69 |
|
---|
70 | ValueArg<string> xmlArg("x", "xml", "xml file", true, "./settings.xml",
|
---|
71 | "string");
|
---|
72 | cmd.add(xmlArg);
|
---|
73 |
|
---|
74 | cmd.parse(argc, argv);
|
---|
75 |
|
---|
76 | // Get the value parsed by each arg.
|
---|
77 | string receiverAddressWithPort = addressArg.getValue();
|
---|
78 | int semiColonPosition = receiverAddressWithPort.find(":");
|
---|
79 | receiverAddress = receiverAddressWithPort.substr(0, semiColonPosition);
|
---|
80 | receiverPort =
|
---|
81 | atoi(receiverAddressWithPort.substr(semiColonPosition + 1).c_str());
|
---|
82 | port = portArg.getValue();
|
---|
83 | xml_file = xmlArg.getValue();
|
---|
84 |
|
---|
85 | } catch (ArgException &e) { // catch any exceptions
|
---|
86 | cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
|
---|
87 | }
|
---|
88 | }
|
---|