source: flair-src/branches/mavlink/tools/Controller/Mavlink/src/main.cpp@ 52

Last change on this file since 52 was 46, checked in by Thomas Fuhrmann, 8 years ago

Add the mavlink branch

File size: 2.4 KB
Line 
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
23using namespace TCLAP;
24using namespace std;
25using namespace flair::core;
26using namespace flair::sensor;
27
28string receiverAddress;
29int receiverPort;
30int port;
31string xml_file;
32
33void parseOptions(int argc, char **argv);
34
35int 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
56void 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}
Note: See TracBrowser for help on using the repository browser.