OBD Library find the right protocol

Inquiry and support for Freematics products
Post Reply
User avatar
Rafael
Posts: 2
Joined: Tue Dec 09, 2014 9:56 pm
Location: Brazil

OBD Library find the right protocol

Post 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).
stanley
Site Admin
Posts: 1029
Joined: Sat Mar 01, 2014 3:15 am

Re: OBD Library find the right protocol

Post by stanley »

Saving the protocol type in eeprom is a good idea. :-)
Post Reply