New Function For Requests With Headers (Custom PIDs)

Discussion about software developed by Freematics, including Freematics Builder and Freematics Emulator GUI
Post Reply
Posts: 5
Joined: Tue Dec 19, 2023 2:55 am

New Function For Requests With Headers (Custom PIDs)

Post by extremerotary »

I created a new function in the OBD2UART.cpp file. Stanley, can you verify that my format is correct? I believe it needs to be 'header' # 'dataMode' 'pid'. The intention is then to be able to request custom manufacturer-specific PIDs that require a header. Do you believe this will function as desired? I know you have a function to set the header via the FreematicsOBD.cpp, but since this is a different chipset with different firmware, I just want to verify that I'm on the right track and there isn't any compatibility issues with the firmware that's loaded on the OBD2UART chip. Thanks for your time!

Code: Select all

bool COBD::readPidWithHeader(byte pid, byte header, byte dataMode, int& result)
	char buffer[64];
	char* data = 0;
	sprintf(buffer, "%02X#%02X%02X\r", header, dataMode, pid);
	if (receive(buffer, sizeof(buffer)) > 0) {
		char *p = buffer;
		while ((p = strstr(p, "41 "))) {
			p += 3;
			byte curpid = hex2uint8(p);
			if (curpid == pid) {
				errors = 0;
				while (*p && *p != ' ') p++;
				while (*p == ' ') p++;
				if (*p) {
					data = p;

	if (!data) {
		result = -9999;
		return false; //was return false
		//checkErrorMessage(buffer);  // This didn't used to be here. Trying to get the error message
	result = normalizeData(pid, data);
	return true;
Post Reply