X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/hmcfgusb/blobdiff_plain/103d40f78446345f6f5b705139492418cf6ee953..e728a6f8c7a1ab84e411129c166cfd8d9d95e1e0:/flash-ota.c diff --git a/flash-ota.c b/flash-ota.c index 953ed34..7291e17 100644 --- a/flash-ota.c +++ b/flash-ota.c @@ -1,6 +1,6 @@ /* flasher for HomeMatic-devices supporting OTA updates * - * Copyright (c) 2014-15 Michael Gernoth + * Copyright (c) 2014-16 Michael Gernoth * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -177,6 +177,16 @@ static int parse_culfw(uint8_t *buf, int buf_len, void *data) *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': @@ -315,6 +325,7 @@ int send_hm_message(struct ota_dev *dev, struct recv_data *rdata, uint8_t *msg) 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); } } @@ -396,6 +407,7 @@ void flash_ota_syntax(char *prog) 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"); @@ -419,6 +431,7 @@ int main(int argc, char **argv) uint8_t msgid = 0x1; uint16_t len; struct firmware *fw; + char *hmcfgusb_serial = NULL; int block; int pfd; int debug = 0; @@ -430,7 +443,7 @@ int main(int argc, char **argv) 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); @@ -484,6 +497,9 @@ int main(int argc, char **argv) endptr += 2; } break; + case 'S': + hmcfgusb_serial = optarg; + break; case 'h': case ':': case '?': @@ -535,9 +551,14 @@ int main(int argc, char **argv) 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"); @@ -548,7 +569,7 @@ int main(int argc, char **argv) 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); @@ -593,7 +614,7 @@ int main(int argc, char **argv) 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) { @@ -606,7 +627,7 @@ int main(int argc, char **argv) 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)); } } @@ -660,7 +681,6 @@ int main(int argc, char **argv) if (hmid && my_hmid) { printf("Sending device with hmid %06x to bootloader\n", hmid); - out[MSGID] = msgid++; out[CTL] = 0x30; out[TYPE] = 0x11; SET_SRC(out, my_hmid); @@ -670,6 +690,7 @@ int main(int argc, char **argv) cnt = 3; do { + out[MSGID] = msgid++; if (send_hm_message(&dev, &rdata, out)) { break; }