]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/generic.cxx
Replace the NOAA METAR URL with the new, updated one
[flightgear.git] / src / Network / generic.cxx
index 06fb65139947f5ade917c357414a0cca8c7a8c0b..eebc6de8ac8912e5d280f21afa4453435fe3f26d 100644 (file)
@@ -121,9 +121,7 @@ int FGKissWrapper::unwrap( size_t n, uint8_t * buf )
 
   if( 0 == n ) return 0;
 
-  uint8_t dest[n];
-  uint8_t * dp = dest;
-
+  std::vector<uint8_t> dest;
   {
     bool escaped = false;
 
@@ -136,11 +134,11 @@ int FGKissWrapper::unwrap( size_t n, uint8_t * buf )
         switch( c ) {
 
           case TFESC:
-            *dp++ = FESC;
+            dest.push_back( FESC );
             break;
 
           case TFEND:
-            *dp++ = FEND;
+            dest.push_back( FEND );
             break;
 
           default: // this is an error - ignore and continue
@@ -165,21 +163,15 @@ int FGKissWrapper::unwrap( size_t n, uint8_t * buf )
             break;
 
           default:
-            *dp++ = c;
+            dest.push_back( c );
             break;
-
         }
       }
     }
   }
 
-  n = 0;
-  for( sp = dest; sp != dp; ) {
-    *buf++ = *sp++;
-    n++;
-  }
-
-  return n;
+  memcpy( buf, dest.data(), dest.size() );
+  return dest.size();
 }
 
 
@@ -354,6 +346,16 @@ bool FGGeneric::gen_message_binary() {
             break;
         }
 
+        case FG_WORD:
+        {
+            val = _out_message[i].offset +
+                  _out_message[i].prop->getIntValue() * _out_message[i].factor;
+            int16_t wordVal = val;
+            memcpy(&buf[length], &wordVal, sizeof(int16_t));
+            length += sizeof(int16_t);
+            break;
+        }
+
         default: // SG_STRING
             const char *strdata = _out_message[i].prop->getStringValue();
             int32_t strlength = strlen(strdata);
@@ -421,6 +423,7 @@ bool FGGeneric::gen_message_ascii() {
 
         switch (_out_message[i].type) {
         case FG_BYTE:
+        case FG_WORD:
         case FG_INT:
             val = _out_message[i].offset +
                   _out_message[i].prop->getIntValue() * _out_message[i].factor;
@@ -539,6 +542,16 @@ bool FGGeneric::parse_message_binary(int length) {
             p1 += sizeof(int8_t);
             break;
 
+        case FG_WORD:
+            if (binary_byte_order == BYTE_ORDER_NEEDS_CONVERSION) {
+                tmp32 = sg_bswap_16(*(int16_t *)p1);
+            } else {
+                tmp32 = *(int16_t *)p1;
+            }
+            updateValue(_in_message[i], (int)tmp32);
+            p1 += sizeof(int16_t);
+            break;
+
         default: // SG_STRING
             SG_LOG( SG_IO, SG_ALERT, "Generic protocol: "
                     "Ignoring unsupported binary input chunk type.");
@@ -579,6 +592,7 @@ bool FGGeneric::parse_message_ascii(int length) {
 
         switch (_in_message[i].type) {
         case FG_BYTE:
+        case FG_WORD:
         case FG_INT:
             updateValue(_in_message[i], atoi(p1));
             break;
@@ -744,11 +758,11 @@ FGGeneric::reinit()
     path.append(file_name.c_str());
 
     SG_LOG(SG_NETWORK, SG_INFO, "Reading communication protocol from "
-                                << path.str());
+                                << path);
 
     SGPropertyNode root;
     try {
-        readProperties(path.str(), &root);
+        readProperties(path, &root);
     } catch (const sg_exception & ex) {
         SG_LOG(SG_NETWORK, SG_ALERT,
          "Unable to load the protocol configuration file: " << ex.getFormattedMessage() );
@@ -939,6 +953,9 @@ FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
         } else if (type == "byte") {
             chunk.type = FG_BYTE;
             record_length += sizeof(int8_t);
+        } else if (type == "word") {
+            chunk.type = FG_WORD;
+            record_length += sizeof(int16_t);
         } else {
             chunk.type = FG_INT;
             record_length += sizeof(int32_t);