diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c index 719ca64..4de3fa9 100644 --- a/src/suunto_eonsteel.c +++ b/src/suunto_eonsteel.c @@ -565,23 +565,8 @@ initialize_eonsteel(suunto_eonsteel_device_t *eon) { dc_status_t rc = DC_STATUS_SUCCESS; const unsigned char init[] = {0x02, 0x00, 0x2a, 0x00}; - unsigned char buf[64]; struct eon_hdr hdr; - dc_iostream_set_timeout(eon->iostream, 10); - - /* Get rid of any pending stale input first */ - for (;;) { - size_t transferred = 0; - rc = dc_iostream_read(eon->iostream, buf, sizeof(buf), &transferred); - if (rc != DC_STATUS_SUCCESS) - break; - if (!transferred) - break; - } - - dc_iostream_set_timeout(eon->iostream, 5000); - rc = send_cmd(eon, CMD_INIT, sizeof(init), init); if (rc != DC_STATUS_SUCCESS) { ERROR(eon->base.context, "Failed to send initialization command"); @@ -634,6 +619,12 @@ suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, unsigned i goto error_free; } + status = dc_iostream_set_timeout(eon->iostream, 5000); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to set the timeout."); + goto error_close; + } + status = initialize_eonsteel(eon); if (status != DC_STATUS_SUCCESS) { ERROR(context, "unable to initialize device");