prima bozza con filtro OK
This commit is contained in:
@@ -23,7 +23,7 @@ BITGREEN=Y8.6
|
||||
|
||||
[BLINK]
|
||||
;MAX_COUNTER_BLINK = 30
|
||||
MAX_COUNTER_BLINK = 3
|
||||
MAX_COUNTER_BLINK = 20
|
||||
;bit0 = 0
|
||||
;bit1 = 0
|
||||
;bit2 = 1
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace IOB_WIN
|
||||
cncPort = "0";
|
||||
tipoIob = tipoAdapter.DEMO;
|
||||
serverData = new serverMapo("127.0.0.1", "/", "/IOB/input/", "/IOB", "/IOB/enabled/", "/sendReboot.aspx?idxMacchina=");
|
||||
MAX_COUNTER_BLINK = 1;
|
||||
MAX_COUNTER_BLINK = 10;
|
||||
BLINK_FILT = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,8 @@ namespace IOB_WIN
|
||||
|
||||
public string lastUrl { get; set; }
|
||||
|
||||
// Tolgo gestione strobes --> bitarray!
|
||||
#if false
|
||||
/// <summary>
|
||||
/// 16 byte di strobe (4 word da 32 bit di flags...)
|
||||
/// </summary>
|
||||
@@ -136,7 +138,8 @@ namespace IOB_WIN
|
||||
{
|
||||
return (StFlag32)BitConverter.ToUInt32(StrobesPrev, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Array dei contatori x segnali blinking
|
||||
/// </summary>
|
||||
@@ -1139,13 +1142,13 @@ namespace IOB_WIN
|
||||
private void processAllMemory()
|
||||
{
|
||||
// in primis SALVO valori previous/precedenti
|
||||
StrobesPrev = Strobes;
|
||||
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 (STRB_DW0 != STRB_00_PREV)
|
||||
if (B_output != B_previous)
|
||||
{
|
||||
// mostro dati variati letti...
|
||||
displayInData();
|
||||
@@ -1162,12 +1165,7 @@ namespace IOB_WIN
|
||||
/// Esegue filtraggio dati x bit blinking!!!
|
||||
/// </summary>
|
||||
private void filterData()
|
||||
{
|
||||
// per ora, PER TEST, copio i valori da stroibe a bits...
|
||||
B_input = (int)STRB_DW0;
|
||||
B_previous = (int)STRB_00_PREV;
|
||||
|
||||
|
||||
{
|
||||
// effettuo filtraggio dei valori letti... inizializzo OUT!
|
||||
B_output = 0;
|
||||
// in primis verifico SE ci siano bit blinkng... se non ci sono OUT=IN...
|
||||
@@ -1183,35 +1181,48 @@ namespace IOB_WIN
|
||||
int iBlink = B_input & currIobConf.BLINK_FILT;
|
||||
// ...aggiungo i "bit che passano"
|
||||
B_output += iBlink;
|
||||
// calcolo QUALI valori (tra quelli blink) siano ad 1 x cui richiedono di inizializzare i counters al max val...
|
||||
BitArray bBlink = new BitArray(new byte[] { Convert.ToByte(iBlink) });
|
||||
int[] bitsUp = bBlink.Cast<bool>().Select(bit => bit ? 1 : 0).ToArray();
|
||||
foreach (int item in bitsUp)
|
||||
|
||||
// calcolo fronte di salita (0 --> 1 dei bit BLINK)
|
||||
int iFronte = (B_input & ~B_previous) & currIobConf.BLINK_FILT;
|
||||
// calcolo QUALI valori (tra quelli blink) siano PASSATI da 0 a 1 --> init counters...
|
||||
BitArray bBlinkStart = new BitArray(new byte[] { Convert.ToByte(iFronte) });
|
||||
int[] bitsUp = bBlinkStart.Cast<bool>().Select(bit => bit ? 1 : 0).ToArray();
|
||||
for (int i = 0; i < bitsUp.Length; i++)
|
||||
{
|
||||
// e impostiamo contatori al MAX
|
||||
i_counters[item] = currIobConf.MAX_COUNTER_BLINK;
|
||||
// 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();
|
||||
foreach (int item in bitsDown)
|
||||
for (int i = 0; i < bitsDown.Length; i++)
|
||||
{
|
||||
// !!!FARE NON VA BENE... legge tutto ma NON VA BENE (deve vedere INDICI...)
|
||||
|
||||
// va usata una funzione di trasformazione x la parte BLINK dei segnali x salvare i vettori IN/OUT e PREV... x testare se sia 0 e abbia finito counter... deve usare INDICE DEL VETTORE int[] x andare a controllare counters...
|
||||
|
||||
// decremento contatore
|
||||
i_counters[item] = i_counters[item] - 1;
|
||||
// controllo, se è 0 CONFERMO e NON faccio nulla (NON aggiungo)m sennò resta 1 ed aggiungo...
|
||||
if (i_counters[item] > 0)
|
||||
// se era a zero (invertito...)
|
||||
if (bitsDown[i] == 1)
|
||||
{
|
||||
B_output += 1 << item;
|
||||
}
|
||||
else
|
||||
{
|
||||
// rimetto a zero counter...
|
||||
i_counters[item] = 0;
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1226,7 +1237,7 @@ namespace IOB_WIN
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
answ = string.Format("{0:yyyyMMddHHmmssfff}#{1:X2}#{2}", DateTime.Now, (int)STRB_DW0, counter);
|
||||
answ = string.Format("{0:yyyyMMddHHmmssfff}#{1:X2}#{2}", DateTime.Now, (int)B_output, counter);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
@@ -1318,7 +1329,7 @@ namespace IOB_WIN
|
||||
public void displayInData()
|
||||
{
|
||||
// mostro update......
|
||||
string newString = string.Format("{0:0000}|{1}{2}{3}", counter, utils.IntToBinStr((int)STRB_DW0, 8), Environment.NewLine, parentForm.dataMonitor_1);
|
||||
string newString = string.Format("{0:0000}|{1}{2}{3}", counter, utils.IntToBinStr((int)B_output, 8), Environment.NewLine, parentForm.dataMonitor_1);
|
||||
// se num righe superiore a limite trimmo...
|
||||
if (newString.Split('\n').Length > parentForm.nLine2show)
|
||||
{
|
||||
@@ -1349,7 +1360,8 @@ namespace IOB_WIN
|
||||
numSim--;
|
||||
}
|
||||
// processo la coda di simulazione (stacco ed accodo 1 valore...)
|
||||
Strobes = BitConverter.GetBytes(QueueSIM.Dequeue());
|
||||
B_input = QueueSIM.Dequeue();
|
||||
//Strobes = BitConverter.GetBytes(QueueSIM.Dequeue());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1363,7 +1375,8 @@ namespace IOB_WIN
|
||||
{
|
||||
countSim++;
|
||||
if (countSim > 255) countSim = 0;
|
||||
Strobes = BitConverter.GetBytes(countSim);
|
||||
B_input =countSim;
|
||||
//Strobes = BitConverter.GetBytes(countSim);
|
||||
}
|
||||
lastSim = DateTime.Now;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user