Update Gestione FIMAT x bit trad
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IOB_UT_NEXT
|
||||
{
|
||||
public class BitUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Test se il bit sia attivo
|
||||
/// </summary>
|
||||
/// <param name="val2check">valkore da verificare</param>
|
||||
/// <param name="bitNum">bit da verificare (0 based, 00..31)</param>
|
||||
/// <returns></returns>
|
||||
public static bool isActive(int val2check, int bitNum)
|
||||
{
|
||||
bool answ = false;
|
||||
// testa i-esimo bit (max 32 bit...)
|
||||
if (bitNum <= 31)
|
||||
{
|
||||
answ = ((val2check & (1 << bitNum)) != 0);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BitUtils.cs" />
|
||||
<Compile Include="FileProcMan.cs" />
|
||||
<Compile Include="IntConditionCheck.cs" />
|
||||
<Compile Include="BitConditionCheck.cs" />
|
||||
|
||||
@@ -5196,6 +5196,28 @@ namespace IOB_WIN_NEXT
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Effettua traduzione ITEM da LUT parametrica (key: lemma) del file di conf, se non
|
||||
/// trovo uso key
|
||||
/// </summary>
|
||||
/// <param name="lemma"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual string itemTranslation(string lemma)
|
||||
{
|
||||
string answ = "";
|
||||
if (cIobConf.itemTranslation != null)
|
||||
{
|
||||
if (cIobConf.itemTranslation.ContainsKey(lemma))
|
||||
{
|
||||
answ = cIobConf.itemTranslation[lemma];
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = lemma;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
|
||||
|
||||
@@ -697,21 +697,69 @@ namespace IOB_WIN_NEXT
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Classe di base implementazione traduzione di una LUT da memoria come valore BIT (multipli) a valore
|
||||
/// esplicito x FLog
|
||||
/// Classe di base implementazione traduzione di una LUT da memoria come valore BIT
|
||||
/// (multipli) a valore esplicito x FLog
|
||||
/// </summary>
|
||||
protected override void checkTranslateBit()
|
||||
{
|
||||
// verifico se devo processare decodifica di qualche valore...
|
||||
if (OptVar2TranslBit != null && OptVar2TranslBit.Count > 0)
|
||||
{
|
||||
Dictionary<string, int> valUpdated = new Dictionary<string, int>();
|
||||
// ciclo x ogni valore da tradurre
|
||||
|
||||
// cerco valore nella LUT... se è pari cerco "direttamente" altrimenti dal pari inferiore e 2° INT[]
|
||||
|
||||
// eseguo trduzione da conf
|
||||
|
||||
// se è variato rispetto precedente --> accodo in FLog e salvo...
|
||||
foreach (var item in OptVar2TranslBit)
|
||||
{
|
||||
int reqAddr = 0;
|
||||
// traduco in int...
|
||||
int.TryParse(item.Key, out reqAddr);
|
||||
int lutAddr = reqAddr + indexLutCorr;
|
||||
int valInt = 0;
|
||||
int[] listInt = new int[2];
|
||||
// cerco valore nella LUT... se è pari cerco "direttamente" altrimenti dal pari
|
||||
// inferiore e 2° INT[]
|
||||
if (lutAddr % 2 == 0)
|
||||
{
|
||||
listInt = HoldingRegisterLUT[lutAddr];
|
||||
valInt = listInt[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
lutAddr--;
|
||||
listInt = HoldingRegisterLUT[lutAddr];
|
||||
valInt = listInt[1];
|
||||
}
|
||||
// gestisco a bitmap --> salvo valore INT x check..
|
||||
string sVal = $"{valInt}";
|
||||
// se è variato rispetto precedente --> calcolo valori string, accodo in FLog e salvo...
|
||||
if (item.Value != sVal)
|
||||
{
|
||||
valUpdated.Add(item.Value, valInt);
|
||||
}
|
||||
}
|
||||
// se ho valori aggiornati --> aggiorno dictionary e invio
|
||||
if (valUpdated.Count > 0)
|
||||
{
|
||||
DateTime locTStamp = DateTime.Now;
|
||||
foreach (var item in valUpdated)
|
||||
{
|
||||
// salvo il valore modificato
|
||||
OptVar2TranslInt[item.Key] = $"{item.Value}";
|
||||
List<string> listVal = new List<string>();
|
||||
// si tratta di valori bit --> devo cercare OGNI bit attivo (0..8 --> 0.255)
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (BitUtils.isActive(item.Value, i))
|
||||
{
|
||||
// traduco ed accodo...
|
||||
listVal.Add(itemTranslation($"{item.Key}.{i}"));
|
||||
}
|
||||
}
|
||||
// costruisco stringa finale...
|
||||
string trad = string.Join(",", listVal);
|
||||
string sVal = $"Change {item.Key}: {locTStamp.ToString()} | Val: {item.Value} | trad: {trad}";
|
||||
accodaFLog(sVal, qEncodeFLog(item.Key, trad));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -723,6 +771,7 @@ namespace IOB_WIN_NEXT
|
||||
{
|
||||
if (OptVar2TranslInt != null && OptVar2TranslInt.Count > 0)
|
||||
{
|
||||
Dictionary<string, string> valUpdated = new Dictionary<string, string>();
|
||||
// ciclo x ogni valore da tradurre
|
||||
foreach (var item in OptVar2TranslInt)
|
||||
{
|
||||
@@ -731,40 +780,39 @@ namespace IOB_WIN_NEXT
|
||||
int.TryParse(item.Key, out reqAddr);
|
||||
int lutAddr = reqAddr + indexLutCorr;
|
||||
int valInt = 0;
|
||||
// cerco valore nella LUT... se è pari cerco "direttamente" altrimenti dal pari inferiore e 2° INT[]
|
||||
int[] listInt = new int[2];
|
||||
// cerco valore nella LUT... se è pari cerco "direttamente" altrimenti dal pari
|
||||
// inferiore e 2° INT[]
|
||||
if (lutAddr % 2 == 0)
|
||||
{
|
||||
listInt = HoldingRegisterLUT[lutAddr];
|
||||
valInt = listInt[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
lutAddr--;
|
||||
listInt = HoldingRegisterLUT[lutAddr];
|
||||
valInt = listInt[1];
|
||||
}
|
||||
#if false
|
||||
listInt = HoldingRegisterLUT[OptCheckCondInt[cKey].BaseAddr];
|
||||
|
||||
int lutAddress = parametri.holdRegBaseAddr + item.Value.index + deltaBase + indexLutCorr;
|
||||
// se size = 1 --> devo cambiare modo recupero
|
||||
if (item.Value.size == 1)
|
||||
{
|
||||
//if (item.Value.index % 2 == 0)
|
||||
if (lutAddress % 2 == 0)
|
||||
{
|
||||
Array.Copy(HoldingRegisterLUT[lutAddress], 0, listInt, 0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
lutAddress--;
|
||||
Array.Copy(HoldingRegisterLUT[lutAddress], 1, listInt, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// eseguo trduzione da conf
|
||||
|
||||
// cerco traduzione...
|
||||
string trad = itemTranslation(item.Key, $"{valInt}");
|
||||
// se è variato rispetto precedente --> accodo in FLog e salvo...
|
||||
if (item.Value != trad)
|
||||
{
|
||||
valUpdated.Add(item.Value, trad);
|
||||
}
|
||||
}
|
||||
// se ho valori aggiornati --> aggiorno dictionary e invio
|
||||
if (valUpdated.Count > 0)
|
||||
{
|
||||
string sVal = "";
|
||||
DateTime locTStamp = DateTime.Now;
|
||||
foreach (var item in valUpdated)
|
||||
{
|
||||
OptVar2TranslInt[item.Key] = item.Value;
|
||||
sVal = $"Change {item.Key}: {locTStamp.ToString()} | Val: {item.Value}";
|
||||
accodaFLog(sVal, qEncodeFLog(item.Key, item.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user