
Originally Posted by
CTdubbin
if it's really that easy, i don't know why someone hasn't just whipped it up real quick. my only guess is those same people who could whip it up real quick already have their hand in the cookie jar (so to speak). and i'm not going to knock their hustle....
For what it's worth, here is some of my code.
It assumes the response from the ELM to a $03 request is contained in the buffer 'ELMrxstr' in the fomat '43 01 33 00 00 00 00' and the number of codes is in 'num_codes'.
At this point it only handles up to 3 stored DTC's and it does not handle the CAN format (yet).
I don't know about others, but I am always a little reluctant to post my code because I am just a hacker, so don't be too hard on me !
(I'm not sure how to use the code window, I hope it is readable. And I don't think the quote at the start from CTdubbin worked quite right?? )
Code:
if(num_codes > 0)
{
sendMODEcmd(0x03); /* request the trouble codes, wait for response */
/* --------------- first trouble code ------------------ */
MAX_goto_row_col(4,2); /* set cursor */
show_code_hdr(ELMrxstr[3]); /* 1st char of 1st code */
printf("%c", ELMrxstr[4]); /* print next char */
printf("%c", ELMrxstr[6]); /* ... and next char */
printf("%c", ELMrxstr[7]); /* ... and last char */
/* --------------- second trouble code ------------------ */
if(ELMrxstr[10] == 0x30 & ELMrxstr[12] == 0x30 & ELMrxstr[13] == 0x30); /* 000 = no code */
else
{
MAX_goto_row_col(5,2); /* set cursor */
show_code_hdr(ELMrxstr[9]); /* 1st char of 2nd code */
printf("%c", ELMrxstr[10]); /* print next char */
printf("%c", ELMrxstr[12]); /* ... and next char */
printf("%c", ELMrxstr[13]); /* ... and last char */
}
/* --------------- third trouble code ------------------ */
if(ELMrxstr[16] == 0x30 & ELMrxstr[18] == 0x30 & ELMrxstr[19] == 0x30); /* 000 = no code */
else
{
MAX_goto_row_col(6,2); /* set cursor */
show_code_hdr(ELMrxstr[15]); /* 1st char of 2nd code */
printf("%c", ELMrxstr[16]); /* print next char */
printf("%c", ELMrxstr[18]); /* ... and next char */
printf("%c", ELMrxstr[19]); /* ... and last char */
}
}
/* ----------------------------------------------------- */
// show_code_hdr()
//
// Show the first part of a trouble code.
// Pass the first byte of a trouble code to this function.
// Set cursor position before calling this function.
//
/* ----------------------------------------------------- */
void show_code_hdr(unsigned char value)
{
switch(value)
{
case 0x30: /* '0' Powertrain Code - SAE defined */
{
printf("P0");
break ;
}
case 0x31: /* '1' Powertrain Code - manufacturer defined */
{
printf("P1");
break ;
}
case 0x32: /* '2' Powertrain Code - SAE defined */
{
printf("P2");
break ;
}
case 0x33: /* '3' Powertrain Code - jointly defined */
{
printf("P3");
break ;
}
case 0x34: /* '4' Chassis Code - SAE defined */
{
printf("C0");
break ;
}
case 0x35: /* '5' Chassis Code - manufacturer defined */
{
printf("C1");
break ;
}
case 0x36: /* '6' Chassis Code - manufacturer defined */
{
printf("C2");
break ;
}
case 0x37: /* '7' Chassis Code - reserved for future */
{
printf("C3");
break ;
}
case 0x38: /* '8' Body Code - SAE defined */
{
printf("B0");
break ;
}
case 0x39: /* '9' Body Code - manufacturer defined */
{
printf("B1");
break ;
}
case 0x41: /* 'A' Body Code - manufacturer defined */
{
printf("B2");
break ;
}
case 0x42: /* 'B' Body Code - reserved for future */
{
printf("B3");
break ;
}
case 0x43: /* 'C' Network Code - SAE defined */
{
printf("U0");
break ;
}
case 0x44: /* 'D' Network Code - manufacturer defined */
{
printf("U1");
break ;
}
case 0x45: /* 'E' Network Code - manufacturer defined */
{
printf("U2");
break ;
}
case 0x46: /* 'F' Network Code - reserved for future */
{
printf("U3");
break ;
}
default: /* unrecognized */
{
printf("xx");
break ;
}
}
}
Bookmarks