From 1f3beb5786094efd5bd903185f8038bd2d728c71 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Tue, 1 Dec 2026 14:23:24 +0100 Subject: [PATCH] fix(tia): a type identifier gives only a concrete article and its version Siemens' Openness notes: catalog identifiers carry wildcards (6SL3040-1MA01-0Axx), drive identifiers a family after the version (/V5.2.3/S120), some a catalog variant instead (//10002). Only a concrete article and a V-version are taken; the rest is not matched. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- compliance-core/src/models/tia_export.rs | 44 ++++++++++++++++++++---- docs/guide/plc.md | 2 +- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/compliance-core/src/models/tia_export.rs b/compliance-core/src/models/tia_export.rs index e32192d..ec07862 100644 --- a/compliance-core/src/models/tia_export.rs +++ b/compliance-core/src/models/tia_export.rs @@ -361,16 +361,25 @@ impl TiaManifest { } /// Order number and firmware of a TIA type identifier -/// (`OrderNumber:6ES7 515-2UM01-0AB0/V2.9`); a GSD or system identifier -/// (`GSD:…`, `System:…`) has neither. +/// (`OrderNumber:6ES7 515-2UM01-0AB0/V2.9`). The firmware is the segment after +/// the order number when it is a version (`/V5.2.3/S120` has `V5.2.3`, a +/// catalog variant `//10002` none). A catalog order number with wildcards +/// (`6SL3040-1MA01-0Axx`) names no single article, so it is none. A GSD or +/// system identifier (`GSD:…`, `System:…`) has neither. fn split_type_identifier(identifier: &str) -> (Option<&str>, Option<&str>) { let Some(rest) = identifier.trim().strip_prefix("OrderNumber:") else { return (None, None); }; - match rest.split_once('/') { - Some((order, firmware)) => (Some(order), Some(firmware)), - None => (Some(rest), None), - } + let mut segments = rest.split('/'); + let order = segments + .next() + .map(str::trim) + .filter(|o| !o.is_empty() && !o.contains(['x', 'X'])); + let firmware = segments + .next() + .map(str::trim) + .filter(|f| f.starts_with(['V', 'v'])); + (order, firmware) } #[cfg(test)] @@ -434,6 +443,29 @@ mod tests { assert_eq!(devices.unmatched, ["Drittgeraet", "Antrieb"]); } + #[test] + fn a_type_identifier_yields_only_a_concrete_article_and_its_version() { + assert_eq!( + split_type_identifier("OrderNumber:6ES7 515-2UM01-0AB0/V2.9"), + (Some("6ES7 515-2UM01-0AB0"), Some("V2.9")) + ); + // A family qualifier after the version. + assert_eq!( + split_type_identifier("OrderNumber:6SL3040-1MA01-0AA0/V5.2.3/S120"), + (Some("6SL3040-1MA01-0AA0"), Some("V5.2.3")) + ); + // A catalog variant is no firmware; a wildcard is no article. + assert_eq!( + split_type_identifier("OrderNumber:6ES7 193-6BP00-0BA0//10002"), + (Some("6ES7 193-6BP00-0BA0"), None) + ); + assert_eq!( + split_type_identifier("OrderNumber:6SL3040-1MA01-0Axx/V5.2"), + (None, Some("V5.2")) + ); + assert_eq!(split_type_identifier("System:Rack.S120"), (None, None)); + } + #[test] fn protected_blocks_are_named_with_their_device() { let m = TiaManifest::parse(MANIFEST.as_bytes()).unwrap(); diff --git a/docs/guide/plc.md b/docs/guide/plc.md index 7dbaa4b..8152e8e 100644 --- a/docs/guide/plc.md +++ b/docs/guide/plc.md @@ -320,7 +320,7 @@ passwords or keys. | `bundle_version` | `1` | | `tia_version` | the TIA Portal version read with: `V20`, `V21` | | `devices[].role` | `cpu`, `hmi`, `module`, anything else counts as other | -| `devices[].type_identifier` | TIA's type identifier; order number and firmware are taken from it unless given as `order_number` and `firmware` | +| `devices[].type_identifier` | TIA's type identifier; order number and firmware are taken from it unless given as `order_number` and `firmware`. A catalog order number with wildcards (`…-0Axx`) or a variant without a version (`//10002`) leaves the device not matched | | `devices[].security` | a CPU's settings as configured in the project; each is `{"value": …}` when read, `{"unreadable": ""}` when Openness could not read it, absent when not looked at | | `security.access_level` | `full_access_including_failsafe`, `full_access`, `read_access`, `hmi_access`, `no_access`, `none` | | `blocks[].kind` | `ob`, `fb`, `fc`, `db`, `udt` |