All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.pires.obd.commands.pressure.PressureCommand Maven / Gradle / Ivy

There is a newer version: 1.0
Show newest version
package com.github.pires.obd.commands.pressure;

import com.github.pires.obd.commands.ObdCommand;
import com.github.pires.obd.commands.SystemOfUnits;

/**
 * Abstract pressure command.
 *
 * @author pires
 * @version $Id: $Id
 */
public abstract class PressureCommand extends ObdCommand implements
        SystemOfUnits {

    protected int tempValue = 0;
    protected int pressure = 0;

    /**
     * Default ctor
     *
     * @param cmd a {@link java.lang.String} object.
     */
    public PressureCommand(String cmd) {
        super(cmd);
    }

    /**
     * Copy ctor.
     *
     * @param other a {@link com.github.pires.obd.commands.pressure.PressureCommand} object.
     */
    public PressureCommand(PressureCommand other) {
        super(other);
    }

    /**
     * Some PressureCommand subclasses will need to implement this method in
     * order to determine the final kPa value.
     * 

* *NEED* to read tempValue * * @return a int. */ protected int preparePressureValue() { return buffer.get(2); } /** *

performCalculations.

*/ protected void performCalculations() { // ignore first two bytes [hh hh] of the response pressure = preparePressureValue(); } /** {@inheritDoc} */ @Override public String getFormattedResult() { return useImperialUnits ? String.format("%.1f%s", getImperialUnit(), getResultUnit()) : String.format("%d%s", pressure, getResultUnit()); } /** *

getMetricUnit.

* * @return the pressure in kPa */ public int getMetricUnit() { return pressure; } /** *

getImperialUnit.

* * @return the pressure in psi */ public float getImperialUnit() { return pressure * 0.145037738F; } /** {@inheritDoc} */ @Override public String getCalculatedResult() { return useImperialUnits ? String.valueOf(getImperialUnit()) : String.valueOf(pressure); } /** {@inheritDoc} */ @Override public String getResultUnit() { return useImperialUnits ? "psi" : "kPa"; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy