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

How to check state of OBD connection? #52

Open
benjaminBrownlee opened this issue Apr 7, 2018 · 1 comment
Open

How to check state of OBD connection? #52

benjaminBrownlee opened this issue Apr 7, 2018 · 1 comment

Comments

@benjaminBrownlee
Copy link

In the code there is the following function to fetch the state of the OBD:

// get connection state
virtual OBD_STATES getState() { 
      return m_state; 
}

These states also have there own variable type defined in the library:

// states
typedef enum {
    OBD_DISCONNECTED = 0,
    OBD_CONNECTING = 1,
    OBD_CONNECTED = 2,
    OBD_FAILED = 3
} OBD_STATES;

I actually have two questions here. First, how can I get the state of the OBD into a usable format? I have tried casting and comparing, as shown below, with little sucess:

boolean isConnected = obd.getState() == OBD_CONNECTED;
int state = (int) obd.getState();

Also, what is the point of making a function that returns a useless variable type? There are no built in functions to these variables that provide any utility to the user, and as far as I can see, they are fairly inconvenient (or even impossible) to get in a format that can interact with other code.

@benjaminBrownlee
Copy link
Author

Never mind, I figured it out.

Serial.write("ODB State: ");
  OBD_STATES state = obd.getState();
  if(state == OBD_DISCONNECTED) Serial.write("Disconnected");
  if(state == OBD_CONNECTING) Serial.write("Connecting");
  if(state == OBD_CONNECTED) Serial.write("Connected");
  if(state == OBD_FAILED) Serial.write("Failed");
  Serial.write("\n");

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

No branches or pull requests

1 participant