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