UNPKG

rxjs-obd

Version:

RxJS Implementation for OBD (On Board Diagnostics) of vehicles via ELM 327 connections.

50 lines 1.51 kB
import { OBDOuterSubscriber } from '../../model/OBDOuterSubscriber'; export function supportedPIDs(pid = '00') { return function (source) { return source.lift(new SupportedPIDsOperator(pid)); }; } class SupportedPIDsOperator { constructor(pid) { this.pid = pid; } call(subscriber, source) { return source.subscribe(new SupportedPIDsSubscriber(subscriber, this.pid)); } } class SupportedPIDsSubscriber extends OBDOuterSubscriber { constructor(destination, pid) { super(destination); this.pid = pid; } /** * Return the frequency of execution of this command. * @return that this command must be executed every pulse. */ pulse() { return 1; } /** * Return the string representation of the OBD Read command. * @returns the string representation of the OBD Read command */ command() { return `01 ${this.pid} 1\r`; } /** * Return the name of the OBD Field on OBD Data object. * @returns the name of the OBD Field on OBD Data object. */ field() { return `supportedPIDs.segment${this.pid}`; } /** * Parse the OBD response. * @param bytes the response read from OBD. * @returns the parsed response. */ parse(bytes) { return parseInt(bytes[2], 16) + (parseInt(bytes[3], 16) * 256) + (parseInt(bytes[3], 16) * 65536) + (parseInt(bytes[3], 16) * 16777216); } } //# sourceMappingURL=supportedPIDs.js.map