commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: gnychis
Subject: [Commit-gnuradio] r6397 - gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband
Date: Tue, 11 Sep 2007 09:32:19 -0600 (MDT)

Author: gnychis
Date: 2007-09-11 09:32:18 -0600 (Tue, 11 Sep 2007)
New Revision: 6397

Modified:
   gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc
   gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h
   
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac_symbols.h
   
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_gmac_tx.cc
Log:
Reworking some of the GMAC code for handling messages in the idle test

beefing up the GMAC test to test carrier sense in more detail.

Adding the ability to override the MAC carrier sense setting on a per packet
basis by allowing each packet to specify an override setting.


Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc   
2007-09-11 05:44:14 UTC (rev 6396)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc   
2007-09-11 15:32:18 UTC (rev 6397)
@@ -197,21 +197,40 @@
     // anything specific.  It is still being passive with data between the
     // application and the lower layer.
     case IDLE:
+      
+      //-------- TX PORT ----------------------------------------------------//
+      if(pmt_eq(d_tx->port_symbol(), port_id)) {
 
-      //-------- INCOMING PACKET ------------------------------------------- //
-      if(pmt_eq(event, s_cmd_tx_pkt)
-       && pmt_eq(d_tx->port_symbol(), port_id)) {
-        handle_cmd_tx_pkt(data);
-        return;
+        //-------- INCOMING PACKET ------------------------------------------//
+        if(pmt_eq(event, s_cmd_tx_pkt)) {
+          handle_cmd_tx_pkt(data);
+          return;
+        }
+
       }
-      
-      //-------- INCOMING PACKET RESPONSE ---------------------------------- //
-      if(pmt_eq(event, s_response_xmit_raw_frame)
-       && pmt_eq(d_us_tx->port_symbol(), port_id)) {
-        handle_response_xmit_raw_frame(data);
-        return;
+
+      //--------- USRP TX PORT ----------------------------------------------//
+      if(pmt_eq(d_us_tx->port_symbol(), port_id)) {
+
+        //-------- INCOMING PACKET RESPONSE ---------------------------------//
+        if(pmt_eq(event, s_response_xmit_raw_frame)) {
+          handle_response_xmit_raw_frame(data);
+          return;
+        }
+
       }
 
+      //--------- CS PORT ---------------------------------------------------//
+      if(pmt_eq(d_cs->port_symbol(), port_id)) {
+
+        //------- DISABLE CARRIER SENSE -------------------------------------//
+        if(pmt_eq(event, s_cmd_disable_carrier_sense)) {
+          handle_cmd_disable_carrier_sense(data);
+          return;
+        }
+
+      }
+
       goto unhandled;
 
     //------------------------ CLOSING CHANNELS -----------------------------//
@@ -362,7 +381,7 @@
   d_state = INIT_GMAC;
 
   // Set carrier sense to enabled by default with the specified threshold
-  set_carrier_sense(true, 21, PMT_NIL);
+  set_carrier_sense(true, 25, PMT_NIL);
 
   // Can now notify the application that we are initialized
   d_cs->send(s_response_gmac_initialized,
@@ -382,15 +401,24 @@
 void gmac::set_carrier_sense(bool toggle, long threshold, pmt_t invocation)
 {
   d_carrier_sense = toggle;
-  d_cs_thresh = threshold;
 
-  d_us_tx->send(s_cmd_to_control_channel,    // C/S packet
-             pmt_list2(invocation,        // invoc handle
-                       pmt_list1(
-                            pmt_list2(s_op_write_reg, 
-                                      pmt_list2(
-                                      pmt_from_long(REG_CS_THRESH), 
-                                      pmt_from_long(d_cs_thresh))))));
+  // Only waste the bandwidth and processing of a C/S packet if needed
+  if(threshold != d_cs_thresh) {
+    d_us_tx->send(s_cmd_to_control_channel,    // C/S packet
+               pmt_list2(invocation,           // invoc handle
+                         pmt_list1(
+                              pmt_list2(s_op_write_reg, 
+                                        pmt_list2(
+                                        pmt_from_long(REG_CS_THRESH), 
+                                        pmt_from_long(threshold))))));
+    d_cs_thresh = threshold;
+
+    if(verbose)
+      std::cout << "[GMAC] Changing CS threshold: " << d_cs_thresh << 
std::endl;
+  }
+
+  if(verbose)
+    std::cout << "[GMAC] Setting carrier sense to " << toggle << std::endl;
 }
 
 // The following sends a command to open the USRP, which will upload the
@@ -480,18 +508,17 @@
   pmt_t invocation_handle = pmt_nth(0, data);
   pmt_t dst = pmt_nth(1, data);
   pmt_t samples = pmt_nth(2, data);
-  pmt_t properties = pmt_nth(3, data);
+  pmt_t pkt_properties = pmt_nth(3, data);
 
-  pmt_t timestamp = pmt_from_long(0xffffffff); // NOW
+  pmt_t us_tx_properties = pmt_make_dict();
 
-  pmt_t tx_properties = pmt_make_dict();
-
   // Set the packet to be carrier sensed?
-  if(d_carrier_sense)
-    pmt_dict_set(tx_properties,
+  if(carrier_sense_pkt(pkt_properties))
+    pmt_dict_set(us_tx_properties,
                  pmt_intern("carrier-sense"),
                  PMT_T);
 
+  pmt_t timestamp = pmt_from_long(0xffffffff); // NOW
 
   // Construct the proper message for USRP server
   d_us_tx->send(s_cmd_xmit_raw_frame,
@@ -499,7 +526,7 @@
                                      d_us_tx_chan,
                                      samples, 
                           timestamp,
-                          tx_properties));
+                          us_tx_properties));
 
   if(verbose && 0)
     std::cout << "[GMAC] Transmitted packet\n";
@@ -519,4 +546,50 @@
                        status));
 }
 
+// This method determines whether carrier sense should be enabled based on two
+// properties.  The first is the MAC setting, which the user can set to carrier
+// sense packets by default or not.  The second is a per packet setting, which
+// can be used to override the MAC setting for the given packet only.
+bool gmac::carrier_sense_pkt(pmt_t pkt_properties) 
+{
+  // First we extract the per packet properties to check the per packet setting
+  // if it exists
+  if(pmt_is_dict(pkt_properties)) {
+
+    if(pmt_t pkt_cs = pmt_dict_ref(pkt_properties,
+                                   pmt_intern("carrier-sense"),
+                                   PMT_NIL)) {
+      // If the per packet property says true, enable carrier sense regardless
+      // of the MAC setting
+      if(pmt_eqv(pkt_cs, PMT_T))
+        return true;
+      // If the per packet setting says false, disable carrier sense regardless
+      // of the MAC setting
+      else if(pmt_eqv(pkt_cs, PMT_F))
+        return false;
+    }
+  }
+
+  // If we've hit this point, the packet properties did not state whether
+  // carrier sense should be used or not, so we use the MAC setting
+  if(d_carrier_sense)
+    return true;
+  else
+    return false;
+
+}
+
+// This method is called when an incoming disable carrier sense command is sent
+// over the control status channel.  It so far does not ellicit a response, 
this
+// needs to be added correctly.  It needs to wait for the response for the C/S
+// packet from usrp_server.
+void gmac::handle_cmd_disable_carrier_sense(pmt_t data) 
+{
+  pmt_t invocation_handle = pmt_nth(0, data);
+  
+  // We don't change the threshold, we leave it as is because the application
+  // did not request that it changes, only to disable carrier sense.
+  set_carrier_sense(false, d_cs_thresh, invocation_handle);
+}
+
 REGISTER_MBLOCK_CLASS(gmac);

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h    
2007-09-11 05:44:14 UTC (rev 6396)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h    
2007-09-11 15:32:18 UTC (rev 6397)
@@ -78,6 +78,8 @@
   void close_usrp();
   void handle_cmd_tx_pkt(pmt_t data);
   void handle_response_xmit_raw_frame(pmt_t data);
+  bool carrier_sense_pkt(pmt_t pkt_properties);
+  void handle_cmd_disable_carrier_sense(pmt_t data);
  
 };
 

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac_symbols.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac_symbols.h
    2007-09-11 05:44:14 UTC (rev 6396)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac_symbols.h
    2007-09-11 15:32:18 UTC (rev 6397)
@@ -32,9 +32,9 @@
 static pmt_t s_response_rx_pkt = pmt_intern("response-rx-pkt");
 
 // CS
-static pmt_t s_enable_carrier_sense = pmt_intern("cmd-enable-carrier-sense");
-static pmt_t s_disable_carrier_sense = pmt_intern("cmd-disable-carrier-sense");
-static pmt_t s_set_tx_retries = pmt_intern("cmd-set-tx-retries");
+static pmt_t s_cmd_enable_carrier_sense = 
pmt_intern("cmd-enable-carrier-sense");
+static pmt_t s_cmd_disable_carrier_sense = 
pmt_intern("cmd-disable-carrier-sense");
+static pmt_t s_cmd_set_tx_retries = pmt_intern("cmd-set-tx-retries");
 static pmt_t s_response_gmac_initialized = 
pmt_intern("response-gmac-initialized");
 static pmt_t s_response_enable_carrier_sense = 
pmt_intern("response-enable-carrier-sense");
 static pmt_t s_response_disable_carrier_sense = 
pmt_intern("response-disable-carrier-sense");

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_gmac_tx.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_gmac_tx.cc
   2007-09-11 05:44:14 UTC (rev 6396)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_gmac_tx.cc
   2007-09-11 15:32:18 UTC (rev 6397)
@@ -201,7 +201,7 @@
   // allocate the uniform vector for the samples
   // FIXME perhaps hold on to this between calls
 
-#if 1
+#if 0
   long nsamples_this_frame =
     std::min(d_nsamples_to_send - d_nsamples_xmitted,
             d_samples_per_frame);
@@ -221,7 +221,6 @@
   int16_t *samples = pmt_s16vector_writeable_elements(uvec, ignore);
 
   // fill in the complex sinusoid
-
   for (int i = 0; i < nsamples_this_frame; i++){
 
     if (1){
@@ -239,18 +238,32 @@
       samples[2*i+1] = (int16_t) s.imag();
     }
   }
-
+    
+  // Per packet properties
   pmt_t tx_properties = pmt_make_dict();
-  pmt_dict_set(tx_properties,
-               pmt_intern("carrier-sense"),
-               PMT_T);
 
+  if(d_nframes_xmitted > 25000) {
+    pmt_dict_set(tx_properties,
+                 pmt_intern("carrier-sense"),
+                 PMT_F);
+  }
+
+  if(d_nframes_xmitted > 40000) {
+    pmt_dict_set(tx_properties,
+                 pmt_intern("carrier-sense"),
+                 PMT_NIL);
+  }
+//
+//  if(d_nframes_xmitted > 60000) {
+//    d_cs->send(s_cmd_disable_carrier_sense, pmt_list1(PMT_NIL));
+//  }
+
   pmt_t timestamp = pmt_from_long(0xffffffff); // NOW
   d_tx->send(s_cmd_tx_pkt,
             pmt_list4(PMT_NIL,   // invocation-handle
            PMT_NIL,         // destination
                       uvec,                                // the samples
-           PMT_NIL));       // no properties yet!
+           tx_properties)); // per pkt properties
 
   d_nsamples_xmitted += nsamples_this_frame;
   d_nframes_xmitted++;





reply via email to

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