00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
#ifndef _VRGUPPISOURCE_H_
00038
#define _VRGUPPISOURCE_H_
00039
00040
extern "C" {
00041
#include <sys/ioctl.h>
00042
#include <fcntl.h>
00043
#include <errno.h>
00044 }
00045
00046
#include <VrSource.h>
00047
#include <VrGuppiBuffer.h>
00048
#include <guppi.h>
00049
00050
template<
class oType>
00051 class VrGuppiSource:
public VrSource<oType> {
00052
protected:
00053 int gupfd;
00054
00055
00056 int currentIndex;
00057 int minIndex;
00058
00059 int extrablocks;
00060
00061
public:
00062 virtual const char *
name() {
return "VrGuppiSource"; }
00063 virtual float memoryTouched() {
00064
return 0;
00065 }
00066
virtual int work2(
VrSampleRange output,
void *o[]);
00067
virtual void initOutputBuffer(
int n);
00068
VrGuppiSource(
double sampling_freq);
00069 };
00070
00071
template<
class oType>
int
00072 VrGuppiSource<oType>::work2(
VrSampleRange output,
void *ao[])
00073 {
00074
struct guppi_status status;
00075
int num;
00076
int blocksleft;
00077
00078
sync(output.
index);
00079
00080 blocksleft = output.
size/
getOutputSize();
00081 num=
currentIndex -
minIndex;
00082 status.
index=minIndex;
00083 blocksleft-=
extrablocks;
00084
00085
while (blocksleft>0) {
00086
00087
00088
00089 status.
num=num-(output.
index+output.
size-
proc_minRP()+
PAGE_SIZE-1)/
PAGE_SIZE*
sizeof(
oType)+blocksleft;
00090
00091
if (PARANOID && status.
num < 0) {
00092 fprintf(stderr,
"Guppi index inconsistency.\n");
00093 abort ();
00094 }
00095
00096
00097
if((
int)status.
num>num) status.
num=num-1;
00098
00099 num-=status.
num;
00100
00101
00102
if((ioctl(
gupfd,
GIOCSETGETSTATUS, &status)) < 0) {
00103 perror(
"Failed to get guppi status");
00104 exit(-1);
00105 }
00106
00107
00108 blocksleft-=status.
num-num;
00109 num=status.
num;
00110
00111
00112
if(status.
lost) {
00113 fprintf(stderr,
"Lost %i pages\n",status.
lost);
00114 }
00115
00116
if(blocksleft>0)
00117
YIELD();
00118 }
00119 minIndex=status.
index;
00120
currentIndex=status.
index+num;
00121 extrablocks=-blocksleft;
00122
return output.
size;
00123 }
00124
00125
template<
class oType>
void
00126 VrGuppiSource<oType>::initOutputBuffer(
int n)
00127 {
00128
if(n!=0) {
00129 fprintf(stderr,
"GuppiSource can only have one output buffer.\n");
00130 exit(-1);
00131 }
00132 outBuffer[0]=
new VrGuppiBuffer<oType>(
this,
gupfd);
00133 }
00134
00135
template<
class oType>
00136 VrGuppiSource<oType>::VrGuppiSource(
double sampling_freq)
00137 :gupfd(-1), currentIndex(0), minIndex(0), extrablocks(0)
00138 {
00139
if ((
gupfd = open(
"/dev/guppi0", (O_RDONLY | O_NONBLOCK))) < 0) {
00140 printf(
"Can't open GuPPI\n");
00141 exit(1);
00142 }
00143
setSamplingFrequency (sampling_freq);
00144
00145
00146
00147
setOutputSize (
PAGE_SIZE/
sizeof(
oType));
00148 }
00149
00150
#endif