001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package org.wpilib.hardware.hal.struct;
006
007import java.nio.ByteBuffer;
008import org.wpilib.hardware.hal.ControlWord;
009import org.wpilib.util.struct.Struct;
010
011public class ControlWordStruct implements Struct<ControlWord> {
012  @Override
013  public Class<ControlWord> getTypeClass() {
014    return ControlWord.class;
015  }
016
017  @Override
018  public String getTypeName() {
019    return "ControlWord";
020  }
021
022  @Override
023  public int getSize() {
024    return 8;
025  }
026
027  @Override
028  public String getSchema() {
029    return "uint64 opModeHash:56;"
030        + "enum{unknown=0,autonomous=1,teleoperated=2,test=3} uint64 robotMode:2;"
031        + "bool enabled:1;bool eStop:1;bool fmsAttached:1;bool dsAttached:1;";
032  }
033
034  @Override
035  public ControlWord unpack(ByteBuffer bb) {
036    ControlWord word = new ControlWord();
037    unpackInto(word, bb);
038    return word;
039  }
040
041  @Override
042  public void unpackInto(ControlWord out, ByteBuffer bb) {
043    out.update(bb.getLong());
044  }
045
046  @Override
047  public void pack(ByteBuffer bb, ControlWord value) {
048    bb.putLong(value.getNative());
049  }
050}