forked from sdr/gr-osmosdr
redpitaya: fix compilation errors on MS Windows and on Mac OS X
This commit is contained in:
parent
810a981d0c
commit
f8cba954f0
|
@ -24,37 +24,23 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <winsock2.h>
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "redpitaya_common.h"
|
#include "redpitaya_common.h"
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__MACH__)
|
void redpitaya_send_command( SOCKET socket, uint32_t command )
|
||||||
#ifndef MSG_NOSIGNAL
|
|
||||||
#define MSG_NOSIGNAL SO_NOSIGPIPE
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void redpitaya_send_command( int socket, uint32_t command )
|
|
||||||
{
|
{
|
||||||
ssize_t size;
|
|
||||||
std::stringstream message;
|
std::stringstream message;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
int total = sizeof(command);
|
||||||
|
int size;
|
||||||
size = ::send( socket, (char *)&command, sizeof(command), 0 );
|
size = ::send( socket, (char *)&command, sizeof(command), 0 );
|
||||||
#else
|
#else
|
||||||
|
ssize_t total = sizeof(command);
|
||||||
|
ssize_t size;
|
||||||
size = ::send( socket, &command, sizeof(command), MSG_NOSIGNAL );
|
size = ::send( socket, &command, sizeof(command), MSG_NOSIGNAL );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( size != sizeof(command) )
|
if ( size != total )
|
||||||
{
|
{
|
||||||
message << "Sending command failed: " << std::hex << command;
|
message << "Sending command failed: " << std::hex << command;
|
||||||
throw std::runtime_error( message.str() );
|
throw std::runtime_error( message.str() );
|
||||||
|
|
|
@ -21,6 +21,35 @@
|
||||||
#ifndef REDPITAYA_COMMON_H
|
#ifndef REDPITAYA_COMMON_H
|
||||||
#define REDPITAYA_COMMON_H
|
#define REDPITAYA_COMMON_H
|
||||||
|
|
||||||
void redpitaya_send_command( int socket, uint32_t command );
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#pragma comment(lib, "ws2_32.lib")
|
||||||
|
#include <windows.h>
|
||||||
|
#define INVSOC INVALID_SOCKET
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#ifndef SOCKET
|
||||||
|
#define SOCKET int
|
||||||
|
#define INVSOC (-1)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__) || defined(__MACH__)
|
||||||
|
#ifndef MSG_NOSIGNAL
|
||||||
|
#define MSG_NOSIGNAL SO_NOSIGPIPE
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void redpitaya_send_command( SOCKET socket, uint32_t command );
|
||||||
|
|
||||||
#endif // REDPITAYA_COMMON_H
|
#endif // REDPITAYA_COMMON_H
|
||||||
|
|
|
@ -24,28 +24,16 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#include <winsock2.h>
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/assign.hpp>
|
#include <boost/assign.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include <gnuradio/io_signature.h>
|
#include <gnuradio/io_signature.h>
|
||||||
|
|
||||||
#include "redpitaya_common.h"
|
|
||||||
#include "redpitaya_sink_c.h"
|
|
||||||
|
|
||||||
#include "arg_helpers.h"
|
#include "arg_helpers.h"
|
||||||
|
|
||||||
|
#include "redpitaya_sink_c.h"
|
||||||
|
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
|
||||||
redpitaya_sink_c_sptr make_redpitaya_sink_c(const std::string &args)
|
redpitaya_sink_c_sptr make_redpitaya_sink_c(const std::string &args)
|
||||||
|
@ -105,7 +93,7 @@ redpitaya_sink_c::redpitaya_sink_c(const std::string &args) :
|
||||||
|
|
||||||
memset( &addr, 0, sizeof(addr) );
|
memset( &addr, 0, sizeof(addr) );
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = inet_addr( host.c_str() );
|
inet_pton( AF_INET, host.c_str(), &addr.sin_addr );
|
||||||
addr.sin_port = htons( port );
|
addr.sin_port = htons( port );
|
||||||
|
|
||||||
if ( ::connect( _sockets[i], (struct sockaddr *)&addr, sizeof(addr) ) < 0 )
|
if ( ::connect( _sockets[i], (struct sockaddr *)&addr, sizeof(addr) ) < 0 )
|
||||||
|
@ -138,13 +126,15 @@ int redpitaya_sink_c::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 )
|
||||||
{
|
{
|
||||||
ssize_t size;
|
|
||||||
ssize_t total = sizeof(gr_complex) * noutput_items;
|
|
||||||
const gr_complex *in = (const gr_complex *)input_items[0];
|
const gr_complex *in = (const gr_complex *)input_items[0];
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
int size;
|
||||||
|
int total = sizeof(gr_complex) * noutput_items;
|
||||||
size = ::send( _sockets[1], (char *)in, total, 0 );
|
size = ::send( _sockets[1], (char *)in, total, 0 );
|
||||||
#else
|
#else
|
||||||
|
ssize_t size;
|
||||||
|
ssize_t total = sizeof(gr_complex) * noutput_items;
|
||||||
size = ::send( _sockets[1], in, total, MSG_NOSIGNAL );
|
size = ::send( _sockets[1], in, total, MSG_NOSIGNAL );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
#include "sink_iface.h"
|
#include "sink_iface.h"
|
||||||
|
|
||||||
|
#include "redpitaya_common.h"
|
||||||
|
|
||||||
class redpitaya_sink_c;
|
class redpitaya_sink_c;
|
||||||
|
|
||||||
typedef boost::shared_ptr< redpitaya_sink_c > redpitaya_sink_c_sptr;
|
typedef boost::shared_ptr< redpitaya_sink_c > redpitaya_sink_c_sptr;
|
||||||
|
@ -77,7 +79,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double _freq, _rate, _corr;
|
double _freq, _rate, _corr;
|
||||||
int _sockets[2];
|
SOCKET _sockets[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REDPITAYA_SINK_C_H
|
#endif // REDPITAYA_SINK_C_H
|
||||||
|
|
|
@ -24,28 +24,16 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#include <winsock2.h>
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/assign.hpp>
|
#include <boost/assign.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include <gnuradio/io_signature.h>
|
#include <gnuradio/io_signature.h>
|
||||||
|
|
||||||
#include "redpitaya_common.h"
|
|
||||||
#include "redpitaya_source_c.h"
|
|
||||||
|
|
||||||
#include "arg_helpers.h"
|
#include "arg_helpers.h"
|
||||||
|
|
||||||
|
#include "redpitaya_source_c.h"
|
||||||
|
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
|
||||||
redpitaya_source_c_sptr make_redpitaya_source_c(const std::string &args)
|
redpitaya_source_c_sptr make_redpitaya_source_c(const std::string &args)
|
||||||
|
@ -100,7 +88,7 @@ redpitaya_source_c::redpitaya_source_c(const std::string &args) :
|
||||||
|
|
||||||
memset( &addr, 0, sizeof(addr) );
|
memset( &addr, 0, sizeof(addr) );
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = inet_addr( host.c_str() );
|
inet_pton( AF_INET, host.c_str(), &addr.sin_addr );
|
||||||
addr.sin_port = htons( port );
|
addr.sin_port = htons( port );
|
||||||
|
|
||||||
if ( ::connect( _sockets[i], (struct sockaddr *)&addr, sizeof(addr) ) < 0 )
|
if ( ::connect( _sockets[i], (struct sockaddr *)&addr, sizeof(addr) ) < 0 )
|
||||||
|
@ -130,13 +118,15 @@ int redpitaya_source_c::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 )
|
||||||
{
|
{
|
||||||
ssize_t size;
|
|
||||||
ssize_t total = sizeof(gr_complex) * noutput_items;
|
|
||||||
gr_complex *out = (gr_complex *)output_items[0];
|
gr_complex *out = (gr_complex *)output_items[0];
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
int size;
|
||||||
|
int total = sizeof(gr_complex) * noutput_items;
|
||||||
size = ::recv( _sockets[1], (char *)out, total, MSG_WAITALL );
|
size = ::recv( _sockets[1], (char *)out, total, MSG_WAITALL );
|
||||||
#else
|
#else
|
||||||
|
ssize_t size;
|
||||||
|
ssize_t total = sizeof(gr_complex) * noutput_items;
|
||||||
size = ::recv( _sockets[1], out, total, MSG_WAITALL );
|
size = ::recv( _sockets[1], out, total, MSG_WAITALL );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
#include "source_iface.h"
|
#include "source_iface.h"
|
||||||
|
|
||||||
|
#include "redpitaya_common.h"
|
||||||
|
|
||||||
class redpitaya_source_c;
|
class redpitaya_source_c;
|
||||||
|
|
||||||
typedef boost::shared_ptr< redpitaya_source_c > redpitaya_source_c_sptr;
|
typedef boost::shared_ptr< redpitaya_source_c > redpitaya_source_c_sptr;
|
||||||
|
@ -77,7 +79,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double _freq, _rate, _corr;
|
double _freq, _rate, _corr;
|
||||||
int _sockets[2];
|
SOCKET _sockets[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REDPITAYA_SOURCE_C_H
|
#endif // REDPITAYA_SOURCE_C_H
|
||||||
|
|
Loading…
Reference in New Issue