Page 1 of 1

OBD Library find the right protocol

Posted: Tue Dec 09, 2014 11:09 pm
by Rafael
Hi,

In OBD.cpp:

Code: Select all

bool COBD::setProtocol(OBD_PROTOCOLS h)
{
    char buf[OBD_RECV_BUF_SIZE];
   if (h == PROTO_AUTO) {
      write("ATSP00\r");
   } else {
      sprintf(buf, "ATSP%d\r", h);
      write(buf);
   }
   if (receive(buf, 3000) > 0 && strstr(buf, "OK"))
        return true;
    else
        return false;
}


Maybe if the code can find the right protocol and store it in the eeprom?

Something like this:

Code: Select all

bool COBD::setProtocol(OBD_PROTOCOLS h)
{
    int p = 0;
    char buf[OBD_RECV_BUF_SIZE];

    while(!strstr(buf, "OK") && p < 10)
    {
         sprintf(buf, "ATSP%d\r", p);
    write(buf);
    }
   
   if (receive(buf, 3000) > 0 && strstr(buf, "OK") && p < 10)
   {
        EEPROM.write(0, p);
        return true;
   }
    else
        return false;
}


Of course, if found, can print in somewhere place the protocol... If not, other message to alert that the adapter is not compatible or not connected.

Store in eeprom, can prevent this can each time... Or if an error, run this scan and store it again (change the car).

Re: OBD Library find the right protocol

Posted: Sat Dec 20, 2014 8:40 pm
by stanley
Saving the protocol type in eeprom is a good idea. :-)