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