/* flasher for HM-MOD-UART
*
- * Copyright (c) 2016 Michael Gernoth <michael@gernoth.net>
+ * Copyright (c) 2016-17 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
memset(&rdata, 0, sizeof(rdata));
+ printf("\nInitializing HM-MOD-UART...\n");
+
dev = hmuart_init(uart, parse_hmuartlgw, &rdata, 0);
if (!dev) {
fprintf(stderr, "Can't initialize HM-MOD-UART\n");
exit(EXIT_FAILURE);
}
- printf("\nHM-MOD-UART opened.\n\n");
+ printf("HM-MOD-UART opened.\n\n");
printf("Flashing %d blocks", fw->fw_blocks);
if (debug) {
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");
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) {
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_BOOTLOADER);
printf("Waiting for bootloader to settle...\n");
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");
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) &&
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));