[hal] Add no throw/error version of CAN Write methods (#2063)

This commit is contained in:
Thad House
2020-08-29 23:07:22 -07:00
committed by GitHub
parent 7c99224bb7
commit ed18693345
5 changed files with 147 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -25,6 +25,7 @@ import edu.wpi.first.hal.HAL;
* read methods and the byte[] passed into the write methods need to not
* be modified for the duration of their respective calls.
*/
@SuppressWarnings("PMD.TooManyMethods")
public class CAN implements Closeable {
public static final int kTeamManufacturer = 8;
public static final int kTeamDeviceType = 10;
@@ -100,6 +101,39 @@ public class CAN implements Closeable {
CANAPIJNI.writeCANRTRFrame(m_handle, length, apiId);
}
/**
* Write a packet to the CAN device with a specific ID. This ID is 10 bits.
*
* @param data The data to write (8 bytes max)
* @param apiId The API ID to write.
*/
public int writePacketNoThrow(byte[] data, int apiId) {
return CANAPIJNI.writeCANPacketNoThrow(m_handle, data, apiId);
}
/**
* Write a repeating packet to the CAN device with a specific ID. This ID is 10 bits.
* The RoboRIO will automatically repeat the packet at the specified interval
*
* @param data The data to write (8 bytes max)
* @param apiId The API ID to write.
* @param repeatMs The period to repeat the packet at.
*/
public int writePacketRepeatingNoThrow(byte[] data, int apiId, int repeatMs) {
return CANAPIJNI.writeCANPacketRepeatingNoThrow(m_handle, data, apiId, repeatMs);
}
/**
* Write an RTR frame to the CAN device with a specific ID. This ID is 10 bits.
* The length by spec must match what is returned by the responding device
*
* @param length The length to request (0 to 8)
* @param apiId The API ID to write.
*/
public int writeRTRFrameNoThrow(int length, int apiId) {
return CANAPIJNI.writeCANRTRFrameNoThrow(m_handle, length, apiId);
}
/**
* Stop a repeating packet with a specific ID. This ID is 10 bits.
*