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,252 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import re
5
+ import shutil
6
+ import subprocess
7
+ import tempfile
8
+ from dataclasses import dataclass
9
+ from pathlib import Path
10
+
11
+ from ..errors import BackendUnavailableError, CaptureError, ValidationError
12
+ from ..models import CaptureRequest, CapturedSignal, Channel
13
+ from ..signal import unpack_bits
14
+ from .base import Device
15
+
16
+
17
+ @dataclass(frozen=True)
18
+ class _SigrokDevice(Device):
19
+ selector: str = ""
20
+
21
+
22
+ class SigrokBackend:
23
+ """Capture digital channels through sigrok-cli.
24
+
25
+ sigrok covers cheap FX2-based analyzers, DSLogic, and many vendor devices.
26
+ Raw sigrok binary output uses one byte per digital channel: bit 0 = D0.
27
+ """
28
+
29
+ name = "sigrok"
30
+
31
+ def __init__(self, executable: str | None = None, timeout_s: float = 90.0) -> None:
32
+ self.executable = executable or os.environ.get("SIGROK_CLI") or shutil.which("sigrok-cli")
33
+ self.timeout_s = timeout_s
34
+ self._trigger_support: tuple[str, bool] | None = None
35
+
36
+ @property
37
+ def available(self) -> bool:
38
+ return bool(self.executable)
39
+
40
+ def _require_executable(self) -> str:
41
+ if not self.executable:
42
+ raise BackendUnavailableError(
43
+ "sigrok-cli was not found. Install sigrok-cli/PulseView and put sigrok-cli on PATH, "
44
+ "or set SIGROK_CLI to its full path."
45
+ )
46
+ return self.executable
47
+
48
+ def list_devices(self) -> list[Device]:
49
+ executable = self._require_executable()
50
+ completed = self._run([executable, "--scan"])
51
+ devices: list[Device] = []
52
+ for index, raw_line in enumerate(completed.stdout.splitlines()):
53
+ line = raw_line.strip()
54
+ if not line or line.lower().startswith("the following devices"):
55
+ continue
56
+ if line.startswith("- "):
57
+ line = line[2:].strip()
58
+ fields = _parse_scan_line(line)
59
+ if not fields:
60
+ continue
61
+ name = fields.get("name") or fields.get("device") or fields.get("driver") or f"sigrok device {index}"
62
+ driver = fields.get("driver") or "sigrok"
63
+ connection = fields.get("conn") or fields.get("connection")
64
+ selector = f"{driver}:{connection}" if connection and connection not in {"conn=?", "?"} else driver
65
+ serial = fields.get("serial") or connection
66
+ devices.append(
67
+ _SigrokDevice(
68
+ id=selector,
69
+ name=name,
70
+ driver=driver,
71
+ channels=tuple(_channel_ids(fields.get("channels", ""))),
72
+ serial=serial,
73
+ selector=selector,
74
+ )
75
+ )
76
+ return devices
77
+
78
+ def capture(self, request: CaptureRequest) -> CapturedSignal:
79
+ executable = self._require_executable()
80
+ devices = self.list_devices()
81
+ if not devices:
82
+ raise BackendUnavailableError("sigrok-cli found no connected logic analyzers")
83
+
84
+ device = _select_device(devices, request.device)
85
+ for channel in request.channels:
86
+ if channel not in device.channels:
87
+ raise ValidationError(
88
+ f"channel {channel} is not exposed by {device.name}",
89
+ details={"available_channels": list(device.channels)},
90
+ )
91
+ if request.trigger is not None and request.trigger.channel not in request.channels:
92
+ raise ValidationError("trigger.channel must be one of the captured channels")
93
+
94
+ sample_count = request.sample_count
95
+ device_channels = list(device.channels)
96
+ with tempfile.TemporaryDirectory(prefix="logic-agent-sigrok-") as temp_dir:
97
+ raw_path = Path(temp_dir) / "capture.bin"
98
+ channel_arg = ",".join(request.channels)
99
+ command = [
100
+ executable,
101
+ "--driver", getattr(device, "selector", device.driver),
102
+ "--config", f"samplerate={request.sample_rate_hz}",
103
+ "--channels", channel_arg,
104
+ "--samples", str(sample_count),
105
+ "--output-format", "binary",
106
+ "--output-file", str(raw_path),
107
+ ]
108
+ if request.trigger is not None:
109
+ if self._supports_trigger(executable):
110
+ command[1:1] = [
111
+ "--trigger",
112
+ f"{request.trigger.channel}={_trigger_letter(request.trigger.edge)}",
113
+ ]
114
+ self._run(command)
115
+ if not raw_path.exists():
116
+ raise CaptureError("sigrok-cli completed without producing a capture file")
117
+ raw = raw_path.read_bytes()
118
+
119
+ unitsize, layout = _infer_binary_layout(raw, sample_count, device_channels)
120
+ expected_bytes = sample_count * unitsize
121
+ if len(raw) < expected_bytes:
122
+ raise CaptureError(
123
+ "sigrok-cli returned fewer samples than requested",
124
+ details={"expected": expected_bytes, "received": len(raw)},
125
+ )
126
+ raw = raw[:expected_bytes]
127
+
128
+ samples = _unpack_channels(raw, sample_count, unitsize, layout, device_channels, request.channels)
129
+ warnings: list[str] = []
130
+ trigger_applied = request.trigger is not None and self._supports_trigger(executable)
131
+ if request.trigger is not None and not trigger_applied:
132
+ warnings.append("trigger was requested but this sigrok-cli build has no --trigger support")
133
+
134
+ return CapturedSignal(
135
+ backend=self.name,
136
+ device_id=device.id,
137
+ device_label=device.name,
138
+ channels=tuple(Channel(id=channel, name=channel, index=index) for index, channel in enumerate(request.channels)),
139
+ sample_rate_hz=request.sample_rate_hz,
140
+ samples=samples,
141
+ trigger_applied=trigger_applied,
142
+ warnings=warnings,
143
+ )
144
+
145
+ def _supports_trigger(self, executable: str) -> bool:
146
+ if self._trigger_support is not None and self._trigger_support[0] == executable:
147
+ return self._trigger_support[1]
148
+ completed = self._run([executable, "--help"])
149
+ supported = "--trigger" in completed.stdout
150
+ self._trigger_support = (executable, supported)
151
+ return supported
152
+
153
+ def _run(self, command: list[str]) -> subprocess.CompletedProcess[str]:
154
+ try:
155
+ completed = subprocess.run(
156
+ command,
157
+ check=False,
158
+ capture_output=True,
159
+ text=True,
160
+ timeout=self.timeout_s,
161
+ encoding="utf-8",
162
+ errors="replace",
163
+ )
164
+ except subprocess.TimeoutExpired as exc:
165
+ raise CaptureError(
166
+ "sigrok-cli timed out",
167
+ details={"timeout_s": self.timeout_s, "command": " ".join(command)},
168
+ ) from exc
169
+ except OSError as exc:
170
+ raise BackendUnavailableError(f"failed to start sigrok-cli: {exc}") from exc
171
+ if completed.returncode != 0:
172
+ raise CaptureError(
173
+ "sigrok-cli failed",
174
+ details={
175
+ "returncode": completed.returncode,
176
+ "stderr": completed.stderr.strip()[-4000:],
177
+ },
178
+ )
179
+ return completed
180
+
181
+
182
+ def _parse_scan_line(record: str) -> dict[str, str]:
183
+ """Parse both modern and older sigrok-cli --scan lines.
184
+
185
+ Modern: fx2lafw:conn=1.2 -- Saleae Logic 8 with 8 channels: D0 D1 ... D7
186
+ Older: driver: fx2lafw ... channels: D0 D1 ...
187
+ """
188
+ match = re.match(
189
+ r"^(?P<driver>[A-Za-z0-9_.-]+):(?P<conn>\S+)\s+--\s+(?P<name>.+?)\s+with\s+\d+\s+channels?:\s*(?P<channels>.+)$",
190
+ record,
191
+ )
192
+ if match:
193
+ return {key: value.strip() for key, value in match.groupdict().items()}
194
+ fields: dict[str, str] = {}
195
+ for key, value in re.findall(r"(\w+):\s*([^:]+?)(?=\s+\w+:\s|$)", record):
196
+ fields[key.lower()] = value.strip()
197
+ if "driver" not in fields and record:
198
+ fields["driver"] = record.split(":", 1)[0].strip()
199
+ return fields
200
+
201
+
202
+ def _channel_ids(value: str) -> list[str]:
203
+ return [item for item in re.split(r"[\s,]+", value.strip()) if item]
204
+
205
+
206
+ def _select_device(devices: list[Device], requested: str | None) -> Device:
207
+ if requested is None:
208
+ return devices[0]
209
+ for device in devices:
210
+ if requested in {device.id, device.name, device.serial}:
211
+ return device
212
+ raise ValidationError(
213
+ f"unknown device: {requested}",
214
+ details={"devices": [device.to_dict() for device in devices]},
215
+ )
216
+
217
+
218
+ def _trigger_letter(edge: str) -> str:
219
+ return {"rising": "r", "falling": "f", "either": "e"}[edge]
220
+
221
+
222
+ def _infer_binary_layout(raw: bytes, sample_count: int, device_channels: list[str]) -> tuple[int, str]:
223
+ """Infer unitsize when sigrok emits raw device-layout or captured-channel layout."""
224
+ max_unitsize = max(1, (len(device_channels) + 7) // 8)
225
+ for unitsize in range(max_unitsize, 0, -1):
226
+ if len(raw) == sample_count * unitsize:
227
+ return unitsize, "device"
228
+ return 1, "captured"
229
+
230
+
231
+ def _unpack_channels(
232
+ raw: bytes,
233
+ sample_count: int,
234
+ unitsize: int,
235
+ layout: str,
236
+ device_channels: list[str],
237
+ requested: tuple[str, ...],
238
+ ) -> dict[str, bytes]:
239
+ result: dict[str, bytes] = {}
240
+ for channel in requested:
241
+ if layout == "device":
242
+ bit = device_channels.index(channel)
243
+ else:
244
+ bit = list(requested).index(channel)
245
+ byte_index = bit // 8
246
+ bit_mask = 1 << (bit % 8)
247
+ result[channel] = bytes(
248
+ (raw[sample * unitsize + byte_index] & bit_mask) >> (bit % 8)
249
+ for sample in range(sample_count)
250
+ )
251
+ return result
252
+
@@ -0,0 +1,387 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+ import os
6
+ import subprocess
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ from .decoders import supported_protocols
11
+ from .errors import LogicAgentError
12
+ from .mcp_clients import SCOPES, Locations, format_clients, format_report, install, list_clients
13
+ from .mcp_server import main as mcp_main
14
+ from .service import LogicAgentService
15
+
16
+
17
+ def main(argv: list[str] | None = None) -> int:
18
+ argv = list(sys.argv[1:] if argv is None else argv)
19
+ argv = _move_global_options(argv)
20
+ parser = argparse.ArgumentParser(prog="logic-agent", description="Logic analyzer gateway for AI agents")
21
+ parser.add_argument("--data-dir", type=Path, default=None, help="Capture archive (default: .logic_agent_data)")
22
+ parser.add_argument("--backend", choices=["mock", "sigrok", "dslab"], default=None, help="Override backend for every command")
23
+ sub = parser.add_subparsers(dest="command", required=True)
24
+
25
+ sub.add_parser("mcp", help="Run the MCP stdio server")
26
+ setup = sub.add_parser(
27
+ "mcp-install",
28
+ help="Add this MCP server to Codex, Claude Code, Copilot, Cursor, Kiro, Windsurf, Cline",
29
+ )
30
+ setup.add_argument("clients", nargs="*", metavar="CLIENT", help="Client ids (default: every detected agent); --list shows them")
31
+ setup.add_argument("--list", action="store_true", help="Show the supported agents and where their config file lives")
32
+ setup.add_argument("--all", action="store_true", help="Also configure agents that were not detected")
33
+ setup.add_argument("--remove", action="store_true", help="Remove the server instead of adding it")
34
+ setup.add_argument("--dry-run", action="store_true", help="Print copy-paste snippets without touching any file")
35
+ setup.add_argument("--scope", choices=list(SCOPES), default="user", help="user: per-user config; project: config in --cwd")
36
+ setup.add_argument("--json", action="store_true", help="Machine-readable result")
37
+ setup.add_argument("--no-verify", action="store_true", help="Do not start the server to verify the launch spec")
38
+ setup.add_argument("--home", type=Path, default=None, help="Override the user home directory (testing)")
39
+ setup.add_argument("--cwd", type=Path, default=None, help="Project directory for --scope project")
40
+ sub.add_parser("capabilities", help="Show backends and limits")
41
+ sub.add_parser("devices", help="List connected devices")
42
+ sub.add_parser("captures", help="List saved captures")
43
+ sub.add_parser("self-test", help="Run the DSLogic internal hardware self-test")
44
+
45
+ imp = sub.add_parser("import-csv", help="Import a DSView CSV export")
46
+ imp.add_argument("path")
47
+ imp.add_argument("--channels", help="Comma-separated channel columns")
48
+ imp.add_argument("--label")
49
+
50
+ cap = sub.add_parser("capture", help="Run a capture and print its summary")
51
+ cap.add_argument("--channels", required=True, help="Comma-separated channel ids, e.g. D0,D1")
52
+ cap.add_argument("--sample-rate", type=int, required=True)
53
+ cap.add_argument("--duration", type=float, required=True)
54
+ cap.add_argument("--device")
55
+ cap.add_argument("--label")
56
+
57
+ demux = sub.add_parser("uart", help="Decode UART from a saved capture")
58
+ demux.add_argument("capture_id")
59
+ demux.add_argument("channel")
60
+ demux.add_argument("--baud", type=int, default=115_200)
61
+ demux.add_argument("--start", type=float, default=0.0)
62
+ demux.add_argument("--duration", type=float)
63
+ demux.add_argument("--idle-low", action="store_true", help="Decode idle-low signalling (start bit is high)")
64
+
65
+ decode = sub.add_parser("decode", help="Decode a saved capture with bundled single-layer or stacked protocol decoders")
66
+ decode.add_argument("capture_id")
67
+ decode.add_argument("protocol", choices=supported_protocols())
68
+ decode.add_argument("--channels", required=True, help="Role mapping, e.g. scl=D0,sda=D1")
69
+ decode.add_argument("--options", default=None, help="Comma-separated decoder options, e.g. cpol=0,cpha=0")
70
+ decode.add_argument("--start", type=float, default=0.0)
71
+ decode.add_argument("--duration", type=float)
72
+ decode.add_argument("--max-events", type=int, default=500)
73
+ decode.add_argument("--include-bits", action="store_true", help="Include per-bit annotations (large)")
74
+ decode.add_argument(
75
+ "--include-lower-layers",
76
+ action="store_true",
77
+ help="For stacked protocols, include lower-layer events such as SPI/UART",
78
+ )
79
+
80
+ period = sub.add_parser("period", help="Measure period/frequency/duty cycle")
81
+ period.add_argument("capture_id")
82
+ period.add_argument("channel")
83
+ period.add_argument("--start", type=float, default=0.0)
84
+ period.add_argument("--duration", type=float)
85
+
86
+ view = sub.add_parser("view", help="Export a saved capture to VCD and open it in a waveform viewer")
87
+ view.add_argument("capture_id")
88
+ view.add_argument("--output", type=Path, help="VCD path (default: <capture dir>/capture.vcd)")
89
+ view.add_argument("--viewer", help="Viewer executable (default: pulseview, then gtkwave)")
90
+ view.add_argument("--no-open", action="store_true", help="Write the VCD but do not launch a viewer")
91
+
92
+ demo = sub.add_parser("demo", help="Capture the mock UART signal and decode it")
93
+
94
+ args = parser.parse_args(argv)
95
+ if args.command == "mcp":
96
+ mcp_args = ["--data-dir", str(args.data_dir)] if args.data_dir else []
97
+ if args.backend:
98
+ mcp_args += ["--backend", args.backend]
99
+ return mcp_main(mcp_args)
100
+ if args.command == "mcp-install":
101
+ return _run_mcp_install(args)
102
+
103
+ service = LogicAgentService(data_dir=args.data_dir)
104
+ if args.backend:
105
+ service.default_backend = args.backend
106
+
107
+ try:
108
+ if args.command == "capabilities":
109
+ payload = service.capabilities()
110
+ elif args.command == "devices":
111
+ payload = service.list_devices()
112
+ elif args.command == "captures":
113
+ payload = service.list_captures()
114
+ elif args.command == "self-test":
115
+ payload = service.self_test()
116
+ elif args.command == "import-csv":
117
+ payload = service.import_csv(
118
+ {
119
+ "path": args.path,
120
+ "channels": [item.strip() for item in args.channels.split(",") if item.strip()] if args.channels else None,
121
+ "label": args.label,
122
+ }
123
+ )
124
+ elif args.command == "capture":
125
+ payload = service.capture(
126
+ {
127
+ "channels": [item.strip() for item in args.channels.split(",") if item.strip()],
128
+ "sample_rate_hz": args.sample_rate,
129
+ "duration_s": args.duration,
130
+ "device": args.device,
131
+ "label": args.label,
132
+ }
133
+ )
134
+ elif args.command == "uart":
135
+ payload = service.decode_uart(
136
+ {
137
+ "capture_id": args.capture_id,
138
+ "channel": args.channel,
139
+ "start_s": args.start,
140
+ "duration_s": args.duration,
141
+ "uart": {"baud": args.baud, "idle_high": not args.idle_low},
142
+ }
143
+ )
144
+ elif args.command == "decode":
145
+ payload = service.decode_protocol(
146
+ {
147
+ "capture_id": args.capture_id,
148
+ "protocol": args.protocol,
149
+ "channels": _parse_mapping(args.channels),
150
+ "options": _parse_options(args.options),
151
+ "start_s": args.start,
152
+ "duration_s": args.duration,
153
+ "max_events": args.max_events,
154
+ "include_bits": args.include_bits,
155
+ "include_lower_layers": args.include_lower_layers,
156
+ }
157
+ )
158
+ elif args.command == "period":
159
+ payload = service.measure_period(
160
+ {
161
+ "capture_id": args.capture_id,
162
+ "channel": args.channel,
163
+ "start_s": args.start,
164
+ "duration_s": args.duration,
165
+ }
166
+ )
167
+ elif args.command == "view":
168
+ payload = _export_and_view(service, args.capture_id, args.output, args.viewer, args.no_open)
169
+ elif args.command == "demo":
170
+ demo_service = LogicAgentService(data_dir=args.data_dir)
171
+ demo_service.default_backend = "mock"
172
+ captured = demo_service.capture(
173
+ {
174
+ "channels": ["D0"],
175
+ "sample_rate_hz": 1_000_000,
176
+ "duration_s": 0.02,
177
+ "label": "mock UART demo",
178
+ }
179
+ )
180
+ decoded = demo_service.decode_uart(
181
+ {"capture_id": captured["capture_id"], "channel": "D0", "uart": {"baud": 115_200}}
182
+ )
183
+ payload = {"capture": captured, "uart": decoded}
184
+ else: # pragma: no cover - argparse enforces choices
185
+ parser.error(f"unknown command: {args.command}")
186
+ except LogicAgentError as exc:
187
+ print(json.dumps(exc.to_dict(), indent=2, ensure_ascii=False))
188
+ return 2
189
+
190
+ print(json.dumps(payload, indent=2, ensure_ascii=False))
191
+ return 0
192
+
193
+
194
+ def _run_mcp_install(args: argparse.Namespace) -> int:
195
+ """Write (or preview, or remove) the MCP entry in every supported agent's config."""
196
+ locations = Locations.detect(home=args.home, cwd=args.cwd)
197
+ try:
198
+ if args.list:
199
+ rows = list_clients(locations)
200
+ print(json.dumps(rows, indent=2, ensure_ascii=False) if args.json else format_clients(rows))
201
+ return 0
202
+ installation = install(
203
+ locations=locations,
204
+ scope=args.scope,
205
+ only=args.clients,
206
+ include_all=args.all,
207
+ remove=args.remove,
208
+ dry_run=args.dry_run,
209
+ verify=not args.no_verify,
210
+ data_dir=args.data_dir,
211
+ backend=args.backend,
212
+ )
213
+ except LogicAgentError as exc:
214
+ print(json.dumps(exc.to_dict(), indent=2, ensure_ascii=False))
215
+ return 2
216
+ if args.json:
217
+ print(json.dumps(installation.as_dict(), indent=2, ensure_ascii=False))
218
+ else:
219
+ print(format_report(installation, dry_run=args.dry_run))
220
+ return 0 if installation.ok else 2
221
+
222
+
223
+ def _parse_mapping(value: str) -> dict[str, str]:
224
+ result: dict[str, str] = {}
225
+ for item in value.split(","):
226
+ item = item.strip()
227
+ if not item:
228
+ continue
229
+ if "=" not in item:
230
+ raise LogicAgentError(f"invalid channel mapping: {item!r}; expected role=D0")
231
+ key, channel = item.split("=", 1)
232
+ key, channel = key.strip(), channel.strip()
233
+ if not key or not channel:
234
+ raise LogicAgentError(f"invalid channel mapping: {item!r}; expected role=D0")
235
+ result[key] = channel
236
+ if not result:
237
+ raise LogicAgentError("--channels must contain at least one role=D0 mapping")
238
+ return result
239
+
240
+
241
+ def _export_and_view(
242
+ service: LogicAgentService,
243
+ capture_id: str,
244
+ output: Path | None,
245
+ viewer: str | None,
246
+ no_open: bool,
247
+ ) -> dict[str, object]:
248
+ """Write a standards-compliant VCD from archived channels and optionally launch a viewer."""
249
+ manifest = service.store.manifest(capture_id)
250
+ channel_ids = [str(item["id"]) for item in manifest["channels"]]
251
+ if not channel_ids:
252
+ raise LogicAgentError("capture has no channels")
253
+
254
+ lines = [
255
+ f"$date {manifest.get('created_at', '')} $end",
256
+ "$version logic-agent view $end",
257
+ f"$comment {manifest.get('device', {}).get('name', 'logic analyzer')}, {manifest.get('sample_rate_hz')} Hz $end",
258
+ "$timescale 1ns $end",
259
+ "$scope module logic $end",
260
+ ]
261
+ identifiers = [chr(ord("!") + index) for index in range(len(channel_ids))]
262
+ for channel_id, identifier in zip(channel_ids, identifiers):
263
+ lines.append(f"$var wire 1 {identifier} {channel_id} $end")
264
+ lines += ["$upscope $end", "$enddefinitions $end", "#0"]
265
+
266
+ sample_rate = float(manifest["sample_rate_hz"])
267
+ samples_by_channel = {channel_id: service.store.load_channel(capture_id, channel_id)[0] for channel_id in channel_ids}
268
+ sample_count = int(manifest["sample_count"])
269
+ previous = {channel_id: None for channel_id in channel_ids}
270
+ last_timestamp = None
271
+ for index in range(sample_count):
272
+ timestamp = round(index * 1_000_000_000 / sample_rate)
273
+ for channel_id, identifier in zip(channel_ids, identifiers):
274
+ value = samples_by_channel[channel_id][index]
275
+ if previous[channel_id] == value:
276
+ continue
277
+ if timestamp != last_timestamp:
278
+ lines.append(f"#{timestamp}")
279
+ last_timestamp = timestamp
280
+ lines.append(f"{value}{identifier}")
281
+ previous[channel_id] = value
282
+
283
+ target = output or (service.store.artifact_path(capture_id) / "capture.vcd")
284
+ target = Path(target).resolve()
285
+ target.parent.mkdir(parents=True, exist_ok=True)
286
+ target.write_text("\n".join(lines) + "\n", encoding="utf-8")
287
+
288
+ launched = False
289
+ viewer_path = None if no_open else _find_viewer(viewer)
290
+ if viewer_path:
291
+ launch_args = [viewer_path, "-D", "-c", str(target)] if _is_pulseview(viewer_path) else [viewer_path, str(target)]
292
+ subprocess.Popen(launch_args, close_fds=True)
293
+ launched = True
294
+ return {
295
+ "ok": True,
296
+ "capture_id": capture_id,
297
+ "vcd_path": str(target),
298
+ "sample_rate_hz": int(sample_rate),
299
+ "sample_count": sample_count,
300
+ "channels": channel_ids,
301
+ "viewer": viewer_path,
302
+ "launched": launched,
303
+ }
304
+
305
+
306
+ def _is_pulseview(path: str) -> bool:
307
+ return Path(path).name.lower() == "pulseview.exe"
308
+
309
+
310
+ def _find_viewer(requested: str | None) -> str | None:
311
+ import shutil
312
+
313
+ if requested:
314
+ resolved = shutil.which(requested) or requested
315
+ if Path(resolved).is_file():
316
+ return str(Path(resolved).resolve())
317
+ raise LogicAgentError(f"viewer not found: {requested}")
318
+ candidates = [
319
+ os.environ.get("PULSEVIEW_EXE"),
320
+ r"C:\Program Files (x86)\sigrok\PulseView\pulseview.exe",
321
+ r"C:\Program Files\sigrok\PulseView\pulseview.exe",
322
+ shutil.which("pulseview"),
323
+ shutil.which("gtkwave"),
324
+ ]
325
+ for candidate in candidates:
326
+ if candidate and Path(candidate).is_file():
327
+ return str(Path(candidate).resolve())
328
+ return None
329
+
330
+
331
+ def _parse_options(value: str | None) -> dict[str, object]:
332
+ result: dict[str, object] = {}
333
+ if not value:
334
+ return result
335
+ for item in value.split(","):
336
+ item = item.strip()
337
+ if not item:
338
+ continue
339
+ if "=" not in item:
340
+ raise LogicAgentError(f"invalid decoder option: {item!r}; expected key=value")
341
+ key, option = item.split("=", 1)
342
+ key, option = key.strip(), option.strip()
343
+ if not key or not option:
344
+ raise LogicAgentError(f"invalid decoder option: {item!r}; expected key=value")
345
+ # Preserve booleans and numeric options as typed values when possible.
346
+ # The decoder registry performs range, enum, and integer/floating-point
347
+ # validation; non-numeric values remain strings for enum options.
348
+ lowered = option.lower()
349
+ if lowered in {"true", "false"}:
350
+ result[key] = lowered == "true"
351
+ continue
352
+ try:
353
+ result[key] = int(option)
354
+ except ValueError:
355
+ try:
356
+ result[key] = float(option)
357
+ except ValueError:
358
+ result[key] = option
359
+ return result
360
+
361
+
362
+ def _move_global_options(argv: list[str]) -> list[str]:
363
+ """Allow --data-dir/--backend on either side of the subcommand.
364
+
365
+ argparse only accepts global options before the subcommand; users and MCP
366
+ launch snippets routinely append them. Move only exact, value-taking flags.
367
+ """
368
+ moved: list[str] = []
369
+ rest: list[str] = []
370
+ index = 0
371
+ while index < len(argv):
372
+ item = argv[index]
373
+ if item in {"--data-dir", "--backend"} and index + 1 < len(argv):
374
+ moved.extend([item, argv[index + 1]])
375
+ index += 2
376
+ continue
377
+ rest.append(item)
378
+ index += 1
379
+ return moved + rest
380
+
381
+
382
+ if __name__ == "__main__":
383
+ sys.exit(main())
384
+
385
+
386
+
387
+