From d5dd671135e8c1306edd4c947d88ee0d67241c7c Mon Sep 17 00:00:00 2001 From: bruceperens Date: Tue, 21 Jan 2014 20:26:00 +0000 Subject: [PATCH] Build the main loop. git-svn-id: https://svn.code.sf.net/p/freetel/code@1382 01035d8c-6547-0410-b346-abe4f91aad63 --- freedv-server/source/big_main.cpp | 7 +- freedv-server/source/run.cpp | 106 ++++++++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 8 deletions(-) diff --git a/freedv-server/source/big_main.cpp b/freedv-server/source/big_main.cpp index 5820b32d..74239717 100644 --- a/freedv-server/source/big_main.cpp +++ b/freedv-server/source/big_main.cpp @@ -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; } diff --git a/freedv-server/source/run.cpp b/freedv-server/source/run.cpp index 23f2375d..8a893370 100644 --- a/freedv-server/source/run.cpp +++ b/freedv-server/source/run.cpp @@ -1,21 +1,113 @@ /// The main loop of the program. #include "drivers.h" +#include +#include + +/// 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; } } -- 2.25.1