2 * FILE: $Header: /home/egg/src/RCS/global.h,v 1.5 1999/02/28 20:10:29 ghn Exp $
3 * PURPOSE: Declare global types, constants, and variables
9 * Revision 1.5 1999/02/28 20:10:29 ghn
10 * Version 5.1: Added netmask field for egg.
12 * Revision 1.4 1998/12/31 22:11:05 ghn
13 * Rev 5 code: includes multi-reg support, HTML, etc.
15 * Revision 1.3 1998/08/01 18:51:25 ghn
16 * Added John's byte-order-independence changes.
18 * Revision 1.2 1998/08/01 17:08:20 ghn
19 * Added upcmd and dncmd for DND.
21 * Revision 1.1 1998/07/21 11:37:56 ghn
24 * Copyright 1998 - Greg Nelson
25 * Redistributable under the terms of the GNU Public Licence (GPL)
30 #include <netinet/in.h>
32 #include "byteorder.h" /* Build byte-order independent version */
34 /* Good for i386, but be careful... */
36 #include <sys/types.h>
45 typedef unsigned char byte;
46 typedef unsigned char uint8;
47 typedef unsigned short uint16;
48 typedef unsigned long uint32;
54 /* Some fixed assumptions:
55 Trial type is always bitsum.
56 Bit spacing method does not need to be communicated, since we'll
57 choose something at compile time.
58 Record size ranges from one to MAXSAMP_REC trials, which are assumed to
59 be evenly spaced starting at timestamp.
60 Records always begin on round seconds divisible by sec_rec, which
61 can range from one to MAXSEC_REC.
64 /* Some adjustable assumptions: */
66 #define MINBITS 32 /* Minimum bits per trial */
67 #define MAXBITS 253 /* Maximum bits per trial */
68 #define MAXSAMP_REC 10 /* Maximum samples/record */
69 #define MAXSEC_REC 3000 /* Maximum seconds/record */
71 #define SEC_PKT 60 /* Desired number of seconds per packet */
72 #define MAXREC_PKT 60 /* Maximum number of records per packet
73 For 1-second records (typ) this is 1 min */
75 #define EGG_MISSING_DATA 254 /* Value used to represent missing data in trials array. */
80 #error "Can't represent MAXBITS in a byte value."
83 #if MAXBITS >= EGG_MISSING_DATA
84 #error "MAXBITS is >= EGG_MISSING_DATA: ambiguous trial data possible."
87 typedef struct eggrec {
88 uint32 timestamp; /* Seconds since the epoch (19700101000000Z) */
89 trial trials[MAXSAMP_REC]; /* Trial values */
90 } EggRec; /* Normally 16 bytes total */
92 /* Make sure type field of packet is non-zero so that CRC works. */
94 typedef struct genpacket {
99 #define DATA_PACKET 0x0101
100 typedef struct eggheader {
101 uint16 type; /* type */
102 uint16 pktsize; /* Number of bytes in packet */
103 uint16 eggid; /* Identifying number for device */
104 uint16 samp_rec; /* Number of samples per record */
105 uint16 sec_rec; /* Number of seconds per record */
106 uint16 rec_pkt; /* Number of records per packet */
107 trial trialsz; /* Number of bits per trial */
108 uint16 numrec; /* Number of valid records */
111 #define REQ_PACKET 0x0202
112 typedef struct reqpacket {
113 uint16 type; /* type */
114 uint16 pktsize; /* Number of bytes in packet */
115 uint16 eggid; /* Identifying number for device */
116 uint32 starttm; /* Time for first record to send */
117 uint16 cksum; /* No data, checksum goes inside */
120 #define AWAKE_PACKET 0x0303
121 typedef struct awakepacket {
122 uint16 type; /* type */
123 uint16 pktsize; /* Number of bytes in packet */
124 uint16 eggid; /* Identifying number for device */
125 uint32 nowtm; /* Egg's identification of "now" (zulu) */
126 uint16 cksum; /* No data, checksum goes inside */
129 #define SETTINGS_PACKET 0x0404
130 typedef struct setpacket {
131 uint16 type; /* type */
132 uint16 pktsize; /* Number of bytes in packet */
133 uint16 eggid; /* Identifying number for device */
134 uint32 nowtm; /* Egg's identification of "now" (zulu) */
135 uint16 samp_rec; /* Number of samples per record */
136 uint16 sec_rec; /* Number of seconds per record */
137 uint16 rec_pkt; /* Number of records per packet */
138 trial trialsz; /* Number of bits per trial */
139 uint16 cksum; /* No data, checksum goes inside */
142 /* An EggCarton is the in-memory representation of a data
143 packet. Fields in it are thus in host byte order,
144 being translated, as appropriate, when transferred
145 to and from a DATA_PACKET by Packetize() and
148 typedef struct eggpkt {
149 EggHeader hdr; /* Header (type = DATA_PACKET) */
150 EggRec records[MAXREC_PKT];
153 typedef struct collect {
156 uint16 sampct; /* Count of completed samples in rec */
157 int32 dd; /* Device handle */
163 typedef struct eggentry {
166 struct sockaddr_in ipaddr;
167 int16 netmask; /* Number of significant bits, default 32. */
170 int16 connival; /* Connect interval in minutes */
171 int32 lastupd; /* Zulutime of last update received */
172 int16 setup; /* Does setup match config file? */
173 char *upcmd; /* Command to bring net up (req if conntype == DND) */
174 char *dncmd; /* Command to bring net down */
175 char *url; /* URL describing basket or NULL */
178 typedef struct basketentry {
180 struct sockaddr_in ipaddr;
184 #define MAX_BASKETS 5
186 extern EggEntry eggtable[MAX_EGGS];
187 extern BasketEntry baskettable[MAX_BASKETS];
188 extern short numeggs, numbaskets;
189 extern EggHeader protocol;
191 extern char *pgmname; /* For error messages to announce program name */
197 #endif /* _GLOBAL_H */