logic-agent-mcp 0.0.0-stage → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (449) hide show
  1. package/API.cmd +5 -0
  2. package/CAPTURE.cmd +8 -0
  3. package/CHECK.cmd +7 -0
  4. package/FIRMWARE-RECOVER.cmd +6 -0
  5. package/FIRMWARE-STATUS.cmd +8 -0
  6. package/INSTALL-DRIVER.cmd +6 -0
  7. package/INSTALL-MCP.cmd +16 -0
  8. package/LICENSE +31 -0
  9. package/MCP.cmd +5 -0
  10. package/README.md +127 -2
  11. package/SELF-TEST.cmd +6 -0
  12. package/THIRD-PARTY-NOTICES.md +32 -0
  13. package/VERIFY-FILES.cmd +6 -0
  14. package/VERSION.txt +17 -0
  15. package/VIEW.cmd +16 -0
  16. package/checksums.sha256 +449 -0
  17. package/docs/DRIVER.md +54 -0
  18. package/docs/DSLOGIC-PLUS.md +180 -0
  19. package/docs/FIRMWARE.md +53 -0
  20. package/docs/INSTALL.md +74 -0
  21. package/docs/MCP-CLIENTS.md +213 -0
  22. package/docs/PROTOCOLS.md +200 -0
  23. package/docs/TROUBLESHOOTING.md +41 -0
  24. package/docs/UPSTREAM-SYNC.md +141 -0
  25. package/docs/WAVEFORM-VIEWER.md +48 -0
  26. package/firmware/DSLogicPlus.fw +0 -0
  27. package/firmware/LICENSE-DreamSourceLab.txt +20 -0
  28. package/launcher/logic-agent-mcp.mjs +106 -0
  29. package/package.json +56 -6
  30. package/runtime/app/logic_agent/__init__.py +4 -0
  31. package/runtime/app/logic_agent/analysis.py +84 -0
  32. package/runtime/app/logic_agent/backends/__init__.py +7 -0
  33. package/runtime/app/logic_agent/backends/base.py +37 -0
  34. package/runtime/app/logic_agent/backends/dslab.py +278 -0
  35. package/runtime/app/logic_agent/backends/mock.py +101 -0
  36. package/runtime/app/logic_agent/backends/sigrok.py +252 -0
  37. package/runtime/app/logic_agent/cli.py +387 -0
  38. package/runtime/app/logic_agent/decoders.py +868 -0
  39. package/runtime/app/logic_agent/errors.py +50 -0
  40. package/runtime/app/logic_agent/importer.py +129 -0
  41. package/runtime/app/logic_agent/mcp_clients.py +956 -0
  42. package/runtime/app/logic_agent/mcp_server.py +345 -0
  43. package/runtime/app/logic_agent/models.py +150 -0
  44. package/runtime/app/logic_agent/protocols.py +233 -0
  45. package/runtime/app/logic_agent/service.py +378 -0
  46. package/runtime/app/logic_agent/signal.py +206 -0
  47. package/runtime/app/logic_agent/store.py +197 -0
  48. package/runtime/bin/_bz2.pyd +0 -0
  49. package/runtime/bin/_ctypes.pyd +0 -0
  50. package/runtime/bin/_decimal.pyd +0 -0
  51. package/runtime/bin/_elementtree.pyd +0 -0
  52. package/runtime/bin/_hashlib.pyd +0 -0
  53. package/runtime/bin/_lzma.pyd +0 -0
  54. package/runtime/bin/_multiprocessing.pyd +0 -0
  55. package/runtime/bin/_socket.pyd +0 -0
  56. package/runtime/bin/_sqlite3.pyd +0 -0
  57. package/runtime/bin/_ssl.pyd +0 -0
  58. package/runtime/bin/dslab.exe +0 -0
  59. package/runtime/bin/libglib-2.0-0.dll +0 -0
  60. package/runtime/bin/libiconv-2.dll +0 -0
  61. package/runtime/bin/libintl-8.dll +0 -0
  62. package/runtime/bin/libpcre2-8-0.dll +0 -0
  63. package/runtime/bin/libusb-1.0.dll +0 -0
  64. package/runtime/bin/libwinpthread-1.dll +0 -0
  65. package/runtime/bin/libz-1.dll +0 -0
  66. package/runtime/bin/msvcp100.dll +0 -0
  67. package/runtime/bin/msvcr100.dll +0 -0
  68. package/runtime/bin/pyexpat.pyd +0 -0
  69. package/runtime/bin/python34.dll +0 -0
  70. package/runtime/bin/python34.zip +0 -0
  71. package/runtime/bin/res/DSCope.bin +0 -0
  72. package/runtime/bin/res/DSCope.fw +0 -0
  73. package/runtime/bin/res/DSCope1.def.dsc +88 -0
  74. package/runtime/bin/res/DSCope2.def.dsc +54 -0
  75. package/runtime/bin/res/DSCope20.bin +0 -0
  76. package/runtime/bin/res/DSCope20.fw +0 -0
  77. package/runtime/bin/res/DSCopeC20B.bin +0 -0
  78. package/runtime/bin/res/DSCopeC20P.bin +0 -0
  79. package/runtime/bin/res/DSCopeU2B100.bin +0 -0
  80. package/runtime/bin/res/DSCopeU2B20.bin +0 -0
  81. package/runtime/bin/res/DSCopeU2P20.bin +0 -0
  82. package/runtime/bin/res/DSCopeU3P100.bin +0 -0
  83. package/runtime/bin/res/DSLogic.fw +0 -0
  84. package/runtime/bin/res/DSLogic0.def.dsc +297 -0
  85. package/runtime/bin/res/DSLogic1.def.dsc +82 -0
  86. package/runtime/bin/res/DSLogic2.def.dsc +52 -0
  87. package/runtime/bin/res/DSLogic33.bin +0 -0
  88. package/runtime/bin/res/DSLogic50.bin +0 -0
  89. package/runtime/bin/res/DSLogicBasic.bin +0 -0
  90. package/runtime/bin/res/DSLogicPlus-pgl12-2.bin +0 -0
  91. package/runtime/bin/res/DSLogicPlus-pgl12.bin +0 -0
  92. package/runtime/bin/res/DSLogicPlus.bin +0 -0
  93. package/runtime/bin/res/DSLogicPlus.fw +0 -0
  94. package/runtime/bin/res/DSLogicPro.bin +0 -0
  95. package/runtime/bin/res/DSLogicPro.fw +0 -0
  96. package/runtime/bin/res/DSLogicU2Basic-pgl12-2.bin +0 -0
  97. package/runtime/bin/res/DSLogicU2Basic-pgl12.bin +0 -0
  98. package/runtime/bin/res/DSLogicU2Basic.bin +0 -0
  99. package/runtime/bin/res/DSLogicU2Pro16.bin +0 -0
  100. package/runtime/bin/res/DSLogicU3Pro16.bin +0 -0
  101. package/runtime/bin/res/DSLogicU3Pro32.bin +0 -0
  102. package/runtime/bin/res/license.txt +20 -0
  103. package/runtime/bin/res/virtual-demo1.dsc +68 -0
  104. package/runtime/bin/select.pyd +0 -0
  105. package/runtime/bin/sigrok-cli.exe +0 -0
  106. package/runtime/bin/unicodedata.pyd +0 -0
  107. package/runtime/bin/winsound.pyd +0 -0
  108. package/runtime/decoders/ac97/__init__.py +38 -0
  109. package/runtime/decoders/ac97/pd.py +477 -0
  110. package/runtime/decoders/ad5626/__init__.py +25 -0
  111. package/runtime/decoders/ad5626/pd.py +62 -0
  112. package/runtime/decoders/ad79x0/__init__.py +25 -0
  113. package/runtime/decoders/ad79x0/pd.py +137 -0
  114. package/runtime/decoders/ade77xx/__init__.py +31 -0
  115. package/runtime/decoders/ade77xx/lists.py +102 -0
  116. package/runtime/decoders/ade77xx/pd.py +131 -0
  117. package/runtime/decoders/adf435x/__init__.py +29 -0
  118. package/runtime/decoders/adf435x/pd.py +230 -0
  119. package/runtime/decoders/adns5020/__init__.py +27 -0
  120. package/runtime/decoders/adns5020/pd.py +116 -0
  121. package/runtime/decoders/adxl345/__init__.py +26 -0
  122. package/runtime/decoders/adxl345/lists.py +96 -0
  123. package/runtime/decoders/adxl345/pd.py +453 -0
  124. package/runtime/decoders/am230x/__init__.py +36 -0
  125. package/runtime/decoders/am230x/pd.py +229 -0
  126. package/runtime/decoders/amulet_ascii/__init__.py +28 -0
  127. package/runtime/decoders/amulet_ascii/lists.py +73 -0
  128. package/runtime/decoders/amulet_ascii/pd.py +699 -0
  129. package/runtime/decoders/arm_etmv3/__init__.py +25 -0
  130. package/runtime/decoders/arm_etmv3/pd.py +567 -0
  131. package/runtime/decoders/arm_itm/__init__.py +25 -0
  132. package/runtime/decoders/arm_itm/pd.py +373 -0
  133. package/runtime/decoders/arm_tpiu/__init__.py +28 -0
  134. package/runtime/decoders/arm_tpiu/pd.py +131 -0
  135. package/runtime/decoders/atsha204a/__init__.py +30 -0
  136. package/runtime/decoders/atsha204a/pd.py +323 -0
  137. package/runtime/decoders/aud/__init__.py +31 -0
  138. package/runtime/decoders/aud/pd.py +108 -0
  139. package/runtime/decoders/avr_isp/__init__.py +25 -0
  140. package/runtime/decoders/avr_isp/parts.py +163 -0
  141. package/runtime/decoders/avr_isp/pd.py +278 -0
  142. package/runtime/decoders/avr_pdi/__init__.py +42 -0
  143. package/runtime/decoders/avr_pdi/pd.py +574 -0
  144. package/runtime/decoders/caliper/__init__.py +36 -0
  145. package/runtime/decoders/caliper/pd.py +146 -0
  146. package/runtime/decoders/can/__init__.py +31 -0
  147. package/runtime/decoders/can/pd.py +519 -0
  148. package/runtime/decoders/cc1101/__init__.py +28 -0
  149. package/runtime/decoders/cc1101/lists.py +115 -0
  150. package/runtime/decoders/cc1101/pd.py +294 -0
  151. package/runtime/decoders/cec/__init__.py +25 -0
  152. package/runtime/decoders/cec/pd.py +311 -0
  153. package/runtime/decoders/cec/protocoldata.py +117 -0
  154. package/runtime/decoders/cfp/__init__.py +34 -0
  155. package/runtime/decoders/cfp/pd.py +110 -0
  156. package/runtime/decoders/cjtag/__init__.py +36 -0
  157. package/runtime/decoders/cjtag/pd.py +323 -0
  158. package/runtime/decoders/common/__init__.py +19 -0
  159. package/runtime/decoders/common/plugtrx/__init__.py +20 -0
  160. package/runtime/decoders/common/plugtrx/mod.py +192 -0
  161. package/runtime/decoders/common/sdcard/__init__.py +20 -0
  162. package/runtime/decoders/common/sdcard/mod.py +150 -0
  163. package/runtime/decoders/common/srdhelper/__init__.py +20 -0
  164. package/runtime/decoders/common/srdhelper/mod.py +98 -0
  165. package/runtime/decoders/counter/__init__.py +28 -0
  166. package/runtime/decoders/counter/pd.py +145 -0
  167. package/runtime/decoders/dali/__init__.py +24 -0
  168. package/runtime/decoders/dali/lists.py +98 -0
  169. package/runtime/decoders/dali/pd.py +244 -0
  170. package/runtime/decoders/dcf77/__init__.py +28 -0
  171. package/runtime/decoders/dcf77/pd.py +311 -0
  172. package/runtime/decoders/dmx512/__init__.py +25 -0
  173. package/runtime/decoders/dmx512/pd.py +361 -0
  174. package/runtime/decoders/ds1307/__init__.py +25 -0
  175. package/runtime/decoders/ds1307/pd.py +270 -0
  176. package/runtime/decoders/ds2408/__init__.py +25 -0
  177. package/runtime/decoders/ds2408/pd.py +129 -0
  178. package/runtime/decoders/ds243x/__init__.py +25 -0
  179. package/runtime/decoders/ds243x/pd.py +270 -0
  180. package/runtime/decoders/ds28ea00/__init__.py +25 -0
  181. package/runtime/decoders/ds28ea00/pd.py +93 -0
  182. package/runtime/decoders/dsi/__init__.py +24 -0
  183. package/runtime/decoders/dsi/pd.py +157 -0
  184. package/runtime/decoders/edid/__init__.py +35 -0
  185. package/runtime/decoders/edid/pd.py +671 -0
  186. package/runtime/decoders/edid/pnpids.txt +2135 -0
  187. package/runtime/decoders/eeprom24xx/__init__.py +25 -0
  188. package/runtime/decoders/eeprom24xx/lists.py +214 -0
  189. package/runtime/decoders/eeprom24xx/pd.py +443 -0
  190. package/runtime/decoders/eeprom93xx/__init__.py +32 -0
  191. package/runtime/decoders/eeprom93xx/pd.py +163 -0
  192. package/runtime/decoders/em4100/__init__.py +24 -0
  193. package/runtime/decoders/em4100/pd.py +238 -0
  194. package/runtime/decoders/em4305/__init__.py +24 -0
  195. package/runtime/decoders/em4305/pd.py +394 -0
  196. package/runtime/decoders/enc28j60/__init__.py +32 -0
  197. package/runtime/decoders/enc28j60/lists.py +161 -0
  198. package/runtime/decoders/enc28j60/pd.py +294 -0
  199. package/runtime/decoders/flexray/__init__.py +32 -0
  200. package/runtime/decoders/flexray/pd.py +413 -0
  201. package/runtime/decoders/graycode/__init__.py +24 -0
  202. package/runtime/decoders/graycode/pd.py +197 -0
  203. package/runtime/decoders/guess_bitrate/__init__.py +40 -0
  204. package/runtime/decoders/guess_bitrate/pd.py +79 -0
  205. package/runtime/decoders/hdcp/__init__.py +27 -0
  206. package/runtime/decoders/hdcp/pd.py +191 -0
  207. package/runtime/decoders/i2c/__init__.py +25 -0
  208. package/runtime/decoders/i2c/pd.py +364 -0
  209. package/runtime/decoders/i2cdemux/__init__.py +27 -0
  210. package/runtime/decoders/i2cdemux/pd.py +80 -0
  211. package/runtime/decoders/i2cfilter/__init__.py +37 -0
  212. package/runtime/decoders/i2cfilter/pd.py +106 -0
  213. package/runtime/decoders/i2s/__init__.py +29 -0
  214. package/runtime/decoders/i2s/pd.py +179 -0
  215. package/runtime/decoders/ieee488/__init__.py +26 -0
  216. package/runtime/decoders/ieee488/pd.py +849 -0
  217. package/runtime/decoders/ir_irmp/__init__.py +25 -0
  218. package/runtime/decoders/ir_irmp/irmp_library.py +168 -0
  219. package/runtime/decoders/ir_irmp/pd.py +139 -0
  220. package/runtime/decoders/ir_nec/__init__.py +25 -0
  221. package/runtime/decoders/ir_nec/lists.py +93 -0
  222. package/runtime/decoders/ir_nec/pd.py +300 -0
  223. package/runtime/decoders/ir_rc5/__init__.py +24 -0
  224. package/runtime/decoders/ir_rc5/lists.py +93 -0
  225. package/runtime/decoders/ir_rc5/pd.py +182 -0
  226. package/runtime/decoders/ir_rc6/__init__.py +24 -0
  227. package/runtime/decoders/ir_rc6/pd.py +205 -0
  228. package/runtime/decoders/ir_sirc/__init__.py +26 -0
  229. package/runtime/decoders/ir_sirc/lists.py +201 -0
  230. package/runtime/decoders/ir_sirc/pd.py +215 -0
  231. package/runtime/decoders/jitter/__init__.py +29 -0
  232. package/runtime/decoders/jitter/pd.py +198 -0
  233. package/runtime/decoders/jtag/__init__.py +30 -0
  234. package/runtime/decoders/jtag/pd.py +235 -0
  235. package/runtime/decoders/jtag_ejtag/__init__.py +25 -0
  236. package/runtime/decoders/jtag_ejtag/pd.py +408 -0
  237. package/runtime/decoders/jtag_stm32/__init__.py +29 -0
  238. package/runtime/decoders/jtag_stm32/pd.py +269 -0
  239. package/runtime/decoders/lfast/__init__.py +35 -0
  240. package/runtime/decoders/lfast/pd.py +335 -0
  241. package/runtime/decoders/lin/__init__.py +28 -0
  242. package/runtime/decoders/lin/pd.py +247 -0
  243. package/runtime/decoders/lm75/__init__.py +25 -0
  244. package/runtime/decoders/lm75/pd.py +186 -0
  245. package/runtime/decoders/lpc/__init__.py +25 -0
  246. package/runtime/decoders/lpc/pd.py +365 -0
  247. package/runtime/decoders/ltc242x/__init__.py +25 -0
  248. package/runtime/decoders/ltc242x/pd.py +86 -0
  249. package/runtime/decoders/ltc26x7/__init__.py +25 -0
  250. package/runtime/decoders/ltc26x7/pd.py +187 -0
  251. package/runtime/decoders/maple_bus/__init__.py +25 -0
  252. package/runtime/decoders/maple_bus/pd.py +222 -0
  253. package/runtime/decoders/max72xx/__init__.py +25 -0
  254. package/runtime/decoders/max72xx/pd.py +130 -0
  255. package/runtime/decoders/mcp230xx/__init__.py +25 -0
  256. package/runtime/decoders/mcp230xx/pd.py +143 -0
  257. package/runtime/decoders/mcs48/__init__.py +31 -0
  258. package/runtime/decoders/mcs48/pd.py +126 -0
  259. package/runtime/decoders/mdio/__init__.py +39 -0
  260. package/runtime/decoders/mdio/pd.py +325 -0
  261. package/runtime/decoders/microwire/__init__.py +40 -0
  262. package/runtime/decoders/microwire/pd.py +194 -0
  263. package/runtime/decoders/midi/__init__.py +28 -0
  264. package/runtime/decoders/midi/lists.py +840 -0
  265. package/runtime/decoders/midi/pd.py +627 -0
  266. package/runtime/decoders/miller/__init__.py +26 -0
  267. package/runtime/decoders/miller/pd.py +190 -0
  268. package/runtime/decoders/mlx90614/__init__.py +25 -0
  269. package/runtime/decoders/mlx90614/pd.py +82 -0
  270. package/runtime/decoders/modbus/__init__.py +28 -0
  271. package/runtime/decoders/modbus/pd.py +941 -0
  272. package/runtime/decoders/morse/__init__.py +28 -0
  273. package/runtime/decoders/morse/pd.py +250 -0
  274. package/runtime/decoders/mrf24j40/__init__.py +25 -0
  275. package/runtime/decoders/mrf24j40/lists.py +165 -0
  276. package/runtime/decoders/mrf24j40/pd.py +188 -0
  277. package/runtime/decoders/mxc6225xu/__init__.py +28 -0
  278. package/runtime/decoders/mxc6225xu/pd.py +217 -0
  279. package/runtime/decoders/nes_gamepad/__init__.py +54 -0
  280. package/runtime/decoders/nes_gamepad/pd.py +92 -0
  281. package/runtime/decoders/nrf24l01/__init__.py +29 -0
  282. package/runtime/decoders/nrf24l01/pd.py +332 -0
  283. package/runtime/decoders/nrf905/__init__.py +26 -0
  284. package/runtime/decoders/nrf905/pd.py +301 -0
  285. package/runtime/decoders/numbers_and_state/__init__.py +41 -0
  286. package/runtime/decoders/numbers_and_state/pd.py +377 -0
  287. package/runtime/decoders/nunchuk/__init__.py +30 -0
  288. package/runtime/decoders/nunchuk/pd.py +207 -0
  289. package/runtime/decoders/onewire_link/__init__.py +56 -0
  290. package/runtime/decoders/onewire_link/pd.py +347 -0
  291. package/runtime/decoders/onewire_network/__init__.py +56 -0
  292. package/runtime/decoders/onewire_network/pd.py +185 -0
  293. package/runtime/decoders/ook/__init__.py +36 -0
  294. package/runtime/decoders/ook/pd.py +484 -0
  295. package/runtime/decoders/ook_oregon/__init__.py +25 -0
  296. package/runtime/decoders/ook_oregon/lists.py +75 -0
  297. package/runtime/decoders/ook_oregon/pd.py +389 -0
  298. package/runtime/decoders/ook_vis/__init__.py +25 -0
  299. package/runtime/decoders/ook_vis/pd.py +194 -0
  300. package/runtime/decoders/pan1321/__init__.py +25 -0
  301. package/runtime/decoders/pan1321/pd.py +164 -0
  302. package/runtime/decoders/parallel/__init__.py +45 -0
  303. package/runtime/decoders/parallel/pd.py +285 -0
  304. package/runtime/decoders/pca9571/__init__.py +25 -0
  305. package/runtime/decoders/pca9571/pd.py +122 -0
  306. package/runtime/decoders/pjdl/__init__.py +27 -0
  307. package/runtime/decoders/pjdl/pd.py +723 -0
  308. package/runtime/decoders/pjon/__init__.py +25 -0
  309. package/runtime/decoders/pjon/pd.py +603 -0
  310. package/runtime/decoders/ps2/__init__.py +26 -0
  311. package/runtime/decoders/ps2/pd.py +126 -0
  312. package/runtime/decoders/pwm/__init__.py +24 -0
  313. package/runtime/decoders/pwm/pd.py +167 -0
  314. package/runtime/decoders/qi/__init__.py +25 -0
  315. package/runtime/decoders/qi/pd.py +244 -0
  316. package/runtime/decoders/rc_encode/__init__.py +40 -0
  317. package/runtime/decoders/rc_encode/pd.py +215 -0
  318. package/runtime/decoders/rfm12/__init__.py +25 -0
  319. package/runtime/decoders/rfm12/pd.py +497 -0
  320. package/runtime/decoders/rgb_led_spi/__init__.py +25 -0
  321. package/runtime/decoders/rgb_led_spi/pd.py +72 -0
  322. package/runtime/decoders/rgb_led_ws281x/__init__.py +27 -0
  323. package/runtime/decoders/rgb_led_ws281x/pd.py +267 -0
  324. package/runtime/decoders/rtc8564/__init__.py +25 -0
  325. package/runtime/decoders/rtc8564/pd.py +254 -0
  326. package/runtime/decoders/sae_j1850_vpw/__init__.py +24 -0
  327. package/runtime/decoders/sae_j1850_vpw/pd.py +296 -0
  328. package/runtime/decoders/sbus_futaba/__init__.py +35 -0
  329. package/runtime/decoders/sbus_futaba/pd.py +273 -0
  330. package/runtime/decoders/sda2506/__init__.py +24 -0
  331. package/runtime/decoders/sda2506/pd.py +146 -0
  332. package/runtime/decoders/sdcard_sd/__init__.py +24 -0
  333. package/runtime/decoders/sdcard_sd/pd.py +554 -0
  334. package/runtime/decoders/sdcard_spi/__init__.py +68 -0
  335. package/runtime/decoders/sdcard_spi/pd.py +518 -0
  336. package/runtime/decoders/sdq/__init__.py +28 -0
  337. package/runtime/decoders/sdq/pd.py +131 -0
  338. package/runtime/decoders/seven_segment/__init__.py +24 -0
  339. package/runtime/decoders/seven_segment/pd.py +186 -0
  340. package/runtime/decoders/signature/__init__.py +25 -0
  341. package/runtime/decoders/signature/pd.py +142 -0
  342. package/runtime/decoders/sipi/__init__.py +30 -0
  343. package/runtime/decoders/sipi/pd.py +181 -0
  344. package/runtime/decoders/sle44xx/__init__.py +26 -0
  345. package/runtime/decoders/sle44xx/pd.py +541 -0
  346. package/runtime/decoders/smart_qspi/PORTING.md +22 -0
  347. package/runtime/decoders/smart_qspi/__init__.py +1 -0
  348. package/runtime/decoders/smart_qspi/pd.py +826 -0
  349. package/runtime/decoders/spdif/__init__.py +25 -0
  350. package/runtime/decoders/spdif/pd.py +295 -0
  351. package/runtime/decoders/spi/__init__.py +32 -0
  352. package/runtime/decoders/spi/pd.py +347 -0
  353. package/runtime/decoders/spiflash/__init__.py +30 -0
  354. package/runtime/decoders/spiflash/lists.py +178 -0
  355. package/runtime/decoders/spiflash/pd.py +537 -0
  356. package/runtime/decoders/ssi32/__init__.py +28 -0
  357. package/runtime/decoders/ssi32/pd.py +127 -0
  358. package/runtime/decoders/st25r39xx_spi/__init__.py +31 -0
  359. package/runtime/decoders/st25r39xx_spi/lists.py +231 -0
  360. package/runtime/decoders/st25r39xx_spi/pd.py +360 -0
  361. package/runtime/decoders/st7735/__init__.py +27 -0
  362. package/runtime/decoders/st7735/pd.py +173 -0
  363. package/runtime/decoders/stepper_motor/__init__.py +25 -0
  364. package/runtime/decoders/stepper_motor/pd.py +95 -0
  365. package/runtime/decoders/swd/__init__.py +34 -0
  366. package/runtime/decoders/swd/pd.py +350 -0
  367. package/runtime/decoders/swim/__init__.py +28 -0
  368. package/runtime/decoders/swim/pd.py +303 -0
  369. package/runtime/decoders/t55xx/__init__.py +25 -0
  370. package/runtime/decoders/t55xx/pd.py +326 -0
  371. package/runtime/decoders/tca6408a/__init__.py +25 -0
  372. package/runtime/decoders/tca6408a/pd.py +157 -0
  373. package/runtime/decoders/tdm_audio/__init__.py +25 -0
  374. package/runtime/decoders/tdm_audio/pd.py +116 -0
  375. package/runtime/decoders/timing/__init__.py +24 -0
  376. package/runtime/decoders/timing/pd.py +194 -0
  377. package/runtime/decoders/tlc5620/__init__.py +24 -0
  378. package/runtime/decoders/tlc5620/pd.py +212 -0
  379. package/runtime/decoders/uart/__init__.py +40 -0
  380. package/runtime/decoders/uart/pd.py +635 -0
  381. package/runtime/decoders/usb_packet/__init__.py +43 -0
  382. package/runtime/decoders/usb_packet/pd.py +401 -0
  383. package/runtime/decoders/usb_power_delivery/__init__.py +24 -0
  384. package/runtime/decoders/usb_power_delivery/pd.py +642 -0
  385. package/runtime/decoders/usb_request/__init__.py +49 -0
  386. package/runtime/decoders/usb_request/pd.py +386 -0
  387. package/runtime/decoders/usb_signalling/__init__.py +50 -0
  388. package/runtime/decoders/usb_signalling/pd.py +348 -0
  389. package/runtime/decoders/wiegand/__init__.py +28 -0
  390. package/runtime/decoders/wiegand/pd.py +148 -0
  391. package/runtime/decoders/x2444m/__init__.py +25 -0
  392. package/runtime/decoders/x2444m/pd.py +111 -0
  393. package/runtime/decoders/xfp/__init__.py +38 -0
  394. package/runtime/decoders/xfp/pd.py +486 -0
  395. package/runtime/decoders/xy2-100/__init__.py +28 -0
  396. package/runtime/decoders/xy2-100/pd.py +242 -0
  397. package/runtime/decoders/z80/__init__.py +36 -0
  398. package/runtime/decoders/z80/pd.py +358 -0
  399. package/runtime/decoders/z80/tables.py +1083 -0
  400. package/runtime/dslab.cmd +5 -0
  401. package/runtime/licenses/DreamSourceLab-res-MIT.txt +20 -0
  402. package/runtime/licenses/dslab-GPL-3.0.txt +674 -0
  403. package/runtime/licenses/logic-agent-MIT.txt +31 -0
  404. package/runtime/licenses/python-PSF.txt +645 -0
  405. package/runtime/licenses/sigrok-cli-GPL-3.0.txt +674 -0
  406. package/runtime/licenses/smart_qspi-PORTING.md +22 -0
  407. package/runtime/licenses/source/patches/dsview-v1.3.2-dslab.patch +124 -0
  408. package/runtime/logic-agent-mcp.cmd +9 -0
  409. package/runtime/logic-agent.cmd +9 -0
  410. package/runtime/python/LICENSE.txt +645 -0
  411. package/runtime/python/_asyncio.pyd +0 -0
  412. package/runtime/python/_bz2.pyd +0 -0
  413. package/runtime/python/_ctypes.pyd +0 -0
  414. package/runtime/python/_decimal.pyd +0 -0
  415. package/runtime/python/_elementtree.pyd +0 -0
  416. package/runtime/python/_hashlib.pyd +0 -0
  417. package/runtime/python/_lzma.pyd +0 -0
  418. package/runtime/python/_multiprocessing.pyd +0 -0
  419. package/runtime/python/_overlapped.pyd +0 -0
  420. package/runtime/python/_queue.pyd +0 -0
  421. package/runtime/python/_socket.pyd +0 -0
  422. package/runtime/python/_sqlite3.pyd +0 -0
  423. package/runtime/python/_ssl.pyd +0 -0
  424. package/runtime/python/_uuid.pyd +0 -0
  425. package/runtime/python/_wmi.pyd +0 -0
  426. package/runtime/python/_zoneinfo.pyd +0 -0
  427. package/runtime/python/libcrypto-3.dll +0 -0
  428. package/runtime/python/libffi-8.dll +0 -0
  429. package/runtime/python/libssl-3.dll +0 -0
  430. package/runtime/python/pyexpat.pyd +0 -0
  431. package/runtime/python/python.cat +0 -0
  432. package/runtime/python/python.exe +0 -0
  433. package/runtime/python/python3.dll +0 -0
  434. package/runtime/python/python313._pth +3 -0
  435. package/runtime/python/python313.dll +0 -0
  436. package/runtime/python/python313.zip +0 -0
  437. package/runtime/python/pythonw.exe +0 -0
  438. package/runtime/python/select.pyd +0 -0
  439. package/runtime/python/sqlite3.dll +0 -0
  440. package/runtime/python/unicodedata.pyd +0 -0
  441. package/runtime/python/vcruntime140.dll +0 -0
  442. package/runtime/python/vcruntime140_1.dll +0 -0
  443. package/runtime/python/winsound.pyd +0 -0
  444. package/runtime/scripts/deploy-check.ps1 +171 -0
  445. package/scripts/check.ps1 +14 -0
  446. package/scripts/firmware-recover.ps1 +27 -0
  447. package/scripts/install-driver.ps1 +30 -0
  448. package/scripts/self-test.ps1 +14 -0
  449. package/scripts/verify-files.py +39 -0
@@ -0,0 +1,941 @@
1
+ ##
2
+ ## This file is part of the libsigrokdecode project.
3
+ ##
4
+ ## Copyright (C) 2015 Bart de Waal <bart@waalamo.com>
5
+ ##
6
+ ## This program is free software; you can redistribute it and/or modify
7
+ ## it under the terms of the GNU General Public License as published by
8
+ ## the Free Software Foundation; either version 3 of the License, or
9
+ ## (at your option) any later version.
10
+ ##
11
+ ## This program is distributed in the hope that it will be useful,
12
+ ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ ## GNU General Public License for more details.
15
+ ##
16
+ ## You should have received a copy of the GNU General Public License
17
+ ## along with this program; if not, see <http://www.gnu.org/licenses/>.
18
+ ##
19
+
20
+ import sigrokdecode as srd
21
+ from math import ceil
22
+
23
+ RX = 0
24
+ TX = 1
25
+ rxtx_channels = ('RX', 'TX')
26
+
27
+ class No_more_data(Exception):
28
+ '''This exception is a signal that we should stop parsing an ADU as there
29
+ is no more data to parse.'''
30
+ pass
31
+
32
+ class Data:
33
+ '''The Data class is used to hold the bytes from the serial decode.'''
34
+ def __init__(self, start, end, data):
35
+ self.start = start
36
+ self.end = end
37
+ self.data = data
38
+
39
+ class Modbus_ADU:
40
+ '''An Application Data Unit is what Modbus calls one message.
41
+ Protocol decoders are supposed to keep track of state and then provide
42
+ decoded data to the backend as it reads it. In Modbus' case, the state is
43
+ the ADU up to that point. This class represents the state and writes the
44
+ messages to the backend.
45
+ This class is for the common infrastructure between CS and SC. It should
46
+ not be used directly, only inhereted from.'''
47
+
48
+ def __init__(self, parent, start, write_channel, annotation_prefix):
49
+ self.data = [] # List of all the data received up to now
50
+ self.parent = parent # Reference to the decoder object
51
+ self.start = start
52
+ self.last_read = start # The last moment parsed by this ADU object
53
+ self.write_channel = write_channel
54
+ self.last_byte_put = -1
55
+ self.annotation_prefix = annotation_prefix
56
+ # Any Modbus message needs to be at least 4 bytes long. The Modbus
57
+ # function may make this longer.
58
+ self.minimum_length = 4
59
+
60
+ # This variable is used by an external function to determine when the
61
+ # next frame should be started.
62
+ self.startNewFrame = False
63
+
64
+ # If there is an error in a frame, we'd like to highlight it. Keep
65
+ # track of errors.
66
+ self.hasError = False
67
+
68
+ def add_data(self, start, end, data):
69
+ '''Let the frame handle another piece of data.
70
+ start: start of this data
71
+ end: end of this data
72
+ data: data as received from the UART decoder'''
73
+ ptype, rxtx, pdata = data
74
+ self.last_read = end
75
+ if ptype == 'DATA':
76
+ self.data.append(Data(start, end, pdata[0]))
77
+ self.parse() # parse() is defined in the specific type of ADU.
78
+
79
+ def puti(self, byte_to_put, annotation, message):
80
+ '''This class keeps track of how much of the data has already been
81
+ annotated. This function tells the parent class to write message, but
82
+ only if it hasn't written about this bit before.
83
+ byte_to_put: Only write if it hasn't yet written byte_to_put. It will
84
+ write from the start of self.last_byte_put+1 to the end
85
+ of byte_to_put.
86
+ annotation: Annotation to write to, without annotation_prefix.
87
+ message: Message to write.'''
88
+ if byte_to_put > len(self.data) - 1:
89
+ # If the byte_to_put hasn't been read yet.
90
+ raise No_more_data
91
+
92
+ if annotation == 'error':
93
+ self.hasError = True
94
+
95
+ if byte_to_put > self.last_byte_put:
96
+ self.parent.puta(
97
+ self.data[self.last_byte_put + 1].start,
98
+ self.data[byte_to_put].end,
99
+ self.annotation_prefix + annotation,
100
+ message)
101
+ self.last_byte_put = byte_to_put
102
+ raise No_more_data
103
+
104
+ def putl(self, annotation, message, maximum=None):
105
+ '''Puts the last byte on the stack with message. The contents of the
106
+ last byte will be applied to message using format.'''
107
+ last_byte_address = len(self.data) - 1
108
+ if maximum is not None and last_byte_address > maximum:
109
+ return
110
+ self.puti(last_byte_address, annotation,
111
+ message.format(self.data[-1].data))
112
+
113
+ def close(self, message_overflow):
114
+ '''Function to be called when next message is started. As there is
115
+ always space between one message and the next, we can use that space
116
+ for errors at the end.'''
117
+ # TODO: Figure out how to make this happen for last message.
118
+ data = self.data
119
+ if len(data) < self.minimum_length:
120
+ if len(data) == 0:
121
+ # Sometimes happens with noise, safe to ignore.
122
+ return
123
+ self.parent.puta(
124
+ data[self.last_byte_put].end, message_overflow,
125
+ self.annotation_prefix + 'error',
126
+ 'Message too short or not finished')
127
+ self.hasError = True
128
+ if self.hasError and self.parent.options['scchannel'] != self.parent.options['cschannel']:
129
+ # If we are decoding different channels (so client->server and
130
+ # server->client messages can be separated) we like to mark blocks
131
+ # containing errors. We don't do this when decoding the same
132
+ # channel as both a client->server and server->client frame, and
133
+ # one of those is bound to contain an error, making highlighting
134
+ # frames useless.
135
+ self.parent.puta(data[0].start, data[-1].end,
136
+ 'error-indication', 'Frame contains error')
137
+ if len(data) > 256:
138
+ try:
139
+ self.puti(len(data) - 1, 'error',
140
+ 'Modbus data frames are limited to 256 bytes')
141
+ except No_more_data:
142
+ pass
143
+
144
+ def check_crc(self, byte_to_put):
145
+ '''Check the CRC code, data[byte_to_put] is the 2nd byte of the CRC.'''
146
+ crc_byte1, crc_byte2 = self.calc_crc(byte_to_put)
147
+ data = self.data
148
+ if data[-2].data == crc_byte1 and data[-1].data == crc_byte2:
149
+ self.puti(byte_to_put, 'crc', 'CRC correct')
150
+ else:
151
+ self.puti(byte_to_put, 'error',
152
+ 'CRC should be {} {}'.format(crc_byte1, crc_byte2))
153
+
154
+ def half_word(self, start):
155
+ '''Return the half word (16 bit) value starting at start bytes in. If
156
+ it goes out of range it raises the usual errors.'''
157
+ if (start + 1) > (len(self.data) - 1):
158
+ # If there isn't enough length to access data[start + 1].
159
+ raise No_more_data
160
+ return self.data[start].data * 0x100 + self.data[start + 1].data
161
+
162
+ def calc_crc(self, last_byte):
163
+ '''Calculate the CRC, as described in the spec.
164
+ The last byte of the CRC should be data[last_byte].'''
165
+ if last_byte < 3:
166
+ # Every Modbus ADU should be as least 4 long, so we should never
167
+ # have to calculate a CRC on something shorter.
168
+ raise Exception('Could not calculate CRC: message too short')
169
+
170
+ result = 0xFFFF
171
+ magic_number = 0xA001 # As defined in the modbus specification.
172
+ for byte in self.data[:last_byte - 1]:
173
+ result = result ^ byte.data
174
+ for i in range(8):
175
+ LSB = result & 1
176
+ result = result >> 1
177
+ if (LSB): # If the LSB is true.
178
+ result = result ^ magic_number
179
+ byte1 = result & 0xFF
180
+ byte2 = (result & 0xFF00) >> 8
181
+ return (byte1, byte2)
182
+
183
+ def parse_write_single_coil(self):
184
+ '''Parse function 5, write single coil.'''
185
+ self.minimum_length = 8
186
+
187
+ self.puti(1, 'function', 'Function 5: Write Single Coil')
188
+
189
+ address = self.half_word(2)
190
+ self.puti(3, 'address',
191
+ 'Address 0x{:X} / {:d}'.format(address, address + 10000))
192
+
193
+ raw_value = self.half_word(4)
194
+ value = 'Invalid Coil Value'
195
+ if raw_value == 0x0000:
196
+ value = 'Coil Value OFF'
197
+ elif raw_value == 0xFF00:
198
+ value = 'Coil Value ON'
199
+ self.puti(5, 'data', value)
200
+
201
+ self.check_crc(7)
202
+
203
+ def parse_write_single_register(self):
204
+ '''Parse function 6, write single register.'''
205
+ self.minimum_length = 8
206
+
207
+ self.puti(1, 'function', 'Function 6: Write Single Register')
208
+
209
+ address = self.half_word(2)
210
+ self.puti(3, 'address',
211
+ 'Address 0x{:X} / {:d}'.format(address, address + 30000))
212
+
213
+ value = self.half_word(4)
214
+ value_formatted = 'Register Value 0x{0:X} / {0:d}'.format(value)
215
+ self.puti(5, 'data', value_formatted)
216
+
217
+ self.check_crc(7)
218
+
219
+ def parse_diagnostics(self):
220
+ '''Parse function 8, diagnostics. This function has many subfunctions,
221
+ but they are all more or less the same.'''
222
+ self.minimum_length = 8
223
+
224
+ self.puti(1, 'function', 'Function 8: Diagnostics')
225
+
226
+ diag_subfunction = {
227
+ 0: 'Return Query data',
228
+ 1: 'Restart Communications Option',
229
+ 2: 'Return Diagnostics Register',
230
+ 3: 'Change ASCII Input Delimiter',
231
+ 4: 'Force Listen Only Mode',
232
+ 10: 'Clear Counters and Diagnostic Register',
233
+ 11: 'Return Bus Message Count',
234
+ 12: 'Return Bus Communication Error Count',
235
+ 13: 'Return Bus Exception Error Count',
236
+ 14: 'Return Slave Message Count',
237
+ 15: 'Return Slave No Response Count',
238
+ 16: 'Return Slave NAK Count',
239
+ 17: 'Return Slave Busy Count',
240
+ 18: 'Return Bus Character Overrun Count',
241
+ 20: 'Return Overrun Counter and Flag',
242
+ }
243
+ subfunction = self.half_word(2)
244
+ subfunction_name = diag_subfunction.get(subfunction,
245
+ 'Reserved subfunction')
246
+ self.puti(3, 'data',
247
+ 'Subfunction {}: {}'.format(subfunction, subfunction_name))
248
+
249
+ diagnostic_data = self.half_word(4)
250
+ self.puti(5, 'data',
251
+ 'Data Field: {0} / 0x{0:04X}'.format(diagnostic_data))
252
+
253
+ self.check_crc(7)
254
+
255
+ def parse_mask_write_register(self):
256
+ '''Parse function 22, Mask Write Register.'''
257
+ self.minimum_length = 10
258
+ data = self.data
259
+
260
+ self.puti(1, 'function', 'Function 22: Mask Write Register')
261
+
262
+ address = self.half_word(2)
263
+ self.puti(3, 'address',
264
+ 'Address 0x{:X} / {:d}'.format(address, address + 30001))
265
+
266
+ self.half_word(4) # To make sure we don't oveflow data.
267
+ and_mask_1 = data[4].data
268
+ and_mask_2 = data[5].data
269
+ self.puti(5, 'data',
270
+ 'AND mask: {:08b} {:08b}'.format(and_mask_1, and_mask_2))
271
+
272
+ self.half_word(6) # To make sure we don't oveflow data.
273
+ or_mask_1 = data[6].data
274
+ or_mask_2 = data[7].data
275
+ self.puti(7, 'data',
276
+ 'OR mask: {:08b} {:08b}'.format(or_mask_1, or_mask_2))
277
+
278
+ self.check_crc(9)
279
+
280
+ def parse_not_implemented(self):
281
+ '''Explicitly mark certain functions as legal functions, but not
282
+ implemented in this parser. This is due to the author not being able to
283
+ find anything (hardware or software) that supports these functions.'''
284
+ # TODO: Implement these functions.
285
+
286
+ # Mentioning what function it is is no problem.
287
+ function = self.data[1].data
288
+ functionname = {
289
+ 20: 'Read File Record',
290
+ 21: 'Write File Record',
291
+ 24: 'Read FIFO Queue',
292
+ 43: 'Read Device Identification/Encapsulated Interface Transport',
293
+ }[function]
294
+ self.puti(1, 'function',
295
+ 'Function {}: {} (not supported)'.format(function, functionname))
296
+
297
+ # From there on out we can keep marking it unsupported.
298
+ self.putl('data', 'This function is not currently supported')
299
+
300
+ class Modbus_ADU_SC(Modbus_ADU):
301
+ '''SC stands for Server -> Client.'''
302
+ def parse(self):
303
+ '''Select which specific Modbus function we should parse.'''
304
+ data = self.data
305
+
306
+ # This try-catch is being used as flow control.
307
+ try:
308
+ server_id = data[0].data
309
+ if 1 <= server_id <= 247:
310
+ message = 'Slave ID: {}'.format(server_id)
311
+ else:
312
+ message = 'Slave ID {} is invalid'
313
+ self.puti(0, 'server-id', message)
314
+
315
+ function = data[1].data
316
+ if function == 1 or function == 2:
317
+ self.parse_read_bits()
318
+ elif function == 3 or function == 4 or function == 23:
319
+ self.parse_read_registers()
320
+ elif function == 5:
321
+ self.parse_write_single_coil()
322
+ elif function == 6:
323
+ self.parse_write_single_register()
324
+ elif function == 7:
325
+ self.parse_read_exception_status()
326
+ elif function == 8:
327
+ self.parse_diagnostics()
328
+ elif function == 11:
329
+ self.parse_get_comm_event_counter()
330
+ elif function == 12:
331
+ self.parse_get_comm_event_log()
332
+ elif function == 15 or function == 16:
333
+ self.parse_write_multiple()
334
+ elif function == 17:
335
+ self.parse_report_server_id()
336
+ elif function == 22:
337
+ self.parse_mask_write_register()
338
+ elif function in {21, 21, 24, 43}:
339
+ self.parse_not_implemented()
340
+ elif function > 0x80:
341
+ self.parse_error()
342
+ else:
343
+ self.puti(1, 'error',
344
+ 'Unknown function: {}'.format(data[1].data))
345
+ self.putl('error', 'Unknown function')
346
+
347
+ # If the message gets here without raising an exception, the
348
+ # message goes on longer than it should.
349
+ self.putl('error', 'Message too long')
350
+
351
+ except No_more_data:
352
+ # Just a message saying we don't need to parse anymore this round.
353
+ pass
354
+
355
+ def parse_read_bits(self):
356
+ self.mimumum_length = 5
357
+
358
+ data = self.data
359
+ function = data[1].data
360
+
361
+ if function == 1:
362
+ self.puti(1, 'function', 'Function 1: Read Coils')
363
+ else:
364
+ self.puti(1, 'function', 'Function 2: Read Discrete Inputs')
365
+
366
+ bytecount = self.data[2].data
367
+ self.minimum_length = 5 + bytecount # 3 before data, 2 CRC.
368
+ self.puti(2, 'length', 'Byte count: {}'.format(bytecount))
369
+
370
+ # From here on out, we expect registers on 3 and 4, 5 and 6 etc.
371
+ # So registers never start when the length is even.
372
+ self.putl('data', '{:08b}', bytecount + 2)
373
+ self.check_crc(bytecount + 4)
374
+
375
+ def parse_read_registers(self):
376
+ self.mimumum_length = 5
377
+
378
+ data = self.data
379
+
380
+ function = data[1].data
381
+ if function == 3:
382
+ self.puti(1, 'function', 'Function 3: Read Holding Registers')
383
+ elif function == 4:
384
+ self.puti(1, 'function', 'Function 4: Read Input Registers')
385
+ elif function == 23:
386
+ self.puti(1, 'function', 'Function 23: Read/Write Multiple Registers')
387
+
388
+ bytecount = self.data[2].data
389
+ self.minimum_length = 5 + bytecount # 3 before data, 2 CRC.
390
+ if bytecount % 2 == 0:
391
+ self.puti(2, 'length', 'Byte count: {}'.format(bytecount))
392
+ else:
393
+ self.puti(2, 'error',
394
+ 'Error: Odd byte count ({})'.format(bytecount))
395
+
396
+ # From here on out, we expect registers on 3 and 4, 5 and 6 etc.
397
+ # So registers never start when the length is even.
398
+ if len(data) % 2 == 1:
399
+ register_value = self.half_word(-2)
400
+ self.putl('data', '0x{0:04X} / {0}'.format(register_value),
401
+ bytecount + 2)
402
+ else:
403
+ raise No_more_data
404
+
405
+ self.check_crc(bytecount + 4)
406
+
407
+ def parse_read_exception_status(self):
408
+ self.mimumum_length = 5
409
+
410
+ self.puti(1, 'function', 'Function 7: Read Exception Status')
411
+ exception_status = self.data[2].data
412
+ self.puti(2, 'data',
413
+ 'Exception status: {:08b}'.format(exception_status))
414
+ self.check_crc(4)
415
+
416
+ def parse_get_comm_event_counter(self):
417
+ self.mimumum_length = 8
418
+
419
+ self.puti(1, 'function', 'Function 11: Get Comm Event Counter')
420
+
421
+ status = self.half_word(2)
422
+ if status == 0x0000:
423
+ self.puti(3, 'data', 'Status: not busy')
424
+ elif status == 0xFFFF:
425
+ self.puti(3, 'data', 'Status: busy')
426
+ else:
427
+ self.puti(3, 'error', 'Bad status: 0x{:04X}'.format(status))
428
+
429
+ count = self.half_word(4)
430
+ self.puti(5, 'data', 'Event Count: {}'.format(count))
431
+ self.check_crc(7)
432
+
433
+ def parse_get_comm_event_log(self):
434
+ self.mimumum_length = 11
435
+ self.puti(1, 'function', 'Function 12: Get Comm Event Log')
436
+
437
+ data = self.data
438
+
439
+ bytecount = data[2].data
440
+ self.puti(2, 'length', 'Bytecount: {}'.format(bytecount))
441
+ # The bytecount is the length of everything except the slaveID,
442
+ # function code, bytecount and CRC.
443
+ self.mimumum_length = 5 + bytecount
444
+
445
+ status = self.half_word(3)
446
+ if status == 0x0000:
447
+ self.puti(4, 'data', 'Status: not busy')
448
+ elif status == 0xFFFF:
449
+ self.puti(4, 'data', 'Status: busy')
450
+ else:
451
+ self.puti(4, 'error', 'Bad status: 0x{:04X}'.format(status))
452
+
453
+ event_count = self.half_word(5)
454
+ self.puti(6, 'data', 'Event Count: {}'.format(event_count))
455
+
456
+ message_count = self.half_word(7)
457
+ self.puti(8, 'data', 'Message Count: {}'.format(message_count))
458
+
459
+ self.putl('data', 'Event: 0x{:02X}'.format(data[-1].data),
460
+ bytecount + 2)
461
+
462
+ self.check_crc(bytecount + 4)
463
+
464
+ def parse_write_multiple(self):
465
+ '''Function 15 and 16 are almost the same, so we can parse them both
466
+ using one function.'''
467
+ self.mimumum_length = 8
468
+
469
+ function = self.data[1].data
470
+ if function == 15:
471
+ data_unit = 'Coils'
472
+ max_outputs = 0x07B0
473
+ long_address_offset = 10001
474
+ elif function == 16:
475
+ data_unit = 'Registers'
476
+ max_outputs = 0x007B
477
+ long_address_offset = 30001
478
+
479
+ self.puti(1, 'function',
480
+ 'Function {}: Write Multiple {}'.format(function, data_unit))
481
+
482
+ starting_address = self.half_word(2)
483
+ # Some instruction manuals use a long form name for addresses, this is
484
+ # listed here for convienience.
485
+ address_name = long_address_offset + starting_address
486
+ self.puti(3, 'address',
487
+ 'Start at address 0x{:X} / {:d}'.format(starting_address,
488
+ address_name))
489
+
490
+ quantity_of_outputs = self.half_word(4)
491
+ if quantity_of_outputs <= max_outputs:
492
+ self.puti(5, 'data',
493
+ 'Write {} {}'.format(quantity_of_outputs, data_unit))
494
+ else:
495
+ self.puti(5, 'error',
496
+ 'Bad value: {} {}. Max is {}'.format(quantity_of_outputs,
497
+ data_unit, max_outputs))
498
+
499
+ self.check_crc(7)
500
+
501
+ def parse_report_server_id(self):
502
+ # Buildup of this function:
503
+ # 1 byte serverID
504
+ # 1 byte function (17)
505
+ # 1 byte bytecount
506
+ # 1 byte serverID (counts for bytecount)
507
+ # 1 byte Run Indicator Status (counts for bytecount)
508
+ # bytecount - 2 bytes of device specific data (counts for bytecount)
509
+ # 2 bytes of CRC
510
+ self.mimumum_length = 7
511
+ data = self.data
512
+ self.puti(1, 'function', 'Function 17: Report Server ID')
513
+
514
+ bytecount = data[2].data
515
+ self.puti(2, 'length', 'Data is {} bytes long'.format(bytecount))
516
+
517
+ self.puti(3, 'data', 'serverID: {}'.format(data[3].data))
518
+
519
+ run_indicator_status = data[4].data
520
+ if run_indicator_status == 0x00:
521
+ self.puti(4, 'data', 'Run Indicator status: Off')
522
+ elif run_indicator_status == 0xFF:
523
+ self.puti(4, 'data', 'Run Indicator status: On')
524
+ else:
525
+ self.puti(4, 'error',
526
+ 'Bad Run Indicator status: 0x{:X}'.format(run_indicator_status))
527
+
528
+ self.putl('data', 'Device specific data: {}, "{}"'.format(data[-1].data,
529
+ chr(data[-1].data)), 2 + bytecount)
530
+
531
+ self.check_crc(4 + bytecount)
532
+
533
+ def parse_error(self):
534
+ '''Parse a Modbus error message.'''
535
+ self.mimumum_length = 5
536
+ # The function code of an error is always 0x80 above the function call
537
+ # that caused it.
538
+ functioncode = self.data[1].data - 0x80
539
+
540
+ functions = {
541
+ 1: 'Read Coils',
542
+ 2: 'Read Discrete Inputs',
543
+ 3: 'Read Holding Registers',
544
+ 4: 'Read Input Registers',
545
+ 5: 'Write Single Coil',
546
+ 6: 'Write Single Register',
547
+ 7: 'Read Exception Status',
548
+ 8: 'Diagnostic',
549
+ 11: 'Get Com Event Counter',
550
+ 12: 'Get Com Event Log',
551
+ 15: 'Write Multiple Coils',
552
+ 16: 'Write Multiple Registers',
553
+ 17: 'Report Slave ID',
554
+ 20: 'Read File Record',
555
+ 21: 'Write File Record',
556
+ 22: 'Mask Write Register',
557
+ 23: 'Read/Write Multiple Registers',
558
+ 24: 'Read FIFO Queue',
559
+ 43: 'Read Device Identification/Encapsulated Interface Transport',
560
+ }
561
+ functionname = '{}: {}'.format(functioncode,
562
+ functions.get(functioncode, 'Unknown function'))
563
+ self.puti(1, 'function',
564
+ 'Error for function {}'.format(functionname))
565
+
566
+ error = self.data[2].data
567
+ errorcodes = {
568
+ 1: 'Illegal Function',
569
+ 2: 'Illegal Data Address',
570
+ 3: 'Illegal Data Value',
571
+ 4: 'Slave Device Failure',
572
+ 5: 'Acknowledge',
573
+ 6: 'Slave Device Busy',
574
+ 8: 'Memory Parity Error',
575
+ 10: 'Gateway Path Unavailable',
576
+ 11: 'Gateway Target Device failed to respond',
577
+ }
578
+ errorname = '{}: {}'.format(error, errorcodes.get(error, 'Unknown'))
579
+ self.puti(2, 'data', 'Error {}'.format(errorname))
580
+ self.check_crc(4)
581
+
582
+ class Modbus_ADU_CS(Modbus_ADU):
583
+ '''CS stands for Client -> Server.'''
584
+ def parse(self):
585
+ '''Select which specific Modbus function we should parse.'''
586
+ data = self.data
587
+
588
+ # This try-catch is being used as flow control.
589
+ try:
590
+ server_id = data[0].data
591
+ message = ''
592
+ if server_id == 0:
593
+ message = 'Broadcast message'
594
+ elif 1 <= server_id <= 247:
595
+ message = 'Slave ID: {}'.format(server_id)
596
+ elif 248 <= server_id <= 255:
597
+ message = 'Slave ID: {} (reserved address)'.format(server_id)
598
+ self.puti(0, 'server-id', message)
599
+
600
+ function = data[1].data
601
+ if function >= 1 and function <= 4:
602
+ self.parse_read_data_command()
603
+ if function == 5:
604
+ self.parse_write_single_coil()
605
+ if function == 6:
606
+ self.parse_write_single_register()
607
+ if function in {7, 11, 12, 17}:
608
+ self.parse_single_byte_request()
609
+ elif function == 8:
610
+ self.parse_diagnostics()
611
+ if function in {15, 16}:
612
+ self.parse_write_multiple()
613
+ elif function == 22:
614
+ self.parse_mask_write_register()
615
+ elif function == 23:
616
+ self.parse_read_write_registers()
617
+ elif function in {21, 21, 24, 43}:
618
+ self.parse_not_implemented()
619
+ else:
620
+ self.puti(1, 'error',
621
+ 'Unknown function: {}'.format(data[1].data))
622
+ self.putl('error', 'Unknown function')
623
+
624
+ # If the message gets here without raising an exception, the
625
+ # message goes on longer than it should.
626
+ self.putl('error', 'Message too long')
627
+
628
+ except No_more_data:
629
+ # Just a message saying we don't need to parse anymore this round.
630
+ pass
631
+
632
+ def parse_read_data_command(self):
633
+ '''Interpret a command to read x units of data starting at address, ie
634
+ functions 1, 2, 3 and 4, and write the result to the annotations.'''
635
+ data = self.data
636
+ self.minimum_length = 8
637
+
638
+ function = data[1].data
639
+ functionname = {1: 'Read Coils',
640
+ 2: 'Read Discrete Inputs',
641
+ 3: 'Read Holding Registers',
642
+ 4: 'Read Input Registers',
643
+ }[function]
644
+
645
+ self.puti(1, 'function',
646
+ 'Function {}: {}'.format(function, functionname))
647
+
648
+ starting_address = self.half_word(2)
649
+ # Some instruction manuals use a long form name for addresses, this is
650
+ # listed here for convienience.
651
+ # Example: holding register 60 becomes 30061.
652
+ address_name = 10000 * function + 1 + starting_address
653
+ self.puti(3, 'address',
654
+ 'Start at address 0x{:X} / {:d}'.format(starting_address,
655
+ address_name))
656
+
657
+ self.puti(5, 'length',
658
+ 'Read {:d} units of data'.format(self.half_word(4)))
659
+ self.check_crc(7)
660
+
661
+ def parse_single_byte_request(self):
662
+ '''Some Modbus functions have no arguments, this parses those.'''
663
+ function = self.data[1].data
664
+ function_name = {7: 'Read Exception Status',
665
+ 11: 'Get Comm Event Counter',
666
+ 12: 'Get Comm Event Log',
667
+ 17: 'Report Slave ID',
668
+ }[function]
669
+ self.puti(1, 'function',
670
+ 'Function {}: {}'.format(function, function_name))
671
+
672
+ self.check_crc(3)
673
+
674
+ def parse_write_multiple(self):
675
+ '''Function 15 and 16 are almost the same, so we can parse them both
676
+ using one function.'''
677
+ self.mimumum_length = 9
678
+
679
+ function = self.data[1].data
680
+ if function == 15:
681
+ data_unit = 'Coils'
682
+ max_outputs = 0x07B0
683
+ ratio_bytes_data = 1/8
684
+ long_address_offset = 10001
685
+ elif function == 16:
686
+ data_unit = 'Registers'
687
+ max_outputs = 0x007B
688
+ ratio_bytes_data = 2
689
+ long_address_offset = 30001
690
+
691
+ self.puti(1, 'function',
692
+ 'Function {}: Write Multiple {}'.format(function, data_unit))
693
+
694
+ starting_address = self.half_word(2)
695
+ # Some instruction manuals use a long form name for addresses, this is
696
+ # listed here for convienience.
697
+ address_name = long_address_offset + starting_address
698
+ self.puti(3, 'address',
699
+ 'Start at address 0x{:X} / {:d}'.format(starting_address,
700
+ address_name))
701
+
702
+ quantity_of_outputs = self.half_word(4)
703
+ if quantity_of_outputs <= max_outputs:
704
+ self.puti(5, 'length',
705
+ 'Write {} {}'.format(quantity_of_outputs, data_unit))
706
+ else:
707
+ self.puti(5, 'error',
708
+ 'Bad value: {} {}. Max is {}'.format(quantity_of_outputs,
709
+ data_unit, max_outputs))
710
+ proper_bytecount = ceil(quantity_of_outputs * ratio_bytes_data)
711
+
712
+ bytecount = self.data[6].data
713
+ if bytecount == proper_bytecount:
714
+ self.puti(6, 'length', 'Byte count: {}'.format(bytecount))
715
+ else:
716
+ self.puti(6, 'error',
717
+ 'Bad byte count, is {}, should be {}'.format(bytecount,
718
+ proper_bytecount))
719
+ self.mimumum_length = bytecount + 9
720
+
721
+ self.putl('data', 'Value 0x{:X}', 6 + bytecount)
722
+
723
+ self.check_crc(bytecount + 8)
724
+
725
+ def parse_read_file_record(self):
726
+ self.puti(1, 'function', 'Function 20: Read file records')
727
+
728
+ data = self.data
729
+
730
+ bytecount = data[2].data
731
+
732
+ self.minimum_length = 5 + bytecount
733
+ # 1 for serverID, 1 for function, 1 for bytecount, 2 for CRC.
734
+
735
+ if 0x07 <= bytecount <= 0xF5:
736
+ self.puti(2, 'length', 'Request is {} bytes long'.format(bytecount))
737
+ else:
738
+ self.puti(2, 'error',
739
+ 'Request claims to be {} bytes long, legal values are between'
740
+ ' 7 and 247'.format(bytecount))
741
+
742
+ current_byte = len(data) - 1
743
+ # Function 20 is a number of sub-requests, the first starting at 3,
744
+ # the total length of the sub-requests is bytecount.
745
+ if current_byte <= bytecount + 2:
746
+ step = (current_byte - 3) % 7
747
+ if step == 0:
748
+ if data[current_byte].data == 6:
749
+ self.puti(current_byte, 'data', 'Start sub-request')
750
+ else:
751
+ self.puti(current_byte, 'error',
752
+ 'First byte of subrequest should be 0x06')
753
+ elif step == 1:
754
+ raise No_more_data
755
+ elif step == 2:
756
+ file_number = self.half_word(current_byte - 1)
757
+ self.puti(current_byte, 'data',
758
+ 'Read File number {}'.format(file_number))
759
+ elif step == 3:
760
+ raise No_more_data
761
+ elif step == 4:
762
+ record_number = self.half_word(current_byte - 1)
763
+ self.puti(current_byte, 'address',
764
+ 'Read from record number {}'.format(record_number))
765
+ # TODO: Check if within range.
766
+ elif step == 5:
767
+ raise No_more_data
768
+ elif step == 6:
769
+ records_to_read = self.half_word(current_byte - 1)
770
+ self.puti(current_byte, 'length',
771
+ 'Read {} records'.format(records_to_read))
772
+ self.check_crc(4 + bytecount)
773
+
774
+ def parse_read_write_registers(self):
775
+ '''Parse function 23: Read/Write multiple registers.'''
776
+ self.minimum_length = 13
777
+
778
+ self.puti(1, 'function', 'Function 23: Read/Write Multiple Registers')
779
+
780
+ starting_address = self.half_word(2)
781
+ # Some instruction manuals use a long form name for addresses, this is
782
+ # listed here for convienience.
783
+ # Example: holding register 60 becomes 30061.
784
+ address_name = 30001 + starting_address
785
+ self.puti(3, 'address',
786
+ 'Read starting at address 0x{:X} / {:d}'.format(starting_address,
787
+ address_name))
788
+
789
+ self.puti(5, 'length', 'Read {:d} units of data'.format(self.half_word(4)))
790
+
791
+ starting_address = self.half_word(6)
792
+ self.puti(7, 'address',
793
+ 'Write starting at address 0x{:X} / {:d}'.format(starting_address,
794
+ address_name))
795
+
796
+ quantity_of_outputs = self.half_word(8)
797
+ self.puti(9, 'length',
798
+ 'Write {} registers'.format(quantity_of_outputs))
799
+ proper_bytecount = quantity_of_outputs * 2
800
+
801
+ bytecount = self.data[10].data
802
+ if bytecount == proper_bytecount:
803
+ self.puti(10, 'length', 'Byte count: {}'.format(bytecount))
804
+ else:
805
+ self.puti(10, 'error',
806
+ 'Bad byte count, is {}, should be {}'.format(bytecount,
807
+ proper_bytecount))
808
+ self.mimumum_length = bytecount + 13
809
+
810
+ self.putl('data', 'Data, value 0x{:02X}', 10 + bytecount)
811
+
812
+ self.check_crc(bytecount + 12)
813
+
814
+ class Decoder(srd.Decoder):
815
+ api_version = 3
816
+ id = 'modbus'
817
+ name = 'Modbus'
818
+ longname = 'Modbus RTU over RS232/RS485'
819
+ desc = 'Modbus RTU protocol for industrial applications.'
820
+ license = 'gplv3+'
821
+ inputs = ['uart']
822
+ outputs = ['modbus']
823
+ tags = ['Embedded/industrial']
824
+ annotations = (
825
+ ('sc-server-id', 'SC server ID'),
826
+ ('sc-function', 'SC function'),
827
+ ('sc-crc', 'SC CRC'),
828
+ ('sc-address', 'SC address'),
829
+ ('sc-data', 'SC data'),
830
+ ('sc-length', 'SC length'),
831
+ ('sc-error', 'SC error'),
832
+ ('cs-server-id', 'CS server ID'),
833
+ ('cs-function', 'CS function'),
834
+ ('cs-crc', 'CS CRC'),
835
+ ('cs-address', 'CS address'),
836
+ ('cs-data', 'CS data'),
837
+ ('cs-length', 'CS length'),
838
+ ('cs-error', 'CS error'),
839
+ ('error-indication', 'Error indication'),
840
+ )
841
+ annotation_rows = (
842
+ ('sc', 'Server->client', (0, 1, 2, 3, 4, 5, 6)),
843
+ ('cs', 'Client->server', (7, 8, 9, 10, 11, 12, 13)),
844
+ ('error-indicators', 'Errors in frame', (14,)),
845
+ )
846
+ options = (
847
+ {'id': 'scchannel', 'desc': 'Server -> client channel',
848
+ 'default': rxtx_channels[0], 'values': rxtx_channels},
849
+ {'id': 'cschannel', 'desc': 'Client -> server channel',
850
+ 'default': rxtx_channels[1], 'values': rxtx_channels},
851
+ {'id': 'framegap', 'desc': 'Inter-frame bit gap', 'default': 28},
852
+ )
853
+
854
+ def __init__(self):
855
+ self.reset()
856
+
857
+ def reset(self):
858
+ self.ADUSc = None # Start off with empty slave -> client ADU.
859
+ self.ADUCs = None # Start off with empty client -> slave ADU.
860
+
861
+ # The reason we have both (despite not supporting full duplex comms) is
862
+ # because we want to be able to decode the message as both client ->
863
+ # server and server -> client, and let the user see which of the two
864
+ # the ADU was.
865
+
866
+ self.bitlength = None # We will later test how long a bit is.
867
+
868
+ def start(self):
869
+ self.out_ann = self.register(srd.OUTPUT_ANN)
870
+
871
+ def puta(self, start, end, ann_str, message):
872
+ '''Put an annotation from start to end, with ann as a
873
+ string. This means you don't have to know the ann's
874
+ number to write annotations to it.'''
875
+ ann = [s[0] for s in self.annotations].index(ann_str)
876
+ self.put(start, end, self.out_ann, [ann, [message]])
877
+
878
+ def decode_adu(self, ss, es, data, direction):
879
+ '''Decode the next byte or bit (depending on type) in the ADU.
880
+ ss: Start time of the data
881
+ es: End time of the data
882
+ data: Data as passed from the UART decoder
883
+ direction: Is this data for the Cs (client -> server) or Sc (server ->
884
+ client) being decoded right now?'''
885
+ ptype, rxtx, pdata = data
886
+
887
+ # We don't have a nice way to get the baud rate from UART, so we have
888
+ # to figure out how long a bit lasts. We do this by looking at the
889
+ # length of (probably) the startbit.
890
+ if self.bitlength is None:
891
+ if ptype == 'STARTBIT' or ptype == 'STOPBIT':
892
+ self.bitlength = es - ss
893
+ else:
894
+ # If we don't know the bitlength yet, we can't start decoding.
895
+ return
896
+
897
+ # Select the ADU, create the ADU if needed.
898
+ # We set ADU.startNewFrame = True when we know the old one is over.
899
+ if direction == 'Sc':
900
+ if (self.ADUSc is None) or self.ADUSc.startNewFrame:
901
+ self.ADUSc = Modbus_ADU_SC(self, ss, TX, 'sc-')
902
+ ADU = self.ADUSc
903
+ if direction == 'Cs':
904
+ if self.ADUCs is None or self.ADUCs.startNewFrame:
905
+ self.ADUCs = Modbus_ADU_CS(self, ss, TX, 'cs-')
906
+ ADU = self.ADUCs
907
+
908
+ # We need to determine if the last ADU is over.
909
+ # According to the Modbus spec, there should be 3.5 characters worth of
910
+ # space between each message. But if within a message there is a length
911
+ # of more than 1.5 character, that's an error. For our purposes
912
+ # somewhere between seems fine.
913
+ # A character is 11 bits long, so (3.5 + 1.5)/2 * 11 ~= 28
914
+ # TODO: Display error for too short or too long.
915
+ if (ss - ADU.last_read) <= self.bitlength * self.options['framegap']:
916
+ ADU.add_data(ss, es, data)
917
+ else:
918
+ # It's been too long since the last part of the ADU!
919
+ # If there is any data in the ADU we need to show it to the user
920
+ if len(ADU.data) > 0:
921
+ # Extend errors for 3 bits after last byte, we can guarantee
922
+ # space.
923
+ ADU.close(ADU.data[-1].end + self.bitlength * 3)
924
+
925
+ ADU.startNewFrame = True
926
+ # Restart this function, it will make a new ADU for us.
927
+ self.decode_adu(ss, es, data, direction)
928
+
929
+ def decode(self, ss, es, data):
930
+ ptype, rxtx, pdata = data
931
+
932
+ # Ignore unknown/unsupported ptypes.
933
+ if ptype not in ('STARTBIT', 'DATA', 'STOPBIT'):
934
+ return
935
+
936
+ # Decide what ADU(s) we need this packet to go to.
937
+ # Note that it's possible to go to both ADUs.
938
+ if rxtx_channels[rxtx] == self.options['scchannel']:
939
+ self.decode_adu(ss, es, data, 'Sc')
940
+ if rxtx_channels[rxtx] == self.options['cschannel']:
941
+ self.decode_adu(ss, es, data, 'Cs')