コード例 #1
0
        public static ArraySegment <int> CopyToArray(this ArraySegment <int> seg, SyncBufManager bufMgr)
        {
            RecycleIntBuf buf = new RecycleIntBuf(seg.Count, bufMgr);

            if (seg.Array == null)
            {
                return(new ArraySegment <int>());
            }
            var result = bufMgr.TakeIntBuf(seg.Count);

            Array.Copy(seg.Array, seg.Offset, result, 0, seg.Count);
            return(new ArraySegment <int>(result, 0, seg.Count));
        }
コード例 #2
0
        public static ArraySegment <int> FastConvertFrom(ArraySegment <byte> data, SyncBufManager mgr)
        {
            if (data.Array == null)
            {
                return(Empty);
            }
            var startInd = data.Offset;
            var count    = data.Count;
            var result   = mgr.TakeIntBuf(count / 3);

            unsafe
            {
                fixed(byte *arr = data.Array)
                {
                    fixed(int *r = result)
                    {
                        int *rt = r;

                        for (int i = startInd; i < count; i = i + 3)
                        {
                            byte *tmp = (byte *)rt;
                            *     tmp = arr[i + 2];
                            tmp++;
                            *tmp = arr[i + 1];
                            tmp++;
                            *tmp = arr[i];
                            tmp++;
                            *tmp = 0;
                            if ((arr[i] & 0x80) != 0)
                            {
                                *rt -= flipVal;
                            }
                            rt++;
                        }
                    }
                }
            }
            return(new ArraySegment <int>(result, 0, count / 3));
        }
コード例 #3
0
        public static ArraySegment <int> ConvertFrom(ArraySegment <byte> data, SyncBufManager mgr)
        {
            var arr = data.Array;

            if (arr == null)
            {
                return(Empty);
            }
            var ind   = data.Offset;
            var count = data.Count;
            var buf   = mgr.TakeIntBuf(count / 3);

            for (int i = 0; i < buf.Length; i++)
            {
                buf[i] = (arr[ind] << 16) + (arr[ind + 1] << 8) + arr[ind + 2];
                if ((arr[ind] & 0x80) != 0)
                {
                    buf[i] -= flipVal;
                }
                ind += 3;
            }
            return(new ArraySegment <int>(buf, 0, count / 3));
        }
コード例 #4
0
 public RecycleIntBuf(int size, SyncBufManager mgr)
 {
     _size = size;
     _buf  = mgr.TakeIntBuf(size);
     _mgr  = mgr;
 }
コード例 #5
0
 public RecycleBuffer(int size, SyncBufManager mgr)
 {
     _size = size;
     _buf  = mgr.TakeBuffer(size);
     _mgr  = mgr;
 }
コード例 #6
0
 /// <summary>
 /// 把ADS1299的24位采样数据转换为电压值,电压单位伏特
 /// </summary>
 /// <param name="data"></param>
 /// <param name="mgr"></param>
 /// <returns></returns>
 public static ArraySegment <int> ConvertFromPlatform(ArraySegment <byte> data, SyncBufManager mgr)
 {
     if (Environment.OSVersion.Platform == PlatformID.Unix)
     {
         return(FastConvertFrom(data, mgr));
     }
     else
     {
         return(ConvertFrom(data, mgr));
     }
 }