Build the main loop.
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 21 Jan 2014 20:26:00 +0000 (20:26 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 21 Jan 2014 20:26:00 +0000 (20:26 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1382 01035d8c-6547-0410-b346-abe4f91aad63

freedv-server/source/big_main.cpp
freedv-server/source/run.cpp

index 5820b32d1116500f901a22d6608dca6804e835ea..742397170c080077da01628f246edcef11823e70 100644 (file)
@@ -71,7 +71,9 @@ static void help(const char * name)
 
 static const struct option options[] = {
   { "codec",           required_argument, 0, 'c' },
+  { "config",          no_argument,       0, 'C' },
   { "drivers",         no_argument,       0, 'd' },
+  { "default",         no_argument,       0, 'D' },
   { "gui",             required_argument, 0, 'g' },
   { "help",            no_argument,       0, 'h' },
   { "interface",       required_argument, 0, 'i' },
@@ -84,7 +86,6 @@ static const struct option options[] = {
   { "receiver",                required_argument, 0, 'r' },
   { "text",            required_argument, 0, 'x' },
   { "transmitter",     required_argument, 0, 't' },
-  { "config",          no_argument,       0, 'C' },
   { 0, 0, 0, 0 }
 };
 
@@ -129,6 +130,9 @@ main(int argc, char * * argv)
         drivers();
         exit(0);
         break;
+      case 'D':
+        i.fill_in();
+        break;
       case 'g':
         i.user_interface = driver_manager.user_interface(driver, parameter, &i);
         break;
@@ -168,6 +172,7 @@ main(int argc, char * * argv)
        i.fill_in();
        // FIX: Operator overload doesn't work here.
         i.print(cout) << endl;
+        exit(0);
       case 0:
         break;
       }
index 23f2375dca481a902ca55c335fe125993b54ec68..8a8933701ed73bf3f48026f95a0ef50fccdfb238 100644 (file)
 /// The main loop of the program.
 
 #include "drivers.h"
+#include <unistd.h>
+#include <iostream>
+
+/// FIX: Make the delay at start of transmit and end of transmit adjustable.
+/// The radio in general takes some time to begin transmitting, and thus we
+/// should not send audio until that's done.
+///
+/// There is a lot to fill in for end-of-transmit.
+/// On PTT-up, we should be sending the remaining audio in the microphone
+/// device queue first, waiting for completion of its transmission, and then
+/// un-keying the transmitter.
+///
 
 namespace FreeDV {
-  static void
-  ptt_digital(bool value)
+  static void key_down(Interfaces * i);
+  static void key_up(Interfaces * i);
+  static void receive(Interfaces * i);
+  static void transmit_digital(Interfaces * i);
+  static void transmit_ssb(Interfaces * i);
+  
+  static bool begin_transmit = false;
+  static bool begin_receive = true;
+
+  int
+  run(Interfaces * i)
   {
+    static bool ptt_digital = false;
+    static bool ptt_ssb = false;
+
+    while ( true ) {
+      if ( i->ptt_input_digital->ready() ) {
+        bool state = i->ptt_input_digital->state();
+        if ( state && !ptt_digital && !ptt_ssb ) {
+          ptt_digital = true;
+          begin_transmit = true;
+        }
+        else if ( !state && ptt_digital ) {
+          begin_receive = true;
+          ptt_digital = false;
+        }
+      }
+      if ( i->ptt_input_ssb->ready() ) {
+        bool state = i->ptt_input_ssb->state();
+        if ( state && !ptt_digital && !ptt_ssb ) {
+          ptt_ssb = true;
+          begin_transmit = true;
+        }
+        else if ( !state && ptt_ssb ) {
+          begin_receive = true;
+          ptt_ssb = false;
+        }
+      }
+      if ( begin_transmit ) {
+        key_down(i);
+      }
+      else if ( begin_receive ) {
+        key_up(i);
+      }
+      else if ( ptt_digital ) {
+        transmit_digital(i);
+      }
+      else if ( ptt_ssb ) {
+        transmit_ssb(i);
+      }
+      else {
+        receive(i);
+      }
+      usleep(10000);
+    }
   }
 
   static void
-  ptt_ssb(bool value)
+  key_down(Interfaces * i)
   {
+    if ( i->keying_output->ready() ) {
+      i->keying_output->key(true);
+      begin_transmit = false;
+    }
+    else {
+      std::cerr << "Keying output is stalled." << std::endl;
+    }
   }
-
-  int
-  run(Interfaces * i)
+  
+  static void
+  key_up(Interfaces * i)
+  {
+    if ( i->keying_output->ready() ) {
+      i->keying_output->key(false);
+      begin_receive = false;
+    }
+    else {
+      std::cerr << "Keying output is stalled." << std::endl;
+    }
+  }
+  
+  static void
+  receive(Interfaces * i)
+  {
+  }
+  
+  static void
+  transmit_digital(Interfaces * i)
+  {
+  }
+  
+  static void
+  transmit_ssb(Interfaces * i)
   {
-    return 0;
   }
 }