discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] Developing for different A to D's


From: Eric Blossom
Subject: Re: [Discuss-gnuradio] Developing for different A to D's
Date: Thu, 17 Apr 2003 14:47:18 -0700
User-agent: Mutt/1.4i

On Thu, Apr 17, 2003 at 04:20:10PM +1000, Alan Gray wrote:
> 
> 
> Thanks for your help Eric, I've finally got a system up and running 
> to start work on my project (still awaiting the arrival of my SMP 
> machine and tuner though, seems it takes a lot of time to get 
> anything much done around here). I've acquired a second A/D card, 
> the Adlink PCI-9812 
> (http://www.adlinktech.com/products/DataAcquisition/PCI-981210.htm) 
> which seems a little better suited to a GNU radio application, and 
> thus I'm going to try to adapt the code to suit it first, and 
> return to the ICS-645 at a later date.
> 
> I wonder if someone could expand a little on the data flow in the 
> program and the format of data required, a "stream of shorts" was 
> mentioned, but I'm a little shady on how that stream is 
> implemented, stored and processed. The PCI-9812 comes with a rather 
> extensive set of libraries which provide functionality for 
> double-buffering and the like, so I can easily read in values to 
> file, however I'm unsure as to how these can be applied to 
> processing data in real time. Basically I think I'm having trouble 
> understanding what modules like VrSource, VrFileSource and 
> GrMC4020Source are doing, so if someone could explain these a bit 
> or point me towards any resources which could give me a good idea 
> of the functionality it would be most appreciated.
> 
> For some reason I can see a lot of coding in my near future
> Thanks
> Alan

Great questions.

Clearly we need a bit of a tutorial.

If you know how to use their library to read data and write it into a
file, you're most of the way there.

Your code should look something like what's below...

I'm assuming for the time being that you're only going to handle a
single channel.  It's not big deal to handle more, but let's get it
working first.  (With multiple channels, your oType template parameter
would change to reflect that that data is no longer short, but is say,
a struct containing two shorts, or four shorts, or whatever.)

I used VrFileSource as a starting point.  It's got a more conventional
interface to the underlying data than GrMC4020Source.  (FWIW,
GrMC4020Source does a bit of magic to map in the underlying kernel DMA
buffer twice so that it functions as a double buffer.  Let's ignore
that for now.)

// file: GrAdlink9812Source.h

/* -*- Mode: c++ -*- */
/*
 * Copyright 2001,2002,2003 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef _GRADLINK9812SOURCE_H_
#define _GRADLINK9812SOURCE_H_

#include <VrSource.h>
#include <fstream>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <library-stuff-for-adlink9812.h>

template<class oType>
class GrAdlink9812Source : public VrSource<oType> {
protected:
  FILE* fp;     // FIXME or whatever handle their library give you
public:
  virtual const char *name() { return "GrAdlink9812Source"; }
  virtual int work2(VrSampleRange output, void *o[]);

  GrAdlink9812Source (double sampling_freq);
  virtual ~GrAdlink9812Source();
};

template<class oType> int
GrAdlink9812Source<oType>::work2(VrSampleRange output, void *ao[])
{
  // get a easier to use pointer to the output buffer
  oType *o= ((oType **)ao)[0];
  int i;
  int size = output.size;       // total number of oTypes (samples) to read
  int index;

  // FIXME
  //
  // Ultimately your job is to copy output.size * sizeof (oType) bytes
  // into the buffer pointed at by o.
  //
  // This is the loop we use for reading from a file.
  // You may be able to do it all in one fell swoop.
  //

  index = 0;
  while (size) {

    // FIXME.  Get samples from the library

    // Note that &o[index] is the address of the destination buffer
    // that is being provided to you.

    i = fread(&o[index], sizeof(oType), size, fp);
    
    size -= i;
    index += i;

    if (size == 0)              // done
      break;

    if (i > 0)                  // short read, try again
      continue;

    // We got a zero from fread.  This is either EOF or error. 

    break;
  }

  if (size > 0){        // EOF or error 
    cerr << "end of file, exiting\n";
    exit(0);            // FIXME harsh, needs better solution
  }

  return output.size;   // return number of oTypes read.
                        // for all intents and purposes it is an error
                        // to return fewer than what was asked for.
}

template<class oType>
GrAdlink9812Source<oType>::GrAdlink9812Source(double sampling_freq)
{
  // tell the GNU Radio scheduler what sampling rate we're using
  setSamplingFrequency (sampling_freq);

  int fd = -1;  // init returned handle to something


  // FIXME open the device using their library interface
  
#if 0
  if ((fd = open (filename, O_RDONLY | OUR_O_LARGEFILE)) < 0){
    fprintf(stderr, "Could not open %s\n", filename);
    exit(1);
  }

  if((fp = fdopen (fd,"r"))==NULL) {
    fprintf(stderr, "Could not open %s\n", filename);
    exit(1);
  }
#endif

}

template<class oType>
GrAdlink9812Source<oType>::~GrAdlink9812Source()
{
  // FIXME close the device
  fclose(fp);
}

#endif




reply via email to

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