1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-29 18:34:51 +00:00

Apply project's coding style

This commit is contained in:
Carles Fernandez 2017-10-18 09:08:13 +02:00
parent 117329c1fc
commit 511675a97e
5 changed files with 103 additions and 90 deletions

View File

@ -36,7 +36,7 @@
*/ */
#ifndef GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H #ifndef GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H
#define GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H #define GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H
#include "rtl_tcp_dongle_info.h" #include "rtl_tcp_dongle_info.h"
#include <boost/asio.hpp> #include <boost/asio.hpp>
@ -67,8 +67,8 @@ public:
~rtl_tcp_signal_source_c(); ~rtl_tcp_signal_source_c();
int work (int noutput_items, int work (int noutput_items,
gr_vector_const_void_star &input_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items); gr_vector_void_star &output_items);
void set_frequency (int frequency); void set_frequency (int frequency);
void set_sample_rate (int sample_rate); void set_sample_rate (int sample_rate);
@ -110,13 +110,15 @@ private:
void handle_read (const boost::system::error_code &ec, void handle_read (const boost::system::error_code &ec,
size_t bytes_transferred); size_t bytes_transferred);
inline bool not_full ( ) const { inline bool not_full ( ) const
{
return unread_ < buffer_.capacity( ); return unread_ < buffer_.capacity( );
} }
inline bool not_empty ( ) const { inline bool not_empty ( ) const
{
return unread_ > 0 || io_service_.stopped (); return unread_ > 0 || io_service_.stopped ();
} }
}; };
#endif //GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H #endif // GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H

View File

@ -29,25 +29,21 @@
* *
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#include "rtl_tcp_commands.h" #include "rtl_tcp_commands.h"
#include <string.h> #include <string>
using boost::asio::ip::tcp; boost::system::error_code rtl_tcp_command (RTL_TCP_COMMAND id, unsigned param, boost::asio::ip::tcp::socket &socket)
{
boost::system::error_code
rtl_tcp_command (RTL_TCP_COMMAND id, unsigned param, tcp::socket &socket) {
// Data payload // Data payload
unsigned char data[sizeof (unsigned char) + sizeof (unsigned)]; unsigned char data[sizeof(unsigned char) + sizeof(unsigned)];
data[0] = static_cast<unsigned char> (id); data[0] = static_cast<unsigned char>(id);
unsigned nparam = boost::asio::detail::socket_ops::host_to_network_long(param);
unsigned nparam = std::memcpy(&data[1], &nparam, sizeof(nparam));
boost::asio::detail::socket_ops::host_to_network_long (param);
::memcpy (&data[1], &nparam, sizeof (nparam));
boost::system::error_code ec; boost::system::error_code ec;
socket.send (boost::asio::buffer (data), 0, ec); socket.send(boost::asio::buffer(data), 0, ec);
return ec; return ec;
} }

View File

@ -48,8 +48,7 @@ enum RTL_TCP_COMMAND {
/*! /*!
* \brief Send a command to rtl_tcp over the given socket. * \brief Send a command to rtl_tcp over the given socket.
*/ */
boost::system::error_code boost::system::error_code rtl_tcp_command (RTL_TCP_COMMAND id, unsigned param,
rtl_tcp_command (RTL_TCP_COMMAND id, unsigned param, boost::asio::ip::tcp::socket &socket);
boost::asio::ip::tcp::socket &socket);
#endif // GNSS_SDR_RTL_TCP_COMMANDS_H #endif // GNSS_SDR_RTL_TCP_COMMANDS_H

View File

@ -30,45 +30,47 @@
* *
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#include "rtl_tcp_dongle_info.h" #include "rtl_tcp_dongle_info.h"
#include <string.h> #include <string>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using boost::asio::ip::tcp; using boost::asio::ip::tcp;
rtl_tcp_dongle_info::rtl_tcp_dongle_info () rtl_tcp_dongle_info::rtl_tcp_dongle_info() : tuner_type_(0), tuner_gain_count_(0)
: tuner_type_ (0), tuner_gain_count_ (0)
{ {
::memset (magic_, 0, sizeof (magic_)); std::memset(magic_, 0, sizeof(magic_));
} }
boost::system::error_code rtl_tcp_dongle_info::read (tcp::socket &socket) {
boost::system::error_code rtl_tcp_dongle_info::read(boost::asio::ip::tcp::socket &socket)
{
boost::system::error_code ec; boost::system::error_code ec;
unsigned char data[sizeof (char) * 4 + sizeof (uint32_t) * 2]; unsigned char data[sizeof(char) * 4 + sizeof(uint32_t) * 2];
socket.receive (boost::asio::buffer (data), 0, ec); socket.receive(boost::asio::buffer(data), 0, ec);
if (!ec) { if (!ec)
::memcpy (magic_, data, 4); {
std::memcpy(magic_, data, 4);
uint32_t type; uint32_t type;
::memcpy (&type, &data[4], 4); std::memcpy(&type, &data[4], 4);
tuner_type_ = tuner_type_ = boost::asio::detail::socket_ops::network_to_host_long(type);
boost::asio::detail::socket_ops::network_to_host_long (type);
uint32_t count;
std ::memcpy(&count, &data[8], 4);
uint32_t count; tuner_gain_count_ = boost::asio::detail::socket_ops::network_to_host_long(count);
::memcpy (&count, &data[8], 4); }
tuner_gain_count_ =
boost::asio::detail::socket_ops::network_to_host_long (count);
}
return ec; return ec;
} }
const char *rtl_tcp_dongle_info::get_type_name () const { const char *rtl_tcp_dongle_info::get_type_name() const
switch (get_tuner_type()) { {
switch(get_tuner_type())
{
default: default:
return "UNKNOWN"; return "UNKNOWN";
case TUNER_E4000: case TUNER_E4000:
@ -86,29 +88,32 @@ const char *rtl_tcp_dongle_info::get_type_name () const {
} }
} }
double rtl_tcp_dongle_info::clip_gain (int gain) const {
double rtl_tcp_dongle_info::clip_gain(int gain) const
{
// the following gain values have been copied from librtlsdr // the following gain values have been copied from librtlsdr
// all gain values are expressed in tenths of a dB // all gain values are expressed in tenths of a dB
std::vector<double> gains; std::vector<double> gains;
switch (get_tuner_type()) { switch (get_tuner_type())
{
case TUNER_E4000: case TUNER_E4000:
gains = { -10, 15, 40, 65, 90, 115, 140, 165, 190, 215, gains = { -10, 15, 40, 65, 90, 115, 140, 165, 190, 215,
240, 290, 340, 420 }; 240, 290, 340, 420 };
break; break;
case TUNER_FC0012: case TUNER_FC0012:
gains = { -99, -40, 71, 179, 192 }; gains = { -99, -40, 71, 179, 192 };
break; break;
case TUNER_FC0013: case TUNER_FC0013:
gains = { -99, -73, -65, -63, -60, -58, -54, 58, 61, gains = { -99, -73, -65, -63, -60, -58, -54, 58, 61,
63, 65, 67, 68, 70, 71, 179, 181, 182, 63, 65, 67, 68, 70, 71, 179, 181, 182,
184, 186, 188, 191, 197 }; 184, 186, 188, 191, 197 };
break; break;
case TUNER_R820T: case TUNER_R820T:
gains = { 0, 9, 14, 27, 37, 77, 87, 125, 144, 157, gains = { 0, 9, 14, 27, 37, 77, 87, 125, 144, 157,
166, 197, 207, 229, 254, 280, 297, 328, 166, 197, 207, 229, 254, 280, 297, 328,
338, 364, 372, 386, 402, 421, 434, 439, 338, 364, 372, 386, 402, 421, 434, 439,
445, 480, 496 }; 445, 480, 496 };
break; break;
default: default:
// no gains // no gains
@ -116,29 +121,37 @@ double rtl_tcp_dongle_info::clip_gain (int gain) const {
} }
// clip // clip
if (gains.size() == 0) { if (gains.size() == 0)
// no defined gains to clip to {
return gain; // no defined gains to clip to
} return gain;
else { }
double last_stop = gains.front (); else
BOOST_FOREACH (double g, gains) { {
g /= 10.0; double last_stop = gains.front();
BOOST_FOREACH (double g, gains)
if (gain < g) { {
if (std::abs (gain - g) < std::abs (gain - last_stop)) { g /= 10.0;
return g;
} if (gain < g)
else { {
return last_stop; if (std::abs(gain - g) < std::abs(gain - last_stop))
} {
} return g;
last_stop = g; }
else
{
return last_stop;
}
}
last_stop = g;
}
return last_stop;
} }
return last_stop;
}
} }
bool rtl_tcp_dongle_info::is_valid () const {
return ::memcmp (magic_, "RTL0", 4) == 0; bool rtl_tcp_dongle_info::is_valid() const
{
return std::memcmp(magic_, "RTL0", 4) == 0;
} }

View File

@ -29,6 +29,7 @@
* *
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#ifndef GNSS_SDR_RTL_TCP_DONGLE_INFO_H #ifndef GNSS_SDR_RTL_TCP_DONGLE_INFO_H
#define GNSS_SDR_RTL_TCP_DONGLE_INFO_H #define GNSS_SDR_RTL_TCP_DONGLE_INFO_H
@ -38,9 +39,16 @@
* \brief This class represents the dongle information * \brief This class represents the dongle information
* which is sent by rtl_tcp. * which is sent by rtl_tcp.
*/ */
class rtl_tcp_dongle_info { class rtl_tcp_dongle_info
public: {
enum { private:
char magic_[4];
uint32_t tuner_type_;
uint32_t tuner_gain_count_;
public:
enum
{
TUNER_UNKNOWN = 0, TUNER_UNKNOWN = 0,
TUNER_E4000, TUNER_E4000,
TUNER_FC0012, TUNER_FC0012,
@ -50,28 +58,23 @@ class rtl_tcp_dongle_info {
TUNER_R828D TUNER_R828D
}; };
private: rtl_tcp_dongle_info();
char magic_[4];
uint32_t tuner_type_;
uint32_t tuner_gain_count_;
public: boost::system::error_code read(boost::asio::ip::tcp::socket &socket);
rtl_tcp_dongle_info ();
boost::system::error_code read ( bool is_valid() const;
boost::asio::ip::tcp::socket &socket);
bool is_valid () const; const char *get_type_name() const;
const char *get_type_name () const; double clip_gain(int gain) const;
double clip_gain (int gain) const; inline uint32_t get_tuner_type() const
{
inline uint32_t get_tuner_type () const {
return tuner_type_; return tuner_type_;
} }
inline uint32_t get_tuner_gain_count () const { inline uint32_t get_tuner_gain_count() const
{
return tuner_gain_count_; return tuner_gain_count_;
} }
}; };