| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 | 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 < startsF.Length; i++)                {                    startsF[i] = startsF[i] + i * 1.386666666666666666666666f;//SlotChecker.dll有BUG,只返回了第一个突发的时间                }                for (int i = 0; i < slotscount; i++)                {                    Slot s = new Slot()                    {                        StartPoint = (int)(fsampleM * 1e6 / multi * startsF[i]),                        TimeSeconds = startsF[i],                        Len = (int)(fsampleM * 1e6 / multi * lenF[i] * 1e-3)                    };                    res.Slots.Add(s);                }            }            Free(slotst, slotle);            return res;        }    }    /// <summary>    /// 突发信息    /// </summary>    class SlotsInfo    {        /// <summary>        /// 采集时刻        /// </summary>        public DateTime AdTime { get; set; }        /// <summary>        /// 信号下行频点MHz        /// </summary>        public double FreqDownMHz { get; set; }        /// <summary>        /// AD采样率        /// </summary>        public float FsampleM { get; set; }        /// <summary>        /// 信号下行频点        /// </summary>        public float FrequenceM { get; set; }        /// <summary>        /// 抽取倍数        /// </summary>        public float Multi { get; set; }        /// <summary>        /// 时隙位置集合        /// </summary>        public List<Slot> Slots { get; set; } = new List<Slot>();    }    /// <summary>    /// 时隙信息    /// </summary>    class Slot    {        /// <summary>        /// 起始样点        /// </summary>        public int StartPoint { get; set; }        /// <summary>        /// 结束样点        /// </summary>        public int Len { get; set; }        /// <summary>        /// 时间的秒数,避免样点转时间出现毫秒级误差        /// </summary>        public float TimeSeconds { get; set; }    }}
 |