#include #include #include #include #include "messages.h" void error(char *msg) { printf("Error: %s\n", msg); exit(0); } void dump(const char *label, uint8_t *data, int len) { int i; printf("%s: ", label); for (i = 0; i < len; i++) printf("%02hhx ", data[i]); printf("\n"); } int main(int argc, char **argv) { char *device = argv[1]; if (!device) error("usage: host /dev/ttyACM0"); header_t head = {}; sync_msg_t body = {}; struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); head.header = MSG_HEADER; head.msgid = MSG_ID_SYNC; head.length = sizeof(sync_msg_t); head.cksum = 0; // todo body.seq = 0; body.time.seconds = ts.tv_sec; body.time.nanosec = ts.tv_nsec; dump("head", (uint8_t*)&head, sizeof(head)); dump("body", (uint8_t*)&body, sizeof(body)); FILE *fd = fopen(device, "a+"); if (!fd) error("opening device"); int len = 0; len += fwrite(&head, 1, sizeof(head), fd); len += fwrite(&body, 1, sizeof(body), fd); fclose(fd); printf("wrote %d bytes\n", len); return 0; }