10 /***********************
11 * Message Definitions *
12 ***********************/
14 #define MSG_HEADER 0x1234
16 #define MSG_CTL_VALID_DEVICE 0x0001 // device id is valid
17 #define MSG_CTL_VALID_WORLD 0x0002 // world time is valid
18 #define MSG_CTL_VALID_START 0x0004 // start time is valid
19 #define MSG_CTL_VALID_PERIOD 0x0008 // period is valid
20 #define MSG_CTL_RELAY_MODE 0x4000 // relay output messages
21 #define MSG_CTL_BEGIN_SYNC 0x8000 // begin time sync
26 MSG_ID_INIT, // Device initialization
27 MSG_ID_SYNC, // Time synchronization
28 MSG_ID_EVENT, // Event occurred
29 MSG_MAX_ID, // Maximum message ID
33 uint32_t seconds; // Seconds since 1970
34 uint32_t nanosec; // Nanoseconds since 'seconds'
38 uint16_t header; // Message Header
39 uint16_t msgid; // Message ID
40 uint16_t length; // Body length
41 uint16_t cksum; // Body checksum
45 uint16_t control; // Message control bits
46 uint16_t device; // Device ID to use
47 ntime_t world; // World time (since 1970)
48 ntime_t start; // Transmit start time
49 ntime_t period; // Transmit period
53 ntime_t time; // Time of previous message
57 uint16_t device; // Device ID
58 uint16_t event; // Event ID
59 ntime_t world; // UTC Time of event
60 ntime_t local; // Time since turn-on
69 typedef void (*handler_t)(header_t *head, void *body);
75 handler_t handler[MSG_MAX_ID];
78 void msg_register(parser_t *parser, int msgid, handler_t handler);
80 void msg_receive(parser_t *parser, int byte);