]> Pileus Git - ~andy/csm213a-hw/blob - hw2/messages.h
Add output event and more messages
[~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
10 #define MSG_VALID_START  0x0002
11 #define MSG_VALID_PERIOD 0x0004
12 #define MSG_VALID_WORLD  0x0008
13
14 #pragma pack(1)
15
16 typedef enum {
17         MSG_ID_INIT,       // Device initialization
18         MSG_ID_SYNC,       // Time synchronization
19         MSG_ID_EVENT,      // Event occurred
20         MSG_MAX_ID,        // Maximum message ID
21 } msgid_t;
22
23 typedef struct {
24         uint32_t seconds;  // Seconds since 1970 (without leap seconds)
25         uint32_t nanosec;  // Nanoseconds since 'seconds'
26 } ntime_t;
27
28 typedef struct {
29         uint16_t header;   // Message Header
30         uint16_t msgid;    // Message ID
31         uint16_t length;   // Body length
32         uint16_t cksum;    // Body checksum
33 } header_t;
34
35 typedef struct {
36         uint16_t valid;    // Message valid bits
37         uint16_t device;   // Device ID to use
38         ntime_t  start;    // Transmit start time 
39         ntime_t  period;   // Transmit period
40         ntime_t  world;    // World time (since 1970)
41 } init_msg_t;
42
43 typedef struct {
44         uint32_t seq;      // Current sequence counter
45         ntime_t  time;     // Time of previous message
46 } sync_msg_t;
47
48 typedef struct {
49         uint16_t device;   // Device ID
50         uint16_t event;    // Event ID
51         ntime_t  time;     // Timestamp
52 } event_msg_t;
53
54 #pragma pack()