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