在整3G模块,交叉编译的usb_modeswitch程序跑不了,不知道为什么

xqhrs232 2011-12-22 06:13:11
在整3G模块,交叉编译的usb_modeswitch程序跑不了,不知道为什么
...全文
551 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
qthsrs232 2012-01-07
  • 打赏
  • 举报
回复
今天才明白取得也不是编译器选择不对的问题.而是要用SYSTEM命令去调编译的应用程序.因为系统自带的应用程序在ADB下执行也报同样的错误.

Android NDK编程实现终端功能(调用system函数)
http://big-room.org/?p=62

本程序能够实现在android中利用system函数执行命令,并将执行结果输出到指定的文件中。

核心代码:

hello-jni.c

view sourceprint?01 #include <jni.h>

02 #include <string.h>

03 JNIEXPORT jstring Java_com_example_hellojni_HelloJni_system(JNIEnv* env,jobject thiz, jstring str , jstring path)

04 {

05 const jbyte* p1 = (*env)->GetStringUTFChars(env , str, NULL);

06 const jbyte* p2 = (*env)->GetStringUTFChars(env , path, NULL);

07 char* str2=(char *)p1;

08 char* path2=(char *)p2;

09 strcat(str2," > ");

10 strcat(str2,path2);

11 system(str2);

12 return(*env)->NewStringUTF(env,str2);

13 }



HelloJni.java

view sourceprint?01 package com.example.hellojni;

02 import android.app.Activity;

03 import android.widget.TextView;

04 import android.os.Bundle;

05

06 public class HelloJni extends Activity

07 {

08 /** Called when the activity is first created. */

09 @Override

10 public void onCreate(Bundle savedInstanceState)

11 {

12 super.onCreate(savedInstanceState);

13 TextView tv = new TextView(this);

14 tv.setText(system("ls","\"/mnt/sdcard/hello.txt\"") );//这里的第一个参数是要执行的命令,第二个参数是要输出的文件路径

15 setContentView(tv);

16 }

17 public native String system(String str ,String path);

18 static {

19 System.loadLibrary("hello-jni");

20 }

21 }

源代码代码:

本站下载:hello-jni

备用下载:leo108.com_614411.zip






xqhrs232 2011-12-23
  • 打赏
  • 举报
回复
还是没搞好!可能还是交叉编译工具链没选对,可能是因为选的是LINUX的而不是ANDROID的,所以编译出来的程序老是执行不起来。把代码放ANDROID系统下编译头文件没地方找,一大堆错误,我看还是算了。

今天通过PUTTY AT COMMAND工具软件把3G模块的CD-ROM功能关闭掉就OK了,也用不着USB-MODESWITCH工具了。

AT^U2DIAG=256/268----打开CD-ROM功能

AT^U2DIAG=0 ----关闭CD-ROM功能

可以看PUTTY的回显看你的AT命令有没支持有没被执行对,可以使用ATI/ATZ对3G模块进行RESET并判断是否工作正常,在PUTTY窗口下输入命令没有被显示可能因为3G模块的回显功能没开启而不是没连上或者坏了,RESET系统回显功能会默认开启,这样你想怎么输入AT命令都可以。
xqhrs232 2011-12-22
  • 打赏
  • 举报
回复

android libUSB如何使用

http://www.javaworld.com.tw/jute/post/view?bid=29&id=301474

請問
因為我想利用JNI方式使用libUSB
但是因為對so製作不是很懂,
所以想了解一下觀念,

目前手上有官方下載的libUSB-1.0.8的檔案,我想寫一隻 callLibUsb.c 的程式去使用libusb的方法
然後再用ndk-buld指令包裝成callLibUsb.so 給java使用,這樣做事可以的嗎?

這過程中我需要去make libusb嗎?

還是我也可以只將libUSB-1.0.8做ndk-build呢?然後直接給Java引用?

因為整個封裝後,要給android環境下來呼叫使用.
希望有人可以不吝指教一下.

謝謝~!


xqhrs232 2011-12-22
  • 打赏
  • 举报
回复
Compiling LibUSB for Android
http://androidforums.com/application-development/394550-compiling-libusb-android.html

Hey Guys,
I'm writing an application that requires a custom USB driver, and i need LibUSB to be able to do it. I downloaded the following:

android.git.kernel.org Git - platform/external/libusb.git/summary

My problem is that when i try to cross compile using ./configure this lib, i get the error: unsupported operating system. I've been trying to configure like this:


Code:
./configure --host=arm-eabi CC=arm-linux-androideabi-gcc CPPFLAGS="-I$NDK_ROOT/platforms/android-3/arch-arm/usr/include/" CFLAGS="-nostdlib" LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-3/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-3/arch-arm/usr/lib/" LIBS="-lc"The main aim is to be able to use the library with the Android NDK. If anybody has managed this - or could help me with this, it would be most appreciated! (Also - i am using Ubuntu)

Cheers, Tony.

qthsrs232 2011-12-22
  • 打赏
  • 举报
回复
http://stackoverflow.com/questions/7469518/using-libusb-in-android-application-how-to-allow-application-to-access-usb
qthsrs232 2011-12-22
  • 打赏
  • 举报
回复
Re: Adding libraries libusb and libnfc to android
http://www.mailinglistarchive.com/html/android-platform@googlegroups.com/2010-03/msg00084.html

用关键字----android libusb进行搜索
qthsrs232 2011-12-22
  • 打赏
  • 举报
回复
xqhrs232 2011-12-22
  • 打赏
  • 举报
回复
Porting libusb to Android2.1
http://hi.baidu.com/ylfan2006/blog/item/0584b1ee21b8bac4b21cb174.html


1、Download Src:http://sourceforge.net/projects/libusb/files/libusb-1.0/

Now the latest release version is 1.0.8,I download version was 1.0.3

2、unpack the src:

tar xjvf libusb-1.0.3.tar.bz2

3、configure:

cd libusb-1.0.3

./configure --host=arm-linux CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc CFLAGS="-Wall -fno-common -g -O2"

then copy it to android2.1 externel directory

4、Create Android.mk

Create Android.mk files in each of the libusb directories. In the top folder your Android.mk just calls your mk files in the libusb subfolders :

LOCAL_PATH := $(call my-dir)
ubdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
libusb \
))
include $(subdirs)

in the libusb folder add the following Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
core.c \

descriptor.c \
io.c \
sync.c \
os/linux_usbfs.c�

LOCAL_C_INCLUDES += \
external/libusb-1.0.3/ \
external/libusb-1.0.3/libusb/ \
external/libusb-1.0.3/libusb/os�

LOCAL_MODULE:= libusb
include $(BUILD_SHARED_LIBRARY)

5、compile

Soon we are ready to compile the library; if we do so now, we will notice that the macro�TIMESPEC_TO_TIMEVAL is not defined by the sources inside Android. To overcome this problem we just need to define the macro in the�lubusb/io.c file

#define TIMESPEC_TO_TIMEVAL(tv, ts) \
do { \
(tv)->tv_sec = (ts)->tv_sec; \
(tv)->tv_usec = (ts)->tv_nsec / 1000; \
} while (0)

If you compile your libusb now, there is going to be the following error: build/tools/apriori/prelinkmap.c(137): library ‘libusb.so’ not in prelink map. This is because Android keeps track of all the shared libraries of the root file system (RFS). Therefore we need to add the library to the prelinked map found in ./build/core/prelink-linux-arm.map. We did so and just added libusb.so below libqcamera.so.

libqcamera.so 0xA9400000
libusb.so 0xA8000000

You are now all set to compile libusb. Execute the following commands in your Android root directory:

$ . build/envsetup.sh
$ choosecombo

mm

6、compile lsusb

Now we need to compile lsusb. The sources are located in the examples folder of libusb. Create a folder lsusb in the ./external directory of the Android sources. Copy the lsusb.c module into it and create a Android.mk file

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_SRC_FILES:= lsusb.c
LOCAL_MODULE := lsusb
LOCAL_C_INCLUDES += external/libusb-1.0.3/
LOCAL_SHARED_LIBRARIES := libc libusb
include $(BUILD_EXECUTABLE


xqhrs232 2011-12-22
  • 打赏
  • 举报
回复
libusb and Android: libusb_control_transfer timeout 选项 http://groups.google.com/group/android-platform/browse_thread/thread/0b13541ab02315c1/14ebf1bee2cfa2df?show_docid=14ebf1bee2cfa2df


Hi all

I've run into some trouble while porting some code to android. I took
a code snippet from our linux application that communicates with our
device through libusb and began porting it. Using the android-ndk-r5b
everything compiles fine. I copied over the libusb source and included
it as a static library in my shared library, then I load the shared
library from my app.
On the android phone (Samsung Galaxy S2) I plug in our device using an
OTG cable and then mount the usbfs with devmode=0666.


The problem occurs at the point in the code where
libusb_control_transfer() is called. Keep in mind that up until this
point other libusb commands like libusb_get_device_list(),
libusb_get_device_descriptor, libusb_claim_interface() are successful
and I can find my device by checking vid pid of available devices.


I've tried to track down in the kernel source where the timeout occurs
and I've found that in the file drivers/usb/core/message.c in the
function usb_start_wait_urb(), that usb_submit_urb() returns
successfully, but then times out right after that. Seems like the urb
is queued and that's it, my app hangs waiting for its completion.


Any help or pointers on what to do from here or where to look?



xqhrs232 2011-12-22
  • 打赏
  • 举报
回复

我的交叉编译器是:arm-elf-gcc
./configure --build=i686-linux --host=arm-elf --prefix=/8620L/libusb-0.1.12/install
出现以下错误:

checking for what USB OS support... unknown operating system
configure: error: libusb does not support compiling for arm-unknown-elf

望高人能解答





难道只支持arm-linux交叉编译工具?
qthsrs232 2011-12-22
  • 打赏
  • 举报
回复
libusb的交叉编译出错----libusb does not support compiling for arm-unknown-eabi
http://topic.csdn.net/u/20110902/15/d3ae3dc4-cb31-4fc4-8d16-d6c1cb1a5a69.html


本人是新手,最近想学习在android系统上移植USB,3G模块
之前用arm-none-linux-gnueabi进行交叉编译,可以编译成功,但移植到板子上的android系统时却显示
./usb_modeswitch command not found
怀疑是由于板子的android系统是用arm-eabi交叉编译的。
之后我便想用arm-eabi交叉编译libusb,结果出错,请大家帮帮我看这错误是怎么回事。
具体错误如下:
WSCEC@ubuntu:~$ cd 3G/123/libusb-0.1.12/
WSCEC@ubuntu:~/3G/123/libusb-0.1.12$ source ../anv
WSCEC@ubuntu:~/3G/123/libusb-0.1.12$ export ROOT=/home/WSCEC/Android/out/target/product/omap3evm/obj
WSCEC@ubuntu:~/3G/123/libusb-0.1.12$ ./configure --build=i686-linux --host=arm-eabi CPPFLAGS="-I$ROOT/include/" CFLAGS="-nostdlib" LDFLAGS="-Wl,-rpath-link=$ROOT/lib/ -L$ROOT/lib/" LIBS="-lc" --prefix=/home/WSCEC/3G/123/libusb-0.1.12/install
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... no
checking for mawk... mawk
……(中间省略)
checking whether stripping libraries is possible... yes
appending configuration tag "F77" to libtool
checking for what USB OS support... unknown operating system
configure: error: libusb does not support compiling for arm-unknown-eabi

其实anv是我弄的环境变量。

后面我看了下config.log:如下:
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by libusb configure 0.1.12, which was
generated by GNU Autoconf 2.59. Invocation command line was

$ ./configure --build=i686-linux --host=arm-eabi CPPFLAGS=-I/home/WSCEC/Android/out/target/product/omap3evm/obj/include/ CFLAGS=-nostdlib LDFLAGS=-Wl,-rpath-link=/home/WSCEC/Android/out/target/product/omap3evm/obj/lib/ -L/home/WSCEC/Android/out/target/product/omap3evm/obj/lib/ LIBS=-lc --prefix=/home/WSCEC/3G/123/libusb-0.1.12/install

## --------- ##
## Platform. ##
## --------- ##

hostname = ubuntu
uname -m = i686
uname -r = 2.6.38-10-generic
uname -s = Linux
uname -v = #46-Ubuntu SMP Tue Jun 28 15:05:41 UTC 2011
……(省略)
configure:2828: $? = 0
configure:2832: test -z
|| test ! -s conftest.err
configure:2835: $? = 0
configure:2838: test -s conftest.o
configure:2841: $? = 0
configure:2852: result: yes
configure:2869: checking for arm-eabi-gcc option to accept ANSI C
configure:2939: arm-eabi-gcc -c -nostdlib -I/home/WSCEC/Android/out/target/product/omap3evm/obj/include/ conftest.c >&5
conftest.c:17:19: error: stdio.h: No such file or directory
conftest.c:18:23: error: sys/types.h: No such file or directory
conftest.c:19:22: error: sys/stat.h: No such file or directory
conftest.c:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
conftest.c:51: error: expected declaration specifiers or '...' before 'FILE'
……
#endif
#ifdef __cplusplus
void exit (int);

configure: exit 1

求各位大神们 帮帮我看看怎么回事

qthsrs232 2011-12-22
  • 打赏
  • 举报
回复
3G网卡在开发板上使用(模式转换)
http://blog.csdn.net/zhanghaijin0911/article/details/6232564
xqhrs232 2011-12-22
  • 打赏
  • 举报
回复
《求助》在android2.3.4上 加入3G模块,usb_modeswitch失败,发送短信失败。。。
http://bbs.witech.com.cn/thread-7356-1-1.html
xqhrs232 2011-12-22
  • 打赏
  • 举报
回复
xqhrs232 2011-12-22
  • 打赏
  • 举报
回复
执行显示line 1: syntax error: word unexpected (expecting ”)" )

估计还是交叉编译工具选择的不对,看到很多例子都是LINUX下的,我的是ANDROID,我的交叉编译工具不好指定.

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧