feat: Implement door status detection and update docs

master
Tongg 8 months ago
parent c9e8170f2b
commit 5a75440f9b
  1. 1
      App.xaml.cs
  2. 2
      Language/zh_CN.xaml
  3. 4
      Model/Entity/ApiEntity/HttpSendResult.cs
  4. 83
      Model/Services/SOCClientService.cs
  5. BIN
      Resource/Document/Helper.pdf
  6. BIN
      Resource/Document/Helper_en.pdf
  7. 9
      ViewModel/Grading/DiamondSelectVM.cs
  8. 52
      ViewModel/Grading/GradingLoadingVM.cs

@ -57,6 +57,7 @@ public partial class App : Application
DispatcherUnhandledException += (s, ex) => DispatcherUnhandledException += (s, ex) =>
{ {
MessageBox.Show($"致命错误: {ex.Exception.Message}"); MessageBox.Show($"致命错误: {ex.Exception.Message}");
Logger.Error($"发生致命错误!!!{ex.Exception.Message}{ex.Exception.StackTrace}");
ex.Handled = true; ex.Handled = true;
}; };
Logger.Info("==== ==== ==== ==== ==== ==== ==== ===="); Logger.Info("==== ==== ==== ==== ==== ==== ==== ====");

@ -201,7 +201,7 @@
<sys:String x:Key="JsonParseFailure">P004:JSON解析失败</sys:String> <sys:String x:Key="JsonParseFailure">P004:JSON解析失败</sys:String>
<sys:String x:Key="Recheck">P021:检测到钻石需进行清洁</sys:String> <sys:String x:Key="Recheck">P021:检测到钻石需进行清洁</sys:String>
<sys:String x:Key="NoDiamond">P011:未检测到钻石</sys:String> <sys:String x:Key="NoDiamond">P011:未检测到钻石</sys:String>
<sys:String x:Key="OpenOfTheHatch">S007:请检查切工仪设备舱门是否关闭</sys:String> <sys:String x:Key="OpenOfTheHatch">请检查切工仪设备舱门是否关闭</sys:String>
<sys:String x:Key="DETECTING_EXCEPTION">算法运行异常:</sys:String> <sys:String x:Key="DETECTING_EXCEPTION">算法运行异常:</sys:String>
<sys:String x:Key="DETECTING_RESULT_ISNULL">检测结果为空:</sys:String> <sys:String x:Key="DETECTING_RESULT_ISNULL">检测结果为空:</sys:String>

@ -2,9 +2,9 @@ using SparkClient.Model.Services;
namespace SparkClient.Model.Entity.ApiEntity; namespace SparkClient.Model.Entity.ApiEntity;
public class HttpSendResult public class HttpSendResult<T> where T : ResponseStatus
{ {
public int StatusCode { get; set; } = 500; public int StatusCode { get; set; } = 500;
public string Message { get; set; } public string Message { get; set; }
public ResponseStatus Content { get; set; } public T Content { get; set; }
} }

@ -63,7 +63,7 @@ namespace SparkClient.Model.Services
/// </summary> /// </summary>
/// <param name="url">请求的完整URL</param> /// <param name="url">请求的完整URL</param>
/// <returns>HTTP响应</returns> /// <returns>HTTP响应</returns>
private async Task<HttpSendResult> SendGetRequestAsync(string url, string sendCode = "") private async Task<HttpSendResult<T>> SendGetRequestAsync<T>(string url, string sendCode = "", JsonSerializerSettings settings = null)where T : ResponseStatus
{ {
if (sendCode.IsNullOrEmpty()) if (sendCode.IsNullOrEmpty())
{ {
@ -81,15 +81,15 @@ namespace SparkClient.Model.Services
int statusCode = (int)result.StatusCode; int statusCode = (int)result.StatusCode;
// 记录日志 // 记录日志
Logger.Info($"[SendCode={sendCode}]Response: Status={statusCode}, Body={responseBody}"); Logger.Info($"[SendCode={sendCode}]Response: Status={statusCode}, Body={responseBody}");
var tempEntity = JsonConvert.DeserializeObject<ResponseStatus>(responseBody); var tempEntity = JsonConvert.DeserializeObject<T>(responseBody, settings);
if (StatusCodes.PreviousTaskIncomplete.Equals(tempEntity.Status)) if (StatusCodes.PreviousTaskIncomplete.Equals(tempEntity.Status))
{ {
Logger.Info($"S009 请求重试"); Logger.Info($"S009 请求重试");
await Task.Delay(500); await Task.Delay(500);
return await SendGetRequestAsync(url, sendCode); return await SendGetRequestAsync<T>(url, sendCode);
} }
return new HttpSendResult() return new HttpSendResult<T>()
{ {
StatusCode = statusCode, StatusCode = statusCode,
Content = tempEntity, Content = tempEntity,
@ -150,7 +150,7 @@ namespace SparkClient.Model.Services
string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}"; string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}";
var response = await SendGetRequestAsync(url); var response = await SendGetRequestAsync<ResponseStatus>(url);
if (response.StatusCode != 200) if (response.StatusCode != 200)
{ {
@ -187,7 +187,7 @@ namespace SparkClient.Model.Services
/// 启动图片收集任务。 /// 启动图片收集任务。
/// </summary> /// </summary>
/// <returns>任务状态</returns> /// <returns>任务状态</returns>
public Task<HttpSendResult> CollectImagesAsyncNotAwait() public Task<HttpSendResult<ResponseStatus>> CollectImagesAsyncNotAwait()
{ {
try try
{ {
@ -221,7 +221,7 @@ namespace SparkClient.Model.Services
string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}"; string url = $"{_baseUrl}/collect_images?light_level={lightLevel}&half_circle={halfCircle}";
var result = SendGetRequestAsync(url); var result = SendGetRequestAsync<ResponseStatus>(url);
return result; return result;
@ -319,7 +319,7 @@ namespace SparkClient.Model.Services
} }
} }
} }
/// <summary> /// <summary>
/// 获取图片采集状态。 /// 获取图片采集状态。
/// </summary> /// </summary>
@ -330,7 +330,7 @@ namespace SparkClient.Model.Services
try try
{ {
var response = await SendGetRequestAsync(url); var response = await SendGetRequestAsync<ResponseStatus>(url);
Logger.Debug($" CollectStatusAsync url :{ url} "); Logger.Debug($" CollectStatusAsync url :{ url} ");
if (response.StatusCode == 200) if (response.StatusCode == 200)
{ {
@ -467,7 +467,7 @@ namespace SparkClient.Model.Services
GenImage = true; GenImage = true;
try try
{ {
var response = await SendGetRequestAsync(url); var response = await SendGetRequestAsync<ResponseStatus>(url);
Logger.Debug(url); Logger.Debug(url);
if (response.StatusCode == 200) if (response.StatusCode == 200)
{ {
@ -500,7 +500,7 @@ namespace SparkClient.Model.Services
Logger.Debug(url); Logger.Debug(url);
try try
{ {
var response = await SendGetRequestAsync(url); var response = await SendGetRequestAsync<ResponseStatus>(url);
if (response.StatusCode == 200) if (response.StatusCode == 200)
{ {
@ -518,6 +518,32 @@ namespace SparkClient.Model.Services
return StatusCodes.DeviceNotFound; return StatusCodes.DeviceNotFound;
} }
} }
public async Task<GpioStatus> GetGpioStatus()
{
// GpioStatus
string url = $"{_baseUrl}/gpio_check";
Logger.Info($"舱门状态检查开始:{url}");
try
{
var response = await SendGetRequestAsync<GpioStatus>(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
/// </summary> /// </summary>
public string device_id { get; set; } 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
};
}
}
} }

Binary file not shown.

Binary file not shown.

@ -156,6 +156,15 @@ public class DiamondSelectVM : BaseViewModel
[Log] [Log]
public async void StartGrading(object param) 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每次都备份一下最新的检测参数 //m每次都备份一下最新的检测参数
Common.LastParam = param; Common.LastParam = param;
MessageBox messageBox = new MessageBox(); MessageBox messageBox = new MessageBox();

@ -120,6 +120,10 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
#endregion #endregion
private bool _isCancel = false; private bool _isCancel = false;
private static Timer _monitorTimer;
private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
public GradingLoadingVM(string diamnondType, string diamondCode) public GradingLoadingVM(string diamnondType, string diamondCode)
{ {
_diamondCode = diamondCode; _diamondCode = diamondCode;
@ -133,8 +137,39 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
_progressCts = new CancellationTokenSource(); _progressCts = new CancellationTokenSource();
_playbackCts = new CancellationTokenSource(); _playbackCts = new CancellationTokenSource();
_completionCts = 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}");
}
}
/// <summary> /// <summary>
/// 开始检测 /// 开始检测
/// </summary> /// </summary>
@ -297,7 +332,7 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
new JProperty("algorithm_log_path", algorithm_log_path), new JProperty("algorithm_log_path", algorithm_log_path),
new JProperty("algo_config", JObject.Parse(algo_config)) new JProperty("algo_config", JObject.Parse(algo_config))
); );
Logger.Info($"算法启动,输入参数:{jsonData.ToString()}"); Logger.Info($"算法启动,输入参数(Encrypt):{AESHelper.Encrypt(jsonData.ToString())}");
_scanner = new Scanner(diamond); _scanner = new Scanner(diamond);
var detectTask = _scanner.DetectAsyncByJsonStr(jsonData.ToString()); var detectTask = _scanner.DetectAsyncByJsonStr(jsonData.ToString());
Logger.Info($"开始等待算法结果"); Logger.Info($"开始等待算法结果");
@ -399,11 +434,16 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
if (!Directory.Exists(outputPath)) if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath); Directory.CreateDirectory(outputPath);
string outputFilePath = $"{outputPath}/{_diamondCode}-{DateTime.Now:yyyyMMdd_HHmmss}.json"; string outputFilePath = $"{outputPath}/{_diamondCode}-{DateTime.Now:yyyyMMdd_HHmmss}.json";
using (var file = File.Create(outputFilePath))
using (StreamWriter stream = new StreamWriter(file)) byte[] data = Encoding.Unicode.GetBytes(parameterJson);
{ byte[] outData = AESHelper.Encrypt(data);
stream.Write(parameterJson); File.WriteAllBytes(outputFilePath, outData);
} //using (var file = File.Create(outputFilePath))
// using (StreamWriter stream = new StreamWriter(file))
// {
// stream.Write(parameterJson);
// }
Logger.Info($"算法结果Json单独保存至log/result 完毕!"); Logger.Info($"算法结果Json单独保存至log/result 完毕!");
} }
catch (Exception ex) catch (Exception ex)

Loading…
Cancel
Save