source: xplra/test/multisettest.cc@ 112:58892a32a039

Last change on this file since 112:58892a32a039 was 112:58892a32a039, checked in by István Váradi <ivaradi@…>, 17 months ago

The test programs can be parameterized to connect over TCP

File size: 4.5 KB
Line 
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 "common.h"
37
38#include <cstdio>
39#include <cstring>
40
41//------------------------------------------------------------------------------
42
43using hu::varadiistvan::xplra::XPlane;
44using hu::varadiistvan::xplra::MultiSetter;
45using hu::varadiistvan::xplra::Exception;
46
47using hu::varadiistvan::scpl::Thread;
48
49//------------------------------------------------------------------------------
50
51int main(int argc, char* argv[])
52{
53 bool dontregister = false;
54 for(int i = 1; i<argc; ++i) {
55 if (strcmp(argv[i], "dontregister")==0) {
56 dontregister = true;
57 }
58 }
59
60 try {
61 XPlane xplane;
62
63 printf("Connecting to X-Plane...\n");
64 connectXPlane(xplane, argc, argv);
65 printf("Connected to X-Plane.\n\n");
66
67 MultiSetter& setter = xplane.createMultiSetter();
68
69 try {
70 const size_t simSpeedID = setter.addInt("sim/time/sim_speed");
71 const size_t zuluSecID = setter.addFloat("sim/time/zulu_time_sec");
72 const size_t localXID = setter.addDouble("sim/flightmodel/position/local_x");
73 const size_t tailNumID = setter.addByteArray("sim/aircraft/view/acf_tailnum", 40);
74 const size_t generatorOnID = setter.addIntArray("sim/cockpit/electrical/generator_on", 8);
75 const size_t propPitchID = setter.addFloatArray("sim/cockpit2/engine/actuators/prop_pitch_deg", 2);
76
77 if (dontregister) {
78 setter.finalize();
79 } else {
80 printf("Registering getter...\n");
81 setter.registerInXPlane();
82 printf("Registered getter.\n\n");
83 }
84
85 printf("Setting values...\n");
86
87 setter.setInt(simSpeedID, 0);
88 setter.setFloat(zuluSecID, 7265.0);
89 setter.setDouble(localXID, 12.0);
90 setter.setString(tailNumID, "Kukutyin");
91 int32_t generatorOn[8] = { 1, 0, 1, 0, 1, 0, 1, 0 };
92 setter.setIntArray(generatorOnID, generatorOn, 8);
93 float propPitch[2] = { 32.4, 78.2 };
94 setter.setFloatArray(propPitchID, propPitch, 2);
95
96 printf("Executing...\n");
97
98 setter.execute();
99
100 printf("Done.\n");
101
102 //xplane.destroyMultiBuffer(setter);
103
104 return 0;
105 } catch(Exception& exception) {
106 printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what());
107
108 return 1;
109 }
110 } catch(Exception& exception) {
111 printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what());
112
113 return 1;
114 }
115}
116
117//------------------------------------------------------------------------------
118
119// Local Variables:
120// mode: C++
121// c-basic-offset: 4
122// indent-tabs-mode: nil
123// End:
Note: See TracBrowser for help on using the repository browser.