Skip to content

Commit

Permalink
Minor improvements:
Browse files Browse the repository at this point in the history
- module name for ConfigTransfer can be set within op:define (configTransferName attribute
- introduced %MaxKoNumber% replacement
- Special types (like TypeIPAddress, TypeColor) got wrong length, if they are placet at the end of a module
- There is a new warning for commented script functions, you should delete them to reduce application size
- Function names for ParameterValidations are checked for existence
  • Loading branch information
Waldemar Porscha committed May 8, 2024
1 parent 17d413d commit 543e923
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 36 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "Debug Fingerprint",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net6.0/OpenKNXproducer.dll",
"args": [
"create",
"--Debug",
"--HeaderFileName",
"../OAM-Fingerprint/include/knxprod.h",
"../OAM-Fingerprint/src/FingerprintModule"
],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "Debug SOM-UP",
"type": "coreclr",
Expand Down
6 changes: 3 additions & 3 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

[assembly: System.Reflection.AssemblyCompanyAttribute("OpenKNX")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("3.2.1.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("3.2.1")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("3.2.5.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("3.2.5")]
[assembly: System.Reflection.AssemblyProductAttribute("OpenKNXproducer")]
[assembly: System.Reflection.AssemblyTitleAttribute("OpenKNXproducer")]
[assembly: System.Reflection.AssemblyVersionAttribute("3.2.1.0")]
[assembly: System.Reflection.AssemblyVersionAttribute("3.2.5.0")]
8 changes: 8 additions & 0 deletions DefineContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class DefineContent
private static bool sWithConfigTransfer = false;

private bool mNoConfigTransfer = false;
private string mConfigTransferName = "";

public string prefix = "LOG";
public int KoOffset = 1;
Expand Down Expand Up @@ -39,6 +40,12 @@ public bool NoConfigTransfer
private set { mNoConfigTransfer = value; }
}

public string ConfigTransferName
{
get { return mConfigTransferName; }
private set { mConfigTransferName = value; }
}

public static DefineContent Factory(XmlNode iDefineNode)
{
DefineContent lResult = new();
Expand Down Expand Up @@ -73,6 +80,7 @@ public static DefineContent Factory(XmlNode iDefineNode)
}
lResult.share = iDefineNode.NodeAttr("share");
lResult.NoConfigTransfer = iDefineNode.NodeAttr("noConfigTransfer") == "true";
lResult.ConfigTransferName = iDefineNode.NodeAttr("configTransferName");
if (lResult.share.Contains("ConfigTransfer.share.xml"))
{
lResult.NoConfigTransfer = true;
Expand Down
32 changes: 15 additions & 17 deletions ExtendedEtsSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

static class ExtendedEtsSupport
{
static readonly Dictionary<string, Dictionary<string, string>> sParameterInfo = new();
static readonly Dictionary<DefineContent, Dictionary<string, string>> sParameterInfo = new();

public static string ParameterInfo
{
Expand All @@ -17,7 +17,7 @@ public static string ParameterInfo
foreach (var lEntry in sParameterInfo)
{
Dictionary<string, string> lModuleParams = lEntry.Value;
lResult += $"\n\"{lEntry.Key}\": {{";
lResult += $"\n\"{lEntry.Key.prefix}\": {{";
foreach (var lModuleParam in lModuleParams)
{
lResult += $"\n {lModuleParam.Value},";
Expand Down Expand Up @@ -48,12 +48,14 @@ private static bool GenerateModuleSelector(ProcessInclude iInclude, int iApplica
lIterator.Reset();
foreach (var lEntry in sParameterInfo)
{
string lText = lEntry.Key;
if (lText == "BASE")
lText = "Allgemein";
else
for (int lIndex = 0; lIndex < lChannels.Count; lIndex++)
{
string lText = lEntry.Key.prefix;
if (lEntry.Key.ConfigTransferName != "")
lText = lEntry.Key.ConfigTransferName;
// if (lText == "BASE")
// lText = "Allgemein";
// else
for (int lIndex = 0; lIndex < lChannels.Count; lIndex++)
{
if (!lIterator.MoveNext())
{
lIterator.Reset();
Expand All @@ -66,14 +68,10 @@ private static bool GenerateModuleSelector(ProcessInclude iInclude, int iApplica
break;
}
}
// if (lEntry.Key != cConfigTransferPrefix)
// {
DefineContent lDefine = DefineContent.GetDefineContent(lEntry.Key);
if (lDefine != null && lDefine.NumChannels > 0)
if (lEntry.Key.NumChannels > 0)
lTypeRestrictionCopy.AppendChild(iInclude.CreateElement("Enumeration", "Text", lText, "Value", lCount.ToString(), "Id", "%ENID%"));
lTypeRestriction.AppendChild(iInclude.CreateElement("Enumeration", "Text", lText, "Value", lCount++.ToString(), "Id", "%ENID%"));
lModuleOrder += "\"" + lEntry.Key + "\",";
// }
lModuleOrder += "\"" + lEntry.Key.prefix + "\",";
}
lModuleOrder = lModuleOrder[..^1] + "];\n";
XmlNode lNode = iInclude.SelectSingleNode("//ApplicationProgram/Static/ParameterTypes");
Expand Down Expand Up @@ -116,12 +114,12 @@ public static void GenerateScriptContent(ProcessInclude iInclude, DefineContent
StringBuilder lParameterNames = new();
StringBuilder lParameterDefaults = new();

if (sParameterInfo.ContainsKey(iDefine.prefix))
lDict = sParameterInfo[iDefine.prefix];
if (sParameterInfo.ContainsKey(iDefine))
lDict = sParameterInfo[iDefine];
else
{
lDict = new();
sParameterInfo.Add(iDefine.prefix, lDict);
sParameterInfo.Add(iDefine, lDict);
// add version information, if available
if (iDefine.NumChannels > 0)
lDict.Add("channels", $"\"channels\": {iDefine.NumChannels}");
Expand Down
20 changes: 10 additions & 10 deletions ProcessInclude.cs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ bool ProcessFinish(XmlNode iTargetNode)
lValue = lValue.Replace("%SerialNumberEncoded%", lSerialNumberEncoded);
lValue = lValue.Replace("%VersionCheck%", lInlineData);
lValue = lValue.Replace("%VersionMessage%", lVersionMessage);
lValue = lValue.Replace("%MaxKoNumber%", sMaxKoNumber.ToString());
lNode.Value = lValue;
}
}
Expand Down Expand Up @@ -1068,17 +1069,16 @@ public int CalcParamSize(XmlNode iParameter)
Console.WriteLine("Parse error in include {0} in line {1}", mXmlFileName, lSizeNode.InnerXml);
}
}
else if (lSizeNode.SelectSingleNode("TypeFloat") != null)
{
lResult = 4;
}
else if (lSizeNode.SelectSingleNode("TypeIPAddress") != null)
{
lResult = 4;
}
else if (lSizeNode.SelectSingleNode("TypeColor") != null)
else
{
lResult = 3;
if (lSizeNode.Name == "ParameterType")
lSizeNode = lSizeNode.SelectSingleNode("*[not(comment())]");
if (lSizeNode.Name == "TypeFloat")
lResult = 4;
else if (lSizeNode.Name == "TypeIPAddress")
lResult = 4;
else if (lSizeNode.Name == "TypeColor")
lResult = 3;
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,9 @@ static bool ProcessSanityChecks(ProcessInclude iInclude, bool iWithVersions)
XmlNode lScript = lXml.SelectSingleNode("//Script");
if (lScript != null)
{
Regex lFindFunctions = new(@"function\s*([A-Za-z0-9_]*)\s*\(");
Regex lFindFunctions = new(@"(//\s*)?function\s*([A-Za-z0-9_]*)\s*\(");
MatchCollection lFunctions = lFindFunctions.Matches(lScript.InnerText);
XmlNodeList lAttributes = lXml.SelectNodes("//Button/@EventHandler|//ParameterCalculation/@LRTransformationFunc|//ParameterCalculation/@RLTransformationFunc");
XmlNodeList lAttributes = lXml.SelectNodes("//Button/@EventHandler|//ParameterCalculation/@LRTransformationFunc|//ParameterCalculation/@RLTransformationFunc|//ParameterValidation/@ValidationFunc");
// speedup: transfer function call into a Hashtable
Dictionary<string, bool> lFunctionCalls = new();
foreach (XmlNode lAttribute in lAttributes)
Expand All @@ -765,11 +765,16 @@ static bool ProcessSanityChecks(ProcessInclude iInclude, bool iWithVersions)
// check unused javascript functions
foreach (Match lFunction in lFunctions.Cast<Match>())
{
string lFunctionName = lFunction.Groups[1].Value;
if (lFunctionCalls.ContainsKey(lFunctionName))
lFunctionCalls[lFunctionName] = true;
string lFunctionName = lFunction.Groups[2].Value;
if (lFunction.Value.StartsWith("//"))
lCheck.WriteWarn(3, "Function with name {0} is commented in <Script> block, you should remove it to reduce application size", lFunctionName);
else
lCheck.WriteWarn(3, "Function with name {0} was never called form xml", lFunctionName);
{
if (lFunctionCalls.ContainsKey(lFunctionName))
lFunctionCalls[lFunctionName] = true;
else
lCheck.WriteWarn(3, "Function with name {0} was never called form xml", lFunctionName);
}
}
foreach (var lFunctionCall in lFunctionCalls)
if (!lFunctionCall.Value)
Expand Down

0 comments on commit 543e923

Please sign in to comment.