Changeset 24:838d1d1b619e in xplra for test


Ignore:
Timestamp:
02/07/13 16:16:04 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added the array reading functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/basicctest.c

    r23 r24  
    4242    float spoolTime = 0.0;
    4343    double latitude = 0.0, longitude = 0.0;
     44    ssize_t length, i;
     45    size_t length1, j;
     46    uint8_t result[260];
     47    uint8_t* result1 = 0;
     48    int32_t result3[8];
     49    int32_t* result4 = 0;
     50    float result5[8];
     51    float* result6 = 0;
    4452
    4553    printf("Connection to X-Plane...\n");
     
    100108    printf("The coordinates: %f, %f\n\n", latitude, longitude);
    101109
     110    printf("Querying the aircraft's description as an array of a fixed size...\n");
     111    length = xplra_get_byte_array(result, sizeof(result)/sizeof(result[0]),
     112                                  0, connectionID,
     113                                  "sim/aircraft/view/acf_descrip");
     114    if (length<0) goto error;
     115    printf("Got %zu bytes, as a string: '%s'\n\n", length, result);
     116
     117    printf("Querying the aircraft's description as a dynamically created array with an offset of 3...\n");
     118    length1 = 0;
     119    result1 = xplra_get_byte_array_new(&length1, 3, connectionID,
     120                                       "sim/aircraft/view/acf_descrip");
     121    if (result1==0) goto error;
     122    printf("Got %zu bytes, as a string: '%s'\n\n", length1, result1);
     123
     124    printf("Querying the aircraft's engine types as an array of a fixed size...\n");
     125    length = xplra_get_int_array(result3, sizeof(result3)/sizeof(result3[0]), 0,
     126                                 connectionID, "sim/aircraft/prop/acf_en_type");
     127
     128    if (length<0) goto error;
     129    printf("Got %zd values:", length);
     130    for(i = 0; i<length; ++i) {
     131        if (i>0) printf(",");
     132        printf(" %d", result3[i]);
     133    }
     134    printf("\n\n");
     135
     136    printf("Querying the aircraft's engine types as a dynamically created array...\n");
     137    length1 = 0;
     138    result4 = xplra_get_int_array_new(&length1, 0, connectionID,
     139                                      "sim/aircraft/prop/acf_en_type");
     140    printf("Got %zu values:", length1);
     141    for(j = 0; j<length1; ++j) {
     142        if (j>0) printf(",");
     143        printf(" %d", result4[j]);
     144    }
     145    printf("\n\n");
     146
     147    printf("Querying the aircraft's propeller direction as an array of a fixed size...\n");
     148    length = xplra_get_float_array(result5, sizeof(result5)/sizeof(result5[0]),
     149                                   0, connectionID,
     150                                   "sim/aircraft/prop/acf_prop_dir");
     151    printf("Got %zd values:", length);
     152    for(i = 0; i<length; ++i) {
     153        if (i>0) printf(",");
     154        printf(" %f", result5[i]);
     155    }
     156    printf("\n\n");
     157
     158    printf("Querying the aircraft's propeller direction as a dynamically created array...\n");
     159    length1 = 0;
     160    result6 = xplra_get_float_array_new(&length1, 0, connectionID,
     161                                        "sim/aircraft/prop/acf_prop_dir");
     162    printf("Got %zu values:", length1);
     163    for(j = 0; j<length1; ++j) {
     164        if (j>0) printf(",");
     165        printf(" %f", result6[j]);
     166    }
     167    printf("\n\n");
     168
    102169    goto cleanup;
    103170error:
     
    116183    // try {
    117184
    118     //     printf("Querying the aircraft's description as an array of a fixed size...\n");
    119     //     uint8_t result[260];
    120     //     size_t length = xplane.getByteArray("sim/aircraft/view/acf_descrip",
    121     //                                         result, sizeof(result)/sizeof(result[0]));
    122     //     printf("Got %zu bytes, as a string: '%s'\n\n", length, result);
    123 
    124     //     printf("Querying the aircraft's description as a dynamically created array...\n");
    125     //     uint8_t* result1 = xplane.getByteArray("sim/aircraft/view/acf_descrip", length);
    126     //     printf("Got %zu bytes, as a string: '%s'\n\n", length, result1);
    127 
    128     //     printf("Querying the aircraft's description as a string, with an offset of 3...\n");
    129     //     string result2 = xplane.getString("sim/aircraft/view/acf_descrip", 3);
    130     //     printf("Got: '%s'\n\n", result2.c_str());
    131 
    132     //     printf("Querying the aircraft's engine types as an array of a fixed size...\n");
    133     //     int32_t result3[8];
    134     //     length = xplane.getIntArray("sim/aircraft/prop/acf_en_type",
    135     //                                 result3, sizeof(result3)/sizeof(result3[0]));
    136     //     printf("Got %zu values:", length);
    137     //     for(size_t i = 0; i<length; ++i) {
    138     //         if (i>0) printf(",");
    139     //         printf(" %d", result3[i]);
    140     //     }
    141     //     printf("\n\n");
    142 
    143     //     printf("Querying the aircraft's engine types as a dynamically created array...\n");
    144     //     length = 0;
    145     //     int32_t* result4 = xplane.getIntArray("sim/aircraft/prop/acf_en_type", length);
    146     //     printf("Got %zu values:", length);
    147     //     for(size_t i = 0; i<length; ++i) {
    148     //         if (i>0) printf(",");
    149     //         printf(" %d", result4[i]);
    150     //     }
    151     //     printf("\n\n");
    152 
    153     //     printf("Querying the aircraft's propeller direction as an array of a fixed size...\n");
    154     //     float result5[8];
    155     //     length = xplane.getFloatArray("sim/aircraft/prop/acf_prop_dir",
    156     //                                   result5, sizeof(result5)/sizeof(result5[0]));
    157     //     printf("Got %zu values:", length);
    158     //     for(size_t i = 0; i<length; ++i) {
    159     //         if (i>0) printf(",");
    160     //         printf(" %f", result5[i]);
    161     //     }
    162     //     printf("\n\n");
    163 
    164     //     printf("Querying the aircraft's propeller direction as a dynamically created array...\n");
    165     //     length = 0;
    166     //     float* result6 = xplane.getFloatArray("sim/aircraft/prop/acf_prop_dir", length);
    167     //     printf("Got %zu values:", length);
    168     //     for(size_t i = 0; i<length; ++i) {
    169     //         if (i>0) printf(",");
    170     //         printf(" %f", result6[i]);
    171     //     }
    172     //     printf("\n\n");
    173185
    174186    //     printf("Setting the number of the engines to %d...\n", numEngines + 1);
Note: See TracChangeset for help on using the changeset viewer.