From 0820991f195712c8a6ee2c54f07a3ac4b5f69cbb Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 22 Nov 2017 16:08:05 +0100 Subject: [PATCH] Accorpati metodi x gestione accodamento IN e FLog --- IOB-WIN/App.config | 5 +- IOB-WIN/IobFanuc.cs | 6 +- IOB-WIN/IobGeneric.cs | 302 +++++++++++++++++++++++++----------------- IOB-WIN/MainForm.cs | 10 +- Jenkinsfile | 2 +- 5 files changed, 194 insertions(+), 131 deletions(-) diff --git a/IOB-WIN/App.config b/IOB-WIN/App.config index 255f3049..20069db7 100644 --- a/IOB-WIN/App.config +++ b/IOB-WIN/App.config @@ -23,9 +23,10 @@ - + - + + diff --git a/IOB-WIN/IobFanuc.cs b/IOB-WIN/IobFanuc.cs index a5965197..cf02da4c 100644 --- a/IOB-WIN/IobFanuc.cs +++ b/IOB-WIN/IobFanuc.cs @@ -423,10 +423,14 @@ namespace IOB_WIN string descrMode = Enum.GetName(typeof(CNC_MODE), currMode); // accodo x invio string sVal = string.Format("[CNC_MODE]{0}", descrMode); + // chiamo accodamento... + accodaFLog(sVal, qEncodeFLog("CNC_MODE", descrMode)); +#if false displayOtherData(sVal); QueueFLog.Enqueue(qEncodeFLog("CNC_MODE", descrMode)); // log nuovo MODE - lg.Info("CNC_MODE: " + descrMode); + lg.Info("CNC_MODE: " + descrMode); +#endif } } catch (Exception exc) diff --git a/IOB-WIN/IobGeneric.cs b/IOB-WIN/IobGeneric.cs index 48685c03..415dfd73 100644 --- a/IOB-WIN/IobGeneric.cs +++ b/IOB-WIN/IobGeneric.cs @@ -46,6 +46,10 @@ namespace IOB_WIN /// public static Logger lg; /// + /// ULtimo valore inviato (in caso di disconnessione lo reinvia x garantire watchdog...) + /// + public string lastSignInVal = ""; + /// /// dataOra ultimo log periodico... /// public DateTime lastPeriodicLog; @@ -54,6 +58,10 @@ namespace IOB_WIN /// public DateTime lastWatchDog; /// + /// dataOra ultima verifica CNC disconnesso... + /// + public DateTime lastDisconnCheck; + /// /// dataOra ultimo PING inviato... /// public DateTime lastPING; @@ -343,6 +351,7 @@ namespace IOB_WIN dtAvvioAdp = DateTime.Now; lastWatchDog = dtAvvioAdp; lastPING = dtAvvioAdp; + lastDisconnCheck = dtAvvioAdp; TimingData.resetData(); // aggiungo altri defaults setDefaults(); @@ -1221,8 +1230,10 @@ namespace IOB_WIN // SE ho qualcosa in coda... if (QueueIN.Count > 0) { + // recupero ed aggiorno ULTIMO valore... + lastSignInVal = QueueIN.Dequeue(); // INVIO!!! - sendToMoonPro(urlType.SignIN, QueueIN.Dequeue()); + sendToMoonPro(urlType.SignIN, lastSignInVal); } } } @@ -1238,6 +1249,7 @@ namespace IOB_WIN parentForm.sOUT = Semaforo.SR; } } + //controllo se è passato oltre watchdog e non ho inviato nulla --> RE-INVIO (ultimo inviato)!!!! } /// /// Processo la coda FLog... @@ -1276,6 +1288,12 @@ namespace IOB_WIN parentForm.sOUT = Semaforo.SR; } } + // ...controllo se è passato oltre watchdog e non ho inviato nulla --> INVIO!!!! + if (DateTime.Now.Subtract(lastWatchDog).TotalSeconds > utils.CRI("watchdogMaxSec")) + { + // se ultimo valore è coerente... + if (lastSignInVal != "") sendToMoonPro(urlType.SignIN, lastSignInVal); + } } /// /// Classe fittizia in caso di processing GLOBALE di tutto in 1 solo colpo... @@ -1291,15 +1309,7 @@ namespace IOB_WIN // effettuo confronto valori vecchi/nuovi... SE trovo variazione if (B_output != B_previous) { - // mostro dati variati letti... - displayInData(); - // --> accodo (valore già formattato)! - QueueIN.Enqueue(qEncodeIN); - nReadFilt++; - // Gestione counter SignIn! - counterSigIN++; - // se supera 10k resetto... - if (counterSigIN > 9999) counterSigIN = 0; + accodaSigIN(); } } /// @@ -1310,20 +1320,11 @@ namespace IOB_WIN // sono disconensso... x prima cosa RESETTO A ZERO VALORI... RawInput = new byte[6]; // controllo contatore invio "keepalive"... invio solo a scadenza - if (DateTime.Now.Subtract(lastWatchDog).TotalSeconds > utils.CRI("watchdogMaxSec")) + if (DateTime.Now.Subtract(lastDisconnCheck).TotalSeconds > utils.CRI("disconMaxSec")) { - // accodo nuovo valore - // invio POWEROFF... è ZERO valore IN --> accodo (valore già formattato)! - QueueIN.Enqueue(qEncodeIN); - // aggiorno counters - nReadFilt++; - if (nReadFilt > int.MaxValue - 1) nReadFilt = 0; // per evitare buffer overflow... - counterSigIN++; - if (counterSigIN > 9999) counterSigIN = 0; // se supera 10k resetto... - // update display - displayInData(); - //// invio svuotando... - //svuotaCodaSignIN(); + accodaSigIN(); + // update controllo + lastDisconnCheck = DateTime.Now; } } /// @@ -1393,49 +1394,7 @@ namespace IOB_WIN } } } - /// - /// Fornisce il valore letto da BITMAP in formato valido x messa in coda nel formato dtEve#value#cont - /// - protected string qEncodeIN - { - get - { - string answ = ""; - try - { - answ = string.Format("{0:yyyyMMddHHmmssfff}#{1:X2}#{2}", DateTime.Now, (int)B_output, counterSigIN); - } - catch - { } - return answ; - } - } - /// - /// Fornisce il valore di flusso e valore in formato valido x messa in coda nel formato dtEve#flux#value#cont - /// - public string qEncodeFLog(string flusso, string valore) - { - string answ = ""; - try - { - answ = string.Format("{0:yyyyMMddHHmmssfff}#{1}#{2}#{3}", DateTime.Now, flusso, valore, counterFLog); - } - catch - { } - return answ; - } - /// - /// Decodifica valore della coda IN nel formato - /// answ[0]=dtEve - /// answ[1]=valore - /// answ[2]=counter - /// - /// dtEve + '#' + value + '#' + cont - /// - protected string[] qDecodeIN(string queueVal) - { - return queueVal.Split('#'); - } + /// /// Effettua lettura dati /// @@ -1483,13 +1442,18 @@ namespace IOB_WIN // salvo! lastPrgName = currPrgName; string sVal = string.Format("[PROG]{0}", currPrgName); + + // chiamo accodamento... + accodaFLog(sVal, qEncodeFLog("PROG", currPrgName)); +#if false displayOtherData(sVal); // --> accodo (valore già formattato)! QueueFLog.Enqueue(qEncodeFLog("PROG", currPrgName)); // Gestione counter FLog! counterFLog++; // se supera 10k resetto... - if (counterFLog > 9999) counterFLog = 0; + if (counterFLog > 9999) counterFLog = 0; +#endif } } @@ -1517,13 +1481,17 @@ namespace IOB_WIN foreach (var item in currSysInfo) { sVal = string.Format("[SYSINFO]{0}|{1}", item.Key, item.Value); + // chiamo accodamento... + accodaFLog(sVal, qEncodeFLog(item.Key, item.Value)); +#if false displayOtherData(sVal); // --> accodo (valore già formattato)! QueueFLog.Enqueue(qEncodeFLog(item.Key, item.Value)); // Gestione counter FLog! counterFLog++; // se supera 10k resetto... - if (counterFLog > 9999) counterFLog = 0; + if (counterFLog > 9999) counterFLog = 0; +#endif } } } @@ -1567,57 +1535,7 @@ namespace IOB_WIN public virtual void readSemafori() { } - /// - /// Effettua invio a MoonPro del valore richiesto - /// - /// - /// Valore da trasmettere: es - /// INPUT: lo status rilevato in HEX - /// FLog: il valore da trasmettere per il flusso indicato - public void sendToMoonPro(urlType tipoUrl, string queueVal) - { - // recupero e formatto URL dati da coda... - switch (tipoUrl) - { - case urlType.FLog: - lastUrl = urlFLog(queueVal); - break; - case urlType.SignIN: - lastUrl = urlInput(queueVal); - break; - default: - lastUrl = ""; - break; - } - // se NON sono in demo effettuo invio! - if (!DemoOut) - { - // chiamo URL! - string answ = callUrl(lastUrl); - // loggo! - lg.Info(string.Format("{0} -> {1}", queueVal, answ)); - // se "OK" verde, altrimenti errore --> ROSSO - if (answ == "OK") - { - parentForm.sOUT = Semaforo.SV; - } - else - { - parentForm.sOUT = Semaforo.SR; - } - } - else - { - parentForm.sOUT = Semaforo.SV; - // loggo! - lg.Info(string.Format("{0} -> [SIM]", queueVal)); - } - nSendOut++; - // riporto cosa inviato - displayOutData(); - // aggiorno data ultimo watchdog... - lastWatchDog = DateTime.Now; - } + /// /// Effettua processing contapezzi (ed eventualmente alza il bit di contapezzo...) /// @@ -1652,13 +1570,17 @@ namespace IOB_WIN foreach (var item in currDynData) { sVal = string.Format("[DYNDATA]{0}|{1}", item.Key, item.Value); + // chiamo accodamento... + accodaFLog(sVal, qEncodeFLog(item.Key, item.Value)); +#if false displayOtherData(sVal); // --> accodo (valore già formattato)! QueueFLog.Enqueue(qEncodeFLog(item.Key, item.Value)); // Gestione counter FLog! counterFLog++; // se supera 10k resetto... - if (counterFLog > 9999) counterFLog = 0; + if (counterFLog > 9999) counterFLog = 0; +#endif } } } @@ -1690,13 +1612,17 @@ namespace IOB_WIN foreach (var item in currOverride) { sVal = string.Format("[OVERRIDES]{0}|{1}", item.Key, item.Value); + // chiamo accodamento... + accodaFLog(sVal, qEncodeFLog(item.Key, item.Value)); +#if false displayOtherData(sVal); // --> accodo (valore già formattato)! QueueFLog.Enqueue(qEncodeFLog(item.Key, item.Value)); // Gestione counter FLog! counterFLog++; // se supera 10k resetto... - if (counterFLog > 9999) counterFLog = 0; + if (counterFLog > 9999) counterFLog = 0; +#endif } } } @@ -1716,7 +1642,139 @@ namespace IOB_WIN #endregion - #region gestione dataMonitor (accodamento valori) + #region gestione code (accumulo, invio) + + /// + /// Fornisce il valore letto da BITMAP in formato valido x messa in coda nel formato dtEve#value#cont + /// + protected string qEncodeIN + { + get + { + string answ = ""; + try + { + answ = string.Format("{0:yyyyMMddHHmmssfff}#{1:X2}#{2}", DateTime.Now, (int)B_output, counterSigIN); + } + catch + { } + return answ; + } + } + /// + /// Fornisce il valore di flusso e valore in formato valido x messa in coda nel formato dtEve#flux#value#cont + /// + public string qEncodeFLog(string flusso, string valore) + { + string answ = ""; + try + { + answ = string.Format("{0:yyyyMMddHHmmssfff}#{1}#{2}#{3}", DateTime.Now, flusso, valore, counterFLog); + } + catch + { } + return answ; + } + /// + /// Decodifica valore della coda IN nel formato + /// answ[0]=dtEve + /// answ[1]=valore + /// answ[2]=counter + /// + /// dtEve + '#' + value + '#' + cont + /// + protected string[] qDecodeIN(string queueVal) + { + return queueVal.Split('#'); + } + /// + /// Accumula in coda i valori Signal IN e logga... + /// + public void accodaSigIN() + { + // --> accodo (valore già formattato)! + QueueIN.Enqueue(qEncodeIN); + // loggo! + lg.Info(string.Format("[QUEUE-IN] {0}", qEncodeIN)); + // aggiorno counters ed eventuale reset + nReadFilt++; + if (nReadFilt > int.MaxValue - 1) nReadFilt = 0; // per evitare buffer overflow... + counterSigIN++; + if (counterSigIN > 9999) counterSigIN = 0; + // mostro dati variati letti... + displayInData(); + } + /// + /// Accumula in coda i valori Signal IN e logga... + /// + /// VALORE RAW (x display) + /// VALORE già processato con qEncodeFLog(...) + public void accodaFLog(string val, string encodedVal) + { + // mostro dati variati letti... + displayOtherData(val); + // --> accodo (valore già formattato)! + QueueFLog.Enqueue(encodedVal); + // loggo! + lg.Info(string.Format("[QUEUE-FLOG] {0}", encodedVal)); + counterFLog++; + if (counterFLog > 9999) counterFLog = 0; + } + /// + /// Effettua invio a MoonPro del valore richiesto + /// + /// + /// Valore da trasmettere: es + /// INPUT: lo status rilevato in HEX + /// FLog: il valore da trasmettere per il flusso indicato + public void sendToMoonPro(urlType tipoUrl, string queueVal) + { + // recupero e formatto URL dati da coda... + switch (tipoUrl) + { + case urlType.FLog: + lastUrl = urlFLog(queueVal); + break; + case urlType.SignIN: + lastUrl = urlInput(queueVal); + break; + default: + lastUrl = ""; + break; + } + // se NON sono in demo effettuo invio! + if (!DemoOut) + { + // chiamo URL! + string answ = callUrl(lastUrl); + // loggo! + lg.Info(string.Format("[SEND] {0} -> {1}", queueVal, answ)); + // se "OK" verde, altrimenti errore --> ROSSO + if (answ == "OK") + { + parentForm.sOUT = Semaforo.SV; + } + else + { + parentForm.sOUT = Semaforo.SR; + } + } + else + { + parentForm.sOUT = Semaforo.SV; + // loggo! + lg.Info(string.Format("{0} -> [SIM]", queueVal)); + } + nSendOut++; + // riporto cosa inviato + displayOutData(); + // aggiorno data ultimo watchdog... + lastWatchDog = DateTime.Now; + } + + #endregion + + #region gestione dataMonitor (update visualizzazione valori) /// /// Mostra i dati grezzi letti in esadecimale diff --git a/IOB-WIN/MainForm.cs b/IOB-WIN/MainForm.cs index cb21b2f2..2dea1962 100644 --- a/IOB-WIN/MainForm.cs +++ b/IOB-WIN/MainForm.cs @@ -171,15 +171,15 @@ namespace IOB_WIN #if DEBUG // Setup the logging view for Sentinel - http://sentinel.codeplex.com - var sentinalTarget = new NLogViewerTarget() + var sentinelTarget = new NLogViewerTarget() { - Name = "sentinal", + Name = "sentinel", Address = "udp://127.0.0.1:9999", IncludeNLogData = false }; - var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget); - LogManager.Configuration.AddTarget("sentinal", sentinalTarget); - LogManager.Configuration.LoggingRules.Add(sentinalRule); + var sentinelRule = new LoggingRule("*", LogLevel.Trace, sentinelTarget); + LogManager.Configuration.AddTarget("sentinel", sentinelTarget); + LogManager.Configuration.LoggingRules.Add(sentinelRule); #endif diff --git a/Jenkinsfile b/Jenkinsfile index 68e23d9c..d32856db 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=187']) { + withEnv(['NEXT_BUILD_NUMBER=188']) { // env.versionNumber = VersionNumber(versionNumberString : '1.15.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '1.15.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO-IOB-WIN'