Changeset 25:77da156bca86 in xplra for test
- Timestamp:
- 02/07/13 16:45:59 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
test/basicctest.c
r24 r25 32 32 33 33 #include <stdio.h> 34 #include <string.h> 34 35 35 36 //------------------------------------------------------------------------------ … … 37 38 int main() 38 39 { 40 static const char* tailNum1 = "VAI"; 41 39 42 int retval = 0; 40 43 const char* errorString = 0; … … 50 53 float result5[8]; 51 54 float* result6 = 0; 55 float acfElevUp; 56 double localX; 57 float numBlades[8]; 58 int32_t batteryArrayOn[8]; 59 uint8_t tailNum[40]; 52 60 53 61 printf("Connection to X-Plane...\n"); … … 167 175 printf("\n\n"); 168 176 177 printf("Setting the number of the engines to %d...\n", numEngines + 1); 178 if (xplra_set_int(connectionID, "sim/aircraft/engine/acf_num_engines", 179 numEngines + 1)<0) 180 { 181 goto error; 182 } 183 if (xplra_get_int(&numEngines, connectionID, 184 "sim/aircraft/engine/acf_num_engines")<0) 185 { 186 goto error; 187 } 188 printf("The new number of engines: %d\n\n", numEngines); 189 190 191 if (xplra_get_float(&acfElevUp, connectionID, 192 "sim/aircraft/controls/acf_elev_up")<0) 193 { 194 goto error; 195 } 196 printf("Setting the aircraft elevator up control from %f to %f...\n", 197 acfElevUp, acfElevUp + 15.0); 198 if (xplra_set_float(connectionID, 199 "sim/aircraft/controls/acf_elev_up", 200 acfElevUp + 15.0) < 0) 201 { 202 goto error; 203 } 204 if (xplra_get_float(&acfElevUp, connectionID, 205 "sim/aircraft/controls/acf_elev_up")<0) 206 { 207 goto error; 208 } 209 printf("The aircraft elevator up control set to %f\n\n", acfElevUp); 210 211 if (xplra_get_double(&localX, connectionID, 212 "sim/flightmodel/position/local_x")<0) 213 { 214 goto error; 215 } 216 printf("Setting the aircraft's local X-coordinate from %f to %f...\n", 217 localX, localX + 15.0); 218 if (xplra_set_double(connectionID, "sim/flightmodel/position/local_x", 219 localX + 15.0)<0) 220 { 221 goto error; 222 } 223 if (xplra_get_double(&localX, connectionID, 224 "sim/flightmodel/position/local_x")<0) 225 { 226 goto error; 227 } 228 printf("The aircraft's local X-coordinate set to %f\n\n", localX); 229 230 length = xplra_get_float_array(numBlades, 231 sizeof(numBlades)/sizeof(numBlades[0]), 0, 232 connectionID, 233 "sim/aircraft/prop/acf_num_blades"); 234 if (length<0) goto error; 235 236 printf("Setting the number of blades\n from:"); 237 for(i = 0; i<length; ++i) { 238 if (i>0) printf(","); 239 printf(" %f", numBlades[i]); 240 } 241 printf("\n to:"); 242 for(i = 0; i<length; ++i) { 243 numBlades[i] += 2.5; 244 if (i>0) printf(","); 245 printf(" %f", numBlades[i]); 246 } 247 printf("\n"); 248 if (xplra_set_float_array(connectionID, 249 "sim/aircraft/prop/acf_num_blades", 250 numBlades, length, 0)<0) 251 { 252 goto error; 253 } 254 length = xplra_get_float_array(numBlades, 255 sizeof(numBlades)/sizeof(numBlades[0]), 0, 256 connectionID, 257 "sim/aircraft/prop/acf_num_blades"); 258 if (length<0) goto error; 259 printf("The result:"); 260 for(i = 0; i<length; ++i) { 261 if (i>0) printf(","); 262 printf(" %f", numBlades[i]); 263 } 264 printf("\n\n"); 265 266 length = xplra_get_int_array(batteryArrayOn, 267 sizeof(batteryArrayOn)/sizeof(batteryArrayOn[0]), 268 0, connectionID, 269 "sim/cockpit/electrical/battery_array_on"); 270 if (length<0) goto error; 271 printf("Setting the batteries\n from:"); 272 for(i = 0; i<length; ++i) { 273 if (i>0) printf(","); 274 printf(" %d", batteryArrayOn[i]); 275 } 276 printf("\n to:"); 277 for(i = 0; i<length; ++i) { 278 batteryArrayOn[i] = !batteryArrayOn[i]; 279 numBlades[i] += 2.5; 280 if (i>0) printf(","); 281 printf(" %d", batteryArrayOn[i]); 282 } 283 printf("\n"); 284 if (xplra_set_int_array(connectionID, 285 "sim/cockpit/electrical/battery_array_on", 286 batteryArrayOn, length, 0)<0) 287 { 288 goto error; 289 } 290 length = xplra_get_int_array(batteryArrayOn, 291 sizeof(batteryArrayOn)/sizeof(batteryArrayOn[0]), 292 0, connectionID, 293 "sim/cockpit/electrical/battery_array_on"); 294 if (length<0) goto error; 295 printf("The result:"); 296 for(i = 0; i<length; ++i) { 297 if (i>0) printf(","); 298 printf(" %d", batteryArrayOn[i]); 299 } 300 printf("\n\n"); 301 302 memset(tailNum, 0, sizeof(tailNum)); 303 strcpy((char*)tailNum, "HA-VAI"); 304 printf("Setting the tail number to %s as a byte array...\n", tailNum); 305 if (xplra_set_byte_array(connectionID, 306 "sim/aircraft/view/acf_tailnum", 307 tailNum, sizeof(tailNum), 0)<0) 308 { 309 goto error; 310 } 311 312 memset(tailNum, 0, sizeof(tailNum)); 313 length = xplra_get_byte_array(tailNum, sizeof(tailNum), 0, 314 connectionID, 315 "sim/aircraft/view/acf_tailnum"); 316 if (length<0) goto error; 317 printf("The tail number is: '%s'\n\n", (char*)tailNum); 318 319 printf("Setting the tail number to %s as a string...\n", tailNum1); 320 if (xplra_set_string(connectionID, "sim/aircraft/view/acf_tailnum", 321 tailNum1, 40, 0)<0) 322 { 323 goto error; 324 } 325 memset(tailNum, 0, sizeof(tailNum)); 326 length = xplra_get_byte_array(tailNum, sizeof(tailNum), 0, 327 connectionID, 328 "sim/aircraft/view/acf_tailnum"); 329 if (length<0) goto error; 330 printf("The tail number is: '%s'\n\n", (char*)tailNum); 331 169 332 goto cleanup; 170 333 error: … … 180 343 if (connectionID>=0) xplra_disconnect(connectionID); 181 344 return retval; 182 183 // try {184 185 186 // printf("Setting the number of the engines to %d...\n", numEngines + 1);187 // xplane.setInt("sim/aircraft/engine/acf_num_engines", numEngines + 1);188 // numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines");189 // printf("The new number of engines: %d\n\n", numEngines);190 191 // float acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up");192 // printf("Setting the aircraft elevator up control from %f to %f...\n",193 // acfElevUp, acfElevUp + 15.0);194 // xplane.setFloat("sim/aircraft/controls/acf_elev_up", acfElevUp);195 // acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up");196 // printf("The aircraft elevator up control set to %f\n\n", acfElevUp);197 198 // double localX = xplane.getDouble("sim/flightmodel/position/local_x");199 // printf("Setting the aircraft's local X-coordinate from %f to %f...\n",200 // localX, localX + 15.0);201 // xplane.setDouble("sim/flightmodel/position/local_x", localX + 15.0);202 // localX = xplane.getDouble("sim/flightmodel/position/local_x");203 // printf("The aircraft's local X-coordinate set to %f\n\n", localX);204 205 // float numBlades[8];206 // length = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades",207 // numBlades, sizeof(numBlades)/sizeof(numBlades[0]));208 209 // printf("Setting the number of blades\n from:");210 // for(size_t i = 0; i<length; ++i) {211 // if (i>0) printf(",");212 // printf(" %f", numBlades[i]);213 // }214 // printf("\n to:");215 // for(size_t i = 0; i<length; ++i) {216 // numBlades[i] += 2.5;217 // if (i>0) printf(",");218 // printf(" %f", numBlades[i]);219 // }220 // printf("\n");221 // xplane.setFloatArray("sim/aircraft/prop/acf_num_blades",222 // numBlades, length);223 // length = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades",224 // numBlades, sizeof(numBlades)/sizeof(numBlades[0]));225 // printf("The result:");226 // for(size_t i = 0; i<length; ++i) {227 // if (i>0) printf(",");228 // printf(" %f", numBlades[i]);229 // }230 // printf("\n\n");231 232 // int32_t batteryArrayOn[8];233 // length = xplane.getIntArray("sim/cockpit/electrical/battery_array_on",234 // batteryArrayOn,235 // sizeof(batteryArrayOn)/sizeof(batteryArrayOn[0]));236 237 // printf("Setting the batteries\n from:");238 // for(size_t i = 0; i<length; ++i) {239 // if (i>0) printf(",");240 // printf(" %d", batteryArrayOn[i]);241 // }242 // printf("\n to:");243 // for(size_t i = 0; i<length; ++i) {244 // batteryArrayOn[i] = !batteryArrayOn[i];245 // numBlades[i] += 2.5;246 // if (i>0) printf(",");247 // printf(" %d", batteryArrayOn[i]);248 // }249 // printf("\n");250 // xplane.setIntArray("sim/cockpit/electrical/battery_array_on",251 // batteryArrayOn, length);252 // length = xplane.getIntArray("sim/cockpit/electrical/battery_array_on",253 // batteryArrayOn,254 // sizeof(batteryArrayOn)/sizeof(batteryArrayOn[0]));255 // printf("The result:");256 // for(size_t i = 0; i<length; ++i) {257 // if (i>0) printf(",");258 // printf(" %d", batteryArrayOn[i]);259 // }260 // printf("\n\n");261 262 // uint8_t tailNum[40];263 // memset(tailNum, 0, sizeof(tailNum));264 // strcpy(reinterpret_cast<char*>(tailNum), "HA-VAI");265 // printf("Setting the tail number to %s as a byte array...\n", tailNum);266 // xplane.setByteArray("sim/aircraft/view/acf_tailnum",267 // tailNum, sizeof(tailNum));268 // printf("The tail number is: '%s'\n\n",269 // xplane.getString("sim/aircraft/view/acf_tailnum").c_str());270 271 // static const char* tailNum1 = "VAI";272 // printf("Setting the tail number to %s as a string...\n", tailNum1);273 // xplane.setString("sim/aircraft/view/acf_tailnum", tailNum1, 40);274 // printf("The tail number is: '%s'\n\n",275 // xplane.getString("sim/aircraft/view/acf_tailnum").c_str());276 277 // try {278 // printf("Querying an invalid dataref...\n");279 // xplane.getInt("sim/aircraft/engine/num_engines");280 // printf("\n>>>>>>>>>>>> Succeeded!!!!!!!!!!!!!!!!!!!!!!\n\n");281 // } catch(const ProtocolException& exception) {282 // printf("Exception caugth: %s\n\n", exception.what());283 // }284 285 286 // return 0;287 // } catch(const Exception& exception) {288 // printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what());289 290 // return 1;291 // }292 345 } 293 346 -
test/basictest.cc
r18 r25 142 142 printf("Setting the aircraft elevator up control from %f to %f...\n", 143 143 acfElevUp, acfElevUp + 15.0); 144 xplane.setFloat("sim/aircraft/controls/acf_elev_up", acfElevUp );144 xplane.setFloat("sim/aircraft/controls/acf_elev_up", acfElevUp + 15.0); 145 145 acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up"); 146 146 printf("The aircraft elevator up control set to %f\n\n", acfElevUp);
Note:
See TracChangeset
for help on using the changeset viewer.