Il giorno gio, 22/03/2007 alle 12.14 +0100, Davide Anastasia ha scritto:
> Il giorno mar, 20/03/2007 alle 10.09 +0100, Davide Anastasia ha scritto:
> > > Maybe we should make gr_complex_short be  a typedef for
> > > complex<short> 
> > > and output those. 
> > 
> > Yep, in this way std::complex make conversion between float and short
> > transparently. Ok, I'll work in this direction. Actually I'm working
> > on
> > usrp1_source_s.cc. I'll send you my work when is completed, tested and
> > fully working. Soon maybe.
> > 
> > Regards, 
> 
> Hi List,
> I attach to this mail the works I've done on the gr-usrp driver, in
> special way on usrp1_source_s. It's not a very beautiful code, but work!
> Any suggestion is appreciate.

Attached there is a cumulative patch, which contains my mods for width
sample settings on usrp1_source_c.* and usrp1_source_s.*.
I tested it with usrp_fft.py and usrp_rx_cfile.py (with some mode I
made. Let me know if you need they.). They work nicely! ;)
In usrp1_source_c I still use the standard gr_complex, but I little
modification is needed to use a new gr_complex_short, if added to
complex.h.

Regards,
-- 
Davide Anastasia

web: http://www.davideanastasia.com/
email: [EMAIL PROTECTED]
diff -ru gr-usrp.old/src/usrp1_source_base.cc gr-usrp/src/usrp1_source_base.cc
--- gr-usrp.old/src/usrp1_source_base.cc	2007-01-31 08:36:56.000000000 +0100
+++ gr-usrp/src/usrp1_source_base.cc	2007-03-22 11:56:51.000000000 +0100
@@ -71,7 +71,9 @@
 unsigned int
 usrp1_source_base::sizeof_basic_sample() const
 {
-  return usrp_standard_rx::format_width(d_usrp->format()) / 8;
+  unsigned int usrp_width = usrp_standard_rx::format_width(d_usrp->format());
+  if (usrp_width >= 8) return usrp_standard_rx::format_width(d_usrp->format()) / 8;
+  else return 1;
 }
 
 bool
diff -ru gr-usrp.old/src/usrp1_source_c.cc gr-usrp/src/usrp1_source_c.cc
--- gr-usrp.old/src/usrp1_source_c.cc	2007-01-31 08:36:56.000000000 +0100
+++ gr-usrp/src/usrp1_source_c.cc	2007-03-23 13:20:41.000000000 +0100
@@ -31,6 +31,11 @@
 
 static const int NBASIC_SAMPLES_PER_ITEM = 2;	// I & Q
 
+static const int RANGE_1BIT = 128;		// setting gain
+static const int RANGE_2BIT = 32;
+static const int RANGE_4BIT = 1;
+static const int RANGE_8BIT = 128;
+
 usrp1_source_c_sptr
 usrp1_make_source_c (int which_board,
 		     unsigned int decim_rate,
@@ -102,6 +107,9 @@
   unsigned sbs = sizeof_basic_sample();
   unsigned nusrp_bytes_per_item = NBASIC_SAMPLES_PER_ITEM * sbs;
 
+  unsigned char traw;		// 8 bit
+  unsigned short tcycle_real, tcycle_img;
+
   int nitems = std::min (output_items_available,
 			 (int)(usrp_buffer_length / nusrp_bytes_per_item));
 
@@ -110,8 +118,43 @@
 
   switch (sbs){
   case 1:
-    for (int i = 0; i < nitems; i++){
-      out[i] = gr_complex ((float)(s8[2*i+0] << 8), (float)(s8[2*i+1] << 8));
+    for (int i = 0, i_in = 0; i < nitems; i++, i_in++){
+	switch ( format_width(format()) ) {	// Same as d_usrp->format_width()
+		case 1:
+		traw = s8[i_in];
+		for ( int j = 0; j <= 3; j++ ) {
+			tcycle_img = (short int)(( traw >> j*2 ) & 0x01);	// Masking (IMG?)
+			tcycle_real = (short int)(( traw >> j*2+1 ) & 0x01);	// Masking (REAL?)
+			out[i] = gr_complex ((float)(tcycle_real * RANGE_1BIT), (float)(tcycle_img * RANGE_1BIT));		// Saving sample
+			
+			(j != 3) ? i++ : 0;
+			if ( i >= nitems ) break;
+		}
+		
+		break;
+		case 2:		
+		traw = s8[i_in];
+		for ( int j=0; j <= 1; j++) {
+			tcycle_img = (short int)(( traw >> j*4 ) & 0x03);							// Masking (IMG?)
+			tcycle_real = (short int)(( traw >> j*4+2 ) & 0x03);							// Masking (REAL?)
+			out[i] = gr_complex ((float)(tcycle_real * RANGE_2BIT), (float)(tcycle_img * RANGE_2BIT));		// Saving sample
+
+			(j != 1) ? i++ : 0;
+			if ( i >= nitems ) break;
+		}
+		break;
+		case 4:		
+		traw = s8[i_in];
+
+		tcycle_img = (short int)( traw & 0x0F);									// Masking (IMG?)
+		tcycle_real = (short int)(( traw >> 4 ) & 0x0F);								// Masking (REAL?)
+		out[i] = gr_complex ((float)(tcycle_real * RANGE_4BIT), (float)(tcycle_img * RANGE_4BIT));			// Saving sample
+
+		break;
+		case 8:
+		default:
+      		out[i] = gr_complex ((float)(s8[2*i_in+0] * RANGE_8BIT), (float)(s8[2*i_in+1] * RANGE_8BIT));	// AS OLD code
+	}
     }
     break;
 
diff -ru gr-usrp.old/src/usrp1_source_s.cc gr-usrp/src/usrp1_source_s.cc
--- gr-usrp.old/src/usrp1_source_s.cc	2007-01-31 08:36:56.000000000 +0100
+++ gr-usrp/src/usrp1_source_s.cc	2007-03-23 12:16:57.000000000 +0100
@@ -28,9 +28,16 @@
 #include <gr_io_signature.h>
 #include <usrp_standard.h>
 #include <usrp_bytesex.h>
+// #include <iostream>
+
 
 static const int NBASIC_SAMPLES_PER_ITEM = 1;
 
+static const int RANGE_1BIT = 1;		// setting gain
+static const int RANGE_2BIT = 1;
+static const int RANGE_4BIT = 1;
+static const int RANGE_8BIT = 128;
+
 usrp1_source_s_sptr
 usrp1_make_source_s (int which_board, 
 		     unsigned int decim_rate,
@@ -103,6 +110,9 @@
   unsigned sbs = sizeof_basic_sample();
   unsigned nusrp_bytes_per_item = NBASIC_SAMPLES_PER_ITEM * sbs;
 
+  unsigned char traw;		// 8 bit
+  unsigned short tcycle;
+
   int nitems = std::min (output_items_available,
 			 (int)(usrp_buffer_length / nusrp_bytes_per_item));
 
@@ -111,8 +121,44 @@
 
   switch(sbs){
   case 1:
-    for (int i = 0; i < nitems; i++){
-      out[i] = s8[i] << 8;
+    for (int i = 0, i_in = 0; i < nitems; i++, i_in++){
+	switch ( format_width(format()) ) {	// Same as d_usrp->format_width()
+		case 1:
+		traw = s8[i_in];
+		for ( int j = 0; j <= 7; j++ ) {
+			// out[i] = 0;					// Setting zero
+			tcycle = (short int)(( traw >> j ) & 0x01);	// Masking
+			out[i] = (tcycle * RANGE_1BIT);			// Saving sample
+			
+			(j != 7) ? i++ : 0;
+			if ( i >= nitems ) break;
+		}
+		
+		break;
+		case 2:		
+		traw = s8[i_in];
+		for ( int j=0; j <= 3; j++) {
+			tcycle = (short int)((traw >> (j*2)) & 0x03 );
+			out[i] = ( tcycle * RANGE_2BIT );
+
+			(j != 3) ? i++ : 0;
+			if ( i >= nitems ) break;
+		}
+		break;
+		case 4:		
+		traw = s8[i_in];
+		for ( int j=0; j <= 1; j++) {	//  Ugly code!
+			tcycle = (short int)((traw >> (j*4)) & 0x0F );
+			out[i] = ( tcycle * RANGE_4BIT );
+
+			(j != 1) ? i++ : 0;
+			if ( i >= nitems ) break;
+		}
+		break;
+		case 8:
+		default:
+      		out[i] = usrp_to_host_short(s8[i_in] * RANGE_8BIT);
+	}
     }
     break;
 
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to