Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions examples/htool_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,32 @@ int htool_console_run(struct libhoth_device* dev,
bool quit = false;

while (!quit) {
// Any previous failure should reset all of the USB state before retrying
while (status != LIBHOTH_OK) {
status = libhoth_device_reconnect(dev);
// If USB is down we might fail reconnect, just retry
}
// Give an opportunity for other clients to use the interface.
libhoth_release_device(dev);
usleep(1000 * opts->yield_ms);
status = libhoth_claim_device(dev, 1000 * 1000 * opts->claim_timeout_secs);
if (status != LIBHOTH_OK) {
// If USB is down we might fail claim, just go back and retry
continue;
}

status = libhoth_read_console(dev, STDOUT_FILENO, false, opts->channel_id,
&offset);
if (status != LIBHOTH_OK) {
break;
// Device resets cause failures, just loop and allow reconnection
continue;
}

status = libhoth_write_console(dev, opts->channel_id, opts->force_drive_tx,
&quit);
if (status != LIBHOTH_OK) {
break;
}

libhoth_release_device(dev);

// Give an opportunity for other clients to use the interface.
usleep(1000 * opts->yield_ms);

status = libhoth_claim_device(dev, 1000 * 1000 * opts->claim_timeout_secs);
if (status != LIBHOTH_OK) {
break;
// Device resets cause failures, just loop and allow reconnection
continue;
}
}

Expand Down
4 changes: 4 additions & 0 deletions protocol/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ int libhoth_read_console(struct libhoth_device* dev, int fd,
if (status != 0) {
return status;
}
if (req.offset != resp.resp.offset) {
fprintf(stderr, "Console jumped forward %u bytes\n",
resp.resp.offset - req.offset);
}

int len = response_size - sizeof(resp.resp);
if (len > 0) {
Expand Down
Loading