当前位置: 技术问答>linux和unix
linux下通过蓝牙发送文件到手机上
来源: 互联网 发布时间:2016-05-28
本文导语: 已经把bluez和openobex移植到开发板上,用以下命令能成功把文件发送到手机: [root@Real /]# usb 1-2.1: new full speed USB device using s3c2410-ohci and address 8 idVendor=1131 idProduct1001 [root@Real /]# hciconfig hci0 up [root@Real /]# hc...
已经把bluez和openobex移植到开发板上,用以下命令能成功把文件发送到手机:
[root@Real /]# usb 1-2.1: new full speed USB device using s3c2410-ohci and address 8
idVendor=1131
idProduct1001
[root@Real /]# hciconfig hci0 up
[root@Real /]# hcid -f /etc/bluetooth/hcid.conf
[root@Real /]# hcitool scan
Scanning ...
00:21:D2:3F:61:D2 n/a
00:1E:A4:52:DE:60 N95 LZX
[root@Real /]# sdptool search 0x1105
Class 0x1105
Inquiring ...
Searching for 0x1105 on 00:1E:A4:52:DE:60 ...
Service Name: OBEX Object Push
Service RecHandle: 0x10004
Service Class ID List:
"OBEX Object Push" (0x1105)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 9
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"OBEX Object Push" (0x1105)
Version: 0x0100
[root@Real /]# obex_test -b 00:1E:A4:52:DE:60 9
Using Bluetooth RFCOMM transport
OBEX Interactive test client/server.
> c
LZX-DEBUG
LZX_DEBUG
LZX-DEBUG-Mina
transport mtu=1024
LZX-DEBUG-T=1
Connect OK!
Version: 0x10. Flags: 0x00
> p out.jpg out.jpg
PUT file (local, remote)> name=out.jpg, size=53258
Going to send 53258 bytes
Made some progress...
Made some progress...
Made some progress...
Made some progress...
Made some progress...
Made some progress...
Made some progress...
PUT successful!
>
红色的为手工输入的部分,黄色的是查看终端输出后才能输入的部分,
上面的操作能把out.jpg发送到手机上,现在的问题是:
1.上面的操作怎么才可以放到我的程序里面;
2.黄色的部分我的程度怎么从令命中得到;
3.那些令命如果出错,我的程序怎么知道;
我的程序的意思就是main()里面,由于我对shell不太熟悉,而且就算用了shell还是一样要和我的mian()结合,这样又怎么做呢?
难道要:用system("sdptool search 0x1105 >tmp.txt");
然后再读tmp.txt里的内容,这样好不好呢?我觉得是好笨的方法,对linux了解不多,高手能指点下吗?
[root@Real /]# usb 1-2.1: new full speed USB device using s3c2410-ohci and address 8
idVendor=1131
idProduct1001
[root@Real /]# hciconfig hci0 up
[root@Real /]# hcid -f /etc/bluetooth/hcid.conf
[root@Real /]# hcitool scan
Scanning ...
00:21:D2:3F:61:D2 n/a
00:1E:A4:52:DE:60 N95 LZX
[root@Real /]# sdptool search 0x1105
Class 0x1105
Inquiring ...
Searching for 0x1105 on 00:1E:A4:52:DE:60 ...
Service Name: OBEX Object Push
Service RecHandle: 0x10004
Service Class ID List:
"OBEX Object Push" (0x1105)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 9
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"OBEX Object Push" (0x1105)
Version: 0x0100
[root@Real /]# obex_test -b 00:1E:A4:52:DE:60 9
Using Bluetooth RFCOMM transport
OBEX Interactive test client/server.
> c
LZX-DEBUG
LZX_DEBUG
LZX-DEBUG-Mina
transport mtu=1024
LZX-DEBUG-T=1
Connect OK!
Version: 0x10. Flags: 0x00
> p out.jpg out.jpg
PUT file (local, remote)> name=out.jpg, size=53258
Going to send 53258 bytes
Made some progress...
Made some progress...
Made some progress...
Made some progress...
Made some progress...
Made some progress...
Made some progress...
PUT successful!
>
红色的为手工输入的部分,黄色的是查看终端输出后才能输入的部分,
上面的操作能把out.jpg发送到手机上,现在的问题是:
1.上面的操作怎么才可以放到我的程序里面;
2.黄色的部分我的程度怎么从令命中得到;
3.那些令命如果出错,我的程序怎么知道;
我的程序的意思就是main()里面,由于我对shell不太熟悉,而且就算用了shell还是一样要和我的mian()结合,这样又怎么做呢?
难道要:用system("sdptool search 0x1105 >tmp.txt");
然后再读tmp.txt里的内容,这样好不好呢?我觉得是好笨的方法,对linux了解不多,高手能指点下吗?
|
最好还是自己去看看sdptool、obex_test这些程序的源码,将操作提取出来整合到自己的程序中去,单纯用脚本的话有一些关键的参数比如sdptool搜索到的蓝牙地址你怎么作为参数传到下一个应用中去?难道要将sdptool的结果再做一次字符串解析?