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