Skip to content

Commit 242e155

Browse files
committed
Add data for CC/TLV debugging
1 parent 9fa7e5e commit 242e155

8 files changed

Lines changed: 42 additions & 14 deletions

File tree

tests/encode_decode/01_info.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ regions:
1515
size: 35
1616
used_size: 1
1717
root:
18+
cc_capacity: 312
19+
ndef_tlv_payload_start: 8
20+
ndef_tlv_payload_size: 303
1821
data_size: 312
1922
payload_size: 245
2023
overhead: 67

tests/encode_decode/02_info.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ regions:
1515
size: 35
1616
used_size: 1
1717
root:
18+
cc_capacity: 312
19+
ndef_tlv_payload_start: 8
20+
ndef_tlv_payload_size: 303
1821
data_size: 312
1922
payload_size: 245
2023
overhead: 67

tests/encode_decode/04_info.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ regions:
1515
size: 35
1616
used_size: 1
1717
root:
18+
cc_capacity: 312
19+
ndef_tlv_payload_start: 8
20+
ndef_tlv_payload_size: 303
1821
data_size: 312
1922
payload_size: 255
2023
overhead: 57

tests/encode_decode/05_info.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ regions:
1515
size: 35
1616
used_size: 1
1717
root:
18+
cc_capacity: 312
19+
ndef_tlv_payload_start: 8
20+
ndef_tlv_payload_size: 303
1821
data_size: 312
1922
payload_size: 269
2023
overhead: 43

tests/specific/unknown_info_1.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ regions:
1515
size: 35
1616
used_size: 1
1717
root:
18+
cc_capacity: 312
19+
ndef_tlv_payload_start: 8
20+
ndef_tlv_payload_size: 303
1821
data_size: 312
1922
payload_size: 269
2023
overhead: 43

tests/specific/unknown_info_2.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ regions:
1515
size: 35
1616
used_size: 1
1717
root:
18+
cc_capacity: 312
19+
ndef_tlv_payload_start: 8
20+
ndef_tlv_payload_size: 303
1821
data_size: 312
1922
payload_size: 269
2023
overhead: 43

utils/rec_info.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import argparse
2+
import json
23
import sys
3-
import yaml
4-
5-
from record import Record
6-
from common import default_config_file
7-
from opt_check import opt_check
8-
from pathlib import Path
9-
import referencing
104
import urllib.parse
5+
from pathlib import Path
6+
117
import jsonschema
128
import jsonschema.validators
13-
import json
9+
import referencing
10+
import yaml
11+
from common import default_config_file
12+
from opt_check import opt_check
13+
from record import Record
1414

1515
parser = argparse.ArgumentParser(prog="rec_info", description="Reads a record from the STDIN and prints various information about it in the YAML format")
1616
parser.add_argument("-c", "--config-file", type=str, default=default_config_file, help="Record configuration YAML file")
@@ -64,6 +64,7 @@
6464
if args.show_root_info:
6565
overhead = len(record.data) - len(record.payload)
6666
output["root"] = {
67+
**record.root_info,
6768
"data_size": len(record.data),
6869
"payload_size": len(record.payload),
6970
"overhead": overhead,

utils/record.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import os
2-
import ndef
3-
import yaml
4-
import cbor2
51
import io
2+
import os
63
import types
74
import typing
85

9-
from fields import Fields, EncodeConfig
6+
import cbor2
7+
import ndef
8+
import yaml
9+
from fields import EncodeConfig, Fields
1010

1111

1212
class Region:
@@ -99,13 +99,17 @@ class Record:
9999

100100
regions: dict[str, Region] = None
101101

102+
# Debug information about the record - to be shown in the CLI if the user demands it
103+
root_info: dict[str, typing.Any]
104+
102105
encode_config: EncodeConfig
103106

104107
def __init__(self, config_file: str, data: memoryview):
105108
assert type(data) is memoryview
106109

107110
self.data = data
108111
self.encode_config = EncodeConfig()
112+
self.root_info = dict()
109113

110114
self.config_dir = os.path.dirname(config_file)
111115
with open(config_file, "r", encoding="utf-8") as f:
@@ -124,6 +128,8 @@ def __init__(self, config_file: str, data: memoryview):
124128
# TODO: Support 8-byte CC (with a different magic)
125129
assert cc[0] == 0xE1, "Capability container magic number does not match"
126130

131+
self.root_info["cc_capacity"] = cc[2] * 8
132+
127133
# Find the NDEF TLV
128134
while True:
129135
base_tlv = data_io.read(2)
@@ -143,7 +149,10 @@ def __init__(self, config_file: str, data: memoryview):
143149

144150
# 0x03 = NDEF TLV
145151
if tag == 0x03:
146-
# Found it -
152+
# Found it
153+
154+
self.root_info["ndef_tlv_payload_start"] = data_io.tell()
155+
self.root_info["ndef_tlv_payload_size"] = tlv_len
147156
break
148157
else:
149158
# Skip the TLV block

0 commit comments

Comments
 (0)