source: flair-src/trunk/tools/FlairGCS/src/main.cpp@ 342

Last change on this file since 342 was 303, checked in by Sanahuja Guillaume, 6 years ago

m

File size: 2.0 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[9]5#include <QApplication>
6#include <QCleanlooksStyle>
7#include <QLocale>
[234]8#include <QTextCursor>
[9]9#include <qmetatype.h>
[15]10#include <tclap/CmdLine.h>
[222]11#include <execinfo.h>
12#include <signal.h>
[9]13
14#include "Manager.h"
[303]15#include "compile_info.h"
[9]16
17using namespace TCLAP;
18using namespace std;
19
20string name;
21int port;
22
[15]23void parseOptions(int argc, char **argv) {
24 try {
25 CmdLine cmd("Command description message", ' ', "0.1");
[9]26
[15]27 ValueArg<string> nameArg("n", "name", "uav name", false, "x4-0", "string");
28 cmd.add(nameArg);
[9]29
[15]30 ValueArg<int> portArg("p", "port", "port number", false, 9000, "int");
31 cmd.add(portArg);
[9]32
[15]33 cmd.parse(argc, argv);
[9]34
[15]35 // Get the value parsed by each arg.
36 name = nameArg.getValue();
37 port = portArg.getValue();
38
39 } catch (ArgException &e) { // catch any exceptions
40 cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
41 }
[9]42}
[15]43
[222]44void seg_fault(int sig __attribute__((unused))) {
45 void *bt[32];
46 int nentries;
47
[244]48 fprintf(stderr,"Segmentation fault:\n");
[222]49 /* Dump a backtrace of the frame which caused the segfault: */
50 nentries = backtrace(bt, sizeof(bt) / sizeof(bt[0]));
51 backtrace_symbols_fd(bt, nentries, fileno(stdout));
52
53 exit(1);
54}
55
[9]56int main(int argc, char *argv[]) {
57
[15]58 union {
59 uint32_t i;
60 char c[4];
61 } bint = {0x01020304};
[9]62
[15]63 if (bint.c[0] == 1) {
[244]64 fprintf(stderr,"error, ground station is only compatible with little endian\n");
[15]65 return -1;
66 }
[9]67
[45]68 compile_info("FlairGCS");
[222]69
70 // catch segfault
71 signal(SIGSEGV, seg_fault);
[9]72
[15]73 parseOptions(argc, argv);
[244]74 fprintf(stderr,"listening on port %i\n", port);
[9]75
[15]76 qRegisterMetaType<const char *>("const char*");
[234]77 qRegisterMetaType<UDTSOCKET>("UDTSOCKET");
78 qRegisterMetaType<QTextCursor>("QTextCursor");
[15]79 QLocale::setDefault(QLocale::C);
80 QApplication app(argc, argv);
81 app.setStyle(new QCleanlooksStyle);
[9]82
[15]83 Manager manager(QString::fromStdString(name), port);
84
85 manager.show();
86
87 app.exec();
[9]88}
Note: See TracBrowser for help on using the repository browser.