]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/generic.cxx
Merge branch 'tat/configure'
[flightgear.git] / src / Network / generic.cxx
index ad362e258005c0c730ba52e905e8f519b06e0fb9..a91f7835eba45a8a2d56d5427b6d20eebfa509ee 100644 (file)
@@ -61,37 +61,15 @@ FGGeneric::FGGeneric(vector<string> tokens) : exitOnError(false)
     }
 
     string config = tokens[ configToken ];
-    string file = config+".xml";
+    file_name = config+".xml";
+    direction = tokens[2];
 
-    SGPath path( globals->get_fg_root() );
-    path.append("Protocol");
-    path.append(file.c_str());
-    SG_LOG(SG_GENERAL, SG_INFO, "Reading communication protocol from "
-                                << path.str());
-
-    SGPropertyNode root;
-    try {
-        readProperties(path.str(), &root);
-    } catch (const sg_exception &) {
-        SG_LOG(SG_GENERAL, SG_ALERT,
-         "Unable to load the protocol configuration file");
-         return;
-    }
-
-    if (tokens[2] == "out") {
-        SGPropertyNode *output = root.getNode("generic/output");
-        if (output) {
-            read_config(output, _out_message);
-        }
-    } else if (tokens[2] == "in") {
-        SGPropertyNode *input = root.getNode("generic/input");
-        if (input) {
-            read_config(input, _in_message);
-        }
-    } else {
+    if (direction != "in" && direction != "out") {
         SG_LOG(SG_GENERAL, SG_ALERT, "Unsuported protocol direction: "
-               << tokens[2]);
+               << direction);
     }
+
+    reinit();
 }
 
 FGGeneric::~FGGeneric() {
@@ -400,11 +378,15 @@ bool FGGeneric::parse_message_ascii() {
 
         case FG_FIXED:
         case FG_FLOAT:
-        case FG_DOUBLE:
             val = _in_message[i].offset + strtod(p1, 0) * _in_message[i].factor;
             _in_message[i].prop->setFloatValue((float)val);
             break;
 
+        case FG_DOUBLE:
+            val = _in_message[i].offset + strtod(p1, 0) * _in_message[i].factor;
+            _in_message[i].prop->setDoubleValue(val);
+            break;
+
         default: // SG_STRING
             _in_message[i].prop->setStringValue(p1);
         }
@@ -537,6 +519,41 @@ bool FGGeneric::close() {
 }
 
 
+void
+FGGeneric::reinit()
+{
+    SGPath path( globals->get_fg_root() );
+    path.append("Protocol");
+    path.append(file_name.c_str());
+
+    SG_LOG(SG_GENERAL, SG_INFO, "Reading communication protocol from "
+                                << path.str());
+
+    SGPropertyNode root;
+    try {
+        readProperties(path.str(), &root);
+    } catch (const sg_exception &) {
+        SG_LOG(SG_GENERAL, SG_ALERT,
+         "Unable to load the protocol configuration file");
+         return;
+    }
+
+    if (direction == "out") {
+        SGPropertyNode *output = root.getNode("generic/output");
+        if (output) {
+            _out_message.clear();
+            read_config(output, _out_message);
+        }
+    } else if (direction == "in") {
+        SGPropertyNode *input = root.getNode("generic/input");
+        if (input) {
+            _in_message.clear();
+            read_config(input, _in_message);
+        }
+    }
+}
+
+
 void
 FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
 {
@@ -675,12 +692,14 @@ FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
 
     }
 
-    if (binary_record_length == -1) {
-        binary_record_length = record_length;
-    } else if (binary_record_length < record_length) {
-        SG_LOG(SG_IO, SG_ALERT,
-               "generic protocol: Requested binary record length shorter than "
-               " requested record representation.");
-        binary_record_length = record_length;
+    if( binary_mode ) {
+        if (binary_record_length == -1) {
+            binary_record_length = record_length;
+        } else if (binary_record_length < record_length) {
+            SG_LOG(SG_IO, SG_ALERT,
+                   "generic protocol: Requested binary record length shorter than "
+                   " requested record representation.");
+            binary_record_length = record_length;
+        }
     }
 }