11 printf("Error: %s\n", msg);
15 void dump(const char *label, uint8_t *data, int len)
18 printf("%s: ", label);
19 for (i = 0; i < len; i++)
20 printf("%02hhx ", data[i]);
24 int main(int argc, char **argv)
27 error("usage: host /dev/ttyACM0 0 sync");
30 char *opt_tty = argv[1];
31 int opt_device = atoi(argv[2]);
32 int opt_sync = argv[3] && !strcmp(argv[3], "sync") ?
35 // Lookup current wall-clock time
37 clock_gettime(CLOCK_REALTIME, &ts);
44 head.header = MSG_HEADER;
45 head.msgid = MSG_ID_INIT;
46 head.length = sizeof(init_msg_t);
47 head.cksum = 0; // todo
50 body.valid = MSG_VALID_DEVICE
57 body.device = opt_device;
58 body.world.seconds = ts.tv_sec;
59 body.world.nanosec = ts.tv_nsec;
60 body.start.seconds = ts.tv_sec;
61 body.start.nanosec = ts.tv_nsec;
62 body.period.seconds = 1;
63 body.period.nanosec = 0;
66 FILE *fd = fopen(opt_tty, "a+");
67 if (!fd) error("opening device");
69 len += fwrite(&head, 1, sizeof(head), fd);
70 len += fwrite(&body, 1, sizeof(body), fd);
74 dump("head", (uint8_t*)&head, sizeof(head));
75 dump("body", (uint8_t*)&body, sizeof(body));
77 printf("wrote %d bytes\n", len);