Code:
int render_obdheader(char *buf, size_t buflen, struct obdiiprotocol *proto,
struct obdgen_ecu *ecu, unsigned int messagelen, int spaces) {
unsigned int ecuaddress; //< The calculated address of this ecu
unsigned int segments[4]; //< If the address needs to be split up
switch(proto->headertype) {
case OBDHEADER_J1850PWM:
ecuaddress = ecu->ecu_num + 0x10;
return snprintf(buf, buflen, "41%s6B%s%02X%s",
spaces?" ":"",
spaces?" ":"",
ecuaddress, spaces?" ":"");
break;
case OBDHEADER_J1850VPW: // also ISO 9141-2
ecuaddress = ecu->ecu_num + 0x10;
return snprintf(buf, buflen, "48%s6B%s%02X%s",
spaces?" ":"",
spaces?" ":"",
ecuaddress, spaces?" ":"");
break;
case OBDHEADER_14230:
ecuaddress = ecu->ecu_num + 0x10;
return snprintf(buf, buflen, "%02X%sF1%s%02X%s",
(unsigned)0b10000000 | messagelen, spaces?" ":"",
spaces?" ":"",
ecuaddress, spaces?" ":"");
break;
case OBDHEADER_CAN29:
ecuaddress = ecu->ecu_num + 0x18DAF110;
segments[0] = (ecuaddress >> 24) & 0xFF;
segments[1] = (ecuaddress >> 16) & 0xFF;
segments[2] = (ecuaddress >> 8) & 0xFF;
segments[3] = (ecuaddress >> 0) & 0xFF;
return snprintf(buf, buflen, "%02X%s%02X%s%02X%s%02X%s%02X%s",
segments[0], spaces?" ":"",
segments[1], spaces?" ":"",
segments[2], spaces?" ":"",
segments[3], spaces?" ":"",
messagelen, spaces?" ":"");
break;
case OBDHEADER_CAN11:
ecuaddress = ecu->ecu_num + 0x7E8;
return snprintf(buf, buflen, "%03X%s%02X%s",
ecuaddress, spaces?" ":"",
messagelen, spaces?" ":"");
break;
case OBDHEADER_NULL:
default:
return 0;
break;
}
return snprintf(buf, buflen, "UNKNOWN%s", spaces?" ":"");
}
Any thoughts would be welcome,
Bookmarks