package com.lingniu.ingest.protocol.gb32960.codec.parser.v2016;

import com.lingniu.ingest.protocol.gb32960.codec.InfoBlockParser;
import com.lingniu.ingest.protocol.gb32960.codec.ValueDecoder;
import com.lingniu.ingest.protocol.gb32960.model.InfoBlock;
import com.lingniu.ingest.protocol.gb32960.model.ProtocolVersion;

import java.nio.ByteBuffer;

/**
 * 发动机数据 (0x04) —— GB/T 32960.3-2016 表 20。固定 5 字节：
 * engineState(1) + crankshaftRpm(2) + fuelConsumptionRate(2,0.01 L/100km)。
 * 停车充电过程和增程式车辆纯电模式无需传输。
 */
public final class EngineV2016BlockParser implements InfoBlockParser {

    @Override public ProtocolVersion version() { return ProtocolVersion.V2016; }
    @Override public int typeCode() { return 0x04; }
    @Override public int fixedLength() { return 5; }

    @Override
    public InfoBlock parse(ByteBuffer buf) {
        Integer engineState = ValueDecoder.u8(buf);
        Integer crankshaftRpm = ValueDecoder.u16(buf);
        Double fuelRate = ValueDecoder.scaledU16(buf, 0.01);
        return new InfoBlock.Gb32960V2016.Engine(engineState, crankshaftRpm, fuelRate);
    }
}
