+ out[0] = 'S';
+ out[1] = (id >> 24) & 0xff;
+ out[2] = (id >> 16) & 0xff;
+ out[3] = (id >> 8) & 0xff;
+ out[4] = id & 0xff;
+ out[10] = 0x01;
+ out[11] = (tv.tv_usec >> 24) & 0xff;
+ out[12] = (tv.tv_usec >> 16) & 0xff;
+ out[13] = (tv.tv_usec >> 8) & 0xff;
+ out[14] = tv.tv_usec & 0xff;
+
+ memcpy(&out[0x0f], msg, msg[0] + 1);
+
+ memset(rdata, 0, sizeof(struct recv_data));
+ hmcfgusb_send(dev->hmcfgusb, out, sizeof(out), 1);
+
+ while (1) {
+ if (rdata->message_type == MESSAGE_TYPE_R) {
+ if (((rdata->status & 0xff) == 0x01) ||
+ ((rdata->status & 0xff) == 0x02)) {
+ break;
+ } else {
+ if ((rdata->status & 0xff00) == 0x0400) {
+ fprintf(stderr, "\nOut of credits!\n");
+ } else if ((rdata->status & 0xff) == 0x08) {
+ fprintf(stderr, "\nMissing ACK!\n");
+ } else {
+ fprintf(stderr, "\nInvalid status: %04x\n", rdata->status);
+ }
+ return 0;
+ }
+ }
+ errno = 0;
+ pfd = hmcfgusb_poll(dev->hmcfgusb, 1);
+ if ((pfd < 0) && errno) {
+ if (errno != ETIMEDOUT) {
+ perror("\n\nhmcfgusb_poll");
+ exit(EXIT_FAILURE);
+ }
+ }
+ }
+ break;
+ case DEVICE_TYPE_CULFW:
+ {
+ char buf[256];
+ int i;
+
+ memset(buf, 0, sizeof(buf));
+ buf[0] = 'A';
+ buf[1] = 's';
+ for (i = 0; i < msg[0] + 1; i++) {
+ buf[2 + (i * 2)] = nibble_to_ascii((msg[i] >> 4) & 0xf);
+ buf[2 + (i * 2) + 1] = nibble_to_ascii(msg[i] & 0xf);
+ }
+ buf[2 + (i * 2) ] = '\r';
+ buf[2 + (i * 2) + 1] = '\n';