Program.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using ConfigOperator;
  2. using GeneralData;
  3. using TemperatureConfigFile;
  4. using Universal;
  5. namespace ToMcFile;
  6. internal class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. Start:
  11. string? path;
  12. Console.WriteLine("Please drag file into console and press <Enter>");
  13. path = Console.ReadLine();
  14. path = path?.Trim('"');
  15. if (string.IsNullOrEmpty(path) || !File.Exists(path))
  16. {
  17. Console.WriteLine("File Not Exist");
  18. goto Start;
  19. }
  20. Console.WriteLine("Input Numerator:");
  21. string? numeratorString = Console.ReadLine();
  22. if (string.IsNullOrEmpty(numeratorString) || !int.TryParse(numeratorString, out int numerator) || numerator < 0)
  23. {
  24. Console.WriteLine("numerator Error");
  25. goto Start;
  26. }
  27. Console.WriteLine("Input Denominator:");
  28. string? denominatorString = Console.ReadLine();
  29. if (string.IsNullOrEmpty(denominatorString) || !int.TryParse(denominatorString, out int denominator) || denominator < 0)
  30. {
  31. Console.WriteLine("denominator Error");
  32. goto Start;
  33. }
  34. Dictionary<string, Dictionary<int, Dictionary<int, string>>> sheet_row_colum = ExcelReader.Read(path, 1);
  35. foreach (var row_colum in sheet_row_colum)
  36. {
  37. ConfigSaveXML configSaveXML = new()
  38. {
  39. EditTime = DateTime.Now,
  40. Editor = "Undefined",
  41. Description = "Undefined",
  42. Mini8Configs = []
  43. };
  44. Dictionary<byte, Mini8ConfigXML> mini8Configs = [];
  45. foreach (var colum in row_colum.Value)
  46. {
  47. if (!byte.TryParse(colum.Value[0], out byte mini8Index))
  48. continue;
  49. if (!mini8Configs.TryGetValue(mini8Index, out Mini8ConfigXML? mini8Config))
  50. {
  51. mini8Config = new()
  52. {
  53. Index = mini8Index,
  54. ChannelConfig = []
  55. };
  56. mini8Configs[mini8Index] = mini8Config;
  57. }
  58. ChannelConfig channel = GetChannelConfig(colum.Value, numerator, denominator);
  59. channel.CapsWarning = (channel.Caps + channel.SetPoint) / 2;
  60. channel.FloorWarning = (channel.Floor + channel.SetPoint) / 2;
  61. mini8Config.ChannelConfig!.Add(channel);
  62. }
  63. configSaveXML.Mini8Configs.AddRange(mini8Configs.Values);
  64. string outputPath = Path.Combine(Path.GetDirectoryName(path)!, $"{row_colum.Key}.mc");
  65. XmlFileHelper.WriteFile(outputPath, configSaveXML);
  66. }
  67. goto Start;
  68. }
  69. private static ChannelConfig GetChannelConfig(Dictionary<int, string> channel, int numerator, int denominator)
  70. {
  71. string[] content = [.. channel.Values];
  72. ChannelConfig config = new();
  73. config.Index = byte.Parse(content[1]);
  74. if (float.TryParse(content[2], out float setPoint))
  75. {
  76. Console.WriteLine(setPoint);
  77. if (setPoint > 60)
  78. config.SetPoint = setPoint / denominator * numerator;
  79. else
  80. config.SetPoint = setPoint;
  81. }
  82. if (numerator != 1 || denominator != 1)
  83. {
  84. config.Floor = config.SetPoint - 10;
  85. config.Caps = config.SetPoint + 10;
  86. }
  87. else
  88. {
  89. if (float.TryParse(content[4], out float floor))
  90. config.Floor = floor;
  91. if (float.TryParse(content[5], out float caps))
  92. config.Caps = caps;
  93. }
  94. if (float.TryParse(content[6], out float p))
  95. config.Running_P = p;
  96. if (float.TryParse(content[7], out float i))
  97. config.Running_I = i;
  98. if (float.TryParse(content[8], out float d))
  99. config.Running_D = d;
  100. config.ActiveTuneSet = ActiveTuneSet.Running;
  101. config.Inhibit = content[9] switch
  102. {
  103. "Enable" => Inhibit.Enable,
  104. _ => Inhibit.Disable
  105. };
  106. config.ChannelMode = content[2] switch
  107. {
  108. "moni" => ChannelMode.Monitor,
  109. _ => ChannelMode.Control,
  110. };
  111. if (config.Inhibit == Inhibit.Disable)
  112. config.ChannelMode = ChannelMode.UnUsed;
  113. if (content.Length < 11)
  114. return config;
  115. if (float.TryParse(content[10], out float upRate))
  116. config.SetpointUpRate = upRate;
  117. if (float.TryParse(content[11], out float downRate))
  118. config.SetpointDownRate = downRate;
  119. return config;
  120. }
  121. private static ChannelConfig GetChannelConfig(Dictionary<int, string> channel)
  122. {
  123. string[] content = [.. channel.Values];
  124. ChannelConfig config = new();
  125. config.Index = byte.Parse(content[1]);
  126. if (float.TryParse(content[2], out float setPoint))
  127. config.SetPoint = setPoint;
  128. if (float.TryParse(content[4], out float floor))
  129. config.Floor = floor;
  130. if (float.TryParse(content[5], out float caps))
  131. config.Caps = caps;
  132. if (float.TryParse(content[6], out float p))
  133. config.Running_P = p;
  134. if (float.TryParse(content[7], out float i))
  135. config.Running_I = i;
  136. if (float.TryParse(content[8], out float d))
  137. config.Running_D = d;
  138. config.ActiveTuneSet = ActiveTuneSet.Running;
  139. config.Inhibit = content[9] switch
  140. {
  141. "Enable" => Inhibit.Enable,
  142. _ => Inhibit.Disable
  143. };
  144. config.ChannelMode = content[2] switch
  145. {
  146. "moni" => ChannelMode.Monitor,
  147. _ => ChannelMode.Control,
  148. };
  149. if (config.Inhibit == Inhibit.Disable)
  150. config.ChannelMode = ChannelMode.UnUsed;
  151. if (content.Length < 11)
  152. return config;
  153. if (float.TryParse(content[10], out float upRate))
  154. config.SetpointUpRate = upRate;
  155. if (float.TryParse(content[11], out float downRate))
  156. config.SetpointDownRate = downRate;
  157. return config;
  158. }
  159. }