Mapper
database.h
Go to the documentation of this file.
1 /****************************************************************************\
2 * database.h - definitions and prototypes for the hydromet database, 1994 *
3 \****************************************************************************/
4 
5 #ifndef _databaseh
6 #define _databaseh
7 
8 #include <sys/types.h>
9 
10 /****************************************************************************\
11 * The EOL stands for End Of Line. It defines the end of line for a text file *
12 * (such as ALARM.LOG, ERROR.LOG, and DIAL.LOG). In 2.15 QNX EOF's are *
13 * indicated by the Record Separator (0x1E). In POSIX QNX,EOF's are indicated *
14 * with the Line Feed (0x0A). *
15 \****************************************************************************/
16 #define EOL 0x0A
17 #define QNX2_EOL 0x1E
18 
19 /****************************************************************************\
20 * This structure is the message that gets passed from one program to another *
21 * when data comes into the system. You can have several programs that are *
22 * all recieving data at the same time. A data recieving program (recdata, *
23 * autointr, datacol, shef_post, etc...) uses this structure to pass the data *
24 * to the databuffer program. The databuffer is a queue that stores incoming *
25 * data until the data filing program, filer, is able to put the data in the *
26 * database. Databuffer uses this message structure to pass data to filer. *
27 * Filer also uses this structure to pass data to any program that want to be *
28 * updated everytime data comes in. *
29 * *
30 * data data data data *
31 * | | | | *
32 * recdata datacol shef_post autointr *
33 * | | | | *
34 * ----------------------------------------------- *
35 * | *
36 * databuffer *
37 * | *
38 * filer *
39 * | *
40 * --------------------------------- *
41 * | | | *
42 * update dbmngr alertalarm *
43 * *
44 \****************************************************************************/
45 #define HB5_ID_LEN 17
46 #define PC_LEN 11
47 #define NAME_LEN 51
48 
49 struct msgbuf {
50  unsigned char action;
51  unsigned long int sta_id;
52  unsigned char hb5_id[HB5_ID_LEN];
53  unsigned char pc[PC_LEN];
54  float report;
55  time_t clock;
56  unsigned char dqr;
57  unsigned char qds;
58  unsigned char qpi;
59  signed short int node;
60  signed short int tty_num;
61  unsigned char gage_type;
62 };
63 
64 /* Message passing actions */
65 #define MSG_OUT 0x01
66 #define DATA_IN 0x02
67 #define READ_SINDX 0x03
68 #define UPDATE 0x04
69 #define SHOWREPORTS 0x05
70 #define VERIFY 0x06
71 #define ALARMS 0x07
72 #define STATS_OUT 0x08
73 #define STATS_CLEAR 0x09
74 
75 /* Gage type */
76 #define UNKNOWN 0x00
77 #define ASCII 0x01 /* ALERT ASCII format */
78 #define BINARY 0x02 /* ALERT binary format */
79 #define ENHANCED 0x03 /* ALERT enhanced format */
80 #define DARDC 0x04 /* NWS DARDC formatted gage */
81 #define LARC 0x05 /* Handar 550A in smart mode */
82 #define HANDAR_560A 0x06 /* Handar 560A in smart mode */
83 #define SYNERGETICS 0x07
84 #define TELMK 0x08
85 #define BDT 0x09
86 #define SSBDT 0x0A
87 #define COMPULOGGER 0x0B
88 #define CLIMATRONICS 0x0C
89 #define CAMBELL_21 0x0D
90 #define CAMBELL_10 0x0E
91 #define ASOS 0x0F
92 #define FTS11 0x10
93 #define STEVENS 0x11
94 #define SUTRON 0x12
95 #define TALKAMARK 0x13
96 
97 struct update {
98  unsigned char name[9];
99  unsigned int tid;
100 };
101 
102 /****************************************************************************\
103 * The sensor id number is the primary key. The sensor id number is *
104 * guaranteed to be a unique value. *
105 * The sensor id number is an unsigned long int. A valid sensor id number may*
106 * take on a value from 0 through 4,294,967,294. The value 4,294,967,295 is *
107 * reserved for marking a record as empty, i.e. empty records in the *
108 * SINDX.DAT file contain the value 4,294,967,295 (NOT_USED = 0xFFFFFFFF). *
109 \****************************************************************************/
110 #define NOT_USED 0xFFFFFFFF
111 #define OLD_NOT_USED 0xFFFF
112 
113 
114 /* ALARM_SAVE.DAT file info */
115 #define ALARMDIR "/usr/DAT/alarm"
116 #define ALARM_SAVE "/usr/DAT/ALARM.LOG"
117 #define DEFAULTACTION "/usr/DAT/alarm/defaultaction"
118 struct alarm_save {
119  unsigned char line1[80];
120  unsigned char line2[80];
121 };
122 
123 /* In the struct databank template, there are two coded bytes,
124  dbk.on_off and dbk.flag_bits. Each bit in the byte represents the
125  status of one of the alarm triggers. For example the first bit
126  represents the On/Off status of the Positive Level 1 Alarm Trigger.
127  dbk.on_off represents whether alarm criteria has been set.
128  dbk.flag_bits represents whether alarm criteria has been exceeded. */
129 #define POS_LEVEL_1 0x01 /* Bit 1 (00000001), Positive Level 1 */
130 #define POS_LEVEL_2 0x02 /* Bit 2 (00000010), Positive Level 2 */
131 #define POS_ROC 0x04 /* Bit 3 (00000100), Positive Rate of Change */
132 #define NEG_LEVEL_1 0x10 /* Bit 5 (00010000), Negative Level 1 */
133 #define NEG_LEVEL_2 0x20 /* Bit 6 (00100000), Negative Level 2 */
134 #define NEG_ROC 0x40 /* Bit 7 (01000000), Negative Rate Of Change */
135 
136 
137 #define DB_DIR "/usr/DAT"
138 
139 /* DATABANK.DAT file info */
140 #define DATABANK "/usr/DAT/DATABANK.DAT"
141 
142 struct report {
143  float data; /* converted data value */
144  time_t clock; /* time in seconds since 01/01/70 00:00:00 */
145  unsigned char dqr; /* SHEF Data Qualifier & Revision bit */
146  unsigned char qds; /* Quality Departure Score */
147  unsigned char qpi; /* Quality Process Identifier */
148 };
149 
150 #define RPTS_PER_REC 365
151 
152 struct databank {
153  unsigned long int sid; /* Sensor id number */
154  unsigned long int stype; /* sensor type number */
155  signed long int next; /* pointer to next report structure used */
156  unsigned long int prior; /* backward pointer to last OVERLOAD rec used*/
157  unsigned short int num_overloads; /* Number of OVERLOAD records assigned to sensor. */
158  /*********************************************/
159  float divr; /* data is stored in database as a converted */
160  float base; /* value. divr,base,mult,and addr fields are */
161  float mult; /* used to convert sensor reports to data */
162  float addr; /* data = (((report/divr)+base)*mult)+addr */
163  /*********************************************/
164  unsigned short int cycle_size; /* sensor cycle size (default=0) */
165  signed char cycle_count;
166  unsigned char data_rate;
167  float max_accept; /* maximum acceptable value from this sensor */
168  float min_accept; /* minimum acceptable value from this sensor */
169  float above_alarm;
170  unsigned char above_status;
171  float below_alarm;
172  unsigned char below_status;
174  unsigned short int above_roc_time;
175  unsigned char above_roc_status;
177  unsigned short int below_roc_time;
178  unsigned char below_roc_status;
179  unsigned short int alrm_rst_tm; /* minutes alarms disabled once triggerred */
180  unsigned char unused_bytes[9];
181  struct report rpt[RPTS_PER_REC];
182 };
183 
184 struct old_databank {
185  unsigned short int sid; /* Sensor id number */
186  signed short int next; /* pointer to next report structure used */
187  unsigned long int prior; /* backward pointer to last OVERLOAD rec used*/
188  unsigned short int stype; /* sensor type number */
189  /*********************************************/
190  float divr; /* data is stored in database as a converted */
191  float base; /* value. divr,base,mult,and addr fields are */
192  float mult; /* used to convert sensor reports to data */
193  float addr; /* data = (((report/divr)+base)*mult)+addr */
194  /*********************************************/
195  unsigned short int cycle_size; /* sensor cycle size (default=0) */
196  unsigned char cycle_count;
197  float max_accept; /* maximum acceptable value from this sensor */
198  float min_accept; /* minimum acceptable value from this sensor */
199  unsigned char on_off; /* indicates if an alarm is set */
200  unsigned char flag_bits; /* indicates if an alarm is exceeded */
201  float alarm_p1; /* positive alarm level one, warning level */
202  float alarm_p2; /* positive alarm level two, alarm level */
203  /*********************************************/
204  float delta_levelp;/* delta_levelp & delta_timep used to compute*/
205  unsigned short int delta_timep; /* a positive rate of change alarm value */
206  /*********************************************/
207  float alarm_n1; /* negative alarm level one, warning level */
208  float alarm_n2; /* negative alarm level two, alarm level */
209  float delta_leveln;/* delta_leveln & delta_timen used to compute*/
210  unsigned short int delta_timen; /* a negative rate of change alarm value */
211  /*********************************************/
212  time_t time_level1; /* time in secs since 01/01/80 level 1 alarm */
213  time_t time_level2; /* time in secs since 01/01/80 level 2 alarm */
214  time_t time_roc; /* time in secs since 01/01/80 roc alarm */
215  unsigned short int alrm_rst_tm; /* minutes alarms disabled once triggerred */
216  struct report rpt[365];
217 };
218 
219 /* DATABASE.DAT file info */
220 #define DATABASE "/usr/DAT/DATABASE.DAT"
221 struct database {
222  unsigned long int recs_allocated; /* # of records allocated for database */
223  unsigned long int recs_used; /* # of records used */
224  unsigned long int overload_recs; /* max # of records in OVERLOAD.DAT */
225  unsigned long int sensor_types; /* # of sensor types defined */
226  time_t dbcreated; /* Creation date of database. */
227  time_t dbmodified; /* Date last modified by dbinit. */
228  unsigned char alarm_check; /* Check incoming reports for alarms? */
229  unsigned char mininum; /* Mininum for datacol dial in */
230 };
231 
232 struct old_database {
233  unsigned short int recs_allocated; /* # of records allocated for database */
234  unsigned short int recs_used; /* # of records used */
235  unsigned long int overload_recs; /* max # of records in OVERLOAD.DAT */
236  unsigned short int sensor_types; /* # of sensor types defined */
237  unsigned char alarm_check; /* Check incoming reports for alarms? */
238  unsigned char mininum; /* Mininum for datacol dial in */
239 };
240 
241 #define DIAL "/usr/DAT/DIAL.DAT"
242 
243 /* structure for /usr/DAT/DIAL.LOG file */
244 #define DIALLOG "/usr/DAT/DIAL.LOG"
245 struct dial_message {
246  unsigned char message[80];
247 };
248 
249 
250 /* Structure used in the ERROR.LOG file */
251 #define ERRORLOG "/usr/DAT/ERROR.LOG"
253  char message[80];
254 };
255 
256 #define GROUP "/usr/DAT/GROUP.DAT"
257 struct group {
258  unsigned char name[NAME_LEN];
259  unsigned long int sid[8];
260  unsigned char sid_name[8][7];
261 };
262 
263 struct old_group {
264  unsigned char name[30];
265  unsigned short int sid[8];
266  unsigned char sid_name[8][7];
267 };
268 
269 /* HANDBOOK5.DAT file info */
270 #define HANDBOOK5 "/usr/DAT/HANDBOOK5.DAT"
271 #define THANDBOOK5 "/tmp/HANDBOOK5.DAT"
272 struct handbook5 {
273  char id[HB5_ID_LEN]; /* Handbook 5 id */
274  char pc[PC_LEN]; /* SHEF parameter code */
275  unsigned long int dbk_ptr; /* relative record number of DATABANK record */
276 };
277 
279  unsigned char id[11]; /* Handbook 5 id */
280  unsigned char pc[9]; /* SHEF parameter code */
281  unsigned short int dbk_ptr; /* relative record number of DATABANK record */
282 };
283 
284 /* INTERROGATE.DAT file info */
285 #define INTERROGATE "/usr/DAT/INTERROGATE.DAT"
286 struct interrogate {
287  unsigned char name[26];
288  unsigned char station_id[21];
289  unsigned int gagetype;
290  signed int call_interval;
291  signed int start_time;
292  unsigned int maxtrys;
293  unsigned int timeout;
294  unsigned char phone_num[41];
295  unsigned int baud;
296  unsigned char parity;
297  unsigned char stop_bits;
298  unsigned char data_bits;
299  unsigned int sens_cnt;
300  struct channel_gage {
301  unsigned int ch;
302  unsigned int sid;
303  } channel[21];
304  unsigned int scans_per_ch;
305  time_t attempt_time;
306  time_t success_time;
307  signed int time_offset;
308 };
309 
310 /* OVERINDX.DAT file info */
311 #define OVERINDX "/usr/DAT/OVERINDX.DAT"
312 #define DEFAULTOV 10
313 #define ONOT_USED 0xFFFFFFFF
314 #define OVIDX_RECS 0x100
315 struct overindx {
316  unsigned long int sid; /* sensor id number of sensor that owns this rec */
317  unsigned long int next; /* forward pointer to the next OVERLOAD.DAT record
318  to be used */
319 };
320 
321 struct old_overindx {
322  unsigned short int sid; /* sensor id number of sensor that owns this rec */
323  unsigned long int next; /* forward pointer to the next OVERLOAD.DAT record
324  to be used */
325 };
326 
327 /****************************************************************************\
328 * The OVERLOAD.DAT file will have a similar format as the DATABANK.DAT *
329 * file. *
330 \****************************************************************************/
331 #define OVERLOAD "/usr/DAT/OVERLOAD.DAT"
332 
333 /* OWNER.DAT file info */
334 #define OWNER "/usr/DAT/OWNER.DAT"
335 struct agency {
336  unsigned char id;
337  unsigned char name[26];
338  unsigned char street1[26];
339  unsigned char street2[26];
340  unsigned char city[26];
341  unsigned char state[3];
342  unsigned char zip[11];
343  unsigned char contact_name[26];
344  unsigned char contact_phone[17];
345  unsigned char comment1[70];
346  unsigned char comment2[70];
347  unsigned char comment3[70];
348  unsigned char comment4[70];
349  unsigned char comment5[70];
350 };
351 
352 #define RATING "/usr/DAT/RATING.DAT"
353 
354 /* Extrapolation methods for rating curves: linear or logarithmic. */
355 #define LINEAR '1'
356 #define LOG '2'
357 
358 struct rating {
359  unsigned long int sid; /* Sensor ID# for this rating record. */
360  time_t entry_date; /* Date when this record last updated. */
361  float datum; /* Arbitrary zero point Mean Sea Level. */
362  struct shift_factors {
363  float shift; /* Adjust rating curve by shift. */
364  float stage;
365  } sf[4];
366  char flow_units[16];
367  char extrapolation_method; /* LINEAR or LOG */
368  struct rating_curve {
369  float stage;
370  float flow;
371  } rc[129];
373  float flood_stage;
374  float max_stage;
375  float min_stage;
376  struct record_stage {
378  signed short int record_month;
379  signed short int record_day;
380  signed long int record_year;
382  struct sig_stages {
383  float stage;
384  unsigned char message[30];
385  } ss[10];
387  unsigned char unused_bytes[59];
388 };
389 
390 #define SENSORGRPS "/usr/DAT/SENSORGRPS.DAT"
391 struct sensorgrps {
392  unsigned char name[NAME_LEN];
393  unsigned long int sid[50];
394 };
395 
397  unsigned char name[31];
398  unsigned short int sid[50];
399 };
400 
401 #define SENSOR_FILE "/usr/DAT/SENSOR_FILE.DAT"
402 #define NO_OWNER 0x00
403 
404 /* Values for (status_flag fields in SENSOR_FILE.DAT),
405  (above_status,below_status,above_roc_status, and
406  below_roc_status in DATABANK.DAT)
407  and (alarm_level field in ALT_ALARM.DAT). */
408 #define INACTIVE 0x00
409 #define ACTIVE 0x01
410 #define ACTIVE1 0x01
411 #define ACTIVE2 0x02
412 #define ACTIVE3 0x03
413 #define ACTIVE4 0x04
414 #define ALARMED 0x05
415 
417  float alarm_level; /* Alarm criteria. */
418  time_t time_last_alarm; /* Time of last alarm. */
419  unsigned char status_flag; /* Status: INACTIVE or ACTIVE */
420  unsigned long int alt_ptr; /* Pointer into ALT_ALARM.DAT.
421  Set to NOT_USED if default */
422 };
423 
424 struct roc_alarm {
425  float delta_level; /* Alarm criteria. */
426  unsigned short int delta_time; /* Alarm criteria. */
427  time_t time_last_alarm; /* Time of last alarm. */
428  unsigned char status_flag; /* Status: INACTIVE or ACTIVE. */
429  unsigned long int alt_ptr; /* Pointer into ALT_ALARM.DAT.
430  Set to NOT_USED if default */
431 };
432 
433 struct sensor_file {
434  unsigned long int sid;
435  char name[NAME_LEN];
437  char pc[PC_LEN];
438  struct absolute_alarm above_abs[4];
439  struct roc_alarm above_roc[4];
440  struct absolute_alarm below_abs[4];
441  struct roc_alarm below_roc[4];
442  unsigned long int rating; /* Index into RATING.DAT file. */
443  signed long lat_ord;
444  unsigned char hemisphere_lat;
445  signed long long_ord;
446  unsigned char hemisphere_long;
447  float elevation;
448  unsigned char elevation_units[16];
449  unsigned char owner;
450  unsigned char location[NAME_LEN];
451  float radio_freq;
452  unsigned char criteria_check;
453  unsigned short int criteria_minutes;
454  unsigned char unused_bytes[112];
455 };
456 
457 #define ALT_ALARM "/usr/DAT/ALT_ALARM.DAT"
458 #define ALARM_ABOVE 0x01
459 #define ALARM_BELOW 0x02
460 #define ALARM_ABOVE_ROC 0x03
461 #define ALARM_BELOW_ROC 0x04
462 
463 struct alt_alarm {
464  unsigned long int sid; /* Sensor ID number of sensor
465  that has an alternate
466  alarm action. */
467  unsigned char alarm_type; /* Type of alarm (for this sensor
468  that has an alternate alarm
469  action: ALARM_ABOVE,
470  ALARM_BELOW, ALARM_ABOVE_ROC,
471  or ALARM_BELOW_ROC. */
472  unsigned char alarm_level; /* Level of alarm (for this sensor
473  that has an alternate alarm
474  action: ACTIVE1, ACTIVE2,
475  ACTIVE3, or ACTIVE4. */
476  unsigned char alarm_action[NAME_LEN]; /* Alternate alarm program
477  to execute when alarm
478  criteria exceeded. */
479 };
480 
482  unsigned short int sid;
483  unsigned char name[26];
484  unsigned char hb5_id[11];
485  unsigned char pc[9];
486  signed long lat_ord;
487  signed long long_ord;
488  float elevation;
489  unsigned char owner;
490  unsigned char location[26];
491  float radio_freq;
492 };
493 
494 /* SENSOR_TYPE.DAT file info */
495 #define SENSOR_TYPE "/usr/DAT/SENSOR_TYPE.DAT"
496 struct sensor_type {
497  unsigned long int number;
498  char name[NAME_LEN];
499  char parm_code[PC_LEN]; /* SHEF parameter code */
500  unsigned short int overloads;
501  float divisor;
502  float base;
503  float multiplier;
504  float adder;
505  char units_name[16];
506  char units_abbr[6];
507  float max_accept;
508  float min_accept;
509  unsigned short int criteria_hours;
511  char unused_bytes[11];
512 };
513 
515  unsigned short int number;
516  unsigned char name[26];
517  unsigned char parm_code[9]; /* SHEF parameter code */
518  unsigned short int overloads;
519  float divisor;
520  float base;
521  float multiplier;
522  float adder;
523  unsigned char units_name[16];
524  unsigned char units_abbr[6];
525  float max_accept;
526  float min_accept;
527  unsigned short int criteria_hours;
528  unsigned char criteria_check;
529  unsigned char stop_bits;
530  unsigned char data_bits;
531  unsigned char inter_mode;
532  unsigned char calibrate; /* 0=NO, 1=YES */
533 };
534 
535 #define SINDX "/usr/DAT/SINDX.DAT"
536 #define TSINDX "/tmp/SINDX.DAT"
537 struct sindx {
538  unsigned long int sid; /* sensor id number of sensor that owns rec */
539  unsigned long int dbk_ptr; /* relative record number for DATABANK recd */
540 };
541 
542 struct old_sindx {
543  unsigned short int sid; /* sensor id number of sensor that owns rec */
544  unsigned short int dbk_ptr; /* relative record number for DATABANK recd */
545 };
546 
547 
548 /* SNAME.DAT file info */
549 #define SNAME "/usr/DAT/SNAME.DAT"
550 #define TSNAME "/tmp/SNAME.DAT"
551 #define CNOT_USED 0x7E
552 struct sensor_name {
553  unsigned char name[NAME_LEN]; /* sensor name */
554  unsigned long int dbk_ptr; /* relative record number for DATABANK recd */
555 };
556 
558  unsigned char name[26]; /* sensor name */
559  unsigned short int dbk_ptr; /* relative record number for DATABANK recd */
560 };
561 
562 #define SIMPARMS "/usr/DAT/SIMPARMS.DAT"
563 #define QSIM "/usr/DAT/QSIM.DAT"
564 #define QFCST "/usr/DAT/QFCST"
565 #define CONT "/usr/DAT/CONT.DAT"
566 #define DIALGROUPS "/usr/DAT/DIALGROUPS.DAT"
567 #define VERSION "/usr/DAT/VERSION.DAT"
568 
569 /* Database port information */
570 #define ALARMPORT 18 /* port number attached to by alarm functions */
571 /* the port # attached to by simulation manager can be found in def_file.h */
572 
573 /* Database file index numbers for files that are ALWAYS OPEN */
574 #define NDATABANK 0x00000000 /* /usr/DAT/DATABANK.DAT */
575 #define NDATABASE 0x00000001 /* /usr/DAT/DATABASE.DAT */
576 #define NSENSOR_FILE 0x00000002 /* /usr/DAT/SENSOR_FILE.DAT */
577 #define NSENSOR_TYPE 0x00000003 /* /usr/DAT/SENSOR_TYPE.DAT */
578 #define NTHANDBOOK5 0x00000004 /* /tmp/HANDBOOK5.DAT */
579 #define NTSINDX 0x00000005 /* /tmp/SINDX.DAT */
580 #define NTSNAME 0x00000006 /* /tmp/SNAME.DAT */
581 
582 /* Database file index numbers for files that are NOT ALWAYS OPEN */
583 #define NALARMLOG 0x00000007 /* /usr/DAT/ALARM.LOG */
584 #define NERRORLOG 0x00000008 /* /usr/DAT/ERROR.LOG */
585 #define NGROUP 0x00000009 /* /usr/DAT/GROUP.DAT */
586 #define NHANDBOOK5 0x0000000A /* /usr/DAT/HANDBOOK5.DAT */
587 #define NOVERINDX 0x0000000B /* /usr/DAT/OVERINDX.DAT */
588 #define NOVERLOAD 0x0000000C /* /usr/DAT/OVERLOAD.DAT */
589 #define NOWNER 0x0000000D /* /usr/DAT/OWNER.DAT */
590 #define NSENSORGRPS 0x0000000E /* /usr/DAT/SENSORGRPS.DAT */
591 #define NSINDX 0x0000000F /* /usr/DAT/SINDX.DAT */
592 #define NSNAME 0x00000010 /* /usr/DAT/SNAME.DAT */
593 #define NDIAL 0x00000011 /* /usr/DAT/DIAL.DAT */
594 #define NINTERROGATE 0x00000012 /* /usr/DAT/INTERROGATE.DAT */
595 #define NDIALLOG 0x00000013 /* /usr/DAT/DIAL.LOG */
596 #define NSIMPARMS 0x00000014 /* /usr/DAT/SIMPARMS.DAT */
597 #define NQSIM 0x00000015 /* /usr/DAT/QSIM.DAT */
598 #define NQFCST 0x00000016 /* /usr/DAT/QFCST.DAT */
599 #define NCONT 0x00000017 /* /usr/DAT/CONT.DAT */
600 #define NDIALGROUPS 0x00000018 /* /usr/DAT/DIALGROUPS.DAT */
601 #define NRATING 0x00000019 /* /usr/DAT/RATING.DAT */
602 #define NALT_ALARM 0x0000001A /* /usr/DAT/ALT_ALARM.DAT */
603 #define NVERSION 0x0000001B /* /usr/DAT/VERSION.DAT */
604 
605 /* Maximum database file index number. */
606 #define NOT_ALWAYS_OPEN 0x00000007
607 #define DB_RESERVED 0x0000001C
608 
609 /* dbmngr message type definitions */
610 #define DBCLOSE 0x00000001
611 #define DBOPEN 0x00000002
612 #define DBREAD 0x00000003
613 #define DBSIZE 0x00000004
614 #define DBTRUNC 0x00000005
615 #define DBWRITE 0x00000006
616 
617 /* Maximum size for a message to the database manager, dbmngr. If requested
618  data exceeds MAX_MSG_SIZE then dbread/dbwrite breaks large message into
619  smaller messages. */
620 #define MAX_MSG_SIZE 16384L
621 
622 /* dbmngr request structure */
623 struct dbmsg_req {
624  unsigned long int msg_type; /* Database message type:DBREAD, DBWRITE, etc...*/
625  unsigned long int file; /* File index number:NDATABANK,NDATABASE, etc...*/
626  off_t offset; /* Offset in bytes for start of operation */
627  unsigned long int rec_size; /* Number of bytes in a record */
628  unsigned long int num_recs; /* Number of records */
629 };
630 
631 
632 /* database function prototypes. */
633 unsigned int dbclose(unsigned long int file_num);
634 unsigned int dbopen(unsigned long int file_num);
635 unsigned long int dbread(unsigned long int file_num, signed long int offset,
636  unsigned long int rec_size, unsigned long int num_recs, void *buf);
637 signed long int dbsize(unsigned long int file_num);
638 signed long int dbtrunc(unsigned long int file_num, signed long int offset);
639 unsigned long int dbwrite(unsigned long int file_num, signed long int offset,
640  unsigned long int rec_size, unsigned long int num_recs, void *buf);
641 struct period_rain {
643  unsigned char dq;
644 };
645 struct work_array {
646  float data; /* converted data value */
647  time_t clock; /* time in seconds since 01/01/80 00:00:00 */
648 };
649 struct period_rain sumALERTrain(struct work_array *work, time_t clock_start,
650  time_t clock_end, float max_accumulator);
651 struct period_rain sum_rain(struct work_array *work, time_t clock_start,
652  time_t clock_end);
653 
654 
655 
656 struct handbook5 bs_hb5(unsigned char *hb5_pc, size_t max_recs,
657  struct handbook5 *hb);
658 void bubble_hb5(size_t num_items);
659 void bubble_sindx(struct sindx *sid_array, unsigned int num_items);
660 void bubble_sname(size_t num_items);
661 void bub_hb5(unsigned long int num_items);
662 void bub_sindx(unsigned long int num_items);
663 void bub_sname(unsigned long int num_items);
664 void check_alarm(struct msgbuf *msg, struct databank *dbk, size_t rec_num,
665  unsigned int reactivate_msg);
666 void chg_reports(unsigned int index, struct databank *dbk,
667  float chgval, signed char all_data, time_t told);
668 pid_t find_databuf(void);
669 unsigned long int get_reports(unsigned long int index, struct databank *dbk,
670  time_t tnew, time_t told, char *qualifier,
671  unsigned long int report_limit, struct report *rpt);
672 signed long get_timezone(unsigned char tz_name[4]);
673 void mk_dial_msg(unsigned char *pname, unsigned char *msg,
674  struct dial_message *dialmsg);
675 void mk_err_msg(char *pname, char *errmsg,
676  struct error_message *err);
677 unsigned long read_ovidx(struct overindx *oi, unsigned long num_oi);
678 unsigned char read_sindx(void);
679 struct msgbuf rec_update(void);
680 void red_alert(struct error_message *err);
681 unsigned int send_databuf(unsigned int id, unsigned char *hb5_id,
682  unsigned char *pc, float data, time_t clock,
683  unsigned char dq, unsigned char gage_type, signed int tid,
684  unsigned int node_num, signed int tty_num);
685 
686 
687 
688 struct update update_on(void);
689 unsigned char update_off(struct update);
690 unsigned long write_ovidx(struct overindx *oi, unsigned long num_oi);
691 
692 #endif /* _databaseh */
unsigned int dbopen(unsigned long int file_num)
struct msgbuf rec_update(void)
unsigned long int dbwrite(unsigned long int file_num, signed long int offset, unsigned long int rec_size, unsigned long int num_recs, void *buf)
Definition: dbwrite.c:22
void bub_sname(unsigned long int num_items)
unsigned long int get_reports(unsigned long int index, struct databank *dbk, time_t tnew, time_t told, char *qualifier, unsigned long int report_limit, struct report *rpt)
unsigned char update_off(struct update)
#define RPTS_PER_REC
Definition: database.h:150
void chg_reports(unsigned int index, struct databank *dbk, float chgval, signed char all_data, time_t told)
unsigned long int dbread(unsigned long int file_num, signed long int offset, unsigned long int rec_size, unsigned long int num_recs, void *buf)
Definition: dbread.c:22
#define NAME_LEN
Definition: database.h:47
struct update update_on(void)
pid_t find_databuf(void)
void bubble_sindx(struct sindx *sid_array, unsigned int num_items)
unsigned long read_ovidx(struct overindx *oi, unsigned long num_oi)
unsigned int dbclose(unsigned long int file_num)
void bubble_hb5(size_t num_items)
unsigned int send_databuf(unsigned int id, unsigned char *hb5_id, unsigned char *pc, float data, time_t clock, unsigned char dq, unsigned char gage_type, signed int tid, unsigned int node_num, signed int tty_num)
signed long int dbsize(unsigned long int file_num)
Definition: dbsize.c:13
struct period_rain sumALERTrain(struct work_array *work, time_t clock_start, time_t clock_end, float max_accumulator)
struct period_rain sum_rain(struct work_array *work, time_t clock_start, time_t clock_end)
unsigned char read_sindx(void)
void bub_hb5(unsigned long int num_items)
struct handbook5 bs_hb5(unsigned char *hb5_pc, size_t max_recs, struct handbook5 *hb)
void mk_err_msg(char *pname, char *errmsg, struct error_message *err)
Definition: mk_err_msg.c:29
signed long get_timezone(unsigned char tz_name[4])
void check_alarm(struct msgbuf *msg, struct databank *dbk, size_t rec_num, unsigned int reactivate_msg)
signed long int dbtrunc(unsigned long int file_num, signed long int offset)
unsigned long write_ovidx(struct overindx *oi, unsigned long num_oi)
void bubble_sname(size_t num_items)
void mk_dial_msg(unsigned char *pname, unsigned char *msg, struct dial_message *dialmsg)
#define HB5_ID_LEN
Definition: database.h:45
#define PC_LEN
Definition: database.h:46
void bub_sindx(unsigned long int num_items)
void red_alert(struct error_message *err)
struct stat buf
Definition: is_file_closed.c:8
char * pname
Definition: shef_structs.h:264
int tid
Definition: shef_structs.h:258
float alarm_level
Definition: database.h:417
time_t time_last_alarm
Definition: database.h:418
unsigned char status_flag
Definition: database.h:419
unsigned long int alt_ptr
Definition: database.h:420
unsigned char comment2[70]
Definition: database.h:346
unsigned char comment4[70]
Definition: database.h:348
unsigned char city[26]
Definition: database.h:340
unsigned char contact_name[26]
Definition: database.h:343
unsigned char state[3]
Definition: database.h:341
unsigned char comment3[70]
Definition: database.h:347
unsigned char comment1[70]
Definition: database.h:345
unsigned char zip[11]
Definition: database.h:342
unsigned char comment5[70]
Definition: database.h:349
unsigned char id
Definition: database.h:336
unsigned char name[26]
Definition: database.h:337
unsigned char contact_phone[17]
Definition: database.h:344
unsigned char street1[26]
Definition: database.h:338
unsigned char street2[26]
Definition: database.h:339
unsigned char line1[80]
Definition: database.h:119
unsigned char line2[80]
Definition: database.h:120
unsigned char alarm_action[NAME_LEN]
Definition: database.h:476
unsigned char alarm_level
Definition: database.h:472
unsigned char alarm_type
Definition: database.h:467
unsigned long int sid
Definition: database.h:464
unsigned long int prior
Definition: database.h:156
unsigned short int alrm_rst_tm
Definition: database.h:179
float max_accept
Definition: database.h:167
unsigned char unused_bytes[9]
Definition: database.h:180
float addr
Definition: database.h:162
unsigned char below_status
Definition: database.h:172
unsigned long int stype
Definition: database.h:154
float base
Definition: database.h:160
float min_accept
Definition: database.h:168
unsigned char above_status
Definition: database.h:170
unsigned short int below_roc_time
Definition: database.h:177
float above_alarm
Definition: database.h:169
unsigned char above_roc_status
Definition: database.h:175
signed char cycle_count
Definition: database.h:165
signed long int next
Definition: database.h:155
unsigned short int above_roc_time
Definition: database.h:174
float below_roc_level
Definition: database.h:176
float above_roc_level
Definition: database.h:173
unsigned char data_rate
Definition: database.h:166
unsigned char below_roc_status
Definition: database.h:178
unsigned short int num_overloads
Definition: database.h:157
unsigned short int cycle_size
Definition: database.h:164
float below_alarm
Definition: database.h:171
float mult
Definition: database.h:161
struct report rpt[RPTS_PER_REC]
Definition: database.h:181
unsigned long int sid
Definition: database.h:153
float divr
Definition: database.h:159
unsigned long int recs_used
Definition: database.h:223
unsigned long int recs_allocated
Definition: database.h:222
unsigned char alarm_check
Definition: database.h:228
unsigned char mininum
Definition: database.h:229
time_t dbcreated
Definition: database.h:226
time_t dbmodified
Definition: database.h:227
unsigned long int overload_recs
Definition: database.h:224
unsigned long int sensor_types
Definition: database.h:225
unsigned long int rec_size
Definition: database.h:627
off_t offset
Definition: database.h:626
unsigned long int file
Definition: database.h:625
unsigned long int msg_type
Definition: database.h:624
unsigned long int num_recs
Definition: database.h:628
unsigned char message[80]
Definition: database.h:246
char message[80]
Definition: database.h:253
unsigned char name[NAME_LEN]
Definition: database.h:258
unsigned long int sid[8]
Definition: database.h:259
unsigned char sid_name[8][7]
Definition: database.h:260
unsigned long int dbk_ptr
Definition: database.h:275
char pc[PC_LEN]
Definition: database.h:274
signed int start_time
Definition: database.h:291
unsigned char station_id[21]
Definition: database.h:288
struct interrogate::channel_gage channel[21]
unsigned int scans_per_ch
Definition: database.h:304
unsigned char parity
Definition: database.h:296
unsigned char phone_num[41]
Definition: database.h:294
unsigned int timeout
Definition: database.h:293
unsigned int maxtrys
Definition: database.h:292
signed int time_offset
Definition: database.h:307
unsigned int baud
Definition: database.h:295
unsigned char name[26]
Definition: database.h:287
signed int call_interval
Definition: database.h:290
time_t attempt_time
Definition: database.h:305
unsigned int gagetype
Definition: database.h:289
unsigned int sens_cnt
Definition: database.h:299
unsigned char stop_bits
Definition: database.h:297
time_t success_time
Definition: database.h:306
unsigned char data_bits
Definition: database.h:298
signed short int node
Definition: database.h:59
time_t clock
Definition: database.h:55
float report
Definition: database.h:54
unsigned char hb5_id[HB5_ID_LEN]
Definition: database.h:52
unsigned char qpi
Definition: database.h:58
unsigned char qds
Definition: database.h:57
unsigned char dqr
Definition: database.h:56
unsigned char gage_type
Definition: database.h:61
unsigned long int sta_id
Definition: database.h:51
signed short int tty_num
Definition: database.h:60
unsigned char pc[PC_LEN]
Definition: database.h:53
unsigned char action
Definition: database.h:50
float alarm_n1
Definition: database.h:207
float delta_leveln
Definition: database.h:209
float alarm_p1
Definition: database.h:201
time_t time_roc
Definition: database.h:214
time_t time_level2
Definition: database.h:213
unsigned short int stype
Definition: database.h:188
float alarm_n2
Definition: database.h:208
float addr
Definition: database.h:193
unsigned char flag_bits
Definition: database.h:200
float min_accept
Definition: database.h:198
unsigned short int cycle_size
Definition: database.h:195
float max_accept
Definition: database.h:197
unsigned short int alrm_rst_tm
Definition: database.h:215
time_t time_level1
Definition: database.h:212
signed short int next
Definition: database.h:186
float mult
Definition: database.h:192
float alarm_p2
Definition: database.h:202
float base
Definition: database.h:191
unsigned short int delta_timen
Definition: database.h:210
float divr
Definition: database.h:190
unsigned char on_off
Definition: database.h:199
unsigned short int sid
Definition: database.h:185
unsigned long int prior
Definition: database.h:187
unsigned short int delta_timep
Definition: database.h:205
unsigned char cycle_count
Definition: database.h:196
float delta_levelp
Definition: database.h:204
struct report rpt[365]
Definition: database.h:216
unsigned char mininum
Definition: database.h:238
unsigned short int sensor_types
Definition: database.h:236
unsigned char alarm_check
Definition: database.h:237
unsigned short int recs_used
Definition: database.h:234
unsigned short int recs_allocated
Definition: database.h:233
unsigned long int overload_recs
Definition: database.h:235
unsigned short int sid[8]
Definition: database.h:265
unsigned char sid_name[8][7]
Definition: database.h:266
unsigned char name[30]
Definition: database.h:264
unsigned short int dbk_ptr
Definition: database.h:281
unsigned char pc[9]
Definition: database.h:280
unsigned long int next
Definition: database.h:323
unsigned short int sid
Definition: database.h:322
signed long long_ord
Definition: database.h:487
signed long lat_ord
Definition: database.h:486
unsigned char hb5_id[11]
Definition: database.h:484
unsigned char pc[9]
Definition: database.h:485
float radio_freq
Definition: database.h:491
unsigned char owner
Definition: database.h:489
unsigned short int sid
Definition: database.h:482
float elevation
Definition: database.h:488
unsigned char name[26]
Definition: database.h:483
unsigned char name[26]
Definition: database.h:558
unsigned short int dbk_ptr
Definition: database.h:559
unsigned char inter_mode
Definition: database.h:531
float min_accept
Definition: database.h:526
unsigned char stop_bits
Definition: database.h:529
float max_accept
Definition: database.h:525
unsigned char criteria_check
Definition: database.h:528
unsigned short int overloads
Definition: database.h:518
unsigned char name[26]
Definition: database.h:516
unsigned char data_bits
Definition: database.h:530
float multiplier
Definition: database.h:521
unsigned char parm_code[9]
Definition: database.h:517
unsigned char units_abbr[6]
Definition: database.h:524
unsigned short int criteria_hours
Definition: database.h:527
unsigned char units_name[16]
Definition: database.h:523
unsigned short int number
Definition: database.h:515
unsigned char calibrate
Definition: database.h:532
unsigned char name[31]
Definition: database.h:397
unsigned short int sid[50]
Definition: database.h:398
unsigned short int dbk_ptr
Definition: database.h:544
unsigned short int sid
Definition: database.h:543
unsigned long int next
Definition: database.h:317
unsigned long int sid
Definition: database.h:316
unsigned char dq
Definition: database.h:643
float total_rainfall
Definition: database.h:642
signed long int record_year
Definition: database.h:380
signed short int record_month
Definition: database.h:378
signed short int record_day
Definition: database.h:379
unsigned char message[30]
Definition: database.h:384
float warning_stage
Definition: database.h:372
struct rating::shift_factors sf[4]
unsigned long int sid
Definition: database.h:359
float drainage_area
Definition: database.h:386
float datum
Definition: database.h:361
time_t entry_date
Definition: database.h:360
struct rating::record_stage min_rs
float flood_stage
Definition: database.h:373
unsigned char unused_bytes[59]
Definition: database.h:387
char extrapolation_method
Definition: database.h:367
char flow_units[16]
Definition: database.h:366
float max_stage
Definition: database.h:374
float min_stage
Definition: database.h:375
struct rating::rating_curve rc[129]
struct rating::record_stage max_rs
struct rating::sig_stages ss[10]
unsigned char dqr
Definition: database.h:145
unsigned char qpi
Definition: database.h:147
unsigned char qds
Definition: database.h:146
time_t clock
Definition: database.h:144
float data
Definition: database.h:143
unsigned long int alt_ptr
Definition: database.h:429
unsigned short int delta_time
Definition: database.h:426
unsigned char status_flag
Definition: database.h:428
time_t time_last_alarm
Definition: database.h:427
float delta_level
Definition: database.h:425
float elevation
Definition: database.h:447
struct absolute_alarm above_abs[4]
Definition: database.h:438
struct absolute_alarm below_abs[4]
Definition: database.h:440
unsigned char owner
Definition: database.h:449
signed long long_ord
Definition: database.h:445
struct roc_alarm above_roc[4]
Definition: database.h:439
char hb5_id[HB5_ID_LEN]
Definition: database.h:436
unsigned short int criteria_minutes
Definition: database.h:453
char name[NAME_LEN]
Definition: database.h:435
unsigned char criteria_check
Definition: database.h:452
unsigned long int sid
Definition: database.h:434
unsigned char hemisphere_lat
Definition: database.h:444
struct roc_alarm below_roc[4]
Definition: database.h:441
unsigned char elevation_units[16]
Definition: database.h:448
unsigned char unused_bytes[112]
Definition: database.h:454
signed long lat_ord
Definition: database.h:443
unsigned long int rating
Definition: database.h:442
unsigned char hemisphere_long
Definition: database.h:446
char pc[PC_LEN]
Definition: database.h:437
float radio_freq
Definition: database.h:451
unsigned char name[NAME_LEN]
Definition: database.h:553
unsigned long int dbk_ptr
Definition: database.h:554
float min_accept
Definition: database.h:508
char criteria_check
Definition: database.h:510
char parm_code[PC_LEN]
Definition: database.h:499
char unused_bytes[11]
Definition: database.h:511
float max_accept
Definition: database.h:507
char name[NAME_LEN]
Definition: database.h:498
float divisor
Definition: database.h:501
float adder
Definition: database.h:504
float multiplier
Definition: database.h:503
unsigned long int number
Definition: database.h:497
float base
Definition: database.h:502
unsigned short int criteria_hours
Definition: database.h:509
char units_abbr[6]
Definition: database.h:506
char units_name[16]
Definition: database.h:505
unsigned short int overloads
Definition: database.h:500
unsigned char name[NAME_LEN]
Definition: database.h:392
unsigned long int sid[50]
Definition: database.h:393
unsigned long int sid
Definition: database.h:538
unsigned long int dbk_ptr
Definition: database.h:539
unsigned char name[9]
Definition: database.h:98
unsigned int tid
Definition: database.h:99
time_t clock
Definition: database.h:647
float data
Definition: database.h:646
int report_limit
Definition: subdisplay.c:53