update gestione LUA x parametri e allarmi (diminuito LOG info --> trace)

This commit is contained in:
Samuele Locatelli
2022-03-24 16:26:37 +01:00
parent a48e444fe2
commit 8a0f445b39
6 changed files with 45 additions and 85 deletions
+9 -6
View File
@@ -25,17 +25,18 @@ namespace MP.MONO.DECODER
public AlarmsManager()
{
// preparo variabile x avvisare script che il modo è da NLua
luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "AlarmDecoder.lua");
state["callMode"] = "NLua";
state["lastVal"] = 0;
state["currVal"] = 0;
#if false
state.DoString(" callMode = 'NLua' ");
// initi 0/0
state.DoString(" lastVal = 0 ");
state.DoString(" currVal = 0 ");
#endif
state["callMode"] = "NLua";
state["lastVal"] = 0;
state["currVal"] = 0;
luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "AlarmDecoder.lua");
state.DoFile(luaPath);
Log.Info("AlarmsManager OK");
Console.WriteLine("AlarmsManager OK");
@@ -68,7 +69,9 @@ namespace MP.MONO.DECODER
state["lastVal"] = lastVal;
state["currVal"] = currVal;
state.DoFile(luaPath);
// eseguo calcolo
//state.DoFile(luaPath);
state.DoString(" doProcess() ");
alarmStatus = state.GetString("alarmStatus");
// recupero NUOVO valore (filtrato) attuale da salvare
currVal = (uint)state.GetNumber("lastVal");
+2 -27
View File
@@ -38,12 +38,11 @@ namespace MP.MONO.DECODER
public ParamsManager()
{
// preparo variabile x avvisare script che il modo è da NLua
luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "ParamsDecoder.lua");
state["callMode"] = "NLua";
state["vcFunct"] = "AVG";
// carico il file
luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "ParamsDecoder.lua");
state.DoFile(luaPath);
Log.Info("ParamsManager OK");
@@ -106,8 +105,7 @@ namespace MP.MONO.DECODER
state["numRec"] = ParamsAccumulator[item.Key].dataArray.Count;
state["vcFunct"] = funcMode;
//// effettuo calcolo
//state.DoFile(luaPath);
// effettuo calcolo
state.DoString("doProcess()");
// recupero valore calcolato
@@ -118,29 +116,6 @@ namespace MP.MONO.DECODER
Log.Trace($"calcVal: {calcVal}");
}
//// FIXME TODO
//var calcVal = ParamsAccumulator[item.Key].dataArray.FirstOrDefault();
#if false
alarmStatus = state.GetString("alarmStatus");
// recupero NUOVO valore (filtrato) attuale da salvare
currVal = (uint)state.GetNumber("lastVal");
bool.TryParse(state.GetString("valueChanged"), out valueChanged);
if (valueChanged)
{
Log.Trace($"Changed: {valueChanged}");
Log.Trace(alarmStatus);
LuaTable tabActive = state.GetTable("alarmListActive");
List<string> activeList = new List<string>();
foreach (var allarme in tabActive.Values)
{
answ.Add($"{allarme}");
}
}
#endif
// aggiungo alla lista finale...
var dbRecord = new DataLogModel()
{
-8
View File
@@ -204,14 +204,6 @@ void AlarmsValPipe_EA_NewMessage(object? sender, EventArgs e)
{
// salvo sul DB
_ = dbController.AlarmLogInsertMany(alarmLogList).Result;
#if false
// salvo nel DB lo stato dei bank di allarme
foreach (var dbItem in alarmLogList)
{
_ = dbController.AlarmLogInsert(dbItem).Result;
}
#endif
}
}
}
+16 -9
View File
@@ -119,14 +119,21 @@ end
-- MAIN
alarmListTable = {}
alarmListActive = {}
alarmStatus = ""
-- MAIN
function doProcess()
alarmListTable = {}
alarmListActive = {}
alarmStatus = ""
checkInit()
setupTable()
checkInit()
setupTable()
checkVariation()
checkActiveAlarms()
calcStatusVar()
displayTestInfo()
checkVariation()
checkActiveAlarms()
calcStatusVar()
displayTestInfo()
end
if (callMode ~= 'NLua') then
doProcess()
end
+18 -35
View File
@@ -8,21 +8,18 @@ namespace MP.MONO.Data
#region Private Fields
private bool enableLog = false;
#if false
private DateTime LastSend = DateTime.Now.AddMinutes(-5);
#endif
private IConnectionMultiplexer redis;
private IDatabase? redisDb;
#endregion Private Fields
#endregion Private Fields
#region Protected Fields
#region Protected Fields
protected static Logger Log = LogManager.GetCurrentClassLogger();
#endregion Protected Fields
#endregion Protected Fields
#region Public Constructors
#region Public Constructors
public MessagePipe(IConnectionMultiplexer redisConn, string channelName, bool enableLog = false)
{
@@ -34,24 +31,24 @@ namespace MP.MONO.Data
setupSubscriber();
}
#endregion Public Constructors
#endregion Public Constructors
#region Public Events
#region Public Events
public event EventHandler EA_NewMessage = delegate { };
#endregion Public Events
#endregion Public Events
#region Private Properties
#region Private Properties
/// <summary>
/// Canale associato al gestore pipeline messaggi
/// </summary>
private string _channel { get; set; } = "";
#endregion Private Properties
#endregion Private Properties
#region Private Methods
#region Private Methods
private void setupSubscriber()
{
@@ -59,7 +56,7 @@ namespace MP.MONO.Data
//Subscribe to the channel named messages
sub.Subscribe(_channel, (channel, message) =>
{
Log.Info($"[{DateTime.Now:HH:mm:ss}] {message}");
Log.Trace($"ch {channel} | {message}");
// messaggio
PubSubEventArgs mea = new PubSubEventArgs(message);
// se qualcuno ascolta sollevo evento nuovo valore...
@@ -71,32 +68,18 @@ namespace MP.MONO.Data
Log.Info($"Subscribed {_channel}");
}
#endregion Private Methods
#endregion Private Methods
#region Public Methods
#region Public Methods
public bool saveAndSendMessage(string memKey, string message)
{
bool answ = false;
// invio notifica tramite il canale richiesto
answ = sendMessage(message);
#if false
// effettuo la scrittura nell'area di memoria indicata SE passato intervallo minimo
bool doSend = true;
if (DateTime.Now.Subtract(LastSend).TotalSeconds < 60)
{
doSend = false;
}
if (doSend && redisDb != null)
#endif
if (redisDb != null)
{
redisDb.StringSetAsync(memKey, message);
#if false
LastSend = DateTime.Now;
#endif
if (enableLog)
{
Log.Info($"Redis Cache Key: {memKey}");
@@ -118,7 +101,7 @@ namespace MP.MONO.Data
return answ;
}
#endregion Public Methods
#endregion Public Methods
/// <summary>
/// Invio messaggio sul canale + salvataggio in cache REDIS
@@ -129,19 +112,19 @@ namespace MP.MONO.Data
public class PubSubEventArgs : EventArgs
{
#region Public Constructors
#region Public Constructors
public PubSubEventArgs(string messaggio)
{
this.newMessage = messaggio;
}
#endregion Public Constructors
#endregion Public Constructors
#region Public Properties
#region Public Properties
public string newMessage { get; set; } = "";
#endregion Public Properties
#endregion Public Properties
}
}