红外通讯协议
wqx和手机不能文件传输,这很令人不爽,所以最近研究红外文件传输协议,好让我
自己编一个通讯程序.
红外文件传输协议有好几种,但我只找到
OBEX协议,而且我在wqx中也搜索到OBEX
这几个字母,所以深入了解了一下.我看了
本OBEX 1.0的书,倒是有所收获
在数据通讯中,每次传输我称之为一次会话
并以数据包为单位,每个数据包结构如下:
xx,yyyy,zzzz.....
xx:一个字节(类推),为操作指码
yyyy:数据包总长度
zzzz....:数据区(也可以没有该部分)
例如:如果没有数据区,那么yyyy为0x0003
以下是操作码含义:
Version 1.0
请求中的操作码 名称 说明
0x80 // high bit always set Connect 请求连接
0x81 // high bit always set Disconnect 断开连接
0x02 (0x82) Put 发送对象
0x03 (0x83) Get 请求对象
0x04 (0x84) Command send a responseless packet
0x85 // high bit always set SetPath 设置路径
0xFF // high bit always set Abort abort the current operation.
0x05 to 0x0F Reserved not to be used w/out extension to this specification
0x10 to 0x1F User definable use as you please with peer application
0x00 to 0x0F none reserved
回复中的操作码 说明
0x10 (0x90) 100 继续
0x11 (0x91) 101 Switching Protocols
0x20 (0xA0) 200 成功
0x21 (0xA1) 201 Created
0x22 (0xA2) 202 Accepted
0x23 (0xA3) 203 Non-Authoritative Information
0x24 (0xA4) 204 No Content
0x25 (0xA5) 205 Reset Content
0x26 (0xA6) 206 Partial Content
0x30 (0xB0) 300 Multiple Choices
0x31 (0xB1) 301 Moved Permanently
0x32 (0xB2) 302 Moved temporarily
0x33 (0xB3) 303 See Other
0x34 (0xB4) 304 Not modified
0x35 (0xB5) 305 Use Proxy
0x40 (0xC0) 400 Bad Request - server couldn’t understand request
0x41 (0xC1) 401 Unauthorized
0x42 (0xC2) 402 Payment required
0x43 (0xC3) 403 Forbidden - operation is understood but refused
0x44 (0xC4) 404 Not Found
0x45 (0xC5) 405 Method not allowed
0x46 (0xC6) 406 Not Acceptable
0x47 (0xC7) 407 Proxy Authentication required
0x48 (0xC8) 408 Request Time Out
0x49 (0xC9) 409 Conflict
0x4A (0xCA) 410 Gone
0x4B (0xCB) 411 Length Required
0x4C (0xCC) 412 Precondition failed
0x4D (0xCD) 413 Requested entity too large
0x4E (0xCE) 414 Request URL too large
0x4F (0xCF) 415 Unsupported media type
0x60 (0xE0) 500 Internal Server Error
0x61 (0xE1) 501 Not Implemented
0x62 (0xE2) 502 Bad Gateway
0x63 (0xE3) 503 Service Unavailable
0x64 (0xE4) 504 Gateway Timeout
0x65 (0xE5) 505
其实和Ftp-link的传输协议有点相似
在数据区中又有一些格式
数据区中可以只包含一条信息
也可包含多条信息
信息代码 名称 数据类型 描述
0xC0 Count long 传输对象的数据包数 (在请求连接时使用)
0x01 Name string 传输对象的名称 (通常是文件名)
0x42 Type char 传输对象的类型
0xC3 Length long 传输对象的长度
0x44 Time ? 时间 ISO8601
0xC4 Time long date/time stamp - 4byte version (for compatibility only)
0x05 Description string 传输对象的文本描述
0x46 Target ? name of service that operation is targeted to
0x47 HTTP ? an HTTP 1.x header
0x48 Body ? 传输对象的一个包
0x49 End of Body ? 传输对象的最后一个包
0x4A Who ? identifies the application using OBEX - used in Connect to tell if talking to a peer
0x0B-0x2Freserved ? this range includes all combinations of the upper 2 bits
0x30-0x3user defined? this range includes all combinations of the upper 2 bits
以下是接头方式
请求端发送
0x80 //请求连接
0xhhhh//数据包长度
0xhh //OBEX版本 0x10表示1.0
0x00 //标志位 flags, all zero for this version of OBEX
0xhhhh//最大可发送数据包长度
接收端回复
0xA0 //成功
0xhhhh//数据包长度
0xhh //OBEX版本
0x00 //标志位
0xhhhh//最大可接收数据包长度
.......(开始传输)
我表达能力有限,再加上我对这个协议的细节还没完全看明白,说了这么多,
或许你的只是了解一点点,我拿出两个例子来让大家更明白
请求端发送
0x80
0x0007
0x10
0x01flags
0x2000
接收端回复
0xA0
0x07
0x11
0x00
0x0400
请求端发送
0x02
0x0422
0x01 //HI for Name
0x000D //Length of Name header
xx.txt/0 //name of object, null terminated
0xC3 // HI for Length
0x00006000//Length of object is 0x6000 bytes
0x48 //HI for Object Body chunk
0x0403 //Length of body header (1K) plus HI and header length
0x..........//1K bytes of body
接收端回复:
0x90
0x0003
请求端发送
0x02 //Put, Final bit not set
0x0406 //1030 bytes is length of packet
0x48 //HI for Object Body chunk
0x0403 //Length of body header (1K) plus HI and header length
0x..........//next 1K bytes of body
接收端回复
0x90
0x0003
一直到最后一块
请求端发送
0x82 //Put, Final bit set
0x0406 //1030 bytes is length of packet
0x49 //HI for final Object Body chunk
0x0403 //Length of body header (1K) plus HI and header length
0x..........//next 1K bytes of body
接收端回复
0xA0
0x0003
这样就成功发送完毕
好,现在我们知道了OBEX协议的部分内容
但还有一个重要的问题没有解决
那就是如何握手,我现在也一直搞不清
我需要解决的问题
1.如何握手
2.NC3000的红外代码
3.WQX的传输协议
4.01页nor函数的意思
不知有谁愿意帮我,我将不胜感激
QQ:280071966
MAIL:gt945@163.com 我回答一下如何握手。
既然是红外通讯协议,那就不仅仅是obex协议了,obex只是红外协议的一部分,是负责文件传输的。
在obex协议的下面,还有irttp协议,irlmp协议,irlap协议,irphy协议。当然,红外协议不仅仅是这几个协议,但是要完成一个通用的文件传输功能,这几个协议是必须的。
irphy协议是物理层协议,物理层负责把一个数据调制成红外脉冲信号。wqx已经有了。
irlap协议是连接访问层协议,提供连接制定,数据转移,流控制功能,握手就在这层实现。
irlmp协议是连接链接管理协议,主要起复用的功能,还提供了ias。
irttp协议是微小传输协议,负责把大数据分成多个小的数据。
协议栈结构是这样的
obex (对象交换层)
|
irttp (微小传输层)
|
irlmp (连接管理层)
|
irlap (连接访问层)
|
irphy(物理层)
握手的过程是两设备先发现对方。然后建立连接,这个时候完成了简单的数据交换,双方均知道对方的数据速率,数据尺寸,窗口尺寸,连接断开阀值等参数。这个过程后就可以以新的速率开始传输数据了。并且已经建立了一个irlap连接。
具体到数据
master:0xff 0x3f 0x01 0x29 0x23 0xbe 0x84 0xff 0xff 0xff 0xff 0x01 0x00 (xid command)
slave:0xfe 0xbf 0x01 0xab 0xcd 0x12 0x34 0x29 0x23 0xbe 0x84 0x01 0x00 0x00 0x82 0x04 0x00 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x20 (xid response)
master:0xff 0x3f 0x01 0x29 0x23 0xbe 0x84 0xff 0xff 0xff 0xff 0x01 0x01
0xff 0x3f 0x01 0x29 0x23 0xbe 0x84 0xff 0xff 0xff 0xff 0x01 0x02
0xff 0x3f 0x01 0x29 0x23 0xbe 0x84 0xff 0xff 0xff 0xff 0x01 0x03
0xff 0x3f 0x01 0x29 0x23 0xbe 0x84 0xff 0xff 0xff 0xff 0x01 0x04
master:FF 93 29 23 BE 84 AB CD 12 34 70 01 01 3E 82 01 01 83 01 3F 84 01 7F 85 01 80 86 01 1F 08 01 07 (snrm command)
slave:70 73 AB CD 12 34 23 29 BE 84 01 01 02 82 01 01 83 01 01 84 01 01 85 01 01 86 01 01 08 01 01 (ua response)
......
......
以上握手已经完成
每一层协议都遵循一定的祯格式,这个你可以看红外官方协议栈datasheet,上面有详细的说明。
[ 本帖最后由 donfz 于 2007-11-7 23:04 编辑 ] 真的么,强悍。。。 非常感谢,看来很复杂,那可不可以修改wqx内部程序来实现?01页nor个各函数具体意义又是什么? 不清楚wqx与手机之间是如何传输图片和铃声的,我想大概用的是图片传输协议,该协议层位于微小传输协议(irttp)之上,那么理论上就应该也有irlap和irlmp协议.因为irttp的数据必须通过irlmp层打包,而irlmp的数据又必须通过irlap打包,然后才能通过irphy层打包传出去.
所以你修改wqx内部的程序也许可以实现.
01页nor个各函数具体意义我不知道,因为wqx早就不见了...... 不好意思,偶不懂的:funk: 看\得我都有点晕了 太麻烦了,不干了 这个帖子谈的东西真是空中楼阁…… dingdingding:) :lol :lol 这样一来
让wqx实现不同红外传输协议就成为了可能
不知道研究一下手机管理器会不会有收获……
页:
[1]