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 compilerLOCAL_SRC_FILES := ftest.c# obj name - the output execute file nameLOCAL_MODULE := ftestLOCAL_MODULE_TAGS := optionalinclude $(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.\n"); return 0; } if(argc > 1) { printf("Strings : %s.\n", 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\n", buf[0], buf[1], buf[2], buf[3]); printf("word count: %d\n", num); close(testdev); return 0;}
now, we should mkdir in the source code :
$ pwd~/Android/source_code/development/ndk/wordcount$ lsAndroid.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.
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer