From 29fe9316afca2db957b811396097169ccf1789f3 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 16 Mar 2017 15:54:38 +0000 Subject: [PATCH] Generic protocol fix for integer-factors. Read all values as floating point before applying a factor, then convert to the target type (int, byte or short). Suggested and implemented by Oliver Kroth. --- src/Network/generic.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Network/generic.cxx b/src/Network/generic.cxx index eebc6de8a..bb97f5c00 100644 --- a/src/Network/generic.cxx +++ b/src/Network/generic.cxx @@ -277,7 +277,7 @@ bool FGGeneric::gen_message_binary() { case FG_INT: { val = _out_message[i].offset + - _out_message[i].prop->getIntValue() * _out_message[i].factor; + _out_message[i].prop->getFloatValue() * _out_message[i].factor; int32_t intVal = val; if (binary_byte_order != BYTE_ORDER_MATCHES_NETWORK_ORDER) { intVal = (int32_t) sg_bswap_32((uint32_t)intVal); @@ -339,7 +339,7 @@ bool FGGeneric::gen_message_binary() { case FG_BYTE: { val = _out_message[i].offset + - _out_message[i].prop->getIntValue() * _out_message[i].factor; + _out_message[i].prop->getFloatValue() * _out_message[i].factor; int8_t byteVal = val; memcpy(&buf[length], &byteVal, sizeof(int8_t)); length += sizeof(int8_t); @@ -349,7 +349,7 @@ bool FGGeneric::gen_message_binary() { case FG_WORD: { val = _out_message[i].offset + - _out_message[i].prop->getIntValue() * _out_message[i].factor; + _out_message[i].prop->getFloatValue() * _out_message[i].factor; int16_t wordVal = val; memcpy(&buf[length], &wordVal, sizeof(int16_t)); length += sizeof(int16_t); @@ -426,7 +426,7 @@ bool FGGeneric::gen_message_ascii() { case FG_WORD: case FG_INT: val = _out_message[i].offset + - _out_message[i].prop->getIntValue() * _out_message[i].factor; + _out_message[i].prop->getFloatValue() * _out_message[i].factor; snprintf(tmp, 255, format.c_str(), (int)val); break;