diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4949b08..7803ed3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,14 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files + exclude: docs_src/media/adhesive_spec.pdf - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.9.9 + rev: v0.14.5 hooks: - id: ruff-format diff --git a/data/aux_fields.yaml b/data/aux_fields.yaml index 2455e61..19e2677 100644 --- a/data/aux_fields.yaml +++ b/data/aux_fields.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/fields.yaml - key: 0 name: consumed_weight type: number diff --git a/data/config_nfcv.yaml b/data/config_nfcv.yaml index 8524105..3300931 100644 --- a/data/config_nfcv.yaml +++ b/data/config_nfcv.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/config.yaml mime_type: application/vnd.openprinttag root: nfcv meta_fields: meta_fields.yaml diff --git a/data/config_noroot.yaml b/data/config_noroot.yaml index 14e9e07..d8d9469 100644 --- a/data/config_noroot.yaml +++ b/data/config_noroot.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/config.yaml mime_type: application/vnd.openprinttag root: none meta_fields: meta_fields.yaml diff --git a/data/main_fields.yaml b/data/main_fields.yaml index a03b616..54581bd 100644 --- a/data/main_fields.yaml +++ b/data/main_fields.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/fields.yaml - key: 0 name: instance_uuid type: uuid @@ -185,10 +186,8 @@ - key: 19 name: primary_color - type: bytes - max_length: 4 + type: color_rgba required: recommended - unit: "[R, G, B] or [R, G, B, A]" example: "`\\xff\\x00\\x00\\x7f`" description: - Primary color of the material in the RGB(A) format, intended for UI purposes. @@ -197,39 +196,29 @@ - key: 20 name: secondary_color_0 - type: bytes - max_length: 4 - unit: "[R, G, B] or [R, G, B, A]" + type: color_rgba description: - One of secondary colors of the material. - Data format is the same as for `primary_color`. - key: 21 name: secondary_color_1 - type: bytes - max_length: 4 - unit: "[R, G, B] or [R, G, B, A]" + type: color_rgba description: See `secondary_color_0`. - key: 22 name: secondary_color_2 - type: bytes - max_length: 4 - unit: "[R, G, B] or [R, G, B, A]" + type: color_rgba description: See `secondary_color_0`. - key: 23 name: secondary_color_3 - type: bytes - max_length: 4 - unit: "[R, G, B] or [R, G, B, A]" + type: color_rgba description: See `secondary_color_0`. - key: 24 name: secondary_color_4 - type: bytes - max_length: 4 - unit: "[R, G, B] or [R, G, B, A]" + type: color_rgba description: See `secondary_color_0`. - key: 25 @@ -256,6 +245,13 @@ required: recommended description: Properties of the material. Can have multiple tags at once. +- key: 56 + name: certifications + type: enum_array + items_file: material_certifications_enum.yaml + example: "`ul_2818`" + description: Certifications the material has. + - key: 29 name: density type: number diff --git a/data/material_certifications_enum.yaml b/data/material_certifications_enum.yaml new file mode 100644 index 0000000..080081e --- /dev/null +++ b/data/material_certifications_enum.yaml @@ -0,0 +1,12 @@ +- key: 0 + name: ul_2818 + display_name: UL 2818 + description: + - GREENGUARD Certification Program For Chemical Emissions For Building Materials, Finishes And Furnishings. + +- key: 1 + name: ul_94_v0 + display_name: UL 94 V0 + description: + - Standard for Safety of Flammability of Plastic Materials for Parts in Devices and Appliances testing. + - Indicates a flame-retardant material. diff --git a/data/material_class_enum.yaml b/data/material_class_enum.yaml index 84d37d9..376c41d 100644 --- a/data/material_class_enum.yaml +++ b/data/material_class_enum.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/material_class_enum.yaml - key: 0 name: FFF description: Filament diff --git a/data/material_type_enum.yaml b/data/material_type_enum.yaml index 8abaa85..3571e01 100644 --- a/data/material_type_enum.yaml +++ b/data/material_type_enum.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/material_type_enum.yaml - key: 0 abbreviation: PLA name: Polylactic Acid diff --git a/data/meta_fields.yaml b/data/meta_fields.yaml index 7993a25..1637b47 100644 --- a/data/meta_fields.yaml +++ b/data/meta_fields.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/fields.yaml - key: 0 name: main_region_offset type: int diff --git a/data/schema/config.yaml b/data/schema/config.yaml new file mode 100644 index 0000000..70291a2 --- /dev/null +++ b/data/schema/config.yaml @@ -0,0 +1,30 @@ +$schema: "https://json-schema.org/draft-07/schema" +$id: "https://specs.openprinttag.org/schema/config.yaml" + +title: Configuration root definition +description: Schema for OpenPrintTag configuration root definitions. + +type: object +required: [ mime_type, meta_fields, main_fields ] +properties: + mime_type: + type: string + const: "application/vnd.openprinttag" + description: The mime type of the configuration. + + root: + type: string + enum: [nfcv, none] + description: The root container of the OpenPrintTag. + + meta_fields: + type: string + description: Path to the definitions of the Meta Section fields. + + main_fields: + type: string + description: Path to the definitions of the Main Region fields. + + aux_fields: + type: string + description: Path to the definitions of the Auxiliary Section fields. diff --git a/data/schema/fields.yaml b/data/schema/fields.yaml new file mode 100644 index 0000000..f022dc3 --- /dev/null +++ b/data/schema/fields.yaml @@ -0,0 +1,116 @@ +$schema: "https://json-schema.org/draft-07/schema" +$id: "https://specs.openprinttag.org/schema/fields.yaml" + +title: Fields definition +description: Schema for OpenPrintTag section field definitions. + +type: array +items: + oneOf: + - $ref: "#/definitions/deprecatedField" + - $ref: "#/definitions/basicField" + - $ref: "#/definitions/arrayField" + - $ref: "#/definitions/enumField" + +definitions: + deprecatedField: + type: object + additionalProperties: false + description: Deprecated field. + + required: [ key, deprecated ] + + properties: + key: + type: integer + minimum: 0 + description: Index of the field in CBOR. + deprecated: + type: boolean + const: true + description: Indicates that the field is deprecated. + + baseField: + type: object + additionalProperties: false + + required: [ key, type, name ] + + not: + required: [ deprecated ] + + properties: + key: + type: integer + minimum: 0 + description: Identifier of the field in CBOR. + name: + type: string + pattern: "^[a-z0-9_]*$" + description: Name of the field. + unit: + type: string + description: Unit of measurement for the field. + example: + type: [ integer, number, string ] + description: Example value for the field. + required: + oneOf: + - type: boolean + - type: string + enum: [recommended] + description: Whether the field is required. + description: + oneOf: + - type: string + - type: array + items: { type: string } + description: Description of the field. + category: + type: string + description: Category of the field. + + basicField: + allOf: + - $ref: "#/definitions/baseField" + - description: A basic value. + + required: [ type ] + + properties: + type: + type: string + enum: [ int, number, boolean, uuid, timestamp, color ] + description: Type of the field. + + arrayField: + allOf: + - $ref: "#/definitions/baseField" + - description: An array of basic values. + + required: [ type, max_length ] + + properties: + type: + type: string + enum: [ bytes, string ] + description: Type of the field. + max_length: + type: integer + minimum: 1 + description: Maximum number of elements in the array. + + enumField: + allOf: + - $ref: "#/definitions/baseField" + description: An enumerated value. + + required: [ items_file ] + + properties: + type: + type: string + enum: [ enum, enum_array ] + items_file: + type: string + description: Path to the definition containing the list of enum values. diff --git a/data/schema/material_class_enum.yaml b/data/schema/material_class_enum.yaml new file mode 100644 index 0000000..a3f0421 --- /dev/null +++ b/data/schema/material_class_enum.yaml @@ -0,0 +1,32 @@ +$schema: "https://json-schema.org/draft-07/schema" +$id: "https://specs.openprinttag.org/schema/material_class_enum.yaml" + +title: Material class variant definition +description: Schema for OpenPrintTag material class variant definitions. + +type: array +items: + type: object + description: Material class variant. + additionalProperties: false + + required: [ key, name ] + + properties: + key: + type: integer + minimum: 0 + description: Identifier of the material class in CBOR. + name: + type: string + pattern: "^[A-Z0-9_+-]*$" + description: Material class name. + description: + oneOf: + - type: string + - type: array + items: { type: string } + description: Description of the material class. + deprecated: + type: boolean + description: Whether the material class is deprecated. diff --git a/data/schema/material_type_enum.yaml b/data/schema/material_type_enum.yaml new file mode 100644 index 0000000..812c8b0 --- /dev/null +++ b/data/schema/material_type_enum.yaml @@ -0,0 +1,41 @@ +$schema: "https://json-schema.org/draft-07/schema" +$id: "https://specs.openprinttag.org/schema/material_type_enum.yaml" + +title: Material type variant definition +description: Schema for OpenPrintTag material type variant definitions. + +type: array +items: + type: object + description: Material type variant. + additionalProperties: false + + required: [ key, abbreviation, name, category ] + + properties: + key: + type: integer + minimum: 0 + description: Identifier of the material type in CBOR. + abbreviation: + type: string + pattern: "^[A-Z0-9_+-]*$" + description: Material type abbreviation. + name: + type: string + description: Human-readable material type name. + category: + type: string + pattern: "^[A-Z0-9_+-]*$" + description: + Material type category name. + See the `material_class` enum for valid categories. + description: + oneOf: + - type: string + - type: array + items: { type: string } + description: Description of the material class. + deprecated: + type: boolean + description: Whether the material class is deprecated. diff --git a/data/schema/tag_categories_enum.yaml b/data/schema/tag_categories_enum.yaml new file mode 100644 index 0000000..4a10926 --- /dev/null +++ b/data/schema/tag_categories_enum.yaml @@ -0,0 +1,29 @@ +$schema: "https://json-schema.org/draft-07/schema" +$id: "https://specs.openprinttag.org/schema/tag_category_enum.yaml" + +title: Tag category variant definition +description: Schema for OpenPrintTag tag category variant definitions. + +type: array +items: + type: object + description: Tag category variant. + additionalProperties: false + + required: [ name, display_name ] + + properties: + name: + type: string + pattern: "^[a-z0-9_+-]*$" + description: Tag category name. + display_name: + type: string + description: The human-readable name of the tag category. + emoji: + type: string + pattern: "^[\\p{So}\\p{Sk}\\p{Sm}\\p{Sc}]\\uFE0F?$" + description: Emoji pictogram for this tag category variant. + deprecated: + type: boolean + description: Whether the tag category is deprecated. diff --git a/data/schema/tags_enum.yaml b/data/schema/tags_enum.yaml new file mode 100644 index 0000000..6e16b7d --- /dev/null +++ b/data/schema/tags_enum.yaml @@ -0,0 +1,53 @@ +$schema: "https://json-schema.org/draft-07/schema" +$id: "https://specs.openprinttag.org/schema/tags_enum.yaml" + +title: Tag variant definition +description: Schema for OpenPrintTag tag variant definitions. + +type: array +items: + type: object + description: Material tag variant. + additionalProperties: false + + required: [ key, name, category, display_name, category ] + + properties: + key: + type: integer + minimum: 0 + description: Identifier of the tag in CBOR. + name: + type: string + pattern: "^[a-z0-9_]*$" + description: Name of the tag. + display_name: + type: string + description: The human-readable name of the tag. + description: + oneOf: + - type: string + - type: array + items: { type: string } + description: Description of the tag. + deprecated: + type: boolean + description: Whether the tag is deprecated. + category: + type: string + pattern: "^[a-z0-9_]*$" + description: + Tag category name. + See the `tag_category` enum for valid categories. + implies: + type: array + items: + type: string + pattern: "^[a-z0-9_]*$" + description: List of tags, by name, that are implied by the tag. + hints: + type: array + items: + type: string + pattern: "^[a-z0-9_]*$" + description: List of tags, by name, that are hinted to with the tag. diff --git a/data/schema/write_protection_enum.yaml b/data/schema/write_protection_enum.yaml new file mode 100644 index 0000000..905967d --- /dev/null +++ b/data/schema/write_protection_enum.yaml @@ -0,0 +1,33 @@ +$schema: "https://json-schema.org/draft-07/schema" +$id: "https://specs.openprinttag.org/schema/write_protection_enum.yaml" + +title: Write-protection variant definition +description: Schema for OpenPrintTag write-protection variant definitions. + +type: array + +items: + type: object + description: Write-protection variant. + additionalProperties: false + + required: [ key, name ] + + properties: + key: + type: integer + minimum: 0 + description: Identifier of the write-protection variant in CBOR. + name: + type: string + pattern: "^[a-z0-9_+-]*$" + description: Write-protection status name. + description: + oneOf: + - type: string + - type: array + items: { type: string } + description: Description of the write-protection status. + deprecated: + type: boolean + description: Whether the write-protection status is deprecated. diff --git a/data/tag_categories_enum.yaml b/data/tag_categories_enum.yaml index fa32165..3c3526c 100644 --- a/data/tag_categories_enum.yaml +++ b/data/tag_categories_enum.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/tag_categories_enum.yaml - name: biological display_name: Biological emoji: 🧬 diff --git a/data/tags_enum.yaml b/data/tags_enum.yaml index 56827db..bb6403d 100644 --- a/data/tags_enum.yaml +++ b/data/tags_enum.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/tags_enum.yaml ## Biological properties # ===================================== diff --git a/data/write_protection_enum.yaml b/data/write_protection_enum.yaml index a7c1f6b..c4fc572 100644 --- a/data/write_protection_enum.yaml +++ b/data/write_protection_enum.yaml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=./schema/write_protection_enum.yaml - key: 0 name: "no" description: The tag is not write protected. diff --git a/docs_src/_sidebar.md b/docs_src/_sidebar.md index 41b0719..379248e 100644 --- a/docs_src/_sidebar.md +++ b/docs_src/_sidebar.md @@ -3,6 +3,8 @@ - [Data format](/nfc_data_format) - [Material types](/material_types) - [Material tags](/material_tags) +- [Material certifications](/material_certifications) - [Technical details](/nfc_technical_details) +- [Physical specification](/physical_spec) - [Examples](/examples) - [Contributing](/contributing) diff --git a/docs_src/generate.py b/docs_src/generate.py index a6b8923..c1bf3f3 100644 --- a/docs_src/generate.py +++ b/docs_src/generate.py @@ -11,8 +11,8 @@ def gen_material_tag_table(): r.write("") r.write("") - tags = yaml.safe_load(open(os.path.join(vars.data_dir, "tags_enum.yaml"), "r")) - categories = yaml.safe_load(open(os.path.join(vars.data_dir, "tag_categories_enum.yaml"), "r")) + tags = yaml.safe_load(open(os.path.join(vars.data_dir, "tags_enum.yaml"), "r", encoding="utf-8")) + categories = yaml.safe_load(open(os.path.join(vars.data_dir, "tag_categories_enum.yaml"), "r", encoding="utf-8")) categories_keys = {c["name"] for c in categories} @@ -73,6 +73,13 @@ def gen_material_tag_table(): Column(field="description", title="Description"), ] +env.globals["material_certification_columns"] = [ + Column(field="key", title="Key"), + Column(field="name", title="Name", transform=lambda x: f"`{x}`"), + Column(field="display_name", title="Display name"), + Column(field="description", title="Description"), +] + gen_doc_file("_navbar") gen_doc_file("_sidebar") gen_doc_file("README") @@ -82,7 +89,12 @@ def gen_material_tag_table(): gen_doc_file("nfc_technical_details") gen_doc_file("examples") gen_doc_file("contributing") -gen_doc_file("material_tags") gen_doc_file("material_types") +gen_doc_file("material_tags") +gen_doc_file("material_certifications") +gen_doc_file("physical_spec") + +shutil.copytree(f"{dir}/media", f"{out_dir}/media", dirs_exist_ok=True) -shutil.copyfile(f"{dir}/class_diagram.svg", f"{out_dir}/class_diagram.svg") +# copy definition schemas +shutil.copytree(os.path.join(vars.data_dir, "schema"), f"{out_dir}/schema") diff --git a/docs_src/generate_common.py b/docs_src/generate_common.py index 27558f3..6025b85 100644 --- a/docs_src/generate_common.py +++ b/docs_src/generate_common.py @@ -109,7 +109,7 @@ def show_file(file, language="yaml"): r.write(f"> ```bash\n> cat {file}\n> ```\n\n") r.write("
Commmand output\n\n") - with open(f"{dir}/{file}", "r") as f: + with open(f"{dir}/{file}", "r", encoding="utf-8") as f: r.write(f"```{language}\n{f.read()}\n```\n") r.write("
\n\n") diff --git a/docs_src/material_certifications.md b/docs_src/material_certifications.md new file mode 100644 index 0000000..ba86744 --- /dev/null +++ b/docs_src/material_certifications.md @@ -0,0 +1,6 @@ +# Material certifications +Material certifications allow expressing what certificates a material has. + +The certifications are stored as an enum on the tag to reduce memory usage and promote standard encoding. If there is a certification missing in the enum, please create a PR or file an issue in the [OpenPrintTag repository]({{repo}}). + +{{ enum_table("material_certifications_enum", material_certification_columns) }} diff --git a/docs_src/media/adhesive_spec.pdf b/docs_src/media/adhesive_spec.pdf new file mode 100644 index 0000000..0f837f7 Binary files /dev/null and b/docs_src/media/adhesive_spec.pdf differ diff --git a/docs_src/class_diagram.mermaid b/docs_src/media/class_diagram.mermaid similarity index 100% rename from docs_src/class_diagram.mermaid rename to docs_src/media/class_diagram.mermaid diff --git a/docs_src/class_diagram.svg b/docs_src/media/class_diagram.svg similarity index 100% rename from docs_src/class_diagram.svg rename to docs_src/media/class_diagram.svg diff --git a/docs_src/media/tag_mk1.pdf b/docs_src/media/tag_mk1.pdf new file mode 100644 index 0000000..68ab4b7 Binary files /dev/null and b/docs_src/media/tag_mk1.pdf differ diff --git a/docs_src/media/tag_placement.svg b/docs_src/media/tag_placement.svg new file mode 100644 index 0000000..47cc0b0 --- /dev/null +++ b/docs_src/media/tag_placement.svg @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs_src/nfc_data_format.md b/docs_src/nfc_data_format.md index ff4fad5..e6b0d33 100644 --- a/docs_src/nfc_data_format.md +++ b/docs_src/nfc_data_format.md @@ -84,6 +84,7 @@ 1. `enum_array` fields are encoded as CBOR arrays of integers, according to the field mapping 1. `timestamp` fields are encoded as UNIX timestamp integers 1. `bytes` and `uuid` types are encoded as CBOR byte string (type 2) +1. `color_rgba` fields are encoded as a CBOR byte string (type 2) with 3 to 4 bytes representing `[R, G, B]` or `[R, G, B, A]` values 1. `number` types can be encoded as either unsigned integers (type 0), signed integers (type 1), half floats or floats 1. `string` types are encoded as CBOR text string (type 3, UTF-8 is enforced by the CBOR specification) 1. The `X` in the `string:X` or `bytes:X` notation defines maximum permissible length of the data in bytes. diff --git a/docs_src/physical_spec.md b/docs_src/physical_spec.md new file mode 100644 index 0000000..403cc43 --- /dev/null +++ b/docs_src/physical_spec.md @@ -0,0 +1,221 @@ +# Physical specification +This document describes the requirements imposed by the OpenPrintTag standard on the physical tag itself, its mechanical and electrical properties. Currently, the **OpenPrintTag standard supports only the reference `OpenPrintTag MK1` tag**. A more generic specification, allowing deviations from the exact reference design and including NFC reader parameters, **will be released later**. + +## Reference `OpenPrintTag MK1` tag +`OpenPrintTag MK1` is a passive paper-label NFC tag with an embedded coil and NFC integrated circuit, compliant with the ISO/IEC 15693 vicinity-RFID standard (13.56 MHz). + +Technical drawing + +## Placement guidelines on filament spools +1. The tag SHALL be attached to a flat, non-metallic surface. +1. The tag SHOULD be placed at either flange of the spool (e.g. not in the middle of the barrel) to ensure compatibility with generic readers. +1. The tag SHALL be placed no further than 130 mm from either side of the spool. + 1. *Note: This limitation ensures the tag remains readable from both sides of the spool.* +1. The tag SHALL be positioned coaxially with the central axis of the spool. +1. The design of the material container SHALL provide sufficient mechanical protection of the tag's integrated circuit (IC) during the entire lifecycle. +1. To achieve this, the tag SHOULD be placed inside a debossed pocket or cavity with a minimum depth of 0.25 mm. The cavity MAY be covered to fully enclose the tag. + + + + + +## Mechanical parameters + +
IDNameDisplay nameInfo
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterMinTypicalMaxUnit
ShapeCircular
Outer diameter (Ø)89.59090.5mm
Inner diameter (Ø)63.56464.5mm
Coil outer diameter (Ø)78.679.179.6mm
Coil loop inner diameter (Ø)73.57474.5mm
Top materialPaper 80 g/m²
Top thickness90100110μm
Winding materialAluminum foil
Winding thickness253035μm
Bottom materialPET
Bottom thickness455055μm
Adhesive materialHot Melt Adhesive
Adhesive thickness152025μm
Total thickness0.140.150.16mm
+ +### Electrical parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterMinTypicalMaxUnit
Communication protocolISO/IEC 15693 (NFC-V)
Integrated CircuitNXP ICODE SLX2
Communication speed53kb/s
Memory size316Byte
Write endurance100,000cycles
Retention time10years
Operating temperature+15+23+45°C
Storage temperature−55+23+80°C
Operating frequency13.55313.5613.567MHz
Coil typePrinted coil
Number of coil turns5
Coil inductance at 13.56 MHzTBD6.91TBDμH
Coil DC resistanceTBD4.565TBDOhm
Minimum operating voltage on unloaded coil11.11.3V_rms
Minimum magnetic field strength12.37614.8mA/m_rms
diff --git a/docs_src/tables.py b/docs_src/tables.py index 109b722..7e70b19 100644 --- a/docs_src/tables.py +++ b/docs_src/tables.py @@ -59,7 +59,7 @@ class Column(typing.NamedTuple): def generate_table(yaml_file: str, columns: typing.List[Column], filter: any = None): - src = open(yaml_file, "r") + src = open(yaml_file, "r", encoding="utf-8") data = yaml.safe_load(src) tgt = io.StringIO("") diff --git a/docs_src/terminology.md b/docs_src/terminology.md index 5e51c0c..993f30b 100644 --- a/docs_src/terminology.md +++ b/docs_src/terminology.md @@ -1,7 +1,7 @@ # Terminology The OpenPrintTag format is based on the following entity model (not all fields are present): - + 1. `Material` represents a material with some color and properties. 1. For example "Prusament PLA Prusa Galaxy Black". diff --git a/pyproject.toml b/pyproject.toml index ccd08b9..a0f60ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,2 @@ [tool.ruff] -line-length = 512 +line-length = 320 diff --git a/tests/encode_decode/01_data.bin b/tests/encode_decode/01_data.bin index 8fd8a51..de48f23 100644 Binary files a/tests/encode_decode/01_data.bin and b/tests/encode_decode/01_data.bin differ diff --git a/tests/encode_decode/01_info.yaml b/tests/encode_decode/01_info.yaml index 37c87fe..1bdbcae 100644 --- a/tests/encode_decode/01_info.yaml +++ b/tests/encode_decode/01_info.yaml @@ -8,7 +8,7 @@ regions: payload_offset: 4 absolute_offset: 70 size: 206 - used_size: 142 + used_size: 148 aux: payload_offset: 210 absolute_offset: 276 @@ -18,8 +18,8 @@ root: data_size: 312 payload_size: 245 overhead: 67 - payload_used_size: 147 - total_used_size: 214 + payload_used_size: 153 + total_used_size: 220 data: meta: aux_region_offset: 210 @@ -51,10 +51,13 @@ data: container_outer_diameter: 200 container_inner_diameter: 100 container_hole_diameter: 52 + certifications: + - ul_2818 + - ul_94_v0 aux: {} raw_data: meta: a10218d2 - main: bf041b000007d0fcab45f9056a33333463353466303838080009000a76504c412050727573612047616c61787920426c61636b0b6950727573616d656e740e1a68d3c7d7101903e8111903f41219011813433d3e3d181c9f17ff181df93cf6182218cd182318e1182418aa182518281826183c18271218281828182914182a1840182b18c8182c1864182d1834ff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + main: bf041b000007d0fcab45f9056a33333463353466303838080009000a76504c412050727573612047616c61787920426c61636b0b6950727573616d656e740e1a68d3c7d7101903e8111903f41219011813433d3e3d181c9f17ff181df93cf6182218cd182318e1182418aa182518281826183c18271218281828182914182a1840182b18c8182c1864182d183418389f0001ffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 aux: a000000000000000000000000000000000000000000000000000000000000000000000 uri: https://3dtag.org/s/334c54f088 opt_check: diff --git a/tests/encode_decode/01_input.yaml b/tests/encode_decode/01_input.yaml index 75dda1d..049ecc4 100644 --- a/tests/encode_decode/01_input.yaml +++ b/tests/encode_decode/01_input.yaml @@ -11,6 +11,7 @@ data: primary_color: hex: 3D3E3D tags: [glitter] + certifications: [ul_2818, ul_94_v0] density: 1.24 # Package-spcific fields diff --git a/tests/run_tests.py b/tests/run_tests.py index 069b6b3..81305f0 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -106,7 +106,7 @@ def check_util_output(name, data, compare_fn): init_args = ["--size=312", "--aux-region=32"] info_args = ["--validate", "--show-all", "--show-raw-data", "--opt-check"] - with open(file, "r") as f: + with open(file, "r", encoding="utf-8") as f: yml = yaml.safe_load(f).get("test_config", {}) if uri := yml.get("uri"): diff --git a/utils/fields.py b/utils/fields.py index 494f27f..3989156 100644 --- a/utils/fields.py +++ b/utils/fields.py @@ -105,7 +105,7 @@ def __init__(self, config, config_dir): self.items_by_key = dict() self.items_by_name = dict() - self.items_yaml = yaml.safe_load(open(os.path.join(config_dir, config["items_file"]), "r")) + self.items_yaml = yaml.safe_load(open(os.path.join(config_dir, config["items_file"]), "r", encoding="utf-8")) for item in self.items_yaml: if item.get("deprecated", False): continue @@ -189,6 +189,15 @@ def encode(self, data): return result +class ColorRGBAField(BytesField): + def __init__(self, config, config_dir): + if "max_length" not in config: + # default to RGBA, but + # leave the door open for RGB or other formats in the future + config["max_length"] = 4 + super().__init__(config, config_dir) + + class UUIDField(Field): def decode(self, data): return str(uuid.UUID(bytes=data)) @@ -206,6 +215,7 @@ def encode(self, data): "enum_array": EnumArrayField, "timestamp": IntField, "bytes": BytesField, + "color_rgba": ColorRGBAField, "uuid": UUIDField, } @@ -239,7 +249,7 @@ def init_from_yaml(self, yaml, config_dir): def from_file(file: str): r = Fields() - r.init_from_yaml(yaml.safe_load(open(file, "r")), os.path.dirname(file)) + r.init_from_yaml(yaml.safe_load(open(file, "r", encoding="utf-8")), os.path.dirname(file)) return r diff --git a/utils/nfc_initialize.py b/utils/nfc_initialize.py index 7c46215..732f03a 100644 --- a/utils/nfc_initialize.py +++ b/utils/nfc_initialize.py @@ -41,7 +41,7 @@ class Args: def nfc_initialize(args: Args): config_dir = os.path.dirname(args.config_file) - with open(args.config_file, "r") as f: + with open(args.config_file, "r", encoding="utf-8") as f: config = types.SimpleNamespace(**yaml.safe_load(f)) assert config.root == "nfcv", "nfc_initialize only supports NFC-V tags" diff --git a/utils/rec_info.py b/utils/rec_info.py index bea0b6d..d2aa5ef 100644 --- a/utils/rec_info.py +++ b/utils/rec_info.py @@ -100,7 +100,7 @@ region.fields.validate(region.read()) if args.extra_required_fields: - with open(args.extra_required_fields, "r") as f: + with open(args.extra_required_fields, "r", encoding="utf-8") as f: req_fields = yaml.safe_load(f) for region_name, region_req_fields in req_fields.items(): diff --git a/utils/rec_update.py b/utils/rec_update.py index b42936e..c2dbffb 100644 --- a/utils/rec_update.py +++ b/utils/rec_update.py @@ -18,7 +18,7 @@ record.encode_config.canonical = args.canonical record.encode_config.indefinite_containers = args.indefinite_containers -update_data = yaml.safe_load(open(args.update_data, "r")) +update_data = yaml.safe_load(open(args.update_data, "r", encoding="utf-8")) for region_name, region in record.regions.items(): region.update( update_fields=update_data.get("data", dict()).get(region_name, dict()), diff --git a/utils/record.py b/utils/record.py index c24ee59..f1b18f5 100644 --- a/utils/record.py +++ b/utils/record.py @@ -102,7 +102,7 @@ def __init__(self, config_file: str, data: memoryview): self.encode_config = EncodeConfig() self.config_dir = os.path.dirname(config_file) - with open(config_file, "r") as f: + with open(config_file, "r", encoding="utf-8") as f: self.config = types.SimpleNamespace(**yaml.safe_load(f)) # Decode the root and find payload