Skip to content

Commit e680e5e

Browse files
Merge branch 'refs/heads/main' into feature/test-action
2 parents d396a93 + bc713ef commit e680e5e

5 files changed

Lines changed: 71 additions & 47 deletions

File tree

.vscode/launch.json

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"stopAtEntry": false
124124
},
125125
{
126-
"name": "Debug Fingerprint",
126+
"name": "Debug AccessControl",
127127
"type": "coreclr",
128128
"request": "launch",
129129
"preLaunchTask": "build",
@@ -132,8 +132,8 @@
132132
"create",
133133
"--Debug",
134134
"--HeaderFileName",
135-
"../OAM-Fingerprint/include/knxprod.h",
136-
"../OAM-Fingerprint/src/FingerprintModule"
135+
"../OAM-AccessControl/include/knxprod.h",
136+
"../OAM-AccessControl/src/AccessControl"
137137
],
138138
"cwd": "${workspaceFolder}",
139139
"console": "internalConsole",
@@ -150,7 +150,7 @@
150150
"--Debug",
151151
"--HeaderFileName",
152152
"../SOM-UP/include/knxprod.h",
153-
"../SOM-UP/src/SoundModule"
153+
"../SOM-UP/src/SoundModule-Dev"
154154
],
155155
"cwd": "${workspaceFolder}",
156156
"console": "internalConsole",
@@ -184,29 +184,12 @@
184184
"--Debug",
185185
"--HeaderFileName",
186186
"../OAM-InternetServices/include/knxprod.h",
187-
"../OAM-InternetServices/src/InternetServicesESP32-Test"
187+
"../OAM-InternetServices/src/InternetServices-Dev"
188188
],
189189
"cwd": "${workspaceFolder}",
190190
"console": "internalConsole",
191191
"stopAtEntry": false
192192
},
193-
{
194-
"name": "Debug SOM-UP (temp)",
195-
"type": "coreclr",
196-
"request": "launch",
197-
"preLaunchTask": "build",
198-
"program": "${workspaceFolder}/bin/Debug/net8.0/OpenKNXproducer.dll",
199-
"args": [
200-
"create",
201-
"--Debug",
202-
"--HeaderFileName",
203-
"../SOM-UP/include/knxprod.h",
204-
"../SOM-UP/src/SoundModule"
205-
],
206-
"cwd": "${workspaceFolder}/../../OpenKNX-tmp/SOM-UP",
207-
"console": "internalConsole",
208-
"stopAtEntry": false
209-
},
210193
{
211194
"name": "Debug PresenceModule",
212195
"type": "coreclr",

OpenKNXproducer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<!-- <Nullable>enable</Nullable> -->
2929
<!-- No git hash in the version info -->
3030
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
31-
<Version>3.10.8</Version>
31+
<Version>3.11.0</Version>
3232
<!-- <PublishTrimmed>false</PublishTrimmed> -->
3333
<PublishReadyToRun>true</PublishReadyToRun>
3434
<PublishSingleFile>true</PublishSingleFile>

ProcessInclude.cs

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,34 +67,82 @@ public int ChannelCount
6767
}
6868
}
6969

70-
private bool MergeParameterTypes(XmlNode iMergeTarget, XmlNode iMergeSource)
70+
private static bool MergeParameterTypes(XmlNode iMergeTarget, XmlNode iMergeSource)
7171
{
7272
// check merge preconditions
7373
if (iMergeTarget == null || iMergeSource == null) return false;
7474
XmlNode lSourceChild = iMergeSource.FirstChild;
7575
XmlNode lTargetChild = iMergeTarget;
76+
// we only merge restrictions
77+
if (lSourceChild.Name != "TypeRestriction") return false;
78+
// Size has to be identical
7679
if (lSourceChild.Name != lTargetChild.Name || lSourceChild.NodeAttr("Base") != lTargetChild.NodeAttr("Base") || lSourceChild.NodeAttr("SizeInBit") != lTargetChild.NodeAttr("SizeInBit"))
7780
{
7881
// we have to check the parameter types, if they are compatible
7982
// if not, we cannot merge them
8083
Program.Message(true, "Merging ParameterType {0}: Source and Target are not compatible!", iMergeTarget.Name);
8184
return false;
8285
}
83-
86+
87+
bool lResult = false;
88+
// simple check (speed): If the first child exists in target, merge was done before
89+
string lValue = lSourceChild.ChildNodes[0].NodeAttr("Value");
90+
if (lValue == "") return false;
91+
foreach (XmlNode lTargetNode in lTargetChild.ChildNodes)
92+
if (lTargetNode.NodeAttr("Value") == lValue) return false;
93+
8494
// we merge the parameter types of the source into the target
8595
foreach (XmlNode lChild in lSourceChild.ChildNodes)
8696
{
8797
XmlNode lImportNode = lTargetChild.OwnerDocument.ImportNode(lChild.Clone(), true);
8898
lTargetChild.AppendChild(lImportNode);
99+
lResult = true;
89100
}
90-
return true;
101+
return lResult;
91102
}
92103

104+
private void MergeParameterTypes()
105+
{
106+
List<XmlNode> lMergedList = new();
107+
Dictionary<string, XmlNode> lFoundParameterTypes = new();
108+
// before we start with template processing, we calculate all Parameter relevant info
109+
XmlNode lParameterTypes = mDocument.SelectSingleNode("//ApplicationProgram/Static/ParameterTypes");
110+
if (lParameterTypes != null)
111+
{
112+
foreach (XmlNode lChild in lParameterTypes.ChildNodes)
113+
if (lChild.NodeType == XmlNodeType.Element)
114+
{
115+
string lParameterTypeId = lChild.SubId("Id", "_PT-");
116+
if (lParameterTypeId == "") continue;
117+
if (lFoundParameterTypes.ContainsKey(lParameterTypeId))
118+
{
119+
// we try to merge parameter types
120+
bool lMerged = MergeParameterTypes(lFoundParameterTypes[lParameterTypeId], lChild);
121+
if (lMerged) lMergedList.Add(lChild);
122+
}
123+
else
124+
{
125+
// Speed: we don't add the full type node, just the type definition itself
126+
XmlNode lTypeChild = lChild.FirstChild;
127+
while (lTypeChild != null && lTypeChild.NodeType == XmlNodeType.Comment) lTypeChild = lTypeChild.NextSibling;
128+
lFoundParameterTypes.Add(lParameterTypeId, lTypeChild);
129+
}
130+
}
131+
// we remove all merged parameter types from the document
132+
// this is necessary, because the parameter types are not allowed to be duplicated
133+
// has to be done after the loop, otherwise we get an exception
134+
if (lMergedList.Count > 0)
135+
foreach (XmlNode lChild in lMergedList)
136+
lChild.ParentNode.RemoveChild(lChild);
137+
}
138+
mParameterTypesFetched = true;
139+
}
140+
141+
93142
private void FetchParameterTypes()
94143
{
95144
if (!mParameterTypesFetched)
96145
{
97-
List<XmlNode> lMergedList = new();
98146
// before we start with template processing, we calculate all Parameter relevant info
99147
XmlNode lParameterTypes = mDocument.SelectSingleNode("//ApplicationProgram/Static/ParameterTypes");
100148
if (lParameterTypes != null)
@@ -104,32 +152,21 @@ private void FetchParameterTypes()
104152
{
105153
string lParameterTypeId = lChild.SubId("Id", "_PT-");
106154
if (lParameterTypeId == "") continue;
107-
if (sParameterTypes.ContainsKey(lParameterTypeId))
108-
{
109-
// we try to merge parameter types
110-
bool lMerged = MergeParameterTypes(sParameterTypes[lParameterTypeId], lChild);
111-
if (lMerged) lMergedList.Add(lChild);
112-
}
113-
else
155+
if (!sParameterTypes.ContainsKey(lParameterTypeId))
114156
{
115157
// Speed: we don't add the full type node, just the type definition itself
116158
XmlNode lTypeChild = lChild.FirstChild;
117159
while (lTypeChild != null && lTypeChild.NodeType == XmlNodeType.Comment) lTypeChild = lTypeChild.NextSibling;
118160
sParameterTypes.Add(lParameterTypeId, lTypeChild);
119161
}
120162
}
121-
// we remove all merged parameter types from the document
122-
// this is necessary, because the parameter types are not allowed to be duplicated
123-
// has to be done after the loop, otherwise we get an exception
124-
if (lMergedList.Count > 0)
125-
foreach (XmlNode lChild in lMergedList)
126-
lChild.ParentNode.RemoveChild(lChild);
127163
}
128164
mParameterTypesFetched = true;
129165
}
130166

131167
}
132168

169+
133170
public static XmlNode ParameterType(string iId, bool iError = true)
134171
{
135172
string lId = "_PT-";
@@ -677,7 +714,7 @@ void ProcessTemplate(DefineContent iDefine, int iChannel, XmlNode iTargetNode, P
677714
ProcessUnion(iDefine, iChannel, iTargetNode, iInclude);
678715
}
679716
else
680-
if ("Channel,ChannelIndependentBlock,ParameterBlock,choose,ParameterCalculations,ParameterValidations,ModuleDef".Contains(iTargetNode.Name))
717+
if ("ParameterType,Channel,ChannelIndependentBlock,ParameterBlock,choose,ParameterCalculations,ParameterValidations,ModuleDef".Contains(iTargetNode.Name))
681718
{
682719
ProcessChannel(iDefine, iChannel, iTargetNode, iInclude);
683720
}
@@ -691,7 +728,7 @@ static void ReplaceDocumentStrings(XmlNode iNode, string iSourceText, string iTa
691728
foreach (XmlAttribute lAttribute in lAttributes)
692729
{
693730
XmlNode lNode = lAttribute.OwnerElement;
694-
XmlNode lComment = lNode.OwnerDocument.CreateComment("Replaced " + iSourceText + " by " + iTargetText);
731+
XmlNode lComment = lNode.OwnerDocument.CreateComment("Replaced " + iSourceText + " by '" + iTargetText + "'");
695732
lNode.ParentNode.InsertBefore(lComment, lNode);
696733
lAttribute.Value = lAttribute.Value.Replace(iSourceText, iTargetText);
697734
}
@@ -701,6 +738,7 @@ bool ProcessFinish(XmlNode iTargetNode)
701738
{
702739
Console.WriteLine("Processing merged file...");
703740
ProcessConfig(iTargetNode);
741+
MergeParameterTypes();
704742
ReplaceKoTemplateFinal(iTargetNode);
705743
// ensure, that we found maxKoNumber
706744
XmlNodeList lKoNumbers = iTargetNode.SelectNodes("//ComObject/@Number");
@@ -2053,7 +2091,6 @@ private void ExportHeader(DefineContent iDefine, string iHeaderPrefixName, Proce
20532091
// if (iInclude.IsInnerInclude)
20542092
// return;
20552093
XmlNodeList lParameterNodes;
2056-
// FetchParameterTypes();
20572094
if (sParameterTypes.Count > 0)
20582095
{
20592096
// the main document contains necessary ParameterTypes definitions

Program.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,9 @@ static bool ProcessSanityChecks(ProcessInclude iInclude, bool iWithVersions)
611611
// remove module prefixes
612612
if (lId.StartsWith("_MD-"))
613613
{
614-
var lUnderscoreIndex = lId.IndexOf("_", 3);
614+
var lUnderscoreIndex = lId.IndexOf('_', 3);
615615
if (lUnderscoreIndex > 0)
616-
lId = lId.Substring(lUnderscoreIndex);
616+
lId = lId[lUnderscoreIndex..];
617617
}
618618
XmlNode lElement = lKeyValuePair.Value;
619619
switch (lElement.Name)
@@ -640,8 +640,11 @@ static bool ProcessSanityChecks(ProcessInclude iInclude, bool iWithVersions)
640640
break;
641641
case "Enumeration":
642642
lIdPart = "_PT-";
643-
string pt_id = lElement.ParentNode.ParentNode.Attributes["Id"].Value;
644-
lIdPart = pt_id.Substring(pt_id.IndexOf("_PT-")) + "_EN-"; // + lElement.Attributes["Value"].Value; don't check the value, ETS accepts anyway.
643+
string pt_id = "";
644+
XmlNode lSubElement = lElement.ParentNode;
645+
if (lSubElement != null) lSubElement = lSubElement.ParentNode;
646+
if (lSubElement != null) pt_id = lSubElement.NodeAttr("Id");
647+
if (pt_id != "") lIdPart = pt_id[pt_id.IndexOf("_PT-")..] + "_EN-"; // + lElement.Attributes["Value"].Value; don't check the value, ETS accepts anyway.
645648
break;
646649
case "ParameterRef":
647650
case "ComObjectRef":

xml/TemplateApplication.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</Code>
1818
<ParameterTypes>
1919
<op:includetemplate href="%share%" xpath="//ApplicationProgram/Static/ParameterTypes/ParameterType" prefix="%prefix%" />
20+
<op:includetemplate href="%templ%" xpath="//ApplicationProgram/Static/ParameterTypes/ParameterType" type="template" prefix="%prefix%" />
2021
</ParameterTypes>
2122
<Parameters>
2223
<op:includetemplate href="%share%" xpath="//ApplicationProgram/Static/Parameters/Parameter|//ApplicationProgram/Static/Parameters/Union" type="parameter" prefix="%prefix%" />

0 commit comments

Comments
 (0)