1446 lines
42 KiB
C#
1446 lines
42 KiB
C#
using IOB_UT;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IOB_WIN
|
|
{
|
|
public class IobGeneric
|
|
{
|
|
#region variabili ed oggetti base
|
|
/// <summary>
|
|
/// Evento Iob ha subito un refresh
|
|
/// </summary>
|
|
public event EventHandler eh_refreshed;
|
|
/// <summary>
|
|
/// Determina se sia encessario convertire valori little/big endian (SIEMENS=true, OSAI=FALSE)
|
|
/// </summary>
|
|
public bool hasBigEndian = false;
|
|
/// <summary>
|
|
/// alias booleano false = R
|
|
/// </summary>
|
|
public bool R = false;
|
|
/// <summary>
|
|
/// alias booleano true = W
|
|
/// </summary>
|
|
public bool W = true;
|
|
/// <summary>
|
|
/// wrapper di log
|
|
/// </summary>
|
|
public static Logger lg;
|
|
/// <summary>
|
|
/// dataOra ultimo log periodico...
|
|
/// </summary>
|
|
public DateTime lastPeriodicLog;
|
|
/// <summary>
|
|
/// Oggetto della coda degli elementi letti (e non ancora trasmessi)
|
|
/// </summary>
|
|
public Queue<string> QueueIN = new Queue<string>();
|
|
/// <summary>
|
|
/// Oggetto della coda degli elementi letti di tipo FluxLog (e non ancora trasmessi)
|
|
/// </summary>
|
|
public Queue<string> QueueFLog = new Queue<string>();
|
|
/// <summary>
|
|
/// Coda valori simulazione deterministica...
|
|
/// </summary>
|
|
public Queue<int> QueueSIM = new Queue<int>();
|
|
/// <summary>
|
|
/// Coda valori letti x DEBUG...
|
|
/// </summary>
|
|
public Queue<int> QueueDebug = new Queue<int>();
|
|
|
|
/// <summary>
|
|
/// valore booleano di check se sia in fase di COMUNICAZIONE ATTIVA con il PLC/NC
|
|
/// </summary>
|
|
protected bool adpCommAct;
|
|
/// <summary>
|
|
/// valore booleano di check se sia stato AVVIATO l'adapter (Running)
|
|
/// </summary>
|
|
public bool adpRunning = false;
|
|
/// <summary>
|
|
/// valore booleano di check se l'adapter STIA SALVANDO
|
|
/// </summary>
|
|
public bool adpSaving = false;
|
|
/// <summary>
|
|
/// valore booleano (richiesta di riavvio automatico)
|
|
/// </summary>
|
|
public bool adpTryRestart;
|
|
/// <summary>
|
|
/// Ultimo valore watchdog rilevato
|
|
/// </summary>
|
|
public bool lastWatchDog = false;
|
|
/// <summary>
|
|
/// Verifica se sia in modalità DEMO x dati INPUT
|
|
/// </summary>
|
|
public bool DemoIn
|
|
{
|
|
get
|
|
{
|
|
return IOB_UT.baseUtils.CRB("DemoIn");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Verifica se sia in modalità DEMO avanzata (campionamento da set di valori ammessi...)
|
|
/// </summary>
|
|
public bool DemoInSample
|
|
{
|
|
get
|
|
{
|
|
return IOB_UT.baseUtils.CRB("DemoInSample");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Numero simulazioni ammesse...
|
|
/// </summary>
|
|
protected int numSim { get; set; }
|
|
/// <summary>
|
|
/// Numero letture IN da avvio
|
|
/// </summary>
|
|
protected int nReadIN { get; set; }
|
|
/// <summary>
|
|
/// Numero letture IN da avvio
|
|
/// </summary>
|
|
protected int nReadFilt { get; set; }
|
|
/// <summary>
|
|
/// Numero invii OUT (svuotamento coda)
|
|
/// </summary>
|
|
protected int nSendOut { get; set; }
|
|
/// <summary>
|
|
/// Verifica se sia in modalità DEMO x dati OUTPUT
|
|
/// </summary>
|
|
public bool DemoOut
|
|
{
|
|
get
|
|
{
|
|
return utils.CRB("DemoOut");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Contatore x invio dati SignalIN
|
|
/// </summary>
|
|
public int counterSigIN { get; set; }
|
|
/// <summary>
|
|
/// Contatore x invio dati FluxLog
|
|
/// </summary>
|
|
public int counterFLog { get; set; }
|
|
/// <summary>
|
|
/// Ultimo URL
|
|
/// </summary>
|
|
public string lastUrl { get; set; }
|
|
/// <summary>
|
|
/// Ultimo programma letto
|
|
/// </summary>
|
|
public string lastPrgName { get; set; }
|
|
/// <summary>
|
|
/// Ultimo sysinfo letto
|
|
/// </summary>
|
|
public string lastSysInfo { get; set; }
|
|
|
|
/// <summary>
|
|
/// Array dei contatori x segnali blinking
|
|
/// </summary>
|
|
protected int[] i_counters;
|
|
/// <summary>
|
|
/// Vettore 16 BIT valori precedenti
|
|
/// </summary>
|
|
protected int B_previous;
|
|
/// <summary>
|
|
/// Vettore 16 BIT valori in ingresso al filtro
|
|
/// </summary>
|
|
protected int B_input;
|
|
/// <summary>
|
|
/// Vettore 16 BIT valori in uscita dal filtro
|
|
/// </summary>
|
|
protected int B_output;
|
|
/// <summary>
|
|
/// 16 byte di strobe (4 word da 32 bit di flags...)
|
|
/// </summary>
|
|
public byte[] RawInput = new byte[4];
|
|
|
|
/// <summary>
|
|
/// Verifica SE si debba fare log verboso (verboso + ogni tot letture IN)
|
|
/// </summary>
|
|
public bool verboseLog
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
int logEvery = utils.CRI("logEvery");
|
|
if (logEvery < 1) logEvery = 10;
|
|
answ = utils.CRB("verbose") && (nReadIN % logEvery == 0);
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Verifica SE si debba fare log periodico (ogni "verboseLogTOut" sec...)
|
|
/// </summary>
|
|
public bool periodicLog
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
answ = (DateTime.Now.Subtract(lastPeriodicLog).TotalSeconds > utils.CRI("verboseLogTOut"));
|
|
if (answ) lastPeriodicLog = DateTime.Now;
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determina se utilizzare blocchi di memoria IOT contigui (e quindi processing "monoblocco" semplificato"=
|
|
/// </summary>
|
|
public bool procIotMem = false;
|
|
/// <summary>
|
|
/// porta x adapter (x restart)
|
|
/// </summary>
|
|
protected int adpPortNum;
|
|
/// <summary>
|
|
/// DataOra ultimo avvio adapter x watchdog
|
|
/// </summary>
|
|
protected DateTime adpStartRun;
|
|
/// <summary>
|
|
/// Data/ora ultimo avvio adapter
|
|
/// </summary>
|
|
public DateTime dtAvvioAdp = DateTime.Now;
|
|
/// <summary>
|
|
/// Data/ora ultimo spegnimento adapter
|
|
/// </summary>
|
|
public DateTime dtStopAdp = DateTime.Now;
|
|
/// <summary>
|
|
/// vettore gestione cronometraggi
|
|
/// </summary>
|
|
public DateTime inizio;
|
|
/// <summary>
|
|
/// Conteggio ATTUALE ore macchina ON
|
|
/// </summary>
|
|
public double contOreMaccOn;
|
|
/// <summary>
|
|
/// Conteggio ATTUALE ore macchina IN LAVORO
|
|
/// </summary>
|
|
public double contOreMaccLav;
|
|
/// <summary>
|
|
/// stato Online/Offline della IOB
|
|
/// </summary>
|
|
public bool IobOnline;
|
|
/// <summary>
|
|
/// stato Online/Offline della IOB
|
|
/// </summary>
|
|
public bool MPOnline;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Form chiamante
|
|
/// </summary>
|
|
protected MainForm parentForm;
|
|
/// <summary>
|
|
/// Conf adapter corrente
|
|
/// </summary>
|
|
public IobConfiguration currIobConf;
|
|
|
|
|
|
/// <summary>
|
|
/// inizializzo l'oggetto sulla form SULLA BASE DEL FILE DI CONFIGURAZIONE letto
|
|
/// </summary>
|
|
/// <param name="caller"></param>
|
|
/// <param name="adpConf"></param>
|
|
public IobGeneric(MainForm caller, IobConfiguration IOBConf)
|
|
{
|
|
lg = LogManager.GetCurrentClassLogger();
|
|
lg.Info("Avvio preliminare AdapterGeneric");
|
|
|
|
// configurazione...
|
|
currIobConf = IOBConf;
|
|
// aggiungo altri defaults
|
|
setDefaults();
|
|
// salvo il form chiamante
|
|
parentForm = caller;
|
|
|
|
// concluso!
|
|
lg.Info("Istanziata classe preliminare IOBGeneric");
|
|
}
|
|
/// <summary>
|
|
/// Imposto alcuni valori di default
|
|
/// </summary>
|
|
private void setDefaults()
|
|
{
|
|
numSim = utils.CRI("numSim");
|
|
lastPrgName = "";
|
|
nReadIN = 0;
|
|
nReadFilt = 0;
|
|
nSendOut = 0;
|
|
// svuoto code... SE NON SIM...
|
|
if (!DemoIn)
|
|
{
|
|
QueueIN.Clear();
|
|
QueueFLog.Clear();
|
|
QueueSIM.Clear();
|
|
}
|
|
// imposto contatori blink a zero...
|
|
i_counters = new int[32];
|
|
lastPeriodicLog = DateTime.Now;
|
|
}
|
|
|
|
|
|
#region metodi adapter
|
|
|
|
|
|
/// <summary>
|
|
/// lettura file di persistenza
|
|
/// </summary>
|
|
public void loadPersData()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Avvia l'adapter sulla porta richiesta
|
|
/// </summary>
|
|
/// <param name="port"></param>
|
|
public virtual void startAdapter(int port)
|
|
{
|
|
lg.Info("Starting adapter...");
|
|
parentForm.commPlcActive = false;
|
|
adpRunning = true;
|
|
dtAvvioAdp = DateTime.Now;
|
|
TimingData.resetData();
|
|
// aggiungo altri defaults
|
|
setDefaults();
|
|
adpTryRestart = true;
|
|
parentForm.displayTaskAndLog("Adapter Started!");
|
|
}
|
|
|
|
/// <summary>
|
|
/// ferma l'adapter...
|
|
/// </summary>
|
|
/// <param name="tryRestart">indica se si debba tentare di riavviare l'adapter (con caduta connessione viene fermato in automatico)</param>
|
|
public void stopAdapter(bool tryRestart)
|
|
{
|
|
// svuoto le code dei valori letti e non ancora trasmessi...
|
|
parentForm.displayTaskAndLog("Svuotamento FORZATO coda segnali...");
|
|
while (QueueIN.Count > 0)
|
|
{
|
|
// INVIO SE PERMESSO...!!!
|
|
sendToMoonPro(urlType.SignIN, QueueIN.Dequeue());
|
|
}
|
|
parentForm.displayTaskAndLog("Svuotamento FORZATO coda FluxLOG...");
|
|
while (QueueFLog.Count > 0)
|
|
{
|
|
// INVIO SE PERMESSO...!!!
|
|
sendToMoonPro(urlType.FLog, QueueFLog.Dequeue());
|
|
}
|
|
//reportDataProc();
|
|
|
|
parentForm.displayTaskAndLog("Stopping adapter...");
|
|
adpTryRestart = false;
|
|
|
|
parentForm.displayTaskAndLog("Stopping adapter - last periodic data read...");
|
|
|
|
// chiudo la connessione all'adapter...
|
|
tryDisconnect();
|
|
dtStopAdp = DateTime.Now;
|
|
adpTryRestart = tryRestart;
|
|
adpRunning = false;
|
|
// chiudo!
|
|
parentForm.resetProgBar();
|
|
parentForm.displayTaskAndLog("Adapter Stopped.");
|
|
parentForm.commPlcActive = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// effettua recupero dati ed invio valori modificati...
|
|
/// </summary>
|
|
/// <param name="ciclo"></param>
|
|
public void getAndSend(gatherCycle ciclo)
|
|
{
|
|
// controllo connessione/connettività
|
|
if (connectionOk)
|
|
{
|
|
// controllo non sia già in esecuzione...
|
|
if (!adpCommAct)
|
|
{
|
|
// provo ad avviare
|
|
try
|
|
{
|
|
// imposto flag adapter running..
|
|
adpCommAct = true;
|
|
adpStartRun = DateTime.Now;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
parentForm.displayTaskAndLog(string.Format("Adapter NOT STARTED!!!{0}{1}", Environment.NewLine, exc));
|
|
adpCommAct = false;
|
|
adpStartRun = DateTime.Now;
|
|
}
|
|
if (adpCommAct)
|
|
{
|
|
// try / catch generale altrimenti segno che è disconnesso...
|
|
try
|
|
{
|
|
bool showDebugData = false;
|
|
// processing dati memoria (lettura, filtraggio, enqueque)
|
|
if (ciclo == gatherCycle.VHF)
|
|
{
|
|
}
|
|
else if (ciclo == gatherCycle.HF)
|
|
{
|
|
processAllMemory();
|
|
}
|
|
else if (ciclo == gatherCycle.MF)
|
|
{
|
|
processProgram();
|
|
}
|
|
else if (ciclo == gatherCycle.LF)
|
|
{
|
|
}
|
|
else if (ciclo == gatherCycle.VLF)
|
|
{
|
|
// recupero dati SETUP (sysinfo) e li invio/mostro se variati...
|
|
processSysInfo();
|
|
// eventuale log!
|
|
if (utils.CRB("recTime")) logTimeResults();
|
|
}
|
|
// gestione queue SignalIN (invio, display)
|
|
svuotaCodaSignIN();
|
|
// gestione queue FluxLog (invio, display)
|
|
svuotaCodaFLog();
|
|
// mostra eventuali altri dati di processo...
|
|
reportDataProc();
|
|
if (showDebugData)
|
|
{
|
|
// verifica se debba salvare e mostrare dati
|
|
checkSavePersDataLayer();
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
// segnalo eccezione e indico disconnesso...
|
|
lg.Error(exc, string.Format("Errore in gestione ciclo principale ADP, fermo adapter{0}{1}", Environment.NewLine, exc));
|
|
parentForm.fermaAdapter(true);
|
|
}
|
|
// tolgo flag running
|
|
adpCommAct = false;
|
|
}
|
|
else
|
|
{
|
|
if (periodicLog) lg.Info("ADP not running...");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// log ADP running
|
|
lg.Error("Non eseguo chiamata: ADP ancora in running");
|
|
// se è bloccato da oltre maxSec lo sblocco...
|
|
if (DateTime.Now.Subtract(adpStartRun).TotalSeconds > utils.CRI("maxAdapterLockSec"))
|
|
{
|
|
// tolgo flag running
|
|
adpCommAct = false;
|
|
adpStartRun = DateTime.Now;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// log connessione KO
|
|
lg.Error("getAndSend - Connessione non disponibile, provo a riconnettere");
|
|
// provo a riconnettere SE abilitato tryRestart...
|
|
if (adpTryRestart && !connectionOk)
|
|
{
|
|
lg.Info("ConnKO - tryConnect");
|
|
tryConnect();
|
|
}
|
|
}
|
|
if (eh_refreshed != null)
|
|
{
|
|
eh_refreshed(this, new EventArgs());
|
|
}
|
|
}
|
|
|
|
private void reportDataProc()
|
|
{
|
|
// update valori visualizzazione...
|
|
parentForm.dataProcLabel = string.Format("RAW: {0} --> IN: {1} --> OUT: {2}", nReadIN, nReadFilt, nSendOut);
|
|
}
|
|
|
|
/// <summary>
|
|
/// riporta il log di tutti i dati di results temporali registrati
|
|
/// </summary>
|
|
public void logTimeResults()
|
|
{
|
|
if (TimingData.results.Count > 0)
|
|
{
|
|
lg.Info("{0}--------------- START TIMING DATA ---------------", Environment.NewLine);
|
|
int globNumCall = 0;
|
|
TimeSpan globAvgMsec = new TimeSpan(0);
|
|
foreach (TimeRec item in TimingData.results)
|
|
{
|
|
lg.Info("Chiamate {0}: effettuate {1}, tempo medio {2:N2} msec | impegno canale {3:P3}", item.codCall, item.numCall, item.avgMsec, item.totMsec.TotalSeconds / DateTime.Now.Subtract(dtAvvioAdp).TotalSeconds);
|
|
globNumCall += item.numCall;
|
|
globAvgMsec += item.totMsec;
|
|
}
|
|
// riporto conteggio medio al secondo...
|
|
lg.Info("Chiamate GLOBALI: {0}, periodo: {1:N2} minuti.cent, tempo medio {2:N2} msec | impegno canale {3:P3}", globNumCall, DateTime.Now.Subtract(dtAvvioAdp).TotalMinutes, globAvgMsec.TotalMilliseconds / globNumCall, globAvgMsec.TotalSeconds / DateTime.Now.Subtract(dtAvvioAdp).TotalSeconds);
|
|
lg.Info("{0}--------------- STOP TIMING DATA ---------------{0}", Environment.NewLine);
|
|
// mostro in form statistiche globali!
|
|
parentForm.updateComStats(string.Format("Periodo: {0:N2}min | {1} x {2:N2}ms | canale {3:P3}", DateTime.Now.Subtract(dtAvvioAdp).TotalMinutes, globNumCall, globAvgMsec.TotalMilliseconds / globNumCall, globAvgMsec.TotalSeconds / DateTime.Now.Subtract(dtAvvioAdp).TotalSeconds));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// processa dataLayer e se necessario salva/mostra
|
|
/// </summary>
|
|
public void checkSavePersDataLayer()
|
|
{
|
|
}
|
|
public void resetDebugConsole()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo base connessione...
|
|
/// </summary>
|
|
public virtual void tryConnect()
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// Metodo base disconnessione...
|
|
/// </summary>
|
|
public virtual void tryDisconnect()
|
|
{
|
|
|
|
}
|
|
protected bool _connOk = false;
|
|
/// <summary>
|
|
/// Salva verifica stato connessione OK
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual bool connectionOk
|
|
{
|
|
get
|
|
{
|
|
return _connOk || DemoIn;
|
|
}
|
|
set
|
|
{
|
|
_connOk = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region layer persistenza dati
|
|
|
|
/// <summary>
|
|
/// Dizionario di persistenza per i valori da salvare da/su file
|
|
/// </summary>
|
|
public Dictionary<string, string> persistenceLayer;
|
|
|
|
/// <summary>
|
|
/// recupera valore salvato in persistence layer (se non c'è crea...)
|
|
/// </summary>
|
|
/// <param name="keyVal"></param>
|
|
/// <returns></returns>
|
|
private string getStoredVal(string keyVal)
|
|
{
|
|
string value = "";
|
|
try
|
|
{
|
|
if (persistenceLayer != null)
|
|
{
|
|
if (!persistenceLayer.TryGetValue(keyVal, out value))
|
|
{
|
|
persistenceLayer.Add(keyVal, "0");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lg.Error(string.Format("Eccezione in getStoredVal: {0}{1}", Environment.NewLine, exc));
|
|
}
|
|
return value;
|
|
}
|
|
/// <summary>
|
|
/// recupera valore salvato in persistence layer (se non c'è crea...) come UINT
|
|
/// </summary>
|
|
/// <param name="keyVal"></param>
|
|
/// <returns></returns>
|
|
private uint getStoredValUInt(string keyVal)
|
|
{
|
|
uint answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToUInt32(getStoredVal(keyVal));
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lg.Error(string.Format("Eccezione in getStoredValUInt: {0}{1}", Environment.NewLine, exc));
|
|
}
|
|
// verifico che il valore sia minore di 9/10 del valore massimo...
|
|
answ = (answ < (uint.MaxValue / 10 * 9)) ? answ : 0;
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// recupera valore salvato in persistence layer (se non c'è crea...) come INT
|
|
/// </summary>
|
|
/// <param name="keyVal"></param>
|
|
/// <returns></returns>
|
|
private long getStoredValLong(string keyVal)
|
|
{
|
|
long answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt64(getStoredVal(keyVal));
|
|
}
|
|
catch
|
|
{ }
|
|
// verifico che il valore sia minore di 9/10 del valore massimo...
|
|
answ = (answ < (long.MaxValue / 10 * 9)) ? answ : 0;
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// recupera valore salvato in persistence layer (se non c'è crea...) come double
|
|
/// </summary>
|
|
/// <param name="keyVal"></param>
|
|
/// <returns></returns>
|
|
private double getStoredValDouble(string keyVal)
|
|
{
|
|
double answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToDouble(getStoredVal(keyVal));
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lg.Error(string.Format("Eccezione in getStoredValDouble: {0}{1}", Environment.NewLine, exc));
|
|
}
|
|
answ = (answ < (double.MaxValue / 10 * 9)) ? answ : 0;
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in SOSTITUZIONE
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="newVal"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private void updateValString(int i, string newVal, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = newVal;
|
|
}
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in SOSTITUZIONE e lo restituisce
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="newVal"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private void updateValUInt(int i, uint newVal, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = newVal.ToString();
|
|
}
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in INCREMENTO e lo restituisce
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="delta"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private uint updateValUIntByIncr(int i, uint delta, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// recupero valore precedente...
|
|
uint contAct = getStoredValUInt(keyVal);
|
|
// nuovo valore...
|
|
contAct += delta;
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = contAct.ToString();
|
|
// rendo il valore!
|
|
return contAct;
|
|
}
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in INCREMENTO e lo restituisce
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="delta"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private long updateValLongByIncr(int i, long delta, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// recupero valore precedente...
|
|
long contAct = getStoredValLong(keyVal);
|
|
// nuovo valore...
|
|
contAct += delta;
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = contAct.ToString();
|
|
// rendo il valore!
|
|
return contAct;
|
|
}
|
|
/// <summary>
|
|
/// Aggiorna un valore del dizionario in INCREMENTO e lo restituisce
|
|
/// </summary>
|
|
/// <param name="i"></param>
|
|
/// <param name="delta"></param>
|
|
/// <param name="searchString"></param>
|
|
/// <returns>Nuovo valore incrementato</returns>
|
|
private double updateValDoubleByIncr(int i, double delta, string searchString)
|
|
{
|
|
// stringa da cercare..
|
|
string keyVal = string.Format(searchString, i + 1);
|
|
// recupero valore precedente...
|
|
double contAct = getStoredValDouble(keyVal);
|
|
// nuovo valore...
|
|
contAct += delta;
|
|
// salvo in ram!
|
|
persistenceLayer[keyVal] = contAct.ToString();
|
|
// rendo il valore!
|
|
return contAct;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// effettua ogni log period una rilettura di TUTTI gli allarmi...
|
|
/// </summary>
|
|
public virtual void forceAlarmCheck()
|
|
{
|
|
}
|
|
|
|
#region area simulazione
|
|
|
|
/// <summary>
|
|
/// lettura memoria in SIMULAZIONE
|
|
/// </summary>
|
|
public void simReadMem()
|
|
{
|
|
if (lastSim == null)
|
|
{
|
|
lastSim = DateTime.Now;
|
|
}
|
|
// simulazione complessa (basata su samples dei parametri effettivi...)
|
|
if (utils.CRB("DemoInSample"))
|
|
{
|
|
if (numSim >= 0)
|
|
{
|
|
// verifico se la coda di simulazione sia piena altrimenti la RICARICO...
|
|
if (QueueSIM.Count == 0)
|
|
{
|
|
leggiSimFile();
|
|
numSim--;
|
|
}
|
|
// processo la coda di simulazione (stacco ed accodo 1 valore...)
|
|
B_input = QueueSIM.Dequeue();
|
|
countSim++;
|
|
// ogni 5 loggo...
|
|
if (countSim % 5 == 0)
|
|
{
|
|
lg.Info("Read {0} sim data", countSim);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// fermo tutto!
|
|
parentForm.sIN = Semaforo.SR;
|
|
parentForm.fermaAdapter(false);
|
|
}
|
|
}
|
|
// simulazione semplice (counter crescente)
|
|
else
|
|
{
|
|
// se passato 1 sec genero NUOV num casuale e lo metto nel bit strobe... ogni 2 sec...
|
|
if (DateTime.Now.Subtract(lastSim).TotalMilliseconds > 100)
|
|
{
|
|
countSim++;
|
|
if (countSim > 255) countSim = 0;
|
|
B_input = countSim;
|
|
}
|
|
}
|
|
lastSim = DateTime.Now;
|
|
}
|
|
/// <summary>
|
|
/// legge ed accoda file Sim in QueueSIM
|
|
/// </summary>
|
|
private void leggiSimFile()
|
|
{
|
|
int totRighe = 0;
|
|
string fileName = utils.simDataFile;
|
|
string linea;
|
|
totRighe = File.ReadLines(fileName).Count();
|
|
lg.Info("File SIM: TROVATE {0} righe", totRighe);
|
|
// ora conto righe effettive...
|
|
totRighe = 0;
|
|
// carica da file...
|
|
StreamReader file = new StreamReader(fileName);
|
|
// leggo 1 linea alla volta...
|
|
int valore = 0;
|
|
while ((linea = file.ReadLine()) != null)
|
|
{
|
|
// SE non è un commento...
|
|
if (linea.Substring(0, 1) != ";")
|
|
{
|
|
//elencoAllarmi[rumRiga] = decodeAlarmLine(linea, ':');
|
|
Int32.TryParse(linea, out valore);
|
|
QueueSIM.Enqueue(valore);
|
|
totRighe++;
|
|
}
|
|
}
|
|
// chiudo file
|
|
file.Close();
|
|
lg.Info("File SIM: LETTE {0} righe", totRighe);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IOB METHODS
|
|
|
|
/// <summary>
|
|
/// Valore del num max invii consecutivi da coda...
|
|
/// </summary>
|
|
protected int nMaxSend = 5;
|
|
/// <summary>
|
|
/// DateTime Ultimo valore simulazione generato
|
|
/// </summary>
|
|
public DateTime lastSim;
|
|
/// <summary>
|
|
/// contatore x simulazione valori input
|
|
/// </summary>
|
|
public int countSim = 0;
|
|
/// <summary>
|
|
/// URL per check alive...
|
|
/// </summary>
|
|
public string urlAlive
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}{1}{2}", currIobConf.serverData.MPIP, currIobConf.serverData.MPURL, currIobConf.serverData.CMDALIVE);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// URL per check alive...
|
|
/// </summary>
|
|
public string urlIobEnabled
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}{1}{2}{3}", currIobConf.serverData.MPIP, currIobConf.serverData.MPURL, currIobConf.serverData.CMDENABLED, currIobConf.codIOB);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Fornisce URL INPUT per i parametri richiesti
|
|
/// </summary>
|
|
/// <param name="queueVal">valore salvato in coda formato dtEve#valore#counter</param>
|
|
/// <returns></returns>
|
|
public string urlInput(string queueVal)
|
|
{
|
|
// URL base x input
|
|
string answ = string.Format(@"{0}{1}{2}", currIobConf.serverData.MPIP, currIobConf.serverData.MPURL, currIobConf.serverData.CMDBASE);
|
|
// decodifica valore!
|
|
string[] valori = qDecodeIN(queueVal);
|
|
// aggiungo macchina e valore...
|
|
answ += string.Format(@"{0}?valore={1}", currIobConf.codIOB, valori[1]);
|
|
// aggiondo dataOra evento e corrente + contatore...
|
|
answ += string.Format(@"&&dtEve={0}&&dtCurr={1:yyyyMMddHHmmssfff}&&cnt={2}", valori[0], DateTime.Now, valori[2]);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Fornisce URL di tipo FluxLog
|
|
/// </summary>
|
|
/// <param name="queueVal">valore salvato in coda nel formato dtEve#flux#valore#counter</param>
|
|
/// <returns></returns>
|
|
public string urlFLog(string queueVal)
|
|
{
|
|
// URL base x input
|
|
string answ = string.Format(@"{0}{1}{2}", currIobConf.serverData.MPIP, currIobConf.serverData.MPURL, currIobConf.serverData.CMDFLOG);
|
|
// decodifica valore!
|
|
string[] valori = qDecodeIN(queueVal);
|
|
// aggiungo macchina e valore...
|
|
answ += string.Format(@"{0}?flux={1}&valore={2}", currIobConf.codIOB, valori[1], valori[2]);
|
|
// aggiondo dataOra evento e corrente + contatore...
|
|
answ += string.Format(@"&&dtEve={0}&&dtCurr={1:yyyyMMddHHmmssfff}&&cnt={2}", valori[0], DateTime.Now, valori[3]);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Effettua chaimata URL e restituisce risultato
|
|
/// </summary>
|
|
/// <param name="URL"></param>
|
|
/// <returns></returns>
|
|
public string callUrl(string URL)
|
|
{
|
|
string answ = "";
|
|
var client = new WebClient();
|
|
answ = client.DownloadString(URL);
|
|
// restituisco valore!
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Verifica se il server sia ALIVE
|
|
/// </summary>
|
|
private bool checkServerAlive
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
if (DemoOut)
|
|
{
|
|
answ = true;
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
// chiamo URL, se restituisce "OK" è alive!
|
|
answ = (callUrl(urlAlive) == "OK");
|
|
}
|
|
catch
|
|
{ }
|
|
// verifico SE è variato stato online/offline...
|
|
if (MPOnline != answ)
|
|
{
|
|
// se ORA sono online riporto...
|
|
if (answ)
|
|
{
|
|
lg.Info("SERVER ONLINE");
|
|
}
|
|
else
|
|
{
|
|
lg.Info("SERVER OFFLINE");
|
|
}
|
|
// salvo nuovo status...
|
|
MPOnline = answ;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Verifica se la IOB sia ENABLED (da server o Demo)
|
|
/// </summary>
|
|
private bool checkIobEnabled
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
if (DemoOut)
|
|
{
|
|
answ = (QueueIN.Count + QueueFLog.Count >= nMaxSend);
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
// chiamo URL, se restituisce "OK" è enabled!
|
|
answ = (callUrl(urlIobEnabled) == "OK");
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
// verifico SE è variato stato online/offline...
|
|
if (IobOnline != answ)
|
|
{
|
|
// se ORA sono online riporto...
|
|
if (answ)
|
|
{
|
|
lg.Info("IOB ONLINE");
|
|
}
|
|
else
|
|
{
|
|
lg.Info("IOB OFFLINE");
|
|
}
|
|
// salvo nuovo status...
|
|
IobOnline = answ;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Processo la coda SignalIN...
|
|
/// </summary>
|
|
private void svuotaCodaSignIN()
|
|
{
|
|
// verifico SE la coda abbia dei valori...
|
|
if (QueueIN.Count > 0)
|
|
{
|
|
// verifico se risponde il server...
|
|
if (checkServerAlive)
|
|
{
|
|
// verifico SE posso inviare dati
|
|
if (checkIobEnabled)
|
|
{
|
|
// invio pacchetto di dati (max da conf)
|
|
for (int i = 0; i < nMaxSend; i++)
|
|
{
|
|
// SE ho qualcosa in coda...
|
|
if (QueueIN.Count > 0)
|
|
{
|
|
// INVIO!!!
|
|
sendToMoonPro(urlType.SignIN, QueueIN.Dequeue());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// mostro VETO-SEND x invio... GIALLO
|
|
parentForm.sOUT = Semaforo.SG;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// mostro SERVER KO x invio... ROSSO
|
|
parentForm.sOUT = Semaforo.SR;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Processo la coda FLog...
|
|
/// </summary>
|
|
private void svuotaCodaFLog()
|
|
{
|
|
// verifico SE la coda abbia dei valori...
|
|
if (QueueFLog.Count > 0)
|
|
{
|
|
// verifico se risponde il server...
|
|
if (checkServerAlive)
|
|
{
|
|
// verifico SE posso inviare dati
|
|
if (checkIobEnabled)
|
|
{
|
|
// invio pacchetto di dati (max da conf)
|
|
for (int i = 0; i < nMaxSend; i++)
|
|
{
|
|
// SE ho qualcosa in coda...
|
|
if (QueueFLog.Count > 0)
|
|
{
|
|
// INVIO!!!
|
|
sendToMoonPro(urlType.FLog, QueueFLog.Dequeue());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// mostro VETO-SEND x invio... GIALLO
|
|
parentForm.sOUT = Semaforo.SG;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// mostro SERVER KO x invio... ROSSO
|
|
parentForm.sOUT = Semaforo.SR;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Classe fittizia in caso di processing GLOBALE di tutto in 1 solo colpo...
|
|
/// </summary>
|
|
private void processAllMemory()
|
|
{
|
|
// in primis SALVO valori previous/precedenti
|
|
B_previous = B_output;
|
|
// poi faccio lettura NUOVI valori
|
|
readAllData();
|
|
// eseguo il filtering dei valori (per i bit "blinking")
|
|
filterData();
|
|
// 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;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Esegue filtraggio dati x bit blinking!!!
|
|
/// </summary>
|
|
private void filterData()
|
|
{
|
|
// effettuo filtraggio dei valori letti... inizializzo OUT!
|
|
B_output = 0;
|
|
// in primis verifico SE ci siano bit blinkng... se non ci sono OUT=IN...
|
|
if (currIobConf.BLINK_FILT == 0)
|
|
{
|
|
B_output = B_input;
|
|
}
|
|
else
|
|
{
|
|
// incomincio con i valori NON blinking: questi "passano invariati", inizio a sommare nel valore OUT...
|
|
B_output = B_input & ~currIobConf.BLINK_FILT;
|
|
// calcolo il valore dei BIT che "passano la maschera"
|
|
int iBlink = B_input & currIobConf.BLINK_FILT;
|
|
// ...aggiungo i "bit che passano"
|
|
B_output += iBlink;
|
|
|
|
// calcolo QUALI valori (tra quelli blink) siano PASSATI da 0 a 1 --> init counters...
|
|
BitArray bBlinkStart = new BitArray(new byte[] { Convert.ToByte(iBlink) });
|
|
int[] bitsUp = bBlinkStart.Cast<bool>().Select(bit => bit ? 1 : 0).ToArray();
|
|
for (int i = 0; i < bitsUp.Length; i++)
|
|
{
|
|
// SE 1... impostiamo contatori al MAX
|
|
if (bitsUp[i] == 1)
|
|
{
|
|
// se era zero indico START blink...
|
|
if (i_counters[i] == 0)
|
|
{
|
|
lg.Info("START BLINK: B{0}", i);
|
|
}
|
|
// imposto comunque contatore al cambio fronte...
|
|
i_counters[i] = currIobConf.MAX_COUNTER_BLINK;
|
|
}
|
|
}
|
|
|
|
// quelli che sono zero... LI RECUPERO E LI PROCESSO...
|
|
int iZero = ~B_input & currIobConf.BLINK_FILT;
|
|
BitArray bBlinkEnd = new BitArray(new byte[] { Convert.ToByte(iZero) });
|
|
int[] bitsDown = bBlinkEnd.Cast<bool>().Select(bit => bit ? 1 : 0).ToArray();
|
|
for (int i = 0; i < bitsDown.Length; i++)
|
|
{
|
|
// se era a zero (invertito...)
|
|
if (bitsDown[i] == 1)
|
|
{
|
|
// SE è in corso il conteggio...
|
|
if (i_counters[i] > 0)
|
|
{
|
|
// decremento!
|
|
i_counters[i] -= 1;
|
|
// se è zero NON faccio nulla, altrimenti SOMMO...
|
|
if (i_counters[i] > 0)
|
|
{
|
|
B_output += 1 << i;
|
|
}
|
|
else
|
|
{
|
|
lg.Info("END BLINK: B{0}", i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Fornisce il valore letto da BITMAP in formato valido x messa in coda nel formato dtEve#value#cont
|
|
/// </summary>
|
|
protected string qEncodeIN
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
try
|
|
{
|
|
answ = string.Format("{0:yyyyMMddHHmmssfff}#{1:X2}#{2}", DateTime.Now, (int)B_output, counterSigIN);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Fornisce il valore di flusso e valore in formato valido x messa in coda nel formato dtEve#flux#value#cont
|
|
/// </summary>
|
|
protected 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;
|
|
}
|
|
/// <summary>
|
|
/// Decodifica valore della coda IN nel formato
|
|
/// answ[0]=dtEve
|
|
/// answ[1]=valore
|
|
/// answ[2]=counter
|
|
/// </summary>
|
|
/// <param name="queueVal">dtEve + '#' + value + '#' + cont</param>
|
|
/// <returns></returns>
|
|
protected string[] qDecodeIN(string queueVal)
|
|
{
|
|
return queueVal.Split('#');
|
|
}
|
|
/// <summary>
|
|
/// Effettua lettura dati
|
|
/// </summary>
|
|
public virtual void readAllData()
|
|
{
|
|
if (!DemoIn)
|
|
{
|
|
if (connectionOk)
|
|
{
|
|
readSemafori();
|
|
}
|
|
else
|
|
{
|
|
lg.Error("Errore connessione mancante x readSemafori");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// segnalo ceh sono in Demo
|
|
parentForm.sIN = Semaforo.SS;
|
|
// simulo letura
|
|
simReadMem();
|
|
}
|
|
nReadIN++;
|
|
// aggiorno valore mostrato...
|
|
displayRawData();
|
|
}
|
|
/// <summary>
|
|
/// Effettua gestioen programma: legge e mostra su display...
|
|
/// </summary>
|
|
private void processProgram()
|
|
{
|
|
string currPrgName = "";
|
|
if (!DemoIn)
|
|
{
|
|
currPrgName = getPrgName();
|
|
}
|
|
else
|
|
{
|
|
currPrgName = string.Format("P-{0:HHmmss}", DateTime.Now);
|
|
}
|
|
// verifico SE sia cambiato il programma...
|
|
if (lastPrgName != currPrgName)
|
|
{
|
|
// salvo!
|
|
lastPrgName = currPrgName;
|
|
displayOtherData(currPrgName);
|
|
lg.Info(string.Format("[PROG]{0}", currPrgName));
|
|
// --> accodo (valore già formattato)!
|
|
QueueFLog.Enqueue(qEncodeFLog("PROG", currPrgName));
|
|
// Gestione counter FLog!
|
|
counterFLog++;
|
|
// se supera 10k resetto...
|
|
if (counterFLog > 9999) counterFLog = 0;
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Processo lettura dati sysinfo
|
|
/// </summary>
|
|
private void processSysInfo()
|
|
{
|
|
Dictionary<string, string> currSysInfo = new Dictionary<string, string>();
|
|
if (!DemoIn)
|
|
{
|
|
currSysInfo = getSysInfo();
|
|
}
|
|
else
|
|
{
|
|
currSysInfo.Add("SYS-DEMO", string.Format("S-{0:HHmm}", DateTime.Now));
|
|
}
|
|
// verifico SE sia cambiato il programma...
|
|
if (lastSysInfo != currSysInfo["SYSINFO"])
|
|
{
|
|
// salvo!
|
|
lastSysInfo = currSysInfo["SYSINFO"];
|
|
// per ogni valore del dizionario mostro ed accodo!
|
|
string sVal = "";
|
|
foreach (var item in currSysInfo)
|
|
{
|
|
sVal = string.Format("[SYSINFO]{0}|{1}", item.Key, item.Value);
|
|
displayOtherData(sVal);
|
|
lg.Info(string.Format("{0}", 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;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Restituisce info sistema
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual Dictionary<string, string> getSysInfo()
|
|
{
|
|
Dictionary<string, string> outVal = new Dictionary<string, string>();
|
|
return outVal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce programma in esecuzione
|
|
/// </summary>
|
|
public virtual string getPrgName()
|
|
{
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua lettura semafori principale
|
|
/// </summary>
|
|
public virtual void readSemafori()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua invio a MoonPro del valore richiesto
|
|
/// </summary>
|
|
/// <param name="tipoUrl"></param>
|
|
/// <param name="queueVal">Valore da trasmettere: es
|
|
/// INPUT: lo status rilevato in HEX
|
|
/// FLog: il valore da trasmettere per il flusso indicato</param>
|
|
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();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region gestione dataMonitor (accodamento valori)
|
|
|
|
/// <summary>
|
|
/// Mostra i dati grezzi letti in esadecimale
|
|
/// </summary>
|
|
private void displayRawData()
|
|
{
|
|
// mostro update...
|
|
string newString = string.Format("{0:X}", (int)B_input);
|
|
accodaRawData(newString);
|
|
// salvo coda debug...
|
|
QueueDebug.Enqueue(B_input);
|
|
}
|
|
/// <summary>
|
|
/// Update visualizzaizone BIT in ingresso
|
|
/// </summary>
|
|
public void displayInData()
|
|
{
|
|
// mostro update...
|
|
string newString = string.Format("{0:0000}|{1}", counterSigIN, utils.IntToBinStr((int)B_output, 8));
|
|
accodaSignaInlData(newString);
|
|
}
|
|
/// <summary>
|
|
/// Mostra cosa ha/avrebbe inviato
|
|
/// </summary>
|
|
public void displayOutData()
|
|
{
|
|
accodaUrlData(lastUrl);
|
|
}
|
|
/// <summary>
|
|
/// Mostra cosa ha/avrebbe inviato
|
|
/// </summary>
|
|
/// <param name="newData"></param>
|
|
public void displayOtherData(string newData)
|
|
{
|
|
// mostro update...
|
|
accodaOtherData(newData);
|
|
}
|
|
/// <summary>
|
|
/// Accoda (visualizzando in cima allo stack) la nuova stringa di output per area OTHER DATA
|
|
/// </summary>
|
|
/// <param name="newLine"></param>
|
|
public void accodaRawData(string newLine)
|
|
{
|
|
// inserisco in cima allo stack, trimmo e aggiorno display
|
|
parentForm.dataMonitor_0 = limitLine2show(string.Format("{0}{1}{2}", newLine, Environment.NewLine, parentForm.dataMonitor_0));
|
|
}
|
|
/// <summary>
|
|
/// Accoda (visualizzando in cima allo stack) la nuova stringa di output per area OTHER DATA
|
|
/// </summary>
|
|
/// <param name="newLine"></param>
|
|
public void accodaSignaInlData(string newLine)
|
|
{
|
|
// inserisco in cima allo stack, trimmo e aggiorno display
|
|
parentForm.dataMonitor_1 = limitLine2show(string.Format("{0}{1}{2}", newLine, Environment.NewLine, parentForm.dataMonitor_1));
|
|
}
|
|
/// <summary>
|
|
/// Accoda (visualizzando in cima allo stack) la nuova stringa di output per area OTHER DATA
|
|
/// </summary>
|
|
/// <param name="newLine"></param>
|
|
public void accodaUrlData(string newLine)
|
|
{
|
|
// inserisco in cima allo stack, trimmo e aggiorno display
|
|
parentForm.dataMonitor_2 = limitLine2show(string.Format("{0}{1}{2}", newLine, Environment.NewLine, parentForm.dataMonitor_2));
|
|
}
|
|
/// <summary>
|
|
/// Accoda (visualizzando in cima allo stack) la nuova stringa di output per area OTHER DATA
|
|
/// </summary>
|
|
/// <param name="newLine"></param>
|
|
public void accodaOtherData(string newLine)
|
|
{
|
|
// inserisco in cima allo stack, trimmo e aggiorno display
|
|
parentForm.dataMonitor_3 = limitLine2show(string.Format("{0}{1}{2}", newLine, Environment.NewLine, parentForm.dataMonitor_3));
|
|
}
|
|
/// <summary>
|
|
/// Effettua un trim della stringa al numero max di linee da mostrare a video
|
|
/// </summary>
|
|
/// <param name="newString"></param>
|
|
/// <returns></returns>
|
|
private string limitLine2show(string newString)
|
|
{
|
|
// se num righe superiore a limite trimmo...
|
|
if (newString.Split('\n').Length > parentForm.nLine2show)
|
|
{
|
|
int idx = newString.LastIndexOf(Environment.NewLine);
|
|
newString = newString.Substring(0, idx);
|
|
}
|
|
return newString;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|