1 /* 2 * @(#)$Id: oscope.h,v 2.7 2009/01/15 07:05:59 baccala Exp $ 3 * 4 * Copyright (C) 1996 - 2001 Tim Witham <twitham@quiknet.com> 5 * 6 * (see the files README and COPYING for more details) 7 * 8 * This file defines the program's global variables and structures 9 * 10 */ 11 12 #include <gtk/gtk.h> /* need GdkPoint below */ 13 #include <gtkdatabox_graph.h> 14 15 #include "config.h" 16 17 /* global program variables */ 18 extern char *progname; 19 extern char version[]; 20 extern char error[256]; 21 extern int quit_key_pressed; 22 extern int clip; 23 extern char *filename; 24 extern int in_progress; 25 26 typedef struct Scope { /* The oscilloscope */ 27 int mode; 28 int run; 29 int scale; 30 int div; 31 int grat; 32 int behind; 33 int select; 34 int trigch; 35 int trige; 36 int verbose; 37 int trig; 38 int curs; 39 int cursa; 40 int cursb; 41 int min_interval; 42 } Scope; 43 extern Scope scope; 44 45 /* Signal - the input/memory/math signals 46 * 47 * sc_linux.c depends on the order of these fields in a static initializer 48 */ 49 50 typedef struct Signal { 51 char name[16]; /* Textual name of this signal (for display) */ 52 char savestr[256]; /* String used in save files */ 53 int rate; /* sampling rate in samples/sec */ 54 int volts; /* millivolts per 320 sample values */ 55 int frame; /* Current frame number, for comparisons */ 56 int num; /* number of samples read from current frame */ 57 int delay; /* Delay, in ten-thousandths of samples */ 58 int listeners; /* Number of things 'listening' to this Sig */ 59 int bits; /* number of valid bits - 0 for analog sig */ 60 int width; /* size of data[] in samples */ 61 short *data; /* the data samples */ 62 } Signal; 63 64 extern Signal mem[26]; /* Memory channels */ 65 66 typedef struct DataSrc { /* A source of data samples */ 67 68 char * name; 69 70 /* returns number of data channels available. Return value can 71 * change around pretty much at will. Zero indicates device unavailable 72 */ 73 int (* nchans)(void); 74 75 /* returns a pointer to the Signal structure for a numbered channel */ 76 Signal * (* chan)(int chan); 77 78 /* mode is 1 (rising trigger) or 2 (falling trigger) returns TRUE if 79 * trigger could be set; otherwise (it couldn't be set) return FALSE 80 * and leave trigger cleared 'level' is a pointer to the trigger 81 * level in signed raw sample values If a trigger can be set near, 82 * but not exactly on, the requested level, the function returns 83 * TRUE, sets the trigger, and modifies 'level' to the adjusted 84 * value. */ 85 int (* set_trigger)(int chan, int *levelp, int mode); 86 void (* clear_trigger)(void); 87 88 /* dir is 1 for faster; -1 for slower; returns TRUE if rate changed */ 89 int (* change_rate)(int dir); 90 91 /* sets the frame width (number of samples to capture per sweep) for 92 * all channels in the DataSrc. Success is indicated by the 'width' 93 * field changing in the DataSrc's Signal structures. Can be NULL 94 * to indicate device does not support multiple frame widths. 95 */ 96 void (* set_width)(int width); 97 98 /* reset() gets called whenever we want to start a new capture sweep. 99 * It should get called after any of the above channel, trigger, or rate 100 * functions have been used to change the data source capturing 101 * parameters, or after the capturing channels have been changed. 102 * Only after reset() has been called are the rate and volts 103 * fields in the Signal structures guaranteed valid. 104 */ 105 void (* reset)(void); 106 107 /* returns a file descriptor to poll on (for read) to indicate that 108 * the data source has data available for read, via get_data() below. 109 * return -1 to indicate no active signal capturing. Always gets 110 * called after a reset() 111 */ 112 int (* fd)(void); 113 114 /* get_data() is called when poll(2) on the file descriptor returned 115 * by fd() indicates data is available to read. It is responsible 116 * for filling in the Signal arrays returned by the chan() function, 117 * and returns TRUE if the trigger condition was hit (currently used 118 * only in single-shot mode to stop the scope after a single trace). 119 * It also must set the global variable 'in_progress' TRUE if it 120 * returns in the middle of a trace, and FALSE at the end of a 121 * trace. get_data() must always return at the end of every trace, 122 * as the display code assumes that a trace is completely drawn 123 * before moving on the next trace. 124 */ 125 int (* get_data)(void); 126 127 /* This function allows the data source to display various status 128 * information on the screen. i ranges from 0 to 7, and corresponds 129 * to 8 information fields near the bottom of the display. Fields 130 * 0 through 3 have room for about 16 chars, fields 4 and 5 have 131 * room for about 20, and fields 6 and 7 can hold about 12. 132 * Function pointer can be NULL if there's no status info to display. 133 */ 134 135 char * (* status_str)(int i); 136 137 /* These functions are called when the option1 (*) or option2 (^) 138 * keys are pressed and should return 1 to do a datasrc->reset. 139 * Their corresponding string functions should return a short string 140 * to be displayed on the screen, which can be NULL. If the 141 * option function returns TRUE, a clear() is done. Any of these 142 * pointers can be NULL. If the 'str' function is NULL, no help 143 * will be displayed for that option key, but this doesn't preclude 144 * the corresponding option function from doing something! 145 */ 146 147 int (* option1)(void); 148 char * (* option1str)(void); 149 int (* option2)(void); 150 char * (* option2str)(void); 151 152 /* set_option()/save_option() 153 * 154 * These functions are used to set and save data source specific 155 * options, either from the command line or from a savefile, 156 * including but not limited to the keyboard options corresponding 157 * to option1/option2. To generate the savefile, save_option() will 158 * be called repeatedly with arguments starting at zero and 159 * increasing until it returns NULL. Each string returned will 160 * later trigger a call to set_option() when the savefile is 161 * loaded. Returning an empty string will skip to the next 162 * integer without outputing anything. 163 * 164 * set_option() should return TRUE if it was able to parse and 165 * process the option; FALSE otherwise. The options can also be 166 * specified on the command line, so should be human readable. 167 * 168 * Both function pointers can be NULL. 169 */ 170 171 int (* set_option)(char *); 172 char * (* save_option)(int); 173 174 /* This function is only used if the X Windows GTK interface is 175 * in use. If non-NULL, it causes the "Device Options..." item 176 * on the File menu to be made sensitive, and the function itself 177 * is called whenever that item is clicked. It should trigger 178 * a popup menu with device-specific options. 179 */ 180 void (* gtk_options)(void); 181 182 } DataSrc; 183 184 extern DataSrc *datasrc; 185 extern DataSrc *datasrcs[]; 186 extern int ndatasrcs; 187 188 typedef GdkPoint Point; 189 190 typedef struct SignalLine { 191 int next_point; 192 struct SignalLine *next; /* keep a linked list */ 193 GtkDataboxGraph *graph; 194 gfloat *X; 195 gfloat *Y; 196 } SignalLine; 197 198 typedef struct Channel { /* The display channels */ 199 Signal *signal; 200 SignalLine *signalline[16]; /* 16 - could have up to 16 bits per sample, 201 * thus, up to 16 signal lines per channel 202 * in digital mode */ 203 int old_frame; /* last frame number plotted */ 204 int mult; /* A scaling ratio we multiply samples by */ 205 int div; 206 int target_mult; /* The target scaling ratio */ 207 int target_div; 208 gfloat pos; /* Location of zero line on scope display; 209 * 0 is center; 1 is top; -1 is bottom */ 210 int color; 211 int show; 212 int bits; 213 } Channel; 214 extern Channel ch[CHANNELS]; 215 216 /* functions that are called by files other than oscope.c */ 217 void usage(); 218 void handle_key(unsigned char); 219 void cleanup(); 220 void init_scope(); 221 void init_channels(); 222 int samples(); 223 void loadfile(); 224 void savefile(); 225 void startcommand(); 226 char * split_field(char *, int, int); 227 228 int datasrc_byname(char *); 229 230 extern char serial_error[]; 231 232 /* Functions defined in display library specific files */ 233 void setinputfd(int); 234 void settimeout(int); 235