diff --git a/Thermo.Active.Config/ServerConfig.cs b/Thermo.Active.Config/ServerConfig.cs index 40aa0903..67a05f5c 100644 --- a/Thermo.Active.Config/ServerConfig.cs +++ b/Thermo.Active.Config/ServerConfig.cs @@ -51,10 +51,9 @@ namespace Thermo.Active.Config public static List SubscribedScada = new List(); public static List MacrosConfig; - + public static List InputsOperatorConfig; public static string CMSMainProgramContent; - // Thermo public static List ThermoProdConfig; public static List RecipeConfig; diff --git a/Thermo.Active.Config/ServerConfigController.cs b/Thermo.Active.Config/ServerConfigController.cs index 315fd631..478a8954 100644 --- a/Thermo.Active.Config/ServerConfigController.cs +++ b/Thermo.Active.Config/ServerConfigController.cs @@ -41,6 +41,7 @@ namespace Thermo.Active.Config // ReadCMSConnectConfig(); ReadMacros(); ReadScadaFile(); + ReadM156(); } catch (XmlException ex) { @@ -254,6 +255,47 @@ namespace Thermo.Active.Config } } + private static void ReadM156() + { + // Get Areas file handler + XDocument xmlConfigFile = GetXmlHandlerWithValidator(M156_SCHEMA_PATH, M156_CONFIG_PATH); + + InputsOperatorConfig = xmlConfigFile + .Descendants("inputsOperator") + .Elements() + .Select(x => new InputOperatorConfigModel() + { + Id = Convert.ToInt32(x.Element("id").Value), + Messages = x.Element("title").Elements().ToDictionary( // Read localized names and convert into a dictionary + y => y.Attribute("langKey").Value, y => y.Value + ), + Buttons = x.Element("buttons")?.Elements().ToDictionary( // Read buttons data and convert into a dictionary + y => Convert.ToByte(y.Element("value").Value), + y => y.Element("title").Elements().ToDictionary( // Read localized names and convert into a dictionary + z => z.Attribute("langKey").Value, + z => z.Value + ) + ), + Type = GetInputOperatoType(x.Name.ToString()) + }) + .ToList(); + } + + + public static string GetInputOperatoType(string tagName) + { + switch (tagName) + { + case "modalValue": + return "REAL"; + case "buttonsListModal": + return "MULTIPLE_BUTTONS"; + case "showValModal": + return "SHOW_VAL"; + default: + return "REAL"; + } + } #region Read config from file from configuration diff --git a/Thermo.Active.Model/ConfigModels/InputOperatorConfigModel.cs b/Thermo.Active.Model/ConfigModels/InputOperatorConfigModel.cs new file mode 100644 index 00000000..581ed4f3 --- /dev/null +++ b/Thermo.Active.Model/ConfigModels/InputOperatorConfigModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Thermo.Active.Model.ConfigModels +{ + public class InputOperatorConfigModel + { + public int Id { get; set; } + public Dictionary Messages { get; set; } + public Dictionary> Buttons { get; set; } + public string Type { get; set; } + } +} diff --git a/Thermo.Active.Model/Constants.cs b/Thermo.Active.Model/Constants.cs index 59a08d22..7a00b085 100644 --- a/Thermo.Active.Model/Constants.cs +++ b/Thermo.Active.Model/Constants.cs @@ -231,6 +231,9 @@ namespace Thermo.Active.Model public const string AREAS_CONFIG_SCHEMA_PATH = RESOURCE_DIRECTORY + "areasConfigValidator.xsd"; public const string AREAS_CONFIG_PATH = CONFIG_DIRECTORY + "areasConfig.xml"; + public const string M156_SCHEMA_PATH = RESOURCE_DIRECTORY + "inputOperatorConfigValidator.xsd"; + public const string M156_CONFIG_PATH = CONFIG_DIRECTORY + "inputOperatorConfig.xml"; + public const string MAINTENANCES_CONFIG_SCHEMA_PATH = RESOURCE_DIRECTORY + "maintenancesConfigValidator.xsd"; public const string CUSTOMER_CONTACTS_CONFIG_SCHEMA_PATH = RESOURCE_DIRECTORY + "customerContactConfigValidator.xsd"; public const string MAINTENANCES_CONFIG_PATH = CONFIG_DIRECTORY + "maintenancesConfig.xml"; @@ -308,6 +311,7 @@ namespace Thermo.Active.Model public const string SEND_ACTIVE_PROGRAM_DATA = "SEND_ACTIVE_PROGRAM_DATA"; public const string SEND_QUEUE_DATA = "SEND_QUEUE_DATA"; public const string SEND_M155_DATA = "SEND_M155_DATA"; + public const string SEND_M156_DATA = "SEND_M156_DATA"; public const string SEND_SCADA_DATA = "SEND_SCADA_DATA"; // MVVM Messages for Thermo active specs diff --git a/Thermo.Active.Model/DTOModels/DTOM156InputModel.cs b/Thermo.Active.Model/DTOModels/DTOM156InputModel.cs new file mode 100644 index 00000000..02ce6091 --- /dev/null +++ b/Thermo.Active.Model/DTOModels/DTOM156InputModel.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static CMS_CORE_Library.Models.DataStructures; + +namespace Thermo.Active.Model.DTOModels +{ + public class DTOM156InputModel : M156InputIsNeededModel + { + public Dictionary Buttons; + public string Type; + public bool isM156 = true; + + public override bool Equals(object obj) + { + if (!(obj is DTOM156InputModel item)) + return false; + + if (Process != item.Process) + return false; + + if (Type != item.Type) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +} diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index fe6dee5b..7f5951c2 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1270,6 +1270,40 @@ namespace Thermo.Active.NC return numericalControl.PLC_RM154Data(ref data, ref MTCStatus); } + public CmsError GetM156Data(out List data) + { + data = new List(); + List ncData = new List(); + CmsError cmsError = numericalControl.PLC_RM156Data(ref ncData); + if (cmsError.IsError()) + return cmsError; + + if (ncData.Count() > 0) + { + foreach (var m156Message in ncData) + { + var inp = InputsOperatorConfig.Where(x => m156Message.Id == x.Id).FirstOrDefault(); + + var buttons = inp.Buttons?.ToDictionary(x => x.Key, x => x.Key.ToString()); + if (inp != null) + { + data.Add(new DTOM156InputModel() + { + Id = inp.Id, + isM156 = true, + Buttons = buttons, + Type = inp.Type, + Process = m156Message.Process, + Value = m156Message.Value + }); + } + } + } + + return NO_ERROR; + } + + public CmsError WriteM154Ack(int processId) { return numericalControl.PLC_W154ManageAck(processId); diff --git a/Thermo.Active/Controllers/WebApi/LanguageController.cs b/Thermo.Active/Controllers/WebApi/LanguageController.cs index 02fc1a2e..c3116b5f 100644 --- a/Thermo.Active/Controllers/WebApi/LanguageController.cs +++ b/Thermo.Active/Controllers/WebApi/LanguageController.cs @@ -57,8 +57,10 @@ namespace Thermo.Active.Controllers.WebApi // scada Dictionary scadaTranslations = GetScadaTranslations(language); + // M156 + Dictionary m156Translations = GetM156Translations(language); - // THermo (modules and recipe enums) translations + // Thermo (modules and recipe enums) translations Dictionary thermoTranslations = GetThermoTranslations(language); @@ -72,7 +74,9 @@ namespace Thermo.Active.Controllers.WebApi translations = translations.Concat(headsNames).ToDictionary(x => x.Key, x => x.Value); // Scada translations = translations.Concat(scadaTranslations).ToDictionary(x => x.Key, x => x.Value); - // Scada + // M156 + translations = translations.Concat(m156Translations).ToDictionary(x => x.Key, x => x.Value); + // Thermo translations = translations.Concat(thermoTranslations).ToDictionary(x => x.Key, x => x.Value); if (translations == null) @@ -210,5 +214,31 @@ namespace Thermo.Active.Controllers.WebApi return translatedNames; } + + public static Dictionary GetM156Translations(string language) + { + Dictionary translatedNames = new Dictionary(); + + foreach (var input in InputsOperatorConfig) + { + translatedNames.Add( + "m156_title_" + input.Id, + GetValueFromLocalizationList(input.Messages, language, "Title_" + input.Id) + ); + + if (input.Buttons != null && input.Buttons.Count() > 0) + foreach (var button in input.Buttons) + { + // Add translated button text to the list + // Buttons have a Dictionary with the translations + translatedNames.Add( + "m156_" + input.Id + "_button_" + button.Key, + GetValueFromLocalizationList(button.Value, language, "Button_" + button.Key) + ); + } + } + + return translatedNames; + } } } \ No newline at end of file diff --git a/Thermo.Active/Listeners/ListenersHandler.cs b/Thermo.Active/Listeners/ListenersHandler.cs index fa99a834..1dbd9005 100644 --- a/Thermo.Active/Listeners/ListenersHandler.cs +++ b/Thermo.Active/Listeners/ListenersHandler.cs @@ -86,6 +86,10 @@ namespace Thermo.Active.Listeners { SignalRListener.SetGatewayRebootStatus(a); })); + infos.Add(MessageServices.Current.Subscribe(SEND_M156_DATA, (a, b) => + { + SignalRListener.SendM156Data(a); + })); // add specific modules for THERMO infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_RECIPE_FULL, (a, b) => diff --git a/Thermo.Active/Listeners/SignalR/SignalRListener.cs b/Thermo.Active/Listeners/SignalR/SignalRListener.cs index 83c6c0e3..46ceedcf 100644 --- a/Thermo.Active/Listeners/SignalR/SignalRListener.cs +++ b/Thermo.Active/Listeners/SignalR/SignalRListener.cs @@ -239,6 +239,17 @@ namespace Thermo.Active.Listeners.SignalR } } #endif + public static void SendM156Data(object data) + { + List dtoM156Data = data as List; + + if (!LastM156Data.SequenceEqual(dtoM156Data)) + { + LastM156Data = dtoM156Data; + var context = GlobalHost.ConnectionManager.GetHubContext(); + context.Clients.Group("ncData").m156Data(dtoM156Data); + } + } public static void SendScadaData(object scada) { @@ -455,6 +466,8 @@ namespace Thermo.Active.Listeners.SignalR } } + + public static void SetGatewayRebootStatus(object status) { string msg = status.ToString(); diff --git a/Thermo.Active/Listeners/SignalRStaticObjects.cs b/Thermo.Active/Listeners/SignalRStaticObjects.cs index 82d094af..37976fd1 100644 --- a/Thermo.Active/Listeners/SignalRStaticObjects.cs +++ b/Thermo.Active/Listeners/SignalRStaticObjects.cs @@ -30,6 +30,7 @@ namespace Thermo.Active.Listeners #if false public static List LastM155Data = new List(); #endif + public static List LastM156Data = new List(); public static List LastScadaData = new List(); // FIXME TODO inserire oggetti corretti per THERMO