source: flair-src/trunk/tools/Controller/Mavlink/src/main.cpp@ 104

Last change on this file since 104 was 88, checked in by Sanahuja Guillaume, 8 years ago

m

File size: 4.3 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 <stdio.h>
20#include <tclap/CmdLine.h>
21
22#include "GuiFlair.h"
23#include "GuiGcs.h"
24#include "Forwarder.h"
25
26//todo remove for tests
27#include <iostream>
28
29using namespace TCLAP;
30using namespace std;
31using namespace flair::core;
32
33string xmlFile;
34string mode;
35string inputAddress;
36int inputPort;
37string outputAddress;
38int outputPort;
39string flairAddress;
40int flairPort;
41
42void parseOptions(int argc, char **argv);
43
44int main(int argc, char *argv[]) {
45 std::cout << "avant parseOptions" << std::endl;
46 parseOptions(argc, argv);
47
48 std::cout << "parseOptions ok" << std::endl;
49
50 FrameworkManager *manager;
51 manager = new FrameworkManager("MavPlanner");
52 manager->SetupConnection(flairAddress, flairPort);
53 manager->SetupUserInterface(xmlFile);
54
55 std::cout << "MavPlanner mode : " << mode << std::endl;
56
57 if(mode == "forward") {
58 Forwarder *guiForwarder = new Forwarder(manager, "Forwarder",
59 inputAddress, inputPort,
60 outputAddress, outputPort);
61 if (!manager->ErrorOccured()) {
62 guiForwarder->Start();
63 guiForwarder->Join();
64 }
65 } else {
66 GuiInterface *guiHandler;
67 if(mode == "flair") {
68 guiHandler = new GuiFlair(manager, "GuiFlair");
69 } else if (mode == "gcs") {
70 guiHandler = new GuiGcs(manager, "GuiGcs", outputAddress, outputPort);
71 } else {
72 //ERROR
73 }
74 if (!manager->ErrorOccured()) {
75 guiHandler->Start();
76 guiHandler->Join();
77 }
78 }
79
80 delete manager;
81}
82
83void parseOptions(int argc, char **argv) {
84 try {
85 CmdLine cmd("Command description message", ' ', "0.1");
86
87 ValueArg<string> inputAddressArg("", "inputAddress",
88 "input IP address", false,
89 "127.0.0.1", "string");
90 cmd.add(inputAddressArg);
91
92 ValueArg<int> inputPortArg("", "inputPort",
93 "input IP port", false,
94 9000, "int");
95 cmd.add(inputPortArg);
96
97 ValueArg<string> outputAddressArg("", "outputAddress",
98 "output IP address", false,
99 "127.0.0.1", "string");
100 cmd.add(outputAddressArg);
101
102 ValueArg<int> outputPortArg("", "outputPort",
103 "output IP port", false,
104 9000, "int");
105 cmd.add(outputPortArg);
106
107 ValueArg<string> flairAddressArg("a", "flairAddress",
108 "flair IP address", true,
109 "127.0.0.1", "string");
110 cmd.add(flairAddressArg);
111
112 ValueArg<int> flairPortArg("p", "flairPort",
113 "flair IP port", true,
114 9000, "int");
115 cmd.add(flairPortArg);
116
117 ValueArg<string> xmlArg("x", "xml", "xml file", true, "./settings.xml",
118 "string");
119 cmd.add(xmlArg);
120
121 ValueArg<string> modeArg("m", "mode", "application mode (forward, flair, gcs)",
122 true, "flair", "string");
123 cmd.add(modeArg);
124
125 cmd.parse(argc, argv);
126
127 // string receiverAddressWithPort = inputAddressArg.getValue();
128 // int semiColonPosition = receiverAddressWithPort.find(":");
129 // receiverAddress = receiverAddressWithPort.substr(0, semiColonPosition);
130 // receiverPort =
131 // atoi(receiverAddressWithPort.substr(semiColonPosition + 1).c_str());
132
133 // Get the value parsed by each arg.
134 inputAddress = inputAddressArg.getValue();
135 inputPort = inputPortArg.getValue();
136 outputAddress = outputAddressArg.getValue();
137 outputPort = outputPortArg.getValue();
138 flairAddress = flairAddressArg.getValue();
139 flairPort = flairPortArg.getValue();
140 xmlFile = xmlArg.getValue();
141 mode = modeArg.getValue();
142
143 } catch (ArgException &e) { // catch any exceptions
144 cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
145 }
146}
Note: See TracBrowser for help on using the repository browser.