1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Threading.Tasks;
- using System.Collections;
- using System.Collections.Generic;
- using XdCxRhDW.Dto;
- using System.Security.Policy;
- namespace CheckServer
- {
-
- public static class CheckHelper
- {
- public static async Task<IEnumerable<DmcResult>> DmcCheckAsync(string fileName, double fsHz, DmcType dmcType, double? bandKHz = null)
- {
- if (bandKHz == null || bandKHz.Value <= 0) bandKHz = 25;
- string dmcCmd = "all";
- var dmp = new Process();
- string pFileName = Path.Combine(dmp.StartInfo.WorkingDirectory, "AddIns\\dmc.exe");
- string pArguments = string.Empty;
- switch (dmcType)
- {
- case DmcType.DAMA:
- dmcCmd = "dm";
- if (fsHz != 96000)
- throw new Exception("DAMA只支持96K采样率");
- pArguments = $"{dmcCmd} \"{fileName}\" -c true";//-c包含ccow
- break;
- case DmcType.IBS:
- dmcCmd = "nd";
- pArguments = $"{dmcCmd} \"{fileName}\" -w {bandKHz}";// -f {fs}" -c --dmfirst";
- break;
- case DmcType.Ky5758:
- pFileName = Path.Combine(dmp.StartInfo.WorkingDirectory, "AddIns\\enc.exe");
- //enc.exe enc-test.dat 0.096 5 0全部文件
- pArguments = $"{fileName} {fsHz * 1e-6} {5} {0}";
- break;
- default:
- break;
- }
- return await Task.Run(() =>
- {
- dmp.StartInfo.FileName = pFileName;
- dmp.StartInfo.Arguments = pArguments;
- dmp.StartInfo.CreateNoWindow = true;
- dmp.StartInfo.RedirectStandardError = true;
- dmp.StartInfo.RedirectStandardOutput = true;
- dmp.StartInfo.UseShellExecute = false;
- dmp.Start();
- Stopwatch stopWatch = new Stopwatch();
- stopWatch.Start();
- dmp.WaitForExit();
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- var str = dmp.StandardOutput.ReadToEnd();
- return ConvertDmcResult(dmcType, str, ts.TotalMilliseconds);
- });
- }
- private static IEnumerable<DmcResult> ConvertDmcResult(DmcType type, string res, double tm)
- {
- var lines = res.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
- foreach (var line in lines)
- {
- var items = line.Split('\t');
- if (items.Length < 2) continue;
- int start = int.Parse(items[0]);
- int length = int.Parse(items[1]);
- string userName = "";
- if (items.Length >= 3)
- userName = items[2];
- var item = new DmcResult(start, length, userName, (int)tm);
- if (type == DmcType.DAMA)
- item.ModType = "BPSK";
- else
- item.ModType = string.Empty;
- item.DmcType = type.GetEnumDisplayName();
- yield return item;
- }
- }
- }
- }
|