Ejemplo n.º 1
0
        /// <summary>
        /// Gets the trends of the specified input channels.
        /// </summary>
        protected void GetTrends(ConnectedClient client, DataPacket request)
        {
            byte[] buffer = request.Buffer;
            int    index  = ArgumentIndex;

            int[]     cnlNums    = GetIntArray(buffer, ref index);
            TimeRange timeRange  = GetTimeRange(buffer, ref index);
            int       archiveBit = GetByte(buffer, ref index);

            TrendBundle     trendBundle     = archiveHolder.GetTrends(cnlNums, timeRange, archiveBit);
            List <DateTime> timestamps      = trendBundle.Timestamps;
            int             totalPointCount = timestamps.Count;
            int             blockCapacity   = (BufferLenght - ArgumentIndex - 16) / (8 + cnlNums.Length * 10);
            int             blockCount      = totalPointCount > 0 ? (int)Math.Ceiling((double)totalPointCount / blockCapacity) : 1;
            int             pointIndex      = 0;

            buffer = client.OutBuf;

            for (int blockNumber = 1; blockNumber <= blockCount; blockNumber++)
            {
                ResponsePacket response = new ResponsePacket(request, buffer);
                index = ArgumentIndex;
                CopyInt32(blockNumber, buffer, ref index);
                CopyInt32(blockCount, buffer, ref index);
                CopyInt32(totalPointCount, buffer, ref index);

                int pointCount = Math.Min(totalPointCount - pointIndex, blockCapacity); // points in this block
                CopyInt32(pointCount, buffer, ref index);

                for (int i = 0, ptIdx = pointIndex; i < pointCount; i++, ptIdx++)
                {
                    CopyTime(timestamps[ptIdx], buffer, ref index);
                }

                foreach (TrendBundle.CnlDataList trend in trendBundle.Trends)
                {
                    for (int i = 0, ptIdx = pointIndex; i < pointCount; i++, ptIdx++)
                    {
                        CopyCnlData(trend[ptIdx], buffer, ref index);
                    }
                }

                pointIndex           += pointCount;
                response.BufferLength = index;
                client.SendResponse(response);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the trends of the specified input channels.
 /// </summary>
 public TrendBundle GetTrends(int[] cnlNums, TimeRange timeRange, int archiveBit)
 {
     return(archiveHolder.GetTrends(cnlNums, timeRange, archiveBit));
 }