[11] | 1 | // %flair:license{
|
---|
[16] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[11] | 4 | // %flair:license}
|
---|
| 5 | // created: 2011/10/20
|
---|
| 6 | // filename: main.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 6599
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: main dual shock 3
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #include "FrameworkManager.h"
|
---|
| 19 | #include "DualShock3.h"
|
---|
| 20 | #include <stdio.h>
|
---|
| 21 | #include <tclap/CmdLine.h>
|
---|
| 22 |
|
---|
| 23 | using namespace TCLAP;
|
---|
| 24 | using namespace std;
|
---|
| 25 | using namespace flair::core;
|
---|
| 26 | using namespace flair::sensor;
|
---|
| 27 |
|
---|
| 28 | string receiverAddress;
|
---|
| 29 | int receiverPort;
|
---|
| 30 | string connection;
|
---|
| 31 | int port;
|
---|
| 32 | uint32_t period;
|
---|
| 33 | string xml_file;
|
---|
| 34 |
|
---|
[16] | 35 | void parseOptions(int argc, char **argv);
|
---|
[11] | 36 |
|
---|
[16] | 37 | int main(int argc, char *argv[]) {
|
---|
| 38 | parseOptions(argc, argv);
|
---|
[11] | 39 |
|
---|
[16] | 40 | DualShock3 *joystick;
|
---|
| 41 | FrameworkManager *manager;
|
---|
[11] | 42 |
|
---|
[16] | 43 | manager = new FrameworkManager("dualshock3");
|
---|
| 44 | manager->SetupConnection("127.0.0.1", port);
|
---|
| 45 | manager->SetupUserInterface(xml_file);
|
---|
[11] | 46 |
|
---|
[16] | 47 | if (connection == "usb") {
|
---|
| 48 | // manager->Warn("!! adresse = %s !!\n", address.c_str());
|
---|
[137] | 49 | joystick = new DualShock3("dualshock3", receiverAddress,
|
---|
[16] | 50 | receiverPort, DualShock3::Usb, period, 6);
|
---|
| 51 | } else {
|
---|
[137] | 52 | joystick = new DualShock3("dualshock3", receiverAddress,
|
---|
[16] | 53 | receiverPort, DualShock3::Bluetooth, period, 6);
|
---|
| 54 | }
|
---|
[11] | 55 |
|
---|
[16] | 56 | joystick->DrawUserInterface();
|
---|
[11] | 57 |
|
---|
[16] | 58 | if (!manager->ErrorOccured()) {
|
---|
| 59 | joystick->Start();
|
---|
| 60 | joystick->Join();
|
---|
| 61 | }
|
---|
[11] | 62 |
|
---|
[16] | 63 | delete manager;
|
---|
[11] | 64 | }
|
---|
| 65 |
|
---|
[16] | 66 | void parseOptions(int argc, char **argv) {
|
---|
| 67 | try {
|
---|
| 68 | CmdLine cmd("Command description message", ' ', "0.1");
|
---|
[11] | 69 |
|
---|
[16] | 70 | ValueArg<string> addressArg("a", "address",
|
---|
| 71 | "data receiver address (ex: uav)", true,
|
---|
| 72 | "127.0.0.1:20000", "string");
|
---|
| 73 | cmd.add(addressArg);
|
---|
[11] | 74 |
|
---|
[16] | 75 | ValueArg<string> connectionArg("c", "connection",
|
---|
| 76 | "connection type (usb or bluetooth)", false,
|
---|
| 77 | "bluetooth", "string");
|
---|
| 78 | cmd.add(connectionArg);
|
---|
[11] | 79 |
|
---|
[16] | 80 | ValueArg<int> portArg("p", "port",
|
---|
| 81 | "local port used to connect to the ground station",
|
---|
| 82 | false, 9000, "int");
|
---|
| 83 | cmd.add(portArg);
|
---|
[11] | 84 |
|
---|
[16] | 85 | ValueArg<int> periodArg("t", "period", "sending data period", false, 10,
|
---|
| 86 | "int");
|
---|
| 87 | cmd.add(periodArg);
|
---|
[11] | 88 |
|
---|
[16] | 89 | ValueArg<string> xmlArg("x", "xml", "xml file", true, "./settings.xml",
|
---|
| 90 | "string");
|
---|
| 91 | cmd.add(xmlArg);
|
---|
[11] | 92 |
|
---|
[16] | 93 | cmd.parse(argc, argv);
|
---|
[11] | 94 |
|
---|
[16] | 95 | // Get the value parsed by each arg.
|
---|
| 96 | string receiverAddressWithPort = addressArg.getValue();
|
---|
| 97 | int semiColonPosition = receiverAddressWithPort.find(":");
|
---|
| 98 | receiverAddress = receiverAddressWithPort.substr(0, semiColonPosition);
|
---|
| 99 | receiverPort =
|
---|
| 100 | atoi(receiverAddressWithPort.substr(semiColonPosition + 1).c_str());
|
---|
| 101 | connection = connectionArg.getValue();
|
---|
| 102 | port = portArg.getValue();
|
---|
| 103 | period = periodArg.getValue();
|
---|
| 104 | xml_file = xmlArg.getValue();
|
---|
[11] | 105 |
|
---|
[16] | 106 | } catch (ArgException &e) { // catch any exceptions
|
---|
| 107 | cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
|
---|
| 108 | }
|
---|
[11] | 109 | }
|
---|