3 * Copyright 2007 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <usrp_standard.h>
32 #include <mb_class_registry.h>
33 #include <usrp_inband_usb_packet.h>
34 #include <fpga_regs_common.h>
37 #include <symbols_usrp_rx_cs.h>
39 typedef usrp_inband_usb_packet transport_pkt;
41 static const bool verbose = false;
43 usrp_rx::usrp_rx(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg)
44 : mb_mblock(rt, instance_name, user_arg),
47 d_cs = define_port("cs", "usrp-rx-cs", true, mb_port::EXTERNAL);
52 d_ofile.open("rx_data.dat",std::ios::binary|std::ios::out);
53 d_cs_ofile.open("rx_cs.dat",std::ios::binary|std::ios::out);
67 usrp_rx::initial_transition()
73 usrp_rx::handle_message(mb_message_sptr msg)
75 pmt_t event = msg->signal();
76 pmt_t port_id = msg->port_id();
77 pmt_t data = msg->data();
79 // Theoretically only have 1 message to ever expect, but
80 // want to make sure its at least what we want
81 if(pmt_eq(port_id, d_cs->port_symbol())) {
83 if(pmt_eqv(event, s_cmd_usrp_rx_start_reading))
84 read_and_respond(data);
89 usrp_rx::read_and_respond(pmt_t data)
94 unsigned int pkt_size = sizeof(transport_pkt);
96 pmt_t invocation_handle = pmt_nth(0, data);
98 // Need the handle to the RX port to send responses, this is passed
99 // by the USRP interface m-block
101 boost::any_cast<usrp_standard_rx *>(pmt_any_ref(pmt_nth(1, data)));
104 std::cout << "[usrp_rx] Waiting for packets..\n";
106 // Read by 512 which is packet size and send them back up
109 pmt_t v_pkt = pmt_make_u8vector(pkt_size, 0);
111 (transport_pkt *) pmt_u8vector_writeable_elements(v_pkt, ignore);
113 n_read = d_urx->read(pkt, pkt_size, &underrun);
115 if(n_read != pkt_size) {
116 std::cerr << "[usrp_rx] Error reading packet, shutting down\n";
117 d_cs->send(s_response_usrp_rx_read,
118 pmt_list3(PMT_NIL, PMT_F, PMT_NIL));
122 if(underrun && verbose && 0)
123 std::cout << "[usrp_rx] Underrun\n";
125 d_cs->send(s_response_usrp_rx_read,
126 pmt_list3(PMT_NIL, PMT_T, v_pkt));
128 std::cout << "[usrp_rx] Read 1 packet\n";
131 if(pkt->chan() == 0x1f)
132 d_cs_ofile.write((const char *)pkt, transport_pkt::max_pkt_size());
134 d_ofile.write((const char *)pkt, transport_pkt::max_pkt_size());
142 REGISTER_MBLOCK_CLASS(usrp_rx);