// Method used to cache DataStream objects (new DataLogger)
        internal virtual YDataStream imm_findDataStream(YDataSet dataset, string def)
        {
            string key = dataset.get_functionId() + ":" + def;

            if (_dataStreams.ContainsKey(key))
            {
                return(_dataStreams[key]);
            }

            YDataStream newDataStream = new YDataStream(this, dataset, YAPIContext.imm_decodeWords(def));

            _dataStreams[key] = newDataStream;
            return(newDataStream);
        }
Example #2
0
        // YDataSet parser for stream list
        protected internal virtual async Task <int> _parse(string json_str)
        {
            YJSONObject json;
            YJSONArray  jstreams;
            double      streamStartTime;
            double      streamEndTime;

            json = new YJSONObject(json_str);
            json.parse();
            _functionId = json.getString("id");
            _unit       = json.getString("unit");
            if (json.has("calib"))
            {
                _calib    = YAPIContext.imm_decodeFloats(json.getString("calib"));
                _calib[0] = _calib[0] / 1000;
            }
            else
            {
                _calib = YAPIContext.imm_decodeWords(json.getString("cal"));
            }
            _streams  = new List <YDataStream>();
            _preview  = new List <YMeasure>();
            _measures = new List <YMeasure>();
            jstreams  = json.getYJSONArray("streams");
            for (int i = 0; i < jstreams.Length; i++)
            {
                YDataStream stream = _parent.imm_findDataStream(this, jstreams.getString(i));
                // the timestamp in the data streams is the end of the measure, so the actual
                // measurement start time is computed as one interval before the first timestamp
                streamStartTime = await stream.get_realStartTimeUTC() * 1000;

                streamEndTime = streamStartTime + await stream.get_realDuration() * 1000;

                if (_startTimeMs > 0 && streamEndTime <= _startTimeMs)
                {
                    // this stream is too early, drop it
                }
                else if (_endTimeMs > 0 && streamStartTime >= _endTimeMs)
                {
                    // this stream is too late, drop it
                }
                else
                {
                    _streams.Add(stream);
                }
            }
            _progress = 0;
            return(await this.get_progress());
        }
Example #3
0
        // Method used to cache DataStream objects (new DataLogger)
        internal virtual YDataStream imm_findDataStream(YDataSet dataset, string def)
        {
            string key = dataset.get_functionId() + ":" + def;

            if (_dataStreams.ContainsKey(key))
            {
                return(_dataStreams[key]);
            }

            List <int> words = YAPIContext.imm_decodeWords(def);

            if (words.Count < 14)
            {
                _throw(YAPI.VERSION_MISMATCH, "device firmware is too old");
                return(null);
            }

            YDataStream newDataStream = new YDataStream(this, dataset, words);

            _dataStreams[key] = newDataStream;
            return(newDataStream);
        }
Example #4
0
        // YDataSet parser for stream list
        protected internal virtual async Task <int> _parse(string json_str)
        {
            YJSONObject json;
            YJSONArray  jstreams;
            double      summaryMinVal    = double.MaxValue;
            double      summaryMaxVal    = double.Epsilon;
            double      summaryTotalTime = 0;
            double      summaryTotalAvg  = 0;
            long        streamStartTime;
            long        streamEndTime;
            long        startTime = 0x7fffffff;
            long        endTime   = 0;

            json = new YJSONObject(json_str);
            json.parse();
            _functionId = json.getString("id");
            _unit       = json.getString("unit");
            if (json.has("calib"))
            {
                _calib    = YAPIContext.imm_decodeFloats(json.getString("calib"));
                _calib[0] = _calib[0] / 1000;
            }
            else
            {
                _calib = YAPIContext.imm_decodeWords(json.getString("cal"));
            }
            _streams  = new List <YDataStream>();
            _preview  = new List <YMeasure>();
            _measures = new List <YMeasure>();
            jstreams  = json.getYJSONArray("streams");
            for (int i = 0; i < jstreams.Length; i++)
            {
                YDataStream stream = _parent.imm_findDataStream(this, jstreams.getString(i));
                streamStartTime = await stream.get_startTimeUTC() - await stream.get_dataSamplesIntervalMs() / 1000;

                streamEndTime = await stream.get_startTimeUTC() + await stream.get_duration();

                if (_startTime > 0 && streamEndTime <= _startTime)
                {
                    // this stream is too early, drop it
                }
                else if (_endTime > 0 && await stream.get_startTimeUTC() > _endTime)
                {
                    // this stream is too late, drop it
                }
                else
                {
                    _streams.Add(stream);
                    if (startTime > streamStartTime)
                    {
                        startTime = streamStartTime;
                    }
                    if (endTime < streamEndTime)
                    {
                        endTime = streamEndTime;
                    }

                    if (await stream.isClosed() && await stream.get_startTimeUTC() >= _startTime && (_endTime == 0 || streamEndTime <= _endTime))
                    {
                        if (summaryMinVal > await stream.get_minValue())
                        {
                            summaryMinVal = await stream.get_minValue();
                        }
                        if (summaryMaxVal < await stream.get_maxValue())
                        {
                            summaryMaxVal = await stream.get_maxValue();
                        }
                        summaryTotalAvg += await stream.get_averageValue() * await stream.get_duration();

                        summaryTotalTime += await stream.get_duration();

                        YMeasure rec = new YMeasure(await stream.get_startTimeUTC(), streamEndTime, await stream.get_minValue(), await stream.get_averageValue(), await stream.get_maxValue());
                        _preview.Add(rec);
                    }
                }
            }
            if ((_streams.Count > 0) && (summaryTotalTime > 0))
            {
                // update time boundaries with actual data
                if (_startTime < startTime)
                {
                    _startTime = startTime;
                }
                if (_endTime == 0 || _endTime > endTime)
                {
                    _endTime = endTime;
                }
                _summary = new YMeasure(_startTime, _endTime, summaryMinVal, summaryTotalAvg / summaryTotalTime, summaryMaxVal);
            }
            _progress = 0;
            return(await this.get_progress());
        }