internal void SetData(ChannelDataSourceScope type, Channel ch, Array arr, bool partial = false)
        {
            if (arr == null)
            {
                return;
            }

            lock (dataLock)
            {
                if (arr.GetType().GetElementType() != ChannelDataTypes[ch.GetType()])
                {
                    throw new Exception("Invalid data type " + arr.GetType().GetElementType().ToString() + " for channel of type " + ch.GetType().ToString());
                }

                data[type][ch]      = new ChannelData(type, ch, arr, partial, samplePeriod[type], offset[type]);
                this.LastDataUpdate = DateTime.Now;

                //if update for LA channel data is received: delete all Digital channel data, as they are now outdated and need to be recalculated
                if (ch is LogicAnalyserChannel)
                {
                    for (int i = data[type].Count - 1; i >= 0; i--)
                    {
                        if (data[type].ElementAt(i).Key is DigitalChannel)
                        {
                            data[type].Remove(data[type].ElementAt(i).Key);
                        }
                    }
                }
            }
        }
 private ChannelData ExtractBitsFromLogicAnalyser(DigitalChannel ch, ChannelDataSourceScope t)
 {
     lock (dataLock)
     {
         //FIXME: expand for more than 1 LA
         if (!data[t].ContainsKey(LogicAnalyserChannel.LA))
         {
             return(null);
         }
         Func <byte, bool> bitFilter = new Func <byte, bool>(x => Utils.IsBitSet(x, ch.Value));
         var laChannel = data[t][LogicAnalyserChannel.LA];
         data[t][ch] = new ChannelData(t, ch, Utils.TransformArray(laChannel.array, bitFilter), laChannel.partial, samplePeriod[t], offset[t]);
         return(data[t][ch]);
     }
 }
 public ChannelData GetData(ChannelDataSourceScope type, Channel ch)
 {
     lock (dataLock)
     {
         if (data[type].ContainsKey(ch))
         {
             return(data[type][ch]);
         }
         else if (ch is DigitalChannel)
         {
             return(ExtractBitsFromLogicAnalyser((DigitalChannel)ch, type));
         }
     }
     return(null);
 }
        internal void SetData(ChannelDataSourceScope type, Channel ch, Array arr, bool partial = false)
        {
            if (arr == null)
            {
                return;
            }

            lock (dataLock)
            {
                if (arr.GetType().GetElementType() != ChannelDataTypes[ch.GetType()])
                {
                    throw new Exception("Invalid data type " + arr.GetType().GetElementType().ToString() + " for channel of type " + ch.GetType().ToString());
                }

                data[type][ch]      = new ChannelData(type, ch, arr, partial, samplePeriod[type], offset[type]);
                this.LastDataUpdate = DateTime.Now;
            }
        }
        internal void AddData(ChannelDataSourceScope type, Channel ch, Array arrayToAdd)
        {
            ChannelData arrayWeHad = GetData(type, ch);

            int MaxElements;

            if (type == ChannelDataSourceScope.Acquisition)
            {
                MaxElements = (int)AcquisitionSamples;
            }
            else if (type == ChannelDataSourceScope.Overview)
            {
                MaxElements = OVERVIEW_SAMPLES;
            }
            else if (type == ChannelDataSourceScope.Viewport)
            {
                MaxElements = ViewportSamples;
            }
            else
            {
                throw new Exception("Unhandled type");
            }

            int arrayToAddElements = Math.Min(arrayToAdd.Length, MaxElements);
            int arrayWeHadElements = arrayWeHad == null ? 0 : Math.Min(arrayWeHad.array.Length, MaxElements - arrayToAddElements);

            this.LatestChunkSize = arrayToAddElements;

            //When adding all elements from new array, don't bother copying things togehter
            if (arrayWeHadElements <= 0 && arrayToAddElements == arrayToAdd.Length)
            {
                SetData(type, ch, arrayToAdd, arrayToAdd.Length < MaxElements);
                return;
            }

            Array arrayResult = Array.CreateInstance(arrayToAdd.GetType().GetElementType(), arrayToAddElements + arrayWeHadElements);

            if (arrayWeHadElements > 0)
            {
                Array.Copy(arrayWeHad.array, arrayWeHad.array.Length - arrayWeHadElements, arrayResult, 0, arrayWeHadElements);
            }
            Array.Copy(arrayToAdd, arrayToAdd.Length - arrayToAddElements, arrayResult, arrayWeHadElements, arrayToAddElements);
            SetData(type, ch, arrayResult, arrayResult.Length < MaxElements);
        }