Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

sched.hh

Go to the documentation of this file.
00001 /*
00002  * MAX : sched.hh, Sam Dez 29 20:07:54 CET 2001 -sg
00003  *
00004  * The scheduler class calls all devices according to their priority list.
00005  * It also contains the functions for handling the measured data.
00006  * See the function int Scheduler::store(int )
00007  *
00008  * This file is part of Max data acquisition software
00009  * Copyright (C) 1998 Christian Rosen
00010  *
00011  * Max is free software; you can redistribute it and/or modify it
00012  * under the terms of the version 2 of GNU General Public License as
00013  * published by the Free Software Foundation.
00014  *
00015  * Max is distributed in the hope that it will be useful, but WITHOUT
00016  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00017  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00018  * for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * (see the file COPYING) in this directory; if not, write to the
00022  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023  */
00024 
00025 #ifndef SCHEDULER_H
00026 #define SCHEDULER_H
00027 
00028 #define BACKUP_ARRAY_SIZE MAX_ARRAY_SIZE //size for array to be plotted, rest is truncated
00029                                 //check with MAX_ARRAY_PLOTSIZE in plot.hpp
00030 #include <qwidget.h>
00031 #include <qtimer.h>
00032 #include <qimage.h>
00033 #include <assert.h>
00034 #include <stdarg.h>
00035 #include <string.h>
00036 #include <stdio.h>
00037 
00038 #include "list_polld.h"
00039 #include "error.h"
00040 #include "packet.h"
00041 #include "data.h"
00042 #include "network.h"
00043 #include "priority.h"
00044 
00045 /****************************************************************************/
00046 /* main header part */
00047 /****************************************************************************/
00058 class Scheduler  : public QWidget {
00059 
00060   Q_OBJECT        //this Macro is for the signal/slot mechanism of Qt
00061 
00062 public :
00063   // This is the Constructor. It initializes to normal mode with external trigger(=0)
00064   Scheduler(int = 100, int = 5, int = 1, int = 1);
00065   //This is the decstructor.
00066   ~Scheduler();
00067 
00068   // these two are called by the devices ....
00069   int error ( char *,char *formatstr, ... ); //new error funtion with format string
00082   void init();
00083   void remove();
00084   void remove_continue();
00088   int  init_measurement (List *, Pr_list &);
00092   int  close_measurement(List *, Pr_list &);
00093   //these are the routines that return after one cycle
00095   int  measure(List *, Pr_list &);      //return 0 to force immedeate stop
00099   int  SLOT_measure(List *, Pr_list &); //measurement routine called by timer event
00101   void initialize_SLOT       (void );   //reset parameters for timer controlled mesurement
00102   void set_max_channel_number(int  );   //set max_channels
00105   void set_max_integrations  (int  );   //set the maximal number of inegrations
00106   //Set the current channel number.
00107 
00108   
00109   int  channel_number        (void );   
00110 
00111   int  maximal_integrations  (void );
00113   int  maximal_channels      (void );
00115   int  act_channel           (void );  //returns the actual channel
00117   int  act_integrations      (void );  //return current number of integrations
00118 
00120   int  trigger_mode          (void );
00122   int  monitor_mode          (void );
00123 
00127   void store   ( int      );
00131   void store   ( double   );
00138   void store   ( int *,int);
00140   void store( double *, int);
00141   void store   ( char *   );     //filename for image loading from disk
00142   void external_trigger      (void );  //set trigger external
00143   void internal_trigger      (void );  //set trigger internal
00144   void monitor_mode_on       (void );
00145   void monitor_mode_off      (void );
00146   void set_channel_number    (int  );
00147   void set_triggermode       (int  );   //trigger = 0 -> internal trigger, 1-> external
00148   void reset_integrations    (void );
00149   void reset_queue           (void );  //clear packet buffer list
00150   void reset                 (void );  //initialize for measurement
00151   uint delay                 (void );  //return delay
00152   void SetWaitFlag         (int,int); //wait for users error response
00153   void SetErrAnswer           (int );
00154   void set_cmd_sfd            (int );  //set Socket filedesriptor
00155   void call_device           (int  );  //call function with priority
00156   void max_channelnr         (int  );  //next functions are to access the according variables
00157 
00158   void inc_integrations      (void );   //increment actual integrations by 1
00159   void inc_channel           (void );   //increment actual channel number by one
00160   void reset_channel_number  (void );
00161 
00162   int DeQueue                 (int );  //send all buffer data to the client
00163   int  Number_devices();                     //Number of devices in Dev_Function Vector
00164   signals :
00165   void Sig_Error( char * );
00166   void channel_number_changed(int );
00167   void plot_data_point(uint ,int ); /*Send value of data point to plot window*/
00168   void plot_array(uint,int *);       //send array to plot routine
00169   void send_data(int, uint, int);    //send data to be stacked
00170   void send_data(uint, int, int*);   //send arrays,-> parameters :
00171   void send_data(QImage *,int);      //window_index,channel,size,pointer to array
00172 
00173 public slots:
00174   void stop_measurement(int);
00175   void SLOT_setdelay(uint );
00176  //called when timeout is generated from internal trigger
00177   void SLOT_timeout( );
00178 
00179   //backup structures for integration of data
00180   //
00181   /*variable type 1 = int, 2 = double, 3 = char, 4 = char * ->*/
00182                   /*bad C++ code !!! I know -> It's your job to make it better*/
00183   private :
00184 
00185   struct backup {
00186     int    i_var;
00187     double d_var;
00188     int    type;
00189   };
00190 
00191 struct arraybackup { //used  for integration of arrays
00192     int *iptr;
00193     int  size;
00194   };
00195 
00196 
00197   //List of measured data packets see : data.cpp
00198   //this class also contains functions to convert data to packets
00199   PacketList         *Que;
00200   dataPacket         dat_packet;  //Packet for sending measured data  -> see packet.h
00201   int max_channels;
00202   int max_integrations;
00203   int channels;                 //current channel
00204   int integrations;             //maximum number of integrations per cycle
00205   int priority;                 //actual priority currently called
00206   int stop ;
00207   int s_mode;                   //False if no signals for display are called from scheduler (high speed)
00208   int t_mode;                   //TRUE = external trigger ,FALSE = internal
00209   int device_status;            //return status of devices -> (used by SLOT_measure only)
00210   uint period;                  //delay for internal trigger contains ms
00211   bool busy;                    //busy flag to block parallel measurements
00212   char             *typelist;
00213   int               var_index;  //index off all "stored" variables
00214   int               temp_var_index;
00215   int               element_counter;   //contains the numberof measured data stored by device functions
00216   int               array_counter;     //counter for array-backup array
00217   int               temp_counter;      //temp counter for add_data function
00218   int               array_temp_counter;//temp counter for array add_data function
00219   backup           *buffPtr;
00220   arraybackup      *arrayPtr;    //array of pointers to int for integration of intarrays
00221   int *             backup_array;  //array for plotting-> divison by integrations
00222   //
00223   //end of database variables
00224   //
00225   //measurement control
00226   //
00227   bool            wait;         //Wait Flag for Scheduler->toggled by SLOT_Timeout
00228   int             data_saved;   //=0 if data is not yet saved
00229   int             monitor;      //monitor mode TRUE = on, FALSE = off
00230   int             maxarraysize; //size of largest array currently stored in database
00231   int             status;       //return status of measurement routines
00232   int             close_status; //return status of close routines
00233   int             err_wait;
00234   int             err_answer;
00235   int             cmd_sfd;     //socket fileds for sending error msg
00236 };
00247 #endif
00248 //don't write  behind the endif

Generated at Mon Sep 2 18:21:04 2002 for MAX by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001