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 <usrp_inband_usb_packet.h>
30 #include <mb_mblock.h>
31 #include <mb_runtime.h>
32 #include <mb_protocol_class.h>
33 #include <mb_class_registry.h>
35 #include "usrp_standard.h"
37 typedef usrp_inband_usb_packet transport_pkt;
39 // Signal set for the USRP server
40 static pmt_t s_cmd_open = pmt_intern("cmd-open");
41 static pmt_t s_response_open = pmt_intern("response-open");
42 static pmt_t s_cmd_close = pmt_intern("cmd-close");
43 static pmt_t s_response_close = pmt_intern("response-close");
44 static pmt_t s_cmd_allocate_channel = pmt_intern("cmd-allocate-channel");
45 static pmt_t s_response_allocate_channel = pmt_intern("response-allocate-channel");
46 static pmt_t s_send_allocate_channel = pmt_intern("send-allocate-channel");
47 static pmt_t s_cmd_deallocate_channel = pmt_intern("cmd-deallocate-channel");
48 static pmt_t s_response_deallocate_channel = pmt_intern("response-deallocate-channel");
49 static pmt_t s_send_deallocate_channel = pmt_intern("send-deallocate-channel");
50 static pmt_t s_cmd_max_capacity = pmt_intern("cmd-max-capacity");
51 static pmt_t s_response_max_capacity = pmt_intern("response-max-capacity");
52 static pmt_t s_cmd_ntx_chan = pmt_intern("cmd-ntx-chan");
53 static pmt_t s_cmd_nrx_chan = pmt_intern("cmd-nrx-chan");
54 static pmt_t s_response_ntx_chan = pmt_intern("response-ntx-chan");
55 static pmt_t s_response_nrx_chan = pmt_intern("response-nrx-chan");
56 static pmt_t s_cmd_current_capacity_allocation = pmt_intern("cmd-current-capacity-allocation");
57 static pmt_t s_response_current_capacity_allocation = pmt_intern("response-current-capacity-allocation");
58 static pmt_t s_cmd_xmit_raw_frame = pmt_intern("cmd-xmit-raw-frame");
59 static pmt_t s_response_xmit_raw_frame = pmt_intern("response-xmit-raw-frame");
61 bool loopback_p = false;
62 bool counting_p = false;
63 bool fake_usrp_p = false;
67 set_progname (char *path)
69 char *p = strrchr (path, '/');
79 fprintf (stderr, "usage: %s [-l]\n", prog_name);
80 fprintf (stderr, " [-l] digital loopback in FPGA\n");
81 fprintf (stderr, " [-c] counting in FPGA\n");
82 fprintf (stderr, " [-f] fake usrp\n");
88 main(int argc, char **argv)
92 set_progname(argv[0]);
94 mb_runtime_sptr rt = mb_make_runtime();
97 while ((ch = getopt(argc, argv, "flc")) != EOF) {
118 std::cout << "[test_usrp_inband] Starting...\n";
120 rt->run("top", "test_usrp_inband_top", PMT_F, &result);
123 class test_usrp_inband_top : public mb_mblock
131 test_usrp_inband_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg);
132 ~test_usrp_inband_top();
133 void initial_transition();
134 void handle_message(mb_message_sptr msg);
139 void check_message(mb_message_sptr msg);
140 void allocate_channel();
144 test_usrp_inband_top::test_usrp_inband_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg)
145 : mb_mblock(runtime, instance_name, user_arg)
147 std::cout << "[TEST_USRP_INBAND_TOP] Initializing...\n";
149 d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL);
150 d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL);
154 // Pass a dictionary to usrp_server which specifies which interface to use, the stub or USRP
155 pmt_t usrp_server_dict = pmt_make_dict();
158 pmt_dict_set(usrp_server_dict, pmt_intern("usrp-interface"), pmt_intern("usrp_usb_interface_stub"));
160 define_component("server", "usrp_server", usrp_server_dict);
161 connect("self", "tx0", "server", "tx0");
162 connect("self", "cs", "server", "cs");
165 test_usrp_inband_top::~test_usrp_inband_top()
170 test_usrp_inband_top::initial_transition()
176 test_usrp_inband_top::handle_message(mb_message_sptr msg)
178 pmt_t event = msg->signal(); // the "name" of the message
179 pmt_t port_id = msg->port_id(); // which port it came in on
180 pmt_t data = msg->data();
181 pmt_t metadata = msg->metadata();
184 if (pmt_eq(port_id, d_cs->port_symbol())) { // message came in on our control/status port
186 //---------- OPEN RESPONSE ----------//
187 if (pmt_eq(event, s_response_open)) {
188 status = pmt_nth(1, data);
190 if(pmt_eq(status, PMT_T)) {
191 std::cout << "[TEST_USRP_INBAND_TOP] Success opening USRP\n";
194 std::cout << "[TEST_USRP_INBAND_TOP] Received error message opening USRP\n";
202 //--------- CLOSE RESPONSE -----------//
203 else if (pmt_eq(event, s_response_close)) {
204 status = pmt_nth(1, data);
206 if(pmt_eq(status, PMT_T)) {
207 std::cout << "[TEST_USRP_INBAND_TOP] Successfully closed USRP\n";
210 std::cout << "[TEST_USRP_INBAND_TOP] Received error message closing USRP\n";
220 if (pmt_eq(port_id, d_tx->port_symbol())) {
222 //---------- ALLOCATE RESPONSE ---------//
223 if(pmt_eq(event, s_response_allocate_channel)) {
224 status = pmt_nth(1, data);
225 pmt_t channel = pmt_nth(2, data);
227 if(pmt_eq(status, PMT_T)) {
228 d_tx_chan = pmt_to_long(channel);
229 std::cout << "[TEST_USRP_INBAND_TOP] Received allocation on channel " << d_tx_chan << "\n";
232 std::cout << "[TEST_USRP_INBAND_TOP] Error allocating channel\n";
240 //----------- XMIT RESPONSE ------------//
241 else if(pmt_eq(event, s_response_xmit_raw_frame)) {
242 status = pmt_nth(1, data);
244 if(pmt_eq(status, PMT_T)) {
245 std::cout << "[TEST_USRP_INBAND_TOP] Transmission successful\n";
248 std::cout << "[TEST_USRP_INBAND_TOP] Failed transmission\n";
258 std::cout << "[TEST_USRP_INBAND_TOP] Received unhandled message: " << event << "\n";
262 test_usrp_inband_top::allocate_channel()
264 std::cout << "[TEST_USRP_INBAND_TOP] Requesting channel allocation...\n";
266 d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1)));
270 test_usrp_inband_top::send_packets()
272 std::cout << "[TEST_USRP_INBAND_TOP] Sending single packet..\n";
273 d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(1), pmt_from_long(d_tx_chan), pmt_make_u32vector(transport_pkt::max_payload()/4, 0), pmt_from_long(0)));
278 test_usrp_inband_top::open_usrp()
280 pmt_t usrp = pmt_from_long(0);
285 rx_mode |= usrp_standard_rx::FPGA_MODE_LOOPBACK;
287 rx_mode |= usrp_standard_rx::FPGA_MODE_COUNTING;
289 d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, usrp));
293 test_usrp_inband_top::close_usrp()
295 d_cs->send(s_cmd_close, pmt_list1(PMT_NIL));
298 REGISTER_MBLOCK_CLASS(test_usrp_inband_top);