001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.util.datalog; 006 007import edu.wpi.first.util.WPIUtilJNI; 008import java.nio.ByteBuffer; 009 010public class DataLogJNI extends WPIUtilJNI { 011 static native long create(String dir, String filename, double period, String extraHeader); 012 013 static native void setFilename(long impl, String filename); 014 015 static native void flush(long impl); 016 017 static native void pause(long impl); 018 019 static native void resume(long impl); 020 021 static native void stop(long impl); 022 023 static native void addSchema(long impl, String name, String type, byte[] schema, long timestamp); 024 025 static native void addSchemaString( 026 long impl, String name, String type, String schema, long timestamp); 027 028 static native int start(long impl, String name, String type, String metadata, long timestamp); 029 030 static native void finish(long impl, int entry, long timestamp); 031 032 static native void setMetadata(long impl, int entry, String metadata, long timestamp); 033 034 static native void close(long impl); 035 036 static native void appendRaw( 037 long impl, int entry, byte[] data, int start, int len, long timestamp); 038 039 static void appendRaw(long impl, int entry, ByteBuffer data, int start, int len, long timestamp) { 040 if (data.isDirect()) { 041 if (start < 0) { 042 throw new IndexOutOfBoundsException("start must be >= 0"); 043 } 044 if (len < 0) { 045 throw new IndexOutOfBoundsException("len must be >= 0"); 046 } 047 if ((start + len) > data.capacity()) { 048 throw new IndexOutOfBoundsException("start + len must be smaller than buffer capacity"); 049 } 050 appendRawBuffer(impl, entry, data, start, len, timestamp); 051 } else if (data.hasArray()) { 052 appendRaw(impl, entry, data.array(), data.arrayOffset() + start, len, timestamp); 053 } else { 054 throw new UnsupportedOperationException("ByteBuffer must be direct or have a backing array"); 055 } 056 } 057 058 private static native void appendRawBuffer( 059 long impl, int entry, ByteBuffer data, int start, int len, long timestamp); 060 061 static native void appendBoolean(long impl, int entry, boolean value, long timestamp); 062 063 static native void appendInteger(long impl, int entry, long value, long timestamp); 064 065 static native void appendFloat(long impl, int entry, float value, long timestamp); 066 067 static native void appendDouble(long impl, int entry, double value, long timestamp); 068 069 static native void appendString(long impl, int entry, String value, long timestamp); 070 071 static native void appendBooleanArray(long impl, int entry, boolean[] value, long timestamp); 072 073 static native void appendIntegerArray(long impl, int entry, long[] value, long timestamp); 074 075 static native void appendFloatArray(long impl, int entry, float[] value, long timestamp); 076 077 static native void appendDoubleArray(long impl, int entry, double[] value, long timestamp); 078 079 static native void appendStringArray(long impl, int entry, String[] value, long timestamp); 080}