ppk2-lib 0.1.0__tar.gz

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 (79) hide show
  1. ppk2_lib-0.1.0/.gitignore +51 -0
  2. ppk2_lib-0.1.0/CHANGELOG.md +70 -0
  3. ppk2_lib-0.1.0/LICENSE-APACHE +202 -0
  4. ppk2_lib-0.1.0/LICENSE-MIT +21 -0
  5. ppk2_lib-0.1.0/PKG-INFO +164 -0
  6. ppk2_lib-0.1.0/pyproject.toml +166 -0
  7. ppk2_lib-0.1.0/src/ppk2/__init__.py +100 -0
  8. ppk2_lib-0.1.0/src/ppk2/__main__.py +5 -0
  9. ppk2_lib-0.1.0/src/ppk2/cli/__init__.py +3 -0
  10. ppk2_lib-0.1.0/src/ppk2/cli/commands/__init__.py +23 -0
  11. ppk2_lib-0.1.0/src/ppk2/cli/commands/capture.py +270 -0
  12. ppk2_lib-0.1.0/src/ppk2/cli/commands/convert.py +119 -0
  13. ppk2_lib-0.1.0/src/ppk2/cli/commands/discover.py +14 -0
  14. ppk2_lib-0.1.0/src/ppk2/cli/commands/list_devices.py +45 -0
  15. ppk2_lib-0.1.0/src/ppk2/cli/commands/metadata.py +36 -0
  16. ppk2_lib-0.1.0/src/ppk2/cli/commands/power.py +63 -0
  17. ppk2_lib-0.1.0/src/ppk2/cli/commands/run.py +162 -0
  18. ppk2_lib-0.1.0/src/ppk2/cli/csv.py +67 -0
  19. ppk2_lib-0.1.0/src/ppk2/cli/main.py +276 -0
  20. ppk2_lib-0.1.0/src/ppk2/cli/ppk2file.py +179 -0
  21. ppk2_lib-0.1.0/src/ppk2/cli/signals.py +46 -0
  22. ppk2_lib-0.1.0/src/ppk2/cli/trace.py +60 -0
  23. ppk2_lib-0.1.0/src/ppk2/client/__init__.py +50 -0
  24. ppk2_lib-0.1.0/src/ppk2/client/discovery.py +515 -0
  25. ppk2_lib-0.1.0/src/ppk2/client/session.py +639 -0
  26. ppk2_lib-0.1.0/src/ppk2/protocol/__init__.py +51 -0
  27. ppk2_lib-0.1.0/src/ppk2/protocol/calibration.py +51 -0
  28. ppk2_lib-0.1.0/src/ppk2/protocol/metadata.py +320 -0
  29. ppk2_lib-0.1.0/src/ppk2/protocol/opcode.py +110 -0
  30. ppk2_lib-0.1.0/src/ppk2/protocol/sample.py +61 -0
  31. ppk2_lib-0.1.0/src/ppk2/protocol/stream.py +375 -0
  32. ppk2_lib-0.1.0/src/ppk2/py.typed +0 -0
  33. ppk2_lib-0.1.0/tests/__init__.py +0 -0
  34. ppk2_lib-0.1.0/tests/cli/__init__.py +0 -0
  35. ppk2_lib-0.1.0/tests/cli/conftest.py +20 -0
  36. ppk2_lib-0.1.0/tests/cli/test_capture_semantics.py +273 -0
  37. ppk2_lib-0.1.0/tests/cli/test_convert.py +172 -0
  38. ppk2_lib-0.1.0/tests/cli/test_csv.py +89 -0
  39. ppk2_lib-0.1.0/tests/cli/test_error_mapping.py +112 -0
  40. ppk2_lib-0.1.0/tests/cli/test_list.py +117 -0
  41. ppk2_lib-0.1.0/tests/cli/test_ppk2file.py +172 -0
  42. ppk2_lib-0.1.0/tests/cli/test_run_child.py +81 -0
  43. ppk2_lib-0.1.0/tests/cli/test_signals.py +56 -0
  44. ppk2_lib-0.1.0/tests/cli/test_smoke.py +166 -0
  45. ppk2_lib-0.1.0/tests/cli/test_trace.py +38 -0
  46. ppk2_lib-0.1.0/tests/cli/test_user_gain.py +118 -0
  47. ppk2_lib-0.1.0/tests/client/__init__.py +0 -0
  48. ppk2_lib-0.1.0/tests/client/test_discovery_logic.py +384 -0
  49. ppk2_lib-0.1.0/tests/client/test_session_internals.py +610 -0
  50. ppk2_lib-0.1.0/tests/fixtures/README.md +50 -0
  51. ppk2_lib-0.1.0/tests/fixtures/make_reference.mjs +50 -0
  52. ppk2_lib-0.1.0/tests/fixtures/metadata.parsed.json +56 -0
  53. ppk2_lib-0.1.0/tests/fixtures/metadata.raw +41 -0
  54. ppk2_lib-0.1.0/tests/fixtures/nordic_hooks.mjs +22 -0
  55. ppk2_lib-0.1.0/tests/fixtures/parsed_poweron.csv +601 -0
  56. ppk2_lib-0.1.0/tests/fixtures/stream_poweron.bin +0 -0
  57. ppk2_lib-0.1.0/tests/hil/README.md +15 -0
  58. ppk2_lib-0.1.0/tests/hil/__init__.py +0 -0
  59. ppk2_lib-0.1.0/tests/hil/bench-dut/.gitignore +6 -0
  60. ppk2_lib-0.1.0/tests/hil/bench-dut/CMakeLists.txt +5 -0
  61. ppk2_lib-0.1.0/tests/hil/bench-dut/README.md +80 -0
  62. ppk2_lib-0.1.0/tests/hil/bench-dut/boards/nrf52840dk_nrf52840.overlay +32 -0
  63. ppk2_lib-0.1.0/tests/hil/bench-dut/boards/nrf54l15dk_nrf54l15_cpuapp.overlay +34 -0
  64. ppk2_lib-0.1.0/tests/hil/bench-dut/boards/nrf54lm20dk_nrf54lm20b_cpuapp.overlay +30 -0
  65. ppk2_lib-0.1.0/tests/hil/bench-dut/justfile +70 -0
  66. ppk2_lib-0.1.0/tests/hil/bench-dut/prj.conf +20 -0
  67. ppk2_lib-0.1.0/tests/hil/bench-dut/src/main.c +87 -0
  68. ppk2_lib-0.1.0/tests/hil/conftest.py +5 -0
  69. ppk2_lib-0.1.0/tests/hil/quickstart.tape +30 -0
  70. ppk2_lib-0.1.0/tests/hil/test_cli.py +93 -0
  71. ppk2_lib-0.1.0/tests/hil/test_client.py +204 -0
  72. ppk2_lib-0.1.0/tests/protocol/__init__.py +0 -0
  73. ppk2_lib-0.1.0/tests/protocol/fixtures.py +15 -0
  74. ppk2_lib-0.1.0/tests/protocol/test_calibration.py +49 -0
  75. ppk2_lib-0.1.0/tests/protocol/test_metadata.py +274 -0
  76. ppk2_lib-0.1.0/tests/protocol/test_opcode.py +44 -0
  77. ppk2_lib-0.1.0/tests/protocol/test_sample.py +46 -0
  78. ppk2_lib-0.1.0/tests/protocol/test_stream.py +603 -0
  79. ppk2_lib-0.1.0/tests/test_package_smoke.py +7 -0
@@ -0,0 +1,51 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+
8
+ # Virtualenvs (uv default)
9
+ .venv/
10
+ venv/
11
+ env/
12
+
13
+ # Test / coverage
14
+ .pytest_cache/
15
+ .coverage
16
+ htmlcov/
17
+ .tox/
18
+
19
+ # Tooling caches
20
+ .ruff_cache/
21
+ .mypy_cache/
22
+ .pyright/
23
+
24
+ # Build artefacts
25
+ build/
26
+ dist/
27
+ site/
28
+ *.egg-info/
29
+ *.egg
30
+
31
+ # IDE
32
+ .vscode/
33
+ .idea/
34
+
35
+ # macOS
36
+ .DS_Store
37
+
38
+ # Capture artefacts (raw byte dumps + CSV exports from validation runs)
39
+ *.csv
40
+ *.csv.gz
41
+ *.ppk2.bin
42
+ # Test fixtures (tiny, committed for reproducibility)
43
+ !tests/fixtures/*.csv
44
+ !tests/fixtures/*.bin
45
+ # The captures of the validation round live on the branch `captures`;
46
+ # `just captures` puts them here.
47
+ /validation/evidence/*/captures/*.csv.xz
48
+
49
+ # Firmware hex artefacts: built locally (`just hex`) or by the CI
50
+ # firmware matrix. Never committed.
51
+ *.hex
@@ -0,0 +1,70 @@
1
+ # Changelog
2
+
3
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
4
+
5
+ ## 0.1.0 (2026-11-24)
6
+
7
+ First public release. Experimental: the API may change between 0.x
8
+ versions.
9
+
10
+ ### Command line
11
+
12
+ - `ppk2 list`, `discover` and `metadata` find a PPK2 and show its
13
+ calibration. `ppk2 list --mask-serial` hides all but the last four
14
+ characters of each serial number, for a screenshot or a recording.
15
+ - `ppk2 capture` records current and digital inputs in Ampere meter or
16
+ Source meter mode, to the 11-column CSV that Nordic's Power Profiler
17
+ app exports, or to a session file in the app's `.ppk2` format.
18
+ `--seconds N` gives N seconds of samples, 500,000 for 5 s, and the
19
+ command exits 1 if they do not all arrive.
20
+ - `ppk2 convert` turns a CSV capture into a `.ppk2` file.
21
+ - `ppk2 power on|off` switches power to the device under test (DUT),
22
+ and `--hold` keeps it on until Ctrl-C.
23
+ - `ppk2 run -- <command>` powers the DUT for the duration of a command
24
+ and can record meanwhile. When it is terminated, it terminates the
25
+ command.
26
+ - Exit codes: 1 for an error with the PPK2, the session or the output
27
+ file, with one line starting with `error:`. 2 for a usage error, and
28
+ 130 after Ctrl-C. `run` returns the command's code.
29
+
30
+ ### Library
31
+
32
+ - `ppk2.protocol`: commands, calibration text, sample decoding,
33
+ calibration formula and stream parser. This layer uses the standard
34
+ library only.
35
+ - `ppk2.client`: discovery of the data port, and a `Session` with
36
+ Ampere meter and Source meter modes, power switching, user gain, a
37
+ voltage limit and spike-filter settings.
38
+ - Lost samples are reported and keep their place in the trace. The
39
+ files record each as 0.2 µA, as Nordic's app does.
40
+ - `Session.capture` calls a function for every sample until it returns
41
+ `False`. `keep_going` ends a capture on a PPK2 that sends nothing.
42
+ - When bytes of the stream are lost, the parser finds the start of the
43
+ words again and goes on.
44
+ - A session leaves the PPK2 quiet for the next program, and opens a
45
+ PPK2 that another program left streaming.
46
+
47
+ ### Validation
48
+
49
+ - The parser gives the same samples as the app's on a recorded stream
50
+ that crosses all five measurement ranges.
51
+ - Captures of the same bench by the app and by `ppk2 capture` agree:
52
+ the mean current and the mean charge of the marked regions within
53
+ 0.11 %, in both modes, and the same 0.2 µA floor. See
54
+ [`validation/evidence/`](validation/evidence/bench_dut/README.md).
55
+ - Hardware tests and their bench firmware are in
56
+ [`tests/hil/`](tests/hil/README.md).
57
+
58
+ ### Limitations
59
+
60
+ - Synchronous only.
61
+ - On a bench it has run on macOS only. Linux and Windows pass the unit
62
+ tests. On Windows, `power on --hold` and Ctrl-C during `run` do not
63
+ work yet.
64
+ - Captures are continuous, like the Data logger mode of the app. There
65
+ is no equivalent of its Scope mode, which samples on a trigger.
66
+ - A capture starts about 10 ms before the DUT's power comes up. See
67
+ the [protocol page](docs/measure/protocol.md#10-known-caveats) for
68
+ the measurements.
69
+ - `.ppk2` files follow the layout the app documents. One 30 s file
70
+ was opened in the app and showed the figures of its CSV.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Roudy Dagher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.5
2
+ Name: ppk2-lib
3
+ Version: 0.1.0
4
+ Summary: Python library + CLI for Nordic's Power Profiler Kit II (PPK2)
5
+ Project-URL: Homepage, https://github.com/rdagher/ppk2-lib
6
+ Project-URL: Documentation, https://rdagher.github.io/ppk2-lib/
7
+ Project-URL: Repository, https://github.com/rdagher/ppk2-lib
8
+ Project-URL: Issues, https://github.com/rdagher/ppk2-lib/issues
9
+ Author: Roudy Dagher
10
+ License-Expression: Apache-2.0 OR MIT
11
+ License-File: LICENSE-APACHE
12
+ License-File: LICENSE-MIT
13
+ Keywords: current-measurement,embedded,nordic,power-profiler,ppk2
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering
24
+ Classifier: Topic :: System :: Hardware
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.11
27
+ Requires-Dist: pyserial>=3.5
28
+ Requires-Dist: typer>=0.12
29
+ Description-Content-Type: text/markdown
30
+
31
+ # ppk2-lib
32
+
33
+ ppk2-lib provides a Python library and CLI for scripted measurements
34
+ with Nordic's
35
+ [Power Profiler Kit II](https://www.nordicsemi.com/Products/Development-hardware/Power-Profiler-Kit-2)
36
+ (PPK2). It records current and the eight digital inputs at 100,000
37
+ samples per second, from a terminal or in CI. Its captures
38
+ are checked against Nordic's
39
+ [Power Profiler app](https://docs.nordicsemi.com/r/bundle/nrf-connect-for-desktop/page/app/pc-nrfconnect-ppk/using_ppk_app.html).
40
+
41
+ A GPIO that the firmware raises around a piece of code shows on a
42
+ digital input, so a capture also tells
43
+ [what that code draws](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/docs/user/recipes.md#current-of-a-marked-region).
44
+
45
+ This is an experimental release (0.1.0). It works and is checked on
46
+ hardware, but the API may still change between 0.x versions.
47
+
48
+ ![From a terminal: the PPK2 found, three seconds recorded to a CSV file, then converted to a file for the app](https://raw.githubusercontent.com/rdagher/ppk2-lib/v0.1.0/docs/img/quickstart.gif)
49
+
50
+ ## Installation
51
+
52
+ ```sh
53
+ pip install ppk2-lib
54
+ ```
55
+
56
+ Or with [uv](https://docs.astral.sh/uv/):
57
+
58
+ ```sh
59
+ uv tool install ppk2-lib
60
+ uvx --from ppk2-lib ppk2 list
61
+ ```
62
+
63
+ You need Python 3.11 or newer. On Windows, two things do not work yet:
64
+ see [platform notes](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/docs/user/getting-started.md#windows).
65
+
66
+ ## Quick start
67
+
68
+ Wire the PPK2 as for the app, quit the app, and run:
69
+
70
+ ```console
71
+ $ ppk2 list
72
+ PPK2 serial=A1B2C3D4E5F6
73
+ /dev/cu.usbmodemA1B2C3D4E5F62 [data port]
74
+ /dev/cu.usbmodemA1B2C3D4E5F64 [idle]
75
+
76
+ $ ppk2 capture --out boot.csv --seconds 3 --source --vdd 3.3
77
+ opening session (Source meter mode, vdd=3300 mV)
78
+ capturing 3.00 s -> boot.csv (Ctrl-C to stop early)
79
+ [ 1.0s] 99329 samples mean 954.17 µA
80
+ [ 2.0s] 199681 samples mean 826.31 µA
81
+ captured 300000 samples over 3.00 s (100037 Hz)
82
+ ```
83
+
84
+ With `--source`, the PPK2 powers the device under test (DUT) at 3.3 V.
85
+ Without it, the PPK2 is in Ampere meter mode, for a DUT with its own
86
+ supply.
87
+
88
+ A few more commands:
89
+
90
+ ```sh
91
+ ppk2 capture --out idle.ppk2 --seconds 30 # a session file in the app's format
92
+ ppk2 convert boot.csv boot.ppk2 # the same, from a CSV
93
+ ppk2 power on --hold --source --vdd 3.3 # keep the DUT powered until Ctrl-C
94
+ ppk2 run --source --vdd 3.3 -- west flash # power the DUT for one command
95
+ ```
96
+
97
+ And from Python:
98
+
99
+ ```python
100
+ from ppk2 import Mode, Session, find_ppk2
101
+
102
+ with Session.open(find_ppk2().device) as session:
103
+ session.set_mode(Mode.AMPERE)
104
+ session.start_measuring()
105
+ session.power_on()
106
+ session.capture(lambda sample: sample.current_micro_amps < 1000)
107
+ ```
108
+
109
+ ## Documentation
110
+
111
+ The documentation is published at <https://rdagher.github.io/ppk2-lib/>,
112
+ built from [`docs/`](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/docs/index.md) by `just docs`.
113
+
114
+ ![The parts. A developer, a CI job or an AI coding assistant run the ppk2 command or use the Python API on the host. The library drives the PPK2 over USB. The PPK2 measures the current of the DUT and samples its digital inputs. A capture is written as a CSV or a .ppk2 file. Beside them, one second of a capture with its marked regions](https://raw.githubusercontent.com/rdagher/ppk2-lib/v0.1.0/docs/img/architecture.png)
115
+
116
+ See the [changelog](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/CHANGELOG.md) for what 0.1.0 contains and for its
117
+ limits. For AI coding assistants, [`llms.txt`](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/llms.txt) maps the
118
+ documentation, and [`.claude/skills/ppk2/SKILL.md`](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/.claude/skills/ppk2/SKILL.md)
119
+ is a procedure for driving a PPK2.
120
+
121
+ ## Validation
122
+
123
+ Captures of the same bench by the app and by `ppk2 capture` agree
124
+ within 0.11 % on the mean current and charge of the marked regions,
125
+ in both modes. See the [method](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/docs/validation/method.md) and
126
+ the [results](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/docs/validation/results.md), with their limits: one PPK2,
127
+ and the app as the reference.
128
+
129
+ ## Development
130
+
131
+ ```sh
132
+ just sync # install into .venv (needs uv and just)
133
+ just ci # type check, lint, unit tests
134
+ just test-hw # hardware tests: needs a PPK2 and the bench firmware
135
+ just docs # build the documentation site into site/
136
+ ```
137
+
138
+ ## Origin
139
+
140
+ The protocol code was written from a reading of the source of Nordic's
141
+ app ([pc-nrfconnect-ppk](https://github.com/nordicsemi/pc-nrfconnect-ppk))
142
+ and from bench measurements. It contains none of that source,
143
+ whose licence allows reading and running it but not redistributing it.
144
+
145
+ The code and the documentation were written with Claude Code and
146
+ reviewed by the author. The figures are checked on a bench against
147
+ Nordic's app: see the [method](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/docs/validation/method.md) and the
148
+ [results](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/docs/validation/results.md).
149
+
150
+ ## Related projects
151
+
152
+ - Nordic's Power Profiler app: the reference for this package.
153
+ - The `ppk2` skill of Nordic MCP, Nordic's tooling for AI assistants.
154
+ - IRNAS's [ppk2-api-python](https://github.com/IRNAS/ppk2-api-python):
155
+ another Python library for the PPK2, under GPL-2.0.
156
+
157
+ See [related projects](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/docs/index.md#related-projects) for more.
158
+
159
+ ## Licence
160
+
161
+ [Apache-2.0](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/LICENSE-APACHE) or [MIT](https://github.com/rdagher/ppk2-lib/blob/v0.1.0/LICENSE-MIT), at your option.
162
+
163
+ ppk2-lib is not affiliated with or endorsed by Nordic Semiconductor.
164
+ PPK2, Power Profiler Kit and nRF are Nordic's product names.
@@ -0,0 +1,166 @@
1
+ [project]
2
+ name = "ppk2-lib"
3
+ dynamic = ["version", "readme"]
4
+ description = "Python library + CLI for Nordic's Power Profiler Kit II (PPK2)"
5
+ authors = [{ name = "Roudy Dagher" }]
6
+ license = "Apache-2.0 OR MIT"
7
+ license-files = ["LICENSE-*"]
8
+ requires-python = ">=3.11"
9
+ keywords = ["ppk2", "nordic", "power-profiler", "embedded", "current-measurement"]
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Intended Audience :: Developers",
13
+ "Operating System :: MacOS",
14
+ "Operating System :: POSIX :: Linux",
15
+ "Operating System :: Microsoft :: Windows",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Topic :: Scientific/Engineering",
21
+ "Topic :: System :: Hardware",
22
+ "Typing :: Typed",
23
+ ]
24
+ dependencies = [
25
+ "pyserial>=3.5",
26
+ "typer>=0.12",
27
+ ]
28
+
29
+ [project.scripts]
30
+ ppk2 = "ppk2.cli.main:main"
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/rdagher/ppk2-lib"
34
+ Documentation = "https://rdagher.github.io/ppk2-lib/"
35
+ Repository = "https://github.com/rdagher/ppk2-lib"
36
+ Issues = "https://github.com/rdagher/ppk2-lib/issues"
37
+
38
+ [dependency-groups]
39
+ # The A/B capture-comparison harness (validation/): not needed for
40
+ # the library, the CLI, or the fast test tier. matplotlib draws the
41
+ # plots of the evidence; uv.lock fixes its version, so they come out
42
+ # the same on every machine.
43
+ validation = [
44
+ "matplotlib>=3.9",
45
+ "pandas>=2",
46
+ "scipy>=1.11",
47
+ ]
48
+ dev = [
49
+ "pytest>=8",
50
+ "pyright>=1.1.380",
51
+ "ruff>=0.7",
52
+ ]
53
+ # The documentation site (zensical.toml, built with Zensical).
54
+ docs = [
55
+ "zensical>=0.1.3",
56
+ "mkdocstrings-python>=1.16",
57
+ ]
58
+
59
+ [tool.hatch.version]
60
+ path = "src/ppk2/__init__.py"
61
+
62
+ # PyPI shows the README but does not resolve its relative links. In
63
+ # the package metadata they point to GitHub at the tag of the version,
64
+ # so the page of a release keeps the pictures and pages of that release.
65
+ [tool.hatch.metadata.hooks.fancy-pypi-readme]
66
+ content-type = "text/markdown"
67
+
68
+ [[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
69
+ path = "README.md"
70
+
71
+ [[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
72
+ pattern = '\]\((docs/img/[^)]+)\)'
73
+ replacement = '](https://raw.githubusercontent.com/rdagher/ppk2-lib/v$HFPR_VERSION/\1)'
74
+
75
+ [[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
76
+ pattern = '\]\((?!https?://|#)([^)]+)\)'
77
+ replacement = '](https://github.com/rdagher/ppk2-lib/blob/v$HFPR_VERSION/\1)'
78
+
79
+ [build-system]
80
+ requires = ["hatchling>=1.27", "hatch-fancy-pypi-readme>=24.1"]
81
+ build-backend = "hatchling.build"
82
+
83
+ [tool.hatch.build.targets.wheel]
84
+ packages = ["src/ppk2"]
85
+
86
+ [tool.hatch.build.targets.sdist]
87
+ # The source and the tests that run from it alone. tests/test_docs.py
88
+ # checks the documentation of the repository, which is not shipped.
89
+ include = ["/src", "/tests", "/CHANGELOG.md"]
90
+ exclude = ["/tests/test_docs.py"]
91
+
92
+ [tool.pytest.ini_options]
93
+ minversion = "8"
94
+ testpaths = ["tests"]
95
+ markers = [
96
+ "hardware: requires a real PPK2 plugged in (slow, HIL tier)",
97
+ ]
98
+ addopts = [
99
+ "-ra",
100
+ "--strict-markers",
101
+ "--strict-config",
102
+ ]
103
+ # A text file opened without an encoding reads differently on Windows.
104
+ # CI sets PYTHONWARNDEFAULTENCODING, which makes Python warn about it.
105
+ filterwarnings = ["error::EncodingWarning"]
106
+
107
+ [tool.pyright]
108
+ include = ["src", "tests"]
109
+ strict = ["src", "tests"]
110
+ exclude = ["**/__pycache__", "**/.*", "tests/hil/bench-dut"] # a Zephyr app and its build tree
111
+ pythonVersion = "3.11"
112
+ pythonPlatform = "All"
113
+ venvPath = "."
114
+ venv = ".venv"
115
+ reportMissingTypeStubs = "error"
116
+ reportImplicitOverride = "error"
117
+ reportUnnecessaryTypeIgnoreComment = "warning"
118
+ reportUnusedImport = "warning"
119
+ reportUnusedVariable = "warning"
120
+
121
+ [tool.ruff]
122
+ line-length = 100
123
+ target-version = "py311"
124
+ src = ["src", "tests"]
125
+
126
+ [tool.ruff.lint]
127
+ select = [
128
+ "E", # pycodestyle errors
129
+ "F", # pyflakes
130
+ "I", # isort
131
+ "B", # bugbear
132
+ "UP", # pyupgrade
133
+ "RUF", # ruff-specific
134
+ "TCH", # type-checking imports
135
+ "D", # pydocstyle
136
+ "SIM", # simplifications
137
+ "PTH", # pathlib usage
138
+ ]
139
+ ignore = [
140
+ "D100", # module-level docstring not required everywhere
141
+ "D104", # __init__.py docstring not required
142
+ "D105", # dunder methods rarely need one
143
+ "D107", # __init__: the class docstring covers it
144
+ "D203", # incompatible with D211
145
+ "D213", # incompatible with D212
146
+ ]
147
+ # Domain-specific Unicode that's intentional and unambiguous in context:
148
+ # µ (micro) in µA / µJ / µC, -> (state-machine flow), σ (statistics).
149
+ # RUF002/RUF003 still catch genuine ASCII-vs-Unicode confusables.
150
+ allowed-confusables = ["µ", "σ"]
151
+
152
+ [tool.ruff.lint.per-file-ignores]
153
+ "tests/**" = ["D"] # tests don't need pydocstyle
154
+
155
+ [tool.ruff.lint.flake8-implicit-str-concat]
156
+ allow-multiline = true
157
+
158
+
159
+ [tool.ruff.lint.pydocstyle]
160
+ convention = "google"
161
+
162
+ [tool.ruff.lint.isort]
163
+ known-first-party = ["ppk2", "tests"]
164
+
165
+ [tool.ruff.format]
166
+ docstring-code-format = true