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 | #include <QApplication>
|
---|
6 | #include <QCleanlooksStyle>
|
---|
7 | #include <QLocale>
|
---|
8 | #include <QTextCursor>
|
---|
9 | #include <qmetatype.h>
|
---|
10 | #include <tclap/CmdLine.h>
|
---|
11 | #include <execinfo.h>
|
---|
12 | #include <signal.h>
|
---|
13 |
|
---|
14 | #include "Manager.h"
|
---|
15 | #include "unexported/compile_info.h"
|
---|
16 |
|
---|
17 | using namespace TCLAP;
|
---|
18 | using namespace std;
|
---|
19 |
|
---|
20 | string name;
|
---|
21 | int port;
|
---|
22 |
|
---|
23 | void parseOptions(int argc, char **argv) {
|
---|
24 | try {
|
---|
25 | CmdLine cmd("Command description message", ' ', "0.1");
|
---|
26 |
|
---|
27 | ValueArg<string> nameArg("n", "name", "uav name", false, "x4-0", "string");
|
---|
28 | cmd.add(nameArg);
|
---|
29 |
|
---|
30 | ValueArg<int> portArg("p", "port", "port number", false, 9000, "int");
|
---|
31 | cmd.add(portArg);
|
---|
32 |
|
---|
33 | cmd.parse(argc, argv);
|
---|
34 |
|
---|
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 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | void seg_fault(int sig __attribute__((unused))) {
|
---|
45 | void *bt[32];
|
---|
46 | int nentries;
|
---|
47 |
|
---|
48 | printf("Segmentation fault:\n");
|
---|
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 |
|
---|
56 | int main(int argc, char *argv[]) {
|
---|
57 |
|
---|
58 | union {
|
---|
59 | uint32_t i;
|
---|
60 | char c[4];
|
---|
61 | } bint = {0x01020304};
|
---|
62 |
|
---|
63 | if (bint.c[0] == 1) {
|
---|
64 | printf("error, ground station is only compatible with little endian\n");
|
---|
65 | return -1;
|
---|
66 | }
|
---|
67 |
|
---|
68 | compile_info("FlairGCS");
|
---|
69 |
|
---|
70 | // catch segfault
|
---|
71 | signal(SIGSEGV, seg_fault);
|
---|
72 |
|
---|
73 | parseOptions(argc, argv);
|
---|
74 | printf("listening on port %i\n", port);
|
---|
75 |
|
---|
76 | qRegisterMetaType<const char *>("const char*");
|
---|
77 | qRegisterMetaType<UDTSOCKET>("UDTSOCKET");
|
---|
78 | qRegisterMetaType<QTextCursor>("QTextCursor");
|
---|
79 | QLocale::setDefault(QLocale::C);
|
---|
80 | QApplication app(argc, argv);
|
---|
81 | app.setStyle(new QCleanlooksStyle);
|
---|
82 |
|
---|
83 | Manager manager(QString::fromStdString(name), port);
|
---|
84 |
|
---|
85 | manager.show();
|
---|
86 |
|
---|
87 | app.exec();
|
---|
88 | }
|
---|