[hal] Add method to detect if the CAN Stream has overflowed (#6105)

This commit is contained in:
Thad House
2023-12-29 09:10:48 -08:00
committed by GitHub
parent 9333951736
commit 24a76be694
5 changed files with 61 additions and 3 deletions

View File

@@ -31,5 +31,6 @@ public class CANJNI extends JNIWrapper {
public static native void closeCANStreamSession(int sessionHandle);
public static native int readCANStreamSession(
int sessionHandle, CANStreamMessage[] messages, int messagesToRead);
int sessionHandle, CANStreamMessage[] messages, int messagesToRead)
throws CANStreamOverflowException;
}

View File

@@ -0,0 +1,35 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.hal.can;
import edu.wpi.first.hal.CANStreamMessage;
import java.io.IOException;
public class CANStreamOverflowException extends IOException {
private final CANStreamMessage[] m_messages;
private final int m_messagesRead;
/**
* Constructs a new CANStreamOverflowException.
*
* @param messages The messages
* @param messagesRead The length of messages read
*/
@SuppressWarnings("PMD.ArrayIsStoredDirectly")
public CANStreamOverflowException(CANStreamMessage[] messages, int messagesRead) {
super("A CAN Stream has overflowed. Data will be missed");
this.m_messages = messages;
this.m_messagesRead = messagesRead;
}
@SuppressWarnings("PMD.MethodReturnsInternalArray")
public CANStreamMessage[] getMessages() {
return m_messages;
}
public int getMessagesRead() {
return m_messagesRead;
}
}