logic-agent-mcp 0.0.0-stage → 1.2.1

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 +200 -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/msvcp100.dll +0 -0
  66. package/runtime/bin/msvcr100.dll +0 -0
  67. package/runtime/bin/pyexpat.pyd +0 -0
  68. package/runtime/bin/python34.dll +0 -0
  69. package/runtime/bin/python34.zip +0 -0
  70. package/runtime/bin/res/DSCope.bin +0 -0
  71. package/runtime/bin/res/DSCope.fw +0 -0
  72. package/runtime/bin/res/DSCope1.def.dsc +88 -0
  73. package/runtime/bin/res/DSCope2.def.dsc +54 -0
  74. package/runtime/bin/res/DSCope20.bin +0 -0
  75. package/runtime/bin/res/DSCope20.fw +0 -0
  76. package/runtime/bin/res/DSCopeC20B.bin +0 -0
  77. package/runtime/bin/res/DSCopeC20P.bin +0 -0
  78. package/runtime/bin/res/DSCopeU2B100.bin +0 -0
  79. package/runtime/bin/res/DSCopeU2B20.bin +0 -0
  80. package/runtime/bin/res/DSCopeU2P20.bin +0 -0
  81. package/runtime/bin/res/DSCopeU3P100.bin +0 -0
  82. package/runtime/bin/res/DSLogic.fw +0 -0
  83. package/runtime/bin/res/DSLogic0.def.dsc +297 -0
  84. package/runtime/bin/res/DSLogic1.def.dsc +82 -0
  85. package/runtime/bin/res/DSLogic2.def.dsc +52 -0
  86. package/runtime/bin/res/DSLogic33.bin +0 -0
  87. package/runtime/bin/res/DSLogic50.bin +0 -0
  88. package/runtime/bin/res/DSLogicBasic.bin +0 -0
  89. package/runtime/bin/res/DSLogicPlus-pgl12-2.bin +0 -0
  90. package/runtime/bin/res/DSLogicPlus-pgl12.bin +0 -0
  91. package/runtime/bin/res/DSLogicPlus.bin +0 -0
  92. package/runtime/bin/res/DSLogicPlus.fw +0 -0
  93. package/runtime/bin/res/DSLogicPro.bin +0 -0
  94. package/runtime/bin/res/DSLogicPro.fw +0 -0
  95. package/runtime/bin/res/DSLogicU2Basic-pgl12-2.bin +0 -0
  96. package/runtime/bin/res/DSLogicU2Basic-pgl12.bin +0 -0
  97. package/runtime/bin/res/DSLogicU2Basic.bin +0 -0
  98. package/runtime/bin/res/DSLogicU2Pro16.bin +0 -0
  99. package/runtime/bin/res/DSLogicU3Pro16.bin +0 -0
  100. package/runtime/bin/res/DSLogicU3Pro32.bin +0 -0
  101. package/runtime/bin/res/license.txt +20 -0
  102. package/runtime/bin/res/virtual-demo1.dsc +68 -0
  103. package/runtime/bin/select.pyd +0 -0
  104. package/runtime/bin/sigrok-cli.exe +0 -0
  105. package/runtime/bin/unicodedata.pyd +0 -0
  106. package/runtime/bin/winsound.pyd +0 -0
  107. package/runtime/bin/zlib1.dll +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,233 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ from .errors import ValidationError
6
+
7
+
8
+ @dataclass(frozen=True)
9
+ class UartSettings:
10
+ baud: int = 115_200
11
+ data_bits: int = 8
12
+ parity: str = "none"
13
+ stop_bits: float = 1.0
14
+ idle_high: bool = True
15
+ inverted: bool = False
16
+ msb_first: bool = False
17
+
18
+ @classmethod
19
+ def from_mapping(cls, value: dict | None) -> "UartSettings":
20
+ value = value or {}
21
+ try:
22
+ settings = cls(
23
+ baud=int(value.get("baud", 115_200)),
24
+ data_bits=int(value.get("data_bits", 8)),
25
+ parity=str(value.get("parity", "none")).lower(),
26
+ stop_bits=float(value.get("stop_bits", 1.0)),
27
+ idle_high=bool(value.get("idle_high", True)),
28
+ inverted=bool(value.get("inverted", False)),
29
+ msb_first=bool(value.get("msb_first", False)),
30
+ )
31
+ except (TypeError, ValueError) as exc:
32
+ raise ValidationError("invalid UART settings") from exc
33
+ settings.validate()
34
+ return settings
35
+
36
+ def validate(self) -> None:
37
+ if not 50 <= self.baud <= 20_000_000:
38
+ raise ValidationError("uart.baud must be between 50 and 20,000,000")
39
+ if self.data_bits not in {5, 6, 7, 8}:
40
+ raise ValidationError("uart.data_bits must be 5, 6, 7, or 8")
41
+ if self.parity not in {"none", "even", "odd"}:
42
+ raise ValidationError("uart.parity must be none, even, or odd")
43
+ if self.stop_bits not in {1.0, 1.5, 2.0}:
44
+ raise ValidationError("uart.stop_bits must be 1, 1.5, or 2")
45
+
46
+
47
+ @dataclass(frozen=True)
48
+ class DecodedByte:
49
+ start_s: float
50
+ end_s: float
51
+ value: int
52
+ parity_ok: bool | None
53
+ stop_ok: bool
54
+
55
+ def to_dict(self) -> dict:
56
+ return {
57
+ "start_s": round(self.start_s, 9),
58
+ "end_s": round(self.end_s, 9),
59
+ "value": self.value,
60
+ "parity_ok": self.parity_ok,
61
+ "stop_ok": self.stop_ok,
62
+ }
63
+
64
+
65
+ @dataclass(frozen=True)
66
+ class UartFrameGroup:
67
+ start_s: float
68
+ end_s: float
69
+ data: bytes
70
+ text: str
71
+ errors: tuple[str, ...] = ()
72
+
73
+ def to_dict(self) -> dict:
74
+ return {
75
+ "start_s": round(self.start_s, 9),
76
+ "end_s": round(self.end_s, 9),
77
+ "data_hex": self.data.hex(" "),
78
+ "text": self.text,
79
+ "errors": list(self.errors),
80
+ }
81
+
82
+
83
+ def decode_uart(
84
+ samples: bytes,
85
+ sample_rate_hz: int,
86
+ settings: UartSettings,
87
+ *,
88
+ max_bytes: int = 4096,
89
+ group_gap_s: float = 0.005,
90
+ ) -> tuple[list[DecodedByte], list[UartFrameGroup], list[str]]:
91
+ """Decode 8N1/8E1/8O1 UART from one-bit-per-sample data.
92
+
93
+ Returns decoded bytes, text groups, and non-fatal warnings. A dominant idle
94
+ level that disagrees with settings is a hard validation error because every
95
+ subsequent bit boundary would be wrong.
96
+ """
97
+ if not samples:
98
+ raise ValidationError("cannot decode UART from empty samples")
99
+ if sample_rate_hz <= 0:
100
+ raise ValidationError("sample_rate_hz must be positive")
101
+ settings.validate()
102
+ if sample_rate_hz < settings.baud * 4:
103
+ raise ValidationError("sample_rate_hz is too low for reliable UART decoding; use at least 4x baud")
104
+ if max_bytes <= 0:
105
+ raise ValidationError("max_bytes must be positive")
106
+
107
+ idle = 1 if settings.idle_high else 0
108
+ observed_idle_ratio = sum(1 for value in samples if value == idle) / len(samples)
109
+ inverted_idle_ratio = 1 - observed_idle_ratio
110
+ if inverted_idle_ratio > observed_idle_ratio and not settings.inverted:
111
+ raise ValidationError(
112
+ "the line idles at the opposite level; set uart.inverted or uart.idle_high to match the probe",
113
+ details={
114
+ "configured_idle_level": idle,
115
+ "configured_idle_ratio": round(observed_idle_ratio, 4),
116
+ "opposite_level_ratio": round(inverted_idle_ratio, 4),
117
+ },
118
+ )
119
+ logical = bytes(1 - value if settings.inverted else value for value in samples)
120
+ idle = 1 if settings.idle_high else 0
121
+
122
+ spb = sample_rate_hz / settings.baud
123
+ start_samples = _edge_positions(logical, 1 - idle)
124
+ decoded: list[DecodedByte] = []
125
+ warnings: list[str] = []
126
+ errors_seen = 0
127
+ index = 0
128
+ while index < len(start_samples) and len(decoded) < max_bytes:
129
+ start = start_samples[index]
130
+ begin = start + spb / 2
131
+ end = start + (1 + settings.data_bits + (1 if settings.parity != "none" else 0) + settings.stop_bits) * spb
132
+ if end >= len(samples):
133
+ break
134
+ if _sample_at(logical, begin) == idle:
135
+ index += 1
136
+ continue
137
+
138
+ value = 0
139
+ for bit in range(settings.data_bits):
140
+ level = _majority(logical, begin + (bit + 1) * spb, spb * 0.25)
141
+ if level:
142
+ value |= 1 << (settings.data_bits - 1 - bit if settings.msb_first else bit)
143
+ cursor = 1 + settings.data_bits
144
+ parity_ok = None
145
+ if settings.parity != "none":
146
+ parity_bit = _majority(logical, begin + cursor * spb, spb * 0.25)
147
+ ones = value.bit_count()
148
+ expected = ones % 2 if settings.parity == "even" else 1 - (ones % 2)
149
+ parity_ok = parity_bit == expected
150
+ if not parity_ok:
151
+ errors_seen += 1
152
+ cursor += 1
153
+ stop_ok = _majority(logical, begin + (cursor + settings.stop_bits / 2 - 0.5) * spb, spb * 0.25) == idle
154
+ if not stop_ok:
155
+ errors_seen += 1
156
+ decoded.append(
157
+ DecodedByte(
158
+ start_s=start / sample_rate_hz,
159
+ end_s=end / sample_rate_hz,
160
+ value=value,
161
+ parity_ok=parity_ok,
162
+ stop_ok=stop_ok,
163
+ )
164
+ )
165
+ index = _first_start_after(start_samples, index, int(end - spb / 2))
166
+
167
+ if len(decoded) >= max_bytes:
168
+ warnings.append(f"decode truncated at max_bytes={max_bytes}")
169
+ if errors_seen:
170
+ warnings.append(f"{errors_seen} framing/parity errors detected; inspect raw bytes before trusting text")
171
+ groups = _group_bytes(decoded, group_gap_s)
172
+ return decoded, groups, warnings
173
+
174
+
175
+ def _group_bytes(decoded: list[DecodedByte], gap_s: float) -> list[UartFrameGroup]:
176
+ groups: list[UartFrameGroup] = []
177
+ current: list[DecodedByte] = []
178
+ for item in decoded:
179
+ if current and item.start_s - current[-1].end_s > gap_s:
180
+ groups.append(_make_group(current))
181
+ current = []
182
+ current.append(item)
183
+ if current:
184
+ groups.append(_make_group(current))
185
+ return groups
186
+
187
+
188
+ def _make_group(items: list[DecodedByte]) -> UartFrameGroup:
189
+ data = bytes(item.value for item in items)
190
+ errors: list[str] = []
191
+ if any(item.parity_ok is False for item in items):
192
+ errors.append("parity")
193
+ if any(not item.stop_ok for item in items):
194
+ errors.append("framing")
195
+ return UartFrameGroup(
196
+ start_s=items[0].start_s,
197
+ end_s=items[-1].end_s,
198
+ data=data,
199
+ text=data.decode("ascii", errors="backslashreplace"),
200
+ errors=tuple(errors),
201
+ )
202
+
203
+
204
+ def _edge_positions(samples: bytes, level: int) -> list[int]:
205
+ positions: list[int] = []
206
+ previous = samples[0]
207
+ for index in range(1, len(samples)):
208
+ if samples[index] == level and previous != level:
209
+ positions.append(index)
210
+ previous = samples[index]
211
+ return positions
212
+
213
+
214
+ def _sample_at(samples: bytes, position: float) -> int:
215
+ index = int(position)
216
+ if index < 0 or index >= len(samples):
217
+ raise ValidationError("UART decode ran past the end of the capture")
218
+ return samples[index]
219
+
220
+
221
+ def _majority(samples: bytes, center: float, width: float) -> int:
222
+ start = max(0, int(center - width / 2))
223
+ stop = min(len(samples), max(start + 1, int(center + width / 2)))
224
+ chunk = samples[start:stop]
225
+ return 1 if sum(chunk) * 2 >= len(chunk) else 0
226
+
227
+
228
+ def _first_start_after(positions: list[int], current: int, threshold: int) -> int:
229
+ index = current + 1
230
+ while index < len(positions) and positions[index] <= threshold:
231
+ index += 1
232
+ return index
233
+
@@ -0,0 +1,378 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import os
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from .analysis import protocol_hints, select_window, window_report
9
+ from .backends import Backend, DslabBackend, MockBackend, SigrokBackend
10
+ from .decoders import DecodeRequest, DecoderRuntime, decode_capture, protocol_specs, supported_protocols
11
+ from .errors import LogicAgentError, NotFoundError, ValidationError
12
+ from .models import CaptureRequest, Limits
13
+ from .protocols import UartSettings, decode_uart
14
+ from .signal import measure_periodic, summarize_channel
15
+ from .store import CaptureStore
16
+
17
+
18
+ DEFAULT_RESOURCE_URI_TEMPLATE = "logic-agent://captures/{capture_id}"
19
+
20
+
21
+ class LogicAgentService:
22
+ def __init__(
23
+ self,
24
+ *,
25
+ data_dir: Path | str | None = None,
26
+ backend: Backend | None = None,
27
+ limits: Limits | None = None,
28
+ ) -> None:
29
+ self.limits = limits or Limits()
30
+ self.data_dir = Path(data_dir or os.environ.get("LOGIC_AGENT_DATA_DIR") or ".logic_agent_data").resolve()
31
+ self.store = CaptureStore(self.data_dir / "captures")
32
+ self.backends: dict[str, Backend] = {
33
+ "mock": MockBackend(),
34
+ "sigrok": SigrokBackend(),
35
+ "dslab": DslabBackend(),
36
+ }
37
+ self.decoder_runtime = DecoderRuntime.discover()
38
+ if backend is not None:
39
+ self.backends[backend.name] = backend
40
+ self.default_backend = os.environ.get("LOGIC_AGENT_BACKEND") or self._auto_backend()
41
+
42
+ def _auto_backend(self) -> str:
43
+ dslab = self.backends.get("dslab")
44
+ if getattr(dslab, "available", False):
45
+ return "dslab"
46
+ sigrok = self.backends.get("sigrok")
47
+ return "sigrok" if getattr(sigrok, "available", False) else "mock"
48
+
49
+ def _backend(self, name: str | None) -> Backend:
50
+ selected = name or self.default_backend
51
+ try:
52
+ return self.backends[selected]
53
+ except KeyError as exc:
54
+ raise ValidationError(
55
+ f"unknown backend: {selected}",
56
+ details={"available_backends": sorted(self.backends)},
57
+ ) from exc
58
+
59
+ def capabilities(self) -> dict[str, Any]:
60
+ return {
61
+ "tool": "logic_agent",
62
+ "version": "0.1.0",
63
+ "backends": {
64
+ name: {
65
+ "available": bool(getattr(backend, "available", True)),
66
+ "kind": "hardware" if name in {"sigrok", "dslab"} else "simulation",
67
+ }
68
+ for name, backend in sorted(self.backends.items())
69
+ },
70
+ "default_backend": self.default_backend,
71
+ "limits": vars(self.limits),
72
+ "protocol_decoding": {
73
+ "runtime": (
74
+ {
75
+ "available": self.decoder_runtime.available,
76
+ "source": self.decoder_runtime.source,
77
+ "executable": self.decoder_runtime.executable,
78
+ "decoder_dir": (
79
+ str(self.decoder_runtime.decoder_dir)
80
+ if self.decoder_runtime.decoder_dir is not None
81
+ else None
82
+ ),
83
+ }
84
+ if self.decoder_runtime is not None
85
+ else {"available": False}
86
+ ),
87
+ "supported_protocols": supported_protocols(),
88
+ "option_syntax": (
89
+ "Decoder option values are validated by type. OPTION and DECODER.OPTION "
90
+ "are both accepted; use the latter when stacked decoders use the same "
91
+ "option name. CLI options must not contain commas or colons."
92
+ ),
93
+ "stacked_decoders": True,
94
+ "protocols": {
95
+ name: spec.describe()
96
+ for name, spec in sorted(protocol_specs().items())
97
+ },
98
+ },
99
+ "resource_uri_template": DEFAULT_RESOURCE_URI_TEMPLATE,
100
+ "next_steps": [
101
+ "Call list_devices before capturing.",
102
+ "Capture a short window, inspect summaries, then drill into another window.",
103
+ "Use read_resource for a bounded preview; raw arrays are intentionally not returned in tool results.",
104
+ ],
105
+ }
106
+
107
+ def list_devices(self, backend: str | None = None) -> dict[str, Any]:
108
+ selected = self._backend(backend)
109
+ try:
110
+ devices = selected.list_devices()
111
+ except LogicAgentError as exc:
112
+ return {**exc.to_dict(), "backend": selected.name}
113
+ return {
114
+ "ok": True,
115
+ "backend": selected.name,
116
+ "devices": [device.to_dict() for device in devices],
117
+ }
118
+
119
+ def capture(self, args: dict[str, Any]) -> dict[str, Any]:
120
+ request = CaptureRequest.from_args(args)
121
+ self._check_limits(request)
122
+ backend = self._backend(request.backend)
123
+ captured = backend.capture(request)
124
+ captured.validate()
125
+ self._check_limits(request, captured.sample_count)
126
+ manifest = self.store.save(captured, request)
127
+ report = {
128
+ "capture_id": manifest["id"],
129
+ "backend": manifest["backend"],
130
+ "device": manifest["device"],
131
+ "sample_rate_hz": manifest["sample_rate_hz"],
132
+ "sample_count": manifest["sample_count"],
133
+ "duration_s": manifest["duration_s"],
134
+ "channels": [
135
+ {"id": channel.id, "summary": summarize_channel(
136
+ channel.id,
137
+ captured.samples[channel.id],
138
+ captured.sample_rate_hz,
139
+ ).to_dict()}
140
+ for channel in captured.channels
141
+ ],
142
+ "trigger": manifest["trigger"],
143
+ "trigger_applied": manifest["trigger_applied"],
144
+ "warnings": manifest["warnings"],
145
+ "resource_uri": DEFAULT_RESOURCE_URI_TEMPLATE.format(capture_id=manifest["id"]),
146
+ }
147
+ report["hints"] = [
148
+ hint
149
+ for channel in captured.channels
150
+ for hint in protocol_hints(
151
+ summarize_channel(channel.id, captured.samples[channel.id], captured.sample_rate_hz).to_dict()
152
+ )
153
+ ]
154
+ return {"ok": True, **report}
155
+
156
+ def list_captures(self) -> dict[str, Any]:
157
+ captures = self.store.list()
158
+ return {"ok": True, "captures": captures, "count": len(captures)}
159
+
160
+ def self_test(self, backend_name: str | None = None) -> dict[str, Any]:
161
+ backend = self._backend(backend_name or "dslab")
162
+ probe = getattr(backend, "self_test", None)
163
+ if probe is None:
164
+ raise ValidationError(
165
+ f"backend {backend.name} has no hardware self-test",
166
+ details={"available_backends": ["dslab"]},
167
+ )
168
+ result = probe()
169
+ return {
170
+ **result,
171
+ "backend": backend.name,
172
+ "note": (
173
+ "This validates USB, firmware, FPGA, sample capture and output files. "
174
+ "It does not validate an external probe connection or protocol."
175
+ ),
176
+ }
177
+
178
+ def import_csv(self, args: dict[str, Any]) -> dict[str, Any]:
179
+ from .importer import inspect_csv, iter_csv_samples
180
+ from .models import Channel, CapturedSignal
181
+
182
+ path = Path(_require_str(args, "path")).expanduser().resolve()
183
+ if path.suffix.lower() != ".csv":
184
+ raise ValidationError("only DSView CSV exports are supported")
185
+ requested = args.get("channels")
186
+ if requested is not None and (not isinstance(requested, list) or not requested):
187
+ raise ValidationError("channels must be a non-empty array when provided")
188
+ info = inspect_csv(path, max_scan_rows=min(self.limits.max_total_samples, 20_000))
189
+ channels = tuple(str(item) for item in requested) if requested else info.channels
190
+ if len(channels) > self.limits.max_channels:
191
+ raise ValidationError(f"at most {self.limits.max_channels} channels may be imported")
192
+ max_rows = self.limits.max_total_samples // max(1, len(channels))
193
+ info, samples = iter_csv_samples(path, channels, max_rows=max_rows)
194
+ total = len(next(iter(samples.values())))
195
+ if total >= max_rows:
196
+ raise ValidationError(
197
+ "CSV is larger than the configured sample budget; export a narrower time range",
198
+ details={"max_rows_per_channel": max_rows, "hint": "Use DSView cursors to select one region"},
199
+ )
200
+ request = CaptureRequest(
201
+ channels=channels,
202
+ sample_rate_hz=info.sample_rate_hz,
203
+ duration_s=max(total, 1) / info.sample_rate_hz,
204
+ label=(str(args["label"]).strip() or None) if args.get("label") is not None else None,
205
+ )
206
+ captured = CapturedSignal(
207
+ backend="dsview-csv",
208
+ device_id="imported-csv",
209
+ device_label=str(path),
210
+ channels=tuple(Channel(id=channel, name=channel, index=index) for index, channel in enumerate(channels)),
211
+ sample_rate_hz=info.sample_rate_hz,
212
+ samples=samples,
213
+ )
214
+ manifest = self.store.save(captured, request)
215
+ return {
216
+ "ok": True,
217
+ "capture_id": manifest["id"],
218
+ "source": str(path),
219
+ "sample_rate_hz": manifest["sample_rate_hz"],
220
+ "sample_count": manifest["sample_count"],
221
+ "duration_s": manifest["duration_s"],
222
+ "channels": [
223
+ {"id": channel, "summary": summarize_channel(channel, samples[channel], info.sample_rate_hz).to_dict()}
224
+ for channel in channels
225
+ ],
226
+ "resource_uri": DEFAULT_RESOURCE_URI_TEMPLATE.format(capture_id=manifest["id"]),
227
+ }
228
+
229
+ def measure_period(self, args: dict[str, Any]) -> dict[str, Any]:
230
+ capture_id = _require_str(args, "capture_id")
231
+ channel_id = _require_str(args, "channel")
232
+ manifest = self.store.manifest(capture_id)
233
+ samples, _ = self.store.load_channel(capture_id, channel_id)
234
+ start_s = _float_arg(args, "start_s", 0.0)
235
+ duration_s = _optional_float_arg(args, "duration_s")
236
+ window = select_window(samples, manifest["sample_rate_hz"], start_s, duration_s)
237
+ report = measure_periodic(channel_id, window.samples, manifest["sample_rate_hz"])
238
+ return {
239
+ "ok": True,
240
+ "capture_id": capture_id,
241
+ "window": {
242
+ "start_s": round(window.offset_samples / manifest["sample_rate_hz"], 9),
243
+ "duration_s": round(len(window.samples) / manifest["sample_rate_hz"], 9),
244
+ },
245
+ **report,
246
+ }
247
+
248
+ def analyze_window(self, args: dict[str, Any]) -> dict[str, Any]:
249
+ capture_id = _require_str(args, "capture_id")
250
+ channel_id = _require_str(args, "channel")
251
+ manifest = self.store.manifest(capture_id)
252
+ samples, _ = self.store.load_channel(capture_id, channel_id)
253
+ start_s = _float_arg(args, "start_s", 0.0)
254
+ duration_s = _optional_float_arg(args, "duration_s")
255
+ max_edges = int(args.get("max_edges", 80))
256
+ window = select_window(samples, manifest["sample_rate_hz"], start_s, duration_s)
257
+ report = window_report(window, channel_id, manifest["sample_rate_hz"], max_edges=max_edges)
258
+ return {"ok": True, "capture_id": capture_id, "channel": channel_id, **report, "hints": protocol_hints(report["summary"])}
259
+
260
+ def decode_uart(self, args: dict[str, Any]) -> dict[str, Any]:
261
+ capture_id = _require_str(args, "capture_id")
262
+ channel_id = _require_str(args, "channel")
263
+ manifest = self.store.manifest(capture_id)
264
+ samples, _ = self.store.load_channel(capture_id, channel_id)
265
+ start_s = _float_arg(args, "start_s", 0.0)
266
+ duration_s = _optional_float_arg(args, "duration_s")
267
+ window = select_window(samples, manifest["sample_rate_hz"], start_s, duration_s)
268
+ settings = UartSettings.from_mapping(args.get("uart"))
269
+ decoded, groups, warnings = decode_uart(
270
+ window.samples,
271
+ manifest["sample_rate_hz"],
272
+ settings,
273
+ max_bytes=int(args.get("max_bytes", 4096)),
274
+ )
275
+ return {
276
+ "ok": True,
277
+ "capture_id": capture_id,
278
+ "channel": channel_id,
279
+ "window": {
280
+ "start_s": round(window.offset_samples / manifest["sample_rate_hz"], 9),
281
+ "duration_s": round(len(window.samples) / manifest["sample_rate_hz"], 9),
282
+ },
283
+ "settings": vars(settings),
284
+ "byte_count": len(decoded),
285
+ "groups": [group.to_dict() for group in groups],
286
+ "warnings": warnings,
287
+ }
288
+
289
+ def decode_protocol(self, args: dict[str, Any]) -> dict[str, Any]:
290
+ capture_id = _require_str(args, "capture_id")
291
+ protocol = _require_str(args, "protocol").lower()
292
+ channel_map = args.get("channels")
293
+ if not isinstance(channel_map, dict) or not channel_map:
294
+ raise ValidationError("channels must be an object such as {\"scl\": \"D0\", \"sda\": \"D1\"}")
295
+ normalized = {str(key): str(value) for key, value in channel_map.items()}
296
+ options = args.get("options") or {}
297
+ if not isinstance(options, dict):
298
+ raise ValidationError("options must be an object")
299
+ request = DecodeRequest(
300
+ capture_id=capture_id,
301
+ protocol=protocol,
302
+ channel_map=normalized,
303
+ options=dict(options),
304
+ start_s=_float_arg(args, "start_s", 0.0),
305
+ duration_s=_optional_float_arg(args, "duration_s"),
306
+ max_events=int(args.get("max_events", 500)),
307
+ include_bits=bool(args.get("include_bits", False)),
308
+ include_lower_layers=bool(args.get("include_lower_layers", False)),
309
+ )
310
+ return decode_capture(store=self.store, runtime=self.decoder_runtime, request=request)
311
+
312
+ def read_resource(self, capture_id: str) -> tuple[str, str]:
313
+ manifest = self.store.manifest(capture_id)
314
+ text = json.dumps(manifest, indent=2, ensure_ascii=False)
315
+ if len(text) > self.limits.max_tool_chars:
316
+ preview = {
317
+ "id": manifest["id"],
318
+ "created_at": manifest["created_at"],
319
+ "label": manifest.get("label"),
320
+ "device": manifest["device"],
321
+ "sample_rate_hz": manifest["sample_rate_hz"],
322
+ "sample_count": manifest["sample_count"],
323
+ "duration_s": manifest["duration_s"],
324
+ "channels": [
325
+ {key: channel[key] for key in ("id", "name", "sample_count", "sha256")}
326
+ for channel in manifest["channels"]
327
+ ],
328
+ "note": "Full manifest omitted because it exceeds max_tool_chars.",
329
+ }
330
+ text = json.dumps(preview, indent=2, ensure_ascii=False)
331
+ return text, "application/json"
332
+
333
+ def _check_limits(self, request: CaptureRequest, actual_samples: int | None = None) -> None:
334
+ if len(request.channels) > self.limits.max_channels:
335
+ raise ValidationError(f"at most {self.limits.max_channels} channels may be captured")
336
+ if request.sample_rate_hz > self.limits.max_sample_rate_hz:
337
+ raise ValidationError(f"sample_rate_hz exceeds the configured limit of {self.limits.max_sample_rate_hz}")
338
+ if request.duration_s > self.limits.max_duration_s:
339
+ raise ValidationError(f"duration_s exceeds the configured limit of {self.limits.max_duration_s}")
340
+ samples = actual_samples or request.sample_count
341
+ if samples * len(request.channels) > self.limits.max_total_samples:
342
+ raise ValidationError(
343
+ "capture would exceed the configured sample budget",
344
+ details={
345
+ "requested_samples": samples,
346
+ "channels": len(request.channels),
347
+ "max_total_samples": self.limits.max_total_samples,
348
+ },
349
+ )
350
+ if samples * len(request.channels) > self.limits.max_capture_bytes:
351
+ raise ValidationError("capture would exceed the configured byte budget")
352
+
353
+
354
+ def _require_str(args: dict[str, Any], key: str) -> str:
355
+ value = args.get(key)
356
+ if not isinstance(value, str) or not value.strip():
357
+ raise ValidationError(f"{key} is required")
358
+ return value.strip()
359
+
360
+
361
+ def _float_arg(args: dict[str, Any], key: str, default: float) -> float:
362
+ value = args.get(key, default)
363
+ try:
364
+ return float(value)
365
+ except (TypeError, ValueError) as exc:
366
+ raise ValidationError(f"{key} must be a number") from exc
367
+
368
+
369
+ def _optional_float_arg(args: dict[str, Any], key: str) -> float | None:
370
+ value = args.get(key)
371
+ if value is None:
372
+ return None
373
+ try:
374
+ return float(value)
375
+ except (TypeError, ValueError) as exc:
376
+ raise ValidationError(f"{key} must be a number") from exc
377
+
378
+