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 2.86 kB
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"DTCBaseDecoder",{enumerable:true,get:function get(){return _DTCBaseDecoder.DTCBaseDecoder;}});Object.defineProperty(exports,"VinDecoder",{enumerable:true,get:function get(){return _VinDecoder.VinDecoder;}});exports.getAllPIDs=getAllPIDs;exports.getPIDInfo=getPIDInfo;exports.parseOBDResponse=parseOBDResponse;var _obdPIDS=_interopRequireDefault(require("./obdPIDS"));var _DTCBaseDecoder=require("./DTC/DTCBaseDecoder");var _VinDecoder=require("./VIN/VinDecoder");function parseOBDResponse(hexString){var reply={};var byteNumber;var valueArray=[];if(hexString==='NO DATA'||hexString==='OK'||hexString==='?'||hexString==='UNABLE TO CONNECT'||hexString==='SEARCHING...'){reply.value=hexString;return reply;}hexString=hexString.replace(/ /g,'');valueArray=[];for(byteNumber=0;byteNumber<hexString.length;byteNumber+=2){valueArray.push(hexString.substr(byteNumber,2));}if(valueArray[0]==='41'){reply.mode=valueArray[0];reply.pid=valueArray[1];for(var i=0;i<_obdPIDS.default.length;i++){if(_obdPIDS.default[i].pid===reply.pid){var numberOfBytes=_obdPIDS.default[i].bytes;reply.name=_obdPIDS.default[i].name;reply.unit=_obdPIDS.default[i].unit;var convertToUseful=_obdPIDS.default[i].convertToUseful;if(!convertToUseful){break;}switch(numberOfBytes){case 1:reply.value=convertToUseful(valueArray[2]);break;case 2:reply.value=convertToUseful(valueArray[2],valueArray[3]);break;case 4:reply.value=convertToUseful(valueArray[2],valueArray[3],valueArray[4],valueArray[5]);break;case 8:reply.value=convertToUseful(valueArray[2],valueArray[3],valueArray[4],valueArray[5],valueArray[6],valueArray[7],valueArray[8],valueArray[9]);break;}break;}}}else if(valueArray[0]==='43'){reply.mode=valueArray[0];for(var _i=0;_i<_obdPIDS.default.length;_i++){if(_obdPIDS.default[_i].mode==='03'){var _convertToUseful=_obdPIDS.default[_i].convertToUseful;if(!_convertToUseful){break;}reply.name=_obdPIDS.default[_i].name;reply.unit=_obdPIDS.default[_i].unit;reply.value=_convertToUseful(valueArray[1],valueArray[2],valueArray[3],valueArray[4],valueArray[5],valueArray[6]);}}}else if(valueArray[0]==='49'){reply.mode=valueArray[0];reply.pid=valueArray[1];for(var _i2=0;_i2<_obdPIDS.default.length;_i2++){if(_obdPIDS.default[_i2].mode==='09'&&_obdPIDS.default[_i2].pid===reply.pid){reply.name=_obdPIDS.default[_i2].name;reply.unit=_obdPIDS.default[_i2].unit;var _convertToUseful2=_obdPIDS.default[_i2].convertToUseful;if(!_convertToUseful2){break;}reply.value=_convertToUseful2(hexString);break;}}}return reply;}function getPIDInfo(pid){var responsePid=_obdPIDS.default.find(function(item){return item.pid===pid;});return responsePid||null;}function getAllPIDs(){return _obdPIDS.default;} //# sourceMappingURL=index.js.map