DetectCgController.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using System.Web.Http;
  8. using DevExpress.Data.Svg;
  9. using XdCxRhDW.Api;
  10. using XdCxRhDW.Dto;
  11. using XdCxRhDW.Repostory;
  12. using XdCxRhDW.WebApi;
  13. namespace XdCxRhDW.App.Controllers
  14. {
  15. /// <summary>
  16. /// 检测参估变采样识别相关接口
  17. /// </summary>
  18. public class DetectCgController : BaseController
  19. {
  20. /// <summary>
  21. /// CPU参估计算(需要先上传文件)
  22. /// </summary>
  23. /// <param name="dto">CPU参估参数</param>
  24. /// <returns></returns>
  25. [HttpPost]
  26. public async Task<AjaxResult<CpuCgResDto>> CpuCgCalc(CpuCgDto dto)
  27. {
  28. try
  29. {
  30. var svr = ServerContext.Instance.GetRandomOne(EnumSvrType.CpuCgSvr);
  31. dto.file1 = await HttpHelper.UploadFileAsync(GetLocalFile(dto.file1), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  32. dto.file2 = await HttpHelper.UploadFileAsync(GetLocalFile(dto.file2), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  33. var res = await HttpHelper.PostRequestAsync<CpuCgResDto>(svr.BaseHttpAddr + "CpuCg/Calc", dto, dto.TimeoutSeconds);
  34. return res;
  35. }
  36. catch (TaskCanceledException)
  37. {
  38. return Error<CpuCgResDto>($"CPU参估超时");
  39. }
  40. }
  41. /// <summary>
  42. /// CPU参估多个时隙的参估计算(需要先上传文件)
  43. /// </summary>
  44. /// <param name="dto">CPU多时隙参估参数模型</param>
  45. /// <returns>返回结果个数始终和传入的时隙个数相同</returns>
  46. [HttpPost]
  47. public async Task<AjaxResult<List<CpuCgResDto>>> CpuCgMultiCalc(CpuCgMultiDto dto)
  48. {
  49. try
  50. {
  51. var svr = ServerContext.Instance.GetRandomOne(EnumSvrType.CpuCgSvr);
  52. dto.file1 = await HttpHelper.UploadFileAsync(GetLocalFile(dto.file1), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  53. dto.file2 = await HttpHelper.UploadFileAsync(GetLocalFile(dto.file2), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  54. var res = await HttpHelper.PostRequestAsync<List<CpuCgResDto>>(svr.BaseHttpAddr + "CpuCg/MultiCalc", dto, dto.TimeoutSeconds);
  55. return res;
  56. }
  57. catch (TaskCanceledException)
  58. {
  59. return Error<List<CpuCgResDto>>($"CPU参估超时({dto.smpPositions.Count}个突发)");
  60. }
  61. }
  62. /// <summary>
  63. /// 参估画图
  64. /// </summary>
  65. /// <returns></returns>
  66. [HttpPost]
  67. public async Task<AjaxResult<List<ImageResultDto>>> DrawImage(CpuCgDto dto)
  68. {
  69. var svr = ServerContext.Instance.GetRandomOne(EnumSvrType.CpuCgSvr);
  70. dto.file1 = await HttpHelper.UploadFileAsync(GetLocalFile(dto.file1), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  71. dto.file2 = await HttpHelper.UploadFileAsync(GetLocalFile(dto.file2), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  72. var res = await HttpHelper.PostRequestAsync<List<ImageResultDto>>(svr.BaseHttpAddr + "CpuCg/DrawImage", dto, dto.TimeoutSeconds);
  73. return res;
  74. }
  75. /// <summary>
  76. /// GPU参估计算(需要先上传文件)
  77. /// </summary>
  78. /// <param name="dto">GPU参估参数</param>
  79. /// <returns></returns>
  80. [HttpPost]
  81. public async Task<AjaxResult<List<GpuCgResponseDto>>> GpuCgCalc(GpuCgRequestDto dto)
  82. {
  83. try
  84. {
  85. var svr = ServerContext.Instance.GetRandomOne(EnumSvrType.GpuCgSvr);
  86. dto.file1 = await HttpHelper.UploadFileAsync(GetLocalFile(dto.file1), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  87. dto.file2 = await HttpHelper.UploadFileAsync(GetLocalFile(dto.file2), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  88. var res = await HttpHelper.PostRequestAsync<List<GpuCgResponseDto>>(svr.BaseHttpAddr + "GpuCg/Calc", dto, dto.TimeoutSeconds);
  89. return res;
  90. }
  91. catch (TaskCanceledException)
  92. {
  93. return Error<List<GpuCgResponseDto>>($"GPU参估超时");
  94. }
  95. }
  96. /// <summary>
  97. /// 信号检测(支持DAMA、IBS、能量检测)(需要先上传文件,会根据信号带宽自动对文件进行滤波)
  98. /// </summary>
  99. /// <param name="dto">信号检测参数</param>
  100. /// <returns></returns>
  101. [HttpPost]
  102. public async Task<AjaxResult<List<DetectResDto>>> DetectCalc(DetectDto dto)
  103. {
  104. try
  105. {
  106. var svr = ServerContext.Instance.GetRandomOne(EnumSvrType.CheckSvr);
  107. dto.file1 = await HttpHelper.UploadFileAsync(GetLocalFile(dto.file1), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  108. var res = await HttpHelper.PostRequestAsync<List<DetectResDto>>(svr.BaseHttpAddr + "Check/Calc", dto, dto.TimeoutSeconds);
  109. if (dto.SigProc && res.data.Any())
  110. {
  111. SignalProcDto procDto = new SignalProcDto()
  112. {
  113. File = dto.file1,
  114. Fs = (long)dto.fsHz,
  115. Smps = res.data.Select(p => new SmpPosition() { smpStart = p.Start, smpCount = p.Length }).ToList(),
  116. };
  117. var procRes = await HttpHelper.PostRequestAsync<List<SignalProcResDto>>(svr.BaseHttpAddr + "Check/SignalProc", procDto);
  118. if (procRes.data == null || res.data.Count != procRes.data.Count)
  119. {
  120. throw new Exception("信号识别结果个数和检测结果个数不一致");
  121. }
  122. for (int i = 0; i < res.data.Count; i++)
  123. {
  124. res.data[i].ModRate = procRes.data[i].Rate;
  125. res.data[i].ModType = procRes.data[i].ModType.GetEnumDisplayName();
  126. res.data[i].FfcHz = procRes.data[i].Ffc;
  127. res.data[i].Snr = procRes.data[i].Snr;
  128. }
  129. }
  130. return res;
  131. }
  132. catch (TaskCanceledException)
  133. {
  134. return Error<List<DetectResDto>>($"信号检测超时");
  135. }
  136. }
  137. /// <summary>
  138. /// 信号识别(调制类型、调制速率、频偏)
  139. /// </summary>
  140. /// <param name="dto">信号检测参数</param>
  141. /// <returns></returns>
  142. [HttpPost]
  143. public async Task<AjaxResult<List<SignalProcResDto>>> SignalProc(SignalProcDto dto)
  144. {
  145. try
  146. {
  147. var svr = ServerContext.Instance.GetRandomOne(EnumSvrType.CheckSvr);
  148. dto.File = await HttpHelper.UploadFileAsync(GetLocalFile(dto.File), svr.BaseHttpAddr);
  149. var res = await HttpHelper.PostRequestAsync<List<SignalProcResDto>>(svr.BaseHttpAddr + "Check/SignalProc", dto);
  150. return res;
  151. }
  152. catch (TaskCanceledException)
  153. {
  154. return Error<List<SignalProcResDto>>($"信号识别超时");
  155. }
  156. }
  157. /// <summary>
  158. /// 滤波处理(滤波处理文件)
  159. /// </summary>
  160. /// <param name="dto">滤波处理参数</param>
  161. /// <returns></returns>
  162. [HttpPost]
  163. public async Task<AjaxResult<SigFilterResponseDto>> SigFilterProc(SigFilterDto dto)
  164. {
  165. try
  166. {
  167. if (dto.BandHz <= 0 || dto.BandHz > dto.FsHz)
  168. {
  169. dto.BandHz = 25000;
  170. //return new AjaxResult<SigFilterResponseDto>() { code = 200, data = new SigFilterResponseDto() { File = dto.File } };
  171. }
  172. var svr = ServerContext.Instance.GetRandomOne(EnumSvrType.CheckSvr);
  173. dto.File = await HttpHelper.UploadFileAsync(GetLocalFile(dto.File), svr.BaseHttpAddr);
  174. var res = await HttpHelper.PostRequestAsync<SigFilterResponseDto>(svr.BaseHttpAddr + "Check/SigFilterProc", dto);
  175. await HttpHelper.DownloadFileAsync(svr.BaseHttpAddr, res.data.File, GetLocalFile(res.data.File), dto.TimeoutSeconds);
  176. return res;
  177. }
  178. catch (TaskCanceledException)
  179. {
  180. return Error<SigFilterResponseDto>($"信号滤波超时");
  181. }
  182. }
  183. /// <summary>
  184. /// 文件变采样(需要先上传文件)
  185. /// </summary>
  186. /// <param name="dto"></param>
  187. /// <returns></returns>
  188. public async Task<AjaxResult<ResampleResponseDto>> Resample(ResampleRequestDto dto)
  189. {
  190. var svr = ServerContext.Instance.GetRandomOne(EnumSvrType.CheckSvr);
  191. dto.File = await HttpHelper.UploadFileAsync(GetLocalFile(dto.File), svr.BaseHttpAddr, timeoutSeconds: dto.TimeoutSeconds);
  192. var res = await HttpHelper.PostRequestAsync<ResampleResponseDto>(svr.BaseHttpAddr + "Check/Resample", dto, dto.TimeoutSeconds);
  193. await HttpHelper.DownloadFileAsync(svr.BaseHttpAddr, res.data.File, GetLocalFile(res.data.File), dto.TimeoutSeconds);
  194. return res;
  195. }
  196. }
  197. }