1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-25 06:23:18 +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
#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 <boost/asio.hpp>
@ -67,8 +67,8 @@ public:
~rtl_tcp_signal_source_c();
int work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
void set_frequency (int frequency);
void set_sample_rate (int sample_rate);
@ -110,13 +110,15 @@ private:
void handle_read (const boost::system::error_code &ec,
size_t bytes_transferred);
inline bool not_full ( ) const {
inline bool not_full ( ) const
{
return unread_ < buffer_.capacity( );
}
inline bool not_empty ( ) const {
inline bool not_empty ( ) const
{
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 <string.h>
#include <string>
using boost::asio::ip::tcp;
boost::system::error_code
rtl_tcp_command (RTL_TCP_COMMAND id, unsigned param, tcp::socket &socket) {
boost::system::error_code rtl_tcp_command (RTL_TCP_COMMAND id, unsigned param, boost::asio::ip::tcp::socket &socket)
{
// 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);
::memcpy (&data[1], &nparam, sizeof (nparam));
unsigned nparam = boost::asio::detail::socket_ops::host_to_network_long(param);
std::memcpy(&data[1], &nparam, sizeof(nparam));
boost::system::error_code ec;
socket.send (boost::asio::buffer (data), 0, ec);
socket.send(boost::asio::buffer(data), 0, ec);
return ec;
}

View File

@ -48,8 +48,7 @@ enum RTL_TCP_COMMAND {
/*!
* \brief Send a command to rtl_tcp over the given socket.
*/
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,
boost::asio::ip::tcp::socket &socket);
#endif // GNSS_SDR_RTL_TCP_COMMANDS_H

View File

@ -30,45 +30,47 @@
*
* -------------------------------------------------------------------------
*/
#include "rtl_tcp_dongle_info.h"
#include <string.h>
#include <string>
#include <boost/foreach.hpp>
using boost::asio::ip::tcp;
rtl_tcp_dongle_info::rtl_tcp_dongle_info ()
: tuner_type_ (0), tuner_gain_count_ (0)
rtl_tcp_dongle_info::rtl_tcp_dongle_info() : 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;
unsigned char data[sizeof (char) * 4 + sizeof (uint32_t) * 2];
socket.receive (boost::asio::buffer (data), 0, ec);
if (!ec) {
::memcpy (magic_, data, 4);
unsigned char data[sizeof(char) * 4 + sizeof(uint32_t) * 2];
socket.receive(boost::asio::buffer(data), 0, ec);
if (!ec)
{
std::memcpy(magic_, data, 4);
uint32_t type;
::memcpy (&type, &data[4], 4);
uint32_t type;
std::memcpy(&type, &data[4], 4);
tuner_type_ =
boost::asio::detail::socket_ops::network_to_host_long (type);
tuner_type_ = boost::asio::detail::socket_ops::network_to_host_long(type);
uint32_t count;
std ::memcpy(&count, &data[8], 4);
uint32_t count;
::memcpy (&count, &data[8], 4);
tuner_gain_count_ =
boost::asio::detail::socket_ops::network_to_host_long (count);
}
tuner_gain_count_ = boost::asio::detail::socket_ops::network_to_host_long(count);
}
return ec;
}
const char *rtl_tcp_dongle_info::get_type_name () const {
switch (get_tuner_type()) {
const char *rtl_tcp_dongle_info::get_type_name() const
{
switch(get_tuner_type())
{
default:
return "UNKNOWN";
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
// all gain values are expressed in tenths of a dB
std::vector<double> gains;
switch (get_tuner_type()) {
switch (get_tuner_type())
{
case TUNER_E4000:
gains = { -10, 15, 40, 65, 90, 115, 140, 165, 190, 215,
240, 290, 340, 420 };
240, 290, 340, 420 };
break;
case TUNER_FC0012:
gains = { -99, -40, 71, 179, 192 };
break;
case TUNER_FC0013:
gains = { -99, -73, -65, -63, -60, -58, -54, 58, 61,
63, 65, 67, 68, 70, 71, 179, 181, 182,
184, 186, 188, 191, 197 };
63, 65, 67, 68, 70, 71, 179, 181, 182,
184, 186, 188, 191, 197 };
break;
case TUNER_R820T:
gains = { 0, 9, 14, 27, 37, 77, 87, 125, 144, 157,
166, 197, 207, 229, 254, 280, 297, 328,
338, 364, 372, 386, 402, 421, 434, 439,
445, 480, 496 };
166, 197, 207, 229, 254, 280, 297, 328,
338, 364, 372, 386, 402, 421, 434, 439,
445, 480, 496 };
break;
default:
// no gains
@ -116,29 +121,37 @@ double rtl_tcp_dongle_info::clip_gain (int gain) const {
}
// clip
if (gains.size() == 0) {
// no defined gains to clip to
return gain;
}
else {
double last_stop = gains.front ();
BOOST_FOREACH (double g, gains) {
g /= 10.0;
if (gain < g) {
if (std::abs (gain - g) < std::abs (gain - last_stop)) {
return g;
}
else {
return last_stop;
}
}
last_stop = g;
if (gains.size() == 0)
{
// no defined gains to clip to
return gain;
}
else
{
double last_stop = gains.front();
BOOST_FOREACH (double g, gains)
{
g /= 10.0;
if (gain < g)
{
if (std::abs(gain - g) < std::abs(gain - last_stop))
{
return 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
#define GNSS_SDR_RTL_TCP_DONGLE_INFO_H
@ -38,9 +39,16 @@
* \brief This class represents the dongle information
* which is sent by rtl_tcp.
*/
class rtl_tcp_dongle_info {
public:
enum {
class rtl_tcp_dongle_info
{
private:
char magic_[4];
uint32_t tuner_type_;
uint32_t tuner_gain_count_;
public:
enum
{
TUNER_UNKNOWN = 0,
TUNER_E4000,
TUNER_FC0012,
@ -50,28 +58,23 @@ class rtl_tcp_dongle_info {
TUNER_R828D
};
private:
char magic_[4];
uint32_t tuner_type_;
uint32_t tuner_gain_count_;
rtl_tcp_dongle_info();
public:
rtl_tcp_dongle_info ();
boost::system::error_code read(boost::asio::ip::tcp::socket &socket);
boost::system::error_code read (
boost::asio::ip::tcp::socket &socket);
bool is_valid() const;
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_;
}
inline uint32_t get_tuner_gain_count () const {
inline uint32_t get_tuner_gain_count() const
{
return tuner_gain_count_;
}
};