12 printf("Error: %s\n", msg);
16 void dump(const char *label, uint8_t *data, int len)
19 printf("%s: ", label);
20 for (i = 0; i < len; i++)
21 printf("%02hhx ", data[i]);
25 int main(int argc, char **argv)
27 char *device = argv[1];
29 error("usage: host /dev/ttyACM0");
35 clock_gettime(CLOCK_REALTIME, &ts);
37 head.header = MSG_HEADER;
38 head.msgid = MSG_ID_SYNC;
39 head.length = sizeof(sync_msg_t);
40 head.cksum = 0; // todo
43 body.time.seconds = ts.tv_sec;
44 body.time.nanosec = ts.tv_nsec;
46 dump("head", (uint8_t*)&head, sizeof(head));
47 dump("body", (uint8_t*)&body, sizeof(body));
49 FILE *fd = fopen(device, "a+");
50 if (!fd) error("opening device");
52 len += fwrite(&head, 1, sizeof(head), fd);
53 len += fwrite(&body, 1, sizeof(body), fd);
56 printf("wrote %d bytes\n", len);