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.
29 #include <mb_class_registry.h>
30 #include <usrp_inband_usb_packet.h>
31 #include <fpga_regs_common.h>
32 #include <usrp_standard.h>
35 #include <symbols_usrp_tx_cs.h>
37 typedef usrp_inband_usb_packet transport_pkt;
39 static const bool verbose = false;
41 usrp_tx::usrp_tx(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg)
42 : mb_mblock(rt, instance_name, user_arg),
45 d_cs = define_port("cs", "usrp-tx-cs", true, mb_port::EXTERNAL);
50 d_ofile.open("tx_data.dat",std::ios::binary|std::ios::out);
51 d_cs_ofile.open("tx_cs.dat",std::ios::binary|std::ios::out);
64 usrp_tx::initial_transition()
70 usrp_tx::handle_message(mb_message_sptr msg)
72 pmt_t event = msg->signal();
73 pmt_t port_id = msg->port_id();
74 pmt_t data = msg->data();
76 // Theoretically only have 1 message to ever expect, but
77 // want to make sure its at least what we want
78 if(pmt_eq(port_id, d_cs->port_symbol())) {
80 if(pmt_eqv(event, s_cmd_usrp_tx_write))
86 usrp_tx::write(pmt_t data)
88 pmt_t invocation_handle = pmt_nth(0, data);
89 pmt_t channel = pmt_nth(1, data);
90 pmt_t v_packets = pmt_nth(2, data);
91 d_utx = boost::any_cast<usrp_standard_tx *>(pmt_any_ref(pmt_nth(3, data)));
94 bool underrun; // this will need to go, as it is taken care of in the packet headers
96 transport_pkt *pkts = (transport_pkt *) pmt_u8vector_writeable_elements(v_packets, n_bytes);
98 int ret = d_utx->write (pkts, n_bytes, &underrun);
101 fprintf(stderr, "uU");
103 if (ret == (int) n_bytes) {
105 std::cout << "[usrp_server] Write of " << n_bytes << " successful\n";
106 // need to respond with the channel so the USRP server knows who to forward the result of
107 // the write to by looking up the owner of the channel
108 d_cs->send(s_response_usrp_tx_write,
109 pmt_list3(invocation_handle, PMT_T, channel));
113 std::cout << "[usrp_server] Error writing " << n_bytes << " bytes to USB bus\n";
114 d_cs->send(s_response_usrp_tx_write,
115 pmt_list3(invocation_handle, PMT_F, channel));
119 static_cast<long>(std::ceil(n_bytes / (double)transport_pkt::max_pkt_size()));
121 for(int i=0; i < n_packets; i++) {
124 if(pkts[i].chan() == 0x1f)
125 d_cs_ofile.write((const char *)&pkts[i], transport_pkt::max_pkt_size());
127 d_ofile.write((const char *)&pkts[i], transport_pkt::max_pkt_size());
138 REGISTER_MBLOCK_CLASS(usrp_tx);