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.can;
006
007import edu.wpi.first.hal.CANStreamMessage;
008import java.io.IOException;
009
010/**
011 * Exception indicating that a CAN stream overflowed at some point between reads, therefore some
012 * messages were lost. This exception contains any messages that were successfully read during the
013 * operation that threw the exception.
014 */
015public class CANStreamOverflowException extends IOException {
016  /** The messages. */
017  private final CANStreamMessage[] m_messages;
018
019  /** The length of messages read. */
020  private final int m_messagesRead;
021
022  /**
023   * Constructs a new CANStreamOverflowException.
024   *
025   * @param messages The messages that were read successfully.
026   * @param messagesRead The length of messages read successfully.
027   */
028  @SuppressWarnings("PMD.ArrayIsStoredDirectly")
029  public CANStreamOverflowException(CANStreamMessage[] messages, int messagesRead) {
030    super("A CAN Stream has overflowed. Data will be missed");
031    this.m_messages = messages;
032    this.m_messagesRead = messagesRead;
033  }
034
035  /**
036   * Gets the messages that were successfully read. Use {@link #getMessagesRead()} to determine how
037   * many messages in the returned array are valid.
038   *
039   * @return the messages
040   */
041  @SuppressWarnings("PMD.MethodReturnsInternalArray")
042  public CANStreamMessage[] getMessages() {
043    return m_messages;
044  }
045
046  /**
047   * Gets the count of messages that were successfully read.
048   *
049   * @return count of messages
050   */
051  public int getMessagesRead() {
052    return m_messagesRead;
053  }
054}