iforce-protocol.rst 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. ===============
  2. Iforce Protocol
  3. ===============
  4. :Author: Johann Deneux <johann.deneux@gmail.com>
  5. Home page at `<http://web.archive.org/web/*/http://www.esil.univ-mrs.fr>`_
  6. :Additions: by Vojtech Pavlik.
  7. Introduction
  8. ============
  9. This document describes what I managed to discover about the protocol used to
  10. specify force effects to I-Force 2.0 devices. None of this information comes
  11. from Immerse. That's why you should not trust what is written in this
  12. document. This document is intended to help understanding the protocol.
  13. This is not a reference. Comments and corrections are welcome. To contact me,
  14. send an email to: johann.deneux@gmail.com
  15. .. warning::
  16. I shall not be held responsible for any damage or harm caused if you try to
  17. send data to your I-Force device based on what you read in this document.
  18. Preliminary Notes
  19. =================
  20. All values are hexadecimal with big-endian encoding (msb on the left). Beware,
  21. values inside packets are encoded using little-endian. Bytes whose roles are
  22. unknown are marked ??? Information that needs deeper inspection is marked (?)
  23. General form of a packet
  24. ------------------------
  25. This is how packets look when the device uses the rs232 to communicate.
  26. == == === ==== ==
  27. 2B OP LEN DATA CS
  28. == == === ==== ==
  29. CS is the checksum. It is equal to the exclusive or of all bytes.
  30. When using USB:
  31. == ====
  32. OP DATA
  33. == ====
  34. The 2B, LEN and CS fields have disappeared, probably because USB handles
  35. frames and data corruption is handled or unsignificant.
  36. First, I describe effects that are sent by the device to the computer
  37. Device input state
  38. ==================
  39. This packet is used to indicate the state of each button and the value of each
  40. axis::
  41. OP= 01 for a joystick, 03 for a wheel
  42. LEN= Varies from device to device
  43. 00 X-Axis lsb
  44. 01 X-Axis msb
  45. 02 Y-Axis lsb, or gas pedal for a wheel
  46. 03 Y-Axis msb, or brake pedal for a wheel
  47. 04 Throttle
  48. 05 Buttons
  49. 06 Lower 4 bits: Buttons
  50. Upper 4 bits: Hat
  51. 07 Rudder
  52. Device effects states
  53. =====================
  54. ::
  55. OP= 02
  56. LEN= Varies
  57. 00 ? Bit 1 (Value 2) is the value of the deadman switch
  58. 01 Bit 8 is set if the effect is playing. Bits 0 to 7 are the effect id.
  59. 02 ??
  60. 03 Address of parameter block changed (lsb)
  61. 04 Address of parameter block changed (msb)
  62. 05 Address of second parameter block changed (lsb)
  63. ... depending on the number of parameter blocks updated
  64. Force effect
  65. ------------
  66. ::
  67. OP= 01
  68. LEN= 0e
  69. 00 Channel (when playing several effects at the same time, each must
  70. be assigned a channel)
  71. 01 Wave form
  72. Val 00 Constant
  73. Val 20 Square
  74. Val 21 Triangle
  75. Val 22 Sine
  76. Val 23 Sawtooth up
  77. Val 24 Sawtooth down
  78. Val 40 Spring (Force = f(pos))
  79. Val 41 Friction (Force = f(velocity)) and Inertia
  80. (Force = f(acceleration))
  81. 02 Axes affected and trigger
  82. Bits 4-7: Val 2 = effect along one axis. Byte 05 indicates direction
  83. Val 4 = X axis only. Byte 05 must contain 5a
  84. Val 8 = Y axis only. Byte 05 must contain b4
  85. Val c = X and Y axes. Bytes 05 must contain 60
  86. Bits 0-3: Val 0 = No trigger
  87. Val x+1 = Button x triggers the effect
  88. When the whole byte is 0, cancel the previously set trigger
  89. 03-04 Duration of effect (little endian encoding, in ms)
  90. 05 Direction of effect, if applicable. Else, see 02 for value to assign.
  91. 06-07 Minimum time between triggering.
  92. 08-09 Address of periodicity or magnitude parameters
  93. 0a-0b Address of attack and fade parameters, or ffff if none.
  94. *or*
  95. 08-09 Address of interactive parameters for X-axis,
  96. or ffff if not applicable
  97. 0a-0b Address of interactive parameters for Y-axis,
  98. or ffff if not applicable
  99. 0c-0d Delay before execution of effect (little endian encoding, in ms)
  100. Time based parameters
  101. ---------------------
  102. Attack and fade
  103. ^^^^^^^^^^^^^^^
  104. ::
  105. OP= 02
  106. LEN= 08
  107. 00-01 Address where to store the parameters
  108. 02-03 Duration of attack (little endian encoding, in ms)
  109. 04 Level at end of attack. Signed byte.
  110. 05-06 Duration of fade.
  111. 07 Level at end of fade.
  112. Magnitude
  113. ^^^^^^^^^
  114. ::
  115. OP= 03
  116. LEN= 03
  117. 00-01 Address
  118. 02 Level. Signed byte.
  119. Periodicity
  120. ^^^^^^^^^^^
  121. ::
  122. OP= 04
  123. LEN= 07
  124. 00-01 Address
  125. 02 Magnitude. Signed byte.
  126. 03 Offset. Signed byte.
  127. 04 Phase. Val 00 = 0 deg, Val 40 = 90 degs.
  128. 05-06 Period (little endian encoding, in ms)
  129. Interactive parameters
  130. ----------------------
  131. ::
  132. OP= 05
  133. LEN= 0a
  134. 00-01 Address
  135. 02 Positive Coeff
  136. 03 Negative Coeff
  137. 04+05 Offset (center)
  138. 06+07 Dead band (Val 01F4 = 5000 (decimal))
  139. 08 Positive saturation (Val 0a = 1000 (decimal) Val 64 = 10000 (decimal))
  140. 09 Negative saturation
  141. The encoding is a bit funny here: For coeffs, these are signed values. The
  142. maximum value is 64 (100 decimal), the min is 9c.
  143. For the offset, the minimum value is FE0C, the maximum value is 01F4.
  144. For the deadband, the minimum value is 0, the max is 03E8.
  145. Controls
  146. --------
  147. ::
  148. OP= 41
  149. LEN= 03
  150. 00 Channel
  151. 01 Start/Stop
  152. Val 00: Stop
  153. Val 01: Start and play once.
  154. Val 41: Start and play n times (See byte 02 below)
  155. 02 Number of iterations n.
  156. Init
  157. ----
  158. Querying features
  159. ^^^^^^^^^^^^^^^^^
  160. ::
  161. OP= ff
  162. Query command. Length varies according to the query type.
  163. The general format of this packet is:
  164. ff 01 QUERY [INDEX] CHECKSUM
  165. responses are of the same form:
  166. FF LEN QUERY VALUE_QUERIED CHECKSUM2
  167. where LEN = 1 + length(VALUE_QUERIED)
  168. Query ram size
  169. ~~~~~~~~~~~~~~
  170. ::
  171. QUERY = 42 ('B'uffer size)
  172. The device should reply with the same packet plus two additional bytes
  173. containing the size of the memory:
  174. ff 03 42 03 e8 CS would mean that the device has 1000 bytes of ram available.
  175. Query number of effects
  176. ~~~~~~~~~~~~~~~~~~~~~~~
  177. ::
  178. QUERY = 4e ('N'umber of effects)
  179. The device should respond by sending the number of effects that can be played
  180. at the same time (one byte)
  181. ff 02 4e 14 CS would stand for 20 effects.
  182. Vendor's id
  183. ~~~~~~~~~~~
  184. ::
  185. QUERY = 4d ('M'anufacturer)
  186. Query the vendors'id (2 bytes)
  187. Product id
  188. ~~~~~~~~~~
  189. ::
  190. QUERY = 50 ('P'roduct)
  191. Query the product id (2 bytes)
  192. Open device
  193. ~~~~~~~~~~~
  194. ::
  195. QUERY = 4f ('O'pen)
  196. No data returned.
  197. Close device
  198. ~~~~~~~~~~~~
  199. ::
  200. QUERY = 43 ('C')lose
  201. No data returned.
  202. Query effect
  203. ~~~~~~~~~~~~
  204. ::
  205. QUERY = 45 ('E')
  206. Send effect type.
  207. Returns nonzero if supported (2 bytes)
  208. Firmware Version
  209. ~~~~~~~~~~~~~~~~
  210. ::
  211. QUERY = 56 ('V'ersion)
  212. Sends back 3 bytes - major, minor, subminor
  213. Initialisation of the device
  214. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  215. Set Control
  216. ~~~~~~~~~~~
  217. .. note::
  218. Device dependent, can be different on different models!
  219. ::
  220. OP= 40 <idx> <val> [<val>]
  221. LEN= 2 or 3
  222. 00 Idx
  223. Idx 00 Set dead zone (0..2048)
  224. Idx 01 Ignore Deadman sensor (0..1)
  225. Idx 02 Enable comm watchdog (0..1)
  226. Idx 03 Set the strength of the spring (0..100)
  227. Idx 04 Enable or disable the spring (0/1)
  228. Idx 05 Set axis saturation threshold (0..2048)
  229. Set Effect State
  230. ~~~~~~~~~~~~~~~~
  231. ::
  232. OP= 42 <val>
  233. LEN= 1
  234. 00 State
  235. Bit 3 Pause force feedback
  236. Bit 2 Enable force feedback
  237. Bit 0 Stop all effects
  238. Set overall
  239. ~~~~~~~~~~~
  240. ::
  241. OP= 43 <val>
  242. LEN= 1
  243. 00 Gain
  244. Val 00 = 0%
  245. Val 40 = 50%
  246. Val 80 = 100%
  247. Parameter memory
  248. ----------------
  249. Each device has a certain amount of memory to store parameters of effects.
  250. The amount of RAM may vary, I encountered values from 200 to 1000 bytes. Below
  251. is the amount of memory apparently needed for every set of parameters:
  252. - period : 0c
  253. - magnitude : 02
  254. - attack and fade : 0e
  255. - interactive : 08
  256. Appendix: How to study the protocol?
  257. ====================================
  258. 1. Generate effects using the force editor provided with the DirectX SDK, or
  259. use Immersion Studio (freely available at their web site in the developer section:
  260. www.immersion.com)
  261. 2. Start a soft spying RS232 or USB (depending on where you connected your
  262. joystick/wheel). I used ComPortSpy from fCoder (alpha version!)
  263. 3. Play the effect, and watch what happens on the spy screen.
  264. A few words about ComPortSpy:
  265. At first glance, this software seems, hum, well... buggy. In fact, data appear with a
  266. few seconds latency. Personally, I restart it every time I play an effect.
  267. Remember it's free (as in free beer) and alpha!
  268. URLS
  269. ====
  270. Check http://www.immerse.com for Immersion Studio,
  271. and http://www.fcoder.com for ComPortSpy.
  272. I-Force is trademark of Immersion Corp.