1 | // Copyright (c) 2013 by István Váradi
|
---|
2 |
|
---|
3 | // This file is part of XPLRA, a remote-access plugin for X-Plane
|
---|
4 |
|
---|
5 | // Redistribution and use in source and binary forms, with or without
|
---|
6 | // modification, are permitted provided that the following conditions are met:
|
---|
7 |
|
---|
8 | // 1. Redistributions of source code must retain the above copyright notice, this
|
---|
9 | // list of conditions and the following disclaimer.
|
---|
10 | // 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
11 | // this list of conditions and the following disclaimer in the documentation
|
---|
12 | // and/or other materials provided with the distribution.
|
---|
13 |
|
---|
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
15 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
---|
18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
24 |
|
---|
25 | // The views and conclusions contained in the software and documentation are those
|
---|
26 | // of the authors and should not be interpreted as representing official policies,
|
---|
27 | // either expressed or implied, of the FreeBSD Project.
|
---|
28 |
|
---|
29 | //------------------------------------------------------------------------------
|
---|
30 |
|
---|
31 | #include <hu/varadiistvan/xplra/XPlane.h>
|
---|
32 | #include <hu/varadiistvan/xplra/MultiSetter.h>
|
---|
33 |
|
---|
34 | #include <hu/varadiistvan/scpl/Thread.h>
|
---|
35 |
|
---|
36 | #include <cstdio>
|
---|
37 | #include <cstring>
|
---|
38 |
|
---|
39 | //------------------------------------------------------------------------------
|
---|
40 |
|
---|
41 | using hu::varadiistvan::xplra::XPlane;
|
---|
42 | using hu::varadiistvan::xplra::MultiSetter;
|
---|
43 | using hu::varadiistvan::xplra::Exception;
|
---|
44 |
|
---|
45 | using hu::varadiistvan::scpl::Thread;
|
---|
46 |
|
---|
47 | //------------------------------------------------------------------------------
|
---|
48 |
|
---|
49 | int main(int argc, char* argv[])
|
---|
50 | {
|
---|
51 | bool dontregister = false;
|
---|
52 | for(int i = 1; i<argc; ++i) {
|
---|
53 | if (strcmp(argv[i], "dontregister")==0) {
|
---|
54 | dontregister = true;
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | try {
|
---|
59 | XPlane xplane;
|
---|
60 |
|
---|
61 | printf("Connecting to X-Plane...\n");
|
---|
62 | xplane.connect();
|
---|
63 | printf("Connected to X-Plane.\n\n");
|
---|
64 |
|
---|
65 | MultiSetter& setter = xplane.createMultiSetter();
|
---|
66 |
|
---|
67 | try {
|
---|
68 | const size_t simSpeedID = setter.addInt("sim/time/sim_speed");
|
---|
69 | const size_t zuluSecID = setter.addFloat("sim/time/zulu_time_sec");
|
---|
70 | const size_t localXID = setter.addDouble("sim/flightmodel/position/local_x");
|
---|
71 | const size_t tailNumID = setter.addByteArray("sim/aircraft/view/acf_tailnum", 40);
|
---|
72 | const size_t generatorOnID = setter.addIntArray("sim/cockpit/electrical/generator_on", 8);
|
---|
73 | const size_t propPitchID = setter.addFloatArray("sim/cockpit2/engine/actuators/prop_pitch_deg", 2);
|
---|
74 |
|
---|
75 | if (dontregister) {
|
---|
76 | setter.finalize();
|
---|
77 | } else {
|
---|
78 | printf("Registering getter...\n");
|
---|
79 | setter.registerInXPlane();
|
---|
80 | printf("Registered getter.\n\n");
|
---|
81 | }
|
---|
82 |
|
---|
83 | printf("Setting values...\n");
|
---|
84 |
|
---|
85 | setter.setInt(simSpeedID, 0);
|
---|
86 | setter.setFloat(zuluSecID, 7265.0);
|
---|
87 | setter.setDouble(localXID, 12.0);
|
---|
88 | setter.setString(tailNumID, "Kukutyin");
|
---|
89 | int32_t generatorOn[8] = { 1, 0, 1, 0, 1, 0, 1, 0 };
|
---|
90 | setter.setIntArray(generatorOnID, generatorOn, 8);
|
---|
91 | float propPitch[2] = { 32.4, 78.2 };
|
---|
92 | setter.setFloatArray(propPitchID, propPitch, 2);
|
---|
93 |
|
---|
94 | printf("Executing...\n");
|
---|
95 |
|
---|
96 | setter.execute();
|
---|
97 |
|
---|
98 | printf("Done.\n");
|
---|
99 |
|
---|
100 | //xplane.destroyMultiBuffer(setter);
|
---|
101 |
|
---|
102 | return 0;
|
---|
103 | } catch(Exception& exception) {
|
---|
104 | printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what());
|
---|
105 |
|
---|
106 | return 1;
|
---|
107 | }
|
---|
108 | } catch(Exception& exception) {
|
---|
109 | printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what());
|
---|
110 |
|
---|
111 | return 1;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | //------------------------------------------------------------------------------
|
---|
116 |
|
---|
117 | // Local Variables:
|
---|
118 | // mode: C++
|
---|
119 | // c-basic-offset: 4
|
---|
120 | // indent-tabs-mode: nil
|
---|
121 | // End:
|
---|