// callback to spit out contents of CAN receive frame
void can_sniff_RX(const CAN_message_t &msg)
{
if (CAN_RX_mode != CAN_RX_MODE_ISOTP_ONLY)
{
Serial.print("RX: ");
status_append_without_NL("RX: ");
Serial.print("MBX: ");
status_append_without_NL("MBX: ");
if (msg.mb < 10)
{
Serial.print("0");
status_append_without_NL("0");
} else {
status_append_without_NL((char)((msg.mb / 10) + '0'));
}
status_append_without_NL((char)((msg.mb % 10) + '0'));
Serial.print(msg.mb);
Serial.print(" LEN: ");
status_append_without_NL(" LEN: ");
if (msg.len < 100)
{
Serial.print(" ");
status_append_without_NL(" ");
} else {
status_append_without_NL((char)((msg.len / 100) + '0'));
}
if (msg.len < 10)
{
Serial.print(" ");
status_append_without_NL(" ");
} else {
status_append_without_NL((char)(((msg.len / 10) % 10) + '0'));
}
status_append_without_NL((char)((msg.len % 10) + '0'));
Serial.print(msg.len);
Serial.print(" EXT: ");
status_append_without_NL(" EXT: ");
Serial.print(msg.flags.extended);
status_append_without_NL((char)(msg.flags.extended + '0'));
Serial.print(" TS: ");
status_append_without_NL(" TS: ");
if (msg.timestamp < 10000)
{
Serial.print(" ");
status_append_without_NL(" ");
} else {
status_append_without_NL((char)((msg.len / 10000) + '0'));
}
if (msg.timestamp < 1000)
{
Serial.print(" ");
status_append_without_NL(" ");
} else {
status_append_without_NL((char)(((msg.len / 1000) % 10) + '0'));
}
if (msg.timestamp < 100)
{
Serial.print(" ");
status_append_without_NL(" ");
} else {
status_append_without_NL((char)(((msg.len / 100) % 10) + '0'));
}
if (msg.timestamp < 10)
{
Serial.print(" ");
status_append_without_NL(" ");
} else {
status_append_without_NL((char)(((msg.len / 10) % 10) + '0'));
}
status_append_without_NL((char)((msg.timestamp % 10) + '0'));
Serial.print(msg.timestamp);
Serial.print(" ID: 0x");
status_append_without_NL(" ID: 0x");
uint32_t i = 0xF0000000;
for (int j = 7; j >= 0; j--)
{
Serial.print(((msg.id & i) >> (4 * j)), HEX);
if (((msg.id & i) >> (4 * j)) <= 9)
{
status_append_without_NL((char)(((msg.id & i) >> (4 * j)) + '0'));
} else {
status_append_without_NL((char)((((msg.id & i) >> (4 * j)) - 10) + 'A'));
}
i = i >> 4;
}
Serial.print(" OVERRUN: ");
status_append_without_NL(" OVERRUN: ");
Serial.println(msg.flags.overrun);
status_append_with_NL((char)(msg.flags.overrun + '0'));
Serial.print(" MSG: ");
status_append_without_NL(" MSG: ");
for ( uint8_t i = 0; i < msg.len; i++ ) {
Serial.print("0x");
status_append_without_NL("0x");
Serial.print((msg.buf[i] & 0xF0) >> 4, HEX);
if (((msg.buf[i] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[i] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[i] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[i] & 0x0F, HEX);
if ((msg.buf[i] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[i] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[i] & 0x0F) - 10) + 'A'));
}
Serial.print(" ");
status_append_without_NL(" ");
}
Serial.println("");
status_append_with_NL("");
LED_timer = millis();
analogWrite(LED_PIN, led_intensity_on);
CAN_baudrate_match_found = true;
CAN_baudrate_match_timeout = millis();
if (CAN_baudrate_mode == CAN_BAUDRATE_MODE_HUNT_AND_STOP)
{
CAN_baudrate_mode = CAN_BAUDRATE_MODE_FIXED;
report_current_baudrate();
// save settings to EEPROM
save_settings();
}
}
if (msg.buf[0] <= 0x07)
{
if (CAN_RX_mode != CAN_RX_MODE_ISOTP_ONLY)
{
switch (msg.buf[1])
{
case 0x41:
case 0x42:
{
if (msg.buf[1] == 0x41)
{
Serial.println(" 0x41: service 0x01 (Show current data) request response");
status_append_with_NL(" 0x41: service 0x01 (Show current data) request response");
}
if (msg.buf[1] == 0x42)
{
Serial.println(" 0x42: service 0x02 (Show freeze frame data) request response");
status_append_with_NL(" 0x42: service 0x02 (Show freeze frame data) request response");
}
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((msg.buf[2] & 0xF0) >> 4, HEX);
if (((msg.buf[2] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[2] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[2] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[2] & 0x0F, HEX);
if ((msg.buf[2] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[2] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[2] & 0x0F) - 10) + 'A'));
}
Serial.print(": PID 0x");
status_append_without_NL(": PID 0x");
Serial.print((msg.buf[2] & 0xF0) >> 4, HEX);
if (((msg.buf[2] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[2] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[2] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[2] & 0x0F, HEX);
if ((msg.buf[2] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[2] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[2] & 0x0F) - 10) + 'A'));
}
Serial.print(" - ");
status_append_without_NL(" - ");
decode_service_01_02_PID_title(STATUS_MODE, msg.buf[1], msg.buf[2]);
Serial.println("");
status_append_with_NL("");
decode_service_01_02_PID_content(msg);
Serial.println("");
status_append_with_NL("");
}
break;
case 0x43:
{
Serial.println(" 0x43: service 0x03 (list DTCs) request response");
status_append_with_NL(" 0x43: service 0x03 (list DTCs) request response");
Serial.println("");
status_append_with_NL("");
}
break;
case 0x44:
{
Serial.println(" 0x44: service 0x04 (clear DTCs) request response");
status_append_with_NL(" 0x44: service 0x04 (clear DTCs) request response");
Serial.println("");
status_append_with_NL("");
}
break;
case 0x49:
{
Serial.println(" 0x49: service 0x09 (vehicle info) request response");
status_append_with_NL(" 0x49: service 0x09 (vehicle info) request response");
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((msg.buf[2] & 0xF0) >> 4, HEX);
if (((msg.buf[2] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[2] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[2] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[2] & 0x0F, HEX);
if ((msg.buf[2] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[2] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[2] & 0x0F) - 10) + 'A'));
}
Serial.print(": PID 0x");
status_append_without_NL(": PID 0x");
Serial.print((msg.buf[2] & 0xF0) >> 4, HEX);
if (((msg.buf[2] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[2] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[2] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[2] & 0x0F, HEX);
if ((msg.buf[2] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[2] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[2] & 0x0F) - 10) + 'A'));
}
Serial.print(" - ");
status_append_without_NL(" - ");
decode_service_09_PID_title(STATUS_MODE, msg.buf[2]);
Serial.println("");
status_append_with_NL("");
decode_service_09_PID_content(msg);
Serial.println("");
status_append_with_NL("");
}
break;
case 0x50:
{
Serial.println(" 0x50: service 0x10 (CAN diagnostic session) request response");
status_append_with_NL(" 0x50: service 0x10 (CAN diagnostic session) request response");
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((msg.buf[2] & 0xF0) >> 4, HEX);
if (((msg.buf[2] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[2] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[2] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[2] & 0x0F, HEX);
if ((msg.buf[2] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[2] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[2] & 0x0F) - 10) + 'A'));
}
Serial.print(": PID 0x");
status_append_without_NL(": PID 0x");
Serial.print((msg.buf[2] & 0xF0) >> 4, HEX);
if (((msg.buf[2] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[2] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[2] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[2] & 0x0F, HEX);
if ((msg.buf[2] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[2] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[2] & 0x0F) - 10) + 'A'));
}
Serial.print(" - ");
status_append_without_NL(" - ");
if (msg.buf[2] == 0x03)
{
Serial.print("Extended CAN diagnostic session");
status_append_without_NL("Extended CAN diagnostic session");
} else {
Serial.print("unexpected PID");
status_append_without_NL("unexpected PID");
}
Serial.println("");
status_append_with_NL("");
}
break;
case 0x7F:
{
Serial.println(" 0x7F: CAN service request - NAK response");
status_append_with_NL(" 0x7F: CAN service request - NAK response");
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((msg.buf[2] & 0xF0) >> 4, HEX);
if (((msg.buf[2] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[2] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[2] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[2] & 0x0F, HEX);
if ((msg.buf[2] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[2] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[2] & 0x0F) - 10) + 'A'));
}
Serial.println(" (service number requested)");
status_append_with_NL(" (service number requested)");
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((msg.buf[3] & 0xF0) >> 4, HEX);
if (((msg.buf[3] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[3] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[3] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[3] & 0x0F, HEX);
if ((msg.buf[3] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[3] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[3] & 0x0F) - 10) + 'A'));
}
Serial.println(" (?? additional data)");
status_append_with_NL(" (?? additional data)");
Serial.println("");
status_append_with_NL("");
}
break;
default:
{
Serial.println("");
status_append_with_NL("");
}
break;
}
Serial.println("");
status_append_with_NL("");
}
} else {
switch (msg.buf[0])
{
case 0x10:
{
send_CAN_isotp_flow_control();
if (CAN_RX_mode != CAN_RX_MODE_ISOTP_ONLY)
{
switch (msg.buf[2])
{
case 0x41:
case 0x42:
case 0x49:
{
if (msg.buf[2] == 0x41)
{
Serial.println(" 0x41: service 0x01 (Show current data) request response");
status_append_with_NL(" 0x41: service 0x01 (Show current data) request response");
}
if (msg.buf[2] == 0x42)
{
Serial.println(" 0x42: service 0x02 (Show freeze frame data) request response");
status_append_with_NL(" 0x42: service 0x02 (Show freeze frame data) request response");
}
if (msg.buf[2] == 0x49)
{
Serial.println(" 0x49: service 0x09 (vehicle info) request response");
status_append_with_NL(" 0x49: service 0x09 (vehicle info) request response");
}
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((msg.buf[2] & 0xF0) >> 4, HEX);
if (((msg.buf[2] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[2] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[2] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[2] & 0x0F, HEX);
if ((msg.buf[2] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[2] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[2] & 0x0F) - 10) + 'A'));
}
Serial.print(": PID 0x");
status_append_without_NL(": PID 0x");
Serial.print((msg.buf[3] & 0xF0) >> 4, HEX);
if (((msg.buf[3] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((msg.buf[3] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((msg.buf[3] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(msg.buf[3] & 0x0F, HEX);
if ((msg.buf[3] & 0x0F) <= 9)
{
status_append_without_NL((char)((msg.buf[3] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((msg.buf[3] & 0x0F) - 10) + 'A'));
}
Serial.print(" - ");
status_append_without_NL(" - ");
if ((msg.buf[2] == 0x41) || (msg.buf[2] == 0x42))
{
decode_service_01_02_PID_title(STATUS_MODE, msg.buf[2], msg.buf[3]);
}
if (msg.buf[2] == 0x49)
{
decode_service_09_PID_title(STATUS_MODE, msg.buf[3]);
}
Serial.println("");
status_append_with_NL("");
}
break;
default:
{
Serial.println("");
status_append_with_NL("");
}
break;
}
}
}
break;
default:
{
if (CAN_RX_mode != CAN_RX_MODE_ISOTP_ONLY)
{
Serial.println("");
status_append_with_NL("");
}
}
break;
}
if (CAN_RX_mode != CAN_RX_MODE_ISOTP_ONLY)
{
Serial.println("");
status_append_with_NL("");
}
}
if (CAN_RX_mode != CAN_RX_MODE_ISOTP_ONLY)
{
check_status_update_time = millis();
status_update_required = true;
}
} // can_sniff_RX()
// callback to spit out contents of CAN ISOTP receive frame
void can_sniff_RX_isotp(const ISOTP_data &config, const uint8_t *buf)
{
if (CAN_RX_mode != CAN_RX_MODE_STD_ONLY)
{
Serial.print("RX: (isotp)");
status_append_without_NL("RX: (isotp)");
Serial.print(" LEN: ");
status_append_without_NL(" LEN: ");
if (config.len < 100)
{
Serial.print(" ");
status_append_without_NL(" ");
} else {
status_append_without_NL((char)(((config.len / 100) % 10) + '0'));
}
if (config.len < 10)
{
Serial.print(" ");
status_append_without_NL(" ");
} else {
status_append_without_NL((char)(((config.len / 10) % 10) + '0'));
}
Serial.print(config.len);
status_append_without_NL((char)((config.len % 10) + '0'));
Serial.print(" EXT: ");
status_append_without_NL(" EXT: ");
Serial.print(config.flags.extended);
status_append_without_NL((char)(config.flags.extended + '0'));
Serial.print(" ID: 0x");
status_append_without_NL(" ID: 0x");
uint32_t i = 0xF0000000;
for (int j = 7; j >= 0; j--)
{
Serial.print(((config.id & i) >> (4 * j)), HEX);
if (((config.id & i) >> (4 * j)) <= 9)
{
status_append_without_NL((char)(((config.id & i) >> (4 * j)) + '0'));
} else {
status_append_without_NL((char)((((config.id & i) >> (4 * j)) - 10) + 'A'));
}
i = i >> 4;
}
Serial.println("");
status_append_with_NL("");
Serial.print(" MSG: ");
status_append_without_NL(" MSG: ");
for (int i = 0; i < config.len; i++) {
Serial.print("0x");
status_append_without_NL("0x");
Serial.print((buf[i] & 0xF0) >> 4, HEX);
if (((buf[i] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[i] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[i] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[i] & 0x0F, HEX);
if ((buf[i] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[i] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[i] & 0x0F) - 10) + 'A'));
}
if ((i != 0) && ((i % 8) == 0))
{
Serial.println("");
status_append_with_NL("");
Serial.print(" ");
status_append_without_NL(" ");
} else {
Serial.print(" ");
status_append_without_NL(" ");
}
}
Serial.println("");
status_append_with_NL("");
LED_timer = millis();
analogWrite(LED_PIN, led_intensity_on);
CAN_baudrate_match_found = true;
CAN_baudrate_match_timeout = millis();
if (CAN_baudrate_mode == CAN_BAUDRATE_MODE_HUNT_AND_STOP)
{
CAN_baudrate_mode = CAN_BAUDRATE_MODE_FIXED;
report_current_baudrate();
// save settings to EEPROM
save_settings();
}
switch (buf[0])
{
case 0x41:
case 0x42:
{
if (buf[0] == 0x41)
{
Serial.println(" 0x41: service 0x01 (Show current data) request response - isotp frame");
status_append_with_NL(" 0x41: service 0x01 (Show current data) request response - isotp frame");
}
if (buf[0] == 0x42)
{
Serial.println(" 0x42: service 0x02 (Show freeze frame data) request response - isotp frame");
status_append_with_NL(" 0x42: service 0x02 (Show freeze frame data) request response - isotp frame");
}
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((buf[1] & 0xF0) >> 4, HEX);
if (((buf[1] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[1] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[1] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[1] & 0x0F, HEX);
if ((buf[0] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[1] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[1] & 0x0F) - 10) + 'A'));
}
Serial.print(": PID 0x");
status_append_without_NL(": PID 0x");
Serial.print((buf[1] & 0xF0) >> 4, HEX);
if (((buf[1] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[1] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[1] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[1] & 0x0F, HEX);
if ((buf[1] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[1] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[1] & 0x0F) - 10) + 'A'));
}
Serial.print(" - ");
status_append_without_NL(" - ");
decode_service_01_02_PID_title(STATUS_MODE, buf[0], buf[1]);
Serial.println("");
status_append_with_NL("");
decode_isotp_service_01_PID_content(config.len, buf);
Serial.println("");
status_append_with_NL("");
}
break;
case 0x43:
{
Serial.println(" 0x43: service 0x03 (list DTCs) request response - isotp frame");
status_append_with_NL(" 0x43: service 0x03 (list DTCs) request response - isotp frame");
Serial.println("");
status_append_with_NL("");
}
break;
case 0x44:
{
Serial.println(" 0x44: service 0x04 (clear DTCs) request response - isotp frame");
status_append_with_NL(" 0x44: service 0x04 (clear DTCs) request response - isotp frame");
Serial.println("");
status_append_with_NL("");
}
break;
case 0x49:
{
Serial.println(" 0x49: service 0x09 (vehicle info) request response - isotp frame");
status_append_with_NL(" 0x49: service 0x09 (vehicle info) request response - isotp frame");
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((buf[1] & 0xF0) >> 4, HEX);
if (((buf[1] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[1] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[1] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[1] & 0x0F, HEX);
if ((buf[1] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[1] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[1] & 0x0F) - 10) + 'A'));
}
Serial.print(": PID 0x");
status_append_without_NL(": PID 0x");
Serial.print((buf[1] & 0xF0) >> 4, HEX);
if (((buf[1] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[1] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[1] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[1] & 0x0F, HEX);
if ((buf[1] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[1] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[1] & 0x0F) - 10) + 'A'));
}
Serial.print(" - ");
status_append_without_NL(" - ");
decode_service_09_PID_title(STATUS_MODE, buf[1]);
Serial.println("");
status_append_with_NL("");
decode_isotp_service_09_PID_content(config.len, buf);
Serial.println("");
status_append_with_NL("");
}
break;
case 0x50:
{
Serial.println(" 0x50: service 0x10 (CAN diagnostic session) request response - isotp frame");
status_append_with_NL(" 0x50: service 0x10 (CAN diagnostic session) request response - isotp frame");
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((buf[1] & 0xF0) >> 4, HEX);
if (((buf[1] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[1] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[1] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[1] & 0x0F, HEX);
if ((buf[1] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[1] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[1] & 0x0F) - 10) + 'A'));
}
Serial.print(": PID 0x");
status_append_without_NL(": PID 0x");
Serial.print((buf[1] & 0xF0) >> 4, HEX);
if (((buf[1] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[1] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[1] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[1] & 0x0F, HEX);
if ((buf[1] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[1] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[1] & 0x0F) - 10) + 'A'));
}
Serial.print(" - ");
status_append_without_NL(" - ");
if (buf[1] == 0x03)
{
Serial.print("Extended CAN diagnostic session");
status_append_without_NL("Extended CAN diagnostic session");
} else {
Serial.print("unexpected PID");
status_append_without_NL("unexpected PID");
}
Serial.println("");
status_append_with_NL("");
}
break;
case 0x7F:
{
Serial.println(" 0x7F: CAN service request - NAK response - isotp frame");
status_append_with_NL(" 0x7F: CAN service request - NAK response - isotp frame");
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((buf[1] & 0xF0) >> 4, HEX);
if (((buf[1] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[1] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[1] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[1] & 0x0F, HEX);
if ((buf[1] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[1] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[1] & 0x0F) - 10) + 'A'));
}
Serial.println(" (service number requested)");
status_append_with_NL(" (service number requested)");
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((buf[2] & 0xF0) >> 4, HEX);
if (((buf[2] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[2] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[2] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[2] & 0x0F, HEX);
if ((buf[2] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[2] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[2] & 0x0F) - 10) + 'A'));
}
Serial.println(" (?? additional data)");
status_append_with_NL(" (?? additional data)");
Serial.println("");
status_append_with_NL("");
}
break;
default:
{
Serial.print(" 0x");
status_append_without_NL(" 0x");
Serial.print((buf[0] & 0xF0) >> 4, HEX);
if (((buf[0] & 0xF0) >> 4) <= 9)
{
status_append_without_NL((char)(((buf[0] & 0xF0) >> 4) + '0'));
} else {
status_append_without_NL((char)((((buf[0] & 0xF0) >> 4) - 10) + 'A'));
}
Serial.print(buf[0] & 0x0F, HEX);
if ((buf[0] & 0x0F) <= 9)
{
status_append_without_NL((char)((buf[0] & 0x0F) + '0'));
} else {
status_append_without_NL((char)(((buf[0] & 0x0F) - 10) + 'A'));
}
Serial.println(": unexpected isotp CAN service request response");
status_append_with_NL(": unexpected isotp CAN service request response");
Serial.println("");
status_append_with_NL("");
}
break;
}
check_status_update_time = millis();
status_update_required = true;
}
} // can_sniff_RX_isotp()