msdd6000 source upgraded and enabled
[debian/gnuradio] / gr-msdd6000 / src / msdd_source_base.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 //#define MSDD_DEBUG_TRUE
24 //#define MSDD_DEBUG2_TRUE
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <msdd_source_base.h>
31 #include <gr_io_signature.h>
32 #include <assert.h>
33 #include <netdb.h>
34 #include <omnithread.h>
35 #include <stdexcept>
36 #include <sys/socket.h>
37 #include <arpa/inet.h>
38
39 #ifdef MSDD_DEBUG_TRUE
40 #include <iostream>
41 #define MSDD_DEBUG(x) std::cout << x << std::endl;
42 #else
43 #define MSDD_DEBUG(x)
44 #endif
45
46
47 #ifdef MSDD_DEBUG2_TRUE
48 #include <iostream>
49 #define MSDD_DEBUG2(x) std::cout << x << std::endl;
50 #else
51 #define MSDD_DEBUG2(x)
52 #endif
53
54 #include <iostream>
55
56 namespace {
57         const int OUTPUT_MAX((1 << 15)*8);
58         const double PGA_MAX(75);
59         const double PGA_MIN(10);
60         const double PGA_STEP(.5);
61         const double DEFAULT_RX_FREQ(2.417e6);
62         const double DEFAULT_GAIN(32);
63         const msdd_source_base::msdd_fft_mode_t DEFAULT_FFT_MODE(msdd_source_base::MODE_MAG);
64         const msdd_source_base::msdd_fft_points_t DEFAULT_FFT_POINTS(msdd_source_base::S8192);
65         const msdd_source_base::msdd_decimation_t DEFAULT_DECIMATION_RATE(msdd_source_base::D2);
66 }
67
68 class msdd_source_base::Impl {
69   
70 public:
71   Impl(int opp_mode) :
72     d_noverruns (0),
73     d_deci_rate (DEFAULT_DECIMATION_RATE),
74     d_rx_freq ((unsigned long) DEFAULT_RX_FREQ),
75     d_gain(DEFAULT_GAIN),
76     d_verbose (false),
77     d_updated(false),
78     d_msdd_command_type((msdd_command_type_t) opp_mode),
79     d_msdd_fft_mode(DEFAULT_FFT_MODE),
80     d_desired_sample_size(2^15),
81     d_fft_points (DEFAULT_FFT_POINTS)
82     {
83     
84     }
85
86   int            d_noverruns;
87   msdd_decimation_t   d_deci_rate;
88   unsigned long  d_rx_freq;
89   double         d_gain;
90   bool           d_verbose;
91   bool           d_updated;  
92   msdd_command_type_t d_msdd_command_type;
93   msdd_fft_mode_t d_msdd_fft_mode;
94   unsigned long  d_desired_sample_size;
95   
96   int            d_socket;        // handle to socket
97   int            d_socket_rcv;    // handle to socket retuned in the accept call
98   struct in_addr d_ip_src;        // store the source IP address to use
99   unsigned short d_port_src;      // the port number to open for connections to this service
100   sockaddr_in    d_sockaddr_src;  // store the source sockaddr data (formatted IP address and port number) 
101   std::auto_ptr<unsigned char> d_temp_buff;     // hold buffer between calls
102
103   omni_mutex    d_mutex;
104   msdd_fft_points_t   d_fft_points; 
105   
106   struct msdd_request_fft_packet {
107       msdd_command_type_t command_type;
108       int foo_x20;
109       unsigned int center_freq_mhz;
110       int offset_freq_hz;
111       int gain;
112       msdd_fft_window_type_t window_type;
113       msdd_fft_points_t fft_points;
114       msdd_decimation_t decimation;
115       msdd_fft_mode_t fft_mode;
116       int number_sets;
117   } __attribute__((__packed__));
118   
119   struct msdd_request_iq_packet {
120       msdd_command_type_t command_type;
121       int foo0x18;
122       unsigned int center_freq_mhz;
123       int offset_freq_hz;
124       int gain;
125       int number;
126       msdd_decimation_t decimation;
127       int number_sets;
128   } __attribute__((__packed__));
129
130   void make_request_fft_packet(msdd_request_fft_packet& packet);
131   
132   void make_request_iq_packet(msdd_request_iq_packet& packet, unsigned int number_samples);
133   
134   msdd_request_fft_packet   d_fft_request_packet; // fft request packet
135   msdd_request_iq_packet    d_iq_request_packet; // fft request packet
136 };
137
138
139 msdd_source_base::msdd_source_base (const std::string &name,
140                                       gr_io_signature_sptr output_signature,
141                                       int which_board,
142                                       int opp_mode,
143                                       const char *src, 
144                                   unsigned short port_src
145                                       ) throw (std::runtime_error)
146   : gr_sync_block (name,
147                    gr_make_io_signature (0, 0, 0),
148                    output_signature),
149                    pimpl( new Impl(opp_mode))
150     
151 {
152     int ret (0);
153     
154     // Set up the address stucture for the source address and port numbers
155     // Get the source IP address from the host name
156     struct hostent *hsrc (gethostbyname(src));
157     
158     if(hsrc) {   // if the source was provided as a host namex
159       pimpl->d_ip_src = *(struct in_addr*)hsrc->h_addr_list[0];    
160     }
161     else { // assume it was specified as an IP address
162       if((ret=inet_aton(src, &pimpl->d_ip_src)) == 0) {            // format IP address
163         perror("Not a valid source IP address or host name");
164         throw std::runtime_error("can't initialize source socket");
165       }
166     }
167
168     pimpl->d_port_src = htons(port_src);     // format port number
169     
170     pimpl->d_sockaddr_src.sin_family = AF_INET;
171     pimpl->d_sockaddr_src.sin_addr   = pimpl->d_ip_src;
172     pimpl->d_sockaddr_src.sin_port   = pimpl->d_port_src;
173
174     pimpl->d_temp_buff.reset(new unsigned char[OUTPUT_MAX + 
175                                      std::max(sizeof(Impl::msdd_request_iq_packet),
176                                          sizeof(Impl::msdd_request_fft_packet))]);   // allow it to hold up to payload_size bytes
177
178   set_output_multiple (OUTPUT_MAX / output_signature->sizeof_stream_item (0));
179 }
180                                       
181
182 bool
183 msdd_source_base::open()
184 {
185   omni_mutex_lock l(pimpl->d_mutex);   // hold mutex for duration of this function
186   // create socket
187   MSDD_DEBUG2("MSDD: Before socket ")
188   pimpl->d_socket = socket(PF_INET, SOCK_STREAM, 0);
189   if(pimpl->d_socket == -1) {
190     perror("socket open");
191     throw std::runtime_error("can't open socket");
192   }
193
194   // Turn on reuse address
195   int opt_val (1);
196   if(setsockopt(pimpl->d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) {
197     perror("SO_REUSEADDR");
198     throw std::runtime_error("can't set socket option SO_REUSEADDR");
199   }
200
201   // Don't wait when shutting down
202   linger lngr;
203   lngr.l_onoff  = 1;
204   lngr.l_linger = 0;
205   if(setsockopt(pimpl->d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger)) == -1) {
206     perror("SO_LINGER");
207     throw std::runtime_error("can't set socket option SO_LINGER");
208   }
209
210   // Set a timeout on the receive function to not block indefinitely
211   // This value can (and probably should) be changed
212 //  timeval timeout;
213 //  timeout.tv_sec = 1;
214 //  timeout.tv_usec = 0;
215 //  if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (void*)&timeout, sizeof(timeout)) == -1) {
216 //    perror("SO_RCVTIMEO");
217 //    throw std::runtime_error("can't set socket option SO_RCVTIMEO");
218 //  }
219
220   // bind socket to an address and port number to listen on
221   MSDD_DEBUG2("MSDD: Before socket bind to " << pimpl->d_sockaddr_src.sin_port)
222   if(::connect(pimpl->d_socket, (struct sockaddr*)&pimpl->d_sockaddr_src, sizeof(pimpl->d_sockaddr_src)) == -1) {
223     perror("socket bind");
224     throw std::runtime_error("can't bind socket");
225   }
226
227   MSDD_DEBUG2("MSDD: Socket open")
228   pimpl->d_updated = true;
229   return pimpl->d_socket != 0;
230 }
231
232 /* read n bytes from a socket descriptor */
233 int 
234 msdd_source_base::readsock(int sockfd, unsigned char* buf, int nbytes) {
235     int nleft (nbytes);
236     int nread (0);
237     
238     while (nleft > 0) {
239       MSDD_DEBUG2("MSDD: Before socket read: " << nleft)
240             if ((nread = ::read(sockfd, buf, nleft)) < 0) {
241                 return(nread); /* error, nread < 0 */
242             } else if (nread == 0) {
243                 break;
244             }
245             
246             nleft -= nread;
247             buf += nread;
248     }
249     return(nbytes - nleft);
250 }
251
252 bool
253 msdd_source_base::close()
254 {
255   omni_mutex_lock l(pimpl->d_mutex);   // hold mutex for duration of this function
256
257   if (pimpl->d_socket){
258     shutdown(pimpl->d_socket, SHUT_RDWR);
259     pimpl->d_socket = 0;
260   }
261   pimpl->d_updated = true;
262   
263   return true;
264 }
265
266 msdd_source_base::~msdd_source_base ()
267 {
268   msdd_source_base::close();
269 }
270
271 unsigned int
272 msdd_source_base::sizeof_basic_sample() const
273 {
274   switch (pimpl->d_msdd_command_type) {
275   case SAMPLES_REALTIME:
276     return 4;
277   case SAMPLES_FFT:
278     switch (pimpl->d_msdd_fft_mode) {
279     case MODE_IQ:
280     case MODE_MAG:
281       return 4;
282     case MODE_MAGDB:
283       return 1;
284     default:
285       assert (false); // bad mode
286     }
287   default:
288     assert (false); // bad mode
289   }
290 }
291
292 bool
293 msdd_source_base::start()
294 {
295         return msdd_source_base::open();
296 }
297
298 bool
299 msdd_source_base::stop()
300 {
301         return msdd_source_base::close();
302 }
303
304 void* 
305 msdd_source_base::make_request_packet(unsigned int& size, unsigned int number_samples) {
306   switch (pimpl->d_msdd_command_type) {
307   case SAMPLES_REALTIME:
308     pimpl->make_request_iq_packet(pimpl->d_iq_request_packet, number_samples);
309     size = sizeof (pimpl->d_iq_request_packet);
310     return &pimpl->d_iq_request_packet;
311   case SAMPLES_FFT:
312     pimpl->make_request_fft_packet(pimpl->d_fft_request_packet);
313     size = sizeof (pimpl->d_fft_request_packet);
314     return &pimpl->d_fft_request_packet;
315   default:
316     assert (false); // bad mode
317   }
318 }
319
320 void 
321 msdd_source_base::Impl::make_request_fft_packet(msdd_request_fft_packet& packet) 
322 {
323     packet.command_type = SAMPLES_FFT;  // FFT samples Command
324     packet.foo_x20 = 0x20;
325     packet.center_freq_mhz = d_rx_freq;
326     packet.offset_freq_hz = 0;
327     packet.gain = (int) d_gain; // gain
328     packet.window_type = WINDOW_HANNING; // magic number
329     packet.fft_points = d_fft_points;
330     packet.decimation = d_deci_rate;
331     packet.fft_mode = MODE_MAGDB;
332     packet.number_sets = 1;
333 }
334
335 void 
336 msdd_source_base::Impl::make_request_iq_packet(msdd_request_iq_packet& packet, unsigned int number_samples) 
337 {
338     packet.command_type = SAMPLES_REALTIME;  // FFT samples Command
339     packet.foo0x18 = 0x18; // magic number
340     packet.center_freq_mhz = d_rx_freq;
341     packet.offset_freq_hz = 0;
342     packet.gain = (int) d_gain; // gain
343     packet.number = number_samples * 4;
344     packet.decimation = d_deci_rate;
345     packet.number_sets = 1;
346 }
347
348 int
349 msdd_source_base::work (int noutput_items,
350                          gr_vector_const_void_star &input_items,
351                          gr_vector_void_star &output_items)
352 {
353   int output_index (0);
354   int output_items_produced;
355   int bytes_read;
356
357   unsigned int packet_size;
358   
359   MSDD_DEBUG("MSDD: requested items: " << noutput_items)
360   int noutput_items_desired = std::min (noutput_items, (int) pimpl->d_desired_sample_size);
361   MSDD_DEBUG("MSDD: desired items: " << noutput_items_desired)
362   
363   while (output_index < noutput_items_desired){
364
365     int nbytes = (pimpl->d_msdd_command_type == SAMPLES_REALTIME) ? 
366         ninput_bytes_reqd_for_noutput_items (noutput_items_desired - output_index) :
367         ninput_bytes_reqd_for_noutput_items (msdd_source_base::fft_points());
368     
369     void* request_packet = msdd_source_base::make_request_packet(packet_size, noutput_items_desired);
370     
371     nbytes = std::min (nbytes, OUTPUT_MAX);
372     MSDD_DEBUG2("MSDD: payload sizes: nbytes1: " << nbytes )
373
374     // send request
375     int result_nbytes = ::write(pimpl->d_socket, request_packet, packet_size);
376     //assert (result_nbytes == sizeof(msdd_request_packet));
377     
378     // receive ack
379     result_nbytes = ::read (pimpl->d_socket, (unsigned char*) request_packet, packet_size);
380     MSDD_DEBUG2("MSDD: response: " << result_nbytes)
381     //assert (result_nbytes == sizeof(msdd_request_packet));
382     
383     // receive payload
384     result_nbytes = msdd_source_base::readsock (pimpl->d_socket, pimpl->d_temp_buff.get(), nbytes);
385     MSDD_DEBUG("MSDD: reading bytes: " << nbytes << " received: " << result_nbytes)
386     if (result_nbytes > (int) nbytes){
387       // fprintf (stderr, "msdd_source: overrun\n");
388       fputs ("uO", stderr);
389       pimpl->d_noverruns++;
390       result_nbytes = nbytes; // truncate
391     }
392     
393     if (result_nbytes < 0)      // We've got a problem.  Usually board unplugged or powered down.
394       return -1;                // Indicate we're done.
395
396     if (result_nbytes != nbytes){       // not really an error, but unexpected
397       fprintf (stderr, "msdd_source: short read.  Expected %d, got %d\n",
398                nbytes, result_nbytes);
399     }
400
401     copy_from_msdd_buffer (output_items,
402                            output_index,
403                            noutput_items_desired - output_index,   // output_items_available
404                            output_items_produced,          // [out]
405                            pimpl->d_temp_buff.get(),                               // usrp_buffer
406                            result_nbytes,
407                            bytes_read);                    // [out]
408     
409     output_index += output_items_produced;
410     
411     if (pimpl->d_msdd_command_type == SAMPLES_FFT) break; 
412   }
413
414   MSDD_DEBUG("MSDD: items produced: " << output_items_produced << " index: " << output_index)
415   
416   //assert(false);
417   return output_index;
418 }
419
420
421 bool
422 msdd_source_base::set_decim_rate (unsigned int rate)
423 {
424         bool result (true);
425         switch (rate) {
426     case 1:
427       pimpl->d_deci_rate = D0;
428       break;
429     case 2:
430       pimpl->d_deci_rate = D1;
431       break;      
432         case 4:
433           pimpl->d_deci_rate = D2;
434       break;      
435         case 8:
436           pimpl->d_deci_rate = D3;
437       break;      
438         case 16:
439           pimpl->d_deci_rate = D4;
440           break;
441     case 32:
442       pimpl->d_deci_rate = D5;
443       break;
444     case 64:
445       pimpl->d_deci_rate = D6;
446       break;
447     case 128:
448       pimpl->d_deci_rate = D7;
449       break;
450     case 256:
451       pimpl->d_deci_rate = D8;
452       break;
453         default:
454           result = false;
455         }
456         
457         return result;
458 }
459 //
460 //bool
461 //msdd_source_base::set_nchannels (int nchan)
462 //{
463 //  // return d_usrp->set_nchannels (nchan);
464 //      return true;
465 //}
466 //
467 //bool
468 //msdd_source_base::set_mux (int mux)
469 //{
470 //  return d_usrp->set_mux (mux);
471 //}
472
473 bool
474 msdd_source_base::set_rx_freq (int channel, double freq)
475 {
476         assert (channel == 0);
477         bool result (false);
478         
479         if (freq >=  30e6 && freq <= 6e9) {
480           pimpl->d_rx_freq = (unsigned long) freq / 1000000;
481                 result = true;
482         }
483         
484         return result;
485 }
486
487
488 unsigned long
489 msdd_source_base::set_fft_size (int channel, unsigned long fft_size)
490 {
491     assert (channel == 1);
492     
493     switch (fft_size) {
494       case 256:        
495         pimpl->d_fft_points = S256;
496         break;
497       case 512:
498         pimpl->d_fft_points = S512;       
499         break;
500       case 1024:
501         pimpl->d_fft_points = S1024;
502         break;        
503       case 2048:
504         pimpl->d_fft_points = S2048;
505         break;        
506       case 4096:
507         pimpl->d_fft_points = S4096;
508         break;        
509       case 8192:
510         pimpl->d_fft_points = S8192;
511         break;        
512       case 16384:
513         pimpl->d_fft_points = S16384;
514         break;        
515       case 32768:
516         pimpl->d_fft_points = S32768;
517         break;        
518     }
519     
520     return msdd_source_base::fft_points();
521 }
522
523 //
524 //long
525 //msdd_source_base::fpga_master_clock_freq() const
526 //{
527 //  return d_usrp->fpga_master_clock_freq();
528 //}
529 //
530 //long
531 //msdd_source_base::converter_rate() const
532 //{
533 //  // return d_usrp->converter_rate();
534 //      return 8;
535 //}
536
537 unsigned int
538 msdd_source_base::decim_rate () const
539 {
540         return 1 << pimpl->d_deci_rate;
541 }
542 //
543 //int
544 //msdd_source_base::nchannels () const
545 //{
546 //  return d_usrp->nchannels ();
547 //}
548 //
549 //int
550 //msdd_source_base::mux () const
551 //{
552 //  return d_usrp->mux ();
553 //}
554
555 double
556 msdd_source_base::rx_freq (int channel) const
557 {
558   assert (channel == 0);
559         
560   return pimpl->d_rx_freq;
561 }
562
563 unsigned int
564 msdd_source_base::fft_points() const
565 {
566   return (1 << pimpl->d_fft_points);
567 }
568
569 int 
570 msdd_source_base::noverruns () const 
571
572   return pimpl->d_noverruns; 
573 }
574
575 //bool
576 //msdd_source_base::set_fpga_mode (int mode)
577 //{
578 //  return d_usrp->set_fpga_mode (mode);
579 //}
580 //
581 //bool
582 //msdd_source_base::set_ddc_phase (int channel, int phase)
583 //{
584 //  return d_usrp->set_ddc_phase(channel, phase);
585 //}
586 //
587 //bool
588 //msdd_source_base::set_dc_offset_cl_enable(int bits, int mask)
589 //{
590 //  return d_usrp->set_dc_offset_cl_enable(bits, mask);
591 //}
592
593 void
594 msdd_source_base::set_verbose (bool verbose)
595 {  
596   pimpl->d_verbose = verbose;
597 }
598 //
599 //bool
600 //msdd_source_base::write_aux_dac (int which_dboard, int which_dac, int value)
601 //{
602 //  return d_usrp->write_aux_dac (which_dboard, which_dac, value);
603 //}
604 //
605 //int
606 //msdd_source_base::read_aux_adc (int which_dboard, int which_adc)
607 //{
608 //  return d_usrp->read_aux_adc (which_dboard, which_adc);
609 //}
610 //
611 //bool
612 //msdd_source_base::write_eeprom (int i2c_addr, int eeprom_offset, const std::string buf)
613 //{
614 //  return d_usrp->write_eeprom (i2c_addr, eeprom_offset, buf);
615 //}
616 //
617 //std::string
618 //msdd_source_base::read_eeprom (int i2c_addr, int eeprom_offset, int len)
619 //{
620 //  return d_usrp->read_eeprom (i2c_addr, eeprom_offset, len);
621 //}
622 //
623 //bool
624 //msdd_source_base::write_i2c (int i2c_addr, const std::string buf)
625 //{
626 //  return d_usrp->write_i2c (i2c_addr, buf);
627 //}
628 //
629 //std::string
630 //msdd_source_base::read_i2c (int i2c_addr, int len)
631 //{
632 //  return d_usrp->read_i2c (i2c_addr, len);
633 //}
634 //
635 bool
636 msdd_source_base::set_pga (int which, double gain)
637 {
638         if (gain >= PGA_MIN & gain <= PGA_MAX) {
639           pimpl->d_gain = gain;
640                 return true;
641         }
642         return false;
643 }
644
645 double
646 msdd_source_base::pga (int which) const
647 {
648   return pimpl->d_gain;
649 }
650
651 double
652 msdd_source_base::pga_min () const
653 {
654   return PGA_MIN;
655 }
656
657 double
658 msdd_source_base::pga_max () const
659 {
660   return PGA_MAX;
661 }
662
663 double
664 msdd_source_base::pga_db_per_step () const
665 {
666   return PGA_STEP;
667 }
668
669 //int
670 //msdd_source_base::daughterboard_id (int which) const
671 //{
672 //  return d_usrp->daughterboard_id (which);
673 //}
674 //
675 //
676 //bool
677 //msdd_source_base::set_adc_offset (int which, int offset)
678 //{
679 //  return d_usrp->set_adc_offset (which, offset);
680 //}
681 //
682 //bool
683 //msdd_source_base::set_dac_offset (int which, int offset, int offset_pin)
684 //{
685 //  return d_usrp->set_dac_offset (which, offset, offset_pin);
686 //}
687 //
688 //bool
689 //msdd_source_base::set_adc_buffer_bypass (int which, bool bypass)
690 //{
691 //  return d_usrp->set_adc_buffer_bypass (which, bypass);
692 //}
693
694 std::string
695 msdd_source_base::serial_number()
696 {
697   return "SoftTronics MSDD 6000";
698 }
699 //
700 //bool
701 //msdd_source_base::_write_oe (int which_dboard, int value, int mask)
702 //{
703 //  return d_usrp->_write_oe (which_dboard, value, mask);
704 //}
705 //
706 //bool
707 //msdd_source_base::write_io (int which_dboard, int value, int mask)
708 //{
709 //  return d_usrp->write_io (which_dboard, value, mask);
710 //}
711 //
712 //int
713 //msdd_source_base::read_io (int which_dboard)
714 //{
715 //  return d_usrp->read_io (which_dboard);
716 //}
717 //
718 //
719 //
720 //
721 //// internal routines...
722 //
723 //bool
724 //msdd_source_base::_write_fpga_reg (int regno, int value)
725 //{
726 //  return d_usrp->_write_fpga_reg (regno, value);
727 //}
728 //
729 //bool
730 //msdd_source_base::_write_fpga_reg_masked (int regno, int value, int mask)
731 //{
732 //  return d_usrp->_write_fpga_reg_masked (regno, value, mask);
733 //}
734 //
735 //int
736 //msdd_source_base::_read_fpga_reg (int regno)
737 //{
738 //  return d_usrp->_read_fpga_reg (regno);
739 //}
740 //
741 //bool
742 //msdd_source_base::_write_9862 (int which_codec, int regno, unsigned char value)
743 //{
744 //  return d_usrp->_write_9862 (which_codec, regno, value);
745 //}
746 //
747 //int
748 //msdd_source_base::_read_9862 (int which_codec, int regno) const
749 //{
750 //  return d_usrp->_read_9862 (which_codec, regno);
751 //}
752 //
753 //bool
754 //msdd_source_base::_write_spi (int optional_header, int enables,
755 //                             int format, std::string buf)
756 //{
757 //  return d_usrp->_write_spi (optional_header, enables, format, buf);
758 //}
759 //
760 //std::string
761 //msdd_source_base::_read_spi (int optional_header, int enables, int format, int len)
762 //{
763 //  return d_usrp->_read_spi (optional_header, enables, format, len);
764 //}
765 //
766 //bool
767 //msdd_source_base::set_format(unsigned int format)
768 //{
769 //  return d_usrp->set_format(format);
770 //}
771 //
772 //unsigned int
773 //msdd_source_base::format() const
774 //{
775 //  return d_usrp->format();
776 //}
777 //
778 //unsigned int
779 //msdd_source_base::make_format(int width, int shift, bool want_q, bool bypass_halfband)
780 //{
781 //  return usrp_standard_rx::make_format(width, shift, want_q, bypass_halfband);
782 //}
783 //
784 //int
785 //msdd_source_base::format_width(unsigned int format)
786 //{
787 //  return usrp_standard_rx::format_width(format);
788 //}
789 //
790 //int
791 //msdd_source_base::format_shift(unsigned int format)
792 //{
793 //  return usrp_standard_rx::format_shift(format);
794 //}
795 //
796 //bool
797 //msdd_source_base::format_want_q(unsigned int format)
798 //{
799 //  return usrp_standard_rx::format_want_q(format);
800 //}
801 //
802 //bool
803 //msdd_source_base::format_bypass_halfband(unsigned int format)
804 //{
805 //  return usrp_standard_rx::format_bypass_halfband(format);
806 //}
807
808 bool msdd_source_base::set_desired_packet_size (int which, unsigned long packet_size) {
809   bool result(false);
810   
811   if (pimpl->d_desired_sample_size < 2^32) { // FIXME: find maximum sample request for MSDD check if greater than 
812     pimpl->d_desired_sample_size = packet_size;
813   }
814   return result;
815 }
816
817 unsigned long msdd_source_base::desired_packet_size (int which) const {
818   return pimpl->d_desired_sample_size;
819 }