Transmiter handler

master
Lucjan Bryndza 2013-05-25 22:19:58 +02:00
rodzic 255e62e36c
commit 90781c35e4
6 zmienionych plików z 27 dodań i 18 usunięć

Wyświetl plik

@ -27,7 +27,7 @@ struct event
tx_char, //Transmit char event type tx_char, //Transmit char event type
spectrum, //Spectrum event type spectrum, //Spectrum event type
imd_rdy, //IMD signal event imd_rdy, //IMD signal event
clk_err //CLK error event clk_err, //CLK error event
} evt; } evt;
struct imd_s struct imd_s
{ {
@ -96,8 +96,6 @@ class tx_codec
tx_codec& operator=(const tx_codec&) = delete; tx_codec& operator=(const tx_codec&) = delete;
public: public:
typedef std::function <void( const event &ev )> handler_t; typedef std::function <void( const event &ev )> handler_t;
tx_codec()
{}
tx_codec( handler_t callback ) tx_codec( handler_t callback )
: m_callback( callback ) : m_callback( callback )
{} {}

Wyświetl plik

@ -49,9 +49,9 @@ private:
//Hardware sound thread func //Hardware sound thread func
void hardware_sound_thread(); void hardware_sound_thread();
//Receive and transmit thread //Receive and transmit thread
bool receive_thread(); int receive_thread();
//Transmit thread //Transmit thread
bool transmit_thread(); int transmit_thread();
//Hardware funcs //Hardware funcs
int enable_hw_rx(); int enable_hw_rx();
int disable_hw_rx(); int disable_hw_rx();
@ -62,6 +62,7 @@ private:
std::unique_ptr< std::thread > m_thread; //TX thread std::unique_ptr< std::thread > m_thread; //TX thread
std::mutex m_thrmutex; //Thread mutex std::mutex m_thrmutex; //Thread mutex
volatile bool m_thread_running {}; //Thread volatile bool m_thread_running {}; //Thread
volatile int m_thread_status {}; //Thread error status
pa_simple *m_pa_ctx; //PA CTX pa_simple *m_pa_ctx; //PA CTX
static constexpr auto audio_buf_len = 1024; static constexpr auto audio_buf_len = 1024;
std::array<short,audio_buf_len> m_audio_buf; std::array<short,audio_buf_len> m_audio_buf;

Wyświetl plik

@ -53,7 +53,7 @@ public:
b125 //Baudrate 125 b125 //Baudrate 125
}; };
//Constructor //Constructor
explicit modulator( int sample_freq, int tx_freq, std::size_t char_que_len ); explicit modulator( int sample_freq, int tx_freq, std::size_t char_que_len, tx_codec::handler_t callback );
//Operator on new samples //Operator on new samples
virtual bool operator()( sample_type* sample, size_t len ); virtual bool operator()( sample_type* sample, size_t len );
//Set char into the modulator //Set char into the modulator

Wyświetl plik

@ -47,7 +47,7 @@ void pulse_device::lock( bool lock )
// Initialize sound hardware in selected mode // Initialize sound hardware in selected mode
int pulse_device::setup_sound_hardware( trx_device_base::mode m ) int pulse_device::setup_sound_hardware( trx_device_base::mode m )
{ {
//Hardware SETUP state
if( m == trx_device_base::mode::on && get_mode()!=trx_device_base::mode::on ) if( m == trx_device_base::mode::on && get_mode()!=trx_device_base::mode::on )
{ {
if( get_mode()==trx_device_base::mode::transmit ) if( get_mode()==trx_device_base::mode::transmit )
@ -68,28 +68,32 @@ int pulse_device::setup_sound_hardware( trx_device_base::mode m )
const int ret = enable_hw_tx(); const int ret = enable_hw_tx();
if( ret != 0 ) return ret; if( ret != 0 ) return ret;
} }
//Thread specific switch
if( get_mode()!=trx_device_base::mode::off && m == trx_device_base::mode::off ) if( get_mode()!=trx_device_base::mode::off && m == trx_device_base::mode::off )
{ {
//Disable and wait for stop //Disable and wait for stop
m_thread_running = false; m_thread_running = false;
m_thread->join(); m_thread->join();
return m_thread_status;
} }
else if( get_mode()==trx_device_base::mode::off && m != trx_device_base::mode::off ) else if( get_mode()==trx_device_base::mode::off && m != trx_device_base::mode::off )
{ {
m_thread_running = true; m_thread_running = true;
m_thread.reset( new std::thread( &pulse_device::hardware_sound_thread, this ) ); m_thread.reset( new std::thread( &pulse_device::hardware_sound_thread, this ) );
return 0;
} }
return 0; return trx_device_base::INVALID;
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
//Hardware sound thread func //Hardware sound thread func
void pulse_device::hardware_sound_thread() void pulse_device::hardware_sound_thread()
{ {
for(;m_thread_running;) int errcode = 0;
for(; m_thread_running && !errcode ;)
{ {
m_thrmutex.lock(); m_thrmutex.lock();
if ( get_mode()==trx_device_base::mode::on ) receive_thread(); if ( get_mode()==trx_device_base::mode::on ) errcode = receive_thread();
else if( get_mode()==trx_device_base::mode::transmit ) transmit_thread(); else if( get_mode()==trx_device_base::mode::transmit ) errcode = transmit_thread();
m_thrmutex.unlock(); m_thrmutex.unlock();
} }
if( get_mode()==trx_device_base::mode::on ) if( get_mode()==trx_device_base::mode::on )
@ -104,10 +108,11 @@ void pulse_device::hardware_sound_thread()
set_mode_off(); set_mode_off();
disable_hw_tx(); disable_hw_tx();
} }
m_thread_status = errcode;
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
//Receive and transmit thread //Receive and transmit thread
bool pulse_device::receive_thread() int pulse_device::receive_thread()
{ {
int error = 0; int error = 0;
/* Record some data ... */ /* Record some data ... */
@ -120,7 +125,7 @@ bool pulse_device::receive_thread()
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
//Transmit thread //Transmit thread
bool pulse_device::transmit_thread() int pulse_device::transmit_thread()
{ {
int error = 0; int error = 0;
dac_hardware_isr( &m_audio_buf[0], audio_buf_len ); dac_hardware_isr( &m_audio_buf[0], audio_buf_len );
@ -175,6 +180,7 @@ int pulse_device::disable_hw_tx()
m_pa_ctx = nullptr; m_pa_ctx = nullptr;
return error; return error;
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
} /* namespace psk */ } /* namespace psk */
} /* namespace ham */ } /* namespace ham */

Wyświetl plik

@ -137,9 +137,10 @@ constexpr int modulator::m_vect_lookup[6][2];
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
//Modulator //Modulator
modulator::modulator( int sample_freq, int tx_freq, std::size_t char_que_len ) modulator::modulator( int sample_freq, int tx_freq, std::size_t char_que_len, tx_codec::handler_t callback )
: m_sample_freq( sample_freq ), m_p_psk_tx_i(psk_shapes::Z), m_p_psk_tx_q(psk_shapes::Z), : tx_codec( callback ),
m_chqueue( char_que_len ) m_sample_freq( sample_freq ), m_p_psk_tx_i(psk_shapes::Z),
m_p_psk_tx_q(psk_shapes::Z), m_chqueue( char_que_len )
{ {
//TODO convert to array //TODO convert to array

Wyświetl plik

@ -476,7 +476,7 @@ private:
int encoder_main( const char *filename ) int encoder_main( const char *filename )
{ {
class audio_writer ww( filename ); class audio_writer ww( filename );
ham::psk::modulator mod( ww.get_samplerate(), 2125, 1024 ); ham::psk::modulator mod( ww.get_samplerate(), 2125, 1024, nullptr );
//mod.set_auto_shutoff( false ); //mod.set_auto_shutoff( false );
const char txt[] = "Ala ma kota a KOT ma ale teraz bedzie nieco dluzszy tekst a im tekst dluzszy tym lepszy"; const char txt[] = "Ala ma kota a KOT ma ale teraz bedzie nieco dluzszy tekst a im tekst dluzszy tym lepszy";
mod.set_mode( ham::psk::modulator::mode::qpsku, ham::psk::modulator::baudrate::b31); mod.set_mode( ham::psk::modulator::mode::qpsku, ham::psk::modulator::baudrate::b31);
@ -559,6 +559,9 @@ void decoder_callback( const ham::psk::event &ev )
case event::type::imd_rdy: case event::type::imd_rdy:
cout << "IMDRDY value " << ev.imd.value << " " << ev.imd.noise << endl; cout << "IMDRDY value " << ev.imd.value << " " << ev.imd.noise << endl;
break; break;
case event::type::tx_char:
cout << "CHRTX " << char(ev.chr) << endl;
break;
default: default:
cout << "Unknown evt" << endl; cout << "Unknown evt" << endl;
} }
@ -570,7 +573,7 @@ int main(int argc, const char * const *argv )
{ {
namespace psk = ham::psk; namespace psk = ham::psk;
//FIX this API //FIX this API
psk::modulator * const mod = new psk::modulator(8000, 2124, 1024); psk::modulator * const mod = new psk::modulator(8000, 2124, 1024, decoder_callback);
psk::decoder * dec = new psk::decoder(8000, decoder_callback ); psk::decoder * dec = new psk::decoder(8000, decoder_callback );
psk::pulse_device pulse( decoder_callback ); psk::pulse_device pulse( decoder_callback );
pulse.add_tx_codec( mod ); pulse.add_tx_codec( mod );