/* flasher for HomeMatic-devices supporting OTA updates
*
- * Copyright (c) 2014-15 Michael Gernoth <michael@gernoth.net>
+ * Copyright (c) 2014-16 Michael Gernoth <michael@gernoth.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
*e = '\0';
v = atoi(s);
rdata->version |= v;
+
+ s = e + 1;
+ e = strchr(s, ' ');
+ if (!e) {
+ break;
+ }
+ *e = '\0';
+ if (!strcmp(s, "a-culfw")) {
+ rdata->version = 0xffff;
+ }
}
break;
case 'E':
memcpy(&(rbuf[PAYLOAD]), resp, 16);
SET_LEN_FROM_PAYLOADLEN(rbuf, 16);
+ usleep(110000); /* Determined by a fair dice roll */
return send_hm_message(dev, rdata, rbuf);
}
}
fprintf(stderr, "\t-c device\tenable CUL-mode with CUL at path \"device\"\n");
fprintf(stderr, "\t-b bps\t\tuse CUL with speed \"bps\" (default: %u)\n", DEFAULT_CUL_BPS);
fprintf(stderr, "\t-l\t\tlower payloadlen (required for devices with little RAM, e.g. CUL v2 and CUL v4)\n");
+ fprintf(stderr, "\t-S serial\tuse HM-CFG-USB with given serial\n");
fprintf(stderr, "\t-h\t\tthis help\n");
fprintf(stderr, "\nOptional parameters for automatically sending device to bootloader\n");
fprintf(stderr, "\t-C\t\tHMID of central (3 hex-bytes, no prefix, e.g. ABCDEF)\n");
uint8_t msgid = 0x1;
uint16_t len;
struct firmware *fw;
+ char *hmcfgusb_serial = NULL;
int block;
int pfd;
int debug = 0;
printf("HomeMatic OTA flasher version " VERSION "\n\n");
- while((opt = getopt(argc, argv, "b:c:f:hls:C:D:K:")) != -1) {
+ while((opt = getopt(argc, argv, "b:c:f:hls:C:D:K:S:")) != -1) {
switch (opt) {
case 'b':
bps = atoi(optarg);
endptr += 2;
}
break;
+ case 'S':
+ hmcfgusb_serial = optarg;
+ break;
case 'h':
case ':':
case '?':
break;
}
- printf("culfw-device firmware version: %u.%02u\n",
- (rdata.version >> 8) & 0xff,
- rdata.version & 0xff);
+ printf("culfw-device firmware version: ");
+ if (rdata.version != 0xffff) {
+ printf("%u.%02u\n",
+ (rdata.version >> 8) & 0xff,
+ rdata.version & 0xff);
+ } else {
+ printf("a-culfw\n");
+ }
if (rdata.version < 0x013a) {
fprintf(stderr, "\nThis version does _not_ support firmware upgrade mode, you need at least 1.58!\n");
hmcfgusb_set_debug(debug);
- dev.hmcfgusb = hmcfgusb_init(parse_hmcfgusb, &rdata);
+ dev.hmcfgusb = hmcfgusb_init(parse_hmcfgusb, &rdata, hmcfgusb_serial);
if (!dev.hmcfgusb) {
fprintf(stderr, "Can't initialize HM-CFG-USB\n");
exit(EXIT_FAILURE);
hmcfgusb_close(dev.hmcfgusb);
}
sleep(1);
- } while (((dev.hmcfgusb = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL) || (!dev.hmcfgusb->bootloader));
+ } while (((dev.hmcfgusb = hmcfgusb_init(parse_hmcfgusb, &rdata, hmcfgusb_serial)) == NULL) || (!dev.hmcfgusb->bootloader));
}
if (dev.hmcfgusb->bootloader) {
hmcfgusb_close(dev.hmcfgusb);
}
sleep(1);
- } while (((dev.hmcfgusb = hmcfgusb_init(parse_hmcfgusb, &rdata)) == NULL) || (dev.hmcfgusb->bootloader));
+ } while (((dev.hmcfgusb = hmcfgusb_init(parse_hmcfgusb, &rdata, hmcfgusb_serial)) == NULL) || (dev.hmcfgusb->bootloader));
}
}