10 /***********************
11 * Message Definitions *
12 ***********************/
14 #define MSG_HEADER 0x1234
16 #define MSG_VALID_DEVICE 0x0001 // device id is valid
17 #define MSG_VALID_WORLD 0x0002 // world time is valid
18 #define MSG_VALID_START 0x0004 // start time is valid
19 #define MSG_VALID_PERIOD 0x0008 // period is valid
20 #define MSG_VALID_SYNC 0x8000 // begin time sync
25 MSG_ID_INIT, // Device initialization
26 MSG_ID_SYNC, // Time synchronization
27 MSG_ID_EVENT, // Event occurred
28 MSG_MAX_ID, // Maximum message ID
32 uint32_t seconds; // Seconds since 1970
33 uint32_t nanosec; // Nanoseconds since 'seconds'
37 uint16_t header; // Message Header
38 uint16_t msgid; // Message ID
39 uint16_t length; // Body length
40 uint16_t cksum; // Body checksum
44 uint16_t valid; // Message valid bits
45 uint16_t device; // Device ID to use
46 ntime_t world; // World time (since 1970)
47 ntime_t start; // Transmit start time
48 ntime_t period; // Transmit period
52 ntime_t time; // Time of previous message
56 uint16_t device; // Device ID
57 uint16_t event; // Event ID
58 ntime_t world; // UTC Time of event
59 ntime_t local; // Time since turn-on
68 typedef void (*handler_t)(header_t *head, void *body);
74 handler_t handler[MSG_MAX_ID];
77 void msg_register(parser_t *parser, int msgid, handler_t handler);
79 void msg_receive(parser_t *parser, int byte);