Added missing F functions set

This commit is contained in:
Felix Weiß
2023-07-26 00:20:01 +02:00
parent d24201b5d9
commit 4d6eee5585
5 changed files with 5447 additions and 18 deletions

View File

@@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
@@ -290,7 +291,7 @@ internal class Program {
if(descrText != null) {
descrText = descrText.SanitizeLinebreakFormatting();
descrText = descrText.SanitizeLinebreakFormatting().Replace("\"", "\\\"");
functionIns.Description = descrText;
@@ -318,10 +319,89 @@ internal class Program {
}
var funcsJson = JsonSerializer.Serialize(functions, new JsonSerializerOptions { WriteIndented = true });
BuildFunctionNamesDictFile(functions);
File.WriteAllText("./function_names.json", funcsJson);
}
static void BuildFunctionNamesDictFile (Dictionary<string, FPFunction> dict) {
var sb = new StringBuilder();
sb.AppendLine("using System.Collections.Generic;\n");
sb.AppendLine("namespace MewtocolNet.AutoGeneratedData {\n");
sb.AppendLine("\tpublic class FPFunction {\n");
sb.AppendLine("\t\tpublic string RedundantName { get; private set; }\n");
sb.AppendLine("\t\tpublic string Description { get; private set; }\n");
sb.AppendLine("\t\tpublic Dictionary<string, string[]> ParametersIn { get; private set; }\n");
sb.AppendLine("\t\tpublic Dictionary<string, string[]> ParametersOut { get; private set; }\n");
sb.AppendLine("\t\tpublic static readonly Dictionary<string, FPFunction> functions = new Dictionary<string, FPFunction> {\n");
foreach (var item in dict) {
sb.AppendLine($"\t\t\t{{ \"{item.Key}\", new FPFunction {{");
if(item.Value.RedundantName != null)
sb.AppendLine($"\t\t\t\tRedundantName = \"{item.Value.RedundantName}\",");
if(item.Value.Description != null)
sb.AppendLine($"\t\t\t\tDescription = \"{item.Value.Description}\",");
if (item.Value.ParametersIn != null) {
sb.AppendLine("\t\t\t\tParametersIn = new Dictionary<string, string[]> {");
foreach (var paramIn in item.Value.ParametersIn) {
sb.AppendLine($"\t\t\t\t\t{{ \"{paramIn.Key}\", new string[] {{");
foreach (var paramType in paramIn.Value) {
sb.AppendLine($"\t\t\t\t\t\t\"{paramType}\",");
}
sb.AppendLine("\t\t\t\t\t}},");
}
sb.AppendLine("\t\t\t\t},");
}
if (item.Value.ParametersOut != null) {
sb.AppendLine("\t\t\t\tParametersOut = new Dictionary<string, string[]> {");
foreach (var paramOut in item.Value.ParametersOut) {
sb.AppendLine($"\t\t\t\t\t{{ \"{paramOut.Key}\", new string[] {{");
foreach (var paramType in paramOut.Value) {
sb.AppendLine($"\t\t\t\t\t\t\"{paramType}\",");
}
sb.AppendLine("\t\t\t\t\t}},");
}
sb.AppendLine("\t\t\t\t},");
}
sb.AppendLine($"\t\t\t}}}},");
}
sb.AppendLine("\t\t};\n");
sb.AppendLine("\t}\n");
sb.AppendLine("}");
File.WriteAllText("../../../../MewtocolNet/AutoGeneratedData/FPFunction.cs", sb.ToString());
}

File diff suppressed because it is too large Load Diff

View File

@@ -43,5 +43,9 @@
<ItemGroup>
<PackageReference Include="System.IO.Ports" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="AutoGeneratedData\" />
</ItemGroup>
</Project>

View File

@@ -4,6 +4,7 @@ using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using MewtocolNet.AutoGeneratedData;
namespace MewtocolNet.ProgramParsing {
@@ -46,17 +47,6 @@ namespace MewtocolNet.ProgramParsing {
{ "R901E", "sys_bPulse1min" },
};
static readonly Dictionary<string, string> stepFunctions = new Dictionary<string, string> {
{ "F0", "MV" },
{ "F1", "DMV" },
{ "F2", "MVN" },
{ "F3", "DMVN" },
{ "F5", "BTM" },
{ "F8", "DMV2" },
{ "F11", "COPY" },
{ "F61", "DCMP" }
};
// ST R50_1 21 AC => WR system area start was set to 50
// ST R57_1 91 AC => WR system area start was set to 57
// ST R901_3 F7 FF 53 A9
@@ -196,7 +186,33 @@ namespace MewtocolNet.ProgramParsing {
private string GetFunctionName (string funcName) {
return stepFunctions.ContainsKey(funcName) ? $"{funcName} ({stepFunctions[funcName]})" : funcName;
var found = FPFunction.functions.FirstOrDefault(x => x.Key.StartsWith(funcName));
if (!found.Equals(default(KeyValuePair<string, FPFunction>))) {
var sb = new StringBuilder();
var splt = found.Key.Split('_');
sb.Append($"{splt[0]} (*{splt[1]}*)");
if(found.Value.ParametersIn.Count > 0) {
sb.Append($" IN: {found.Value.ParametersIn.Count}");
}
if (found.Value.ParametersOut.Count > 0) {
sb.Append($" OUT: {found.Value.ParametersOut.Count}");
}
return sb.ToString();
}
return funcName;
}

View File

@@ -3,16 +3,19 @@
public enum PlcVarType {
BOOL,
WORD,
INT,
UINT,
DWORD,
DINT,
UDINT,
REAL,
TIME,
DATE_AND_TIME,
DATE,
TIME_OF_DAY,
STRING,
WORD,
DWORD
}
}