• ok6410 android driver(5)


      Test the android driver by JNI (Java Native Interface),

      In the third article, we know how to compiler the moduler for localhost, ok6410 and goldfish platform.

    http://www.cnblogs.com/plinx/p/3209500.html

      But we didn't try to test the driver using by C/C++ program on ok6410 and goldfish.

      Android was changing from linux, so there must remain some fetures linux working.

      If we want to test a driver using C/C++ program, we should get ready for the following conditions :

      (1) Goldfish emulator/Ok6410/Phone must got the permission to "root".

      (2) The exec file compiled by the cross compiler.

      It's easy to go on within these limits, we just need to compile the C/C++ program in the android source configured by "Android.mk".

      

      Here is the Android.mk :

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    # files to compiler
    LOCAL_SRC_FILES := ftest.c
    
    # obj name - the output execute file name
    LOCAL_MODULE := ftest
    
    LOCAL_MODULE_TAGS := optional
    
    include $(BUILD_EXECUTABLE)

      And the ftest.c is :

    #include <stdio.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(int argc, char *argv[])
    {
        int testdev;
        int ret;
        int num = 0;
        unsigned char buf[4];
    
        testdev = open("/dev/wordcount2", O_RDWR);
    
        if(testdev == -1) {
            printf("Can not open file.
    ");
            return 0;
        }
    
        if(argc > 1) {
            printf("Strings : %s.
    ", argv[1]);
            write(testdev, argv[1], strlen(argv[1]));
        }
    
        read(testdev, buf, 4);
    
        num =     ((int)buf[0]) << 24 | 
            ((int)buf[1]) << 16 | 
            ((int)buf[2]) << 8  | 
            ((int)buf[3]);
    
        printf("Word Byte : 0x%d%d%d%dH
    ", buf[0], buf[1], buf[2], buf[3]);
        printf("word count: %d
    ", num);
    
        close(testdev);
        return 0;
    }

      now, we should mkdir in the source code :

    $ pwd
    ~/Android/source_code/development/ndk/wordcount
    $ ls
    Android.mk  ftest.c

      then return to the root directory :

    $ cd ~/Android/source_code/
    $ source build/envsetup.sh
    $ mmm development/ndk/wordcount
    ...
    Install: out/target/product/generic/system/bin/ftest
    ...

      Then we just need to push the file to emulator and test it.

        

  • 相关阅读:
    mysql中文乱码解决方法
    MYSQL常用数据类型详解
    aspx中格式化时间的几种方式
    常用PHP中花括号使用规则详解
    jQuery对表单的操作
    jQuery Ajax 实例 ($.ajax、$.post、$.get)
    PHPEXCEL使用基础教程
    LINQ to XML 编程基础
    PHP获取URL各个部分的函数
    phpExcel常用方法详解大全
  • 原文地址:https://www.cnblogs.com/plinx/p/3211874.html
Copyright © 2020-2023  润新知