コード例 #1
0
        //   int _byteIndex;
        /// <summary>
        /// Takes in a stream of bytes and converts it into accelerometer data points which are stored in an internal queue.
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns> Number of bytes successfully converted into valid data. If no bytes were read, 0 is returned.</returns>
        public int AccelerometerByteStreamParser(byte[] bytes)
        {
            // An accelerometer data point contains at least 6 bytes
            // If there are less than 6 bytes, it's discarded
            int len = bytes.Length;

            len = len / C_NUM_BYTES_PER_DATA_POINT;

            for (int i = 0; i < len; i++)
            {
                int offset           = i * C_NUM_BYTES_PER_DATA_POINT;
                AccelerationPoint ap = new AccelerationPoint();
                ap.aX = getInt16(bytes[offset + 1], bytes[offset + 0]);
                ap.aY = getInt16(bytes[offset + 3], bytes[offset + 2]);
                ap.aZ = getInt16(bytes[offset + 5], bytes[offset + 4]);
                if (_sw != null)
                {
                    for (int j = 0; j < C_NUM_BYTES_PER_DATA_POINT; j++)
                    {
                        _sw.Write(bytes[offset + j]);
                    }
                }
                AccQ.Add(ap);
            }
            return(len * C_NUM_BYTES_PER_DATA_POINT);
        }
コード例 #2
0
        //   int _byteIndex;
        /// <summary>
        /// Takes in a stream of bytes and converts it into accelerometer data points which are stored in an internal queue.
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns> Number of bytes successfully converted into valid data. If no bytes were read, 0 is returned.</returns>
        public int AccelerometerByteStreamParser(byte[] bytes)
        {
            // An accelerometer data point contains at least 6 bytes
            // If there are less than 6 bytes, it's discarded
            int len = bytes.Length;
            len = len / C_NUM_BYTES_PER_DATA_POINT;

            for (int i = 0; i < len; i++)
            {
                int offset = i * C_NUM_BYTES_PER_DATA_POINT;
                AccelerationPoint ap = new AccelerationPoint();
                ap.aX = getInt16(bytes[offset + 1], bytes[offset + 0]);
                ap.aY = getInt16(bytes[offset + 3], bytes[offset + 2]);
                ap.aZ = getInt16(bytes[offset + 5], bytes[offset + 4]);
                if (_sw != null)
                {
                    for (int j = 0; j < C_NUM_BYTES_PER_DATA_POINT; j++)
                    {
                        _sw.Write(bytes[offset + j]);
                    }

                }
                AccQ.Add(ap);
            }
            return (len * C_NUM_BYTES_PER_DATA_POINT);
        }
コード例 #3
0
        /// <summary>
        /// Returns an array of Acceleration points available.
        /// Just get the data from here and plot it!
        /// </summary>
        /// <returns></returns>
        public AccelerationPoint[] GetAvailablePoints()
        {
            if (AccQ == null || AccQ.Count == 0)
            {
                return(null);
            }

            int items = AccQ.Count;

            AccelerationPoint[] acc_array = new AccelerationPoint[items];
            for (int i = 0; i < items; i++)
            {
                acc_array[i] = AccQ.Take(); // will block if it's not available
            }
            return(acc_array);
        }
コード例 #4
0
        /// <summary>
        /// Returns an array of Acceleration points available.
        /// Just get the data from here and plot it!
        /// </summary>
        /// <returns></returns>
        public AccelerationPoint[] GetAvailablePoints()
        {
            if (AccQ == null || AccQ.Count == 0)
                return (null);

            int items = AccQ.Count;
            AccelerationPoint[] acc_array = new AccelerationPoint[items];
            for(int i = 0; i < items; i++){
                acc_array[i] = AccQ.Take(); // will block if it's not available
            }
            return (acc_array);
        }