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

Add feature: Output human readable error codes #4

Open
dave992 opened this issue Dec 16, 2019 · 4 comments
Open

Add feature: Output human readable error codes #4

dave992 opened this issue Dec 16, 2019 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@dave992
Copy link
Member

dave992 commented Dec 16, 2019

Originally added by @rtonnaer:

The Micro-Epsilon SDK outputs numerical error codes that are explained in the SDK Manual. The driver should output the error code with a text message containing the explanation in the SDK manual.

@gavanderhoorn I intend to make a translator function that translates a numerical value into a numerical value + text string. Is there a C++ structure (e.g. an error code function) that I should use.


Response by @gavanderhoorn :

These sort of things are typically done using either a map (which maps int to std::string), or even just a simple switch:

switch(error_code)
{
  ...

  case 302:
    return "Sensor is already connected";

  ...

  default:
    return "Unknown error code (please report)";
}

You could wrap this in a function which takes the error code and returns a std::string.

@dave992 dave992 added the enhancement New feature or request label Dec 16, 2019
@dave992
Copy link
Member Author

dave992 commented Dec 16, 2019

For the 0.2.0 version of the API (as used by this driver):
C++-Linux-InterfaceDocumentation.pdf

@rtonnaer
Copy link
Contributor

@dave992 I created a feature branch and (very naively) just started to make a function in driver.cpp. The function is not a member of "scancontrol_driver::ScanControlDriver".

How to proceed, in general I want to:

  1. define a function that returns a string does this work: std::string function_name(arg,arg1){ }
  2. as a test: call this function directly as a first thing in the driver. As I want to test without sensor....

@dave992
Copy link
Member Author

dave992 commented Dec 16, 2019

  1. That prototype is nearly correct, the definition also needs the type of the input, in this case, an int or a derivative thereof, e.g:
std::string function_name(int error_code)
{
    std::string error_string;
    ....
    return error_string;
}
  1. To test the function you do not need the driver, so calling your function at the beginning of main() should be okay for testing purposes. When it works you can move it to the correct place(s) in the driver code.

@gavanderhoorn
Copy link
Member

1. To test the function you do not need the driver, so calling your function at the beginning of main() should be okay for testing purposes

suggestion: write an actual test and integrate it with the regular rostest framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants