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... */
37 #include <sys/types.h>
46 typedef unsigned char byte;
47 typedef unsigned char uint8;
48 typedef unsigned ushort uint16;
49 typedef unsigned uint uint32;
58 typedef uint8_t uint8;
59 typedef uint16_t uint16;
60 typedef uint32_t uint32;
62 typedef int16_t int16;
63 typedef int32_t int32;
65 /* Some fixed assumptions:
66 Trial type is always bitsum.
67 Bit spacing method does not need to be communicated, since we'll
68 choose something at compile time.
69 Record size ranges from one to MAXSAMP_REC trials, which are assumed to
70 be evenly spaced starting at timestamp.
71 Records always begin on round seconds divisible by sec_rec, which
72 can range from one to MAXSEC_REC.
75 /* Some adjustable assumptions: */
77 #define MINBITS 32 /* Minimum bits per trial */
78 #define MAXBITS 253 /* Maximum bits per trial */
79 #define MAXSAMP_REC 10 /* Maximum samples/record */
80 #define MAXSEC_REC 3000 /* Maximum seconds/record */
82 #define SEC_PKT 60 /* Desired number of seconds per packet */
83 #define MAXREC_PKT 60 /* Maximum number of records per packet
84 For 1-second records (typ) this is 1 min */
86 #define EGG_MISSING_DATA 254 /* Value used to represent missing data in trials array. */
91 #error "Can't represent MAXBITS in a byte value."
94 #if MAXBITS >= EGG_MISSING_DATA
95 #error "MAXBITS is >= EGG_MISSING_DATA: ambiguous trial data possible."
98 typedef struct eggrec {
99 uint32 timestamp; /* Seconds since the epoch (19700101000000Z) */
100 trial trials[MAXSAMP_REC]; /* Trial values */
101 } EggRec; /* Normally 16 bytes total */
103 /* Make sure type field of packet is non-zero so that CRC works. */
105 typedef struct genpacket {
110 #define DATA_PACKET 0x0101
111 typedef struct eggheader {
112 uint16 type; /* type */
113 uint16 pktsize; /* Number of bytes in packet */
114 uint16 eggid; /* Identifying number for device */
115 uint16 samp_rec; /* Number of samples per record */
116 uint16 sec_rec; /* Number of seconds per record */
117 uint16 rec_pkt; /* Number of records per packet */
118 trial trialsz; /* Number of bits per trial */
119 uint16 numrec; /* Number of valid records */
122 #define REQ_PACKET 0x0202
123 typedef struct reqpacket {
124 uint16 type; /* type */
125 uint16 pktsize; /* Number of bytes in packet */
126 uint16 eggid; /* Identifying number for device */
127 uint32 starttm; /* Time for first record to send */
128 uint16 cksum; /* No data, checksum goes inside */
131 #define AWAKE_PACKET 0x0303
132 typedef struct awakepacket {
133 uint16 type; /* type */
134 uint16 pktsize; /* Number of bytes in packet */
135 uint16 eggid; /* Identifying number for device */
136 uint32 nowtm; /* Egg's identification of "now" (zulu) */
137 uint16 cksum; /* No data, checksum goes inside */
140 #define SETTINGS_PACKET 0x0404
141 typedef struct setpacket {
142 uint16 type; /* type */
143 uint16 pktsize; /* Number of bytes in packet */
144 uint16 eggid; /* Identifying number for device */
145 uint32 nowtm; /* Egg's identification of "now" (zulu) */
146 uint16 samp_rec; /* Number of samples per record */
147 uint16 sec_rec; /* Number of seconds per record */
148 uint16 rec_pkt; /* Number of records per packet */
149 trial trialsz; /* Number of bits per trial */
150 uint16 cksum; /* No data, checksum goes inside */
153 /* An EggCarton is the in-memory representation of a data
154 packet. Fields in it are thus in host byte order,
155 being translated, as appropriate, when transferred
156 to and from a DATA_PACKET by Packetize() and
159 typedef struct eggpkt {
160 EggHeader hdr; /* Header (type = DATA_PACKET) */
161 EggRec records[MAXREC_PKT];
164 typedef struct collect {
167 uint16 sampct; /* Count of completed samples in rec */
168 int32 dd; /* Device handle */
174 typedef struct eggentry {
177 struct sockaddr_in ipaddr;
178 int16 netmask; /* Number of significant bits, default 32. */
181 int16 connival; /* Connect interval in minutes */
182 uint32 lastupd; /* Zulutime of last update received */
183 int16 setup; /* Does setup match config file? */
184 char *upcmd; /* Command to bring net up (req if conntype == DND) */
185 char *dncmd; /* Command to bring net down */
186 char *url; /* URL describing basket or NULL */
189 typedef struct basketentry {
191 struct sockaddr_in ipaddr;
195 #define MAX_BASKETS 5
197 extern EggEntry eggtable[MAX_EGGS];
198 extern BasketEntry baskettable[MAX_BASKETS];
199 extern short numeggs, numbaskets;
200 extern EggHeader protocol;
202 extern char *pgmname; /* For error messages to announce program name */
208 #endif /* _GLOBAL_H */