#include "culfw.h"
#include "util.h"
-#define MAX_RETRIES 5
+#define MAX_RETRIES 5
+#define NORMAL_MAX_PAYLOAD 37
+#define LOWE_MAX_PAYLOAD 17
extern char *optarg;
uint32_t hmid = 0;
uint32_t my_hmid = 0;
+/* Maximum payloadlen supported by IO */
+uint32_t max_payloadlen = NORMAL_MAX_PAYLOAD;
+
enum device_type {
DEVICE_TYPE_HMCFGUSB,
DEVICE_TYPE_CULFW,
fprintf(stderr, "\nPossible options:\n");
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-h\t\tthis help\n");
}
printf("HomeMatic OTA flasher version " VERSION "\n\n");
- while((opt = getopt(argc, argv, "b:c:f:hs:")) != -1) {
+ while((opt = getopt(argc, argv, "b:c:f:hls:")) != -1) {
switch (opt) {
case 'b':
bps = atoi(optarg);
case 'f':
fw_file = optarg;
break;
+ case 'l':
+ printf("Reducing payload-len from %d to %d\n", max_payloadlen, LOWE_MAX_PAYLOAD);
+ max_payloadlen = LOWE_MAX_PAYLOAD;
+ break;
case 's':
serial = optarg;
break;
}
dev.type = DEVICE_TYPE_CULFW;
- printf("Requesting firmware-version\n");
+ printf("Requesting firmware version\n");
culfw_send(dev.culfw, "\r\n", 2);
culfw_flush(dev.culfw);
(rdata.version >> 8) & 0xff,
rdata.version & 0xff);
- if (rdata.version < 0x0139) {
- fprintf(stderr, "\nThis version does _not_ support firmware upgrade mode!\n");
+ if (rdata.version < 0x013a) {
+ fprintf(stderr, "\nThis version does _not_ support firmware upgrade mode, you need at least 1.58!\n");
exit(EXIT_FAILURE);
- } else if (rdata.version < 0x0140) {
- printf("\n*** This version probably not supports firmware upgrade mode! ***\n\n");
}
} else {
hmcfgusb_set_debug(debug);
if (!dev.hmcfgusb->bootloader) {
printf("HM-CFG-USB not in bootloader mode, entering bootloader.\n");
- hmcfgusb_enter_bootloader(dev.hmcfgusb);
printf("Waiting for device to reappear...\n");
do {
if (dev.hmcfgusb) {
+ if (!dev.hmcfgusb->bootloader)
+ hmcfgusb_enter_bootloader(dev.hmcfgusb);
hmcfgusb_close(dev.hmcfgusb);
}
sleep(1);
if (dev.hmcfgusb->bootloader) {
printf("HM-CFG-USB in bootloader mode, rebooting\n");
- hmcfgusb_leave_bootloader(dev.hmcfgusb);
do {
if (dev.hmcfgusb) {
+ if (dev.hmcfgusb->bootloader)
+ hmcfgusb_leave_bootloader(dev.hmcfgusb);
hmcfgusb_close(dev.hmcfgusb);
}
sleep(1);
first = 1;
cnt = 0;
do {
- int payloadlen = 35;
+ int payloadlen = max_payloadlen - 2;
int ack = 0;
if (first) {
- payloadlen = 37;
+ payloadlen = max_payloadlen;
first = 0;
}
switch(dev.type) {
case DEVICE_TYPE_HMCFGUSB:
hmcfgusb_close(dev.hmcfgusb);
+ hmcfgusb_exit();
break;
case DEVICE_TYPE_CULFW:
culfw_close(dev.culfw);