[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r11064 - in gnuradio/branches/developers/eb/vrt: gr-vr
From: |
eb |
Subject: |
[Commit-gnuradio] r11064 - in gnuradio/branches/developers/eb/vrt: gr-vrt/src vrt/apps vrt/include/vrt vrt/lib |
Date: |
Tue, 19 May 2009 19:09:24 -0600 (MDT) |
Author: eb
Date: 2009-05-19 19:09:24 -0600 (Tue, 19 May 2009)
New Revision: 11064
Added:
gnuradio/branches/developers/eb/vrt/vrt/include/vrt/quadradio.h
gnuradio/branches/developers/eb/vrt/vrt/lib/quadradio.cc
Removed:
gnuradio/branches/developers/eb/vrt/gr-vrt/src/rx_16sc_handler.cc
gnuradio/branches/developers/eb/vrt/gr-vrt/src/rx_16sc_handler.h
gnuradio/branches/developers/eb/vrt/gr-vrt/src/rx_32fc_handler.cc
gnuradio/branches/developers/eb/vrt/gr-vrt/src/rx_32fc_handler.h
Modified:
gnuradio/branches/developers/eb/vrt/gr-vrt/src/Makefile.am
gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
gnuradio/branches/developers/eb/vrt/vrt/lib/Makefile.am
Log:
refactoring in progress...
Modified: gnuradio/branches/developers/eb/vrt/gr-vrt/src/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/vrt/gr-vrt/src/Makefile.am 2009-05-20
01:06:55 UTC (rev 11063)
+++ gnuradio/branches/developers/eb/vrt/gr-vrt/src/Makefile.am 2009-05-20
01:09:24 UTC (rev 11064)
@@ -83,10 +83,9 @@
# vrt_sink_16sc.h \
# vrt_sink_32fc.h
-noinst_HEADERS = \
- rx_16sc_handler.h \
- rx_32fc_handler.h
+noinst_HEADERS =
+
# ----------------------------------------------------------------------
# Python SWIG wrapper around C++ library
#
Modified: gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
2009-05-20 01:06:55 UTC (rev 11063)
+++ gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
2009-05-20 01:09:24 UTC (rev 11064)
@@ -19,12 +19,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
+#include <vrt/quadradio.h>
+#include <vrt/rx.h>
+#include <vrt/copiers.h>
+#include <errno.h>
#include <iostream>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
@@ -34,8 +33,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
-#include <vrt/rx.h>
-#include <vrt/copiers.h>
#include <gruel/realtime.h>
#include <complex>
@@ -267,140 +264,6 @@
// ------------------------------------------------------------------------
-static bool
-open_sockets(const char *quad_radio_ip, int quad_radio_ctrl_port,
- int *ctrl_fd_ptr, struct in_addr *ctrl_port_inaddr,
- int *data_fd_ptr, int *data_port_ptr)
-{
- int ctrl_fd; // socket for control
- int data_fd; // socket fd for data
- int data_port; // our port number
-
- //
- // create a udp socket and connect it to the quad radio control port
- //
-
- ctrl_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (ctrl_fd == -1){
- perror("socket: ctrl_fd");
- return false;
- }
-
- struct sockaddr_in si_other;
- memset(&si_other, 0, sizeof(si_other));
- si_other.sin_family = AF_INET;
- si_other.sin_port = htons(quad_radio_ctrl_port);
- if (inet_pton(AF_INET, quad_radio_ip, &si_other.sin_addr) <= 0){
- perror("inet_pton");
- return false;
- }
-
- if (connect(ctrl_fd, (struct sockaddr *) &si_other, sizeof(si_other)) != 0){
- perror("connect");
- return false;
- }
-
- // get our ip address associated with the interface connected to the control
port
-
- struct sockaddr_in si_me;
- memset(&si_me, 0, sizeof(si_me));
- socklen_t sockname_len = sizeof(si_me);
- if (getsockname(ctrl_fd, (struct sockaddr *) &si_me, &sockname_len) != 0){
- perror("getsockname");
- }
-
- *ctrl_port_inaddr = si_me.sin_addr;
-
- if (1){
- char buf[128];
- const char *s = inet_ntop(si_me.sin_family, &si_me.sin_addr, buf,
sizeof(buf));
- if (s == 0){
- perror("inet_ntop");
- return false;
- }
- printf("our ip addr associated with ctrl port: %s\n", s);
- }
-
- //
- // create a udp socket to use to receive data
- //
-
- data_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (data_fd == -1){
- perror("socket: data_fd");
- return false;
- }
-
- // bind it to a local port on the interface that connects to the ctrl port.
- // FIXME this assumes that interface connected to the control port and the
- // interface connected to the data port are the same. If we're using
- // both ethernet ports on the quad radio, this may not be the case.
-
- data_port = -1;
- for (int port = MIN_IP_LOCAL_PORT; port <= MAX_IP_LOCAL_PORT; port++){
- struct sockaddr_in si_me;
- memset(&si_me, 0, sizeof(si_me));
- si_me.sin_family = AF_INET;
- si_me.sin_port = htons(port);
- si_me.sin_addr.s_addr = htonl(INADDR_ANY);
-
- if (bind(data_fd, (struct sockaddr *) &si_me, sizeof(si_me)) == 0){
// found one!
- data_port = port;
- break;
- }
- }
-
- if (data_port == -1){
- fprintf(stderr, "failed to bind to a local port\n");
- return false;
- }
-
- printf("our data port = %d\n", data_port);
-
- *ctrl_fd_ptr = ctrl_fd;
- *data_fd_ptr = data_fd;
- *data_port_ptr = data_port;
-
- return true;
-}
-
-
-static bool
-send_rx_command(int ctrl_fd, bool start,
- struct in_addr addr, int data_port, int samples_per_pkt, int
siggen_param)
-{
- uint32_t cmd[7];
- cmd[0] = htonl(0); // verb: set
- cmd[1] = htonl(0); // id: rx_streaming
- cmd[2] = htonl(start ? 1: 0); // start or stop?
- cmd[3] = addr.s_addr; // ip address to send data to
(already network endian)
- cmd[4] = htonl(data_port); // port to send data to
- cmd[5] = htonl(samples_per_pkt);
- cmd[6] = htonl(siggen_param);
-
- int r = send(ctrl_fd, cmd, sizeof(cmd), 0);
- if (r < 0){
- perror("send");
- return false;
- }
- if (r != sizeof(cmd)){
- fprintf(stderr, "send: short return value. expected %zd, got %d\n",
sizeof(cmd), r);
- return false;
- }
-
- return true;
-}
-
-static bool
-send_stop_rx_command(int ctrl_fd)
-{
- struct in_addr in_addr;
- in_addr.s_addr = 0;
- return send_rx_command(ctrl_fd, false, in_addr, 0, 0, 0);
-}
-
-// ------------------------------------------------------------------------
-
static void
usage(const char *progname)
{
@@ -431,21 +294,13 @@
main(int argc, char **argv)
{
const char *quad_radio_ip = "192.168.123.123";
- int quad_radio_ctrl_port = 790;
size_t rx_bufsize = 62.5e6; // sizeof memory mapped network buffer
int samples_per_pkt = 0; // use default
uint64_t nsamples = 0;
char *output_filename = 0;
bool output_shorts = false;
- int siggen_param = 0;
int t;
- int ctrl_fd; // socket for control
- struct in_addr ctrl_port_inaddr; // our ip addr
- int data_fd; // socket for data
- int data_port; // our data port number
-
-
int ch;
while ((ch = getopt(argc, argv, "hN:o:sS:")) != EOF){
@@ -487,13 +342,15 @@
std::cerr << "Failed to enable realtime scheduling" << std::endl;
- if (!open_sockets(quad_radio_ip, quad_radio_ctrl_port,
- &ctrl_fd, &ctrl_port_inaddr, &data_fd, &data_port))
+ vrt::quadradio qr;
+ if (!qr.open(quad_radio_ip)){
+ std::cerr << "Failed to open quadradio\n";
return 1;
+ }
- vrt::rx::sptr vrt_receiver = vrt::rx::make(data_fd, rx_bufsize);
-
+ vrt::rx::sptr vrt_receiver = vrt::rx::make(qr.data_socket_fd(), rx_bufsize);
+
rx_nop_handler::sptr handler;
if (output_filename){
@@ -506,7 +363,7 @@
handler = rx_nop_handler::sptr(new rx_nop_handler(nsamples));
- if (!send_rx_command(ctrl_fd, true, ctrl_port_inaddr, data_port,
samples_per_pkt, siggen_param)){
+ if (!qr.start_streaming(samples_per_pkt)){
fprintf(stderr, "failed to send_rx_command\n");
return 1;
}
@@ -524,7 +381,7 @@
}
}
- send_stop_rx_command(ctrl_fd);
+ qr.stop_streaming();
printf("%llu packets received, %llu bad pkt_cnt field values, %llu
samples\n",
handler->npackets(), handler->nwrong_pkt_cnt(), handler->nsamples());
Added: gnuradio/branches/developers/eb/vrt/vrt/include/vrt/quadradio.h
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/include/vrt/quadradio.h
(rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/include/vrt/quadradio.h
2009-05-20 01:09:24 UTC (rev 11064)
@@ -0,0 +1,72 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_VRT_QUADRADIO_H
+#define INCLUDED_VRT_QUADRADIO_H
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+/*
+ * We're not committing to this interface. It's just here so we can make
progress...
+ */
+
+namespace vrt {
+
+ class quadradio
+ {
+ int d_ctrl_fd; // socket for control
+ struct in_addr d_ctrl_port_inaddr; // our ip addr
+ int d_data_fd; // socket for data
+ int d_data_port; // our data port number
+
+ static bool
+ open_sockets(const char *quad_radio_ip, int quad_radio_ctrl_port,
+ int *ctrl_fd_ptr, struct in_addr *ctrl_port_inaddr,
+ int *data_fd_ptr, int *data_port_ptr);
+
+ static bool
+ send_rx_command(int ctrl_fd, bool start,
+ struct in_addr addr, int data_port, int samples_per_pkt,
int siggen_param);
+
+ static bool
+ send_stop_rx_command(int ctrl_fd);
+
+ static int control_port() { return 790; }
+
+ public:
+ quadradio();
+ ~quadradio();
+
+ bool open(const char *ip);
+ bool close();
+
+ bool start_streaming(int samples_per_pkt = 0);
+ bool stop_streaming();
+
+ int data_socket_fd() const { return d_data_fd; }
+ };
+
+};
+
+
+#endif /* INCLUDED_QUADRADIO_H */
Property changes on:
gnuradio/branches/developers/eb/vrt/vrt/include/vrt/quadradio.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: gnuradio/branches/developers/eb/vrt/vrt/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/Makefile.am 2009-05-20
01:06:55 UTC (rev 11063)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/Makefile.am 2009-05-20
01:09:24 UTC (rev 11064)
@@ -31,6 +31,7 @@
copiers.cc \
data_handler.cc \
expanded_header.cc \
+ quadradio.cc \
rx.cc \
rx_packet_handler.cc \
socket_rx_buffer.cc
Added: gnuradio/branches/developers/eb/vrt/vrt/lib/quadradio.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/quadradio.cc
(rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/quadradio.cc 2009-05-20
01:09:24 UTC (rev 11064)
@@ -0,0 +1,205 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <vrt/quadradio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdexcept>
+
+#define MIN_IP_LOCAL_PORT 32768
+#define MAX_IP_LOCAL_PORT 61000
+
+
+vrt::quadradio::quadradio()
+ : d_ctrl_fd(0), d_data_fd(0), d_data_port(0)
+{
+}
+
+vrt::quadradio::~quadradio()
+{
+ close();
+}
+
+bool
+vrt::quadradio::open(const char *ip)
+{
+ return vrt::quadradio::open_sockets(ip, control_port(),
+ &d_ctrl_fd, &d_ctrl_port_inaddr,
+ &d_data_fd, &d_data_port);
+}
+
+bool
+vrt::quadradio::close()
+{
+ ::close(d_ctrl_fd);
+ ::close(d_data_fd);
+ return true;
+}
+
+bool
+vrt::quadradio::start_streaming(int samples_per_pkt)
+{
+ return send_rx_command(d_ctrl_fd, true, d_ctrl_port_inaddr,
+ d_data_port, samples_per_pkt, 0);
+}
+
+bool
+vrt::quadradio::stop_streaming()
+{
+ return send_stop_rx_command(d_ctrl_fd);
+}
+
+
+bool
+vrt::quadradio::open_sockets(const char *quad_radio_ip, int
quad_radio_ctrl_port,
+ int *ctrl_fd_ptr, struct in_addr *ctrl_port_inaddr,
+ int *data_fd_ptr, int *data_port_ptr)
+{
+ int ctrl_fd; // socket for control
+ int data_fd; // socket fd for data
+ int data_port; // our port number
+
+ //
+ // create a udp socket and connect it to the quad radio control port
+ //
+
+ ctrl_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (ctrl_fd == -1){
+ perror("socket: ctrl_fd");
+ return false;
+ }
+
+ struct sockaddr_in si_other;
+ memset(&si_other, 0, sizeof(si_other));
+ si_other.sin_family = AF_INET;
+ si_other.sin_port = htons(quad_radio_ctrl_port);
+ if (inet_pton(AF_INET, quad_radio_ip, &si_other.sin_addr) <= 0){
+ perror("inet_pton");
+ return false;
+ }
+
+ if (connect(ctrl_fd, (struct sockaddr *) &si_other, sizeof(si_other)) != 0){
+ perror("connect");
+ return false;
+ }
+
+ // get our ip address associated with the interface connected to the control
port
+
+ struct sockaddr_in si_me;
+ memset(&si_me, 0, sizeof(si_me));
+ socklen_t sockname_len = sizeof(si_me);
+ if (getsockname(ctrl_fd, (struct sockaddr *) &si_me, &sockname_len) != 0){
+ perror("getsockname");
+ }
+
+ *ctrl_port_inaddr = si_me.sin_addr;
+
+ if (1){
+ char buf[128];
+ const char *s = inet_ntop(si_me.sin_family, &si_me.sin_addr, buf,
sizeof(buf));
+ if (s == 0){
+ perror("inet_ntop");
+ return false;
+ }
+ printf("our ip addr associated with ctrl port: %s\n", s);
+ }
+
+ //
+ // create a udp socket to use to receive data
+ //
+
+ data_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (data_fd == -1){
+ perror("socket: data_fd");
+ return false;
+ }
+
+ // bind it to a local port on the interface that connects to the ctrl port.
+ // FIXME this assumes that interface connected to the control port and the
+ // interface connected to the data port are the same. If we're using
+ // both ethernet ports on the quad radio, this may not be the case.
+
+ data_port = -1;
+ for (int port = MIN_IP_LOCAL_PORT; port <= MAX_IP_LOCAL_PORT; port++){
+ struct sockaddr_in si_me;
+ memset(&si_me, 0, sizeof(si_me));
+ si_me.sin_family = AF_INET;
+ si_me.sin_port = htons(port);
+ si_me.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ if (bind(data_fd, (struct sockaddr *) &si_me, sizeof(si_me)) == 0){
// found one!
+ data_port = port;
+ break;
+ }
+ }
+
+ if (data_port == -1){
+ fprintf(stderr, "failed to bind to a local port\n");
+ return false;
+ }
+
+ printf("our data port = %d\n", data_port);
+
+ *ctrl_fd_ptr = ctrl_fd;
+ *data_fd_ptr = data_fd;
+ *data_port_ptr = data_port;
+
+ return true;
+}
+
+
+bool
+vrt::quadradio::send_rx_command(int ctrl_fd, bool start,
+ struct in_addr addr, int data_port,
+ int samples_per_pkt, int siggen_param)
+{
+ uint32_t cmd[7];
+ cmd[0] = htonl(0); // verb: set
+ cmd[1] = htonl(0); // id: rx_streaming
+ cmd[2] = htonl(start ? 1: 0); // start or stop?
+ cmd[3] = addr.s_addr; // ip address to send data to
(already network endian)
+ cmd[4] = htonl(data_port); // port to send data to
+ cmd[5] = htonl(samples_per_pkt);
+ cmd[6] = htonl(siggen_param);
+
+ int r = send(ctrl_fd, cmd, sizeof(cmd), 0);
+ if (r < 0){
+ perror("send");
+ return false;
+ }
+ if (r != sizeof(cmd)){
+ fprintf(stderr, "send: short return value. expected %zd, got %d\n",
sizeof(cmd), r);
+ return false;
+ }
+
+ return true;
+}
+
+bool
+vrt::quadradio::send_stop_rx_command(int ctrl_fd)
+{
+ struct in_addr in_addr;
+ in_addr.s_addr = 0;
+ return send_rx_command(ctrl_fd, false, in_addr, 0, 0, 0);
+}
Property changes on: gnuradio/branches/developers/eb/vrt/vrt/lib/quadradio.cc
___________________________________________________________________
Added: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r11064 - in gnuradio/branches/developers/eb/vrt: gr-vrt/src vrt/apps vrt/include/vrt vrt/lib,
eb <=