| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 | using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net.Http;using System.Net;using System.Text;using System.Threading.Tasks;using System.Web.Http;using XdCxRhDw.Dto;using XdCxRhDW.Core.Api;using XdCxRhDW.WebApi;using System.ComponentModel.DataAnnotations;namespace XdCxRhDW.WebApi.Controllers{    /// <summary>    /// 检测参估功能相关接口    /// </summary>    public class DetectCgController : BaseController    {        /// <summary>        /// CPU参估计算        /// </summary>        /// <param name="dto">CPU参估参数</param>        /// <returns></returns>        [HttpPost]        public async Task<AjaxResult<CpuCgResDto>> CpuCgCalc(CpuCgDto dto)        {            dto.file1 = GetLocalFile(dto.file1);            dto.file2 = GetLocalFile(dto.file2);            XcorrStruct xItem = new XcorrStruct();            xItem.file1 = dto.file1;            xItem.file2 = dto.file2;            xItem.samplingRate = dto.samplingRate;            xItem.dtCenter = dto.dtCenter;            xItem.dtRange = dto.dtRange;            xItem.dfRange = dto.dfRange;            //样点数为0时计算所有样本            if (dto.smpCount == 0)            {                FileInfo file = new FileInfo(dto.file1);                long totalsamp = file.Length / 4;                xItem.smpCount = (int)totalsamp - dto.smpStart;            }            else            {                xItem.smpCount = dto.smpCount;            }            xItem.smpStart = dto.smpStart;            xItem.snrThreshold = dto.snrThreshold;            CpuCgResDto resDto = new CpuCgResDto();            try            {                XcorrUtils xcorr = new XcorrUtils();                var result = await xcorr.Calc(xItem);                //开始计算                if (result.flag == -2)                {                    Serilog.Log.Warning("参估计算内部错误!");                    return Error<CpuCgResDto>("参估计算内部错误!");                }                else if (result.flag == -1)                {                    Serilog.Log.Warning("参估计算所需数据超出文件范围!");                    return Error<CpuCgResDto>("参估计算所需数据超出文件范围!");                }                resDto.TimeMs = result.tm;                resDto.Smpstart = result.smpstart;                resDto.Smplen = result.smplen;                resDto.File1 = result.file1;                resDto.File2 = result.file2;                if (result.flag == 1)                {                    resDto.Dt = result.dt.Value;                    resDto.Df = result.df.Value;                    resDto.Snr = result.snr.Value;                }            }            catch (Exception ex)            {                return Error<CpuCgResDto>($"执行参估计算异常,{ex.Message}");            }            finally            {                try                {                    //删除计算得文件                    File.Delete(dto.file1);                    File.Delete(dto.file2);                }                catch                {                }            }            return Success(resDto);        }        /// <summary>        /// 信号检测(支持DAMA、IBS、能量检测)        /// </summary>        /// <param name="dto">信号检测参数</param>        /// <returns></returns>        [HttpPost]        public async Task<AjaxResult<IEnumerable<DetectResDto>>> DetectCalc(DetectDto dto)        {            dto.file1 = GetLocalFile(dto.file1);            List<DetectResDto> list = new List<DetectResDto>();            try            {                XcorrUtils xcorr = new XcorrUtils();                var dmcResult = await xcorr.DmcCheckAsync(dto.file1, dto.fsHz, dto.dmcType);                foreach (var dmcItem in dmcResult)                {                    DetectResDto detectRes = new DetectResDto(dmcItem.Start, dmcItem.Length, dmcItem.UserName);                    detectRes.SigType = dmcItem.SigType;                    detectRes.File1 = dto.file1;                    detectRes.TimeMs = dmcItem.Times;                    list.Add(detectRes);                }            }            catch (Exception ex)            {                return Error<IEnumerable<DetectResDto>>($"执行检测计算异常,{ex.Message}");            }            finally            {                try                {                    //删除检测的文件                    File.Delete(dto.file1);                }                catch                {                }            }            return Success<IEnumerable<DetectResDto>>(list);        }    }}
 |