From 5c53aa9f1560e280bc808134757bc7ae2f38728b Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 17 Oct 2020 15:12:04 +0200 Subject: [PATCH] Reorg simula... --- IOB-WIN/IobSimula.cs | 336 ++++++++++++++++++++++--------------------- 1 file changed, 174 insertions(+), 162 deletions(-) diff --git a/IOB-WIN/IobSimula.cs b/IOB-WIN/IobSimula.cs index 9872f1f7..4ea64010 100644 --- a/IOB-WIN/IobSimula.cs +++ b/IOB-WIN/IobSimula.cs @@ -86,6 +86,8 @@ namespace IOB_WIN #endregion Protected Fields + #region Public Fields + /// /// Ora spegniemnto (standard) /// @@ -96,6 +98,10 @@ namespace IOB_WIN /// public int tOn = 6; + #endregion Public Fields + + #region Public Constructors + /// /// estende l'init della classe base... /// @@ -145,167 +151,9 @@ namespace IOB_WIN lgInfo($"Impostazione iniziale contatori: contapezzi macchina contapezziPLC: {contapezziPLC} | contapezziIOB: {contapezziIOB}"); } - /// - /// Effettua reset del contapezzi - /// - /// - public override bool resetcontapezziPLC() - { - bool answ = false; - // ...SE abilitato da conf IOB - if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE") - { - // fingo di aver fatto... - answ = true; - } - return answ; - } + #endregion Public Constructors - public override void tryConnect() - { - base.tryConnect(); - connectionOk = true; - } - - public override void tryDisconnect() - { - base.tryDisconnect(); - connectionOk = false; - } - - /// - /// Setup aprametri di simulazione per BIT indicato - /// - /// - private simPar setupSimPar(string keyName) - { - simPar answ = new simPar(); - if (cIobConf.optPar.Count > 0) - { - if (cIobConf.optPar.ContainsKey(keyName)) - { - string fullVal = getOptPar(keyName); - if (!string.IsNullOrEmpty(fullVal) && fullVal.IndexOf("|") > 0) - { - string[] param = fullVal.Split('|'); - int.TryParse(param[0], out answ.wait); - int.TryParse(param[1], out answ.duration); - // aggiongo noise, +/- 40%... - Random rnd = new Random(); - int noise = rnd.Next(1, answ.wait * 40 / 100); - answ.wait += noise - (answ.wait * 20 / 100); - } - } - } - return answ; - } - - #region Metodi specifici (da verificare/completare in implementazione) - - /// - /// Recupera e processa allarmi CNC... - /// - public override Dictionary getCncAlarms() - { - Dictionary outVal = new Dictionary(); - return outVal; - } - - /// - /// Recupero dati dinamici... - /// - public override Dictionary getDynData() - { - // valore non presente in vers default... se gestito fare override - Dictionary outVal = new Dictionary(); - // verificare periodo SIM parametri... se passato li invio altrimenti NO... FIX a 20 sec - if (lastSimData.AddSeconds(waitSimPar) < DateTime.Now) - { - Random rnd = new Random(); - // controllo conf memorie json (se ci sono...) - try - { - if (memMap.mMapWrite.Count > 0) - { - foreach (var item in memMap.mMapWrite) - { - outVal.Add(item.Key, item.Value.value); - } - } - if (memMap.mMapRead.Count > 0) - { - foreach (var item in memMap.mMapRead) - { - // uso factor come valore MAX ammesso - int randVal = rnd.Next(item.Value.minVal, item.Value.maxVal); - outVal.Add(item.Key, randVal.ToString()); - } - } - } - catch - { } - lastSimData = DateTime.Now; - } - return outVal; - } - - /// - /// Recupero programma in lavorazione - /// - /// - public override string getPrgName() - { - // valore non presente in vers default... se gestito fare override - string prgName = string.Format("DEMO_{0:00}", DateTime.Now.Minute); - return prgName; - } - - /// - /// Recupero info sistema generiche - /// - public override Dictionary getSysInfo() - { - // valore non presente in vers default... se gestito fare override - Dictionary outVal = new Dictionary(); - outVal.Add("MACHINE", "IOB_SIM"); - return outVal; - } - - /// - /// Effettua vero processing contapezzi - /// - public override void processContapezzi() - { - } - - /// - /// Processo contatori eventi... - /// - public override void processVHF() - { - if (lastEvCheck.AddMilliseconds(periodoMSec) < DateTime.Now) - { - // decremento contatore ultimo evento - bit2.wait--; - bit3.wait--; - bit4.wait--; - bit5.wait--; - lastEvCheck = DateTime.Now; - } - } - - /// - /// Effettua lettura semafori principale - /// Parametri da aggiornare x display in form - /// - public override void readSemafori(ref newDisplayData currDispData) - { - base.readSemafori(ref currDispData); - // decodifica e gestione - decodeToBaseBitmap(); - decodeOtherData(); - reportRawInput(ref currDispData); - } + #region Private Methods /// /// Decodifica il resto dell'area x i dati accessori (allarmi, ...) @@ -601,7 +449,34 @@ namespace IOB_WIN } /// - /// provo a chaimare split ODL + /// Setup aprametri di simulazione per BIT indicato + /// + /// + private simPar setupSimPar(string keyName) + { + simPar answ = new simPar(); + if (cIobConf.optPar.Count > 0) + { + if (cIobConf.optPar.ContainsKey(keyName)) + { + string fullVal = getOptPar(keyName); + if (!string.IsNullOrEmpty(fullVal) && fullVal.IndexOf("|") > 0) + { + string[] param = fullVal.Split('|'); + int.TryParse(param[0], out answ.wait); + int.TryParse(param[1], out answ.duration); + // aggiongo noise, +/- 40%... + Random rnd = new Random(); + int noise = rnd.Next(1, answ.wait * 40 / 100); + answ.wait += noise - (answ.wait * 20 / 100); + } + } + } + return answ; + } + + /// + /// provo a chiamare split ODL /// private void trySplitOdl() { @@ -619,7 +494,144 @@ namespace IOB_WIN } } - #endregion Metodi specifici (da verificare/completare in implementazione) + #endregion Private Methods + + #region Public Methods + + /// + /// Recupera e processa allarmi CNC... + /// + public override Dictionary getCncAlarms() + { + Dictionary outVal = new Dictionary(); + return outVal; + } + + /// + /// Recupero dati dinamici... + /// + public override Dictionary getDynData() + { + // valore non presente in vers default... se gestito fare override + Dictionary outVal = new Dictionary(); + // verificare periodo SIM parametri... se passato li invio altrimenti NO... FIX a 20 sec + if (lastSimData.AddSeconds(waitSimPar) < DateTime.Now) + { + Random rnd = new Random(); + // controllo conf memorie json (se ci sono...) + try + { + if (memMap.mMapWrite.Count > 0) + { + foreach (var item in memMap.mMapWrite) + { + outVal.Add(item.Key, item.Value.value); + } + } + if (memMap.mMapRead.Count > 0) + { + foreach (var item in memMap.mMapRead) + { + // uso factor come valore MAX ammesso + int randVal = rnd.Next(item.Value.minVal, item.Value.maxVal); + outVal.Add(item.Key, randVal.ToString()); + } + } + } + catch + { } + lastSimData = DateTime.Now; + } + return outVal; + } + + /// + /// Recupero programma in lavorazione + /// + /// + public override string getPrgName() + { + // valore non presente in vers default... se gestito fare override + string prgName = string.Format("DEMO_{0:00}", DateTime.Now.Minute); + return prgName; + } + + /// + /// Recupero info sistema generiche + /// + public override Dictionary getSysInfo() + { + // valore non presente in vers default... se gestito fare override + Dictionary outVal = new Dictionary(); + outVal.Add("MACHINE", "IOB_SIM"); + return outVal; + } + + /// + /// Effettua vero processing contapezzi + /// + public override void processContapezzi() + { + } + + /// + /// Processo contatori eventi... + /// + public override void processVHF() + { + if (lastEvCheck.AddMilliseconds(periodoMSec) < DateTime.Now) + { + // decremento contatore ultimo evento + bit2.wait--; + bit3.wait--; + bit4.wait--; + bit5.wait--; + lastEvCheck = DateTime.Now; + } + } + + /// + /// Effettua lettura semafori principale + /// Parametri da aggiornare x display in form + /// + public override void readSemafori(ref newDisplayData currDispData) + { + base.readSemafori(ref currDispData); + // decodifica e gestione + decodeToBaseBitmap(); + decodeOtherData(); + reportRawInput(ref currDispData); + } + + /// + /// Effettua reset del contapezzi + /// + /// + public override bool resetcontapezziPLC() + { + bool answ = false; + // ...SE abilitato da conf IOB + if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE") + { + // fingo di aver fatto... + answ = true; + } + return answ; + } + + public override void tryConnect() + { + base.tryConnect(); + connectionOk = true; + } + + public override void tryDisconnect() + { + base.tryDisconnect(); + connectionOk = false; + } + + #endregion Public Methods } ///