Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HID++ error data and non-long errors #24

Merged
merged 2 commits into from
Aug 27, 2021

Conversation

mrubli2
Copy link
Contributor

@mrubli2 mrubli2 commented Aug 17, 2021

This fixes a bug that we previously talked about in #12 (comment) and adds a small feature to allow client applications to read the error bytes that HID++ errors can contain (quite helpful to retrieve details about the errors for certain HID++ functions).

The two commits are unrelated, so they could be separated if desired.

Martin Rubli added 2 commits August 17, 2021 16:04
Some HID++ 2.0 features return error data as part of an error report. Make this
available to applications.
--offset;
*error_data = { _data.data() + 6, _data.data() + offset + 1 }; // Copy the error data
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like this should be a standard algorithm. But I don't know which one. The best I can come up with is:

auto begin = _data.begin() + 6;
auto end = std::find_if(std::make_reverse_iterator(_data.end()), std::make_reverse_iterator(begin), [](int v){return v != 0;}).base();    // Look for the last non-zero byte
error_data->assign(begin, end);

But it is not really readable. I guess your version is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember starting off searching for a standard algorithm solution and ended up deciding that the loop was a lot more readable. 😄

@cvuchener
Copy link
Owner

OK, this looks good but I have one question. On what does the presence and the format of the extra data depends? Is it the protocol version? Or the function being called? (the underlying question being: who should be responsible for parsing the data?)

@cvuchener cvuchener merged commit b334cbd into cvuchener:master Aug 27, 2021
@mrubli2
Copy link
Contributor Author

mrubli2 commented Sep 2, 2021

Sorry for the delay! The extra data depends purely on the function. Most functions don't give any extra data but some might, in which case the feature code needs to decode it.

I can't share the full spec for that feature just yet but here's an excerpt from an upcoming feature that should help illustrate how functions might specify the error behavior:

This function may return standard HID++ 2.0 error codes.

In order to assist with debugging additional error data may optionally be included in the error response’s data bytes. Such information appears in the form of short non-zero-terminated ASCII strings. In the case of short reports the additional error data may be truncated to a single byte.

Possible errors include:

NOT_ALLOWED if levels are not supported for this control.

INVALID_ARGUMENT with "T" if the level type (linear or non-linear) implied by the linear flag is not supported.

INVALID_ARGUMENT with "D" if the payload data is too short.

INVALID_ARGUMENT with "MMR" if the conditions on the control’s min, max, or res restrictions are violated.

In this case the extra error data not only shows up nicely in the USB analyzer but the client code can turn it into a more meaningful message.

@mrubli2 mrubli2 deleted the feature/error-data branch September 2, 2021 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants