using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace X3TaskServer54 { static class SlotHelper { #region cpp dll Interop private const string slotDll = @"AddIns\时隙获取\SlotChecker.dll"; [DllImport(slotDll, EntryPoint = "getslots", CallingConvention = CallingConvention.Cdecl)] private extern static int GetFileSlots(string file, byte[] fileTime, ref float frequenceM, ref float fsampleM, ref int multi, ref int slotscount, out IntPtr slotst, out IntPtr slotle); [DllImport(slotDll, EntryPoint = "freeslots", CallingConvention = CallingConvention.Cdecl)] private extern static void Free(IntPtr slotst, IntPtr slotle); #endregion public static SlotsInfo GetFileSlots(string file) { SlotsInfo res = new SlotsInfo(); string name = Path.GetFileName(file); res.FreqDownMHz = Convert.ToDouble(name.Split(new string[] { "_", "MHz" }, StringSplitOptions.RemoveEmptyEntries)[1]); byte[] timeData = new byte[6]; float frequenceM = 0, fsampleM = 0; int multi = 0, slotscount = 0; IntPtr slotst, slotle; var ret = GetFileSlots(file, timeData, ref frequenceM, ref fsampleM, ref multi, ref slotscount, out slotst, out slotle); if (ret == 0) { res.FrequenceM = (float)((long)((decimal)frequenceM * 1000000) / 1e6); res.FsampleM = fsampleM; res.Multi = multi; res.AdTime = new DateTime(2000 + timeData[0], timeData[1], timeData[2], timeData[3], timeData[4], timeData[5]); float[] startsF = new float[slotscount]; float[] lenF = new float[slotscount]; Marshal.Copy(slotst, startsF, 0, slotscount); Marshal.Copy(slotle, lenF, 0, slotscount); for (int i = 0; i < slotscount; i++) { Slot s = new Slot() { StartPoint = (int)(fsampleM * 1e6 / multi * startsF[i]), Len = (int)(fsampleM * 1e6 / multi * lenF[i] * 1e-3) }; res.Slots.Add(s); } } Free(slotst, slotle); return res; } } /// /// 突发信息 /// class SlotsInfo { /// /// 采集时刻 /// public DateTime AdTime { get; set; } /// /// 信号下行频点MHz /// public double FreqDownMHz { get; set; } /// /// AD采样率 /// public float FsampleM { get; set; } /// /// 信号下行频点 /// public float FrequenceM { get; set; } /// /// 抽取倍数 /// public float Multi { get; set; } /// /// 时隙位置集合 /// public List Slots { get; set; } = new List(); } /// /// 时隙信息 /// class Slot { /// /// 起始样点 /// public int StartPoint { get; set; } /// /// 结束样点 /// public int Len { get; set; } } }