diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-02 14:50:49 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-02 14:50:49 +0300 |
| commit | 8d4dc3692614e299314af9f4a5dd7827946ca721 (patch) | |
| tree | d8088b4bcee914ea83a9d28cd6a8f4c4a0139065 /Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs | |
| parent | 245f33b78eac4f0659d7d3493c01a45e35da205a (diff) | |
| download | Tango-8d4dc3692614e299314af9f4a5dd7827946ca721.tar.gz Tango-8d4dc3692614e299314af9f4a5dd7827946ca721.zip | |
Implementing alarm parameters generator.
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs')
| -rw-r--r-- | Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs b/Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs new file mode 100644 index 000000000..027f2fc73 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Helpers; +using Tango.Documents; +using Tango.PMR.Debugging; +using Tango.PMR.Diagnostics; +using Tango.PMR.EmbeddedParameters; + +namespace Tango.AlarmParametersGenerator +{ + class Program + { + private class ExcelEventType + { + public String Code { get; set; } + public String Name { get; set; } + public String Title { get; set; } + public String Description { get; set; } + public String TechnicalDescription { get; set; } + public String Index { get; set; } + public String Category { get; set; } + public String Group { get; set; } + public String UserInterventionRequired { get; set; } + public String ActionsUI { get; set; } + public String ActionsEmbedded { get; set; } + public String NotificationTime { get; set; } + public String Guidance { get; set; } + + //Embedded + public String SWIndex { get; set; } + public String Frequency { get; set; } + public String Source { get; set; } + public String DeviceId { get; set; } + public String ApplicationDeviceID { get; set; } + public String Criteria { get; set; } + public String Direction { get; set; } + public String Severity { get; set; } + public String Predeccesor { get; set; } + public String DebounceValue { get; set; } + + public override string ToString() + { + return this.ToJsonString(); + } + } + + static void Main(string[] args) + { + try + { + if (args.Count() == 0) + { + throw new ArgumentException("Please specify an output file path"); + } + + String outputFile = args[0]; + + Console.WriteLine("Generating alarm parameters file..."); + + ExcelReader reader = new ExcelReader(PathHelper.GetStartupPath() + "\\Tango alarm events handling chart_Rev8.xlsx"); + var results = reader.GetDataByIndex<ExcelEventType>("ALARM EVENTS HANDLING", 2); + + AlarmParameters parameters = new AlarmParameters(); + + foreach (var item in results) + { + if (!String.IsNullOrWhiteSpace(item.Source)) + { + Console.WriteLine($"Parsing event {item.Code}..."); + + AlarmHandlingItem alarm = new AlarmHandlingItem(); + alarm.AlarmSource = item.Source.ToEnum<AlarmSourceType>(); + alarm.Frequency = item.Frequency.ToUint(); + alarm.DeviceId = item.DeviceId.ToUint(); + alarm.ModuleDeviceId = item.ApplicationDeviceID.ToUint(); + alarm.AlarmValue = item.Criteria.ToUint(); + alarm.AlarmDirection = item.Direction.ToBoolean(); + alarm.Severity = item.Severity.ToEnum<DebugLogCategory>(); + alarm.Predecessor = item.Predeccesor.ToUint(); + alarm.DebounceValue = item.DebounceValue.ToUint(); + alarm.EventType = (EventType)item.Code.ToUint(); + + parameters.AlarmItem.Add(alarm); + } + } + + File.WriteAllBytes(outputFile, parameters.ToBytes()); + + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("File generated successfully!"); + } + catch (Exception ex) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(ex.Message); + } + } + } + + public static class Extensions + { + public static UInt32 ToUint(this String str) + { + return String.IsNullOrWhiteSpace(str) ? 0 : UInt32.Parse(str); + } + + public static T ToEnum<T>(this String str) where T : struct + { + return String.IsNullOrWhiteSpace(str) ? default(T) : (T)Enum.Parse(typeof(T), str); + } + + public static bool ToBoolean(this String str) + { + return String.IsNullOrWhiteSpace(str) ? false : (str.Contains("0") ? false : true); + } + } +} |
