Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Finished fixing non-bytebuffer based java driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
MB3hel committed Mar 8, 2019
1 parent 9dce3a0 commit 496a8e6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions java/src/main/java/com/analog/adis16448/frc/ADIS16448_IMU.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ static int ToUShort(ByteBuffer buf) {
return (buf.getShort(0)) & 0xFFFF;
}
static int ToUShort(byte[] buf) {
return (buf[0] << 8 | buf[1]) & 0xFFFF;
}
return (((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF) << 0));
}
static int ToUShort(int... data) {
byte[] buf = new byte[data.length];
for(int i = 0; i < data.length; ++i) {
Expand All @@ -394,7 +394,7 @@ public static long ToULong(int sint) {
}

private static int ToShort(int... buf) {
return (buf[0] << 8 | buf[1]);
return (short)(((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF) << 0));
}
static int ToShort(ByteBuffer buf) {
return ToShort(buf.get(0), buf.get(1));
Expand Down Expand Up @@ -510,13 +510,14 @@ private void acquire() {
data_to_read = data_count - array_offset; // Discard "extra" data
m_spi.readAutoReceivedData(readBuf,data_to_read,0); // Read data from DMA buffer
for(int i = 0; i < data_to_read; i += 116) { // Process each set of 28 bytes (timestamp + 28 data) * 4 (32-bit ints)

for(int j = 1; j < 29; j++) { // Split each set of 28 bytes into a sub-array for processing
int at = (i + 4 * (j));
int at = (i + 1 * (j));
data_subset[j - 1] = readBuf[at];//readBuf.getInt(at);
}

// DEBUG: Print the received data
// printBytes(data_subset);
//printBytes(data_subset);

// DEBUG: Plot Sub-Array Data in Terminal
/*System.out.println(ToUShort(data_subset[0], data_subset[1]) + "," + ToUShort(data_subset[2], data_subset[3]) + "," +
Expand Down Expand Up @@ -546,8 +547,10 @@ private void acquire() {
// This is the data needed for CRC
//ByteBuffer bBuf = ByteBuffer.allocateDirect(2);
//byte[] bBuf = new byte[2];
bBuf[0] = (byte)readBuf[(i + 26) * 4 + 4]; // (i + 26) * 4 = position (32-bit ints) + 4 to skip timestamp
bBuf[1] = (byte)readBuf[(i + 27) * 4 + 4]; // (i + 27) * 4 = position (32-bit ints) + 4 to skip timestamp
bBuf[0] = (byte)data_subset[26];
bBuf[1] = (byte)data_subset[27];

//System.out.println("Data: " + bBuf[0] + "," + bBuf[1]);

imu_crc = ToUShort(bBuf); // Extract DUT CRC from data
//System.out.println("IMU: " + imu_crc);
Expand All @@ -556,7 +559,7 @@ private void acquire() {
// Compare calculated vs read CRC. Don't update outputs if CRC-16 is bad
if(calc_crc == imu_crc) {
// Calculate delta-time (dt) using FPGA timestamps
timestamp_new = ToULong(readBuf[i * 4]);
timestamp_new = ToULong(readBuf[i]);
dt = (timestamp_new - timestamp_old)/1000000.0; // Calculate dt and convert us to seconds
timestamp_old = timestamp_new; // Store new timestamp in old variable for next cycle

Expand Down

0 comments on commit 496a8e6

Please sign in to comment.