1
0
Fork 0

MP2017.2 V2 protocol enhancements

1. Add support for scaled floats; most of the floats we transmit are small and thus can fit into a scaled short.
2. Change most properties to use scaled floats.
This commit is contained in:
Richard Harrison 2017-02-23 22:33:33 +01:00
parent 3fceba7a24
commit 80dc810d15
3 changed files with 501 additions and 406 deletions

View file

@ -71,10 +71,10 @@ enum TransmissionType {
TT_STRING = simgear::props::STRING,
TT_SHORTINT = 0x100,
TT_SHORT_FLOAT_NORM = 0x101, // -1 .. 1 encoded into a short int (16 bit)
TT_SHORT_FLOAT_1 = 0x102, // float encoded into a short int (16 bit) range -6553.5 .. 6553.5
TT_SHORT_FLOAT_2 = 0x103, // float encoded into a short int (16 bit) range -655.35 .. 655.35
TT_SHORT_FLOAT_3 = 0x103, // float encoded into a short int (16 bit) range -65.535 .. 65.535
TT_SHORT_FLOAT_4 = 0x103, // float encoded into a short int (16 bit) range -6.5535 .. 6.5535
TT_SHORT_FLOAT_1 = 0x102, //range -3276.7 .. 3276.7 float encoded into a short int (16 bit)
TT_SHORT_FLOAT_2 = 0x103, //range -327.67 .. 327.67 float encoded into a short int (16 bit)
TT_SHORT_FLOAT_3 = 0x104, //range -32.767 .. 32.767 float encoded into a short int (16 bit)
TT_SHORT_FLOAT_4 = 0x105, //range -3.2767 .. 3.2767 float encoded into a short int (16 bit)
TT_BOOLARRAY,
TT_CHAR,
};
@ -112,75 +112,75 @@ static int convert_launchbar_state(int direction, xdr_data_t*, FGPropertyData*)
// This should be extendable dynamically for every specific aircraft ...
// For now only that static list
static const IdPropertyList sIdPropertyList[] = {
{ 10, "surface-positions/left-aileron-pos-norm", simgear::props::INT, TT_SHORTINT, V1_1_PROP_ID, NULL },
{ 100, "surface-positions/left-aileron-pos-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 101, "surface-positions/right-aileron-pos-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 102, "surface-positions/elevator-pos-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 103, "surface-positions/rudder-pos-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 104, "surface-positions/flap-pos-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 105, "surface-positions/speedbrake-pos-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 106, "gear/tailhook/position-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 107, "gear/launchbar/position-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 10, "sim/multiplay/protocol-version", simgear::props::INT, TT_SHORTINT, V1_1_PROP_ID, NULL },
{ 100, "surface-positions/left-aileron-pos-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 101, "surface-positions/right-aileron-pos-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 102, "surface-positions/elevator-pos-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 103, "surface-positions/rudder-pos-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 104, "surface-positions/flap-pos-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 105, "surface-positions/speedbrake-pos-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 106, "gear/tailhook/position-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 107, "gear/launchbar/position-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 108, "gear/launchbar/state", simgear::props::STRING, TT_ASIS, V1_1_2_PROP_ID, NULL },
{ 109, "gear/launchbar/holdback-position-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 110, "canopy/position-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 111, "surface-positions/wing-pos-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 112, "surface-positions/wing-fold-pos-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 109, "gear/launchbar/holdback-position-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 110, "canopy/position-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 111, "surface-positions/wing-pos-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 112, "surface-positions/wing-fold-pos-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 200, "gear/gear[0]/compression-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 201, "gear/gear[0]/position-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 210, "gear/gear[1]/compression-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 211, "gear/gear[1]/position-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 220, "gear/gear[2]/compression-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 221, "gear/gear[2]/position-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 230, "gear/gear[3]/compression-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 231, "gear/gear[3]/position-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 240, "gear/gear[4]/compression-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 241, "gear/gear[4]/position-norm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 200, "gear/gear[0]/compression-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 201, "gear/gear[0]/position-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 210, "gear/gear[1]/compression-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 211, "gear/gear[1]/position-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 220, "gear/gear[2]/compression-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 221, "gear/gear[2]/position-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 230, "gear/gear[3]/compression-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 231, "gear/gear[3]/position-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 240, "gear/gear[4]/compression-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 241, "gear/gear[4]/position-norm", simgear::props::FLOAT, TT_SHORT_FLOAT_NORM, V1_1_PROP_ID, NULL },
{ 300, "engines/engine[0]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 301, "engines/engine[0]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 302, "engines/engine[0]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 310, "engines/engine[1]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 311, "engines/engine[1]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 312, "engines/engine[1]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 320, "engines/engine[2]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 321, "engines/engine[2]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 322, "engines/engine[2]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 330, "engines/engine[3]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 331, "engines/engine[3]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 332, "engines/engine[3]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 340, "engines/engine[4]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 341, "engines/engine[4]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 342, "engines/engine[4]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 350, "engines/engine[5]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 351, "engines/engine[5]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 352, "engines/engine[5]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 360, "engines/engine[6]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 361, "engines/engine[6]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 362, "engines/engine[6]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 370, "engines/engine[7]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 371, "engines/engine[7]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 372, "engines/engine[7]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 380, "engines/engine[8]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 381, "engines/engine[8]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 382, "engines/engine[8]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 390, "engines/engine[9]/n1", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 391, "engines/engine[9]/n2", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 392, "engines/engine[9]/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 300, "engines/engine[0]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 301, "engines/engine[0]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 302, "engines/engine[0]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 310, "engines/engine[1]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 311, "engines/engine[1]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 312, "engines/engine[1]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 320, "engines/engine[2]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 321, "engines/engine[2]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 322, "engines/engine[2]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 330, "engines/engine[3]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 331, "engines/engine[3]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 332, "engines/engine[3]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 340, "engines/engine[4]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 341, "engines/engine[4]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 342, "engines/engine[4]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 350, "engines/engine[5]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 351, "engines/engine[5]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 352, "engines/engine[5]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 360, "engines/engine[6]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 361, "engines/engine[6]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 362, "engines/engine[6]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 370, "engines/engine[7]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 371, "engines/engine[7]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 372, "engines/engine[7]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 380, "engines/engine[8]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 381, "engines/engine[8]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 382, "engines/engine[8]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 390, "engines/engine[9]/n1", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 391, "engines/engine[9]/n2", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 392, "engines/engine[9]/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 800, "rotors/main/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 801, "rotors/tail/rpm", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 810, "rotors/main/blade[0]/position-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 811, "rotors/main/blade[1]/position-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 812, "rotors/main/blade[2]/position-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 813, "rotors/main/blade[3]/position-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 820, "rotors/main/blade[0]/flap-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 821, "rotors/main/blade[1]/flap-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 822, "rotors/main/blade[2]/flap-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 823, "rotors/main/blade[3]/flap-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 830, "rotors/tail/blade[0]/position-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 831, "rotors/tail/blade[1]/position-deg", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 800, "rotors/main/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 801, "rotors/tail/rpm", simgear::props::FLOAT, TT_SHORT_FLOAT_1, V1_1_PROP_ID, NULL },
{ 810, "rotors/main/blade[0]/position-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 811, "rotors/main/blade[1]/position-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 812, "rotors/main/blade[2]/position-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 813, "rotors/main/blade[3]/position-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 820, "rotors/main/blade[0]/flap-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 821, "rotors/main/blade[1]/flap-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 822, "rotors/main/blade[2]/flap-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 823, "rotors/main/blade[3]/flap-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 830, "rotors/tail/blade[0]/position-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 831, "rotors/tail/blade[1]/position-deg", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 900, "sim/hitches/aerotow/tow/length", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 901, "sim/hitches/aerotow/tow/elastic-constant", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
@ -199,27 +199,27 @@ static const IdPropertyList sIdPropertyList[] = {
{ 934, "sim/hitches/aerotow/local-pos-y", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 935, "sim/hitches/aerotow/local-pos-z", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1001, "controls/flight/slats", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1002, "controls/flight/speedbrake", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1003, "controls/flight/spoilers", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1004, "controls/gear/gear-down", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1005, "controls/lighting/nav-lights", simgear::props::FLOAT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1006, "controls/armament/station[0]/jettison-all", simgear::props::BOOL, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1001, "controls/flight/slats", simgear::props::FLOAT, TT_SHORT_FLOAT_4, V1_1_PROP_ID, NULL },
{ 1002, "controls/flight/speedbrake", simgear::props::FLOAT, TT_SHORT_FLOAT_4, V1_1_PROP_ID, NULL },
{ 1003, "controls/flight/spoilers", simgear::props::FLOAT, TT_SHORT_FLOAT_4, V1_1_PROP_ID, NULL },
{ 1004, "controls/gear/gear-down", simgear::props::FLOAT, TT_SHORT_FLOAT_4, V1_1_PROP_ID, NULL },
{ 1005, "controls/lighting/nav-lights", simgear::props::FLOAT, TT_SHORT_FLOAT_3, V1_1_PROP_ID, NULL },
{ 1006, "controls/armament/station[0]/jettison-all", simgear::props::BOOL, TT_SHORTINT, V1_1_PROP_ID, NULL },
{ 1100, "sim/model/variant", simgear::props::INT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1101, "sim/model/livery/file", simgear::props::STRING, TT_ASIS, V1_1_2_PROP_ID, NULL },
{ 1200, "environment/wildfire/data", simgear::props::STRING, TT_ASIS, V1_1_2_PROP_ID, NULL },
{ 1201, "environment/contrail", simgear::props::INT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1201, "environment/contrail", simgear::props::INT, TT_SHORTINT, V1_1_PROP_ID, NULL },
{ 1300, "tanker", simgear::props::INT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1300, "tanker", simgear::props::INT, TT_SHORTINT, V1_1_PROP_ID, NULL },
{ 1400, "scenery/events", simgear::props::STRING, TT_ASIS, V1_1_2_PROP_ID, NULL },
{ 1500, "instrumentation/transponder/transmitted-id", simgear::props::INT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1501, "instrumentation/transponder/altitude", simgear::props::INT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1502, "instrumentation/transponder/ident", simgear::props::BOOL, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1503, "instrumentation/transponder/inputs/mode", simgear::props::INT, TT_ASIS, V1_1_PROP_ID, NULL },
{ 1500, "instrumentation/transponder/transmitted-id", simgear::props::INT, TT_SHORTINT, V1_1_PROP_ID, NULL },
{ 1501, "instrumentation/transponder/altitude", simgear::props::INT, TT_ASIS, TT_SHORTINT, NULL },
{ 1502, "instrumentation/transponder/ident", simgear::props::BOOL, TT_ASIS, TT_SHORTINT, NULL },
{ 1503, "instrumentation/transponder/inputs/mode", simgear::props::INT, TT_ASIS, TT_SHORTINT, NULL },
{ 10001, "sim/multiplay/transmission-freq-hz", simgear::props::STRING, TT_ASIS, V1_1_2_PROP_ID, NULL },
{ 10002, "sim/multiplay/chat", simgear::props::STRING, TT_ASIS, V1_1_2_PROP_ID, NULL },
@ -437,8 +437,7 @@ static const IdPropertyList sIdPropertyList[] = {
* which will contain the newly supported shortint and fixed string encoding schemes.
*/
const int MAX_PARTITIONS = 2;
const unsigned int numProperties = (sizeof(sIdPropertyList)
/ sizeof(sIdPropertyList[0]));
const unsigned int numProperties = (sizeof(sIdPropertyList) / sizeof(sIdPropertyList[0]));
// Look up a property ID using binary search.
namespace
@ -691,7 +690,7 @@ FGMultiplayMgr::FGMultiplayMgr()
globals->get_commands()->addCommand("multiplayer-disconnect", do_multiplayer_disconnect);
globals->get_commands()->addCommand("multiplayer-refreshserverlist", do_multiplayer_refreshserverlist);
pXmitLen = fgGetNode("/sim/multiplay/last-xmit-packet-len", true);
pProtocolVersion = fgGetNode("/sim/multiplay/last-xmit-packet-len", true);
pProtocolVersion = fgGetNode("/sim/multiplay/protocol-version", true);
pMultiPlayDebugLevel = fgGetNode("/sim/multiplay/debug-level", true);
pMultiPlayRange = fgGetNode("/sim/multiplay/visibility-range-nm", true);
pMultiPlayRange->setIntValue(100);
@ -983,7 +982,7 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
* the protocol version as the very first property as a shortint.
*/
if (getProtocolToUse() > 1)
PosMsg->pad = XDR_encode_double(V2_PAD_MAGIC);
PosMsg->pad = XDR_encode_int32(V2_PAD_MAGIC);
strncpy(PosMsg->Model, fgGetString("/sim/model/path"), MAX_MODEL_NAME_LEN);
PosMsg->Model[MAX_MODEL_NAME_LEN - 1] = '\0';
@ -1039,7 +1038,12 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
xdr_data_t* data = ptr;
xdr_data_t* msgEnd = msgBuf.propsEnd();
for (int partition = 1; partition <= getProtocolToUse(); partition++)
int protocolVersion = getProtocolToUse();
//if (pMultiPlayDebugLevel->getIntValue())
// msgBuf.zero();
for (int partition = 1; partition <= protocolVersion; partition++)
{
std::vector<FGPropertyData*>::const_iterator it = motionInfo.properties.begin();
while (it != motionInfo.properties.end()) {
@ -1048,15 +1052,22 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
{
if (ptr + 2 >= msgEnd)
{
SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer packet truncated prop id: " << (*it)->id);
SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer packet truncated prop id: " << (*it)->id << ": " << propDef->name);
break;
}
// First element is the ID. Write it out when we know we have room for
// the whole property.
xdr_data_t id = XDR_encode_uint32((*it)->id);
/*
* 2017.2 protocol has the ability to transmit as a different type (to save space), so
* process this when using this protocol (protocolVersion 2) or later
*/
int transmit_type = (*it)->type;
if (partition > 1 && propDef->TransmitAs != TT_ASIS)
if (propDef->TransmitAs != TT_ASIS && protocolVersion > 1)
{
transmit_type = propDef->TransmitAs;
}
@ -1074,23 +1085,54 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
*ptr++ = XDR_encode_shortints32((*it)->id, (*it)->int_value);
break;
}
case TT_SHORT_FLOAT_1:
{
short value = get_scaled_short((*it)->float_value, 10.0);
*ptr++ = XDR_encode_shortints32((*it)->id, value);
break;
}
case TT_SHORT_FLOAT_2:
{
short value = get_scaled_short((*it)->float_value, 100.0);
*ptr++ = XDR_encode_shortints32((*it)->id, value);
break;
}
case TT_SHORT_FLOAT_3:
{
short value = get_scaled_short((*it)->float_value, 1000.0);
*ptr++ = XDR_encode_shortints32((*it)->id, value);
break;
}
case TT_SHORT_FLOAT_4:
{
short value = get_scaled_short((*it)->float_value, 10000.0);
*ptr++ = XDR_encode_shortints32((*it)->id, value);
break;
}
case TT_SHORT_FLOAT_NORM:
{
short value = get_scaled_short((*it)->float_value, 32767.0);
*ptr++ = XDR_encode_shortints32((*it)->id, value);
break;
}
case simgear::props::INT:
case simgear::props::BOOL:
case simgear::props::LONG:
*ptr++ = id;
*ptr++ = XDR_encode_uint32((*it)->int_value);
//cout << "Prop:" << (*it)->id << " " << (*it)->type << " "<< (*it)->int_value << "\n";
break;
case simgear::props::FLOAT:
case simgear::props::DOUBLE:
*ptr++ = id;
*ptr++ = XDR_encode_float((*it)->float_value);
//cout << "Prop:" << (*it)->id << " " << (*it)->type << " "<< (*it)->float_value << "\n";
break;
case simgear::props::STRING:
case simgear::props::UNSPECIFIED:
{
if (partition > 1) {
if (protocolVersion > 1)
{
// New string encoding:
// xdr[0] : ID length packed into 32 bit containing two shorts.
// xdr[1..len/4] The string itself (char[length])
@ -1186,8 +1228,6 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
lcharptr++;
lcount++;
}
//cout << "Prop:" << (*it)->id << " " << (*it)->type << " " << len << " " << (*it)->string_value;
// Now pad if required
while ((lcount % 4) != 0)
{
@ -1198,10 +1238,7 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
}
*ptr++ = XDR_encode_int8(0);
lcount++;
//cout << "0";
}
//cout << "\n";
}
}
else
@ -1209,17 +1246,14 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
// Nothing to encode
*ptr++ = id;
*ptr++ = XDR_encode_uint32(0);
//cout << "Prop:" << (*it)->id << " " << (*it)->type << " 0\n";
}
}
}
break;
default:
//cout << " Unknown Type: " << (*it)->type << "\n";
*ptr++ = id;
*ptr++ = XDR_encode_float((*it)->float_value);;
//cout << "Prop:" << (*it)->id << " " << (*it)->type << " "<< (*it)->float_value << "\n";
break;
}
}
@ -1245,9 +1279,9 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
{
SG_LOG(SG_NETWORK, SG_INFO,
"[SEND] Packet len " << msgLen);
}
if (pMultiPlayDebugLevel->getIntValue() & 2)
SG_LOG_HEXDUMP(SG_NETWORK, SG_INFO, data, (ptr - data) * sizeof(*ptr));
}
/*
* simple loopback of ourselves - to enable easy MP debug for model developers.
*/
@ -1262,6 +1296,14 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
SG_LOG(SG_NETWORK, SG_BULK, "FGMultiplayMgr::SendMyPosition");
} // FGMultiplayMgr::SendMyPosition()
short FGMultiplayMgr::get_scaled_short(double v, double scale)
{
float nv = v * scale;
if (nv >= 32767) return 32767;
if (nv <= -32767) return -32767;
short rv = (short)nv;
return rv;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
@ -1533,6 +1575,11 @@ FGMultiplayMgr::Send()
switch (pData->type) {
case TT_SHORTINT:
case TT_SHORT_FLOAT_1:
case TT_SHORT_FLOAT_2:
case TT_SHORT_FLOAT_3:
case TT_SHORT_FLOAT_4:
case TT_SHORT_FLOAT_NORM:
case props::INT:
case props::LONG:
case props::BOOL:
@ -1647,7 +1694,7 @@ FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
* This will preserve the position info but not transmit the properties; which is about
* the most reasonable compromise we can have
*/
if (PosMsg->pad != 0 && PosMsg->pad != V2_PAD_MAGIC) {
if (PosMsg->pad != 0 && XDR_decode_int32(PosMsg->pad) != V2_PAD_MAGIC) {
if (verifyProperties(&PosMsg->pad, Msg.propsRecvdEnd()))
xdr = &PosMsg->pad;
else if (!verifyProperties(xdr, Msg.propsRecvdEnd()))
@ -1695,19 +1742,67 @@ FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
case simgear::props::INT:
case simgear::props::BOOL:
case simgear::props::LONG:
if (short_int_encoded)
{
pData->int_value = int_value;
pData->type = simgear::props::INT;
}
else
{
pData->int_value = XDR_decode_uint32(*xdr);
xdr++;
}
//cout << pData->int_value << "\n";
break;
case simgear::props::FLOAT:
case simgear::props::DOUBLE:
if (short_int_encoded)
{
switch (plist->TransmitAs)
{
case TT_SHORT_FLOAT_1:
pData->float_value = (double)int_value / 10.0;
break;
case TT_SHORT_FLOAT_2:
pData->float_value = (double)int_value / 100.0;
break;
case TT_SHORT_FLOAT_3:
pData->float_value = (double)int_value / 1000.0;
break;
case TT_SHORT_FLOAT_4:
pData->float_value = (double)int_value / 10000.0;
break;
case TT_SHORT_FLOAT_NORM:
pData->float_value = (double)int_value / 32767.0;
break;
default:
break;
}
}
else
{
pData->float_value = XDR_decode_float(*xdr);
}
xdr++;
//cout << pData->float_value << "\n";
break;
case simgear::props::STRING:
case simgear::props::UNSPECIFIED:
{
// if the string is using short int encoding then it is in the new format.
if (short_int_encoded)
{
uint32_t length = int_value;
pData->string_value = new char[length + 1];
char *cptr = (char*)xdr;
for (unsigned i = 0; i < length; i++)
{
pData->string_value[i] = *cptr++;
}
pData->string_value[length] = '\0';
xdr = (xdr_data_t*)cptr;
}
else {
// String is complicated. It consists of
// The length of the string
// The string itself
@ -1724,7 +1819,6 @@ FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
{
pData->string_value[i] = (char) XDR_decode_int8(*xdr);
xdr++;
//cout << pData->string_value[i];
}
pData->string_value[length] = '\0';
@ -1738,6 +1832,7 @@ FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
}
//cout << "\n";
}
}
break;
default:
@ -1755,7 +1850,6 @@ FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::ProcessPosMsg - "
"message from " << MsgHdr->Callsign << " has unknown property id "
<< id);
SG_LOG_HEXDUMP(SG_NETWORK, SG_DEBUG, data, (Msg.propsRecvdEnd() - data) * sizeof(*data));
// At this point the packet must be considered to be unreadable
// as we have no way of knowing the length of this property (it could be a string)

View file

@ -85,6 +85,7 @@ private:
void Send();
void SendMyPosition(const FGExternalMotionData& motionInfo);
short get_scaled_short(double v, double scale);
union MsgBuf;
FGAIMultiplayer* addMultiplayer(const std::string& callsign,

View file

@ -73,7 +73,7 @@ XDR_encode_int32 ( const int32_t & n_Val )
return (SWAP32(static_cast<xdr_data_t> (n_Val)));
}
static short convert_int_to_short(int v1)
static short XDR_convert_int_to_short(int v1)
{
if (v1 < -32767)
v1 = -32767;
@ -89,7 +89,7 @@ static short convert_int_to_short(int v1)
*/
xdr_data_t XDR_encode_shortints32(const int v1, const int v2)
{
return XDR_encode_uint32( (convert_int_to_short(v1) << 16) | (convert_int_to_short(v2)));
return XDR_encode_uint32( ((XDR_convert_int_to_short(v1) << 16) & 0xffff0000) | ((XDR_convert_int_to_short(v2)) & 0xffff));
}
/* Decode packed shorts into two ints. V1 in the highword ($V1..V2..)*/
void XDR_decode_shortints32(const xdr_data_t & n_Val, int &v1, int &v2)