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