From 9dce3a003a95afc6f8b07b5eb66828919ee5eb79 Mon Sep 17 00:00:00 2001 From: Marcus Behel Date: Sun, 24 Feb 2019 00:15:28 -0500 Subject: [PATCH] Fix java short and ushort conversions using byte arrays --- build.gradle | 2 +- .../java/com/analog/adis16448/frc/ADIS16448_IMU.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index a453b78..c2f0e31 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ allprojects { def mavenrepo = rootProject.projectDir.toString() + "/build/maven" def vendordepsdir = rootProject.projectDir.toString() + "/build/vendordeps" -def libraryVersion = "2019-r1" +def libraryVersion = "2019-r2" def publishGroupId = 'com.github.juchong' subprojects{ diff --git a/java/src/main/java/com/analog/adis16448/frc/ADIS16448_IMU.java b/java/src/main/java/com/analog/adis16448/frc/ADIS16448_IMU.java index 32c9321..5317c37 100644 --- a/java/src/main/java/com/analog/adis16448/frc/ADIS16448_IMU.java +++ b/java/src/main/java/com/analog/adis16448/frc/ADIS16448_IMU.java @@ -379,12 +379,12 @@ static int ToUShort(ByteBuffer buf) { return (buf.getShort(0)) & 0xFFFF; } static int ToUShort(byte[] buf) { - return buf[0] << 8 & buf[1]; + return (buf[0] << 8 | buf[1]) & 0xFFFF; } static int ToUShort(int... data) { - ByteBuffer buf = ByteBuffer.allocate(data.length); - for(int d : data) { - buf.put((byte)d); + byte[] buf = new byte[data.length]; + for(int i = 0; i < data.length; ++i) { + buf[i] = (byte)data[i]; } return ToUShort(buf); } @@ -394,7 +394,7 @@ public static long ToULong(int sint) { } private static int ToShort(int... buf) { - return (short)(((short)buf[0]) << 8 | buf[1]); + return (buf[0] << 8 | buf[1]); } static int ToShort(ByteBuffer buf) { return ToShort(buf.get(0), buf.get(1));