source: xplra/test/multisetctest.c@ 113:14139defbd04

Last change on this file since 113:14139defbd04 was 112:58892a32a039, checked in by István Váradi <ivaradi@…>, 2 years ago

The test programs can be parameterized to connect over TCP

File size: 4.6 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/xplra.h>
32
33#include "ccommon.h"
34
35#include <stdlib.h>
36#include <stdio.h>
37#include <string.h>
38
39//------------------------------------------------------------------------------
40
41int main(int argc, char* argv[])
42{
43 int retval = 0;
44 const char* errorString;
45
46 int i;
47
48 int connectionID = -1;
49 int setterID = -1;
50
51 size_t simSpeedID = INVALID_DATAREF_ID;
52 size_t zuluSecID = INVALID_DATAREF_ID;
53 size_t localXID = INVALID_DATAREF_ID;
54 size_t tailNumID = INVALID_DATAREF_ID;
55 size_t generatorOnID = INVALID_DATAREF_ID;
56 size_t propPitchID = INVALID_DATAREF_ID;
57
58 int32_t generatorOn[8] = { 1, 0, 1, 0, 1, 0, 1, 0 };
59 float propPitch[2] = { 32.4, 78.2 };
60
61 int dontregister = 0;
62
63 for(i = 1; i<argc; ++i) {
64 if (strcmp(argv[i], "dontregister")==0) {
65 dontregister = 1;
66 }
67 }
68
69 printf("Connecting to X-Plane...\n");
70 connectionID = connect_xplane(argc, argv);
71 if (connectionID>=0) {
72 printf("Connected to X-Plane.\n\n");
73 } else {
74 printf("Connection failed.\n\n");
75 goto cleanup;
76 }
77
78 setterID = xplra_multi_create_setter(connectionID);
79 if (setterID<0) goto error;
80
81 simSpeedID = xplra_multi_add_int(setterID, "sim/time/sim_speed");
82 zuluSecID = xplra_multi_add_float(setterID, "sim/time/zulu_time_sec");
83 localXID = xplra_multi_add_double(setterID, "sim/flightmodel/position/local_x");
84 tailNumID = xplra_multi_add_byte_array(setterID, "sim/aircraft/view/acf_tailnum", 40, 0);
85 generatorOnID = xplra_multi_add_int_array(setterID, "sim/cockpit/electrical/generator_on", 8, 0);
86 propPitchID = xplra_multi_add_float_array(setterID, "sim/cockpit2/engine/actuators/prop_pitch_deg", 2, 0);
87
88 if (dontregister) {
89 xplra_multi_finalize(setterID);
90 } else {
91 printf("Registering getter...\n");
92 if (xplra_multi_register(setterID)<0) goto error;
93 printf("Registered getter.\n\n");
94 }
95
96 printf("Setting values...\n");
97
98 xplra_multi_set_int(setterID, simSpeedID, 0);
99 xplra_multi_set_float(setterID, zuluSecID, 7265.0);
100 xplra_multi_set_double(setterID, localXID, 12.0);
101 xplra_multi_set_string(setterID, tailNumID, "Kukutyin", 0);
102 xplra_multi_set_int_array(setterID, generatorOnID, generatorOn, 8, 0);
103 xplra_multi_set_float_array(setterID, propPitchID, propPitch, 2, 0);
104
105 printf("Executing...\n");
106
107 if (xplra_multi_execute(setterID)<0) goto error;
108
109 printf("Done.\n");
110
111 goto cleanup;
112
113error:
114 errorString = xplra_get_last_error_string(connectionID);
115 if (errorString==0) {
116 printf("\nUnknown error occured!\n");
117 } else {
118 printf("\nError: %s\n", errorString);
119 }
120
121 retval = 1;
122
123cleanup:
124 if (connectionID>=0) xplra_disconnect(connectionID);
125 return retval;
126}
127
128//------------------------------------------------------------------------------
129
130// Local Variables:
131// mode: C++
132// c-basic-offset: 4
133// indent-tabs-mode: nil
134// End:
Note: See TracBrowser for help on using the repository browser.