ok6410 android driver(5)

时间:2021-11-07 16:45:43

  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 = ;
unsigned char buf[]; testdev = open("/dev/wordcount2", O_RDWR); if(testdev == -) {
printf("Can not open file.\n");
return ;
} if(argc > ) {
printf("Strings : %s.\n", argv[]);
write(testdev, argv[], strlen(argv[]));
} read(testdev, buf, ); num = ((int)buf[]) << | \
((int)buf[]) << | \
((int)buf[]) << | \
((int)buf[]); printf("Word Byte : 0x%d%d%d%dH\n", buf[], buf[], buf[], buf[]);
printf("word count: %d\n", num); close(testdev);
return ;
}

  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.