[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5662 - gnuradio/branches/developers/gnychis/inband/us
From: |
gnychis |
Subject: |
[Commit-gnuradio] r5662 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband |
Date: |
Mon, 4 Jun 2007 10:08:58 -0600 (MDT) |
Author: gnychis
Date: 2007-06-04 10:08:57 -0600 (Mon, 04 Jun 2007)
New Revision: 5662
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
Log:
Had trouble writing RX code from "messyness" of usrp_server, so significantly
cleaned up the code.
Code also follows the Eric "80" rule now ;)
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-04 16:08:44 UTC (rev 5661)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
2007-06-04 16:08:57 UTC (rev 5662)
@@ -115,8 +115,16 @@
// (if/when we do replicated ports, these will be replaced by a
// single replicated port)
for(int port=0; port < N_PORTS; port++) {
- d_tx.push_back(define_port("tx"+str(port), "usrp-tx", true,
mb_port::EXTERNAL));
- d_rx.push_back(define_port("rx"+str(port), "usrp-rx", true,
mb_port::EXTERNAL));
+
+ d_tx.push_back(define_port("tx"+str(port),
+ "usrp-tx",
+ true,
+ mb_port::EXTERNAL));
+
+ d_rx.push_back(define_port("rx"+str(port),
+ "usrp-rx",
+ true,
+ mb_port::EXTERNAL));
}
define_component("usrp", usrp_interface, PMT_F);
@@ -165,31 +173,36 @@
pmt_t event = msg->signal(); // the "name" of the message
pmt_t port_id = msg->port_id(); // which port it came in on
pmt_t data = msg->data();
+ pmt_t invocation_handle;
pmt_t metadata = msg->metadata();
- pmt_t invocation_handle;
- pmt_t reply_data;
pmt_t status;
+ // shutdown has no invocation handle, this prevents an exception
+ if(!pmt_eq(event, pmt_intern("%shutdown")))
+ invocation_handle = pmt_nth(0, data);
+
if (verbose){
std::cout << "[USRP_SERVER] event: " << event << std::endl;
std::cout << "[USRP_SERVER] port_id: " << port_id << std::endl;
}
- // It would be nice if this were all table driven, and we could
- // compute our state transition as f(current_state, port_id, signal)
+ // It would be nice if this were all table driven, and we could compute our
+ // state transition as f(current_state, port_id, signal)
// A message from the USRP CS, which should *only* be responses
//
// It is important that this set come before checking messages of any other
// components. This is since we always want to listen to the low level USRP
// server, even if we aren't initialized we are waiting for responses to
- // become initialized. Likewise, after the usrp_server is "closed", we
- // still want to pass responses back from the low level.
+ // become initialized. Likewise, after the usrp_server is "closed", we still
+ // want to pass responses back from the low level.
+
+ //---------------- USRP RESPONSE ---------------//
if (pmt_eq(port_id, d_cs_usrp->port_symbol())) {
-
+
+ //-------------- USRP OPEN ------------------//
if(pmt_eq(event, s_response_usrp_open)) {
// pass the response back over the regular CS port
- invocation_handle = pmt_nth(0, data);
pmt_t status = pmt_nth(1, data);
d_cs->send(s_response_open, pmt_list2(invocation_handle, status));
@@ -201,8 +214,8 @@
return;
}
+ //------------- USRP CLOSE -------------------//
else if (pmt_eq(event, s_response_usrp_close)) {
- invocation_handle = pmt_nth(0, data);
pmt_t status = pmt_nth(1, data);
d_cs->send(s_response_close, pmt_list2(invocation_handle, status));
@@ -215,15 +228,16 @@
return;
}
+ //--------------- USRP WRITE --------------//
else if (pmt_eq(event, s_response_usrp_write)) {
- invocation_handle = pmt_nth(0, data);
long channel = pmt_to_long(pmt_nth(1, data));
pmt_t status = pmt_nth(2, data);
// Find the port through the owner of the channel
long port = tx_port_index(d_chaninfo_tx[channel].owner);
- d_tx[port]->send(s_response_xmit_raw_frame, pmt_list2(invocation_handle,
status));
+ d_tx[port]->send(s_response_xmit_raw_frame,
+ pmt_list2(invocation_handle, status));
return;
}
@@ -233,18 +247,20 @@
// Checking for defer on all other messages
if(d_defer) {
if (verbose)
- std::cout << "[USRP_SERVER] Received msg while deferring (" <<
msg->signal() << ")\n";
+ std::cout << "[USRP_SERVER] Received msg while deferring ("
+ << msg->signal() << ")\n";
d_defer_queue.push(msg);
return;
}
- if (pmt_eq(port_id, d_cs->port_symbol())){ // message came in on our
control/status port
-
+ //--------- CONTROL / STATUS ------------//
+ if (pmt_eq(port_id, d_cs->port_symbol())){
+
+ //----------- OPEN -----------//
if (pmt_eq(event, s_cmd_open)){
// Reject if already open
if(d_opened) {
- invocation_handle = pmt_nth(0, data);
d_cs->send(s_response_open, pmt_list2(invocation_handle, PMT_F));
return;
}
@@ -256,8 +272,9 @@
return;
}
+ //---------- CLOSE -----------//
else if (pmt_eq(event, s_cmd_close)){
- invocation_handle = pmt_nth(0, data);
+
if(!d_opened) {
d_cs->send(s_response_close, pmt_list2(invocation_handle, PMT_F));
return;
@@ -268,60 +285,88 @@
return;
}
+ //---------- MAX CAPACITY ----------//
else if (pmt_eq(event, s_cmd_max_capacity)) {
- invocation_handle = pmt_nth(0, data);
+
if(!d_opened) {
- d_cs->send(s_response_max_capacity, pmt_list3(invocation_handle,
PMT_F, pmt_from_long(0)));
+ d_cs->send(s_response_max_capacity,
+ pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
return;
}
- reply_data = pmt_list3(invocation_handle, PMT_T,
pmt_from_long(max_capacity()));
- d_cs->send(s_response_max_capacity, reply_data);
+
+ d_cs->send(s_response_max_capacity,
+ pmt_list3(invocation_handle,
+ PMT_T,
+ pmt_from_long(max_capacity())));
return;
}
+ //---------- NTX CHAN --------------//
else if (pmt_eq(event, s_cmd_ntx_chan)) {
- invocation_handle = pmt_nth(0, data);
+
if(!d_opened) {
- d_cs->send(s_response_ntx_chan, pmt_list3(invocation_handle, PMT_F,
pmt_from_long(0)));
+ d_cs->send(s_response_ntx_chan,
+ pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
return;
}
- reply_data = pmt_list3(invocation_handle, PMT_T,
pmt_from_long(d_ntx_chan));
- d_cs->send(s_response_ntx_chan, reply_data);
+
+ d_cs->send(s_response_ntx_chan,
+ pmt_list3(invocation_handle,
+ PMT_T,
+ pmt_from_long(d_ntx_chan)));
return;
}
+ //---------- NRX CHAN -----------//
else if (pmt_eq(event, s_cmd_nrx_chan)) {
- invocation_handle = pmt_nth(0, data);
+
if(!d_opened) {
- d_cs->send(s_response_nrx_chan, pmt_list3(invocation_handle, PMT_F,
pmt_from_long(0)));
+ d_cs->send(s_response_nrx_chan,
+ pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
return;
}
- reply_data = pmt_list3(invocation_handle, PMT_T,
pmt_from_long(d_nrx_chan));
- d_cs->send(s_response_nrx_chan, reply_data);
+
+ d_cs->send(s_response_nrx_chan,
+ pmt_list3(invocation_handle,
+ PMT_T,
+ pmt_from_long(d_nrx_chan)));
return;
- }
+ }
+ //--------- ALLOCATION? -----------//
else if (pmt_eq(event, s_cmd_current_capacity_allocation)) {
- invocation_handle = pmt_nth(0, data);
+
if(!d_opened) {
- d_cs->send(s_response_current_capacity_allocation,
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+ d_cs->send(s_response_current_capacity_allocation,
+ pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
return;
}
- reply_data = pmt_list3(invocation_handle, PMT_T,
pmt_from_long(current_capacity_allocation()));
- d_cs->send(s_response_current_capacity_allocation, reply_data);
+
+ d_cs->send(s_response_current_capacity_allocation,
+ pmt_list3(invocation_handle,
+ PMT_T,
+ pmt_from_long(current_capacity_allocation())));
return;
}
goto unhandled;
}
-
+ //------------ ALLOCATE ----------------//
if (pmt_eq(event, s_cmd_allocate_channel)){
- if(!d_opened) { // check the USRP was opened
- pmt_t invocation_handle = pmt_nth(0, data);
+
+ if(!d_opened) {
long port;
if((port = tx_port_index(port_id)) != -1) {
- d_tx[port]->send(s_response_allocate_channel,
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+
+ d_tx[port]->send(s_response_allocate_channel,
+ pmt_list3(invocation_handle,
+ PMT_F,
+ pmt_from_long(0)));
} else {
+
port = rx_port_index(port_id);
- d_rx[port]->send(s_response_allocate_channel,
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+ d_rx[port]->send(s_response_allocate_channel,
+ pmt_list3(invocation_handle,
+ PMT_F,
+ pmt_from_long(0)));
}
return;
}
@@ -330,16 +375,25 @@
return;
}
+ //----------- DEALLOCATE ---------------//
if (pmt_eq(event, s_cmd_deallocate_channel)) {
+
if(!d_opened) { // check the USRP was opened
- pmt_t invocation_handle = pmt_nth(0, data);
long port;
if((port = tx_port_index(port_id)) != -1) {
- d_tx[port]->send(s_response_allocate_channel,
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+
+ d_tx[port]->send(s_response_deallocate_channel,
+ pmt_list3(invocation_handle,
+ PMT_F,
+ pmt_from_long(0)));
} else {
+
port = rx_port_index(port_id);
- d_rx[port]->send(s_response_allocate_channel,
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+ d_rx[port]->send(s_response_deallocate_channel,
+ pmt_list3(invocation_handle,
+ PMT_F,
+ pmt_from_long(0)));
}
return;
}
@@ -348,17 +402,38 @@
return;
}
+ //-------------- 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;
+ if(rx_port_index(port_id) != -1) {
+ // FIXME: this should include an error
+ d_rx[port]->send(s_response_xmit_raw_frame,
+ pmt_list2(invocation_handle, PMT_F));
+ return;
+ }
+
if(!d_opened) { // check the USRP was opened
- pmt_t invocation_handle = pmt_nth(0, data);
- long port = tx_port_index(port_id);
- d_tx[port]->send(s_response_xmit_raw_frame, pmt_list2(invocation_handle,
PMT_F));
+ port = tx_port_index(port_id);
+ d_tx[port]->send(s_response_xmit_raw_frame,
+ pmt_list2(invocation_handle, PMT_F));
return;
}
+
handle_cmd_xmit_raw_frame(port_id, data);
return;
}
+ //-------------- START RECV ----------------//
+ if (pmt_eq(event, s_cmd_start_recv_raw_samples)) {
+
+ if(!d_opened) {
+
+ }
+
+ }
+
unhandled:
std::cout << "[USRP_SERVER] unhandled msg: " << msg << std::endl;
}
@@ -402,7 +477,6 @@
pmt_t invocation_handle = pmt_nth(0, data);
long rqstd_capacity = pmt_to_long(pmt_nth(1, data));
long chan, port;
- pmt_t reply_data;
// If it's a TX port, allocate on a free channel, else check if it's a RX
port
// and allocate.
@@ -410,8 +484,12 @@
// Check capacity exists
if((D_USB_CAPACITY - current_capacity_allocation()) < rqstd_capacity) {
- reply_data = pmt_list3(invocation_handle,
pmt_from_long(RQSTD_CAPACITY_UNAVAIL), PMT_NIL); // no capacity available
- d_tx[port]->send(s_response_allocate_channel, reply_data);
+
+ // no capacity available
+ d_tx[port]->send(s_response_allocate_channel,
+ pmt_list3(invocation_handle,
+ pmt_from_long(RQSTD_CAPACITY_UNAVAIL),
+ PMT_NIL));
return;
}
@@ -420,8 +498,10 @@
if(d_chaninfo_tx[chan].owner == PMT_NIL) {
d_chaninfo_tx[chan].owner = port_id;
d_chaninfo_tx[chan].assigned_capacity = rqstd_capacity;
- reply_data = pmt_list3(invocation_handle, PMT_T, pmt_from_long(chan));
- d_tx[port]->send(s_response_allocate_channel, reply_data);
+ d_tx[port]->send(s_response_allocate_channel,
+ pmt_list3(invocation_handle,
+ PMT_T,
+ pmt_from_long(chan)));
return;
}
}
@@ -429,17 +509,24 @@
if (verbose)
std::cout << "[USRP_SERVER] Couldnt find a TX chan\n";
- reply_data = pmt_list3(invocation_handle, pmt_from_long(CHANNEL_UNAVAIL),
PMT_NIL); // no free TX chan found
- d_tx[port]->send(s_response_allocate_channel, reply_data);
+ // 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;
}
- // Repeat the same process on the RX side if the port was not determined to
be TX
+ // 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) {
- reply_data = pmt_list3(invocation_handle,
pmt_from_long(RQSTD_CAPACITY_UNAVAIL), PMT_NIL); // no capacity available
- d_rx[port]->send(s_response_allocate_channel, reply_data);
+
+ // no capacity available
+ d_rx[port]->send(s_response_allocate_channel,
+ pmt_list3(invocation_handle,
+ pmt_from_long(RQSTD_CAPACITY_UNAVAIL),
+ PMT_NIL));
return;
}
@@ -447,74 +534,90 @@
if(d_chaninfo_rx[chan].owner == PMT_NIL) {
d_chaninfo_rx[chan].owner = port_id;
d_chaninfo_rx[chan].assigned_capacity = rqstd_capacity;
- reply_data = pmt_list3(invocation_handle, PMT_T, pmt_from_long(chan));
- d_rx[port]->send(s_response_allocate_channel, reply_data);
+ 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 RX chan\n";
- reply_data = pmt_list3(invocation_handle, pmt_from_long(CHANNEL_UNAVAIL),
PMT_NIL); // no free RX chan found
- d_rx[port]->send(s_response_allocate_channel, reply_data);
+
+
+ // 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;
}
}
// 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.
+// 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) {
pmt_t invocation_handle = pmt_nth(0, data);
long channel = pmt_to_long(pmt_nth(1, data));
long port;
- pmt_t reply_data;
- // 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.
+ // 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) {
- reply_data = pmt_list2(invocation_handle,
pmt_from_long(CHANNEL_INVALID)); // not a legit channel number
- d_tx[port]->send(s_response_deallocate_channel, reply_data);
+ 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) {
- reply_data = pmt_list2(invocation_handle,
pmt_from_long(PERMISSION_DENIED)); // not the owner of the port
- d_tx[port]->send(s_response_deallocate_channel, reply_data);
+ 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;
- reply_data = pmt_list2(invocation_handle, PMT_T);
- d_tx[port]->send(s_response_deallocate_channel, reply_data);
+ d_tx[port]->send(s_response_deallocate_channel,
+ pmt_list2(invocation_handle,
+ PMT_T));
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) {
- reply_data = pmt_list2(invocation_handle,
pmt_from_long(CHANNEL_INVALID)); // not a legit channel number
- d_rx[port]->send(s_response_deallocate_channel, reply_data);
+ d_rx[port]->send(s_response_deallocate_channel,
+ pmt_list2(invocation_handle,
+ pmt_from_long(CHANNEL_INVALID)));
return;
}
+ // not the owner of the channel?
if(d_chaninfo_rx[channel].owner != port_id) {
- reply_data = pmt_list2(invocation_handle,
pmt_from_long(PERMISSION_DENIED)); // not the owner of the port
- d_rx[port]->send(s_response_deallocate_channel, reply_data);
+ 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;
-
- reply_data = pmt_list2(invocation_handle, PMT_T);
- d_rx[port]->send(s_response_deallocate_channel, reply_data);
+ d_rx[port]->send(s_response_deallocate_channel,
+ pmt_list2(invocation_handle,
+ PMT_T));
return;
}
@@ -524,7 +627,6 @@
size_t n_bytes, psize;
long max_payload_len = transport_pkt::max_payload();
- pmt_t reply_data;
pmt_t invocation_handle = pmt_nth(0, data);
long channel = pmt_to_long(pmt_nth(1, data));
@@ -533,25 +635,32 @@
long port;
- // Check that the channel number is valid, and that the caller is the owner
- // of the channel to send the frame
+ // Check that the channel number is valid, and that the caller is the owner
of
+ // the channel to send the frame
if((port = tx_port_index(port_id)) != -1) {
+ // Not a valid channel?
if(channel >= d_ntx_chan) {
- reply_data = pmt_list2(invocation_handle,
pmt_from_long(CHANNEL_INVALID)); // not a legit channel number
- d_tx[port]->send(s_response_xmit_raw_frame, reply_data);
+ d_tx[port]->send(s_response_xmit_raw_frame,
+ pmt_list2(invocation_handle,
+ pmt_from_long(CHANNEL_INVALID)));
return;
}
+ // Not the owner of the channel?
if(d_chaninfo_tx[channel].owner != port_id) {
- reply_data = pmt_list2(invocation_handle,
pmt_from_long(PERMISSION_DENIED)); // not the owner of the port
- d_tx[port]->send(s_response_xmit_raw_frame, reply_data);
+ 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
- long n_packets = static_cast<long>(std::ceil(n_bytes /
(double)max_payload_len));
+ // 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
+ long n_packets =
+ static_cast<long>(std::ceil(n_bytes / (double)max_payload_len));
+
pmt_t v_packets = pmt_make_u8vector(sizeof(transport_pkt) * n_packets, 0);
transport_pkt *pkts =
@@ -559,7 +668,8 @@
for(int n=0; n < n_packets; n++) {
- long payload_len = std::min((long)(n_bytes-(n*max_payload_len)),
(long)max_payload_len);
+ long payload_len =
+ std::min((long)(n_bytes-(n*max_payload_len)), (long)max_payload_len);
if(n == 0) { // first packet gets start of burst flag and timestamp
pkts[n].set_header(pkts[n].FL_START_OF_BURST, channel, 0, payload_len);
@@ -569,16 +679,23 @@
pkts[n].set_timestamp(0xffffffff);
}
- memcpy(pkts[n].payload(), (uint8_t *)samples+(max_payload_len * n),
payload_len);
+ memcpy(pkts[n].payload(),
+ (uint8_t *)samples+(max_payload_len * n),
+ payload_len);
}
- pkts[n_packets-1].set_end_of_burst(); // set the last packet's end of
burst
+ pkts[n_packets-1].set_end_of_burst(); // set the last packet's end of burst
if (verbose)
- std::cout << "[USRP_SERVER] Received raw frame invocation: " <<
invocation_handle << std::endl;
+ std::cout << "[USRP_SERVER] Received raw frame invocation: "
+ << invocation_handle << std::endl;
- // The actual response to the write will be generated by a
s_response_usrp_write
- d_cs_usrp->send(s_cmd_usrp_write, pmt_list3(invocation_handle,
pmt_from_long(channel), v_packets));
+ // The actual response to the write will be generated by a
+ // s_response_usrp_write
+ d_cs_usrp->send(s_cmd_usrp_write,
+ pmt_list3(invocation_handle,
+ pmt_from_long(channel),
+ v_packets));
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5662 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband,
gnychis <=