UNPKG

obd-raw-data-parser

Version:

A React Native hook library to manage Bluetooth Low Energy connections and communication with ELM327 OBD-II adapters.

2 lines 1.19 kB
Object.defineProperty(exports,"__esModule",{value:true});exports.decToDTC=decToDTC;exports.hexToDTC=hexToDTC;var DTC_CATEGORIES={0:'P',1:'C',2:'B',3:'U'};function extractBits(binary,start,length){return binary.substring(start-1,start-1+length);}function hexToDTC(hexValue){hexValue=hexValue.padStart(4,'0').toUpperCase();var fullBinary=parseInt(hexValue,16).toString(2).padStart(16,'0');var categoryBits=extractBits(fullBinary,1,2);var firstDigitBits=extractBits(fullBinary,3,2);var secondDigitBits=extractBits(fullBinary,5,4);var thirdDigitBits=extractBits(fullBinary,9,4);var fourthDigitBits=extractBits(fullBinary,13,4);var category=DTC_CATEGORIES[parseInt(categoryBits,2)];var firstDigit=parseInt(firstDigitBits,2).toString(16).toUpperCase();var secondDigit=parseInt(secondDigitBits,2).toString(16).toUpperCase();var thirdDigit=parseInt(thirdDigitBits,2).toString(16).toUpperCase();var fourthDigit=parseInt(fourthDigitBits,2).toString(16).toUpperCase();return`${category}${firstDigit}${secondDigit}${thirdDigit}${fourthDigit}`;}function decToDTC(decValue){var hexValue=decValue.toString(16).padStart(4,'0').toUpperCase();return hexToDTC(hexValue);} //# sourceMappingURL=dtcConverter.js.map