示例#1
0
        /**
         * <summary>
         *   Builds a list of all data streams hold by the data logger (legacy method).
         * <para>
         *   The caller must pass by reference an empty array to hold YDataStream
         *   objects, and the function fills it with objects describing available
         *   data sequences.
         * </para>
         * <para>
         *   This is the old way to retrieve data from the DataLogger.
         *   For new applications, you should rather use <c>get_dataSets()</c>
         *   method, or call directly <c>get_recordedData()</c> on the
         *   sensor object.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="v">
         *   an array of YDataStream objects to be filled in
         * </param>
         * <returns>
         *   <c>YAPI.SUCCESS</c> if the call succeeds.
         * </returns>
         * <para>
         *   On failure, throws an exception or returns a negative error code.
         * </para>
         */
        public int get_dataStreams(List <YDataStream> v)
        {
            YAPI.TJsonParser j = null;
            int i   = 0;
            int res = 0;

            YAPI.TJSONRECORD root = default(YAPI.TJSONRECORD);
            YAPI.TJSONRECORD el   = default(YAPI.TJSONRECORD);

            v.Clear();
            res = getData(0, 0, ref j);
            if (res != YAPI.SUCCESS)
            {
                return(res);
            }

            root = j.GetRootNode();
            if (root.itemcount == 0)
            {
                return(YAPI.SUCCESS);
            }
            if (root.items[0].recordtype == YAPI.TJSONRECORDTYPE.JSON_ARRAY)
            {
                // old datalogger format: [runIdx, timerel, utc, interval]
                for (i = 0; i <= root.itemcount - 1; i++)
                {
                    el = root.items[i];
                    v.Add(new YOldDataStream(this, (int)el.items[0].ivalue, (int)el.items[1].ivalue, (UInt32)el.items[2].ivalue, (int)el.items[3].ivalue));
                }
            }
            else
            {
                // new datalogger format: {"id":"...","unit":"...","streams":["...",...]}
                string          json_buffer = j.convertToString(root, false);
                List <YDataSet> sets        = this.parse_dataSets(YAPI.DefaultEncoding.GetBytes(json_buffer));
                for (int sj = 0; sj < sets.Count; sj++)
                {
                    List <YDataStream> ds = sets[sj].get_privateDataStreams();
                    for (int si = 0; si < ds.Count; si++)
                    {
                        v.Add(ds[si]);
                    }
                }
            }
            j = null;
            return(YAPI.SUCCESS);
        }