]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/generic.cxx
Fix Linux compile / math dependency
[flightgear.git] / src / Network / generic.cxx
index 2f96180c914d9cf90150d4359fa7815e08e9a526..242bd881c58765cc73e88e0afcb3b5f6faad2b15 100644 (file)
@@ -1,4 +1,4 @@
-// generic.cxx -- generic protocal class
+// generic.cxx -- generic protocol class
 //
 // Written by Curtis Olson, started November 1999.
 //
@@ -34,6 +34,7 @@
 #include <simgear/misc/stdint.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/math/SGMath.hxx>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
@@ -175,6 +176,7 @@ bool FGGeneric::gen_message_binary() {
             /* FIXME padding for alignment? Something like: 
              * length += (strlength % 4 > 0 ? sizeof(int32_t) - strlength % 4 : 0;
              */
+            break;
         }
     }
 
@@ -273,7 +275,6 @@ bool FGGeneric::gen_message() {
 bool FGGeneric::parse_message_binary(int length) {
     char *p2, *p1 = buf;
     int32_t tmp32;
-    double val;
     int i = -1;
 
     p2 = p1 + length;
@@ -291,7 +292,7 @@ bool FGGeneric::parse_message_binary(int length) {
             break;
 
         case FG_BOOL:
-            _in_message[i].prop->setBoolValue( p1[0] != 0 );
+            updateValue(_in_message[i], p1[0] != 0);
             p1 += 1;
             break;
 
@@ -330,6 +331,7 @@ bool FGGeneric::parse_message_binary(int length) {
         default: // SG_STRING
             SG_LOG( SG_IO, SG_ALERT, "Generic protocol: "
                     "Ignoring unsupported binary input chunk type.");
+            break;
         }
     }
     
@@ -338,7 +340,6 @@ bool FGGeneric::parse_message_binary(int length) {
 
 bool FGGeneric::parse_message_ascii(int length) {
     char *p2, *p1 = buf;
-    double val;
     int i = -1;
     int chunks = _in_message.size();
     int line_separator_size = line_separator.size();
@@ -365,7 +366,7 @@ bool FGGeneric::parse_message_ascii(int length) {
             break;
 
         case FG_BOOL:
-            _in_message[i].prop->setBoolValue( atof(p1) != 0.0 );
+            updateValue(_in_message[i], atof(p1) != 0.0);
             break;
 
         case FG_FIXED:
@@ -379,6 +380,7 @@ bool FGGeneric::parse_message_ascii(int length) {
 
         default: // SG_STRING
             _in_message[i].prop->setStringValue(p1);
+            break;
         }
 
         p1 = p2;
@@ -712,23 +714,16 @@ FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
     }
 }
 
-/*
-  set/getValue: Implementations for supported datatypes
-*/
-#define DEF_DATA_ACCESS(type, method)\
-template<>\
-const type FGGeneric::getValue(SGPropertyNode_ptr& prop)\
-{\
-  return prop->get##method##Value();\
-}\
-\
-template<>\
-void FGGeneric::setValue(SGPropertyNode_ptr& prop, const type& val)\
-{\
-  prop->set##method##Value(val);\
+void FGGeneric::updateValue(FGGeneric::_serial_prot& prot, bool val)
+{
+  if( prot.rel )
+  {
+    // value inverted if received true, otherwise leave unchanged
+    if( val )
+      setValue(prot.prop, !getValue<bool>(prot.prop));
+  }
+  else
+  {
+    setValue(prot.prop, val);
+  }
 }
-
-DEF_DATA_ACCESS(int, Int)
-DEF_DATA_ACCESS(float, Float)
-DEF_DATA_ACCESS(double, Double)
-