nfcscript 0.0.1__py3-none-any.whl
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.
- nfcscript/__init__.py +0 -0
- nfcscript/assertions.py +37 -0
- nfcscript/bits.py +26 -0
- nfcscript/main.py +5 -0
- nfcscript-0.0.1.dist-info/METADATA +12 -0
- nfcscript-0.0.1.dist-info/RECORD +9 -0
- nfcscript-0.0.1.dist-info/WHEEL +5 -0
- nfcscript-0.0.1.dist-info/entry_points.txt +2 -0
- nfcscript-0.0.1.dist-info/top_level.txt +1 -0
nfcscript/__init__.py
ADDED
|
File without changes
|
nfcscript/assertions.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
def _get_stack_trace() -> str:
|
|
5
|
+
"""获取格式化的调用堆栈"""
|
|
6
|
+
# inspect.stack()[0] 是 _get_stack_trace
|
|
7
|
+
# inspect.stack()[1] 是 ASSERT_... 函数
|
|
8
|
+
# inspect.stack()[2:] 是实际的业务调用代码
|
|
9
|
+
stack = inspect.stack()[2:]
|
|
10
|
+
chain = []
|
|
11
|
+
for frame in stack:
|
|
12
|
+
# 简化路径,仅显示文件名
|
|
13
|
+
filename = frame.filename.split('\\')[-1].split('/')[-1]
|
|
14
|
+
chain.append(f" at {filename}:{frame.lineno} in {frame.function}")
|
|
15
|
+
return "\n".join(chain)
|
|
16
|
+
|
|
17
|
+
def ASSERT_LEN(data: Any, expected_len: int) -> None:
|
|
18
|
+
actual_len = len(data)
|
|
19
|
+
if actual_len != expected_len:
|
|
20
|
+
error_msg = (
|
|
21
|
+
f"\nAssertion Failed: Length mismatch\n"
|
|
22
|
+
f" Expected: {expected_len}\n"
|
|
23
|
+
f" Actual : {actual_len}\n"
|
|
24
|
+
f" Data : {data}\n"
|
|
25
|
+
f"Stack Trace:\n{_get_stack_trace()}"
|
|
26
|
+
)
|
|
27
|
+
raise AssertionError(error_msg)
|
|
28
|
+
|
|
29
|
+
def ASSERT_EQUAL(actual: Any, expected: Any) -> None:
|
|
30
|
+
if actual != expected:
|
|
31
|
+
error_msg = (
|
|
32
|
+
f"\nAssertion Failed: Value mismatch\n"
|
|
33
|
+
f" Expected: {expected} ({type(expected).__name__})\n"
|
|
34
|
+
f" Actual : {actual} ({type(actual).__name__})\n"
|
|
35
|
+
f"Stack Trace:\n{_get_stack_trace()}"
|
|
36
|
+
)
|
|
37
|
+
raise AssertionError(error_msg)
|
nfcscript/bits.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
def bits_update(val: int, mask: int, data: int) -> int:
|
|
2
|
+
"""
|
|
3
|
+
更新寄存器中的特定位域 (Read-Modify-Write)
|
|
4
|
+
:param val: 当前寄存器的原始值
|
|
5
|
+
:param mask: 预移位的位掩码 (例如: 0x20)
|
|
6
|
+
:param data: 已移位对齐的新数值 (例如: 0x20, 即 1 << 5)
|
|
7
|
+
:return: 更新后的寄存器值
|
|
8
|
+
"""
|
|
9
|
+
assert (data & ~mask) == 0, f"Data {hex(data)} contains bits outside mask {hex(mask)}"
|
|
10
|
+
return (val & ~mask) | (data & mask)
|
|
11
|
+
|
|
12
|
+
def bits_set(val: int, mask: int) -> int:
|
|
13
|
+
"""
|
|
14
|
+
将寄存器中的指定位强制置 1 (OR 操作)
|
|
15
|
+
|
|
16
|
+
:param mask: 想要置 1 的位掩码
|
|
17
|
+
"""
|
|
18
|
+
return val | mask
|
|
19
|
+
|
|
20
|
+
def bits_reset(val: int, mask: int) -> int:
|
|
21
|
+
"""
|
|
22
|
+
将寄存器中的指定位强制清 0 (AND-NOT 操作)
|
|
23
|
+
|
|
24
|
+
:param mask: 想要清 0 的位掩码
|
|
25
|
+
"""
|
|
26
|
+
return val & ~mask
|
nfcscript/main.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
nfcscript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
nfcscript/assertions.py,sha256=Cag79RUWvUH2KhWdPlK_NQlgdHC5_9wqmgP8etS_zHY,1347
|
|
3
|
+
nfcscript/bits.py,sha256=1z7yFWEiRbqp-qDlROLs0y3L1VaB4AO-58pnITDVuS8,891
|
|
4
|
+
nfcscript/main.py,sha256=ZRme3aUqH0Yn3jgMHI_yW_cYYYlZJEDC2peTzMkhTOY,86
|
|
5
|
+
nfcscript-0.0.1.dist-info/METADATA,sha256=J6cG17YbzMG4W85oRZ1b9BEbptcU0liQ0EqrHE6sdp4,219
|
|
6
|
+
nfcscript-0.0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
nfcscript-0.0.1.dist-info/entry_points.txt,sha256=aHhVEPW92MkR83dZy3f-b8iJtSRFphfjEl4sdJQPqWk,50
|
|
8
|
+
nfcscript-0.0.1.dist-info/top_level.txt,sha256=ZNgFsFkDHI3lcF-IL6_45fL4DUQgYPFUay-hyU5q3jI,10
|
|
9
|
+
nfcscript-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nfcscript
|