Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Fixed Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hapakala committed Mar 10, 2024
1 parent f70e14c commit 2a4ca46
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 30 deletions.
37 changes: 36 additions & 1 deletion src/AasxPluginAID/AIDTDExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JObject> headers = new List<JObject>();
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;
Expand Down Expand Up @@ -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);
}
Expand Down
79 changes: 69 additions & 10 deletions src/AasxPluginAID/AIDTDImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JObject> headers = new List<JObject>();
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)
{
Expand Down Expand Up @@ -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<string> 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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]);
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
48 changes: 30 additions & 18 deletions src/AasxPredefinedConcepts/AIDResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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': ''
}
]
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/AasxPredefinedConcepts/DefinitionsAID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Submodel
public JObject EndpointMetadataJObject = AIDResources.EndpointMetadataJObject;
public List<string> mqttFormElemList = new List<string>() { "mqv_retain",
"mqv_controlPacket","mqv_qos"};
public List<string> modvFormElemList = new List<string>() { "modv_function",
public List<string> modvFormElemList = new List<string>() { "modv:function",
"modv_entity","modv_zeroBasedAddressing","modv_pollingTime",
"modv_type","modv_mostSignificantByte","modv_mostSignificantWord"
};
Expand Down

0 comments on commit 2a4ca46

Please sign in to comment.