enum message_type message_type;
uint16_t status;
int speed;
+ uint16_t hmcfgusb_version;
};
static int parse_hmcfgusb(uint8_t *buf, int buf_len, void *data)
case 'G':
rdata->speed = buf[1];
break;
+ case 'H':
+ rdata->hmcfgusb_version = (buf[11] << 8) | buf[12];
+ break;
default:
break;
}
memcpy(&out[0x0f], msg, msg[0] + 1);
memset(rdata, 0, sizeof(struct recv_data));
- hmcfgusb_send(dev, out, sizeof(out), 2);
+ hmcfgusb_send(dev, out, sizeof(out), 1);
while (1) {
if (rdata->message_type == MESSAGE_TYPE_R) {
((rdata->status & 0xff) == 0x02)) {
break;
} else {
- fprintf(stderr, "\n\nInvalid status: %04x\n\n", rdata->status);
+ fprintf(stderr, "\nInvalid status: %04x\n", rdata->status);
return 0;
}
}
out[0] = 'G';
out[1] = speed;
- hmcfgusb_send(dev, out, sizeof(out), 2);
+ hmcfgusb_send(dev, out, sizeof(out), 1);
while (1) {
errno = 0;
printf("\nHM-CFG-USB opened\n\n");
+ memset(out, 0, sizeof(out));
+ out[0] = 'K';
+ hmcfgusb_send(dev, out, sizeof(out), 1);
+
+ while (1) {
+ errno = 0;
+ pfd = hmcfgusb_poll(dev, 1);
+ if ((pfd < 0) && errno) {
+ if (errno != ETIMEDOUT) {
+ perror("\n\nhmcfgusb_poll");
+ exit(EXIT_FAILURE);
+ }
+ }
+ if (rdata.hmcfgusb_version)
+ break;
+ }
+
+ if (rdata.hmcfgusb_version < 0x3c7) {
+ fprintf(stderr, "HM-CFG-USB firmware too low: %u < 967\n", rdata.hmcfgusb_version);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("HM-CFG-USB firmware version: %u\n", rdata.hmcfgusb_version);
+
if (!switch_speed(dev, &rdata, 10)) {
fprintf(stderr, "Can't switch speed!\n");
exit(EXIT_FAILURE);
out[2] = (hmid >> 8) & 0xff;
out[3] = hmid & 0xff;
- hmcfgusb_send(dev, out, sizeof(out), 2);
+ hmcfgusb_send(dev, out, sizeof(out), 1);
switchcnt = 3;
do {
}
} while ((!switched) && (switchcnt--));
+ if (!switched) {
+ fprintf(stderr, "Too many errors, giving up!\n");
+ exit(EXIT_FAILURE);
+ }
printf("Yes!\n");