SlotHelper.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace X1LeoTaskServer54
  9. {
  10. static class SlotHelper
  11. {
  12. #region cpp dll Interop
  13. private const string slotDll = @"AddIns\时隙获取\SlotChecker.dll";
  14. [DllImport(slotDll, EntryPoint = "getslots", CallingConvention = CallingConvention.Cdecl)]
  15. private extern static int GetFileSlots(string file, byte[] fileTime, ref float frequenceM, ref float fsampleM,
  16. ref int multi, ref int slotscount, out IntPtr slotst, out IntPtr slotle);
  17. [DllImport(slotDll, EntryPoint = "freeslots", CallingConvention = CallingConvention.Cdecl)]
  18. private extern static void Free(IntPtr slotst, IntPtr slotle);
  19. #endregion
  20. public static SlotsInfo GetFileSlots(string file)
  21. {
  22. SlotsInfo res = new SlotsInfo();
  23. string name = Path.GetFileName(file);
  24. res.FreqDownMHz = Convert.ToDouble(name.Split(new string[] { "_", "MHz" }, StringSplitOptions.RemoveEmptyEntries)[1]);
  25. byte[] timeData = new byte[6];
  26. float frequenceM = 0, fsampleM = 0;
  27. int multi = 0, slotscount = 0;
  28. IntPtr slotst, slotle;
  29. var ret = GetFileSlots(file, timeData, ref frequenceM, ref fsampleM, ref multi, ref slotscount, out slotst, out slotle);
  30. if (ret == 0)
  31. {
  32. res.FrequenceM = (float)((long)((decimal)frequenceM * 1000000) / 1e6);
  33. res.FsampleM = fsampleM;
  34. res.Multi = multi;
  35. res.AdTime = new DateTime(2000 + timeData[0], timeData[1], timeData[2], timeData[3], timeData[4], timeData[5]);
  36. float[] startsF = new float[slotscount];
  37. float[] lenF = new float[slotscount];
  38. Marshal.Copy(slotst, startsF, 0, slotscount);
  39. Marshal.Copy(slotle, lenF, 0, slotscount);
  40. for (int i = 0; i < slotscount; i++)
  41. {
  42. Slot s = new Slot()
  43. {
  44. StartPoint = (int)(fsampleM * 1e6 / multi * startsF[i]),
  45. TimeSeconds = startsF[i],
  46. Len = (int)(fsampleM * 1e6 / multi * lenF[i] * 1e-3)
  47. };
  48. res.Slots.Add(s);
  49. }
  50. }
  51. Free(slotst, slotle);
  52. return res;
  53. }
  54. }
  55. /// <summary>
  56. /// 突发信息
  57. /// </summary>
  58. class SlotsInfo
  59. {
  60. /// <summary>
  61. /// 采集时刻
  62. /// </summary>
  63. public DateTime AdTime { get; set; }
  64. /// <summary>
  65. /// 信号下行频点MHz
  66. /// </summary>
  67. public double FreqDownMHz { get; set; }
  68. /// <summary>
  69. /// AD采样率
  70. /// </summary>
  71. public float FsampleM { get; set; }
  72. /// <summary>
  73. /// 信号下行频点
  74. /// </summary>
  75. public float FrequenceM { get; set; }
  76. /// <summary>
  77. /// 抽取倍数
  78. /// </summary>
  79. public float Multi { get; set; }
  80. /// <summary>
  81. /// 时隙位置集合
  82. /// </summary>
  83. public List<Slot> Slots { get; set; } = new List<Slot>();
  84. }
  85. /// <summary>
  86. /// 时隙信息
  87. /// </summary>
  88. class Slot
  89. {
  90. /// <summary>
  91. /// 起始样点
  92. /// </summary>
  93. public int StartPoint { get; set; }
  94. /// <summary>
  95. /// 结束样点
  96. /// </summary>
  97. public int Len { get; set; }
  98. /// <summary>
  99. /// 时间的秒数,避免误差
  100. /// </summary>
  101. public float TimeSeconds { get; set; }
  102. }
  103. }