obd-raw-data-parser
Version:
A lightweight TypeScript library for parsing OBD-II raw data into human readable format. Based on the excellent work of obd-utils by Nishkalkashyap.
66 lines (65 loc) • 2.61 kB
JavaScript
import { DTCBaseDecoder } from "../index.js";
describe("DTC Multi-Frame Tests", () => {
const baseConfig = {
logPrefix: "TEST",
};
describe("Multi-Frame Parsing", () => {
test("should handle split DTCs across frames", () => {
const decoder = new DTCBaseDecoder({
...baseConfig,
isCan: true,
serviceMode: "03",
troubleCodeType: "CURRENT",
});
const response = [
// First frame with partial DTC
[],
// Second frame with rest of the DTC
[],
[]
];
const result = decoder.decodeDTCs(response);
expect(result).toEqual(["P0101", "P0113"]);
});
test("should handle leftover bytes between frames", () => {
const decoder = new DTCBaseDecoder({
...baseConfig,
isCan: true,
serviceMode: "07",
troubleCodeType: "PENDING",
});
const response = [
// First frame with odd number of bytes
[],
// Second frame should handle leftover byte
[],
[]
];
const result = decoder.decodeDTCs(response);
expect(result).toEqual(["P0101", "P0113", "U114B", "U115B"]);
});
test("should handle frame sequence interruptions", () => {
const decoder = new DTCBaseDecoder({
...baseConfig,
isCan: true,
serviceMode: "03",
troubleCodeType: "CURRENT",
});
const response = [
// Start of sequence
[],
// Interrupting NO DATA frame
[],
// Continue sequence
[],
[]
];
const result = decoder.decodeDTCs(response);
// Should ignore NO DATA frame and continue processing
expect(result).toEqual([
"P0101", "P0113",
"U114B", "U115B", "U115E"
]);
});
});
});