001package jmri.jmrix.ipocs.protocol.packets;
002
003import java.nio.ByteBuffer;
004
005import jmri.jmrix.ipocs.protocol.enums.RqDerailerState;
006import jmri.jmrix.ipocs.protocol.enums.RqReleaseState;
007
008/**
009 * Derailer status
010 *
011 * @author Fredrik Elestedt Copyright (C) 2020
012 * @since 4.21.2
013 */
014@org.openide.util.lookup.ServiceProvider(service = Packet.class)
015public class DerailerStatusPacket extends Packet {
016  public final static byte IDENT = 18;
017  private RqDerailerState state = null;
018  private RqReleaseState releaseState = null;
019  private short operationTime;
020
021  @Override
022  public byte getId() {
023    return IDENT;
024  }
025
026  @Override
027  protected void parseSpecific(ByteBuffer buffer) {
028    state = RqDerailerState.valueOf(buffer.get());
029    releaseState = RqReleaseState.valueOf(buffer.get());
030    operationTime = buffer.getShort();
031  }
032
033  @Override
034  protected byte[] serializeSpecific() {
035    ByteBuffer buffer = ByteBuffer.allocate(4);
036    buffer.put(state.value);
037    buffer.put(releaseState.value);
038    buffer.putShort(operationTime);
039    buffer.rewind();
040    return buffer.array();
041  }
042
043  public RqDerailerState getState() {
044    return state;
045  }
046
047  public void setState(RqDerailerState state) {
048    this.state = state;
049  }
050
051  public RqReleaseState getReleaseState() {
052    return releaseState;
053  }
054
055  public void setReleaseState(RqReleaseState releaseState) {
056    this.releaseState = releaseState;
057  }
058
059  public short getOperationTime() {
060    return operationTime;
061  }
062
063  public void setOperationTime(short operationTime) {
064    this.operationTime = operationTime;
065  }
066}