diff --git a/src/AasxPluginAID/AIDTDExport.cs b/src/AasxPluginAID/AIDTDExport.cs index e8f35f60..045f6ff1 100644 --- a/src/AasxPluginAID/AIDTDExport.cs +++ b/src/AasxPluginAID/AIDTDExport.cs @@ -11,6 +11,41 @@ namespace AasxPluginAID class AIDTDExport { public static AasxPredefinedConcepts.IDTAAid idtaDef = AasxPredefinedConcepts.IDTAAid.Static; + public static JToken ReplaceformProperties(JToken form) + { + JObject temp = new JObject(); + foreach (var elem in JObject.FromObject(form)) + { + string name = (elem.Key).Replace("_", ":"); + if (name == "htv:headers") + { + int i = 0; + List headers = new List(); + foreach (var _header in JObject.FromObject(elem.Value)) + { + JObject htvHeader = JObject.FromObject(_header.Value); + JObject headerElem = new JObject(); + if (htvHeader.ContainsKey("htv_fieldName")) + { + headerElem["htv:fieldName"] = htvHeader["htv_fieldName"].ToString(); + } + if (htvHeader.ContainsKey("htv_fieldName")) + { + headerElem["htv:fieldValue"] = htvHeader["htv_fieldValue"].ToString(); + } + headers.Add(headerElem); + i = i + 1; + } + temp["htv:headers"] = JToken.FromObject(headers); + } + else + { + string value = elem.Value.ToString(); + temp[name] = value; + } + } + return JToken.FromObject(temp); + } public static JToken TDelemDefinition(ISubmodelElement se, JObject tdSchemaObject, string addParams = null) { string semanticReference = se.SemanticId.GetAsExactlyOneKey().Value; @@ -86,7 +121,7 @@ public static JObject serialize_aid_elem(JToken tdJToken, Aas.ISubmodelElement s foreach (var form in formsSC.Value) { JToken formSchemadefinition = TDelemDefinition(form, tdSchemaObject); - forms.Add(serialize_aid_elem(formSchemadefinition, form)[form.IdShort]); + forms.Add(ReplaceformProperties(serialize_aid_elem(formSchemadefinition, form)[form.IdShort])); } TDJson["forms"] = JToken.FromObject(forms); } diff --git a/src/AasxPluginAID/AIDTDImport.cs b/src/AasxPluginAID/AIDTDImport.cs index b24b2b29..f5cba93d 100644 --- a/src/AasxPluginAID/AIDTDImport.cs +++ b/src/AasxPluginAID/AIDTDImport.cs @@ -28,6 +28,42 @@ class AIDTDImport public static string fileName = ""; public static AasxPredefinedConcepts.IDTAAid idtaDef = AasxPredefinedConcepts.IDTAAid.Static; + public static JObject ReplaceformProperties(JObject form) + { + JObject temp = JObject.FromObject(form); + foreach(var elem in form) + { + string name = (elem.Key).Replace(":","_"); + if (name == "htv_headers") + { + int i = 0; + List headers = new List(); + foreach (var _header in elem.Value) + { + JObject htvHeader = JObject.FromObject(_header); + JObject headerElem = new JObject(); + if (htvHeader.ContainsKey("htv:fieldName")) + { + headerElem["htv_fieldName"] = htvHeader["htv:fieldName"].ToString(); + } + if (htvHeader.ContainsKey("htv:fieldName")) + { + headerElem["htv_fieldValue"] = htvHeader["htv:fieldValue"].ToString(); + } + headers.Add(headerElem); + i = i + 1; + } + temp.Remove("htv:headers"); + temp["htv_headers"] = JToken.FromObject(headers); + } + else + { + string value = elem.Value.ToString(); + temp[name] = value; + } + } + return temp; + } public static Property BuildAasProperty(string idShort, Reference semanticReference, LangStringTextType description, string value, DataTypeDefXsd valueType) { @@ -138,14 +174,12 @@ public static ISubmodelElement BuildAasElement(JObject tdJObject, JObject tdSche int i = 1; foreach (var _form in tdJObject["forms"]) { - JObject formJObject = JObject.FromObject(_form); + JObject formJObject = ReplaceformProperties(JObject.FromObject(_form)); + List keys = formJObject.Properties().Select(p => p.Name).ToList(); - if (keys.Contains("htv:methodName")) + if (keys.Contains("htv_methodName")) { JObject formSchemaJObject = JObject.FromObject(tdSchemaObject["childs"][0]); - string methodName = formJObject["htv:methodName"].ToString(); - formJObject.Remove("htv:methodName"); - formJObject["htv_methodName"] = methodName; JObject httpFormJobject = new JObject(); httpFormJobject["HTTP Form"] = JToken.FromObject(formJObject); ISubmodelElement fsmc = BuildAasElement(httpFormJobject, formSchemaJObject); @@ -155,7 +189,7 @@ public static ISubmodelElement BuildAasElement(JObject tdJObject, JObject tdSche else if (isMQTTForm(keys)) { JObject mttFormJobject = new JObject(); - mttFormJobject["MQTT Form"] = JToken.FromObject(formJObject); + mttFormJobject["MQTT Form"] = ReplaceformProperties(formJObject); JObject formSchemaJObject = JObject.FromObject(tdSchemaObject["childs"][1]); ISubmodelElement fsmc = BuildAasElement(mttFormJobject, formSchemaJObject); fsmc.IdShort = "form" + string.Format("{00:00}", i); @@ -164,7 +198,7 @@ public static ISubmodelElement BuildAasElement(JObject tdJObject, JObject tdSche else if (isModBusForm(keys)) { JObject modbusFormJobject = new JObject(); - modbusFormJobject["MODBUS Form"] = JToken.FromObject(formJObject); + modbusFormJobject["MODBUS Form"] = ReplaceformProperties(formJObject); JObject formSchemaJObject = JObject.FromObject(tdSchemaObject["childs"][2]); ISubmodelElement fsmc = BuildAasElement(modbusFormJobject, formSchemaJObject); fsmc.IdShort = "form" + string.Format("{00:00}", i); @@ -173,6 +207,28 @@ public static ISubmodelElement BuildAasElement(JObject tdJObject, JObject tdSche break; } } + else if (formText == "htv_headers") + { + { + if (!tdJObject.ContainsKey("htv_headers")) + { + return null; + } + int j = 0; + foreach (var _header in tdJObject["htv_headers"]) + { + JObject headerJObject = new JObject(); + headerJObject["htv_header"] = JObject.FromObject(_header); + JObject headerSchemaJObject = JObject.FromObject(tdSchemaObject["childs"][0]); + ISubmodelElement hsme = BuildAasElement(headerJObject, headerSchemaJObject); + hsme.IdShort = "htv_header" + string.Format("{00:00}", j); + submodelElement.Add(hsme); + j++; + } + submodelElement.IdShort = "htv_headers"; + return submodelElement; + } + } else { JObject jobject = JObject.FromObject(tdJObject[formText]); @@ -319,10 +375,13 @@ public static SubmodelElementCollection CreateAssetInterfaceDescriptionFromTd( } else { - Aas.ISubmodelElement tdElement = BuildAasElement(tdJObject, childSchemaObject); - if (tdElement != null) + if (tdJObject.ContainsKey(formText)) { - interfaceDescription.Add(tdElement); + Aas.ISubmodelElement tdElement = BuildAasElement(tdJObject, childSchemaObject); + if (tdElement != null) + { + interfaceDescription.Add(tdElement); + } } } } diff --git a/src/AasxPredefinedConcepts/AIDResources.cs b/src/AasxPredefinedConcepts/AIDResources.cs index 406db7b6..b141a12a 100644 --- a/src/AasxPredefinedConcepts/AIDResources.cs +++ b/src/AasxPredefinedConcepts/AIDResources.cs @@ -533,7 +533,7 @@ class AIDResources 'childs': [ { 'AasElementType': 'SubmodelElementCollection', - 'multiplcity': '0..1', + 'multiplcity': '0..*', 'description': 'An Interaction Affordance that exposes state of the Thing', 'semanticReference': 'https://admin-shell.io/idta/AssetInterfaceDescription/1/0/PropertyDefinition', 'formtext': 'property', @@ -638,29 +638,41 @@ class AIDResources }, { 'AasElementType': 'SubmodelElementCollection', - 'formtext': 'htv_header', + 'formtext': 'htv_headers', + 'presetIdShort': 'htv_headers', 'multiplcity': '0..*', 'semanticReference': 'https://www.w3.org/2011/http#headers', 'presetIdShort': '', 'description': ' Information for http message header definition', 'childs': [ { - 'AasElementType': 'Property', - 'valueType' : 'xs:string', - 'formtext': 'htv_fieldName', - 'multiplcity': '0..1', - 'semanticReference': 'https://www.w3.org/2011/http#fieldName', - 'presetIdShort': 'htv_fieldName', - 'description': '' - }, - { - 'AasElementType': 'Property', - 'valueType' : 'xs:string', - 'formtext': 'htv_fieldValue', - 'multiplcity': '0..1', - 'semanticReference': 'https://www.w3.org/2011/http#fieldValue', - 'presetIdShort': 'htv_fieldValue', - 'description': '' + 'AasElementType': 'SubmodelElementCollection', + 'formtext': 'htv_header', + 'presetIdShort': 'htv_header{00:00}', + 'multiplcity': '0..*', + 'semanticReference': 'https://www.w3.org/2011/http#headers', + 'presetIdShort': '', + 'description': ' Information for http message header definition', + 'childs': [ + { + 'AasElementType': 'Property', + 'valueType' : 'xs:string', + 'formtext': 'htv_fieldName', + 'multiplcity': '0..1', + 'semanticReference': 'https://www.w3.org/2011/http#fieldName', + 'presetIdShort': 'htv_fieldName', + 'description': '' + }, + { + 'AasElementType': 'Property', + 'valueType' : 'xs:string', + 'formtext': 'htv_fieldValue', + 'multiplcity': '0..1', + 'semanticReference': 'https://www.w3.org/2011/http#fieldValue', + 'presetIdShort': 'htv_fieldValue', + 'description': '' + } + ] } ] } diff --git a/src/AasxPredefinedConcepts/DefinitionsAID.cs b/src/AasxPredefinedConcepts/DefinitionsAID.cs index c6912957..035e7526 100644 --- a/src/AasxPredefinedConcepts/DefinitionsAID.cs +++ b/src/AasxPredefinedConcepts/DefinitionsAID.cs @@ -33,7 +33,7 @@ public Submodel public JObject EndpointMetadataJObject = AIDResources.EndpointMetadataJObject; public List mqttFormElemList = new List() { "mqv_retain", "mqv_controlPacket","mqv_qos"}; - public List modvFormElemList = new List() { "modv_function", + public List modvFormElemList = new List() { "modv:function", "modv_entity","modv_zeroBasedAddressing","modv_pollingTime", "modv_type","modv_mostSignificantByte","modv_mostSignificantWord" };