1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.car.obd2.commands; 18 19 import com.android.car.obd2.IntegerArrayStream; 20 import com.android.car.obd2.Obd2Command; 21 22 import java.util.Optional; 23 24 public abstract class FuelTrimCommand implements Obd2Command.OutputSemanticHandler<Float> { 25 @Override consume(IntegerArrayStream data)26 public Optional<Float> consume(IntegerArrayStream data) { 27 return data.hasAtLeast( 28 1, 29 theData -> Optional.of(3 * theData.consume() / 1.28f - 100), 30 theData -> Optional.<Float>empty()); 31 } 32 33 public static class Bank1ShortTermFuelTrimCommand extends FuelTrimCommand { 34 @Override getPid()35 public int getPid() { 36 return 0x06; 37 } 38 } 39 40 public static class Bank1LongTermFuelTrimCommand extends FuelTrimCommand { 41 @Override getPid()42 public int getPid() { 43 return 0x07; 44 } 45 } 46 47 public static class Bank2ShortTermFuelTrimCommand extends FuelTrimCommand { 48 @Override getPid()49 public int getPid() { 50 return 0x08; 51 } 52 } 53 54 public static class Bank2LongTermFuelTrimCommand extends FuelTrimCommand { 55 @Override getPid()56 public int getPid() { 57 return 0x09; 58 } 59 } 60 } 61