diff --git a/App.xaml.cs b/App.xaml.cs index fd34e5e..b9c5ca1 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -57,6 +57,7 @@ public partial class App : Application DispatcherUnhandledException += (s, ex) => { MessageBox.Show($"致命错误: {ex.Exception.Message}"); + Logger.Error($"发生致命错误!!!{ex.Exception.Message}{ex.Exception.StackTrace}"); ex.Handled = true; }; Logger.Info("==== ==== ==== ==== ==== ==== ==== ===="); diff --git a/Language/zh_CN.xaml b/Language/zh_CN.xaml index 9a1c6d4..a4d5fa0 100644 --- a/Language/zh_CN.xaml +++ b/Language/zh_CN.xaml @@ -201,7 +201,7 @@ P004:JSON解析失败 P021:检测到钻石需进行清洁 P011:未检测到钻石 - S007:请检查切工仪设备舱门是否关闭 + 请检查切工仪设备舱门是否关闭 算法运行异常: 检测结果为空: diff --git a/Model/Entity/ApiEntity/HttpSendResult.cs b/Model/Entity/ApiEntity/HttpSendResult.cs index 0821e1d..88255fe 100644 --- a/Model/Entity/ApiEntity/HttpSendResult.cs +++ b/Model/Entity/ApiEntity/HttpSendResult.cs @@ -2,9 +2,9 @@ using SparkClient.Model.Services; namespace SparkClient.Model.Entity.ApiEntity; -public class HttpSendResult +public class HttpSendResult where T : ResponseStatus { public int StatusCode { get; set; } = 500; public string Message { get; set; } - public ResponseStatus Content { get; set; } + public T Content { get; set; } } \ No newline at end of file diff --git a/Model/Services/SOCClientService.cs b/Model/Services/SOCClientService.cs index 1284edc..49bd3b6 100644 --- a/Model/Services/SOCClientService.cs +++ b/Model/Services/SOCClientService.cs @@ -63,7 +63,7 @@ namespace SparkClient.Model.Services /// /// 请求的完整URL /// HTTP响应 - private async Task SendGetRequestAsync(string url, string sendCode = "") + private async Task> SendGetRequestAsync(string url, string sendCode = "", JsonSerializerSettings settings = null)where T : ResponseStatus { if (sendCode.IsNullOrEmpty()) { @@ -81,15 +81,15 @@ namespace SparkClient.Model.Services int statusCode = (int)result.StatusCode; // 记录日志 Logger.Info($"[SendCode={sendCode}]Response: Status={statusCode}, Body={responseBody}"); - var tempEntity = JsonConvert.DeserializeObject(responseBody); + var tempEntity = JsonConvert.DeserializeObject(responseBody, settings); if (StatusCodes.PreviousTaskIncomplete.Equals(tempEntity.Status)) { Logger.Info($"S009 请求重试"); await Task.Delay(500); - return await SendGetRequestAsync(url, sendCode); + return await SendGetRequestAsync(url, sendCode); } - return new HttpSendResult() + return new HttpSendResult() { StatusCode = statusCode, Content = tempEntity, @@ -150,7 +150,7 @@ namespace SparkClient.Model.Services string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}"; - var response = await SendGetRequestAsync(url); + var response = await SendGetRequestAsync(url); if (response.StatusCode != 200) { @@ -187,7 +187,7 @@ namespace SparkClient.Model.Services /// 启动图片收集任务。 /// /// 任务状态 - public Task CollectImagesAsyncNotAwait() + public Task> CollectImagesAsyncNotAwait() { try { @@ -221,7 +221,7 @@ namespace SparkClient.Model.Services string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}"; - var result = SendGetRequestAsync(url); + var result = SendGetRequestAsync(url); return result; @@ -319,7 +319,7 @@ namespace SparkClient.Model.Services } } } - + /// /// 获取图片采集状态。 /// @@ -330,7 +330,7 @@ namespace SparkClient.Model.Services try { - var response = await SendGetRequestAsync(url); + var response = await SendGetRequestAsync(url); Logger.Debug($" CollectStatusAsync url :{ url} "); if (response.StatusCode == 200) { @@ -467,7 +467,7 @@ namespace SparkClient.Model.Services GenImage = true; try { - var response = await SendGetRequestAsync(url); + var response = await SendGetRequestAsync(url); Logger.Debug(url); if (response.StatusCode == 200) { @@ -500,7 +500,7 @@ namespace SparkClient.Model.Services Logger.Debug(url); try { - var response = await SendGetRequestAsync(url); + var response = await SendGetRequestAsync(url); if (response.StatusCode == 200) { @@ -518,6 +518,32 @@ namespace SparkClient.Model.Services return StatusCodes.DeviceNotFound; } } + + public async Task GetGpioStatus() + { + // GpioStatus + string url = $"{_baseUrl}/gpio_check"; + Logger.Info($"舱门状态检查开始:{url}"); + try + { + var response = await SendGetRequestAsync(url); + + if (response.StatusCode == 200) + { + var result = response.Content; + Logger.Info($"Set Pump : {result.ToSafeAbundantString()} "); + return result; + } + Logger.Info($"舱门状态检查完毕,接口status非200视为关闭"); + return GpioStatus.Default(); + } + catch (Exception e) + { + string logMessage = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] 发生异常: {e.Message}{Environment.NewLine}"; + Logger.Error(logMessage); + return GpioStatus.Default(); + } + } } @@ -541,4 +567,39 @@ namespace SparkClient.Model.Services /// public string device_id { get; set; } } + + public class GpioStatus : ResponseStatus + { + public int Value1 { get; set; } + public int Value2 { get; set; } + + public bool LensGpioIsOpen() + { + return Value1 == 48; + } + + public bool DiamondGpioIsOpen() + { + return Value2 == 48; + } + public bool LensGpioIsClose() + { + return Value1 == 49; + } + + public bool DiamondGpioIsClose() + { + return Value2 == 49; + } + + public static GpioStatus Default() + { + return new GpioStatus + { + Status = "S000", + Value1 = 48, + Value2 = 48 + }; + } + } } diff --git a/Resource/Document/Helper.pdf b/Resource/Document/Helper.pdf index cc28659..1cc824e 100644 Binary files a/Resource/Document/Helper.pdf and b/Resource/Document/Helper.pdf differ diff --git a/Resource/Document/Helper_en.pdf b/Resource/Document/Helper_en.pdf index 113521d..3b0e3ea 100644 Binary files a/Resource/Document/Helper_en.pdf and b/Resource/Document/Helper_en.pdf differ diff --git a/ViewModel/Grading/DiamondSelectVM.cs b/ViewModel/Grading/DiamondSelectVM.cs index a55a8f1..9c52eae 100644 --- a/ViewModel/Grading/DiamondSelectVM.cs +++ b/ViewModel/Grading/DiamondSelectVM.cs @@ -156,6 +156,15 @@ public class DiamondSelectVM : BaseViewModel [Log] public async void StartGrading(object param) { + Logger.Info($"开始检测钻石{param.ToSafeAbundantString()}"); + //新增检测舱门 + GpioStatus gpioStatus = await SOCClientService.Service.GetGpioStatus(); + + if (gpioStatus.LensGpioIsOpen() || gpioStatus.DiamondGpioIsOpen()) + { + new MessageBox().Show(MultilingualHelper.getString("OpenOfTheHatch")); + return; + } //m每次都备份一下最新的检测参数 Common.LastParam = param; MessageBox messageBox = new MessageBox(); diff --git a/ViewModel/Grading/GradingLoadingVM.cs b/ViewModel/Grading/GradingLoadingVM.cs index 55f1f1e..094c3da 100644 --- a/ViewModel/Grading/GradingLoadingVM.cs +++ b/ViewModel/Grading/GradingLoadingVM.cs @@ -120,6 +120,10 @@ public class GradingLoadingVM : BaseViewModel,IDisposable #endregion private bool _isCancel = false; + + private static Timer _monitorTimer; + private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); + public GradingLoadingVM(string diamnondType, string diamondCode) { _diamondCode = diamondCode; @@ -133,8 +137,39 @@ public class GradingLoadingVM : BaseViewModel,IDisposable _progressCts = new CancellationTokenSource(); _playbackCts = new CancellationTokenSource(); _completionCts = new CancellationTokenSource(); + + Logger.Info("周期检查舱门,周期500ms"); + if (_monitorTimer == null) + { + _monitorTimer = new Timer(CheckSpeedCallback, + null, + 500, + Timeout.Infinite); + } } + private async void CheckSpeedCallback(object state) + { + try + { + GpioStatus gpioStatus = await SOCClientService.Service.GetGpioStatus(); + if (gpioStatus.LensGpioIsOpen() || gpioStatus.DiamondGpioIsOpen()) + { + new MessageBox().Show(MultilingualHelper.getString("OpenOfTheHatch")); + WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); + _scanner?.Cancel(); + _isCancel = true; + _progressCts.Cancel(); + this.Dispose(); + return; + } + } + catch (Exception ex) + { + Logger.Info($"监控异常: {ex.Message}"); + } + } + /// /// 开始检测 /// @@ -297,7 +332,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable new JProperty("algorithm_log_path", algorithm_log_path), new JProperty("algo_config", JObject.Parse(algo_config)) ); - Logger.Info($"算法启动,输入参数:{jsonData.ToString()}"); + Logger.Info($"算法启动,输入参数(Encrypt):{AESHelper.Encrypt(jsonData.ToString())}"); _scanner = new Scanner(diamond); var detectTask = _scanner.DetectAsyncByJsonStr(jsonData.ToString()); Logger.Info($"开始等待算法结果"); @@ -399,11 +434,16 @@ public class GradingLoadingVM : BaseViewModel,IDisposable if (!Directory.Exists(outputPath)) Directory.CreateDirectory(outputPath); string outputFilePath = $"{outputPath}/{_diamondCode}-{DateTime.Now:yyyyMMdd_HHmmss}.json"; - using (var file = File.Create(outputFilePath)) - using (StreamWriter stream = new StreamWriter(file)) - { - stream.Write(parameterJson); - } + + byte[] data = Encoding.Unicode.GetBytes(parameterJson); + byte[] outData = AESHelper.Encrypt(data); + File.WriteAllBytes(outputFilePath, outData); + //using (var file = File.Create(outputFilePath)) + + // using (StreamWriter stream = new StreamWriter(file)) + // { + // stream.Write(parameterJson); + // } Logger.Info($"算法结果Json单独保存至log/result 完毕!"); } catch (Exception ex)