PSK api improved

master
Lucjan Bryndza 2014-06-27 23:38:08 +02:00
rodzic 31953d1206
commit d9a81490eb
8 zmienionych plików z 91 dodań i 53 usunięć

Wyświetl plik

@ -17,26 +17,24 @@ namespace psk {
/* PSK Modulation config */
struct mod_psk_config : public modulation_config_base
{
enum class mode : short
{
enum class mode : short {
bpsk,
qpsku,
qpskl,
tune //Valid only in transmission
};
enum class baud : short
{
enum class baud : short {
b31, //Baudrate 31
b63, //Baudrate 63
b125 //Baudrate 125
};
mod_psk_config( mode _mode, baud _baudrate )
mod_psk_config( mode _mode = mode::bpsk, baud _baudrate = baud::b31 )
: modulation_config_base( modulation_config_base::type::psk ),
mmode(_mode), baudrate(_baudrate)
{
}
const mode mmode;
const baud baudrate;
mode mmode {};
baud baudrate {};
};

Wyświetl plik

@ -110,26 +110,27 @@ public:
virtual void reset() = 0;
virtual void set_frequency( int freq ) = 0;
virtual int get_frequency( ) const = 0;
virtual sqelch_value_type get_squelch() const = 0;
virtual sqelch_value_type get_signal_level() const = 0;
virtual void set_squelch( sqelch_value_type , squelch_mode ) = 0;
virtual int set_mode( const modulation_config_base &config ) = 0;
virtual bool get_vector_data( signal_vector_type& ) const
{
virtual int get_mode( modulation_config_base& cfg ) = 0;
virtual bool get_vector_data( signal_vector_type& ) const {
//Not handled
return true;
}
virtual bool set_afc_limit( int /*limit*/ )
{
virtual bool set_afc_limit( int /*limit*/ ) {
//Not handled
return true;
}
virtual bool get_sync_data(sync_array_type& ) const
{
virtual int get_afc_limit() const {
return 0;
}
virtual bool get_sync_data(sync_array_type& ) const {
return true;
}
protected:
void callback_notify( const event &ev )
{
void callback_notify( const event &ev ) {
m_callback( ev );
}
private:

Wyświetl plik

@ -83,6 +83,9 @@ public:
tx_codec* operator->() {
return m_obj->get_tx_codec();
}
tx_codec const* operator->() const {
return m_obj->get_tx_codec();
}
private:
trx_device_base* m_obj {};
};
@ -107,6 +110,9 @@ public:
rx_codec* operator->() {
return m_obj->get_rx_codec( m_id );
}
rx_codec const* operator->() const {
return m_obj->get_rx_codec( m_id );
}
private:
trx_device_base* m_obj {};
int m_id;
@ -144,6 +150,10 @@ public:
tx_proxy tx();
//Locked access RX
rx_proxy rx( int id = 0 );
//Get locked TX
tx_proxy tx() const;
//Locked access RX
rx_proxy rx( int id = 0 ) const;
//Get spectrum
spectrum_proxy get_spectrum();
private:

Wyświetl plik

@ -47,6 +47,7 @@ public:
//Set AFC limit
void set_afc_limit( int limit, int freq, int phz_inc )
{
m_hz_limit = limit;
//No frequency control
if( limit == 0 ) m_fperr_ave = 0;
if( limit==0 ) m_afc_on = false;
@ -59,6 +60,9 @@ public:
m_afc_min = phz_inc + m_freq_error - m_afc_limit;
if(m_afc_min<=0) m_afc_min = 0;
}
int get_afc_limit() const {
return m_hz_limit;
}
//Handle sample timer
void handle_sample_timer( int phz_inc )
{
@ -318,6 +322,7 @@ private:
int m_phz_inc_fract {};
int m_freq_error_fract {};
int m_fperr_ave {};
int m_hz_limit {};
};
/* ------------------------------------------------------------------------- */

Wyświetl plik

@ -45,8 +45,7 @@ class decoder : public rx_codec {
public:
static constexpr auto RCODE_ERR = -1;
static constexpr auto RCODE_OK = 0;
enum cbevent
{
enum cbevent {
cb_rxchar,
cb_clkerror,
cb_imdrdy
@ -63,40 +62,46 @@ public:
}
//Reset decoder
virtual void reset();
//Set receive frequency
virtual void set_frequency( int freq );
//Set detector mode
virtual int set_mode( const modulation_config_base& cfg );
//Get detector mode
virtual int get_mode( modulation_config_base& cfg );
//Set AFC limit
virtual bool set_afc_limit( int limit );
virtual bool set_afc_limit( int limit ) {
m_afc.set_afc_limit( limit, m_sample_freq, m_nco_phzinc );
return false;
}
//Get afc limit
virtual int get_afc_limit() const {
return m_afc.get_afc_limit();
}
//Get current frequency
virtual int get_frequency() const
{
virtual int get_frequency() const {
return m_rx_frequency;
}
//Get signal level
virtual sqelch_value_type get_signal_level() const
{
virtual sqelch_value_type get_signal_level() const {
return m_squelch.get_level();
}
virtual bool get_sync_data(sync_array_type& sync_data) const
{
virtual bool get_sync_data(sync_array_type& sync_data) const {
sync_data = m_sync.get_sync_data();
return false;
}
//Set squelch tresh
virtual void set_squelch( sqelch_value_type tresh, squelch_mode mode )
{
m_squelch.set_tresh( tresh, mode );
virtual void set_squelch( sqelch_value_type tresh, squelch_mode mode ) {
m_squelch.set_thresh( tresh, mode );
}
//! Get squelch
virtual sqelch_value_type get_squelch() const {
return m_squelch.get_thresh();
}
private:
typedef mod_psk_config::mode mode;
typedef mod_psk_config::baud baudrate;
int decode_symb( std::complex<int> newsamp );
bool is_qpsk() const
{
bool is_qpsk() const {
return m_rx_mode != mode::bpsk;
}
//Numeric controlled oscillator and mixer

Wyświetl plik

@ -35,45 +35,47 @@ class squelch
static constexpr int PHZ_0_BMIN = PI2/2.0 * SCALE + 0.5; // Pi
static constexpr int PHZ_0_BMAX = PI2 * SCALE + 0.5;
private:
static constexpr int scale( const double v )
{
static constexpr int scale( const double v ) {
return v * SCALE + 0.5;
}
public:
//! Maximum squelch value
static constexpr sqelch_value_type max_thresh = 100;
//Constructor
squelch()
{}
//Set squelch tresh
void set_tresh( sqelch_value_type thresh, squelch_mode mode )
{
void set_thresh( sqelch_value_type thresh, squelch_mode mode ) {
if( thresh > max_thresh ) {
thresh = max_thresh;
}
m_sq_thresh = thresh;
if( mode == squelch_mode::fast ) m_squelch_speed = 20;
else if( mode == squelch_mode::slow ) m_squelch_speed = 75;
}
//Get SQL tresh
int get_thresh() const {
return m_sq_thresh;
}
//Get squelch level
int get_level() const
{
int get_level() const {
return m_sql_level>0?m_sql_level:0;
}
//Is squelch open
bool is_open() const
{
bool is_open() const {
return m_sq_open;
}
//IMD is valid
bool is_imd_valid() const
{
bool is_imd_valid() const {
return m_imd_valid;
}
//Reset squelch
void reset()
{
void reset() {
m_sql_level = 10;
m_dev_ave = 90*SCALE;
}
//Reset frequency
void reset_frequency()
{
void reset_frequency() {
m_pcnt = 0;
m_ncnt = 0;
}

Wyświetl plik

@ -171,6 +171,18 @@ ham_digi::rx_proxy ham_digi::rx( int id )
return rx_proxy( m_iodev.get(), id );
}
/* ------------------------------------------------------------------------- */
//Get locked TX
ham_digi::tx_proxy ham_digi::tx() const
{
return tx_proxy( m_iodev.get() );
}
/* ------------------------------------------------------------------------- */
//Locked access RX
ham_digi::rx_proxy ham_digi::rx( int id ) const
{
return rx_proxy( m_iodev.get(), id );
}
/* ------------------------------------------------------------------------- */
//Get spectrum
ham_digi::spectrum_proxy ham_digi::get_spectrum()
{

Wyświetl plik

@ -391,14 +391,6 @@ void decoder::set_frequency( int freq )
m_afc.reset( m_nco_phzinc );
}
}
/* ------------------------------------------------------------------------- */
//Set AFC limit
bool decoder::set_afc_limit( int limit )
{
m_afc.set_afc_limit( limit, m_sample_freq, m_nco_phzinc );
return false;
}
/* ------------------------------------------------------------------------- */
//Reset decoder
void decoder::reset()
@ -411,6 +403,19 @@ void decoder::reset()
m_squelch.reset();
}
/* ------------------------------------------------------------------------- */
/* Set modulator config */
int decoder::get_mode( modulation_config_base& _cfg )
{
if( _cfg.cfg_type() == modulation_config_base::type::psk ) {
mod_psk_config& cfg = static_cast<mod_psk_config&>(_cfg);
cfg.mmode = m_rx_mode;
cfg.baudrate = m_baudrate;
return RCODE_OK;
} else {
return RCODE_ERR;
}
}
/* ------------------------------------------------------------------------- */
/* Set modulator config */
int decoder::set_mode( const modulation_config_base& _cfg )