diff --git a/.gitignore b/.gitignore index 71f3992..97c3cd5 100644 --- a/.gitignore +++ b/.gitignore @@ -344,3 +344,6 @@ _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML + +.fake +.ionide \ No newline at end of file diff --git a/MP.MONO.ALL.sln b/MP.MONO.ALL.sln index 235b20b..f19dea8 100644 --- a/MP.MONO.ALL.sln +++ b/MP.MONO.ALL.sln @@ -11,40 +11,92 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.MONO.Core", "MP.MONO.Cor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.MONO.SIM", "MP.MONO.SIM\MP.MONO.SIM.csproj", "{BFF20F9D-5706-4CF1-BFE3-FB771034070F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.MONO.DECODER", "MP.MONO.DECODER\MP.MONO.DECODER.csproj", "{2D0206F1-E432-4D0E-AAF6-CEA18833A746}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.MONO.DECODER", "MP.MONO.DECODER\MP.MONO.DECODER.csproj", "{2D0206F1-E432-4D0E-AAF6-CEA18833A746}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.MONO.ANALYZER", "MP.MONO.ANALYZER\MP.MONO.ANALYZER.csproj", "{4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.MONO.ANALYZER", "MP.MONO.ANALYZER\MP.MONO.ANALYZER.csproj", "{4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6FB65850-C023-4986-9DFF-770C4E582D60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6FB65850-C023-4986-9DFF-770C4E582D60}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6FB65850-C023-4986-9DFF-770C4E582D60}.Debug|x64.ActiveCfg = Debug|x64 + {6FB65850-C023-4986-9DFF-770C4E582D60}.Debug|x64.Build.0 = Debug|x64 + {6FB65850-C023-4986-9DFF-770C4E582D60}.Debug|x86.ActiveCfg = Debug|x86 + {6FB65850-C023-4986-9DFF-770C4E582D60}.Debug|x86.Build.0 = Debug|x86 {6FB65850-C023-4986-9DFF-770C4E582D60}.Release|Any CPU.ActiveCfg = Release|Any CPU {6FB65850-C023-4986-9DFF-770C4E582D60}.Release|Any CPU.Build.0 = Release|Any CPU + {6FB65850-C023-4986-9DFF-770C4E582D60}.Release|x64.ActiveCfg = Release|x64 + {6FB65850-C023-4986-9DFF-770C4E582D60}.Release|x64.Build.0 = Release|x64 + {6FB65850-C023-4986-9DFF-770C4E582D60}.Release|x86.ActiveCfg = Release|x86 + {6FB65850-C023-4986-9DFF-770C4E582D60}.Release|x86.Build.0 = Release|x86 {60EB575C-1E63-4A29-B233-5E661F2D2387}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {60EB575C-1E63-4A29-B233-5E661F2D2387}.Debug|Any CPU.Build.0 = Debug|Any CPU + {60EB575C-1E63-4A29-B233-5E661F2D2387}.Debug|x64.ActiveCfg = Debug|x64 + {60EB575C-1E63-4A29-B233-5E661F2D2387}.Debug|x64.Build.0 = Debug|x64 + {60EB575C-1E63-4A29-B233-5E661F2D2387}.Debug|x86.ActiveCfg = Debug|x86 + {60EB575C-1E63-4A29-B233-5E661F2D2387}.Debug|x86.Build.0 = Debug|x86 {60EB575C-1E63-4A29-B233-5E661F2D2387}.Release|Any CPU.ActiveCfg = Release|Any CPU {60EB575C-1E63-4A29-B233-5E661F2D2387}.Release|Any CPU.Build.0 = Release|Any CPU + {60EB575C-1E63-4A29-B233-5E661F2D2387}.Release|x64.ActiveCfg = Release|x64 + {60EB575C-1E63-4A29-B233-5E661F2D2387}.Release|x64.Build.0 = Release|x64 + {60EB575C-1E63-4A29-B233-5E661F2D2387}.Release|x86.ActiveCfg = Release|x86 + {60EB575C-1E63-4A29-B233-5E661F2D2387}.Release|x86.Build.0 = Release|x86 {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Debug|x64.ActiveCfg = Debug|x64 + {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Debug|x64.Build.0 = Debug|x64 + {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Debug|x86.ActiveCfg = Debug|x86 + {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Debug|x86.Build.0 = Debug|x86 {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Release|Any CPU.ActiveCfg = Release|Any CPU {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Release|Any CPU.Build.0 = Release|Any CPU + {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Release|x64.ActiveCfg = Release|x64 + {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Release|x64.Build.0 = Release|x64 + {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Release|x86.ActiveCfg = Release|x86 + {7DE649D8-511E-4674-A170-7E7AFDE4FD89}.Release|x86.Build.0 = Release|x86 {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Debug|x64.ActiveCfg = Debug|x64 + {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Debug|x64.Build.0 = Debug|x64 + {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Debug|x86.ActiveCfg = Debug|x86 + {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Debug|x86.Build.0 = Debug|x86 {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Release|Any CPU.ActiveCfg = Release|Any CPU {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Release|Any CPU.Build.0 = Release|Any CPU + {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Release|x64.ActiveCfg = Release|x64 + {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Release|x64.Build.0 = Release|x64 + {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Release|x86.ActiveCfg = Release|x86 + {BFF20F9D-5706-4CF1-BFE3-FB771034070F}.Release|x86.Build.0 = Release|x86 {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Debug|x64.ActiveCfg = Debug|x64 + {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Debug|x64.Build.0 = Debug|x64 + {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Debug|x86.ActiveCfg = Debug|x86 + {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Debug|x86.Build.0 = Debug|x86 {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Release|Any CPU.ActiveCfg = Release|Any CPU {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Release|Any CPU.Build.0 = Release|Any CPU + {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Release|x64.ActiveCfg = Release|x64 + {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Release|x64.Build.0 = Release|x64 + {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Release|x86.ActiveCfg = Release|x86 + {2D0206F1-E432-4D0E-AAF6-CEA18833A746}.Release|x86.Build.0 = Release|x86 {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Debug|x64.ActiveCfg = Debug|x64 + {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Debug|x64.Build.0 = Debug|x64 + {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Debug|x86.ActiveCfg = Debug|x86 + {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Debug|x86.Build.0 = Debug|x86 {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Release|Any CPU.ActiveCfg = Release|Any CPU {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Release|Any CPU.Build.0 = Release|Any CPU + {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Release|x64.ActiveCfg = Release|x64 + {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Release|x64.Build.0 = Release|x64 + {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Release|x86.ActiveCfg = Release|x86 + {4C9BEAED-1A33-41A7-B9D6-7C173A43FDB8}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MP.MONO.ANALYZER/MP.MONO.ANALYZER.csproj b/MP.MONO.ANALYZER/MP.MONO.ANALYZER.csproj index 8a9ce66..2da2a3e 100644 --- a/MP.MONO.ANALYZER/MP.MONO.ANALYZER.csproj +++ b/MP.MONO.ANALYZER/MP.MONO.ANALYZER.csproj @@ -5,6 +5,7 @@ net6.0 enable enable + AnyCPU;x86;x64 diff --git a/MP.MONO.Core/MP.MONO.Core.csproj b/MP.MONO.Core/MP.MONO.Core.csproj index c294001..40f602d 100644 --- a/MP.MONO.Core/MP.MONO.Core.csproj +++ b/MP.MONO.Core/MP.MONO.Core.csproj @@ -4,6 +4,7 @@ net6.0 enable enable + AnyCPU;x86;x64 diff --git a/MP.MONO.DECODER/MP.MONO.DECODER.csproj b/MP.MONO.DECODER/MP.MONO.DECODER.csproj index a02f86e..ba954d9 100644 --- a/MP.MONO.DECODER/MP.MONO.DECODER.csproj +++ b/MP.MONO.DECODER/MP.MONO.DECODER.csproj @@ -5,6 +5,7 @@ net6.0 enable enable + AnyCPU;x86;x64 @@ -33,6 +34,12 @@ Always + + Always + + + Always + Always diff --git a/MP.MONO.DECODER/MyClass.cs b/MP.MONO.DECODER/MyClass.cs index 55f9d01..6f8b1da 100644 --- a/MP.MONO.DECODER/MyClass.cs +++ b/MP.MONO.DECODER/MyClass.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -13,5 +14,11 @@ namespace MP.MONO.DECODER { Console.WriteLine($"Doing something: {p}"); } + + public void SaveData(string key, object objVal) + { + string rawData = JsonConvert.SerializeObject(objVal); + Console.WriteLine($"Request save | key: {key} | value: {rawData}"); + } } } diff --git a/MP.MONO.DECODER/Program.cs b/MP.MONO.DECODER/Program.cs index 315abf1..60b9814 100644 --- a/MP.MONO.DECODER/Program.cs +++ b/MP.MONO.DECODER/Program.cs @@ -6,33 +6,128 @@ Console.WriteLine("Start DECODER with LUA integration!"); Lua state; +state = new Lua(); +// preparo variabile x avvisare script che il modo è da NLua +state.DoString(" callMode = 'NLua' "); -static double Compute(double x) +int numTest = 1; +if (numTest == 1) { - return x * (x - 1); + // inserisco dati in LUA... + List alarmList = new List(); + alarmList = new List() { "Allarme01", "Allarme02", "##Allarme03", "Allarme04" }; + //state.NewTable("alarmList"); + //state.DoString(" print(alarmList) "); + state["alarmList"] = alarmList; + //state.DoString(" print(alarmList) "); + state["numAlarm"] = alarmList.Count; + + // chiamo script + string luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "AlarmDecoder.lua"); + state.DoFile(luaPath); + + LuaTable tabA = state.GetTable("alarmListFix"); + + // aggiorno valori + alarmList = new List() { "Allarme01", "Allarme02", "##Allarme03", "Allarme04", "Allarme05", "##Allarme06", "Allarme07", "Allarme08" }; + state["alarmList"] = alarmList; + state["numAlarm"] = alarmList.Count; + // rieseguo + state.DoFile(luaPath); + + //state.DoString("a={b={c=2}}"); + //LuaTable tabA = state.GetTable("a"); + //LuaTable tabB = state.GetTable("a.b"); + //state.DoString(" print(a) "); + //foreach (var item in tabA) + //{ + // Console.WriteLine(item); + //} + + //foreach (var item in tabB) + //{ + // Console.WriteLine(item); + //} +} +else if (numTest == 2) +{ + static double Compute(double x) + { + return x * (x - 1); + + } + var myobj = new MyClass(); + myobj.IntegerProperty = 17; + state["var1"] = "someValue"; + state["obj"] = myobj; + state["compute"] = new Func(Compute); + // Will print "output: someValue" + state.DoString(" print('output: ' .. var1) "); + // Will print 18 + state.DoString(" print(obj.IntegerProperty + 1) "); + // Will print "Doing something: hello" + state.DoString(" obj:DoSomething('hello') "); + state.DoString(" obj:SaveData('redis:key:name','{John = 320, Mary = 340, Bob = 880, Rob = 860}') "); + + state.DoString("a={b={c=2}}"); + LuaTable tabA = state.GetTable("a"); + LuaTable tabB = state.GetTable("a.b"); + state.DoString(" print(a) "); + foreach (var item in tabA) + { + Console.WriteLine(item); + } + + foreach (var item in tabB) + { + Console.WriteLine(item); + } + + + // Will print "-0.1875" + state.DoString(" print(compute(0.25)) "); + // Reading values back + state.DoString(" x = compute(0.75) "); + state.DoString(" y = 2.0 * (obj.IntegerProperty * x) "); + + double x = state.GetNumber("x"); + double y = state.GetNumber("y"); + // Will print: x = -0.1875, y = -6.375 + Console.WriteLine($"x = {x}, y = {y}"); + + double val = 12.0; + state["x"] = val; // Create a global value 'x' + var resRaw = state.DoString("return 10 + x*(5 + 2)")[0]; + double res = 0; + double.TryParse($"{resRaw}", out res); + Console.WriteLine($"{res}"); + + + + state.DoString("y = 10 + x*(4 + 2)"); + var rawState = state["y"]; // Retrieve the value of y + double y2 = 0; + double.TryParse($"{rawState}", out y2); + Console.WriteLine($"{y2}"); + + state.DoString(@" + function ScriptFunc (val1, val2) + if val1 > val2 then + return val1 + 1 + else + return val2 - 1 + end + end + "); + var scriptFunc = state["ScriptFunc"] as LuaFunction; + var res2 = (long)scriptFunc.Call(3, 9).First(); + Console.WriteLine($"risultato script: {res2}"); + // LuaFunction.Call will also return a array of objects, since a Lua function + // can return multiple values } - -var myobj = new MyClass(); -myobj.IntegerProperty = 17; -state = new Lua(); -state["var1"] = "someValue"; -state["obj"] = myobj; -state["compute"] = new Func(Compute); -// Will print "output: someValue" -state.DoString(" print('output: ' .. var1) "); -// Will print 18 -state.DoString(" print(obj.IntegerProperty + 1) "); -// Will print "Doing something: hello" -state.DoString(" obj:DoSomething('hello') "); -// Will print "-0.1875" -state.DoString(" print(compute(0.25)) "); -// Reading values back -state.DoString(" x = compute(0.75) "); -state.DoString(" y = 2.0 * (obj.IntegerProperty * x) "); -string luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "prova.lua"); -state.DoFile(luaPath); -double x = state.GetNumber("x"); -double y = state.GetNumber("y"); -// Will print: x = -0.1875, y = -6.375 -Console.WriteLine($"x = {x}, y = {y}"); \ No newline at end of file +else if (numTest == 99) +{ + string luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "prova.lua"); + state.DoFile(luaPath); +} diff --git a/MP.MONO.DECODER/lua/AlarmDecoder.lua b/MP.MONO.DECODER/lua/AlarmDecoder.lua new file mode 100644 index 0000000..b82cd0f --- /dev/null +++ b/MP.MONO.DECODER/lua/AlarmDecoder.lua @@ -0,0 +1,98 @@ + +-- This is a one-line comment that ends at the end of the line +--[[ This a multi-line (long) [comment](http://www.lua.org/manual/5.1/manual.html#2.1) + that ends with this closing bracket --> ]] +--[=[ This is also a long comment ]=] + + + +--[[--------------------------------------------------- +Procedura decodifica Allarmi: + +- ricezione tab elenco allarmi gestiti a bitmap, se ## = silenziati +- produzione var string con status finale risultati +- ricezione obj stato corrente x i vari allarmi +- decodifica x ogni info ricevuta dello stato allarmi relativo +- invio (salvataggio) stato allarmi tramite funzione + +---------------------------------------------------]]-- +-- ricezione da codice tab status allarmi, attenzione da C# è 0 based, qui è 1 based --> fix costruzione tabella + +-- variabile semaforo callMode x chiamate locali o remote da NLua +callMode = callMode or '' + +-- se non è da NLua inizializzo variabili accessorie +if(callMode ~= 'NLua') +then + alarmList = {"Allarme01", "Allarme02", "##Silenzio", "##Allarme04", "Allarme05", "Allarme06", "Allarme07", "##Allarme08"} + numAlarm = #alarmList + --print(alarmList) +end + +alarmListTable={} + +if numAlarm > 0 and alarmList[0] ~= nil +then + for i = numAlarm,1, -1 + do + alarmListTable[i] = alarmList[i-1] + end +else + alarmListTable = alarmList +end + +print('------------------------------') +for i = 1, numAlarm +do + print("AL"..i.." | "..alarmListTable[i]) +end + +--print('------------------------------') +-- +--for i,val in pairs(alarmListTable) do +-- print("AL"..i.." | "..val) +--end +--print('------------------------------') +-- +--for i,val in ipairs(alarmListTable) do +-- print("AL"..i.." | "..val) +--end + +rawVal = 6 +b0 = 1 +b1 = 2 +b2 = 4 +--bVal = bit.tobit(rawVal) +--bHex = bit.tohex(rawVal) +--print(bit.band(bVal,b0)) +--print(bit.band(bVal,b1)) +--print(bit.band(bVal,b2)) +--print(bHex) + +--print('------------------------------') +--print(6&1 == 1) +--print(6&2 == 2) +--print(6&4 == 4) +--print(6&2 == 8) +--print(6&4 == 16) +--print('------------------------------') +--print(6|1) +--print(6|2) +--print(6|4) +--print(6|2) +--print(6|4) + +--OR, XOR, AND = 1, 3, 4 +-- +--function bitoper(a, b, oper) +-- local r, m, s = 0, 2^31 +-- repeat +-- s,a,b = a+b+m, a%m, b%m +-- r,m = r + m*oper%(s-a-b), m/2 +-- until m < 1 +-- return r +--end +-- +--print(bitoper(6,3,OR)) --> 7 +--print(bitoper(6,3,XOR)) --> 5 +--print(bitoper(6,3,AND)) --> 2 \ No newline at end of file diff --git a/MP.MONO.DECODER/lua/prova.lua b/MP.MONO.DECODER/lua/prova.lua index 8adb133..42f931f 100644 --- a/MP.MONO.DECODER/lua/prova.lua +++ b/MP.MONO.DECODER/lua/prova.lua @@ -4,6 +4,16 @@ that ends with this closing bracket --> ]] --[=[ This is also a long comment ]=] +-- Per eventuale debug +local ZBS = "c:/ZeroBraneStudio" +if not package.path:find(ZBS,1,true) then + package.path = ZBS .. "/lualibs/?/?.lua;" .. ZBS .. "/lualibs/?.lua;" .. package.path + package.cpath = ZBS .. "/bin/?.dll;" .. ZBS .. "/bin/clibs53/?.dll;" .. package.cpath +end + + +require('mobdebug').start() + -- [Numbers](http://www.lua.org/manual/5.1/manual.html#2.1) hours = 54 regularRate = 16 diff --git a/MP.MONO.SIM/MP.MONO.SIM.csproj b/MP.MONO.SIM/MP.MONO.SIM.csproj index 1c7c06b..d59cb6d 100644 --- a/MP.MONO.SIM/MP.MONO.SIM.csproj +++ b/MP.MONO.SIM/MP.MONO.SIM.csproj @@ -5,6 +5,7 @@ net6.0 enable enable + AnyCPU;x86;x64 diff --git a/MP.MONO.UI/MP.MONO.UI.csproj b/MP.MONO.UI/MP.MONO.UI.csproj index e1c233b..3d3a9db 100644 --- a/MP.MONO.UI/MP.MONO.UI.csproj +++ b/MP.MONO.UI/MP.MONO.UI.csproj @@ -4,6 +4,7 @@ net6.0 enable enable + AnyCPU;x86;x64