diff --git a/LaserGRBL/AssemblyInfo.cs b/LaserGRBL/AssemblyInfo.cs index 1bb6a01a..8e9f2b36 100644 --- a/LaserGRBL/AssemblyInfo.cs +++ b/LaserGRBL/AssemblyInfo.cs @@ -31,5 +31,5 @@ // È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build // utilizzando l'asterisco (*) come descritto di seguito: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion ("5.4.0")] +[assembly: AssemblyVersion ("5.5.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/LaserGRBL/Core/GrblCore.cs b/LaserGRBL/Core/GrblCore.cs index acf46098..140581f3 100644 --- a/LaserGRBL/Core/GrblCore.cs +++ b/LaserGRBL/Core/GrblCore.cs @@ -3851,12 +3851,18 @@ internal ListLLC GetClone() return clone; } + + //internal void FixWeirdMeasures() + //{ + // foreach (LaserLifeCounter LLC in this) + // LLC.FixWeirdMeasures(); + //} } static ListLLC mLLCL; static LaserLifeCounter mCurrentLLC; - private static long mLastStatusHiResTimeNano; - private static long mLastPowerHiResTimeNano; + private static long? mLastStatusHiResTimeNano; + private static long? mLastPowerHiResTimeNano; private static long mLastSave; private static string mLLCFileName; @@ -3946,7 +3952,7 @@ internal void AddTrueLaserTimePower(TimeSpan elapsed, double powerperc) clx = Math.Min(9, Math.Max(0, clx)); //ensure 0-9 range mTimeClasses[clx] = mTimeClasses[clx] + elapsed; } - + mLastUsage = DateTime.Today; //System.Diagnostics.Debug.WriteLine($"LT: {mTimeInRun.TotalSeconds} LTT: {mTimeUsageNormalizedPower.TotalSeconds}"); } @@ -3970,6 +3976,22 @@ void IDeserializationCallback.OnDeserialization(object sender) if (mTimeClasses == null) mTimeClasses = new TimeSpan[10]; } + + //internal void FixWeirdMeasures() + //{ + // TimeSpan TT = TimeSpan.Zero; + // foreach (TimeSpan TS in Classes) + // TT = TT.Add(TS); + + // if ( + // LastUsage.HasValue && + // DateTime.Today < new DateTime(2023, 12, 31) && // smette di farlo ad una certa data + // TimeInRun.TotalHours > 100 && // almeno 100 ore + // TimeInRun.TotalHours > ((LastUsage.Value - MonitoringDate.Value).TotalHours + 24) * 2 && //TIR > 2 * DELTA TRA DATE MONITORATE + // TimeInRun.TotalHours > TT.TotalHours * 100 //TIR > 100 volte Classes.Time + // ) + // mTimeInRun = TimeSpan.FromHours(TT.TotalHours * 1.5); //ri-assegna da TT (total time preso dalle classi) esteso * 1.5 + //} } static LaserLifeHandler() @@ -3982,6 +4004,8 @@ static LaserLifeHandler() if (mLLCL == null) mLLCL = new ListLLC(); if (mLLCL.Count == 0) mLLCL.Add(LaserLifeCounter.CreateDefault()); + + //mLLCL.FixWeirdMeasures(); } } @@ -3992,13 +4016,15 @@ public static void ComputeLaserTime(GrblCore.MacStatus status) lock (mLLCL) { long now = HiResTimer.TotalNano; - if (mLastStatusHiResTimeNano != 0) + if (mLastStatusHiResTimeNano != null) { - double delta = now - mLastPowerHiResTimeNano; - double perc = status == MacStatus.Run ? 1 : 0; //potenza da applicare a questo delta - double normal = delta * perc; - - mCurrentLLC?.AddRunTime(TimeSpan.FromMilliseconds(normal / 1000 / 1000)); + long delta = now - mLastPowerHiResTimeNano.Value; + if (delta > 0 && delta < 600000000000L) //do not add delta if bigger then 600s (or negative) - just a safety test + { + double perc = status == MacStatus.Run ? 1 : 0; //potenza da applicare a questo delta + double normal = delta * perc; + mCurrentLLC?.AddRunTime(TimeSpan.FromMilliseconds(normal / 1000 / 1000)); + } } mLastStatusHiResTimeNano = now; } @@ -4020,15 +4046,18 @@ public static void ComputeLaserTrueTime(float power) lock (mLLCL) { long now = HiResTimer.TotalNano; - if (mLastPowerHiResTimeNano != 0) + if (mLastPowerHiResTimeNano != null) { - double elapsed = now - mLastPowerHiResTimeNano; - decimal maxpwm = Configuration.MaxPWM; + long delta = now - mLastPowerHiResTimeNano.Value; + if (delta > 0 && delta < 600000000000L) //do not add delta if bigger then 600s (or negative) - just a safety test + { + decimal maxpwm = Configuration.MaxPWM; - if (maxpwm >= 10 && maxpwm <= 100000) //we have a configured value in a valid range - { - double powerperc = Math.Max(0, Math.Min(1, (double)power / (double)maxpwm)); //potenza da applicare a questo delta - mCurrentLLC?.AddTrueLaserTimePower(TimeSpan.FromMilliseconds(elapsed / 1000 / 1000), powerperc); + if (maxpwm >= 10 && maxpwm <= 100000) //we have a configured value in a valid range + { + double powerperc = Math.Max(0, Math.Min(1, (double)power / (double)maxpwm)); //potenza da applicare a questo delta + mCurrentLLC?.AddTrueLaserTimePower(TimeSpan.FromMilliseconds((double)delta / 1000000.0), powerperc); + } } } mLastPowerHiResTimeNano = now; diff --git a/LaserGRBL/MainForm.cs b/LaserGRBL/MainForm.cs index 878c4f87..88b776e0 100644 --- a/LaserGRBL/MainForm.cs +++ b/LaserGRBL/MainForm.cs @@ -294,6 +294,7 @@ void MainFormFormClosing(object sender, FormClosingEventArgs e) private void UpdateTimer_Tick(object sender, EventArgs e) { + long foo = HiResTimer.TotalNano; //ensure call TotalNano to be able to detect and fix sleep/hibernation TimerUpdate(); ConnectionForm.TimerUpdate(); PreviewForm.TimerUpdate(); diff --git a/LaserGRBL/Tools/HiResTimer.cs b/LaserGRBL/Tools/HiResTimer.cs index 461cbc9d..3f5f8a5d 100644 --- a/LaserGRBL/Tools/HiResTimer.cs +++ b/LaserGRBL/Tools/HiResTimer.cs @@ -215,11 +215,15 @@ public static long TotalNano ComputeFrequency(now); TimeReference delta = now.Subtract(mLastReference); + long deltaNano = delta.IsGoodHiRes() ? delta.HiResNano : delta.LowResNano; + long nanoSleepThreshold = 10000000000L; // se passano più di 10s tra due chiamate abbiamo avuto una sleep da non conteggiare! (assicurati di chiamare TotalNano con una frequenza più alta) - if (delta.IsGoodHiRes()) - mTotalNano = mTotalNano + Math.Max(0, delta.HiResNano); + if (deltaNano < 0) + LaserGRBL.Logger.LogMessage("Issue detector", "Negative delta detected!"); + else if (deltaNano > nanoSleepThreshold) + LaserGRBL.Logger.LogMessage("Issue detector", "System sleep/hibernation detected ({0}s)", deltaNano / 1000000000L); else - mTotalNano = mTotalNano + Math.Max(0, delta.LowResNano); + mTotalNano += deltaNano; mLastReference = now; diff --git a/setup.iss b/setup.iss index 24961d08..13ab12b9 100644 --- a/setup.iss +++ b/setup.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "LaserGRBL" -#define MyAppVersion "5.4.0" +#define MyAppVersion "5.5.0" #define MyAppVersionName "Rhydon" #define MyAppPublisher "LaserGRBL" #define MyAppURL "https://lasergrbl.com"