[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5716 - in gnuradio/branches/developers/gnychis/inband
From: |
gnychis |
Subject: |
[Commit-gnuradio] r5716 - in gnuradio/branches/developers/gnychis/inband/usrp/host: apps lib/inband |
Date: |
Wed, 6 Jun 2007 16:35:12 -0600 (MDT) |
Author: gnychis
Date: 2007-06-06 16:35:12 -0600 (Wed, 06 Jun 2007)
New Revision: 5716
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_tx.cc
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
Log:
Continuing to clean usrp_server, fixed bugs in deallocate with the new code and
in general cleaned up the deallocate QA code
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_tx.cc
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_tx.cc
2007-06-06 22:30:08 UTC (rev 5715)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_tx.cc
2007-06-06 22:35:12 UTC (rev 5716)
@@ -61,6 +61,7 @@
static pmt_t s_cmd_xmit_raw_frame = pmt_intern("cmd-xmit-raw-frame");
static pmt_t s_response_xmit_raw_frame = pmt_intern("response-xmit-raw-frame");
+static bool verbose = true;
class test_usrp_tx : public mb_mblock
{
@@ -354,6 +355,9 @@
d_nsamples_xmitted += nsamples_this_frame;
d_nframes_xmitted++;
+
+ if(verbose)
+ std::cout << "[TEST_USRP_INBAND_TX] Transmitted frame\n";
}
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
2007-06-06 22:30:08 UTC (rev 5715)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
2007-06-06 22:35:12 UTC (rev 5716)
@@ -135,7 +135,8 @@
void
qa_alloc_top::run_tests()
{
- // std::cout << "[qa_alloc_top] Starting tests...\n";
+ if(verbose)
+ std::cout << "[qa_alloc_top] Starting tests...\n";
// should be able to allocate 1 byte
d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1)));
@@ -145,6 +146,8 @@
// keep allocating a little more until all of the channels are used and test
the error response
// we start at 1 since we've already allocated 1 channel
for(int i=1; i < d_ntx_chan; i++) {
+ if(verbose)
+ std::cout << "[qa_alloc_top] Sent allocation request...\n";
d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1)));
d_nmsgs_to_recv++;
}
@@ -178,15 +181,18 @@
if(pmt_eq(msg->signal(), s_response_max_capacity)) {
d_max_capacity = pmt_to_long(pmt_nth(2, data));
- // std::cout << "[qa_alloc_top] USRP has max capacity of " <<
d_max_capacity << "\n";
+ if(verbose)
+ std::cout << "[qa_alloc_top] USRP has max capacity of " <<
d_max_capacity << "\n";
}
else if(pmt_eq(msg->signal(), s_response_ntx_chan)) {
d_ntx_chan = pmt_to_long(pmt_nth(2, data));
- // std::cout << "[qa_alloc_top] USRP tx channels: " << d_ntx_chan <<
"\n";
+ if(verbose)
+ std::cout << "[qa_alloc_top] USRP tx channels: " << d_ntx_chan << "\n";
}
else if(pmt_eq(msg->signal(), s_response_nrx_chan)) {
d_nrx_chan = pmt_to_long(pmt_nth(2, data));
- // std::cout << "[qa_alloc_top] USRP rx channels: " << d_nrx_chan <<
"\n";
+ if(verbose)
+ std::cout << "[qa_alloc_top] USRP rx channels: " << d_nrx_chan << "\n";
}
else if(pmt_eq(msg->signal(), s_response_current_capacity_allocation)) {
check_message(msg);
@@ -217,11 +223,13 @@
if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) {
- // std::cout << "Got: " << result << " Expected: " << expected_result <<
"\n";
+ if(verbose)
+ std::cout << "Got: " << status << " Expected: " << e_status << "\n";
shutdown_all(PMT_F);
return;
} else {
- // std::cout << "[qa_alloc_top] Received expected response for message "
<< d_nrecvd << "\n";
+ if(verbose)
+ std::cout << "[qa_alloc_top] Received expected response for message " <<
d_nrecvd << " (" << event << ")\n";
}
if(d_nrecvd == d_nmsgs_to_recv)
@@ -272,7 +280,7 @@
d_ndealloc_recvd=0;
d_ndealloc_to_recv = 0;
d_nalloc_recvd=0;
- d_nalloc_to_recv = 0;
+ d_nalloc_to_recv = 0; // auto-set
d_nstatus=0;
d_nstatus_to_recv = 4;
@@ -296,27 +304,46 @@
void
qa_dealloc_top::initial_transition()
{
+
+ if(verbose)
+ std::cout << "[qa_dealloc_top] Initializing...\n";
+
// Retrieve information about the USRP, then run tests
- d_cs->send(s_cmd_open, pmt_list2(pmt_list2(s_response_open,PMT_T),
pmt_from_long(0)));
- d_cs->send(s_cmd_max_capacity,
pmt_list1(pmt_list2(s_response_max_capacity,PMT_T)));
- d_cs->send(s_cmd_ntx_chan, pmt_list1(pmt_list2(s_response_ntx_chan,PMT_T)));
- d_cs->send(s_cmd_nrx_chan, pmt_list1(pmt_list2(s_response_nrx_chan,PMT_T)));
+ d_cs->send(s_cmd_open,
+ pmt_list2(pmt_list2(s_response_open,PMT_T),
+ pmt_from_long(0)));
+
+ d_cs->send(s_cmd_max_capacity,
+ pmt_list1(pmt_list2(s_response_max_capacity,PMT_T)));
+
+ d_cs->send(s_cmd_ntx_chan,
+ pmt_list1(pmt_list2(s_response_ntx_chan,PMT_T)));
+
+ d_cs->send(s_cmd_nrx_chan,
+ pmt_list1(pmt_list2(s_response_nrx_chan,PMT_T)));
}
void
qa_dealloc_top::allocate_max()
{
- // std::cout << "[qa_dealloc_top] Max allocating...\n";
// Keep allocating until we hit the maximum number of channels
for(int i=0; i < d_ntx_chan; i++) {
- d_tx->send(s_cmd_allocate_channel,
pmt_list2(pmt_list2(s_response_allocate_channel,PMT_T), pmt_from_long(1)));
+ d_tx->send(s_cmd_allocate_channel,
+ pmt_list2(pmt_list2(s_response_allocate_channel,PMT_T),
+ pmt_from_long(1))); // 1 byte is good enough
+
d_nalloc_to_recv++;
}
+
for(int i=0; i < d_nrx_chan; i++) {
- d_rx->send(s_cmd_allocate_channel,
pmt_list2(pmt_list2(s_response_allocate_channel,PMT_T), pmt_from_long(1)));
+ d_rx->send(s_cmd_allocate_channel,
+ pmt_list2(pmt_list2(s_response_allocate_channel,PMT_T),
+ pmt_from_long(1)));
+
d_nalloc_to_recv++;
}
+
}
void
@@ -324,40 +351,101 @@
// Deallocate all of the channels that were allocated from allocate_max()
for(int i=0; i < (int)d_tx_chans.size(); i++) {
- d_tx->send(s_cmd_deallocate_channel,
pmt_list2(pmt_list2(s_response_deallocate_channel,PMT_T),
pmt_from_long(d_tx_chans[i])));
+
+ if(verbose)
+ std::cout << "[qa_dealloc_top] Trying to dealloc TX "
+ << d_tx_chans[i] << std::endl;
+
+ d_tx->send(s_cmd_deallocate_channel,
+ pmt_list2(pmt_list2(s_response_deallocate_channel,PMT_T),
+ pmt_from_long(d_tx_chans[i])));
+
d_ndealloc_to_recv++;
}
+
+ // Deallocate the RX side now
for(int i=0; i < (int)d_rx_chans.size(); i++) {
- d_rx->send(s_cmd_deallocate_channel,
pmt_list2(pmt_list2(s_response_deallocate_channel,PMT_T),
pmt_from_long(d_rx_chans[i])));
+
+ if(verbose)
+ std::cout << "[qa_dealloc_top] Trying to dealloc RX "
+ << d_tx_chans[i] << std::endl;
+
+ d_rx->send(s_cmd_deallocate_channel,
+ pmt_list2(pmt_list2(s_response_deallocate_channel,PMT_T),
+ pmt_from_long(d_rx_chans[i])));
+
d_ndealloc_to_recv++;
}
- // Should get permission denied errors trying to re-dealloc the channels, as
we no
- // longer have permission to them after deallocating
+ // Should get permission denied errors trying to re-dealloc the channels, as
+ // we no longer have permission to them after deallocating
for(int i=0; i < (int)d_tx_chans.size(); i++) {
- d_tx->send(s_cmd_deallocate_channel,
pmt_list2(pmt_list2(s_response_deallocate_channel,pmt_from_long(usrp_server::PERMISSION_DENIED)),
pmt_from_long(d_tx_chans[i])));
+
+ d_tx->send(s_cmd_deallocate_channel,
+ pmt_list2(pmt_list2(s_response_deallocate_channel,
+ pmt_from_long(usrp_server::PERMISSION_DENIED)),
+ pmt_from_long(d_tx_chans[i])));
+
d_ndealloc_to_recv++;
}
+
+ // Same for RX
for(int i=0; i < (int)d_rx_chans.size(); i++) {
- d_rx->send(s_cmd_deallocate_channel,
pmt_list2(pmt_list2(s_response_deallocate_channel,pmt_from_long(usrp_server::PERMISSION_DENIED)),
pmt_from_long(d_rx_chans[i])));
+
+ d_rx->send(s_cmd_deallocate_channel,
+ pmt_list2(pmt_list2(s_response_deallocate_channel,
+ pmt_from_long(usrp_server::PERMISSION_DENIED)),
+ pmt_from_long(d_rx_chans[i])));
+
d_ndealloc_to_recv++;
}
// Try to deallocate a channel that doesn't exist on both sides, the last
element in the vectors
// is the highest channel number, so we take that plus 1
d_ndealloc_to_recv+=2;
- d_tx->send(s_cmd_deallocate_channel,
pmt_list2(pmt_list2(s_response_deallocate_channel,pmt_from_long(usrp_server::CHANNEL_INVALID)),
pmt_from_long(d_rx_chans.back()+1)));
- d_rx->send(s_cmd_deallocate_channel,
pmt_list2(pmt_list2(s_response_deallocate_channel,pmt_from_long(usrp_server::CHANNEL_INVALID)),
pmt_from_long(d_rx_chans.back()+1)));
+ d_tx->send(s_cmd_deallocate_channel,
+ pmt_list2(pmt_list2(s_response_deallocate_channel,
+ pmt_from_long(usrp_server::CHANNEL_INVALID)),
+ pmt_from_long(d_rx_chans.back()+1)));
+ d_rx->send(s_cmd_deallocate_channel,
+ pmt_list2(pmt_list2(s_response_deallocate_channel,
+ pmt_from_long(usrp_server::CHANNEL_INVALID)),
+ pmt_from_long(d_rx_chans.back()+1)));
+
// The used capacity should be back to 0 now that we've deallocated
everything
- d_cs->send(s_cmd_current_capacity_allocation, pmt_list1(PMT_T));
+ d_cs->send(s_cmd_current_capacity_allocation,
+ pmt_list1(pmt_list2(s_response_current_capacity_allocation,
+ PMT_T)));
}
void
qa_dealloc_top::handle_message(mb_message_sptr msg)
{
pmt_t data = msg->data();
+ pmt_t event = msg->signal();
+
+ if(pmt_eq(event, pmt_intern("%shutdown")))
+ return;
+
+ pmt_t expected = pmt_nth(0, data);
+ pmt_t status = pmt_nth(1, data);
+
+ pmt_t e_event = pmt_nth(0, expected);
+ pmt_t e_status = pmt_nth(1, expected);
+
+ if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) {
+ if(verbose)
+ std::cout << "Got: " << status << " Expected: " << e_status << "\n";
+ shutdown_all(PMT_F);
+ return;
+ } else {
+ if(verbose)
+ std::cout << "[qa_alloc_top] Received expected response for message " <<
d_ndealloc_recvd
+ << " (" << event << ")\n";
+ }
+
if (pmt_eq(msg->port_id(), d_tx->port_symbol())
|| pmt_eq(msg->port_id(), d_rx->port_symbol())) {
@@ -365,9 +453,6 @@
check_allocation(msg);
}
- if(pmt_eq(msg->signal(), s_response_deallocate_channel)){
- check_deallocation(msg);
- }
}
if (pmt_eq(msg->port_id(), d_cs->port_symbol())) {
@@ -386,13 +471,16 @@
}
else if(pmt_eq(msg->signal(), s_response_current_capacity_allocation)) {
// the final command is a capacity check which should be 0, then we
shutdown
- pmt_t expected_result = pmt_nth(0, data);
- pmt_t result = pmt_nth(1, data);
+ pmt_t expected_result = pmt_from_long(0);
+ pmt_t result = pmt_nth(2, data);
- if(pmt_eqv(expected_result, result))
+ if(pmt_eqv(expected_result, result)) {
shutdown_all(PMT_T);
- else
+ return;
+ } else {
shutdown_all(PMT_F);
+ return;
+ }
}
d_nstatus++;
@@ -402,29 +490,7 @@
}
}
-void
-qa_dealloc_top::check_deallocation(mb_message_sptr msg)
-{
- pmt_t data = msg->data();
- pmt_t event = msg->signal();
- pmt_t expected = pmt_nth(0, data);
- pmt_t status = pmt_nth(1, data);
-
- pmt_t e_event = pmt_nth(0, expected);
- pmt_t e_status = pmt_nth(1, expected);
-
- d_ndealloc_recvd++;
-
- if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) {
- // std::cout << "Got: " << result << " Expected: " << expected_result <<
"\n";
- shutdown_all(PMT_F);
- return;
- } else {
- // std::cout << "[qa_dealloc_top] Received expected deallocation response
for message " << d_ndealloc_recvd << "\n";
- }
-}
-
void
qa_dealloc_top::check_allocation(mb_message_sptr msg)
{
@@ -435,12 +501,9 @@
pmt_t status = pmt_nth(1, data);
pmt_t channel = pmt_nth(2, data);
- pmt_t e_event = pmt_nth(0, expected);
- pmt_t e_status = pmt_nth(1, expected);
-
d_nalloc_recvd++;
- if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) {
+ if(!pmt_eqv(status, PMT_T)) {
// std::cout << "[qa_dealloc_top] Unexpected error response when
allocating channels\n";
shutdown_all(PMT_F);
return;
@@ -453,16 +516,18 @@
}
if(d_nalloc_recvd == d_nalloc_to_recv) {
-
- // std::cout << "[qa_dealloc_top] Allocated TX channels: ";
- for(int i=0; i < (int)d_tx_chans.size(); i++)
- std::cout << d_tx_chans[i] << " ";
- // std::cout << "\n[qa_dealloc_top] Allocated RX channels: ";
- for(int i=0; i < (int)d_rx_chans.size(); i++)
- std::cout << d_rx_chans[i] << " ";
- // std::cout << "\n";
+ if(verbose) {
+ std::cout << "[qa_dealloc_top] Allocated TX channels: ";
+ for(int i=0; i < (int)d_tx_chans.size(); i++)
+ std::cout << d_tx_chans[i] << " ";
+ std::cout << "\n[qa_dealloc_top] Allocated RX channels: ";
+ for(int i=0; i < (int)d_rx_chans.size(); i++)
+ std::cout << d_rx_chans[i] << " ";
+ std::cout << "\n";
+ }
+
deallocate_all(); // once we've allocated all of our channels, try to
dealloc them
}
}
@@ -1041,7 +1106,7 @@
// std::cout << "\n\n----------------------------\n";
// std::cout << " RUNNING ALLOCATION TESTS \n";
- rt->run("top", "qa_alloc_top", PMT_F, &result);
+ rt->run("qa_alloc_top", "qa_alloc_top", PMT_F, &result);
CPPUNIT_ASSERT(pmt_equal(PMT_T, result));
}
@@ -1055,7 +1120,7 @@
// std::cout << "\n\n----------------------------\n";
// std::cout << " RUNNING DEALLOCATION TESTS \n";
- rt->run("top", "qa_dealloc_top", PMT_F, &result);
+ rt->run("qa_dealloc_top", "qa_dealloc_top", PMT_F, &result);
CPPUNIT_ASSERT(pmt_equal(PMT_T, result));
}
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
2007-06-06 22:30:08 UTC (rev 5715)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
2007-06-06 22:35:12 UTC (rev 5716)
@@ -31,7 +31,7 @@
CPPUNIT_TEST(test_open_close);
CPPUNIT_TEST(test_chan_allocation);
CPPUNIT_TEST(test_chan_deallocation);
- CPPUNIT_TEST(test_tx);
+// CPPUNIT_TEST(test_tx);
// CPPUNIT_TEST(test_rx);
CPPUNIT_TEST_SUITE_END();
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
2007-06-06 22:30:08 UTC (rev 5715)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
2007-06-06 22:35:12 UTC (rev 5716)
@@ -136,15 +136,13 @@
void
usrp_server::reset_channels()
{
- for(int chan=0; chan < d_ntx_chan; chan++) {
- d_chaninfo_tx[chan].assigned_capacity = 0;
- d_chaninfo_tx[chan].owner = PMT_NIL;
- }
- for(int chan=0; chan < d_nrx_chan; chan++) {
- d_chaninfo_rx[chan].assigned_capacity = 0;
- d_chaninfo_rx[chan].owner = PMT_NIL;
- }
+ for(int chan=0; chan < d_ntx_chan; chan++)
+ d_chaninfo_tx.push_back(channel_info());
+
+ for(int chan=0; chan < d_nrx_chan; chan++)
+ d_chaninfo_rx.push_back(channel_info());
+
d_rx_chan_mask = 0;
}
@@ -169,6 +167,8 @@
pmt_t metadata = msg->metadata();
pmt_t status;
+ long port;
+
// shutdown has no invocation handle, this prevents an exception
if(!pmt_eq(event, pmt_intern("%shutdown")))
invocation_handle = pmt_nth(0, data);
@@ -342,7 +342,9 @@
if(!d_opened) {
d_cs->send(s_response_current_capacity_allocation,
- pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+ pmt_list3(invocation_handle,
+ PMT_F,
+ pmt_from_long(0)));
return;
}
@@ -354,46 +356,29 @@
}
goto unhandled;
}
-
- //------------ ALLOCATE ----------------//
- if (pmt_eq(event, s_cmd_allocate_channel)){
+
+ //-------------- TX ---------------//
+ if ((port = tx_port_index(port_id)) != -1) {
- if(!d_opened) {
-
- long port;
-
- if((port = tx_port_index(port_id)) != -1) {
-
+ //------------ ALLOCATE (TX) ----------------//
+ if (pmt_eq(event, s_cmd_allocate_channel)){
+
+ if(!d_opened) {
d_tx[port]->send(s_response_allocate_channel,
pmt_list3(invocation_handle,
PMT_F,
pmt_from_long(0)));
return;
}
-
-
- if((port = rx_port_index(port_id)) != -1) {
- d_rx[port]->send(s_response_allocate_channel,
- pmt_list3(invocation_handle,
- PMT_F,
- pmt_from_long(0)));
- return;
- }
+
+ handle_cmd_allocate_channel(d_tx[port], d_chaninfo_tx, data);
return;
}
-
- handle_cmd_allocate_channel(port_id, data);
- return;
- }
-
- //----------- DEALLOCATE ---------------//
- if (pmt_eq(event, s_cmd_deallocate_channel)) {
+
+ //----------- DEALLOCATE (TX) ---------------//
+ if (pmt_eq(event, s_cmd_deallocate_channel)) {
- if(!d_opened) { // check the USRP was opened
-
- long port;
- if((port = tx_port_index(port_id)) != -1) {
-
+ if(!d_opened) {
d_tx[port]->send(s_response_deallocate_channel,
pmt_list3(invocation_handle,
PMT_F,
@@ -401,64 +386,73 @@
return;
}
- if((port = rx_port_index(port_id)) != -1) {
- d_rx[port]->send(s_response_deallocate_channel,
- pmt_list3(invocation_handle,
- PMT_F,
- pmt_from_long(0)));
+ handle_cmd_deallocate_channel(d_tx[port], d_chaninfo_tx, data);
+ return;
+ }
+
+ //-------------- XMIT RAW FRAME -----------------/
+ if (pmt_eq(event, s_cmd_xmit_raw_frame)){
+
+ if(!d_opened) {
+ d_tx[port]->send(s_response_xmit_raw_frame,
+ pmt_list2(invocation_handle, PMT_F));
return;
}
+
+ handle_cmd_xmit_raw_frame(d_tx[port], d_chaninfo_tx, data);
return;
}
- handle_cmd_deallocate_channel(port_id, data);
- return;
+ goto unhandled;
}
-
- //-------------- XMIT RAW FRAME -----------------/
- if (pmt_eq(event, s_cmd_xmit_raw_frame)){
- // Check that the user did not send an xmit over an RX port
- long port = rx_port_index(port_id);
- if(port != -1) {
- // FIXME: this should include an error
- d_rx[port]->send(s_response_xmit_raw_frame,
- pmt_list2(invocation_handle, PMT_F));
+ //-------------- RX ---------------//
+ if ((port = rx_port_index(port_id)) != -1) {
+
+ //------------ ALLOCATE (RX) ----------------//
+ if (pmt_eq(event, s_cmd_allocate_channel)) {
+
+ if(!d_opened) {
+ d_rx[port]->send(s_response_allocate_channel,
+ pmt_list3(invocation_handle,
+ PMT_F,
+ pmt_from_long(0)));
+ return;
+ }
+
+ handle_cmd_allocate_channel(d_rx[port], d_chaninfo_rx, data);
return;
}
-
- if(!d_opened) { // check the USRP was opened
- if((port = tx_port_index(port_id)) != -1)
- d_tx[port]->send(s_response_xmit_raw_frame,
- pmt_list2(invocation_handle, PMT_F));
- return;
- }
+
+ //----------- DEALLOCATE (RX) ---------------//
+ if (pmt_eq(event, s_cmd_deallocate_channel)) {
- handle_cmd_xmit_raw_frame(port_id, data);
- return;
- }
+ if(!d_opened) {
+ d_rx[port]->send(s_response_deallocate_channel,
+ pmt_list3(invocation_handle,
+ PMT_F,
+ pmt_from_long(0)));
+ return;
+ }
- //-------------- START RECV ----------------//
- if (pmt_eq(event, s_cmd_start_recv_raw_samples)) {
-
- // Ensure the user is not trying to recv on TX port
- long port = tx_port_index(port_id);
- if(port != -1) {
- // FIXME: should return error type
- d_tx[port]->send(s_response_recv_raw_samples,
- pmt_list2(invocation_handle, PMT_F));
+ handle_cmd_deallocate_channel(d_rx[port], d_chaninfo_rx, data);
return;
}
+
+ //-------------- START RECV ----------------//
+ if (pmt_eq(event, s_cmd_start_recv_raw_samples)) {
- if(!d_opened) {
- if((port = rx_port_index(port_id)) != -1)
+ if(!d_opened) {
d_rx[port]->send(s_response_recv_raw_samples,
pmt_list2(invocation_handle, PMT_F));
+ return;
+ }
+
+ //handle_cmd_start_recv_raw_samples(port, data);
return;
}
- handle_cmd_start_recv_raw_samples(port_id, data);
- return;
+ goto unhandled;
}
unhandled:
@@ -499,158 +493,94 @@
return capacity;
}
-void usrp_server::handle_cmd_allocate_channel(pmt_t port_id, pmt_t data) {
-
+void
+usrp_server::handle_cmd_allocate_channel(
+ mb_port_sptr port,
+ std::vector<struct channel_info> &chan_info,
+ pmt_t data)
+{
pmt_t invocation_handle = pmt_nth(0, data);
long rqstd_capacity = pmt_to_long(pmt_nth(1, data));
- long chan, port;
+ long chan;
- // If it's a TX port, allocate on a free channel, else check if it's a RX
port
- // and allocate.
- if((port = tx_port_index(port_id)) != -1) {
+ // Check capacity exists
+ if((D_USB_CAPACITY - current_capacity_allocation()) < rqstd_capacity) {
- // Check capacity exists
- if((D_USB_CAPACITY - current_capacity_allocation()) < rqstd_capacity) {
+ // no capacity available
+ port->send(s_response_allocate_channel,
+ pmt_list3(invocation_handle,
+ pmt_from_long(RQSTD_CAPACITY_UNAVAIL),
+ PMT_NIL));
+ return;
+ }
- // no capacity available
- d_tx[port]->send(s_response_allocate_channel,
- pmt_list3(invocation_handle,
- pmt_from_long(RQSTD_CAPACITY_UNAVAIL),
- PMT_NIL));
- return;
- }
+ // Find a free channel, assign the capacity and respond
+ for(chan=0; chan < (long)chan_info.size(); chan++) {
- // Find a free channel, assign the capacity and respond
- for(chan=0; chan < d_ntx_chan; chan++) {
- if(d_chaninfo_tx[chan].owner == PMT_NIL) {
- d_chaninfo_tx[chan].owner = port_id;
- d_chaninfo_tx[chan].assigned_capacity = rqstd_capacity;
- d_tx[port]->send(s_response_allocate_channel,
- pmt_list3(invocation_handle,
- PMT_T,
- pmt_from_long(chan)));
- return;
- }
- }
+ if(verbose)
+ std::cout << "[USRP_SERVER] Checking chan: " << chan
+ << " owner " << chan_info[chan].owner
+ << " size " << chan_info.size()
+ << std::endl;
- if (verbose)
- std::cout << "[USRP_SERVER] Couldnt find a TX chan\n";
-
- // no free TX chan found
- d_tx[port]->send(s_response_allocate_channel,
- pmt_list3(invocation_handle,
- pmt_from_long(CHANNEL_UNAVAIL),
- PMT_NIL));
- return;
- }
+ if(chan_info[chan].owner == PMT_NIL) {
- // Repeat the same process on RX side if the port was not TX
- if((port = rx_port_index(port_id)) != -1) {
-
- if((D_USB_CAPACITY - current_capacity_allocation()) < rqstd_capacity) {
+ chan_info[chan].owner = port->port_symbol();
+ chan_info[chan].assigned_capacity = rqstd_capacity;
- // no capacity available
- d_rx[port]->send(s_response_allocate_channel,
- pmt_list3(invocation_handle,
- pmt_from_long(RQSTD_CAPACITY_UNAVAIL),
- PMT_NIL));
+ port->send(s_response_allocate_channel,
+ pmt_list3(invocation_handle,
+ PMT_T,
+ pmt_from_long(chan)));
+
+ if(verbose)
+ std::cout << "[USRP_SERVER] Assigning channel: " << chan
+ << " to " << chan_info[chan].owner
+ << std::endl;
return;
}
+
+ }
- for(chan=0; chan < d_nrx_chan; chan++) {
- if(d_chaninfo_rx[chan].owner == PMT_NIL) {
- d_chaninfo_rx[chan].owner = port_id;
- d_chaninfo_rx[chan].assigned_capacity = rqstd_capacity;
- d_rx[port]->send(s_response_allocate_channel,
- pmt_list3(invocation_handle,
- PMT_T,
- pmt_from_long(chan)));
- return;
- }
- }
+ if (verbose)
+ std::cout << "[USRP_SERVER] Couldnt find a TX chan\n";
- if (verbose)
- std::cout << "[USRP_SERVER] Couldnt find a RX chan\n";
-
-
- // no free RX chan found
- d_rx[port]->send(s_response_allocate_channel,
- pmt_list3(invocation_handle,
- pmt_from_long(CHANNEL_UNAVAIL),
- PMT_NIL));
- return;
- }
+ // no free TX chan found
+ port->send(s_response_allocate_channel,
+ pmt_list3(invocation_handle,
+ pmt_from_long(CHANNEL_UNAVAIL),
+ PMT_NIL));
+ return;
}
// Check the port type and deallocate assigned capacity based on this, ensuring
// that the owner of the method invocation is the owner of the port and that
the
// channel number is valid.
-void usrp_server::handle_cmd_deallocate_channel(pmt_t port_id, pmt_t data) {
+void
+usrp_server::handle_cmd_deallocate_channel(
+ mb_port_sptr port,
+ std::vector<struct channel_info> &chan_info,
+ pmt_t data)
+{
pmt_t invocation_handle = pmt_nth(0, data);
long channel = pmt_to_long(pmt_nth(1, data));
- long port;
-
- // Check that the channel number is valid, and that the calling port is the
- // owner of the channel, and if so remove the assigned capacity.
- if((port = tx_port_index(port_id)) != -1) {
-
- // not a valid channel number?
- if(channel >= d_ntx_chan) {
- d_tx[port]->send(s_response_deallocate_channel,
- pmt_list2(invocation_handle,
- pmt_from_long(CHANNEL_INVALID)));
- return;
- }
- // not the owner of the port?
- if(d_chaninfo_tx[channel].owner != port_id) {
- d_tx[port]->send(s_response_deallocate_channel,
- pmt_list2(invocation_handle,
- pmt_from_long(PERMISSION_DENIED)));
- return;
- }
-
- d_chaninfo_tx[channel].assigned_capacity = 0;
- d_chaninfo_tx[channel].owner = PMT_NIL;
-
- d_tx[port]->send(s_response_deallocate_channel,
- pmt_list2(invocation_handle,
- PMT_T));
+ // Ensure the channel is valid and the caller owns the port
+ if(!check_valid(port, channel, chan_info,
+ pmt_list2(s_response_deallocate_channel, invocation_handle)))
return;
- }
-
- // Repeated process on the RX side
- if((port = rx_port_index(port_id)) != -1) {
- // not a valid channel number?
- if(channel >= d_nrx_chan) {
- d_rx[port]->send(s_response_deallocate_channel,
- pmt_list2(invocation_handle,
- pmt_from_long(CHANNEL_INVALID)));
- return;
- }
+ chan_info[channel].assigned_capacity = 0;
+ chan_info[channel].owner = PMT_NIL;
- // not the owner of the channel?
- if(d_chaninfo_rx[channel].owner != port_id) {
- d_rx[port]->send(s_response_deallocate_channel,
- pmt_list2(invocation_handle,
- pmt_from_long(PERMISSION_DENIED)));
- return;
- }
-
- // Deallocate channel, remove ownership, and respond with success
- d_chaninfo_rx[channel].assigned_capacity = 0;
- d_chaninfo_rx[channel].owner = PMT_NIL;
- d_rx[port]->send(s_response_deallocate_channel,
- pmt_list2(invocation_handle,
- PMT_T));
- return;
- }
-
+ port->send(s_response_deallocate_channel,
+ pmt_list2(invocation_handle,
+ PMT_T));
+ return;
}
-void usrp_server::handle_cmd_xmit_raw_frame(pmt_t port_id, pmt_t data) {
+void usrp_server::handle_cmd_xmit_raw_frame(mb_port_sptr port,
std::vector<struct channel_info> &chan_info, pmt_t data) {
size_t n_bytes, psize;
long max_payload_len = transport_pkt::max_payload();
@@ -660,27 +590,11 @@
const void *samples = pmt_uniform_vector_elements(pmt_nth(2, data), n_bytes);
long timestamp = pmt_to_long(pmt_nth(3, data));
- long port = tx_port_index(port_id); // If returns -1, the port is invalid
- // which I don't know how to handle
- // since you can't respond on an
- // invalid port
-
- // Not a valid channel?
- if(channel >= d_ntx_chan) {
- d_tx[port]->send(s_response_xmit_raw_frame,
- pmt_list2(invocation_handle,
- pmt_from_long(CHANNEL_INVALID)));
+ // Ensure the channel is valid and the caller owns the port
+ if(!check_valid(port, channel, chan_info,
+ pmt_list2(s_response_xmit_raw_frame, invocation_handle)))
return;
- }
-
- // Not the owner of the channel?
- if(d_chaninfo_tx[channel].owner != port_id) {
- d_tx[port]->send(s_response_xmit_raw_frame,
- pmt_list2(invocation_handle,
- pmt_from_long(PERMISSION_DENIED)));
- return;
- }
-
+
// Determine the number of packets to allocate contiguous memory for
// bursting over the USB and get a pointer to the memory to be used in
// building the packets
@@ -864,4 +778,46 @@
return;
}
+bool
+usrp_server::check_valid(mb_port_sptr port,
+ long channel,
+ std::vector<struct channel_info> &chan_info,
+ pmt_t signal_info)
+{
+
+ pmt_t response_signal = pmt_nth(0, signal_info);
+ pmt_t invocation_handle = pmt_nth(1, signal_info);
+
+ // not a valid channel number?
+ if(channel >= chan_info.size()) {
+ port->send(response_signal,
+ pmt_list2(invocation_handle,
+ pmt_from_long(CHANNEL_INVALID)));
+
+ if(verbose)
+ std::cout << "[USRP_SERVER] Invalid channel number for event "
+ << response_signal << std::endl;
+ return false;
+ }
+
+ // not the owner of the port?
+ if(chan_info[channel].owner != port->port_symbol()) {
+ port->send(response_signal,
+ pmt_list2(invocation_handle,
+ pmt_from_long(PERMISSION_DENIED)));
+
+ if(verbose)
+ std::cout << "[USRP_SERVER] Invalid permissions"
+ << " for " << response_signal
+ << " from " << port->port_symbol()
+ << " proper owner is " << chan_info[channel].owner
+ << " on channel " << channel
+ << " invocation " << invocation_handle
+ << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
REGISTER_MBLOCK_CLASS(usrp_server);
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
2007-06-06 22:30:08 UTC (rev 5715)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
2007-06-06 22:35:12 UTC (rev 5716)
@@ -58,13 +58,18 @@
struct channel_info {
long assigned_capacity; // the capacity currently assignedby the channel
pmt_t owner; // port ID of the owner of the channel
+
+ channel_info() {
+ assigned_capacity = 0;
+ owner = PMT_NIL;
+ }
};
long d_rx_chan_mask; // A bitmask representing the channels in the
// receiving state
- struct channel_info d_chaninfo_tx[D_MAX_CHANNELS];
- struct channel_info d_chaninfo_rx[D_MAX_CHANNELS];
+ std::vector<struct channel_info> d_chaninfo_tx;
+ std::vector<struct channel_info> d_chaninfo_rx;
std::queue<mb_message_sptr> d_defer_queue;
@@ -84,9 +89,9 @@
static int max_capacity() { return D_USB_CAPACITY; }
private:
- void handle_cmd_allocate_channel(pmt_t port_id, pmt_t data);
- void handle_cmd_deallocate_channel(pmt_t port_id, pmt_t data);
- void handle_cmd_xmit_raw_frame(pmt_t port_id, pmt_t data);
+ void handle_cmd_allocate_channel(mb_port_sptr port, std::vector<struct
channel_info> &chan_info, pmt_t data);
+ void handle_cmd_deallocate_channel(mb_port_sptr port, std::vector<struct
channel_info> &chan_info, pmt_t data);
+ void handle_cmd_xmit_raw_frame(mb_port_sptr port, std::vector<struct
channel_info> &chan_info, pmt_t data);
void handle_cmd_start_recv_raw_samples(pmt_t port_id, pmt_t data);
int rx_port_index(pmt_t port_id);
int tx_port_index(pmt_t port_id);
@@ -94,6 +99,7 @@
void recall_defer_queue();
void reset_channels();
void handle_response_usrp_read(pmt_t data);
+ bool check_valid(mb_port_sptr port, long channel, std::vector<struct
channel_info> &chan_info, pmt_t signal_info);
};
#endif /* INCLUDED_USRP_SERVER_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5716 - in gnuradio/branches/developers/gnychis/inband/usrp/host: apps lib/inband,
gnychis <=