comedi_hwi_dev.C

Go to the documentation of this file.
00001 /* Gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
00006  *
00007  * Authors: Percy Zahl <zahl@users.sf.net>
00008  * additional features: Andreas Klust <klust@users.sf.net>
00009  * WWW Home: http://gxsm.sf.net
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00024  */
00025 
00026 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00027 
00028 /* irnore this module for docuscan
00029 % PlugInModuleIgnore
00030  */
00031 
00032 
00033 #include <locale.h>
00034 #include <libintl.h>
00035 
00036 
00037 #include <fcntl.h>
00038 #include <sys/ioctl.h>
00039 
00040 #include "glbvars.h"
00041 #include "comedi_hwi.h"
00042 
00043 // you may want to handle/emulate some DSP commands later...
00044 #include "dsp-pci32/xsm/dpramdef.h"
00045 #include "dsp-pci32/xsm/xsmcmd.h"
00046 
00047 // enable debug:
00048 #define COMEDI_DEBUG(S) XSM_DEBUG (DBG_L4, "comedi_hwi_dev: " << S )
00049 
00050 /* Construktor for Gxsm comedi support base class
00051  * ==================================================
00052  * - open device
00053  * - init things
00054  * - ...
00055  */
00056 comedi_hwi_dev::comedi_hwi_dev(){
00057         COMEDI_DEBUG("open driver");
00058         max_points_per_line = 400000; // what ever you are willing to handle...
00059         // here you may want to open you comedi device(s) 
00060         // and do some basic initialisations if needed
00061 
00062 // e.g. open like this, the device name in the Gxsm prefs is "xsmres.DSPDev"
00063 //      comedi_drv = open(xsmres.DSPDev, O_RDWR);
00064 }
00065 
00066 /* Destructor
00067  * close device
00068  */
00069 comedi_hwi_dev::~comedi_hwi_dev(){
00070         COMEDI_DEBUG("close driver");
00071 //      close (comedi_drv);
00072 }
00073 
00074 void comedi_hwi_dev::ExecCmd(int Cmd){
00075         // Exec "DSP" command (additional stuff)
00076 
00077         // Put CMD to DSP for execution.
00078         // Wait until done and
00079         // call whenever you are waiting longer for sth.:
00080         // gapp->check_events(); // inbetween!
00081 }
00082 
00083 int comedi_hwi_dev::WaitExec(int data){
00084         return 0; // not needed today, always returns 0 
00085 }
00086 
00087 // you may want this later for mover and other tasks...
00088 void comedi_hwi_dev::SetParameter(PARAMETER_SET &hps, int scanflg){
00089 }
00090 
00091 void comedi_hwi_dev::GetParameter(PARAMETER_SET &hps){
00092 }
00093 
00094 size_t comedi_hwi_dev::ReadData(void *buf, size_t count) { 
00095         // move data into buf
00096         // e.g.: return read(dsp_data, buf, count); 
00097         return count; // return num of data read form source successfully
00098 }
00099 
00100 int comedi_hwi_dev::ReadScanData(int y_index, int num_srcs, Mem2d *m[MAX_SRCS_CHANNELS]){
00101         static time_t t0 = 0; // only for demo
00102         int len = m[0]->GetNx();
00103         SHT *linebuffer = new SHT[len*num_srcs];
00104 
00105 // create dummy data (need to read some stuff from driver/tmp buffer...)
00106 // should use ReadData (see above) later!
00107 // and should not block...
00108 
00109         COMEDI_DEBUG("ReadData:" << y_index);
00110 
00111         if (t0 == 0) t0 = time (NULL);
00112         int drift = (int) (time (NULL) - t0);
00113         if (y_index < 0) // 2D HS Area Capture/Scan
00114                 for (int k=0; k<m[0]->GetNy (); ++k)
00115                         for (int i=0; i<num_srcs; ++i){
00116                                 for (int j=0; j<len; ++j){
00117                                         double x = rx*Dx + j*Dx + drift*5;
00118                                         double y = ry*Dy + k*Dx;
00119                                         Transform(&x, &y);
00120                                         linebuffer[i*len + j] = (SHT)(1000.*sin(x/100.*2*M_PI)
00121                                                                       *cos(k/100.*2*M_PI));
00122                                 }
00123                                 if (m[i])
00124                                         m[i]->PutDataLine (k, linebuffer+i*len);
00125                         }
00126         else
00127                 for (int i=0; i<num_srcs; ++i){
00128                         for (int j=0; j<len; ++j){
00129                                 double x = rx*Dx + j*Dx + drift;
00130                                 double y = ry*Dy;
00131                                 Transform(&x, &y);
00132                                 linebuffer[i*len + j] = (SHT)(1000.*sin(x/100.*2*M_PI)
00133                                                               *cos(y_index/100.*2*M_PI));
00134                         }
00135                         if (m[i])
00136                                 m[i]->PutDataLine (y_index, linebuffer+i*len);
00137                 }
00138 
00139 // move data into mem2d objects -- it's done above already...
00140 //      for (int i=0; i<num_srcs; ++i)
00141 //              if (m[i])
00142 //                      m[i]->PutDataLine (y_index, linebuffer+i*len);
00143         
00144         delete[] linebuffer;
00145         return 0;
00146 }
00147 
00148 int comedi_hwi_dev::ReadProbeData(int nsrcs, int nprobe, int kx, int ky, Mem2d *m, double scale){
00149         // later
00150         return 1;
00151 }
00152 
00153 
00154 /*
00155  * provide some info about the connected hardware/driver/etc.
00156  */
00157 gchar* comedi_hwi_dev::get_info(){
00158         return g_strdup("*--Gxsm Comedi HwI base class--*\n"
00159                         "Comedi device: do not know\n"
00160                         "*--Features--*\n"
00161                         "SCAN: Yes\n"
00162                         "PROBE: No\n"
00163                         "ACPROBE: No\n"
00164                         "*--EOF--*\n"
00165                 ); 
00166 }

Generated on Sat Apr 1 09:04:15 2006 for GXSM by  doxygen 1.4.6