]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/morse.cxx
Add support for numerals as well as letters in Morse identifiers
[flightgear.git] / src / Sound / morse.cxx
index 507cf54eb0f858ca8128cd79d0e506d973d2156e..ced5a02dba0e0e8bae66616260b9293ffa8630a0 100644 (file)
@@ -55,6 +55,19 @@ static const char alphabet[26][4] = {
     { DA, DA, DI, DIT }                /* Z */ 
 };
 
+static const char numerals[10][5] = {
+    { DA, DA, DA, DA, DAH },    // 0
+    { DI, DA, DA, DA, DAH },    // 1
+    { DI, DI, DA, DA, DAH },    // 2
+    { DI, DI, DI, DA, DAH },    // 3
+    { DI, DI, DI, DI, DAH },    // 4
+    { DI, DI, DI, DI, DIT },    // 5
+    { DA, DI, DI, DI, DIT },    // 6
+    { DA, DA, DI, DI, DIT },    // 7
+    { DA, DA, DA, DI, DIT },    // 8
+    { DA, DA, DA, DA, DIT }     // 9
+};
+
 
 // constructor
 FGMorse::FGMorse() {
@@ -187,6 +200,16 @@ FGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
                }
            }
            length += SPACE_SIZE;
+        } else if ( idptr[i] >= '0' && idptr[i] <= '9' ) {
+            char c = idptr[i] - '0';
+            for ( j = 0; j < 5; ++j) {
+                if ( numerals[c][j] == DIT ) {
+                    length += DIT_SIZE;
+                } else if ( numerals[c][j] == DAH ) {
+                    length += DAH_SIZE;
+                }
+            }
+            length += SPACE_SIZE;
        } else {
            // skip unknown character
        }
@@ -214,6 +237,19 @@ FGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) {
            }
            memcpy( buf_ptr, space, SPACE_SIZE );
            buf_ptr += SPACE_SIZE;
+        } else if ( idptr[i] >= '0' && idptr[i] <= '9' ) {
+            char c = idptr[i] - '0';
+            for ( j = 0; j < 5; ++j ) {
+                if ( numerals[c][j] == DIT ) {
+                    memcpy( buf_ptr, dit_ptr, DIT_SIZE );
+                    buf_ptr += DIT_SIZE;
+                } else if ( numerals[c][j] == DAH ) {
+                    memcpy( buf_ptr, dah_ptr, DAH_SIZE );
+                    buf_ptr += DAH_SIZE;
+                }
+            }
+           memcpy( buf_ptr, space, SPACE_SIZE );
+           buf_ptr += SPACE_SIZE;
        } else {
            // skip unknown character
        }