10. Iforce 协议¶
- 作者:
Johann Deneux <johann.deneux@gmail.com>
主页地址:http://web.archive.org/web/*/http://www.esil.univ-mrs.fr
- 补充内容:
由 Vojtech Pavlik。
10.1. 简介¶
本文档描述了我对用于指定力反馈效果到 I-Force 2.0 设备的协议所发现的信息。所有这些信息均非来自 Immerse 公司。因此,您不应完全相信本文档中的内容。本文档旨在帮助理解该协议,并非参考资料。欢迎提供评论和更正。要联系我,请发送电子邮件至:johann.deneux@gmail.com
警告
如果您尝试根据本文档中的内容向您的 I-Force 设备发送数据,我将不对因此造成的任何损害或伤害负责。
10.2. 预备说明¶
所有值均为十六进制,采用大端编码(最高有效字节在左侧)。请注意,数据包内部的值采用小端编码。作用未知字节标记为“???”。需要进一步检查的信息标记为“(?)"。
10.2.1. 数据包的一般形式¶
当设备使用 RS232 进行通信时,数据包的格式如下。
2B |
OP |
LEN |
DATA |
CS |
CS 是校验和。它等于所有字节的异或运算结果。
使用 USB 时
OP |
DATA |
2B、LEN 和 CS 字段已消失,这可能是因为 USB 处理帧,并且数据损坏已得到处理或不重要。
首先,我描述设备发送给计算机的效果。
10.3. 设备输入状态¶
此数据包用于指示每个按钮的状态和每个轴的值。
OP= 01 for a joystick, 03 for a wheel
LEN= Varies from device to device
00 X-Axis lsb
01 X-Axis msb
02 Y-Axis lsb, or gas pedal for a wheel
03 Y-Axis msb, or brake pedal for a wheel
04 Throttle
05 Buttons
06 Lower 4 bits: Buttons
Upper 4 bits: Hat
07 Rudder
10.4. 设备效果状态¶
OP= 02
LEN= Varies
00 ? Bit 1 (Value 2) is the value of the deadman switch
01 Bit 8 is set if the effect is playing. Bits 0 to 7 are the effect id.
02 ??
03 Address of parameter block changed (lsb)
04 Address of parameter block changed (msb)
05 Address of second parameter block changed (lsb)
... depending on the number of parameter blocks updated
10.4.1. 力反馈效果¶
OP= 01
LEN= 0e
00 Channel (when playing several effects at the same time, each must
be assigned a channel)
01 Wave form
Val 00 Constant
Val 20 Square
Val 21 Triangle
Val 22 Sine
Val 23 Sawtooth up
Val 24 Sawtooth down
Val 40 Spring (Force = f(pos))
Val 41 Friction (Force = f(velocity)) and Inertia
(Force = f(acceleration))
02 Axes affected and trigger
Bits 4-7: Val 2 = effect along one axis. Byte 05 indicates direction
Val 4 = X axis only. Byte 05 must contain 5a
Val 8 = Y axis only. Byte 05 must contain b4
Val c = X and Y axes. Bytes 05 must contain 60
Bits 0-3: Val 0 = No trigger
Val x+1 = Button x triggers the effect
When the whole byte is 0, cancel the previously set trigger
03-04 Duration of effect (little endian encoding, in ms)
05 Direction of effect, if applicable. Else, see 02 for value to assign.
06-07 Minimum time between triggering.
08-09 Address of periodicity or magnitude parameters
0a-0b Address of attack and fade parameters, or ffff if none.
*or*
08-09 Address of interactive parameters for X-axis,
or ffff if not applicable
0a-0b Address of interactive parameters for Y-axis,
or ffff if not applicable
0c-0d Delay before execution of effect (little endian encoding, in ms)
10.4.2. 基于时间的参数¶
10.4.2.1. 起效和消退¶
OP= 02
LEN= 08
00-01 Address where to store the parameters
02-03 Duration of attack (little endian encoding, in ms)
04 Level at end of attack. Signed byte.
05-06 Duration of fade.
07 Level at end of fade.
10.4.2.2. 幅度¶
OP= 03
LEN= 03
00-01 Address
02 Level. Signed byte.
10.4.2.3. 周期性¶
OP= 04
LEN= 07
00-01 Address
02 Magnitude. Signed byte.
03 Offset. Signed byte.
04 Phase. Val 00 = 0 deg, Val 40 = 90 degs.
05-06 Period (little endian encoding, in ms)
10.4.3. 交互参数¶
OP= 05
LEN= 0a
00-01 Address
02 Positive Coeff
03 Negative Coeff
04+05 Offset (center)
06+07 Dead band (Val 01F4 = 5000 (decimal))
08 Positive saturation (Val 0a = 1000 (decimal) Val 64 = 10000 (decimal))
09 Negative saturation
这里的编码有点特别:对于系数,它们是带符号的值。最大值为 64(十进制 100),最小值为 9c。对于偏移量,最小值为 FE0C,最大值为 01F4。对于死区,最小值为 0,最大值为 03E8。
10.4.4. 控制¶
OP= 41
LEN= 03
00 Channel
01 Start/Stop
Val 00: Stop
Val 01: Start and play once.
Val 41: Start and play n times (See byte 02 below)
02 Number of iterations n.
10.4.5. 初始化¶
10.4.5.1. 查询特性¶
OP= ff
Query command. Length varies according to the query type.
The general format of this packet is:
ff 01 QUERY [INDEX] CHECKSUM
responses are of the same form:
FF LEN QUERY VALUE_QUERIED CHECKSUM2
where LEN = 1 + length(VALUE_QUERIED)
10.4.5.1.1. 查询内存大小¶
QUERY = 42 ('B'uffer size)
设备应回复相同的数据包,并附加两个字节表示内存大小:ff 03 42 03 e8 CS 表示设备有 1000 字节的可用内存。
10.4.5.1.2. 查询效果数量¶
QUERY = 4e ('N'umber of effects)
设备应回复同时可以播放的效果数量(一个字节):ff 02 4e 14 CS 代表 20 种效果。
10.4.5.1.3. 厂商 ID¶
QUERY = 4d ('M'anufacturer)
查询厂商 ID(2 字节)
10.4.5.1.4. 产品 ID¶
QUERY = 50 ('P'roduct)
查询产品 ID(2 字节)
10.4.5.1.5. 打开设备¶
QUERY = 4f ('O'pen)
无数据返回。
10.4.5.1.6. 关闭设备¶
QUERY = 43 ('C')lose
无数据返回。
10.4.5.1.7. 查询效果¶
QUERY = 45 ('E')
发送效果类型。如果支持则返回非零值(2 字节)。
10.4.5.1.8. 固件版本¶
QUERY = 56 ('V'ersion)
返回 3 字节 - 主版本、次版本、修订版本
10.4.5.2. 设备初始化¶
10.4.5.2.1. 设置控制¶
注意
取决于设备,在不同型号上可能不同!
OP= 40 <idx> <val> [<val>]
LEN= 2 or 3
00 Idx
Idx 00 Set dead zone (0..2048)
Idx 01 Ignore Deadman sensor (0..1)
Idx 02 Enable comm watchdog (0..1)
Idx 03 Set the strength of the spring (0..100)
Idx 04 Enable or disable the spring (0/1)
Idx 05 Set axis saturation threshold (0..2048)
10.4.5.2.2. 设置效果状态¶
OP= 42 <val>
LEN= 1
00 State
Bit 3 Pause force feedback
Bit 2 Enable force feedback
Bit 0 Stop all effects
10.4.5.2.3. 整体设置¶
OP= 43 <val>
LEN= 1
00 Gain
Val 00 = 0%
Val 40 = 50%
Val 80 = 100%
10.4.6. 参数内存¶
每个设备都有一定量的内存来存储效果参数。内存大小可能有所不同,我遇到过 200 到 1000 字节的值。下面是每组参数显然所需的内存量:
周期 : 0c
幅度 : 02
起效和消退 : 0e
交互 : 08
10.5. 附录:如何研究协议?¶
1. 使用 DirectX SDK 提供的力反馈编辑器生成效果,或使用 Immersion Studio(可在其网站的开发者部分免费获取:www.immersion.com)。2. 启动一个 RS232 或 USB 端口监视软件(取决于您连接操纵杆/方向盘的方式)。我使用了 fCoder 的 ComPortSpy(alpha 版本!)。3. 播放效果,并观察监视屏幕上的变化。
关于 ComPortSpy 的几句话:乍一看,这个软件似乎,嗯,有点……buggy。实际上,数据会出现几秒的延迟。就我个人而言,每次播放效果时我都会重启它。请记住它是免费的(如同免费啤酒)且处于 alpha 阶段!
10.6. URLS¶
请访问 http://www.immerse.com 获取 Immersion Studio,访问 http://www.fcoder.com 获取 ComPortSpy。
I-Force 是 Immersion Corp. 的商标。