So I made an OBD2 reader and it works smoothly for both CAN 11/500 and CAN 29/500. But not always, when I was testing a Honda Accord my CAN detection logic failed (CAN 29/500 found through ELM scanner).
CAN_Detection() - set request ID and response ID for 11bit CAN - GetPid(ENGINE_RPM, &buffer) - if we receive RPM and RPM greater than 0 then protocol = CAN11
If failed - set request ID and response ID for 29bit CAN - GetPid(ENGINE_RPM, &buffer) - if we receive RPM and RPM greater than 0 then protocol = CAN29
While debugging I noticed that I was receiving a different pid as my response, for example when I request for RPM (0x0c) I get 0x0D (speed), and according to my logic, I'm verifying if the pid I requested and the pid received are the same. But it's not like I don't get RPM, I do get it after an offset of about 4 readings. I know if I change this and have a different approach to check for CAN my problem will be sorted, but I was wondering why I was getting an offset value.