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: 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 |
|
---|
35 | void parseOptions(int argc, char** argv);
|
---|
36 |
|
---|
37 | int main(int argc, char* argv[]) {
|
---|
38 | parseOptions(argc,argv);
|
---|
39 |
|
---|
40 | DualShock3 *joystick;
|
---|
41 | FrameworkManager *manager;
|
---|
42 |
|
---|
43 | manager= new FrameworkManager("dualshock3");
|
---|
44 | manager->SetupConnection("127.0.0.1",port);
|
---|
45 | manager->SetupUserInterface(xml_file);
|
---|
46 |
|
---|
47 | if(connection=="usb") {
|
---|
48 | // manager->Warn("!! adresse = %s !!\n", address.c_str());
|
---|
49 | joystick=new DualShock3(manager,"dualshock3",receiverAddress,receiverPort,DualShock3::Usb,period,6);
|
---|
50 | } else {
|
---|
51 | joystick=new DualShock3(manager,"dualshock3",receiverAddress,receiverPort,DualShock3::Bluetooth,period,6);
|
---|
52 | }
|
---|
53 |
|
---|
54 | joystick->DrawUserInterface();
|
---|
55 |
|
---|
56 | if(!manager->ErrorOccured()) {
|
---|
57 | joystick->Start();
|
---|
58 | joystick->Join();
|
---|
59 | }
|
---|
60 |
|
---|
61 | delete manager;
|
---|
62 | }
|
---|
63 |
|
---|
64 | void parseOptions(int argc, char** argv) {
|
---|
65 | try {
|
---|
66 | CmdLine cmd("Command description message", ' ', "0.1");
|
---|
67 |
|
---|
68 | ValueArg<string> addressArg("a","address","data receiver address (ex: uav)",true,"127.0.0.1:20000","string");
|
---|
69 | cmd.add(addressArg);
|
---|
70 |
|
---|
71 | ValueArg<string> connectionArg("c","connection","connection type (usb or bluetooth)",false,"bluetooth","string");
|
---|
72 | cmd.add(connectionArg);
|
---|
73 |
|
---|
74 | ValueArg<int> portArg("p","port","local port used to connect to the ground station",false,9000,"int");
|
---|
75 | cmd.add(portArg);
|
---|
76 |
|
---|
77 | ValueArg<int> periodArg("t","period","sending data period",false,10,"int");
|
---|
78 | cmd.add(periodArg);
|
---|
79 |
|
---|
80 | ValueArg<string> xmlArg("x","xml","xml file",true,"./settings.xml","string");
|
---|
81 | cmd.add( xmlArg );
|
---|
82 |
|
---|
83 | cmd.parse(argc, argv);
|
---|
84 |
|
---|
85 | // Get the value parsed by each arg.
|
---|
86 | string receiverAddressWithPort=addressArg.getValue();
|
---|
87 | int semiColonPosition = receiverAddressWithPort.find(":");
|
---|
88 | receiverAddress=receiverAddressWithPort.substr (0,semiColonPosition);
|
---|
89 | receiverPort=atoi(receiverAddressWithPort.substr(semiColonPosition+1).c_str());
|
---|
90 | connection=connectionArg.getValue();
|
---|
91 | port=portArg.getValue();
|
---|
92 | period=periodArg.getValue();
|
---|
93 | xml_file=xmlArg.getValue();
|
---|
94 |
|
---|
95 | } catch (ArgException &e) { // catch any exceptions
|
---|
96 | cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
|
---|
97 | }
|
---|
98 | }
|
---|