ACQ2XX_API
Frame.h
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file Frame.h                                                      */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2009 Peter Milne, D-TACQ Solutions Ltd
00005  *                      <Peter dot Milne at D hyphen TACQ dot com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of Version 2 of the GNU General Public License
00009     as published by the Free Software Foundation;
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
00019 /* ------------------------------------------------------------------------- */
00020 
00021 /** @file Frame.h Defines ACQ streaming frame. 
00022  * Refs: see ICD for frame definition
00023 */
00024 
00025 #ifndef __FRAME_H__
00026 #define __FRAME_H__
00027 
00028 #include <assert.h>
00029 
00030 #include "AcqType.h"
00031 #define FRAME_SAMPLES 64
00032 
00033 typedef unsigned short Tag;
00034 
00035 class AcqType;
00036 
00037 class Frame {
00038 protected:
00039         const AcqType& acqType;
00040 
00041         enum STATE {
00042                 EMPTY, FULL, INVALID
00043         } state;
00044         unsigned id;
00045         
00046         Tag tags[FRAME_SAMPLES];
00047         int nchan;
00048         int word_size;
00049 
00050         virtual int fillData(void *raw, int nraw) = 0;
00051 
00052         int appendTag(int isam, unsigned short tag);
00053         long long startSampleNumber;
00054 
00055         void computeStartSampleNumber();
00056         void reset(void) {
00057                 state = EMPTY;
00058         }
00059 public:
00060         Frame(const AcqType& acqType);
00061         virtual ~Frame();
00062 
00063         const Tag getTag(int isam) const {
00064                 return tags[0];
00065         }
00066         virtual unsigned getID(void) const
00067         /**< return ID (frame number). */
00068         {
00069                 return id;
00070         }
00071         enum STATE getState(void) {
00072                 return state;
00073         }
00074 
00075         int sampleSize(void) const {
00076                 return word_size * nchan;
00077         }
00078 
00079         int lineSize(void) const {
00080                 return sampleSize() + sizeof(Tag);
00081         }
00082         int frameSize(void) const {
00083                 return FRAME_SAMPLES * lineSize();
00084         }
00085         
00086         long long getStartSampleNumber(void) const {
00087                 if (state == FULL){
00088                         return startSampleNumber;
00089                 }else{
00090                         return -1;
00091                 }
00092         }
00093         unsigned char getDIO(void) const;
00094         unsigned short getExtra(void) const;
00095 
00096         static int buildFrame(unsigned id, Frame *frame, void *raw, int nraw);
00097 };
00098 
00099 template <class T> class ConcreteFrame : public Frame {
00100 
00101         T* data;
00102 
00103 protected:
00104         virtual int fillData(void *raw, int nraw);
00105 public:
00106         ConcreteFrame<T>(const AcqType& _acqType);
00107 
00108         virtual ~ConcreteFrame<T>() {
00109                 delete [] data;
00110         }
00111 
00112         virtual const T* getChannel(int ch) const;
00113 };
00114 
00115 /* need to include implementation to get it to link.
00116  * Stroustrup says so.
00117  */
00118  
00119 #include "Frame.c"
00120 
00121 #endif // __FRAME_H__