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: control /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") ?
33 MSG_CTL_VALID_SYNC : 0;
34 int opt_relay = opt_device == 2;
36 // Lookup current wall-clock time
38 clock_gettime(CLOCK_REALTIME, &ts);
45 head.header = MSG_HEADER;
46 head.msgid = MSG_ID_INIT;
47 head.length = sizeof(init_msg_t);
48 head.cksum = 0; // todo
51 body.control = MSG_CTL_VALID_DEVICE
53 | MSG_CTL_VALID_PERIOD
59 body.device = opt_device;
60 body.world.seconds = ts.tv_sec;
61 body.world.nanosec = ts.tv_nsec;
62 body.start.seconds = ts.tv_sec;
63 body.start.nanosec = 0; //ts.tv_nsec;
64 body.period.seconds = 0;
65 body.period.nanosec = 100000000;
69 FILE *fd = fopen(opt_tty, "a+");
70 if (!fd) error("opening device");
72 len += fwrite(&head, 1, sizeof(head), fd);
73 len += fwrite(&body, 1, sizeof(body), fd);
77 dump("head", (uint8_t*)&head, sizeof(head));
78 dump("body", (uint8_t*)&body, sizeof(body));
80 printf("wrote %d bytes\n", len);