diff options
Diffstat (limited to 'usrp/host/apps-inband')
-rw-r--r-- | usrp/host/apps-inband/Makefile.am | 31 | ||||
-rw-r--r-- | usrp/host/apps-inband/gmac.cc | 690 | ||||
-rw-r--r-- | usrp/host/apps-inband/gmac.h | 91 | ||||
-rw-r--r-- | usrp/host/apps-inband/gmac.mbh | 146 | ||||
-rw-r--r-- | usrp/host/apps-inband/gmac_symbols.h | 47 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_gmac_tx.cc | 330 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_2rx.cc | 371 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_2tx.cc (renamed from usrp/host/apps-inband/test_usrp_inband_cs.cc) | 212 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_overrun.cc | 5 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_registers.cc | 2 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_rx.cc | 26 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_timestamps.cc | 2 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_tx.cc | 83 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_underrun.cc | 8 |
14 files changed, 526 insertions, 1518 deletions
diff --git a/usrp/host/apps-inband/Makefile.am b/usrp/host/apps-inband/Makefile.am index 86bb406181..f231b57f7a 100644 --- a/usrp/host/apps-inband/Makefile.am +++ b/usrp/host/apps-inband/Makefile.am @@ -30,46 +30,31 @@ AM_CPPFLAGS = \ bin_PROGRAMS = noinst_PROGRAMS = \ - test_usrp_inband_cs \ test_usrp_inband_ping \ test_usrp_inband_registers \ test_usrp_inband_rx \ + test_usrp_inband_2rx \ test_usrp_inband_tx \ + test_usrp_inband_2tx \ test_usrp_inband_timestamps \ test_usrp_inband_overrun \ test_usrp_inband_underrun \ - test_gmac_tx \ read_packets noinst_HEADERS = \ ui_nco.h \ - ui_sincos.h \ - gmac.h \ - gmac_symbols.h + ui_sincos.h -EXTRA_DIST = \ - gmac.mbh - -#------------------------------------------------------------------ -# Build gmac sources - -BUILT_SOURCES = \ - gmac_mbh.cc - -gmac_mbh.cc : gmac.mbh - $(COMPILE_MBH) $(srcdir)/gmac.mbh gmac_mbh.cc - - -test_usrp_inband_cs_SOURCES = test_usrp_inband_cs.cc ui_sincos.c -test_usrp_inband_cs_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - test_usrp_inband_ping_SOURCES = test_usrp_inband_ping.cc test_usrp_inband_ping_LDADD = $(USRP_LA) $(USRP_INBAND_LA) test_usrp_inband_tx_SOURCES = test_usrp_inband_tx.cc ui_sincos.c test_usrp_inband_tx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) +test_usrp_inband_2tx_SOURCES = test_usrp_inband_2tx.cc ui_sincos.c +test_usrp_inband_2tx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) + test_usrp_inband_timestamps_SOURCES = test_usrp_inband_timestamps.cc ui_sincos.c test_usrp_inband_timestamps_LDADD = $(USRP_LA) $(USRP_INBAND_LA) @@ -85,8 +70,8 @@ test_usrp_inband_underrun_LDADD = $(USRP_LA) $(USRP_INBAND_LA) test_usrp_inband_rx_SOURCES = test_usrp_inband_rx.cc ui_sincos.c test_usrp_inband_rx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) -test_gmac_tx_SOURCES = test_gmac_tx.cc gmac.cc gmac_mbh.cc ui_sincos.c -test_gmac_tx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) +test_usrp_inband_2rx_SOURCES = test_usrp_inband_2rx.cc ui_sincos.c +test_usrp_inband_2rx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) read_packets_SOURCES = read_packets.cc read_packets_LDADD = $(USRP_LA) $(USRP_INBAND_LA) diff --git a/usrp/host/apps-inband/gmac.cc b/usrp/host/apps-inband/gmac.cc deleted file mode 100644 index 107582e121..0000000000 --- a/usrp/host/apps-inband/gmac.cc +++ /dev/null @@ -1,690 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 <gmac.h> - -#include <mb_mblock.h> -#include <mb_runtime.h> -#include <mb_protocol_class.h> -#include <mb_exception.h> -#include <mb_msg_queue.h> -#include <mb_message.h> -#include <mb_msg_accepter.h> -#include <mb_class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <iostream> -#include <ui_nco.h> - -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_tx.h> -#include <symbols_usrp_rx.h> - -#include <gmac_symbols.h> - -static bool verbose = true; - -gmac::gmac(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(rt, instance_name, user_arg), - d_us_rx_chan(PMT_NIL), d_us_tx_chan(PMT_NIL) -{ - - // When the MAC layer is initialized, we must connect to the USRP and setup - // channels. We begin by defining ports to connect to the 'usrp_server' block - // and then initialize the USRP by opening it through the 'usrp_server.' - - // Initialize the ports - define_ports(); - - // Initialize the connection to the USRP - initialize_usrp(); - -} - -gmac::~gmac() -{ -} - -// The full functionality of GMAC is based on messages passed back and forth -// between the application and a physical layer and/or usrp_server. Each -// message triggers additional events, states, and messages to be sent. -void gmac::handle_message(mb_message_sptr msg) -{ - - // The MAC functionality is dispatched based on the event, which is the - // driving force of the MAC. The event can be anything from incoming samples - // to a message to change the carrier sense threshold. - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - pmt_t port_id = msg->port_id(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - pmt_t dict = PMT_NIL; - std::string error_msg; - - switch(d_state) { - - //---------------------------- INIT ------------------------------------// - // In the INIT state, there should be no messages across the ports. - case INIT: - error_msg = "no messages should be passed during the INIT state:"; - goto unhandled; - - //-------------------------- OPENING USRP -------------------------------// - // In this state we expect a response from usrp_server over the CS channel - // as to whether or not the opening of the USRP was successful. If so, we - // switch states to allocating the channels for use. - case OPENING_USRP: - - if(pmt_eq(event, s_response_open) - && pmt_eq(d_us_cs->port_symbol(), port_id)) { - - status = pmt_nth(1, data); // PMT_T or PMT_F - - if(pmt_eq(status, PMT_T)) { // on success, allocate channels! - allocate_channels(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - - } - - goto unhandled; // all other messages not handled in this state - - //------------------------ ALLOCATING CHANNELS --------------------------// - // When allocating channels, we need to wait for 2 responses from USRP - // server: one for TX and one for RX. Both are initialized to NIL so we - // know to continue to the next state once both are set. - case ALLOCATING_CHANNELS: - - // ************* TX ALLOCATION RESPONSE ***************** // - if(pmt_eq(event, s_response_allocate_channel) - && pmt_eq(d_us_tx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - if(pmt_eq(status, PMT_T)) { // extract channel on success - d_us_tx_chan = pmt_nth(2, data); - - if(verbose) - std::cout << "[GMAC] Received TX allocation" - << " on channel " << d_us_tx_chan << std::endl; - - // If the RX has also been allocated already, we can continue - if(!pmt_eqv(d_us_rx_chan, PMT_NIL)) { - //enter_receiving(); - initialize_gmac(); - } - - return; - } - else { // TX allocation failed - error_msg = "failed to allocate TX channel:"; - goto bail; - } - } - - // ************* RX ALLOCATION RESPONSE ****************// - if(pmt_eq(event, s_response_allocate_channel) - && pmt_eq(d_us_rx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - if(pmt_eq(status, PMT_T)) { - - d_us_rx_chan = pmt_nth(2, data); - - if(verbose) - std::cout << "[GMAC] Received RX allocation" - << " on channel " << d_us_rx_chan << std::endl; - - // If the TX has also been allocated already, we can continue - if(!pmt_eqv(d_us_tx_chan, PMT_NIL)) { - //enter_receiving(); - initialize_gmac(); - } - - return; - } - else { // RX allocation failed - error_msg = "failed to allocate RX channel:"; - goto bail; - } - } - - goto unhandled; - - //----------------------------- INIT GMAC --------------------------------// - // In the INIT_GMAC state, now that the USRP is initialized we can do things - // like right the carrier sense threshold to the FPGA register. - case INIT_GMAC: - goto unhandled; - - - //----------------------------- IDLE ------------------------------------// - // In the idle state the MAC is not quite 'idle', it is just not doing - // anything specific. It is still being passive with data between the - // application and the lower layer. - case IDLE: - - //-------- TX PORT ----------------------------------------------------// - if(pmt_eq(d_tx->port_symbol(), port_id)) { - - //-------- INCOMING PACKET ------------------------------------------// - if(pmt_eq(event, s_cmd_tx_pkt)) { - handle_cmd_tx_pkt(data); - return; - } - - } - - //--------- USRP TX PORT ----------------------------------------------// - if(pmt_eq(d_us_tx->port_symbol(), port_id)) { - - //-------- INCOMING PACKET RESPONSE ---------------------------------// - if(pmt_eq(event, s_response_xmit_raw_frame)) { - handle_response_xmit_raw_frame(data); - return; - } - - } - - //--------- CS PORT ---------------------------------------------------// - if(pmt_eq(d_cs->port_symbol(), port_id)) { - - //------- ENABLE CARRIER SENSE --------------------------------------// - if(pmt_eq(event, s_cmd_carrier_sense_enable)) { - handle_cmd_carrier_sense_enable(data); - return; - } - - //------- CARRIER SENSE THRESHOLD -----------------------------------// - if(pmt_eq(event, s_cmd_carrier_sense_threshold)) { - handle_cmd_carrier_sense_threshold(data); - return; - } - - //------- CARRIER SENSE DEADLINE ------------------------------------// - if(pmt_eq(event, s_cmd_carrier_sense_deadline)) { - handle_cmd_carrier_sense_deadline(data); - return; - } - - //------- DISABLE CARRIER SENSE -------------------------------------// - if(pmt_eq(event, s_cmd_carrier_sense_disable)) { - handle_cmd_carrier_sense_disable(data); - return; - } - - } - - goto unhandled; - - //------------------------ CLOSING CHANNELS -----------------------------// - case CLOSING_CHANNELS: - - if (pmt_eq(event, s_response_deallocate_channel) - && pmt_eq(d_us_tx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - if(pmt_eq(status, PMT_T)) { - d_us_tx_chan = PMT_NIL; - - if(verbose) - std::cout << "[GMAC] Received TX deallocation\n"; - - // If the RX is also deallocated, we can close the USRP - if(pmt_eq(d_us_rx_chan, PMT_NIL)) - close_usrp(); - - return; - - } else { - - error_msg = "failed to deallocate TX channel:"; - goto bail; - - } - } - - if (pmt_eq(event, s_response_deallocate_channel) - && pmt_eq(d_us_rx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If successful, set the port to NIL - if(pmt_eq(status, PMT_T)) { - d_us_rx_chan = PMT_NIL; - - if(verbose) - std::cout << "[GMAC] Received RX deallocation\n"; - - // If the TX is also deallocated, we can close the USRP - if(pmt_eq(d_us_tx_chan, PMT_NIL)) - close_usrp(); - - return; - - } else { - - error_msg = "failed to deallocate RX channel:"; - goto bail; - - } - } - - goto unhandled; - - //-------------------------- CLOSING USRP -------------------------------// - case CLOSING_USRP: - goto unhandled; - - } - - // An error occured, print it, and shutdown all m-blocks - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - // Received an unhandled message for a specific state - unhandled: - if(0 && verbose && !pmt_eq(event, pmt_intern("%shutdown"))) - std::cout << "[GMAC] unhandled msg: " << msg - << "in state "<< d_state << std::endl; -} - -// The MAC layer connects to 'usrp_server' which has a control/status channel, -// a TX, and an RX port. The MAC layer can then relay TX/RX data back and -// forth to the application, or a physical layer once available. -void gmac::define_ports() -{ - // Ports we use to connect to usrp_server - d_us_tx = define_port("us-tx0", "usrp-tx", false, mb_port::INTERNAL); - d_us_rx = define_port("us-rx0", "usrp-rx", false, mb_port::INTERNAL); - d_us_cs = define_port("us-cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Ports applications used to connect to us - d_tx = define_port("tx0", "gmac-tx", true, mb_port::EXTERNAL); - d_rx = define_port("rx0", "gmac-rx", true, mb_port::EXTERNAL); - d_cs = define_port("cs", "gmac-cs", true, mb_port::EXTERNAL); -} - -// To initialize the USRP we must pass several parameters to 'usrp_server' such -// as the RBF to use, and the interpolation/decimation rate. The MAC layer will -// then pass these parameters to the block with a message to establish the -// connection to the USRP. -void gmac::initialize_usrp() -{ - - if(verbose) - std::cout << "[GMAC] Initializing USRP\n"; - - // The initialization parameters are passed to usrp_server via a PMT - // dictionary. - pmt_t usrp_dict = pmt_make_dict(); - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("test2.rbf")); - - pmt_dict_set(usrp_dict, - pmt_intern("interp-tx"), - pmt_from_long(128)); - - pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(16)); - - // Center frequency - pmt_dict_set(usrp_dict, - pmt_intern("rf-freq"), - pmt_from_long((long)10e6)); - - // Default is to use USRP considered '0' (incase of multiple) - d_which_usrp = pmt_from_long(0); - - define_component("USRP-SERVER", "usrp_server", usrp_dict); - - connect("self", "us-tx0", "USRP-SERVER", "tx0"); - connect("self", "us-rx0", "USRP-SERVER", "rx0"); - connect("self", "us-cs", "USRP-SERVER", "cs"); - - // Finally, enter the OPENING_USRP state by sending a request to open the - // USRP. - open_usrp(); - -} - -// In the initialization state of the MAC layer we set default values for -// several functionalities. -void gmac::initialize_gmac() -{ - - // The initial state is the INIT state. - d_state = INIT_GMAC; - - // Set carrier sense to enabled by default with the specified threshold and - // the deadline to 0 -- which is wait forever. - set_carrier_sense(true, 25, 0, PMT_NIL); - - // Can now notify the application that we are initialized - d_cs->send(s_response_gmac_initialized, - pmt_list2(PMT_NIL, PMT_T)); - - // The MAC enters an IDLE state where it waits for messages and dispatches - // based on them - enter_idle(); -} - -// Method for setting the carrier sense and an associated threshold which is -// written to a register on the FPGA, which it will read if the CS flag is set -// and perform carrier sense based on. -// -// We currently do not wait for the successful response for the write to -// register command, we assume it will succeed else the MAC must -void gmac::set_carrier_sense(bool toggle, long threshold, long deadline, pmt_t invocation) -{ - d_carrier_sense = toggle; - - // Only waste the bandwidth and processing of a C/S packet if needed - if(threshold != d_cs_thresh) { - d_us_tx->send(s_cmd_to_control_channel, // C/S packet - pmt_list2(invocation, // invoc handle - pmt_list1( - pmt_list2(s_op_write_reg, - pmt_list2( - pmt_from_long(REG_CS_THRESH), - pmt_from_long(threshold)))))); - d_cs_thresh = threshold; - - if(verbose) - std::cout << "[GMAC] Changing CS threshold: " << d_cs_thresh << std::endl; - } - - if(deadline != d_cs_deadline) { - d_us_tx->send(s_cmd_to_control_channel, // C/S packet - pmt_list2(invocation, // invoc handle - pmt_list1( - pmt_list2(s_op_write_reg, - pmt_list2( - pmt_from_long(REG_CS_DEADLINE), - pmt_from_long(deadline)))))); - d_cs_deadline = deadline; - - if(verbose) - std::cout << "[GMAC] Changing CS deadline: " << d_cs_deadline << std::endl; - } - - if(verbose) - std::cout << "[GMAC] Setting carrier sense to " << toggle << std::endl; -} - -// The following sends a command to open the USRP, which will upload the -// specified RBF when creating the instance of the USRP server and set all other -// relevant parameters. -void gmac::open_usrp() -{ - d_state = OPENING_USRP; - - d_us_cs->send(s_cmd_open, pmt_list2(PMT_NIL, d_which_usrp)); - - if(verbose) - std::cout << "[GMAC] Opening USRP " - << d_which_usrp << std::endl; -} - -// Before sending the close to the USRP we wait a couple seconds to let any data -// through the USB exit, else a bug in the driver will kick an error and cause -// an abnormal termination. -void gmac::close_usrp() -{ - d_state = CLOSING_USRP; - - sleep(2); - - d_us_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); -} - -// RX and TX channels must be allocated so that the USRP server can -// properly share bandwidth across multiple USRPs. No commands will be -// successful to the USRP through the USRP server on the TX or RX channels until -// a bandwidth allocation has been received. -void gmac::allocate_channels() -{ - d_state = ALLOCATING_CHANNELS; - - if(verbose) - std::cout << "[GMAC] Sending channel allocation requests\n"; - - long capacity = (long) 16e6; - d_us_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_us_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - -} - -// Before closing the USRP connection, we deallocate our channels so that the -// capacity can be reused. -void gmac::close_channels() -{ - d_state = CLOSING_CHANNELS; - - d_us_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_us_tx_chan)); - d_us_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_us_rx_chan)); - - if(verbose) - std::cout << "[GMAC] Closing channels...\n"; -} - -// Used to enter the receiving state -void gmac::enter_receiving() -{ - d_us_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_F, - d_us_rx_chan)); - - if(verbose) - std::cout << "[GMAC] Started RX sample stream\n"; -} - -// A simple idle state, nothing more to it. -void gmac::enter_idle() -{ - d_state = IDLE; -} - -// Handles the transmission of a pkt from the application. The invocation -// handle is passed on but a response is not given back to the application until -// the response is passed from usrp_server. This ensures that the MAC passes -// back the success or failure. Furthermore, the MAC could decide to retransmit -// on a failure based on the result of the packet transmission. -// -// This should eventually be connected to a physically layer rather than -// directly to usrp_server. (d_us_tx should be replaced with a different -// connection) -void gmac::handle_cmd_tx_pkt(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t dst = pmt_nth(1, data); - pmt_t samples = pmt_nth(2, data); - pmt_t pkt_properties = pmt_nth(3, data); - - pmt_t us_tx_properties = pmt_make_dict(); - - // Set the packet to be carrier sensed? - if(carrier_sense_pkt(pkt_properties)) - pmt_dict_set(us_tx_properties, - pmt_intern("carrier-sense"), - PMT_T); - - pmt_t timestamp = pmt_from_long(0xffffffff); // NOW - - // Construct the proper message for USRP server - d_us_tx->send(s_cmd_xmit_raw_frame, - pmt_list5(invocation_handle, - d_us_tx_chan, - samples, - timestamp, - us_tx_properties)); - - if(verbose && 0) - std::cout << "[GMAC] Transmitted packet\n"; -} - -// Handles a response from the USRP server about the transmission of a frame, -// whether it was successful or failed. This should eventually be replaced with -// a response from the PHY layer. This is where a retransmit could be -// implemented. -void gmac::handle_response_xmit_raw_frame(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - - d_tx->send(s_response_tx_pkt, - pmt_list2(invocation_handle, - status)); -} - -// This method determines whether carrier sense should be enabled based on two -// properties. The first is the MAC setting, which the user can set to carrier -// sense packets by default or not. The second is a per packet setting, which -// can be used to override the MAC setting for the given packet only. -bool gmac::carrier_sense_pkt(pmt_t pkt_properties) -{ - // First we extract the per packet properties to check the per packet setting - // if it exists - if(pmt_is_dict(pkt_properties)) { - - if(pmt_t pkt_cs = pmt_dict_ref(pkt_properties, - pmt_intern("carrier-sense"), - PMT_NIL)) { - // If the per packet property says true, enable carrier sense regardless - // of the MAC setting - if(pmt_eqv(pkt_cs, PMT_T)) - return true; - // If the per packet setting says false, disable carrier sense regardless - // of the MAC setting - else if(pmt_eqv(pkt_cs, PMT_F)) - return false; - } - } - - // If we've hit this point, the packet properties did not state whether - // carrier sense should be used or not, so we use the MAC setting - if(d_carrier_sense) - return true; - else - return false; - -} - -// This method is envoked by an incoming cmd-enable-carrier-sense signal on the -// C/S port. It can be used to re-adjust the threshold or simply enabled -// carrier sense. When a threshold is not provided, the MAC will use an -// averaging algorithm to determine the threshold (in the future). -void gmac::handle_cmd_carrier_sense_enable(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t threshold = pmt_nth(1, data); - pmt_t deadline = pmt_nth(2, data); - long l_threshold, l_deadline; - - // FIXME: for now, if threshold is NIL, we do not change the threshold. - // This should be replaced with an averaging algorithm - if(pmt_eqv(threshold, PMT_NIL)) - l_threshold = d_cs_thresh; - else - l_threshold = pmt_to_long(threshold); - - // If the deadline is NIL, we do not change the value - if(pmt_eqv(threshold, PMT_NIL)) - l_deadline = d_cs_deadline; - else - l_deadline = pmt_to_long(deadline); - - set_carrier_sense(true, l_threshold, l_deadline, invocation_handle); -} - -// This method is called when an incoming disable carrier sense command is sent -// over the control status channel. It so far does not ellicit a response, this -// needs to be added correctly. It needs to wait for the response for the C/S -// packet from usrp_server. -void gmac::handle_cmd_carrier_sense_disable(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - - // We don't change the threshold, we leave it as is because the application - // did not request that it changes, only to disable carrier sense. - set_carrier_sense(false, d_cs_thresh, d_cs_deadline, invocation_handle); -} - -// When the app requests that the threshold changes, the state of the carrier -// sense should not change. If it was enabled, it should remain enabled. -// Likewise if it was disabled. The deadline value should also remain -// unchanged. -void gmac::handle_cmd_carrier_sense_threshold(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t threshold = pmt_nth(1, data); - long l_threshold; - - // FIXME: for now, if threshold is NIL, we do not change the threshold. - // This should be replaced with an averaging algorithm - if(pmt_eqv(threshold, PMT_NIL)) - l_threshold = d_cs_thresh; - else - l_threshold = pmt_to_long(threshold); - - set_carrier_sense(d_carrier_sense, l_threshold, d_cs_deadline, invocation_handle); -} - -// Ability to change the deadline using a C/S packet. The state of all other -// carrier sense parameters should not change. -void gmac::handle_cmd_carrier_sense_deadline(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t deadline = pmt_nth(1, data); - long l_deadline; - - // If the deadline passed is NIL, do *not* change the value. - if(pmt_eqv(deadline, PMT_NIL)) - l_deadline = d_cs_deadline; - else - l_deadline = pmt_to_long(deadline); - - set_carrier_sense(d_carrier_sense, d_cs_thresh, l_deadline, invocation_handle); -} - -REGISTER_MBLOCK_CLASS(gmac); diff --git a/usrp/host/apps-inband/gmac.h b/usrp/host/apps-inband/gmac.h deleted file mode 100644 index a6d0bcb128..0000000000 --- a/usrp/host/apps-inband/gmac.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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_GMAC_H -#define INCLUDED_GMAC_H - -#include <mb_mblock.h> - -class gmac; - -class gmac : public mb_mblock -{ - - // The state is used to determine how to handle incoming messages and of - // course, the state of the MAC protocol. - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNELS, - INIT_GMAC, - IDLE, - CLOSING_CHANNELS, - CLOSING_USRP, - }; - state_t d_state; - - // Ports used for applications to connect to this block - mb_port_sptr d_tx, d_rx, d_cs; - - // Ports to connect to usrp_server (us) - mb_port_sptr d_us_tx, d_us_rx, d_us_cs; - - // The channel numbers assigned for use - pmt_t d_us_rx_chan, d_us_tx_chan; - - pmt_t d_which_usrp; - - bool d_carrier_sense; - long d_cs_thresh; - long d_cs_deadline; - - enum FPGA_REGISTERS { - REG_CS_THRESH = 1, - REG_CS_DEADLINE = 2 - }; - - public: - gmac(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg); - ~gmac(); - void handle_message(mb_message_sptr msg); - - private: - void define_ports(); - void initialize_usrp(); - void initialize_gmac(); - void set_carrier_sense(bool toggle, long threshold, long deadline, pmt_t invocation); - void allocate_channels(); - void enter_receiving(); - void enter_idle(); - void close_channels(); - void open_usrp(); - void close_usrp(); - void handle_cmd_tx_pkt(pmt_t data); - void handle_response_xmit_raw_frame(pmt_t data); - bool carrier_sense_pkt(pmt_t pkt_properties); - void handle_cmd_carrier_sense_enable(pmt_t data); - void handle_cmd_carrier_sense_threshold(pmt_t data); - void handle_cmd_carrier_sense_disable(pmt_t data); - void handle_cmd_carrier_sense_deadline(pmt_t data); - -}; - -#endif // INCLUDED_GMAC_H diff --git a/usrp/host/apps-inband/gmac.mbh b/usrp/host/apps-inband/gmac.mbh deleted file mode 100644 index 4fa9a062fd..0000000000 --- a/usrp/host/apps-inband/gmac.mbh +++ /dev/null @@ -1,146 +0,0 @@ -;; -*- scheme -*- ; not really, but tells emacs how to format this -;; -;; Copyright 2007 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 2, 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. -;; - -;; ---------------------------------------------------------------- -;; This is an mblock header file -;; -;; The format is very much a work-in-progress. -;; It'll be compiled to C++. -;; ---------------------------------------------------------------- - -;; In the outgoing messages described below, invocation-handle is an -;; identifier provided by the client to tag the method invocation. -;; The identifier will be returned with the response, to provide the -;; client with a mechanism to match asynchronous responses with the -;; commands that generate them. The value of the invocation-handle is -;; opaque the the server, and is not required by the server to be -;; unique. -;; -;; In the incoming messages described below, invocation-handle is the -;; identifier provided by the client in the prompting invocation. The -;; identifier is returned with the response, so that the client has a -;; mechanism to match asynchronous responses with the commands that -;; generated them. -;; -;; status is either #t, indicating success, or a symbol indicating an error. -;; All symbol's names shall begin with %error- - - -;; ---------------------------------------------------------------- -;; gmac-tx -;; -;; The protocol class is defined from the client's point-of-view. -;; (The client port is unconjugated, the server port is conjugated.) - -(define-protocol-class gmac-tx - - (:outgoing - - ;; Transmitting packets can carry an invocation handle so the application - ;; can get TX results on specific packets, such as whether a packet tagged - ;; as #1 was successfully transmitted or not. This would allow the - ;; application to implement something sliding window like. - ;; - ;; 'dst' is the destination MAC address (given a MAC addressing scheme) - ;; - ;; 'data' will be treated transparently and passed on as samples. - ;; - ;; 'properties' can be used in the future to set per-packet options such as - ;; carrier sense overriding functionality. - (cmd-tx-pkt invocation-handle dst data properties) - - ) - - (:incoming - - ;; The response will carry the same invocation-handle passed with cmd-tx-pkt - (response-tx-pkt invocation-handle status) - - ) - ) - -;; ---------------------------------------------------------------- -;; gmac-rx -;; -;; The protocol class is defined from the client's point-of-view. -;; (The client port is unconjugated, the server port is conjugated.) - -(define-protocol-class gmac-rx - - (:outgoing - - ;; There are currently no outgoing commands, I believe that the RX - ;; should always be enabled, there is no point in having an enable/disable - ;; that I can see. - - ) - - (:incoming - - ;; Contains packets decoded by the MAC destined for this machine, sent by - ;; the specified address. - (response-rx-pkt invocation-handle src data) - - ) - ) - - -;; ---------------------------------------------------------------- -;; gmac-cs -;; -;; The protocol class is defined from the client's point-of-view. -;; (The client port is unconjugated, the server port is conjugated.) -;; -;; This defines a control/status interface to the MAC layer, for control over -;; functionality such as carrier sense and future functionality such as channel -;; hopping. - - -(define-protocol-class gmac-cs - - (:outgoing - - ;; Threshold represents the carrier sense threshold based on the digital - ;; reading out of the DAC. If the threshold is set to PMT_NIL then the - ;; MAC will use averaging to determine an appropriate threshold. - (cmd-carrier-sense-enable invocation-handle threshold deadline) - (cmd-carrier-sense-threshold invocation-handle threshold) - (cmd-carrier-sense-disable invocation-handle) - - ;; Setting the number of fast transmission retries on a failure before - ;; reporting a loss back to the application. - (cmd-set-tx-retries invocation-handle retries) - - ) - - (:incoming - - (response-gmac-initialized invocation-handle status) - - (response-carrier-sense-enable invocation-handle status) - (response-carrier-sense-threshold invocation-handle status) - (response-carrier-sense-deadline invocation-handle status) - (response-carrier-sense-disable invocation-handle status) - - (response-set-tx-retries invocation-handle status) - - ) - ) diff --git a/usrp/host/apps-inband/gmac_symbols.h b/usrp/host/apps-inband/gmac_symbols.h deleted file mode 100644 index 0d7804be15..0000000000 --- a/usrp/host/apps-inband/gmac_symbols.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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_GMAC_SYMBOLS_H -#define INCLUDED_GMAC_SYMBOLS_H - -#include <pmt.h> - -// TX -static pmt_t s_cmd_tx_pkt = pmt_intern("cmd-tx-pkt"); -static pmt_t s_response_tx_pkt = pmt_intern("response-tx-pkt"); - -// RX -static pmt_t s_response_rx_pkt = pmt_intern("response-rx-pkt"); - -// CS -static pmt_t s_cmd_carrier_sense_enable = pmt_intern("cmd-carrier-sense-enable"); -static pmt_t s_cmd_carrier_sense_threshold = pmt_intern("cmd-carrier-sense-threshold"); -static pmt_t s_cmd_carrier_sense_deadline = pmt_intern("cmd-carrier-sense-deadline"); -static pmt_t s_cmd_carrier_sense_disable = pmt_intern("cmd-carrier-sense-disable"); -static pmt_t s_cmd_set_tx_retries = pmt_intern("cmd-set-tx-retries"); -static pmt_t s_response_gmac_initialized = pmt_intern("response-gmac-initialized"); -static pmt_t s_response_carrier_sense_enable = pmt_intern("response-carrier-sense-enable"); -static pmt_t s_response_carrier_sense_treshold = pmt_intern("response-carrier-sense-threshold"); -static pmt_t s_response_carrier_sense_deadline = pmt_intern("response-carrier-sense-deadline"); -static pmt_t s_response_carrier_sense_disable = pmt_intern("response-carrier-sense-disable"); -static pmt_t s_response_set_tx_retries = pmt_intern("response-set-tx-retries"); - -#endif // INCLUDED_GMAC_SYMBOLS_H diff --git a/usrp/host/apps-inband/test_gmac_tx.cc b/usrp/host/apps-inband/test_gmac_tx.cc deleted file mode 100644 index 74f16c669a..0000000000 --- a/usrp/host/apps-inband/test_gmac_tx.cc +++ /dev/null @@ -1,330 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 <mb_mblock.h> -#include <mb_runtime.h> -#include <mb_protocol_class.h> -#include <mb_exception.h> -#include <mb_msg_queue.h> -#include <mb_message.h> -#include <mb_msg_accepter.h> -#include <mb_class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <iostream> - -#include <ui_nco.h> -#include <gmac.h> -#include <gmac_symbols.h> - -static bool verbose = true; - -class test_gmac_tx : public mb_mblock -{ - mb_port_sptr d_tx; - mb_port_sptr d_cs; - pmt_t d_tx_chan; // returned tx channel handle - - enum state_t { - INIT, - TRANSMITTING, - }; - - state_t d_state; - long d_nsamples_to_send; - long d_nsamples_xmitted; - long d_nframes_xmitted; - long d_samples_per_frame; - bool d_done_sending; - - // for generating sine wave output - ui_nco<float,float> d_nco; - double d_amplitude; - - public: - test_gmac_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_gmac_tx(); - void handle_message(mb_message_sptr msg); - - protected: - void open_usrp(); - void close_usrp(); - void allocate_channel(); - void send_packets(); - void enter_transmitting(); - void build_and_send_next_frame(); - void handle_xmit_response(pmt_t invocation_handle); - void enter_closing_channel(); -}; - -test_gmac_tx::test_gmac_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_state(INIT), d_nsamples_to_send((long) 40e6), - d_nsamples_xmitted(0), - d_nframes_xmitted(0), - d_samples_per_frame((long)(126 * 4)), // full packet - d_done_sending(false), - d_amplitude(16384) -{ - - define_component("GMAC", "gmac", PMT_NIL); - d_tx = define_port("tx0", "gmac-tx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "gmac-cs", false, mb_port::INTERNAL); - - connect("self", "tx0", "GMAC", "tx0"); - connect("self", "cs", "GMAC", "cs"); - - // initialize NCO - double freq = 100e3; - int interp = 32; // 32 -> 4MS/s - double sample_rate = 128e6 / interp; - d_nco.set_freq(2*M_PI * freq/sample_rate); - -} - -test_gmac_tx::~test_gmac_tx() -{ -} - -void -test_gmac_tx::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - pmt_t port_id = msg->port_id(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - pmt_t dict = PMT_NIL; - std::string error_msg; - - // Dispatch based on state - switch(d_state) { - - //------------------------------ INIT ---------------------------------// - // When GMAC is done initializing, it will send a response - case INIT: - - if(pmt_eq(event, s_response_gmac_initialized)) { - handle = pmt_nth(0, data); - status = pmt_nth(1, data); - - if(pmt_eq(status, PMT_T)) { - enter_transmitting(); - return; - } - else { - error_msg = "error initializing gmac:"; - goto bail; - } - } - goto unhandled; - - //-------------------------- TRANSMITTING ----------------------------// - // In the transmit state we count the number of underruns received and - // ballpark the number with an expected count (something >1 for starters) - case TRANSMITTING: - - // Check that the transmits are OK - if (pmt_eq(event, s_response_tx_pkt)){ - handle = pmt_nth(0, data); - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - handle_xmit_response(handle); - return; - } - else { - error_msg = "bad response-tx-pkt:"; - goto bail; - } - } - - goto unhandled; - - } - - // An error occured, print it, and shutdown all m-blocks - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - // Received an unhandled message for a specific state - unhandled: - if(verbose && !pmt_eq(event, pmt_intern("%shutdown"))) - std::cout << "[TEST_GMAC_TX] unhandled msg: " << msg - << "in state "<< d_state << std::endl; -} - -void -test_gmac_tx::enter_transmitting() -{ - d_state = TRANSMITTING; - d_nsamples_xmitted = 0; - - d_cs->send(s_cmd_carrier_sense_deadline, - pmt_list2(PMT_NIL, - pmt_from_long(50000000))); - - build_and_send_next_frame(); // fire off 4 to start pipeline - build_and_send_next_frame(); - build_and_send_next_frame(); - build_and_send_next_frame(); -} - -void -test_gmac_tx::build_and_send_next_frame() -{ - // allocate the uniform vector for the samples - // FIXME perhaps hold on to this between calls - -#if 0 - long nsamples_this_frame = - std::min(d_nsamples_to_send - d_nsamples_xmitted, - d_samples_per_frame); -#else - long nsamples_this_frame = d_samples_per_frame; -#endif - - if (nsamples_this_frame == 0){ - d_done_sending = true; - return; - } - - - size_t nshorts = 2 * nsamples_this_frame; // 16-bit I & Q - pmt_t uvec = pmt_make_s16vector(nshorts, 0); - size_t ignore; - int16_t *samples = pmt_s16vector_writeable_elements(uvec, ignore); - - // fill in the complex sinusoid - for (int i = 0; i < nsamples_this_frame; i++){ - - if (1){ - gr_complex s; - d_nco.sincos(&s, 1, d_amplitude); - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - else { - gr_complex s(d_amplitude, d_amplitude); - - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - } - - // Per packet properties - pmt_t tx_properties = pmt_make_dict(); - - if(d_nframes_xmitted > 25000) { - pmt_dict_set(tx_properties, - pmt_intern("carrier-sense"), - PMT_F); - } - - if(d_nframes_xmitted > 35000) { - pmt_dict_set(tx_properties, - pmt_intern("carrier-sense"), - PMT_NIL); - } - - if(d_nframes_xmitted == 45000) { - d_cs->send(s_cmd_carrier_sense_threshold, - pmt_list2(PMT_NIL, - pmt_from_long(100))); - } - - if(d_nframes_xmitted == 60000) { - d_cs->send(s_cmd_carrier_sense_threshold, - pmt_list2(PMT_NIL, - pmt_from_long(25))); - } - - if(d_nframes_xmitted == 75000) { - d_cs->send(s_cmd_carrier_sense_disable, - pmt_list1(PMT_NIL)); - } - - if(d_nframes_xmitted > 90000 && d_nframes_xmitted < 110000) { - pmt_dict_set(tx_properties, - pmt_intern("carrier-sense"), - PMT_T); - } - - if(d_nframes_xmitted > 110000) { - - if(d_nframes_xmitted % 100 == 0) - pmt_dict_set(tx_properties, - pmt_intern("carrier-sense"), - PMT_T); -} - - pmt_t timestamp = pmt_from_long(0xffffffff); // NOW - d_tx->send(s_cmd_tx_pkt, - pmt_list4(PMT_NIL, // invocation-handle - PMT_NIL, // destination - uvec, // the samples - tx_properties)); // per pkt properties - - d_nsamples_xmitted += nsamples_this_frame; - d_nframes_xmitted++; - - if(verbose && 0) - std::cout << "[TEST_GMAC_TX] Transmitted frame\n"; -} - - -void -test_gmac_tx::handle_xmit_response(pmt_t handle) -{ - if (d_done_sending && - pmt_to_long(handle) == (d_nframes_xmitted - 1)){ - // We're done sending and have received all responses - } - - build_and_send_next_frame(); -} - -REGISTER_MBLOCK_CLASS(test_gmac_tx); - - -// ---------------------------------------------------------------- - -int -main (int argc, char **argv) -{ - // handle any command line args here - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("test_gmac_tx", "test_gmac_tx", PMT_F, &result); -} diff --git a/usrp/host/apps-inband/test_usrp_inband_2rx.cc b/usrp/host/apps-inband/test_usrp_inband_2rx.cc new file mode 100644 index 0000000000..da8d7271c3 --- /dev/null +++ b/usrp/host/apps-inband/test_usrp_inband_2rx.cc @@ -0,0 +1,371 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 <mb_mblock.h> +#include <mb_runtime.h> +#include <mb_runtime_nop.h> // QA only +#include <mb_protocol_class.h> +#include <mb_exception.h> +#include <mb_msg_queue.h> +#include <mb_message.h> +#include <mb_mblock_impl.h> +#include <mb_msg_accepter.h> +#include <mb_class_registry.h> +#include <pmt.h> +#include <stdio.h> +#include <string.h> +#include <iostream> +#include <fstream> + +// Include the symbols needed for communication with USRP server +#include <symbols_usrp_server_cs.h> +#include <symbols_usrp_channel.h> +#include <symbols_usrp_low_level_cs.h> +#include <symbols_usrp_rx.h> + +static bool verbose = true; + +class test_usrp_rx : public mb_mblock +{ + mb_port_sptr d_rx; + mb_port_sptr d_cs; + pmt_t d_rx_chan0, d_rx_chan1; + + enum state_t { + INIT, + OPENING_USRP, + ALLOCATING_CHANNEL, + RECEIVING, + CLOSING_CHANNEL, + CLOSING_USRP, + }; + + state_t d_state; + + std::ofstream d_ofile; + + long d_samples_recvd; + long d_samples_to_recv; + + public: + test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); + ~test_usrp_rx(); + void initial_transition(); + void handle_message(mb_message_sptr msg); + + protected: + void open_usrp(); + void close_usrp(); + void allocate_channel(); + void send_packets(); + void enter_receiving(); + void build_and_send_next_frame(); + void handle_response_recv_raw_samples(pmt_t invocation_handle); + void enter_closing_channel(); +}; + +test_usrp_rx::test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) + : mb_mblock(runtime, instance_name, user_arg), + d_rx_chan0(PMT_NIL), d_rx_chan1(PMT_NIL), + d_samples_recvd(0), + d_samples_to_recv(20e6) +{ + d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); + d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); + + // Pass a dictionary to usrp_server which specifies which interface to use, the stub or USRP + pmt_t usrp_dict = pmt_make_dict(); + + // To test the application without a USRP + bool fake_usrp_p = false; + if(fake_usrp_p) { + pmt_dict_set(usrp_dict, + pmt_intern("fake-usrp"), + PMT_T); + } + + // Specify the RBF to use + pmt_dict_set(usrp_dict, + pmt_intern("rbf"), + pmt_intern("inband_2rxhb_2tx.rbf")); + + pmt_dict_set(usrp_dict, + pmt_intern("decim-rx"), + pmt_from_long(64)); + + define_component("server", "usrp_server", usrp_dict); + + connect("self", "rx0", "server", "rx0"); + connect("self", "cs", "server", "cs"); + +} + +test_usrp_rx::~test_usrp_rx() +{ +} + +void +test_usrp_rx::initial_transition() +{ + open_usrp(); +} + +void +test_usrp_rx::handle_message(mb_message_sptr msg) +{ + pmt_t event = msg->signal(); + pmt_t data = msg->data(); + + pmt_t handle = PMT_F; + pmt_t status = PMT_F; + std::string error_msg; + + switch(d_state){ + + //----------------------------- OPENING_USRP ----------------------------// + // We only expect a response from opening the USRP which should be succesful + // or failed. + case OPENING_USRP: + if (pmt_eq(event, s_response_open)){ + status = pmt_nth(1, data); + if (pmt_eq(status, PMT_T)){ + allocate_channel(); + return; + } + else { + error_msg = "failed to open usrp:"; + goto bail; + } + } + goto unhandled; + + //----------------------- ALLOCATING CHANNELS --------------------// + // Allocate an RX channel to perform the overrun test. + case ALLOCATING_CHANNEL: + if (pmt_eq(event, s_response_allocate_channel)){ + status = pmt_nth(1, data); + if(pmt_eqv(d_rx_chan0, PMT_NIL)) + d_rx_chan0 = pmt_nth(2, data); + else + d_rx_chan1 = pmt_nth(2, data); + + if (pmt_eq(status, PMT_T) && !pmt_eqv(d_rx_chan1, PMT_NIL)){ + enter_receiving(); + return; + } + else if(pmt_eq(status, PMT_F)){ + error_msg = "failed to allocate channel:"; + goto bail; + } + return; + } + goto unhandled; + + //--------------------------- RECEIVING ------------------------------// + // In the receiving state, we receive samples until the specified amount + // while counting the number of overruns. + case RECEIVING: + if (pmt_eq(event, s_response_recv_raw_samples)){ + status = pmt_nth(1, data); + + if (pmt_eq(status, PMT_T)){ + handle_response_recv_raw_samples(data); + return; + } + else { + error_msg = "bad response-xmit-raw-frame:"; + goto bail; + } + } + goto unhandled; + + //------------------------- CLOSING CHANNEL ----------------------------// + // Check deallocation response for the RX channel + case CLOSING_CHANNEL: + if (pmt_eq(event, s_response_deallocate_channel)){ + status = pmt_nth(1, data); + + if (pmt_eq(status, PMT_T)){ + close_usrp(); + return; + } + else { + error_msg = "failed to deallocate channel:"; + goto bail; + } + } + + // Alternately, we ignore all response recv samples while waiting for the + // channel to actually close + if (pmt_eq(event, s_response_recv_raw_samples)) + return; + + goto unhandled; + + //--------------------------- CLOSING USRP ------------------------------// + // Once we have received a successful USRP close response, we shutdown all + // mblocks and exit. + case CLOSING_USRP: + if (pmt_eq(event, s_response_close)){ + status = pmt_nth(1, data); + + if (pmt_eq(status, PMT_T)){ + fflush(stdout); + shutdown_all(PMT_T); + return; + } + else { + error_msg = "failed to close USRP:"; + goto bail; + } + } + goto unhandled; + + default: + goto unhandled; + } + return; + + // An error occured, print it, and shutdown all m-blocks + bail: + std::cerr << error_msg << data + << "status = " << status << std::endl; + shutdown_all(PMT_F); + return; + + // Received an unhandled message for a specific state + unhandled: + if(verbose && !pmt_eq(event, pmt_intern("%shutdown"))) + std::cout << "test_usrp_inband_tx: unhandled msg: " << msg + << "in state "<< d_state << std::endl; +} + + +void +test_usrp_rx::open_usrp() +{ + pmt_t which_usrp = pmt_from_long(0); + + d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp)); + d_state = OPENING_USRP; + + if(verbose) + std::cout << "[TEST_USRP_INBAND_RX] Opening the USRP\n"; +} + +void +test_usrp_rx::close_usrp() +{ + + d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); + d_state = CLOSING_USRP; + + if(verbose) + std::cout << "[TEST_USRP_INBAND_RX] Closing the USRP\n"; +} + +void +test_usrp_rx::allocate_channel() +{ + long capacity = (long) 16e6; + d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); + d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); + d_state = ALLOCATING_CHANNEL; + + if(verbose) + std::cout << "[TEST_USRP_INBAND_RX] Requesting RX channel allocation\n"; +} + +void +test_usrp_rx::enter_receiving() +{ + d_state = RECEIVING; + + d_rx->send(s_cmd_start_recv_raw_samples, + pmt_list2(PMT_F, + d_rx_chan0)); + + d_rx->send(s_cmd_start_recv_raw_samples, + pmt_list2(PMT_F, + d_rx_chan1)); + + if(verbose) + std::cout << "[TEST_USRP_INBAND_RX] Receiving...\n"; +} + +void +test_usrp_rx::handle_response_recv_raw_samples(pmt_t data) +{ + pmt_t invocation_handle = pmt_nth(0, data); + pmt_t status = pmt_nth(1, data); + pmt_t v_samples = pmt_nth(2, data); + pmt_t timestamp = pmt_nth(3, data); + pmt_t channel = pmt_nth(4, data); + pmt_t properties = pmt_nth(5, data); + + d_samples_recvd += pmt_length(v_samples) / 4; + + // Check for overrun + if(!pmt_is_dict(properties)) { + std::cout << "[TEST_USRP_INBAND_RX] Recv samples dictionary is improper\n"; + return; + } + + // Check if the number samples we have received meets the test + if(d_samples_recvd >= d_samples_to_recv) { + d_rx->send(s_cmd_stop_recv_raw_samples, pmt_list2(PMT_NIL, d_rx_chan0)); + d_rx->send(s_cmd_stop_recv_raw_samples, pmt_list2(PMT_NIL, d_rx_chan1)); + enter_closing_channel(); + return; + } + +} + +void +test_usrp_rx::enter_closing_channel() +{ + d_state = CLOSING_CHANNEL; + + d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_rx_chan0)); + d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_rx_chan1)); + + if(verbose) + std::cout << "[TEST_USRP_INBAND_RX] Deallocating RX channel\n"; +} + +REGISTER_MBLOCK_CLASS(test_usrp_rx); + + +// ---------------------------------------------------------------- + +int +main (int argc, char **argv) +{ + mb_runtime_sptr rt = mb_make_runtime(); + pmt_t result = PMT_NIL; + + rt->run("top", "test_usrp_rx", PMT_F, &result); + +} diff --git a/usrp/host/apps-inband/test_usrp_inband_cs.cc b/usrp/host/apps-inband/test_usrp_inband_2tx.cc index 2497f8d5c4..5ab9be06ac 100644 --- a/usrp/host/apps-inband/test_usrp_inband_cs.cc +++ b/usrp/host/apps-inband/test_usrp_inband_2tx.cc @@ -25,16 +25,17 @@ #include <mb_mblock.h> #include <mb_runtime.h> +#include <mb_runtime_nop.h> // QA only #include <mb_protocol_class.h> #include <mb_exception.h> #include <mb_msg_queue.h> #include <mb_message.h> +#include <mb_mblock_impl.h> #include <mb_msg_accepter.h> #include <mb_class_registry.h> #include <pmt.h> #include <stdio.h> #include <string.h> -#include <sys/time.h> #include <iostream> #include <ui_nco.h> @@ -42,21 +43,14 @@ #include <symbols_usrp_channel.h> #include <symbols_usrp_low_level_cs.h> #include <symbols_usrp_tx.h> -#include <symbols_usrp_rx.h> -#define NBPING 10 +static bool verbose = true; -static bool verbose = false; - -class test_usrp_cs : public mb_mblock +class test_usrp_tx : public mb_mblock { mb_port_sptr d_tx; - mb_port_sptr d_rx; mb_port_sptr d_cs; - pmt_t d_tx_chan; // returned tx channel handle - pmt_t d_rx_chan; // returned tx channel handle - - struct timeval times[NBPING]; + pmt_t d_tx_chan0, d_tx_chan1; enum state_t { INIT, @@ -79,8 +73,8 @@ class test_usrp_cs : public mb_mblock double d_amplitude; public: - test_usrp_cs(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_cs(); + test_usrp_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); + ~test_usrp_tx(); void initial_transition(); void handle_message(mb_message_sptr msg); @@ -89,32 +83,25 @@ class test_usrp_cs : public mb_mblock void close_usrp(); void allocate_channel(); void send_packets(); - void enter_receiving(); void enter_transmitting(); - void build_and_send_ping(); void build_and_send_next_frame(); void handle_xmit_response(pmt_t invocation_handle); void enter_closing_channel(); }; -test_usrp_cs::test_usrp_cs(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) +test_usrp_tx::test_usrp_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) : mb_mblock(runtime, instance_name, user_arg), - d_tx_chan(PMT_NIL), - d_rx_chan(PMT_NIL), - d_state(INIT), d_nsamples_to_send((long) 40e6), + d_tx_chan0(PMT_NIL), d_tx_chan1(PMT_NIL), + d_state(INIT), d_nsamples_to_send((long) 80e6), d_nsamples_xmitted(0), d_nframes_xmitted(0), - //d_samples_per_frame((long)(126)), - //d_samples_per_frame((long)(126 * 3.5)), // non-full packet d_samples_per_frame((long)(126 * 4)), // full packet d_done_sending(false), d_amplitude(16384) { - if(verbose) - std::cout << "[TEST_USRP_INBAND_CS] Initializing...\n"; + // std::cout << "[TEST_USRP_TX] Initializing...\n"; d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); //bool fake_usrp_p = true; @@ -129,6 +116,11 @@ test_usrp_cs::test_usrp_cs(mb_runtime *runtime, const std::string &instance_name pmt_intern("fake-usrp"), PMT_T); } + + // Specify the RBF to use + pmt_dict_set(usrp_dict, + pmt_intern("rbf"), + pmt_intern("inband_2rxhb_2tx.rbf")); // Set TX and RX interpolations pmt_dict_set(usrp_dict, @@ -136,18 +128,12 @@ test_usrp_cs::test_usrp_cs(mb_runtime *runtime, const std::string &instance_name pmt_from_long(128)); pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(16)); - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("boe.rbf")); + pmt_intern("rf-freq"), + pmt_from_long(10e6)); define_component("server", "usrp_server", usrp_dict); connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); connect("self", "cs", "server", "cs"); // initialize NCO @@ -160,22 +146,21 @@ test_usrp_cs::test_usrp_cs(mb_runtime *runtime, const std::string &instance_name // for now, we'll have the low-level code hardwire it. } -test_usrp_cs::~test_usrp_cs() +test_usrp_tx::~test_usrp_tx() { } void -test_usrp_cs::initial_transition() +test_usrp_tx::initial_transition() { open_usrp(); } void -test_usrp_cs::handle_message(mb_message_sptr msg) +test_usrp_tx::handle_message(mb_message_sptr msg) { pmt_t event = msg->signal(); pmt_t data = msg->data(); - pmt_t port_id = msg->port_id(); pmt_t handle = PMT_F; pmt_t status = PMT_F; @@ -200,48 +185,21 @@ test_usrp_cs::handle_message(mb_message_sptr msg) case ALLOCATING_CHANNEL: if (pmt_eq(event, s_response_allocate_channel)){ + status = pmt_nth(1, data); + if(pmt_eqv(d_tx_chan0, PMT_NIL)) + d_tx_chan0 = pmt_nth(2, data); + else + d_tx_chan1 = pmt_nth(2, data); - if(pmt_eq(d_tx->port_symbol(), port_id)) { - status = pmt_nth(1, data); - d_tx_chan = pmt_nth(2, data); - - if (pmt_eq(status, PMT_T)){ - - if(verbose) - std::cout << "[TEST_USRP_INBAND_CS] Received allocation for TX\n"; - - if(!pmt_eqv(d_rx_chan, PMT_NIL)) { - enter_receiving(); - enter_transmitting(); - } - return; - } - else { - error_msg = "failed to allocate channel:"; - goto bail; - } + if (pmt_eq(status, PMT_T) && !pmt_eqv(d_tx_chan1, PMT_NIL)){ + enter_transmitting(); + return; } - - if(pmt_eq(d_rx->port_symbol(), port_id)) { - status = pmt_nth(1, data); - d_rx_chan = pmt_nth(2, data); - - if (pmt_eq(status, PMT_T)){ - - if(verbose) - std::cout << "[TEST_USRP_INBAND_CS] Received allocation for TX\n"; - - if(!pmt_eqv(d_tx_chan, PMT_NIL)) { - enter_receiving(); - enter_transmitting(); - } - return; - } - else { - error_msg = "failed to allocate channel:"; - goto bail; - } + else if(pmt_eq(status, PMT_F)){ + error_msg = "failed to allocate channel:"; + goto bail; } + return; } goto unhandled; @@ -303,81 +261,64 @@ test_usrp_cs::handle_message(mb_message_sptr msg) return; unhandled: - if(verbose) - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; + std::cout << "test_usrp_inband_tx: unhandled msg: " << msg + << "in state "<< d_state << std::endl; } void -test_usrp_cs::open_usrp() +test_usrp_tx::open_usrp() { pmt_t which_usrp = pmt_from_long(0); d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp)); d_state = OPENING_USRP; + + if(verbose) + std::cout << "[TEST_USRP_INBAND_TX] Opening the USRP\n"; } void -test_usrp_cs::close_usrp() +test_usrp_tx::close_usrp() { d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); d_state = CLOSING_USRP; - + if(verbose) - std::cout << "[TEST_USRP_INBAND_CS] Closing USRP\n"; + std::cout << "[TEST_USRP_INBAND_TX] Closing the USRP\n"; } void -test_usrp_cs::allocate_channel() +test_usrp_tx::allocate_channel() { long capacity = (long) 16e6; + + // Send two capacity requests, which will allocate us two channels + d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); d_state = ALLOCATING_CHANNEL; + + if(verbose) + std::cout << "[TEST_USRP_INBAND_TX] Requesting TX channel allocation\n"; } void -test_usrp_cs::enter_receiving() -{ - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_F, - d_rx_chan)); -} - -void -test_usrp_cs::enter_transmitting() +test_usrp_tx::enter_transmitting() { d_state = TRANSMITTING; d_nsamples_xmitted = 0; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_CS] Beginning transmission\n"; - - sleep(1); - -// build_and_send_next_frame(); // fire off 4 to start pipeline - - build_and_send_ping(); - build_and_send_ping(); - build_and_send_ping(); -} - -void -test_usrp_cs::build_and_send_ping() -{ + if(verbose) + std::cout << "[TEST_USRP_INBAND_TX] Transmitting...\n"; - d_tx->send(s_cmd_to_control_channel, - pmt_list2(PMT_NIL, pmt_list1(pmt_list2(s_op_ping_fixed, - pmt_list2(pmt_from_long(0), - pmt_from_long(0)))))); - - std::cout << "[TEST_USRP_INBAND_CS] Ping sent" << std::endl; + build_and_send_next_frame(); // fire off 4 to start pipeline + build_and_send_next_frame(); + build_and_send_next_frame(); + build_and_send_next_frame(); } void -test_usrp_cs::build_and_send_next_frame() +test_usrp_tx::build_and_send_next_frame() { // allocate the uniform vector for the samples // FIXME perhaps hold on to this between calls @@ -421,23 +362,34 @@ test_usrp_cs::build_and_send_next_frame() } } + pmt_t tx_properties = pmt_make_dict(); + pmt_t timestamp = pmt_from_long(0xffffffff); // NOW d_tx->send(s_cmd_xmit_raw_frame, - pmt_list4(pmt_from_long(d_nframes_xmitted), // invocation-handle - d_tx_chan, // channel + pmt_list5(pmt_from_long(d_nframes_xmitted), // invocation-handle + d_tx_chan0, // channel uvec, // the samples - timestamp)); + timestamp, + tx_properties)); + + // Resend on channel 1 + d_tx->send(s_cmd_xmit_raw_frame, + pmt_list5(pmt_from_long(d_nframes_xmitted), // invocation-handle + d_tx_chan1, // channel + uvec, // the samples + timestamp, + tx_properties)); d_nsamples_xmitted += nsamples_this_frame; d_nframes_xmitted++; - if(verbose) - std::cout << "[TEST_USRP_INBAND_CS] Transmitted frame\n"; + if(verbose && 0) + std::cout << "[TEST_USRP_INBAND_TX] Transmitted frame\n"; } void -test_usrp_cs::handle_xmit_response(pmt_t handle) +test_usrp_tx::handle_xmit_response(pmt_t handle) { if (d_done_sending && pmt_to_long(handle) == (d_nframes_xmitted - 1)){ @@ -445,21 +397,23 @@ test_usrp_cs::handle_xmit_response(pmt_t handle) enter_closing_channel(); } - //build_and_send_next_frame(); + build_and_send_next_frame(); } void -test_usrp_cs::enter_closing_channel() +test_usrp_tx::enter_closing_channel() { d_state = CLOSING_CHANNEL; - d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_tx_chan)); - + // Deallocate both channels + d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_tx_chan0)); + d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_tx_chan1)); + if(verbose) - std::cout << "[TEST_USRP_INBAND_CS] Closing channel\n"; + std::cout << "[TEST_USRP_INBAND_tX] Deallocating TX channel\n"; } -REGISTER_MBLOCK_CLASS(test_usrp_cs); +REGISTER_MBLOCK_CLASS(test_usrp_tx); // ---------------------------------------------------------------- @@ -472,5 +426,5 @@ main (int argc, char **argv) mb_runtime_sptr rt = mb_make_runtime(); pmt_t result = PMT_NIL; - rt->run("top", "test_usrp_cs", PMT_F, &result); + rt->run("top", "test_usrp_tx", PMT_F, &result); } diff --git a/usrp/host/apps-inband/test_usrp_inband_overrun.cc b/usrp/host/apps-inband/test_usrp_inband_overrun.cc index 9041a09845..107668b894 100644 --- a/usrp/host/apps-inband/test_usrp_inband_overrun.cc +++ b/usrp/host/apps-inband/test_usrp_inband_overrun.cc @@ -102,7 +102,7 @@ test_usrp_rx::test_usrp_rx(mb_runtime *runtime, const std::string &instance_name // Specify the RBF to use pmt_dict_set(usrp_dict, pmt_intern("rbf"), - pmt_intern("nanocell9.rbf")); + pmt_intern("inband_1rxhb_1tx.rbf")); pmt_dict_set(usrp_dict, pmt_intern("decim-rx"), @@ -306,7 +306,8 @@ test_usrp_rx::handle_response_recv_raw_samples(pmt_t data) pmt_t status = pmt_nth(1, data); pmt_t v_samples = pmt_nth(2, data); pmt_t timestamp = pmt_nth(3, data); - pmt_t properties = pmt_nth(4, data); + pmt_t channel = pmt_nth(4, data); + pmt_t properties = pmt_nth(5, data); d_samples_recvd += pmt_length(v_samples) / 4; diff --git a/usrp/host/apps-inband/test_usrp_inband_registers.cc b/usrp/host/apps-inband/test_usrp_inband_registers.cc index 017ccdbf50..a1d9cc1417 100644 --- a/usrp/host/apps-inband/test_usrp_inband_registers.cc +++ b/usrp/host/apps-inband/test_usrp_inband_registers.cc @@ -118,7 +118,7 @@ test_usrp_inband_registers::test_usrp_inband_registers(mb_runtime *runtime, cons // Specify the RBF to use pmt_dict_set(usrp_dict, pmt_intern("rbf"), - pmt_intern("boe2.rbf")); + pmt_intern("inband_1rxhb_1tx.rbf")); // Set TX and RX interpolations pmt_dict_set(usrp_dict, diff --git a/usrp/host/apps-inband/test_usrp_inband_rx.cc b/usrp/host/apps-inband/test_usrp_inband_rx.cc index 0429951f3c..cff2aa723c 100644 --- a/usrp/host/apps-inband/test_usrp_inband_rx.cc +++ b/usrp/host/apps-inband/test_usrp_inband_rx.cc @@ -87,23 +87,30 @@ class test_usrp_rx : public mb_mblock test_usrp_rx::test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) : mb_mblock(runtime, instance_name, user_arg), d_samples_recvd(0), - d_samples_to_recv(5e6) + d_samples_to_recv(20e6) { - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); // Pass a dictionary to usrp_server which specifies which interface to use, the stub or USRP pmt_t usrp_dict = pmt_make_dict(); + + // To test the application without a USRP + bool fake_usrp_p = false; + if(fake_usrp_p) { + pmt_dict_set(usrp_dict, + pmt_intern("fake-usrp"), + PMT_T); + } // Specify the RBF to use pmt_dict_set(usrp_dict, pmt_intern("rbf"), - pmt_intern("nanocell9.rbf")); + pmt_intern("inband_1rxhb_1tx.rbf")); pmt_dict_set(usrp_dict, pmt_intern("decim-rx"), - pmt_from_long(128)); + pmt_from_long(64)); define_component("server", "usrp_server", usrp_dict); @@ -264,6 +271,7 @@ test_usrp_rx::open_usrp() void test_usrp_rx::close_usrp() { + d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); d_state = CLOSING_USRP; @@ -302,7 +310,8 @@ test_usrp_rx::handle_response_recv_raw_samples(pmt_t data) pmt_t status = pmt_nth(1, data); pmt_t v_samples = pmt_nth(2, data); pmt_t timestamp = pmt_nth(3, data); - pmt_t properties = pmt_nth(4, data); + pmt_t channel = pmt_nth(4, data); + pmt_t properties = pmt_nth(5, data); d_samples_recvd += pmt_length(v_samples) / 4; @@ -325,9 +334,7 @@ void test_usrp_rx::enter_closing_channel() { d_state = CLOSING_CHANNEL; - - sleep(2); - + d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_rx_chan)); if(verbose) @@ -342,10 +349,9 @@ REGISTER_MBLOCK_CLASS(test_usrp_rx); int main (int argc, char **argv) { - // handle any command line args here - mb_runtime_sptr rt = mb_make_runtime(); pmt_t result = PMT_NIL; rt->run("top", "test_usrp_rx", PMT_F, &result); + } diff --git a/usrp/host/apps-inband/test_usrp_inband_timestamps.cc b/usrp/host/apps-inband/test_usrp_inband_timestamps.cc index 8824a72fec..297c7126ab 100644 --- a/usrp/host/apps-inband/test_usrp_inband_timestamps.cc +++ b/usrp/host/apps-inband/test_usrp_inband_timestamps.cc @@ -147,7 +147,7 @@ test_usrp_inband_timestamps::test_usrp_inband_timestamps(mb_runtime *runtime, co // Specify the RBF to use pmt_dict_set(usrp_dict, pmt_intern("rbf"), - pmt_intern("tmac5.rbf")); + pmt_intern("inband_1rxhb_1tx.rbf")); define_component("server", "usrp_server", usrp_dict); diff --git a/usrp/host/apps-inband/test_usrp_inband_tx.cc b/usrp/host/apps-inband/test_usrp_inband_tx.cc index 7118d2d0f4..7f894a4c34 100644 --- a/usrp/host/apps-inband/test_usrp_inband_tx.cc +++ b/usrp/host/apps-inband/test_usrp_inband_tx.cc @@ -42,7 +42,7 @@ #include <symbols_usrp_low_level_cs.h> #include <symbols_usrp_tx.h> -static bool verbose = false; +static bool verbose = true; class test_usrp_tx : public mb_mblock { @@ -89,11 +89,9 @@ class test_usrp_tx : public mb_mblock test_usrp_tx::test_usrp_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) : mb_mblock(runtime, instance_name, user_arg), - d_state(INIT), d_nsamples_to_send((long) 40e6), + d_state(INIT), d_nsamples_to_send((long) 80e6), d_nsamples_xmitted(0), d_nframes_xmitted(0), - //d_samples_per_frame((long)(126)), - //d_samples_per_frame((long)(126 * 3.5)), // non-full packet d_samples_per_frame((long)(126 * 4)), // full packet d_done_sending(false), d_amplitude(16384) @@ -119,18 +117,14 @@ test_usrp_tx::test_usrp_tx(mb_runtime *runtime, const std::string &instance_name // Specify the RBF to use pmt_dict_set(usrp_dict, pmt_intern("rbf"), - pmt_intern("cs1.rbf")); + pmt_intern("inband_1rxhb_1tx.rbf")); // Set TX and RX interpolations pmt_dict_set(usrp_dict, pmt_intern("interp-tx"), - pmt_from_long(128)); + pmt_from_long(64)); pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(16)); - - pmt_dict_set(usrp_dict, pmt_intern("rf-freq"), pmt_from_long(10e6)); @@ -176,12 +170,12 @@ test_usrp_tx::handle_message(mb_message_sptr msg) if (pmt_eq(event, s_response_open)){ status = pmt_nth(1, data); if (pmt_eq(status, PMT_T)){ - allocate_channel(); - return; + allocate_channel(); + return; } else { - error_msg = "failed to open usrp:"; - goto bail; + error_msg = "failed to open usrp:"; + goto bail; } } goto unhandled; @@ -192,12 +186,12 @@ test_usrp_tx::handle_message(mb_message_sptr msg) d_tx_chan = pmt_nth(2, data); if (pmt_eq(status, PMT_T)){ - enter_transmitting(); - return; + enter_transmitting(); + return; } else { - error_msg = "failed to allocate channel:"; - goto bail; + error_msg = "failed to allocate channel:"; + goto bail; } } goto unhandled; @@ -208,12 +202,12 @@ test_usrp_tx::handle_message(mb_message_sptr msg) status = pmt_nth(1, data); if (pmt_eq(status, PMT_T)){ - handle_xmit_response(handle); - return; + handle_xmit_response(handle); + return; } else { - error_msg = "bad response-xmit-raw-frame:"; - goto bail; + error_msg = "bad response-xmit-raw-frame:"; + goto bail; } } goto unhandled; @@ -223,12 +217,12 @@ test_usrp_tx::handle_message(mb_message_sptr msg) status = pmt_nth(1, data); if (pmt_eq(status, PMT_T)){ - close_usrp(); - return; + close_usrp(); + return; } else { - error_msg = "failed to deallocate channel:"; - goto bail; + error_msg = "failed to deallocate channel:"; + goto bail; } } goto unhandled; @@ -238,12 +232,12 @@ test_usrp_tx::handle_message(mb_message_sptr msg) status = pmt_nth(1, data); if (pmt_eq(status, PMT_T)){ - shutdown_all(PMT_T); - return; + shutdown_all(PMT_T); + return; } else { - error_msg = "failed to close USRP:"; - goto bail; + error_msg = "failed to close USRP:"; + goto bail; } } goto unhandled; @@ -272,6 +266,9 @@ test_usrp_tx::open_usrp() d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp)); d_state = OPENING_USRP; + + if(verbose) + std::cout << "[TEST_USRP_INBAND_TX] Opening the USRP\n"; } void @@ -279,6 +276,9 @@ test_usrp_tx::close_usrp() { d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); d_state = CLOSING_USRP; + + if(verbose) + std::cout << "[TEST_USRP_INBAND_TX] Closing the USRP\n"; } void @@ -287,6 +287,9 @@ test_usrp_tx::allocate_channel() long capacity = (long) 16e6; d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); d_state = ALLOCATING_CHANNEL; + + if(verbose) + std::cout << "[TEST_USRP_INBAND_TX] Requesting TX channel allocation\n"; } void @@ -295,15 +298,9 @@ test_usrp_tx::enter_transmitting() d_state = TRANSMITTING; d_nsamples_xmitted = 0; - // FIXME: carrier sense hack - d_tx->send(s_cmd_to_control_channel, // C/S packet - pmt_list2(PMT_NIL, // invoc handle - pmt_list1( - pmt_list2(s_op_write_reg, - pmt_list2( - pmt_from_long(1), - pmt_from_long(21)))))); - + if(verbose) + std::cout << "[TEST_USRP_INBAND_TX] Transmitting...\n"; + build_and_send_next_frame(); // fire off 4 to start pipeline build_and_send_next_frame(); build_and_send_next_frame(); @@ -356,9 +353,6 @@ test_usrp_tx::build_and_send_next_frame() } pmt_t tx_properties = pmt_make_dict(); - pmt_dict_set(tx_properties, - pmt_intern("carrier-sense"), - PMT_T); pmt_t timestamp = pmt_from_long(0xffffffff); // NOW d_tx->send(s_cmd_xmit_raw_frame, @@ -371,7 +365,7 @@ test_usrp_tx::build_and_send_next_frame() d_nsamples_xmitted += nsamples_this_frame; d_nframes_xmitted++; - if(verbose) + if(verbose && 0) std::cout << "[TEST_USRP_INBAND_TX] Transmitted frame\n"; } @@ -394,6 +388,9 @@ test_usrp_tx::enter_closing_channel() d_state = CLOSING_CHANNEL; d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_tx_chan)); + + if(verbose) + std::cout << "[TEST_USRP_INBAND_tX] Deallocating TX channel\n"; } REGISTER_MBLOCK_CLASS(test_usrp_tx); diff --git a/usrp/host/apps-inband/test_usrp_inband_underrun.cc b/usrp/host/apps-inband/test_usrp_inband_underrun.cc index 0404208b43..c9630cec2e 100644 --- a/usrp/host/apps-inband/test_usrp_inband_underrun.cc +++ b/usrp/host/apps-inband/test_usrp_inband_underrun.cc @@ -127,7 +127,7 @@ test_usrp_inband_underrun::test_usrp_inband_underrun(mb_runtime *runtime, const d_rx_chan(PMT_NIL), d_which_usrp(pmt_from_long(0)), d_state(INIT), - d_nsamples_to_send((long) 20e6), + d_nsamples_to_send((long) 27e6), d_nsamples_xmitted(0), d_nframes_xmitted(0), d_samples_per_frame(d_nsamples_to_send), // full packet @@ -143,12 +143,12 @@ test_usrp_inband_underrun::test_usrp_inband_underrun(mb_runtime *runtime, const // Specify the RBF to use pmt_dict_set(usrp_dict, pmt_intern("rbf"), - pmt_intern("nanocell9.rbf")); + pmt_intern("inband_1rxhb_1tx.rbf")); // Set TX and RX interpolations pmt_dict_set(usrp_dict, pmt_intern("interp-tx"), - pmt_from_long(8)); + pmt_from_long(64)); pmt_dict_set(usrp_dict, pmt_intern("decim-rx"), @@ -668,8 +668,6 @@ test_usrp_inband_underrun::closing_usrp() { d_state = CLOSING_USRP; - sleep(2); - d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); } |