source: xplra/test/multisetctest.c@ 86:f7714df5165f

Last change on this file since 86:f7714df5165f was 30:d92d686b4d70, checked in by István Váradi <ivaradi@…>, 12 years ago

Fixed problems with detecting a broken connection

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