Example #1
0
        public GraphItemAdapter(string name, Color color, double windowSize, DataItemAdapter dataItemAdapter)
        {
            // store values
            this.dataItemAdapter = dataItemAdapter;
            this.name            = name;

            // get the source units
            this.sourceUnits = UnitConverter.GetUnit(dataItemAdapter.DataItemUnits);

            // create the queues
            plotQueue = new TimeWindowQueue(windowSize);
            recvQueue = new TimeWindowQueue(windowSize);

            // create the plot object
            plot       = new LinePlot(plotQueue.ValueList, plotQueue.TimestampList);
            plot.Color = color;
            plot.Label = name;

            // subscribe to relevant events
            Services.RunControlService.RenderCycle += RunControlService_RenderCycle;
            dataItemAdapter.DataValueReceived      += dataItemAdapter_DataValueReceived;
        }
 public ValueQueueWrapper(TimeWindowQueue parent)
 {
     this.parent = parent;
 }
 public TimestampQueueWrapper(TimeWindowQueue parent)
 {
     this.parent = parent;
 }
        public void AddRange(TimeWindowQueue queue)
        {
            // perform a preliminary check to see if the queue has data
            if (queue.count == 0)
            {
                return;
            }

            // if it has data, therefore all the indicators (min, max value, reset, etc) will be valid

            // check if the time window of the other queue makes us have to flush our entire queue
            // basically, if the other queue's max timestamp less the window time is greater than our max timestamp,
            // then we know all of our data will get invalidated
            // also check if a reset was performed on the queue or we have no data
            if (queue.WasReset || this.count == 0 || (queue.MaxTimestamp - windowSize > this.MaxTimestamp))
            {
                // we need to flush our queue
                Clear();
            }
            else
            {
                // now we know that we want to keep around some our data
                // run maintain queue to clean out our old data based on the max timestamp of the new queue
                MaintainQueue(queue.MaxTimestamp - windowSize);
            }

            // check if we have enough space for the data
            if (count + queue.count > timestamps.Length)
            {
                // resize our queue
                ResizeQueue(count + queue.count);
            }

            // we verified that we have space to hold the remaining data, so we can just copy data after tail (wrapping
            // around if needed) and be fine
            if (tail + queue.count <= timestamps.Length)
            {
                // don't need to wrap around
                // copy the data directly
                queue.CopyTo(0, values, timestamps, tail, queue.count);
            }
            else
            {
                // we need to wrap
                int firstLength = timestamps.Length - tail;
                // copy tail->end
                queue.CopyTo(0, values, timestamps, tail, firstLength);
                queue.CopyTo(firstLength, values, timestamps, 0, queue.count - firstLength);
            }

            // update tail pointer
            tail = (tail + queue.count) % timestamps.Length;
            // update count
            count += queue.count;

            // update min and max from other queue
            if (queue.maxValue > maxValue)
            {
                maxValue = queue.maxValue;
            }
            if (queue.minValue < minValue)
            {
                minValue = queue.minValue;
            }

            // update the last timestamp from the other queue
            this.lastTimestamp = queue.lastTimestamp;
        }