71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
using NLog;
|
|
using NLua;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.MONO.DECODER
|
|
{
|
|
public class AlarmManager
|
|
{
|
|
protected List<string> AlarmList = new List<string>();
|
|
List<int> currAlarmStatus = new List<int>();
|
|
protected static Lua state = new Lua();
|
|
protected static string luaPath = "";
|
|
public static string alarmStatus = "";
|
|
public static bool valueChanged = false;
|
|
protected static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
public AlarmManager()
|
|
{
|
|
// !!!FIXME TODO
|
|
|
|
// fare vero setup da file... x ora è fake
|
|
for (int i = 1; i < 9; i++)
|
|
{
|
|
AlarmList.Add($"Allarme{i:00}");
|
|
}
|
|
currAlarmStatus.Add(0);
|
|
|
|
// preparo variabile x avvisare script che il modo è da NLua
|
|
luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "AlarmDecoder.lua");
|
|
state.DoString(" callMode = 'NLua' ");
|
|
state["alarmList"] = AlarmList;
|
|
state["numAlarm"] = AlarmList.Count;
|
|
|
|
// initi 0/0
|
|
state["lastVal"] = 0;
|
|
state["currVal"] = 0;
|
|
|
|
Log.Info("AlarmManager OK");
|
|
Console.WriteLine("AlarmManager OK");
|
|
}
|
|
|
|
public static List<string> processData(int newStatus)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
// invio dati aggiornati a LUA
|
|
state["currVal"] = newStatus;
|
|
// FIXME TODO!!! fare invio banco allarmi correnti (SE fossero + banchi da config)
|
|
state.DoFile(luaPath);
|
|
alarmStatus = state.GetString("alarmStatus");
|
|
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}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
}
|