ACQ2XX_API
Frame.c
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file Frame.c                                                      */
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.c Implementation of Frame template functions
00022 */
00023 
00024 
00025 template<class T>
00026 ConcreteFrame<T>::ConcreteFrame(const AcqType& _acqType):
00027         Frame(_acqType)
00028 {
00029         assert(sizeof(T) == acqType.getWordSize());
00030         data = new T[acqType.getNumChannels() * FRAME_SAMPLES];
00031 }
00032 
00033 
00034 template<class T>
00035 const T* ConcreteFrame<T>::getChannel(int ch) const
00036 /** @@TODO : lookup logical channel */
00037 {
00038         return &data[acqType.getChannelOffset(ch) * FRAME_SAMPLES];
00039 }
00040 
00041 
00042 
00043 
00044 template<class T>
00045 int ConcreteFrame<T>::fillData(void *raw, int nraw)
00046 /**< fillData() - fill frame with incoming data
00047  * @@TODO: rejects on invalid tag. Should really try to resync. */
00048 {
00049         int isam = 0;
00050         unsigned short *praw = (unsigned short*)raw;
00051 
00052         for (isam = 0; isam < FRAME_SAMPLES; ++isam){
00053                 int rc = appendTag(isam, *praw);
00054                 if (rc != 0){
00055                         return rc;
00056                 }
00057 
00058                 /* this is likely to be a misaligned 32 bit access 
00059                  * could be horribly inefficient - may need optimising */
00060 
00061                 T* pdata = (T*)(praw+1);
00062                 for (int ichan = 0; ichan < nchan; ++ichan){
00063                         data[ichan*FRAME_SAMPLES+isam] = pdata[ichan];
00064                 }
00065                 praw += lineSize()/sizeof(unsigned short);
00066         }       
00067 
00068         
00069         // temp: let's check what's happening!
00070         //write(1, tags, sizeof(tags));
00071         return 0;
00072 }