X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/hmcfgusb/blobdiff_plain/70faa2739b0dbfdf06ece20ba5171b895f0000be..867564c59f3e0687e581efe822365d3ef599c76f:/hmuartlgw.c diff --git a/hmuartlgw.c b/hmuartlgw.c index 52aa2a4..9335c44 100644 --- a/hmuartlgw.c +++ b/hmuartlgw.c @@ -48,10 +48,12 @@ enum hmuartlgw_state { HMUARTLGW_ENTER_BOOTLOADER, HMUARTLGW_ENTER_BOOTLOADER_ACK, HMUARTLGW_BOOTLOADER, + HMUARTLGW_HMIP_BOOTLOADER, HMUARTLGW_ENTER_APPLICATION, HMUARTLGW_ENTER_APPLICATION_ACK, HMUARTLGW_APPLICATION, HMUARTLGW_DUAL_APPLICATION, + HMUARTLGW_HMIP_APPLICATION, }; struct recv_data { @@ -106,6 +108,12 @@ static int hmuartlgw_init_parse(enum hmuartlgw_dst dst, uint8_t *buf, int buf_le if (!strncmp(((char*)buf)+2, "DualCoPro_App", 13)) { rdata->state = HMUARTLGW_DUAL_APPLICATION; return 1; + } else if (!strncmp(((char*)buf)+2, "HMIP_TRX_App", 12)) { + rdata->state = HMUARTLGW_HMIP_APPLICATION; + return 1; + } else if (!strncmp(((char*)buf)+2, "HMIP_TRX_Bl", 11)) { + rdata->state = HMUARTLGW_HMIP_BOOTLOADER; + return 1; } } break; @@ -204,6 +212,12 @@ static int hmuartlgw_init_parse(enum hmuartlgw_dst dst, uint8_t *buf, int buf_le break; } + /* Try to query current app in case we might be in the DUAL/HMIP-Bootloader */ + if ((buf[0] == HMUARTLGW_OS_ACK) && (buf[1] == 0x03)) { + buf[0] = HMUARTLGW_DUAL_GET_APP; + hmuartlgw_send(rdata->dev, buf, 1, HMUARTLGW_DUAL); + } + return 1; } @@ -287,6 +301,7 @@ void hmuartlgw_enter_bootloader(struct hmuartlgw_dev *dev) void *cb_data_old = dev->cb_data; struct recv_data rdata = { 0 }; uint8_t buf[128] = { 0 }; + int ret; if (debug) { fprintf(stderr, "Entering bootloader\n"); @@ -300,17 +315,29 @@ void hmuartlgw_enter_bootloader(struct hmuartlgw_dev *dev) buf[0] = HMUARTLGW_OS_GET_APP; hmuartlgw_send(dev, buf, 1, HMUARTLGW_OS); do { - hmuartlgw_poll(dev, HMUARTLGW_INIT_TIMEOUT); + errno = 0; + ret = hmuartlgw_poll(dev, HMUARTLGW_INIT_TIMEOUT); + if (ret == -1 && errno == ETIMEDOUT) { + fprintf(stderr, "Communication with the module timed out, is the serial port configured correctly?\n"); + exit(1); + } } while (rdata.state == HMUARTLGW_QUERY_APPSTATE); - if (rdata.state != HMUARTLGW_BOOTLOADER) { + if ((rdata.state != HMUARTLGW_BOOTLOADER) && + (rdata.state != HMUARTLGW_HMIP_BOOTLOADER)) { rdata.dev = dev; rdata.state = HMUARTLGW_ENTER_BOOTLOADER; buf[0] = HMUARTLGW_OS_CHANGE_APP; hmuartlgw_send(dev, buf, 1, HMUARTLGW_OS); do { - hmuartlgw_poll(dev, HMUARTLGW_INIT_TIMEOUT); - } while (rdata.state != HMUARTLGW_BOOTLOADER); + errno = 0; + ret = hmuartlgw_poll(dev, HMUARTLGW_INIT_TIMEOUT); + if (ret == -1 && errno == ETIMEDOUT) { + fprintf(stderr, "Communication with the module timed out, is the serial port configured correctly?\n"); + exit(1); + } + } while ((rdata.state != HMUARTLGW_BOOTLOADER) && + (rdata.state != HMUARTLGW_HMIP_BOOTLOADER)); printf("Waiting for bootloader to settle...\n"); sleep(HMUARTLGW_SETTLE_TIME); @@ -326,6 +353,7 @@ void hmuartlgw_enter_app(struct hmuartlgw_dev *dev) void *cb_data_old = dev->cb_data; struct recv_data rdata = { 0 }; uint8_t buf[128] = { 0 }; + int ret; if (debug) { fprintf(stderr, "Entering application\n"); @@ -339,7 +367,12 @@ void hmuartlgw_enter_app(struct hmuartlgw_dev *dev) buf[0] = HMUARTLGW_OS_GET_APP; hmuartlgw_send(dev, buf, 1, HMUARTLGW_OS); do { - hmuartlgw_poll(dev, HMUARTLGW_INIT_TIMEOUT); + errno = 0; + ret = hmuartlgw_poll(dev, HMUARTLGW_INIT_TIMEOUT); + if (ret == -1 && errno == ETIMEDOUT) { + fprintf(stderr, "Communication with the module timed out, is the serial port configured correctly?\n"); + exit(1); + } } while (rdata.state == HMUARTLGW_QUERY_APPSTATE); if ((rdata.state != HMUARTLGW_APPLICATION) && @@ -349,7 +382,12 @@ void hmuartlgw_enter_app(struct hmuartlgw_dev *dev) buf[0] = HMUARTLGW_OS_CHANGE_APP; hmuartlgw_send(dev, buf, 1, HMUARTLGW_OS); do { - hmuartlgw_poll(dev, HMUARTLGW_INIT_TIMEOUT); + errno = 0; + ret = hmuartlgw_poll(dev, HMUARTLGW_INIT_TIMEOUT); + if (ret == -1 && errno == ETIMEDOUT) { + fprintf(stderr, "Communication with the module timed out, is the serial port configured correctly?\n"); + exit(1); + } } while ((rdata.state != HMUARTLGW_APPLICATION) && (rdata.state != HMUARTLGW_DUAL_APPLICATION));