File: global.h

package info (click to toggle)
gcpegg 5.1-14
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 324 kB
  • ctags: 439
  • sloc: ansic: 3,726; makefile: 97; sh: 33; csh: 21
file content (208 lines) | stat: -rw-r--r-- 6,092 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* PROGRAM:     eggsh
 * FILE:        $Header: /home/egg/src/RCS/global.h,v 1.5 1999/02/28 20:10:29 ghn Exp $
 * PURPOSE:     Declare global types, constants, and variables
 * AUTHOR:      Greg Nelson
 * DATE:        98-04-12
 *
 * REVISED:
 * $Log: global.h,v $
 * Revision 1.5  1999/02/28 20:10:29  ghn
 * Version 5.1: Added netmask field for egg.
 *
 * Revision 1.4  1998/12/31 22:11:05  ghn
 *  Rev 5 code: includes multi-reg support, HTML, etc.
 *
 * Revision 1.3  1998/08/01 18:51:25  ghn
 * Added John's byte-order-independence changes.
 *
 * Revision 1.2  1998/08/01 17:08:20  ghn
 * Added upcmd and dncmd for DND.
 *
 * Revision 1.1  1998/07/21 11:37:56  ghn
 * Initial revision
 *
 * Copyright 1998 - Greg Nelson
 * Redistributable under the terms of the GNU Public Licence (GPL)
 */

#ifndef _GLOBAL_H

#include <netinet/in.h>

#include "byteorder.h"		/* Build byte-order independent version */

/* Good for i386, but be careful... */
/*
#ifdef linux
#include <sys/types.h>
 typedef __u8  byte;
 typedef __u8  uint8;
 typedef __u16 uint16;
 typedef __u32 uint32;
 typedef __s8  int8;
 typedef __s16 int16;
 typedef __s32 int32;
#else
 typedef unsigned char byte;
 typedef unsigned char uint8;
 typedef unsigned ushort uint16;
 typedef unsigned uint uint32;
 typedef char int8;
 typedef short int16;
 typedef int int32;
#endif
*/

#include <stdint.h>
typedef uint8_t byte;
typedef uint8_t	uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;

/* Some fixed assumptions:
   Trial type is always bitsum.
   Bit spacing method does not need to be communicated, since we'll
     choose something at compile time. 
   Record size ranges from one to MAXSAMP_REC trials, which are assumed to
     be evenly spaced starting at timestamp.
   Records always begin on round seconds divisible by sec_rec, which
     can range from one to MAXSEC_REC.
*/

/* Some adjustable assumptions: */

#define MINBITS		32	/* Minimum bits per trial */
#define MAXBITS		253	/* Maximum bits per trial */
#define MAXSAMP_REC	10	/* Maximum samples/record */
#define MAXSEC_REC	3000	/* Maximum seconds/record */	

#define SEC_PKT		60	/* Desired number of seconds per packet */
#define MAXREC_PKT	60	/* Maximum number of records per packet
				   For 1-second records (typ) this is 1 min */

#define EGG_MISSING_DATA 254    /* Value used to represent missing data in trials array. */

#if MAXBITS < 256
typedef uint8 trial;
#else
#error "Can't represent MAXBITS in a byte value."
#endif

#if MAXBITS >= EGG_MISSING_DATA
#error "MAXBITS is >= EGG_MISSING_DATA: ambiguous trial data possible."
#endif

typedef struct eggrec {
  uint32 timestamp;	/* Seconds since the epoch (19700101000000Z) */
  trial trials[MAXSAMP_REC]; /* Trial values */
} EggRec;		/* Normally 16 bytes total */

/* Make sure type field of packet is non-zero so that CRC works. */

typedef struct genpacket {
  uint16 type;
  uint16 pktsize;
} GenPacket;

#define DATA_PACKET	0x0101
typedef struct eggheader {
  uint16 type;		/* type */
  uint16 pktsize;	/* Number of bytes in packet */
  uint16 eggid;		/* Identifying number for device */
  uint16 samp_rec;	/* Number of samples per record */
  uint16 sec_rec;	/* Number of seconds per record */
  uint16 rec_pkt;	/* Number of records per packet */
  trial trialsz;	/* Number of bits per trial */
  uint16 numrec;	/* Number of valid records */
} EggHeader;

#define REQ_PACKET	0x0202
typedef struct reqpacket {
  uint16 type;		/* type */
  uint16 pktsize;	/* Number of bytes in packet */
  uint16 eggid;		/* Identifying number for device */
  uint32 starttm;	/* Time for first record to send */
  uint16 cksum;		/* No data, checksum goes inside */
} ReqPacket;

#define AWAKE_PACKET	0x0303
typedef struct awakepacket {
  uint16 type;		/* type */
  uint16 pktsize;	/* Number of bytes in packet */
  uint16 eggid;		/* Identifying number for device */
  uint32 nowtm;		/* Egg's identification of "now" (zulu) */
  uint16 cksum;		/* No data, checksum goes inside */
} AwakePacket;

#define SETTINGS_PACKET	0x0404
typedef struct setpacket {
  uint16 type;		/* type */
  uint16 pktsize;	/* Number of bytes in packet */
  uint16 eggid;		/* Identifying number for device */
  uint32 nowtm;		/* Egg's identification of "now" (zulu) */
  uint16 samp_rec;	/* Number of samples per record */
  uint16 sec_rec;	/* Number of seconds per record */
  uint16 rec_pkt;	/* Number of records per packet */
  trial trialsz;	/* Number of bits per trial */
  uint16 cksum;		/* No data, checksum goes inside */
} SettingsPacket;

/*  An EggCarton is the in-memory representation of a data
    packet.  Fields in it are thus in host byte order,
    being translated, as appropriate, when transferred
    to and from a DATA_PACKET by Packetize() and
    Unpacketize().  */

typedef struct eggpkt {
  EggHeader hdr;	/* Header (type = DATA_PACKET) */
  EggRec records[MAXREC_PKT];
} EggCarton;

typedef struct collect {
  EggHeader opts;
  EggRec data;
  uint16 sampct;		/* Count of completed samples in rec */
  int32 dd;			/* Device handle */
} CollectRecord;

#define CONN_PERM	0
#define CONN_DND	1

typedef struct eggentry {
  char *name;
  int16 id;
  struct sockaddr_in ipaddr;
  int16 netmask;	/* Number of significant bits, default 32. */
  char *primbasket;
  int16 conntype;
  int16 connival;	/* Connect interval in minutes */
  uint32 lastupd;	/* Zulutime of last update received */
  int16 setup;		/* Does setup match config file? */
  char *upcmd;		/* Command to bring net up (req if conntype == DND) */
  char *dncmd;		/* Command to bring net down */
  char *url;		/* URL describing basket or NULL */
} EggEntry;

typedef struct basketentry {
  char *name;
  struct sockaddr_in ipaddr;
} BasketEntry;

#define MAX_EGGS	100
#define MAX_BASKETS	5

extern EggEntry eggtable[MAX_EGGS];
extern BasketEntry baskettable[MAX_BASKETS];
extern short numeggs, numbaskets;
extern EggHeader protocol;

extern char *pgmname;	/* For error messages to announce program name */

#define TRUE	-1
#define FALSE	0

#define _GLOBAL_H
#endif /* _GLOBAL_H */