java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Java接收kernel数组

Java 如何接收kernel传过来的数组(推荐)

作者:baidu_37552881

这篇文章主要介绍了Java 如何接收kernel传过来的数组,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧

如接收float 类型数组,JNI 定义jfloatArray 类型数据 通过env->ReleaseFloatArrayElements 将float 数据拷贝成jfloatArray类型
JNI 部分:

static jfloatArray TempMlsSensorRead_native(JNIEnv* env , jobject /* clazz */,jint length){
     float * address=(float *)g_device->mlx90640_read(g_device);
           float *example =new float [768]{};
           for(int i=0;i<768;i++){
               example[i]=address[i];
           }
           jfloatArray copyArray = env->NewFloatArray(768);
           env->ReleaseFloatArrayElements(copyArray,example,0);
    return copyArray;
}
static const JNINativeMethod method_table[] = {
  { "nativeTempMlsSensorOpen", "()I", (void*)TempMlsSensorOpen_native },
  { "nativeTempMlsSensorWrite", "(I)I", (void*)TempMlsSensorWrite_native },
+ { "nativeTempMlsSensorRead", "(I)[F", (void*)TempMlsSensorRead_native },
  { "nativeTempMlsSensorReadValue", "()I", (void*)TempMlsSensorRead_native_value },
  { "nativeTempMlsSensorIoctl", "(II)I", (void*)TempMlsSensorIoctl_native },
  { "nativeTempMlsSensorClose", "()I", (void*)TempMlsSensorClose_native },

AIDL 接口添加float 数组类型

interface ITempMlsSensor {
    int TempMlsSensorOpen();
    int TempMlsSensorWrite(int value);
 +  float[] TempMlsSensorRead(int length);
    int TempMlsSensorReadValue();
    int TempMlsSensorIoctl(int cmd, int value);
    int TempMlsSensorClose();
}

JAVA 类型数组类型

    @Override
  +  public float[] TempMlsSensorRead(int length) throws android.os.RemoteException{
  +          return nativeTempMlsSensorRead(length);
  + }
    public static native int nativeTempMlsSensorOpen();
    public static native int nativeTempMlsSensorWrite(int value);
  +  public static native float [] nativeTempMlsSensorRead(int length);
    public static native int nativeTempMlsSensorReadValue();
    public static native int nativeTempMlsSensorIoctl(int cmd,int value);
    public static native int nativeTempMlsSensorClose();

到此这篇关于Java 如何接收kernel传过来的数组的文章就介绍到这了,更多相关Java接收kernel数组内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

阅读全文