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 edu.wpi.first.hal;
006
007@SuppressWarnings("MemberName")
008public class PowerDistributionStickyFaults {
009  public final boolean Channel0BreakerFault;
010
011  public final boolean Channel1BreakerFault;
012
013  public final boolean Channel2BreakerFault;
014
015  public final boolean Channel3BreakerFault;
016
017  public final boolean Channel4BreakerFault;
018
019  public final boolean Channel5BreakerFault;
020
021  public final boolean Channel6BreakerFault;
022
023  public final boolean Channel7BreakerFault;
024
025  public final boolean Channel8BreakerFault;
026
027  public final boolean Channel9BreakerFault;
028
029  public final boolean Channel10BreakerFault;
030
031  public final boolean Channel11BreakerFault;
032
033  public final boolean Channel12BreakerFault;
034
035  public final boolean Channel13BreakerFault;
036
037  public final boolean Channel14BreakerFault;
038
039  public final boolean Channel15BreakerFault;
040
041  public final boolean Channel16BreakerFault;
042
043  public final boolean Channel17BreakerFault;
044
045  public final boolean Channel18BreakerFault;
046
047  public final boolean Channel19BreakerFault;
048
049  public final boolean Channel20BreakerFault;
050
051  public final boolean Channel21BreakerFault;
052
053  public final boolean Channel22BreakerFault;
054
055  public final boolean Channel23BreakerFault;
056
057  public final boolean Brownout;
058
059  public final boolean CanWarning;
060
061  public final boolean CanBusOff;
062
063  public final boolean HasReset;
064
065  /**
066   * Gets whether there is a sticky breaker fault at the specified channel.
067   *
068   * @param channel Channel to check for sticky faults.
069   * @return True if there is a sticky breaker fault at the channel, otherwise false.
070   * @throws IndexOutOfBoundsException if the provided channel is outside of the range supported by
071   *     the hardware.
072   */
073  public final boolean getBreakerFault(int channel) {
074    switch (channel) {
075      case 0:
076        return Channel0BreakerFault;
077      case 1:
078        return Channel1BreakerFault;
079      case 2:
080        return Channel2BreakerFault;
081      case 3:
082        return Channel3BreakerFault;
083      case 4:
084        return Channel4BreakerFault;
085      case 5:
086        return Channel5BreakerFault;
087      case 6:
088        return Channel6BreakerFault;
089      case 7:
090        return Channel7BreakerFault;
091      case 8:
092        return Channel8BreakerFault;
093      case 9:
094        return Channel9BreakerFault;
095      case 10:
096        return Channel10BreakerFault;
097      case 11:
098        return Channel11BreakerFault;
099      case 12:
100        return Channel12BreakerFault;
101      case 13:
102        return Channel13BreakerFault;
103      case 14:
104        return Channel14BreakerFault;
105      case 15:
106        return Channel15BreakerFault;
107      case 16:
108        return Channel16BreakerFault;
109      case 17:
110        return Channel17BreakerFault;
111      case 18:
112        return Channel18BreakerFault;
113      case 19:
114        return Channel19BreakerFault;
115      case 20:
116        return Channel20BreakerFault;
117      case 21:
118        return Channel21BreakerFault;
119      case 22:
120        return Channel22BreakerFault;
121      case 23:
122        return Channel23BreakerFault;
123      default:
124        throw new IndexOutOfBoundsException("Power distribution fault channel out of bounds!");
125    }
126  }
127
128  /**
129   * Constructs from a bitfield.
130   *
131   * @param faults faults
132   */
133  public PowerDistributionStickyFaults(int faults) {
134    Channel0BreakerFault = (faults & 0x1) != 0;
135    Channel1BreakerFault = (faults & 0x2) != 0;
136    Channel2BreakerFault = (faults & 0x4) != 0;
137    Channel3BreakerFault = (faults & 0x8) != 0;
138    Channel4BreakerFault = (faults & 0x10) != 0;
139    Channel5BreakerFault = (faults & 0x20) != 0;
140    Channel6BreakerFault = (faults & 0x40) != 0;
141    Channel7BreakerFault = (faults & 0x80) != 0;
142    Channel8BreakerFault = (faults & 0x100) != 0;
143    Channel9BreakerFault = (faults & 0x200) != 0;
144    Channel10BreakerFault = (faults & 0x400) != 0;
145    Channel11BreakerFault = (faults & 0x800) != 0;
146    Channel12BreakerFault = (faults & 0x1000) != 0;
147    Channel13BreakerFault = (faults & 0x2000) != 0;
148    Channel14BreakerFault = (faults & 0x4000) != 0;
149    Channel15BreakerFault = (faults & 0x8000) != 0;
150    Channel16BreakerFault = (faults & 0x10000) != 0;
151    Channel17BreakerFault = (faults & 0x20000) != 0;
152    Channel18BreakerFault = (faults & 0x40000) != 0;
153    Channel19BreakerFault = (faults & 0x80000) != 0;
154    Channel20BreakerFault = (faults & 0x100000) != 0;
155    Channel21BreakerFault = (faults & 0x200000) != 0;
156    Channel22BreakerFault = (faults & 0x400000) != 0;
157    Channel23BreakerFault = (faults & 0x800000) != 0;
158    Brownout = (faults & 0x1000000) != 0;
159    CanWarning = (faults & 0x2000000) != 0;
160    CanBusOff = (faults & 0x4000000) != 0;
161    HasReset = (faults & 0x8000000) != 0;
162  }
163}