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

max.h

Go to the documentation of this file.
00001 /*
00002  * MAX : max.h, Sam Dez 29 19:18:22 CET 2001 -sg
00003  * 
00004  * This file is part of Max data acquisition software
00005  * Copyright (C) 1997,98 Christian Rosen
00006  * 
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or (at
00010  * your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * (see the file COPYING) in this directory; if not, write to the
00019  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020  */
00021 
00022 #ifndef _MAX_H_
00023 #define _MAX_H_
00024 
00025 #include <vector.h>
00026 
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <errno.h>
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include <sys/types.h>
00033 #include <sys/socket.h>
00034 
00035 #include "definitions.h"
00036 #include "network.h"
00037 #include "packet.h"
00038 #include "qtincludes.h"
00039 #include "list_client.h"
00040 #include "plot.h"
00041 #include "priority.h"   //priority list
00042 #include "utils.h"
00043 #include "database.h"   //the main database for measured data
00044 #include "error.hh"
00045 
00046 // this class is used in a list to buffer the measured data
00047 // before it is plotted
00048 class PlotBuffer  {
00049 public :
00050         PlotBuffer(int    value=0, int channel=0, int index=0, int priority=0);
00051         PlotBuffer(double value=0, int channel=0, int index=0, int priority=0);
00052         PlotBuffer(int *a=0,int len=0, int channel=0, int index=0, int priority=0);
00053         PlotBuffer(double *a=0, int len=0, int channel=0, int index=0, int priority=0);
00054         //buffers plotdata
00055         PlotBuffer(vector<int> *vptr=NULL, int len=0, int channel=0, int index = 0, int priority = 0); 
00056         //buffers plotdata
00057          PlotBuffer(vector<double> *vptr=NULL,int len=0,int channel=0,int index = 0, int priority = 0);
00058         ~PlotBuffer() {
00059                 if (i_array) delete i_array;
00060                 if (d_array) delete d_array;
00061         }
00062         int    ival()  const    { return i_val;  }
00063         double dval()  const    { return d_val;  }
00064         int *  iarr()  const    { return i_array;}
00065         double*darr()  const    { return d_array;}
00066         vector<int>    *ivec() const { return iVecPtr; }
00067         vector<double> *dvec() const { return dVecPtr; }
00068         int    ind()   const    { return indx;   }
00069         int    prior() const    { return prio;   }
00070         int    chann() const    { return chan;   }
00071         int    len()   const    { return length; }
00072         void   setindex(int x)  { indx = x;}
00073         int    var_type() const { return type; }
00074 private :
00075         int     i_val;
00076         double  d_val;
00077         int    *i_array;
00078         double *d_array;
00079         int     length;
00080         int     type;
00081         int     chan;
00082         int     prio;
00083         int     indx;
00084         int     x;
00085         vector<int>    *iVecPtr;    //Pointers to Vectors in database
00086         vector<double> *dVecPtr;
00087 };
00088 
00089 class MainGUI : public QMainWindow {
00090         Q_OBJECT;
00091 public:
00092         MainGUI(char *hostname,char *filename);
00093         ~MainGUI();
00094         int  readMainInitfile(char *);
00095  protected:
00096         void signalhandler( int );
00097         int devDataConnect  ( char *, int ); //establish devData sockets
00098         int cmdSocketConnect( char *, int ); //establish command socket
00099         int datSocketConnect( char *, int ); //establish data socket connection
00100         int connectSockets(char *);  //Connect all sockets to char * hostname
00101         void sendDeviceData(unsigned char *,unsigned char *,
00102                       unsigned char *,unsigned char ,unsigned char);
00103         int  sendDeviceData(devDataPacket *);
00104         void sendAllDeviceData(void );
00105         void sendAllPriorities(void);   //send priority database to polld
00106         //send command line + additional info to the polld
00107         int  sendCommand   (char ,char *,int);
00108 signals:
00109         void stop (int  );
00110         void timeout( );
00111         void timeout2( );
00112         void timeout3(); //timeout to update channel number widget
00113 protected slots :
00114         //virtual void dataReceived(int );
00115         // virtual void timerEvent(QTimerEvent *e);
00116         void commandReceived();
00117         void dataReceived();
00118         void parameterReceived();
00119  public slots :
00120         void open ();
00121         void save ();
00122         void do_save(const char *,const char *,
00123                const char *,int ,char * ,
00124                const char *,const char *);
00125         void about();
00126         void print();
00127         void help ();
00128         void bye  ();
00129         void browsePrio();
00130         void browseDev();
00131         void browseMain();
00132         void reinit();
00133         int  reinitAll();
00134         void reinit_priority();
00135         void reinit_devices();
00136         void startclicked();
00137         void stopclicked();
00138         void contclicked();
00139         void resetclicked();
00140         void pauseclicked();
00141         void toggle_trigger_mode();
00142         void toggle_monitor_mode();
00143         void listbox_update();
00144         void priority_update();
00145         void set_plotwindow_update_intervall();
00146         void set_trigger_internal();
00147         void set_trigger_external();
00148         void set_trigger_delay();
00149         void toggle_save_widget_enable();
00150         void toggle_save_widget_disable();
00151         void apply_trigger_delay(uint ); //send new delay to polld
00152         void apply_update_intervall(uint, uint );
00153         void apply_options(int,int);      //called from options widgets
00154         void select_plotvars();
00155         void set_maxnum();
00156         void set_integrations();
00157         void set_new_parameter();  //these two slots deal with dev_parameter editor
00158         void edit_parameter(int ); //called when user double clicks a device lbItem
00159         void edit_priority(QListViewItem *);   //same for priorites listbox (the right one)
00160         void prio_lv_PopUp( QListViewItem *,const QPoint &, int);
00161         void set_priority();
00162         void Prio_Enabled();
00163         void Prio_Disabled();
00164         void edit_pfile();        //signals for edit of initfile filenames
00165         void edit_dfile();        //devices
00166         void edit_ifile();        //main initfile
00167         //
00168         //timer events....
00169         void ButtonTimerEvent();  //timer to make pause button blink
00170         void RefreshNumber();     //channelnumber widget updated periodically
00171         void UpdatePlotWindows(); //empty Plotbuffer and send to p_window
00172         void SetWindowParameters(Plot *,PlotProps *);
00173         void appendData(dataPacket);
00174 private:
00175         /* max' own classes used for data&parameter handling and some widgets... */
00176         void SortPlotProperties();   //bring list in right order after priorites have changed
00177 
00178         Database     *Schedule;
00179         SaveWidget   *SaveW;
00180         UpdateWidget *W;
00181         DelayWidget  *DelayW;
00182         Cl_List      *Devices;       //data base of device data
00183         Pr_list Priority;            //data base for device priorites
00184         
00185         //network stuff
00186         QWidget*        Main_Widget;
00187         QSocketNotifier *RDataNotifier; //Not. to receive device data from polld
00188         QSocketNotifier *RCmdNotifier;  //Notifier to receive commands from polld
00189         QSocketNotifier *DataNotifier;  //Notifer about measured data socket
00190         int             data_sfd;      //socket-filedescriptor for parameter socket
00191         int             mdat_sfd;       //sfd for measured data
00192         int              cmd_sfd;       // "         "   for Receivecommand sockets
00193         int              cmdr_sfd;      //command receive socket filedescriptor
00194         int              devr_sfd;      //socket     "      for Receiving DevData
00195         int              devs_sfd;      //sockfd to send par data
00196         int              timerID;
00197         int              port;          //port for sockets
00198         int              flag;          //used in ioctl comd
00199         int              pid;           //process ID of child
00200         char*           hostname;      //host to connect to
00201         struct hostent   *host, *hostBackup;
00202         struct hostent   *hp;
00203         struct sockaddr_in server,server_buffer; //pold is server
00204         struct sockaddr_in client;              //max is client
00205         struct sockaddr_in client_polld;         //polld is client sends devdata to max
00206         struct sockaddr_in server_max;           //max is server, seceives devData from polld
00207         struct sockaddr_in cmdClient_max;        //client/server address for the two
00208         struct sockaddr_in cmdClient_polld;      //command exchange sockets
00209         struct sockaddr_in cmdServer_max;
00210         struct sockaddr_in cmdServer_polld;
00211         struct sockaddr_in dataClient;           //max is client to receive data
00212         struct sockaddr_in dataServer;           //address for polld
00213         struct sockaddr_in server_polld;
00214         unsigned int     server_len;
00215         int              dataClient_len;
00216         devDataPacket    d_packet;  //Packet for sending dev_parameters
00217         command_packet   c_packet;  //Packet for sending commands and measurement infos
00218         dataPacket       packet;    //Packet containing measured data
00219         int              n;
00220         int              cmdClient_max_len;
00221         int              cmdvalue; //value of received command
00222 
00223         //file-parameters for max
00224         char       *pr_filename;    //  [80];  //filename of priority list initfile
00225         char       *init_filename;  //  [80];  //filename of device_data initfile
00226         char       *max_init_filename;//[70];  //filename of general initfile
00227         char       save_fname       [100]; //filename of measured data saved to disk
00228         char       array_fname      [100]; //filename of measured int array file
00229         char       image_fname      [100];
00230         char       data_dir         [100]; //path of directory to store data in
00231         char       *l_fname;
00232         char       *l_afname;
00233         char       *l_ifname ;
00234         char       *f_name;
00235         
00236         //QT-Widgets
00237         bool        eventFilter(QObject *,QEvent *);
00238         QMenuBar    *menu;
00239         QToolBar    *fileTools;
00240         QLabel      *label;
00241         QLabel      *channel;
00242         QLabel      *label_max_channels;
00243         QLabel      *integrations;
00244         QLabel      *label_integrations;
00245         QLabel      *label_measurement;
00246         QLabel      *prio_label;
00247         QLabel      *dev_label;
00248         QLabel      *init_label;
00249         QLCDNumber  *chan_no;
00250         QPopupMenu  *options;
00251         QPopupMenu  *priority_trigger;
00252         QFrame      *top_separator;
00253         QFrame      *bottom_separator;
00254         QPushButton *button_triggermode;
00255         QPushButton *button_monitormode;
00256         QPushButton *button_speed;
00257         QPushButton *pbcont;
00258         QPushButton *pbstart;
00259         QPushButton *pbstop;
00260         QPushButton *pbreset;
00261         QPushButton *pbpause;
00262         QProgressBar *progress;
00263         QProgressBar *int_progress;
00264         QLabel      *progressTitle;
00265         QCheckBox   *cbutton_update;
00266         QLabel      *chn_no;
00267         QLabel      *chn_label;
00268         QListBox    *device_lb;
00269         QListBox    *prio_lb;
00270         QListView   *prio_lv;        //ListView for Priority listbox
00271         QLineEdit   *dev_editor;
00272         QLineEdit   *integ_editor;
00273         QLineEdit   *channel_editor;
00274         QLineEdit   *prio_editor;
00275         QLineEdit   *prio_fname;
00276         QLineEdit   *dev_fname;
00277         QLineEdit   *in_fname;
00278         QCursor     *mouse;
00279         QTimer       *blink_timer;   //pause button blinking
00280         QTimer       *number_timer;  //timer for update of channel number
00281         QTimer       *update_timer;   //timer to empty plot_data queue
00282         QColor       col;            //color object for stopbutton
00283         QColor       col_off,col_on; //blink colors for pause button
00284         QColor       editcol;        //color for activated line edit boxes
00285         QColorGroup  colgrp;
00286         QColorGroup  colgrp_off,colgrp_on;
00287         QColorGroup  grp_active,grp_passive;
00288 
00289         // All the rest ...
00290         bool         dev_lb_update; //flag for update of devpar listbox
00291         bool         save_flag;   //is data saved
00292         bool         device_lb_flag;
00293         int          *lbtodata;  //array maps dev listbox index to database index
00294         int          *lbtoplotprops; //array to map listboxpostion to PlotProperties Listposition
00295         int          m_running;     //TRUE if measurement is runnning
00296         int          trigger_period;//period of internal trigger
00297         int          monitor_mode;  //TRUE = dataq mode, FALSE = mon_mode
00298         int          trigger_mode;  //TRUE = external, FALSE = internal
00299         int          update_intervall; //timer intervalls to update widgets
00300         int          plot_update;
00301         int          data_send_intervall; //timer value of Polld' sendData timer
00302         int          color_state;
00303         int          pause_flag;
00304         int          stop_flag;
00305         int          continue_flag; //to enable continue button
00306         int          max_channels;
00307         int          max_integrations;
00308         QDate        date;
00309         QTime        time;                  //actual time of measurement
00310         QString      namestr;
00311         Plot         *Plotwin;
00312         QList<Plot>  *WindowList;      //this list contains the pointers to plotwins
00313         QList<PlotBuffer> *P_Buf;        //queue to buffer plotdata
00314         vector<int>  WindowPtr;         //this vector helps to identify each variable with it's plotwindow
00315         //vector[var_index] = index of element in WindowList.
00316         //this is the Plotwindow for variable with index var_index
00317         //one plot window for each variable
00318         //
00319         //variables for handling of measured data and it's storage
00320         //
00321         VarType     *VarListPtr;      //order to save data in
00322         ArrayType   *ArrayListPtr;    //order to save arrays in
00323         int         *iarraybuffer;    //buffer to stack packets together
00324         double      *darraybuffer;
00325         int          bufpos;  //# of elements in the arraybuffer
00326         int         *buf;             //buffer to copy data from packets into
00327         double      *dbuf;
00328         int          varcounter;      //number of vars per channel
00329         int          arraycounter;    //number of arrays per channels
00330         int          dev_index;       //index of dataset to modifiy plot flag in
00331         int          plot_index;      //same index in PlotProperties list
00332         int          windowcounter;
00333         bool         m_enable;       //enable measurement
00334         bool         save_detect_enable; //enable automatic popup of save-widget
00335 };
00336 
00337 #endif

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