added periodic recreation of the LHM objects, to prevent memory leaks
This commit is contained in:
@@ -40,16 +40,17 @@ const uint8_t pwmResolution = 10; // 10-bit resolution (0–1023)
|
||||
float logicalPoints[5] = {0, 25, 50, 75, 100};
|
||||
|
||||
float calibratedPoints[NUM_CHANNELS][5] = {
|
||||
{0, 25, 50, 75, 99},
|
||||
{0, 24, 49, 74, 98},
|
||||
{0, 26, 51, 76, 99},
|
||||
{0, 25, 50, 75, 97},
|
||||
{0, 25, 50, 75, 99},
|
||||
{0, 24, 50, 74, 98},
|
||||
{0, 25, 49, 75, 97},
|
||||
{0, 26, 50, 76, 99}
|
||||
{0.0f, 25.0f, 50.0f, 75.0f, 99.0f},
|
||||
{0.0f, 24.0f, 49.0f, 74.0f, 98.0f},
|
||||
{0.0f, 26.0f, 51.0f, 76.0f, 99.0f},
|
||||
{0.0f, 25.0f, 50.0f, 75.0f, 97.0f},
|
||||
{0.0f, 25.0f, 50.0f, 75.0f, 99.0f},
|
||||
{0.0f, 24.0f, 50.0f, 74.0f, 98.0f},
|
||||
{0.0f, 25.0f, 49.0f, 75.0f, 97.0f},
|
||||
{0.0f, 26.0f, 50.0f, 76.0f, 99.0f}
|
||||
};
|
||||
|
||||
|
||||
// -------------------------------
|
||||
// Duty tracking + Slew system
|
||||
// -------------------------------
|
||||
|
||||
@@ -10,7 +10,7 @@ public class Telemetry : IDisposable
|
||||
public int UpdateRateMs => UpdateRateDefaultMs;
|
||||
|
||||
private readonly UdpSender udp = new UdpSender();
|
||||
private readonly Computer computer = new Computer();
|
||||
private Computer computer = new Computer();
|
||||
|
||||
private IHardware? cpuHw;
|
||||
private IHardware? gpuHw;
|
||||
@@ -29,25 +29,70 @@ public class Telemetry : IDisposable
|
||||
|
||||
private static readonly CultureInfo CI = CultureInfo.InvariantCulture;
|
||||
|
||||
// Restart LHM every 30 minutes
|
||||
private readonly TimeSpan restartInterval = TimeSpan.FromMinutes(30);
|
||||
private DateTime lastRestart = DateTime.UtcNow;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
ConfigureComputer();
|
||||
computer.Open();
|
||||
CacheHardwareAndSensors();
|
||||
}
|
||||
|
||||
private void ConfigureComputer()
|
||||
{
|
||||
computer.IsCpuEnabled = true;
|
||||
computer.IsGpuEnabled = true;
|
||||
computer.IsMemoryEnabled = true;
|
||||
// Disable everything else (true minimal mode)
|
||||
computer.IsMotherboardEnabled = false;
|
||||
computer.IsControllerEnabled = false;
|
||||
computer.IsNetworkEnabled = false;
|
||||
computer.IsStorageEnabled = false;
|
||||
computer.IsBatteryEnabled = false;
|
||||
|
||||
// True minimal mode
|
||||
computer.IsMotherboardEnabled = false;
|
||||
computer.IsControllerEnabled = false;
|
||||
computer.IsNetworkEnabled = false;
|
||||
computer.IsStorageEnabled = false;
|
||||
computer.IsBatteryEnabled = false;
|
||||
}
|
||||
|
||||
private void RestartComputerIfNeeded()
|
||||
{
|
||||
if (DateTime.UtcNow - lastRestart < restartInterval)
|
||||
return;
|
||||
|
||||
lastRestart = DateTime.UtcNow;
|
||||
|
||||
try
|
||||
{
|
||||
computer.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
computer = new Computer();
|
||||
ConfigureComputer();
|
||||
computer.Open();
|
||||
CacheHardwareAndSensors();
|
||||
}
|
||||
|
||||
private void CacheHardwareAndSensors()
|
||||
{
|
||||
cpuHw = null;
|
||||
gpuHw = null;
|
||||
memHw = null;
|
||||
|
||||
cpuLoadSensors = Array.Empty<ISensor>();
|
||||
cpuTempSensor = null;
|
||||
|
||||
gpu3DLoadSensor = null;
|
||||
gpuTempSensor = null;
|
||||
gpuVramUsedSensor = null;
|
||||
gpuVramTotalSensor = null;
|
||||
|
||||
memUsedSensor = null;
|
||||
memAvailSensor = null;
|
||||
|
||||
foreach (var hw in computer.Hardware)
|
||||
{
|
||||
hw.Update();
|
||||
@@ -141,6 +186,8 @@ public class Telemetry : IDisposable
|
||||
|
||||
public void UpdateAndSend()
|
||||
{
|
||||
RestartComputerIfNeeded();
|
||||
|
||||
cpuHw?.Update();
|
||||
gpuHw?.Update();
|
||||
memHw?.Update();
|
||||
|
||||
Reference in New Issue
Block a user