Add new CAN API (#1036)

This commit is contained in:
Thad House
2018-05-21 16:09:38 -07:00
committed by Peter Johnson
parent 55b0fe0082
commit 680aabbe7c
19 changed files with 1545 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
public class CANData {
@SuppressWarnings("MemberName")
public final byte[] data = new byte[8];
@SuppressWarnings("MemberName")
public int length;
@SuppressWarnings("MemberName")
public long timestamp;
/**
* API used from JNI to set the data.
*/
public byte[] setData(int length, long timestamp) {
this.length = length;
this.timestamp = timestamp;
return data;
}
}

View File

@@ -0,0 +1,34 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.hal;
import edu.wpi.first.wpilibj.CANData;
@SuppressWarnings("AbbreviationAsWordInName")
public class CANAPIJNI extends JNIWrapper {
public static native int initializeCAN(int manufacturer, int deviceId, int deviceType);
public static native void cleanCAN(int handle);
public static native void writeCANPacket(int handle, byte[] data, int apiId);
public static native void writeCANPacketRepeating(int handle, byte[] data, int apiId,
int repeatMs);
public static native void stopCANPacketRepeating(int handle, int apiId);
public static native boolean readCANPacketNew(int handle, int apiId, CANData data);
public static native boolean readCANPacketLatest(int handle, int apiId, CANData data);
public static native boolean readCANPacketTimeout(int handle, int apiId, int timeoutMs,
CANData data);
public static native boolean readCANPeriodicPacket(int handle, int apiId, int timeoutMs,
int periodMs, CANData data);
}