commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4946 - gnuradio/branches/developers/gnychis/inband/us


From: gnychis
Subject: [Commit-gnuradio] r4946 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Wed, 11 Apr 2007 01:29:05 -0600 (MDT)

Author: gnychis
Date: 2007-04-11 01:29:05 -0600 (Wed, 11 Apr 2007)
New Revision: 4946

Modified:
   
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:
putting ports in to a vector instead of having a seperate instance variable for 
each

fixed up the allocation and deallocation to cover both the RX and the TX side

no longer using pmt where not needed

added two predicates used for port type, RX or TX

added method to get the current capacity by summing over all RX and TX channels

added method to get the type of a port, RX or TX


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-04-11 06:17:05 UTC (rev 4945)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-04-11 07:29:05 UTC (rev 4946)
@@ -140,12 +140,12 @@
     d_cs->send(s_response_allocate_channel, reply_data);
     return;
   }
-//
-//  if (pmt_eq(event, s_cmd_deallocate_channel)) {
-//    reply_data = handle_cmd_deallocate_channel(port_id, data);
-//    d_cs->send(s_response_allocate_channel, reply_data);
-//    return;
-//  }
+
+  if (pmt_eq(event, s_cmd_deallocate_channel)) {
+    reply_data = handle_cmd_deallocate_channel(port_id, data);
+    d_cs->send(s_response_allocate_channel, reply_data);
+    return;
+  }
 //    
 //  if (pmt_eq(event, s_cmd_xmit_raw_frame)){
 //    reply_data = handle_cmd_xmit_raw_frame(data);
@@ -157,22 +157,40 @@
   std::cout << "unhandled msg: " << msg << std::endl;
 }
 
-int usrp_server::get_port_type(pmt_t port_id) {
+// Return -1 if it is not an RX port, or an index
+long usrp_server::is_tx_port(pmt_t port_id) {
 
-  // Go through all of the ports and determine if it is
-  // TX or RX
-  for(int port=0; port < D_MAX_PORTS; port++) {
-
+  for(int port=0; port < D_MAX_PORTS; port++) 
     if(pmt_eq(pmt_intern(d_tx.at(port)->port_name()), port_id))
-      return D_PORT_TYPE_TX;
+      return port;
 
+  return -1;
+}
+
+// Return -1 if it is not an RX port, or an index
+long usrp_server::is_rx_port(pmt_t port_id) {
+
+  for(int port=0; port < D_MAX_PORTS; port++) 
     if(pmt_eq(pmt_intern(d_rx.at(port)->port_name()), port_id))
-      return D_PORT_TYPE_RX;
-  }
+      return port;
 
-  return -1;  // couldn't find the port, -1 for error
+  return -1;
 }
 
+// Return one of two predicates for TX or RX ... -1 on error
+long usrp_server::get_port_type(pmt_t port_id) {
+
+  if(is_tx_port(port_id) != -1)
+    return D_PORT_TYPE_TX;
+
+  if(is_rx_port(port_id) != -1)
+    return D_PORT_TYPE_RX;
+
+  return -1;
+}
+
+// Go through all TX and RX channels, sum up the assigned capacity
+// and return it
 long usrp_server::current_capacity_allocation() {
   long capacity = 0;
 
@@ -181,61 +199,105 @@
 
   for(int chan=0; chan < d_in_rx_chan; chan++)
     capacity += chaninfo_rx[chan].d_assigned_capacity;
+
+  return capacity;
 }
     
-//pmt_t usrp_server::handle_cmd_allocate_channel(pmt_t port_id, pmt_t data) {
-//
-//  pmt_t invocation_handle = pmt_nth(0, data);
-//  long assigned_capacity = pmt_to_long(pmt_nth(1, data));
-//  long channel_number;
-//
-//  // Does the capacity exist?
-//  if(capacity_current >= assigned_capacity) {
-//    
-//    // Find a free channel
-//    for(channel_number=0; channel_number < d_in_tx_chan; channel_number++) 
-//      if(capacity_tx[channel_number].owner == PMT_NIL) 
-//        break;
-//
-//    // If we found a free channel, set the owner of the channel and the 
assigned capacity
-//    if(channel_number < d_in_tx_chan) {
-//      capacity_tx[channel_number].owner = port_id;
-//      capacity_tx[channel_number].reserved_capacity = 
pmt_from_long(assigned_capacity);  // set port capacity
-//      capacity = pmt_from_long(capacity_current + assigned_capacity);        
            // increase overall capacity
-//      return pmt_list3(invocation_handle, PMT_T, 
pmt_from_long(channel_number));
-//    }
-//    // no free channels found
-//    return pmt_list3(invocation_handle, PMT_F, PMT_NIL); 
-//  }
-//  // the capacity is not available
-//  return pmt_list3(invocation_handle, PMT_F, PMT_NIL);
-//}
+pmt_t usrp_server::handle_cmd_allocate_channel(pmt_t port_id, pmt_t data) {
 
-//pmt_t usrp_server::handle_cmd_deallocate_channel(pmt_t port_id, pmt_t data) {
-//  pmt_t invocation_handle = pmt_nth(0, data); 
-//  long channel_number = pmt_to_long(pmt_nth(1, data));    // the channel to 
deallocate
-//  long capacity_current = pmt_to_long(capacity);          // our current 
capacity as 'long'
+  pmt_t invocation_handle = pmt_nth(0, data);
+  long assigned_capacity = pmt_to_long(pmt_nth(1, data));
+  long chan, port_type;
+
+  // Regardless of port type, need to ensure the capacity exists, then we
+  // will worry about finding a channel depending on type
+  if((D_USB_CAPACITY - current_capacity_allocation()) < assigned_capacity)
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // no capacity 
available
+  
+  // Get the type of port sending the command which will be used to
+  // assign the capacity in the correct channel pool
+  if((port_type = get_port_type(port_id)) == -1)
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // unknown port type
+
+  if(port_type == D_PORT_TYPE_TX) {
+
+    // Find a free channel
+    for(chan=0; chan < d_in_tx_chan; chan++) 
+      if(chaninfo_tx[chan].d_owner == PMT_NIL) 
+        break;
+
+    // If we found a free channel, set the owner of the channel and assigned 
capacity
+    if(chan < d_in_tx_chan) {
+      chaninfo_tx[chan].d_owner = port_id;
+      chaninfo_tx[chan].d_assigned_capacity = assigned_capacity;
+      return pmt_list3(invocation_handle, PMT_T, pmt_from_long(chan));
+    }
+
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // no free TX chan 
found
+  }
+  
+  if(port_type == D_PORT_TYPE_RX) {
+
+    for(chan=0; chan < d_in_tx_chan; chan++) 
+      if(chaninfo_tx[chan].d_owner == PMT_NIL) 
+        break;
+
+    if(chan < d_in_tx_chan) {
+      chaninfo_tx[chan].d_owner = port_id;
+      chaninfo_tx[chan].d_assigned_capacity = assigned_capacity;
+      return pmt_list3(invocation_handle, PMT_T, pmt_from_long(chan));
+    }
+
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // no free RX chan 
found
+  }
+}
+
+// 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.
+pmt_t 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_type;
+  
+  if((port_type = get_port_type(port_id)) == -1)
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // unknown port type
+
+  if(port_type == D_PORT_TYPE_TX) {
+  
+    if(channel >= d_in_tx_chan) 
+      return pmt_list2(invocation_handle, PMT_F);   // not a legit channel 
number
+
+    if(chaninfo_tx[channel].d_owner != port_id) 
+      return pmt_list2(invocation_handle, PMT_F);   // not the owner of the 
port
+
+    chaninfo_tx[channel].d_assigned_capacity = 0;
+    chaninfo_tx[channel].d_owner = PMT_NIL;
+
+    return pmt_list2(invocation_handle, PMT_T);
+  }
+
+  if(port_type == D_PORT_TYPE_RX) {
+  
+    if(channel >= d_in_rx_chan) 
+      return pmt_list2(invocation_handle, PMT_F);   // not a legit channel 
number
+
+    if(chaninfo_rx[channel].d_owner != port_id) 
+      return pmt_list2(invocation_handle, PMT_F);   // not the owner of the 
port
+
+    chaninfo_rx[channel].d_assigned_capacity = 0;
+    chaninfo_rx[channel].d_owner = PMT_NIL;
+
+    return pmt_list2(invocation_handle, PMT_T);
+  }
+
+}
+
 //  
-//  // Check that this is a legit channel number, else bail immediately
-//  if(channel_number >= d_in_tx_chan) 
-//    return pmt_list2(invocation_handle, PMT_F);
-//
-//  // Check that the port is the owner of the channel
-//  if(capacity_tx[channel_number].owner == port_id) {
-//    // give back the capacity
-//    capacity = pmt_from_long(capacity_current + 
pmt_to_long(capacity_tx[channel_number].reserved_capacity));
-//    capacity_tx[channel_number].reserved_capacity = PMT_NIL;
-//    capacity_tx[channel_number].owner = PMT_NIL;
-//    return pmt_list2(invocation_handle, PMT_T);
-//  }
-//
-//  // not the owner
-//  return pmt_list2(invocation_handle, PMT_F);
-//}
-//  
 //pmt_t usrp_server::handle_cmd_xmit_raw_frame(pmt_t data) {
 //  pmt_t invocation_handle = pmt_nth(0, data);
-//  long channel_number = pmt_to_long(pmt_nth(1, data));  // the channel to 
deallocate
+//  long channel = pmt_to_long(pmt_nth(1, data));  // the channel to deallocate
 //
 //  // Read the samples, which are in a uniform numeric vector and find the 
number of samples
 //  size_t num_samples;
@@ -247,7 +309,7 @@
 //  usrp_inband_usb_packet usb_packet;                    // lets make a 
packet!
 //  
 //  // Set the header of the packet... what should 'tag' be set to here?
-//  usb_packet.set_header(0, channel_number, 0, payload_len);
+//  usb_packet.set_header(0, channel, 0, payload_len);
 //  usb_packet.set_timestamp(timestamp);
 //  memcpy(usb_packet.payload(), samples, payload_len);
 //

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-04-11 06:17:05 UTC (rev 4945)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-04-11 07:29:05 UTC (rev 4946)
@@ -29,6 +29,7 @@
  */
 class usrp_server : public mb_mblock
 {
+public:
   // our ports
   static const int D_PORT_TYPE_RX = 0;
   static const int D_PORT_TYPE_TX = 1;
@@ -61,8 +62,10 @@
   pmt_t handle_cmd_allocate_channel(pmt_t port_id, pmt_t data);
   pmt_t handle_cmd_deallocate_channel(pmt_t port_id, pmt_t data);
   pmt_t handle_cmd_xmit_raw_frame(pmt_t data);
-  int get_port_type(pmt_t port_id);
+  long is_rx_port(pmt_t port_id);
+  long is_tx_port(pmt_t port_id);
   long current_capacity_allocation();
+  long get_port_type(pmt_t port_id);
 };
 
 #endif /* INCLUDED_USRP_SERVER_H */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]