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

Last change on this file since 79 was 77, checked in by Thomas Fuhrmann, 5 years ago

Change the GUI of MavPlanner? to match with mission planning (only GUI is working)

File size: 4.3 KB
RevLine 
[46]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
[71]22#include "GuiFlair.h"
23#include "GuiGcs.h"
24#include "Forwarder.h"
25
26//todo remove for tests
27#include <iostream>
28
[46]29using namespace TCLAP;
30using namespace std;
31using namespace flair::core;
32
[71]33string xmlFile;
34string mode;
35string inputAddress;
36int inputPort;
37string outputAddress;
38int outputPort;
39string flairAddress;
40int flairPort;
[46]41
42void parseOptions(int argc, char **argv);
43
44int main(int argc, char *argv[]) {
[71]45  std::cout << "avant parseOptions" << std::endl;
[46]46  parseOptions(argc, argv);
47
[71]48  std::cout << "parseOptions ok" << std::endl;
49
[46]50  FrameworkManager *manager;
[77]51  manager = new FrameworkManager("MavPlanner");
[71]52  manager->SetupConnection(flairAddress, flairPort);
53  manager->SetupUserInterface(xmlFile);
[46]54
[71]55  std::cout << "MavPlanner mode : " << mode << std::endl;
[46]56
[71]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    }
[46]78  }
79
80  delete manager;
81}
82
83void parseOptions(int argc, char **argv) {
84  try {
85    CmdLine cmd("Command description message", ' ', "0.1");
86
[71]87    ValueArg<string> inputAddressArg("", "inputAddress",
88                                "input IP address", false,
89                                "127.0.0.1", "string");
90    cmd.add(inputAddressArg);
[46]91
[71]92    ValueArg<int> inputPortArg("", "inputPort",
93                          "input IP port", false,
94                          9000, "int");
95    cmd.add(inputPortArg);
[46]96
[71]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
[46]117    ValueArg<string> xmlArg("x", "xml", "xml file", true, "./settings.xml",
118                            "string");
119    cmd.add(xmlArg);
120
[71]121    ValueArg<string> modeArg("m", "mode", "application mode (forward, flair, gcs)",
122                             true, "flair", "string");
123    cmd.add(modeArg);
124
[46]125    cmd.parse(argc, argv);
126
[71]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   
[46]133    // Get the value parsed by each arg.
[71]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();
[46]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.