SignalProcHelper.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace CheckServer
  8. {
  9. public static class SignalProcHelper
  10. {
  11. private const string dll = @"AddIns\SignalProc.dll";
  12. #region cpp dll Interop
  13. [DllImport(dll, EntryPoint = "SigalEst", CallingConvention = CallingConvention.Cdecl)]
  14. private extern static void SigalEst(string file, long fsHz, int[] smpStart, int[] smpCount, int[] modes, double[] rates, double[] ffcs, double[] snrs, int len);
  15. #endregion
  16. static List<int> list1 = new List<int>();
  17. static List<int> list2 = new List<int>();
  18. public static List<SignalProcRes> SigalEst(string file, long fsHz, int[] smpStart, int[] smpCount)
  19. {
  20. for (int i = 0; i < smpStart.Length; i++)
  21. {
  22. if (!list1.Contains(smpStart[i]))
  23. list1.Add(smpStart[i]);
  24. if (!list2.Contains(smpCount[i]))
  25. list2.Add(smpCount[i]);
  26. }
  27. int sigCount = smpStart.Length;
  28. int[] modes = new int[sigCount];//信号模式
  29. double[] rates = new double[sigCount];//调制速率
  30. double[] ffcs = new double[sigCount];//信号频偏Hz
  31. double[] snrs = new double[sigCount];//信号信噪比dB
  32. SigalEst(file, fsHz, smpStart, smpCount, modes, rates, ffcs, snrs, sigCount);
  33. List<SignalProcRes> list = new List<SignalProcRes>();
  34. for (int i = 0; i < modes.Length; i++)
  35. {
  36. SignalProcRes item = new SignalProcRes()
  37. {
  38. SignalType = (EnumSignalType)modes[i],
  39. Ffc = Math.Round(ffcs[i], 2),
  40. Rate = Math.Round(rates[i], 2),
  41. Snr= Math.Round(snrs[i], 2),
  42. };
  43. list.Add(item);
  44. }
  45. return list;
  46. }
  47. }
  48. public class SignalProcRes
  49. {
  50. /// <summary>
  51. /// 信号类型
  52. /// </summary>
  53. public EnumSignalType SignalType { get; set; }
  54. /// <summary>
  55. /// 调制速率(bps)
  56. /// </summary>
  57. public double Rate { get; set; }
  58. /// <summary>
  59. /// 频偏
  60. /// </summary>
  61. public double Ffc { get; set; }
  62. /// <summary>
  63. /// 信号信噪比
  64. /// </summary>
  65. public double Snr { get; set; }
  66. }
  67. public enum EnumSignalType
  68. {
  69. SUNKNOW = -1, //UNKNOW
  70. BPSK = 1, //BPSK 备注为界面显示字母
  71. OQPSK = 2, //OQPSK
  72. QPSK = 3, //QPSK
  73. P4QPSK = 4, //Pi/4QPSK
  74. _8PSK = 5, //8PSK
  75. _16APSK = 6, //16APSK
  76. _32APSK = 7 //32APSK
  77. }
  78. }