diff --git a/MP.MONO.Data/Controllers/SimController.cs b/MP.MONO.Data/Controllers/SimController.cs
deleted file mode 100644
index 34e69ae..0000000
--- a/MP.MONO.Data/Controllers/SimController.cs
+++ /dev/null
@@ -1,91 +0,0 @@
-using Microsoft.Extensions.Configuration;
-using MP.MONO.Core;
-using MP.MONO.Core.DTO;
-using NLog;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace MP.MONO.Data.Controllers
-{
- ///
- /// Classe per generazione dati simulati
- ///
- public class SimController : IDisposable
- {
-
-#if false
- protected List? paramList = null;
-
- public SimController()
- {
- paramList = new List();
- }
- public SimController(List setSimParam)
- {
- if (setSimParam == null)
- {
- setSimParam = new List();
-
- }
- paramList = setSimParam;
- }
-#endif
-
- public void Dispose()
- {
- // Clear database context
- //Log.Info("Dispose di GWMSController");
- }
-
- ///
- /// Restituisce stato Macchina simulato come DTO
- ///
- ///
- public MachineDTO MachineGetStatus()
- {
- Random rand = new Random();
- int maxRun = 5;
- int maxExe = 7;
-
- MachineDTO currMachDto = new MachineDTO()
- {
- Manufacturer = "Egalware",
- Model = "SIM Machine",
- Name = "DEMO 01",
- SerNumber = "2022-0001",
- Mode = $"{(Enums.MachRunMode)rand.Next(0, maxRun)}",
- Status = $"{(Enums.MachExeStatus)rand.Next(0, maxExe)}"
- };
-
- return currMachDto;
- }
-
-
- public ProductionDTO MachineGetProd()
- {
- // !!!FIXME TODO... è fake...
-
- Random rand = new Random();
- int stdCycle = 5;
-
- ProductionDTO currMachDto = new ProductionDTO()
- {
- Order = "ODL Test",
- ItemCode = "ART.0000123",
- ProgName = "P000012",
- CurrQty = DateTime.Now.Minute + rand.Next(1, 40),
- OrderQty = 100,
- CycleTimeMin = rand.NextDouble() * stdCycle,
- Message = "...simulated data..."
- };
-
- Task.Delay(400).Wait();
-
- return currMachDto;
- }
-
- }
-}
diff --git a/MP.MONO.UI/Data/CurrentDataService.cs b/MP.MONO.UI/Data/CurrentDataService.cs
index cd4f941..7f7265d 100644
--- a/MP.MONO.UI/Data/CurrentDataService.cs
+++ b/MP.MONO.UI/Data/CurrentDataService.cs
@@ -49,10 +49,6 @@ namespace MP.MONO.UI.Data
/// Controller dati da DB
///
public static MpDbController dbController;
- ///
- /// Controller dati simulati
- ///
- public static SimController simGen;
#endregion Public Fields
@@ -92,7 +88,6 @@ namespace MP.MONO.UI.Data
dbController = new MpDbController(configuration);
_logger.LogInformation("DbController OK");
}
- simGen = new SimController();
}
#endregion Public Constructors
diff --git a/MachineSim/Program.cs b/MachineSim/Program.cs
index e3e586b..7ef8281 100644
--- a/MachineSim/Program.cs
+++ b/MachineSim/Program.cs
@@ -9,7 +9,6 @@ string lineSep = "------------------------------------------------------";
string redisConf = "127.0.0.1:6379";
Random rand = new Random();
-SimController simGen = new SimController();
Console.WriteLine(lineSep);
Console.WriteLine($"Starting Machine SIM - redis server on {redisConf}!");
@@ -106,7 +105,7 @@ void simStatus()
do
{
// recupero uno stato simulato
- var newStatus = simGen.MachineGetStatus();
+ var newStatus = currSimGen.MachineGetStatus();
string rawData = JsonConvert.SerializeObject(newStatus);
saveAndSendMessage(mHash("Machine:Status:Current"), rawData, "status", rawData);
diff --git a/MachineSim/Simulator.cs b/MachineSim/Simulator.cs
index 9109cd1..7380025 100644
--- a/MachineSim/Simulator.cs
+++ b/MachineSim/Simulator.cs
@@ -1,4 +1,5 @@
using MathNet.Numerics.Distributions;
+using MP.MONO.Core;
using MP.MONO.Core.DTO;
using Newtonsoft.Json;
using System;
@@ -17,6 +18,9 @@ namespace MachineSim
protected string basePath = "";
protected string paramFileName = "SimParams.json";
+
+ protected Random rand = new Random();
+
protected List? currSimPar = new List();
public Simulator(string _basePath)
@@ -139,7 +143,9 @@ namespace MachineSim
public ProductionDTO MachineGetProd()
{
- Random rand = new Random();
+#if false
+ Random rand = new Random();
+#endif
int stdCycle = 5;
ProductionDTO currMachDto = new ProductionDTO()
@@ -154,5 +160,48 @@ namespace MachineSim
};
return currMachDto;
}
+
+
+ ///
+ /// Restituisce stato Macchina simulato come DTO
+ ///
+ ///
+ public MachineDTO MachineGetStatus()
+ {
+#if false
+ Random rand = new Random();
+#endif
+ int maxRun = 5;
+ int maxExe = 7;
+
+ MachineDTO currMachDto = new MachineDTO()
+ {
+ Manufacturer = "Egalware",
+ Model = "SIM Machine",
+ Name = "DEMO 01",
+ SerNumber = "2022-0001",
+ Mode = $"{(Enums.MachRunMode)rand.Next(0, maxRun)}",
+ Status = $"{(Enums.MachExeStatus)rand.Next(0, maxExe)}"
+ };
+
+ return currMachDto;
+ }
+
+ public List getAlarms()
+ {
+ List activeAlarms = new List();
+ //int alarmCode = rand.Next(0, 255);
+ int alarmCode = rand.Next(0, 160);
+ // se >= 128 --> 0 (no alarm)
+ alarmCode = alarmCode <= 127 ? alarmCode : 0;
+ for (int i = 0; i < 8; i++)
+ {
+ if ((alarmCode & (1 << i)) != 0)
+ {
+ activeAlarms.Add($"Alarm {i:000}");
+ }
+ }
+ return activeAlarms;
+ }
}
}