Changeset 25:77da156bca86 in xplra
- Timestamp:
- 02/07/13 16:45:59 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/client/c/hu/varadiistvan/xplra/xplra.cc
r24 r25 505 505 //------------------------------------------------------------------------------ 506 506 507 extern "C" int xplra_set_int(int connectionID, const char* name, int value) 508 { 509 Connection* connection = Slot::getConnection(connectionID); 510 if (connection==0) return 0; 511 try { 512 connection->setInt(name, value); 513 return 0; 514 } catch (...) { 515 connection->handleException(); 516 return -1; 517 } 518 } 519 520 //------------------------------------------------------------------------------ 521 522 extern "C" int xplra_set_float(int connectionID, const char* name, float value) 523 { 524 Connection* connection = Slot::getConnection(connectionID); 525 if (connection==0) return 0; 526 try { 527 connection->setFloat(name, value); 528 return 0; 529 } catch (...) { 530 connection->handleException(); 531 return -1; 532 } 533 } 534 535 //------------------------------------------------------------------------------ 536 537 extern "C" int xplra_set_double(int connectionID, const char* name, 538 double value) 539 { 540 Connection* connection = Slot::getConnection(connectionID); 541 if (connection==0) return 0; 542 try { 543 connection->setDouble(name, value); 544 return 0; 545 } catch (...) { 546 connection->handleException(); 547 return -1; 548 } 549 } 550 551 /*----------------------------------------------------------------------------*/ 552 553 extern "C" int xplra_set_float_array(int connectionID, const char* name, 554 const float* values, 555 size_t length, size_t offset) 556 { 557 Connection* connection = Slot::getConnection(connectionID); 558 if (connection==0) return 0; 559 try { 560 connection->setFloatArray(name, values, length, offset); 561 return 0; 562 } catch (...) { 563 connection->handleException(); 564 return -1; 565 } 566 } 567 568 /*----------------------------------------------------------------------------*/ 569 570 extern "C" int xplra_set_int_array(int connectionID, const char* name, 571 const int32_t* values, 572 size_t length, size_t offset) 573 { 574 Connection* connection = Slot::getConnection(connectionID); 575 if (connection==0) return 0; 576 try { 577 connection->setIntArray(name, values, length, offset); 578 return 0; 579 } catch (...) { 580 connection->handleException(); 581 return -1; 582 } 583 } 584 585 /*----------------------------------------------------------------------------*/ 586 587 extern "C" int xplra_set_byte_array(int connectionID, const char* name, 588 const void* values, 589 size_t length, size_t offset) 590 { 591 Connection* connection = Slot::getConnection(connectionID); 592 if (connection==0) return 0; 593 try { 594 connection->setByteArray(name, reinterpret_cast<const uint8_t*>(values), 595 length, offset); 596 return 0; 597 } catch (...) { 598 connection->handleException(); 599 return -1; 600 } 601 } 602 603 /*----------------------------------------------------------------------------*/ 604 605 extern "C" int xplra_set_string(int connectionID, const char* name, 606 const char* value, 607 size_t length, size_t offset) 608 { 609 Connection* connection = Slot::getConnection(connectionID); 610 if (connection==0) return 0; 611 try { 612 connection->setString(name, value, length, offset); 613 return 0; 614 } catch (...) { 615 connection->handleException(); 616 return -1; 617 } 618 } 619 620 //------------------------------------------------------------------------------ 621 507 622 extern "C" int xplra_disconnect(int connectionID) 508 623 { -
src/client/c/hu/varadiistvan/xplra/xplra.h
r24 r25 245 245 246 246 /** 247 * Set the integer dataref with the given name to the given value. 248 * 249 * @return 0 on success, -1 on error. 250 */ 251 int xplra_set_int(int connectionID, const char* name, int value); 252 253 /*----------------------------------------------------------------------------*/ 254 255 /** 256 * Set the float dataref with the given name to the given value. 257 * 258 * @return 0 on success, -1 on error. 259 */ 260 int xplra_set_float(int connectionID, const char* name, float value); 261 262 /*----------------------------------------------------------------------------*/ 263 264 /** 265 * Set the double dataref with the given name to the given value. 266 * 267 * @return 0 on success, -1 on error. 268 */ 269 int xplra_set_double(int connectionID, const char* name, double value); 270 271 /*----------------------------------------------------------------------------*/ 272 273 /** 274 * Set the array of float values with the given name from the given 275 * buffer. 276 * 277 * @return 0 on success, -1 on error. 278 */ 279 int xplra_set_float_array(int connectionID, const char* name, 280 const float* values, size_t length, size_t offset); 281 282 /*----------------------------------------------------------------------------*/ 283 284 /** 285 * Set the array of integer values with the given name from the given 286 * buffer. 287 * 288 * @return 0 on success, -1 on error. 289 */ 290 int xplra_set_int_array(int connectionID, const char* name, 291 const int32_t* values, size_t length, size_t offset); 292 293 /*----------------------------------------------------------------------------*/ 294 295 /** 296 * Set the array of byte values with the given name from the given 297 * buffer. 298 * 299 * @return 0 on success, -1 on error. 300 */ 301 int xplra_set_byte_array(int connectionID, const char* name, 302 const void* values, size_t length, size_t offset); 303 304 /*----------------------------------------------------------------------------*/ 305 306 /** 307 * Set the array of byte values with the given name from the given 308 * string. The string will be padded with 0 if it has a length less 309 * than the given length. 310 * 311 * @return 0 on success, -1 on error. 312 */ 313 int xplra_set_string(int connectionID, const char* name, 314 const char* value, size_t length, size_t offset); 315 316 /*----------------------------------------------------------------------------*/ 317 318 /** 247 319 * Destroy the connection with the given ID. 248 320 * -
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.