]> Pileus Git - ~andy/csm213a-hw/blob - hw2/messages.h
Update message definitions
[~andy/csm213a-hw] / hw2 / messages.h
1 /***********************
2  * Message Definitions *
3  ***********************/
4
5 #include <stdint.h>
6
7 #define MSG_HEADER       0x1234
8
9 #define MSG_VALID_DEVICE 0x0001  // device id is valid
10 #define MSG_VALID_WORLD  0x0002  // world time is valid
11 #define MSG_VALID_START  0x0004  // start time is valid
12 #define MSG_VALID_PERIOD 0x0008  // period is valid
13 #define MSG_VALID_SYNC   0x8000  // begin time sync
14
15 #pragma pack(1)
16
17 typedef enum {
18         MSG_ID_INIT,       // Device initialization
19         MSG_ID_SYNC,       // Time synchronization
20         MSG_ID_EVENT,      // Event occurred
21         MSG_MAX_ID,        // Maximum message ID
22 } msgid_t;
23
24 typedef struct {
25         uint32_t seconds;  // Seconds since 1970
26         uint32_t nanosec;  // Nanoseconds since 'seconds'
27 } ntime_t;
28
29 typedef struct {
30         uint16_t header;   // Message Header
31         uint16_t msgid;    // Message ID
32         uint16_t length;   // Body length
33         uint16_t cksum;    // Body checksum
34 } header_t;
35
36 typedef struct {
37         uint16_t valid;    // Message valid bits
38         uint16_t device;   // Device ID to use
39         ntime_t  world;    // World time (since 1970)
40         ntime_t  start;    // Transmit start time 
41         ntime_t  period;   // Transmit period
42 } init_msg_t;
43
44 typedef struct {
45         uint32_t seq;      // Current sequence counter
46         ntime_t  time;     // Time of previous message
47 } sync_msg_t;
48
49 typedef struct {
50         uint16_t device;   // Device ID
51         uint16_t event;    // Event ID
52         ntime_t  world;    // UTC Time of event
53         ntime_t  local;    // Time since turn-on
54 } event_msg_t;
55
56 #pragma pack()