Пример #1
0
    /**
     * <summary>
     *   Builds a list of all data streams hold by the data logger.
     * <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>
     * </summary>
     * <param name="v">
     *   an array of YDataStream objects to be filled in
     * </param>
     * <returns>
     *   YAPI.SUCCESS 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)
    {
        int functionReturnValue = 0;

        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))
        {
            functionReturnValue = res;
            return(functionReturnValue);
        }

        root = j.GetRootNode();
        for (i = 0; i <= root.itemcount - 1; i++)
        {
            el = root.items[i];
            v.Add(new YDataStream(this, el.items[0].ivalue, el.items[1].ivalue, el.items[2].ivalue, el.items[3].ivalue));
        }

        j = null;
        functionReturnValue = YAPI.SUCCESS;
        return(functionReturnValue);
    }
Пример #2
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);
        }
Пример #3
0
        public new int loadStream()
        {
            YAPI.TJsonParser json = null;
            int res   = 0;
            int count = 0;

            YAPI.TJSONRECORD root    = default(YAPI.TJSONRECORD);
            YAPI.TJSONRECORD el      = default(YAPI.TJSONRECORD);
            string           name    = null;
            List <int>       coldiv  = new List <int>();
            List <int>       coltype = new List <int>();
            List <int>       udat    = new List <int>();
            List <double>    date    = new List <double>();
            List <double>    colscl  = new List <double>();
            List <int>       colofs  = new List <int>();
            List <int>       caltyp  = new List <int>();
            List <YAPI.yCalibrationHandler> calhdl = new List <YAPI.yCalibrationHandler>();
            List <List <int> >    calpar           = new List <List <int> >();
            List <List <double> > calraw           = new List <List <double> >();
            List <List <double> > calref           = new List <List <double> >();

            int x = 0;
            int i = 0;
            int j = 0;

            res = _dataLogger.getData(_runNo, _timeStamp, ref json);
            if ((res != YAPI.SUCCESS))
            {
                return(res);
            }

            _nRows = 0;
            _nCols = 0;
            _columnNames.Clear();
            _values = new List <List <double> >();


            root = json.GetRootNode();

            for (i = 0; i <= root.membercount - 1; i++)
            {
                el   = root.members[i];
                name = el.name;

                if (name == "time")
                {
                    _timeStamp = (int)el.ivalue;
                }
                else if (name == "UTC")
                {
                    _utcStamp = (UInt32)el.ivalue;
                }
                else if (name == "interval")
                {
                    _interval = (int)el.ivalue;
                }
                else if (name == "nRows")
                {
                    _nRows = (int)el.ivalue;
                }
                else if (name == "keys")
                {
                    _nCols = el.itemcount;
                    for (j = 0; j <= _nCols - 1; j++)
                    {
                        _columnNames.Add(el.items[j].svalue);
                    }
                }
                else if (name == "div")
                {
                    _nCols = el.itemcount;
                    for (j = 0; j <= _nCols - 1; j++)
                    {
                        coldiv.Add((int)el.items[j].ivalue);
                    }
                }
                else if (name == "type")
                {
                    _nCols = el.itemcount;
                    for (j = 0; j <= _nCols - 1; j++)
                    {
                        coltype.Add((int)el.items[j].ivalue);
                    }
                }
                else if (name == "scal")
                {
                    _nCols = el.itemcount;
                    for (j = 0; j <= _nCols - 1; j++)
                    {
                        colscl.Add(el.items[j].ivalue / 65536.0);
                        if (coltype[j] != 0)
                        {
                            colofs.Add(-32767);
                        }
                        else
                        {
                            colofs.Add(0);
                        }
                    }
                }
                else if (name == "cal")
                {
                    //fixme no calibration
                }
                else if (name == "data")
                {
                    if (colscl.Count <= 0)
                    {
                        for (j = 0; j <= _nCols - 1; j++)
                        {
                            colscl.Add(1.0 / coldiv[j]);
                            if (coltype[j] != 0)
                            {
                                colofs.Add(-32767);
                            }
                            else
                            {
                                colofs.Add(0);
                            }
                        }
                    }
                    udat.Clear();
                    if (el.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRING)
                    {
                        udat = YAPI._decodeWords(el.svalue);
                    }
                    else
                    {
                        count = el.itemcount;
                        for (j = 0; j <= count - 1; j++)
                        {
                            int tmp = (int)(el.items[j].ivalue);
                            udat.Add(tmp);
                        }
                    }
                    _values = new List <List <double> >();
                    List <double> dat = new List <double>();
                    foreach (int uval in udat)
                    {
                        double value;
                        if (coltype[x] < 2)
                        {
                            value = (uval + colofs[x]) * colscl[x];
                        }
                        else
                        {
                            value = YAPI._decimalToDouble(uval - 32767);
                        }
                        if (caltyp[x] > 0 && calhdl[x] != null)
                        {
                            YAPI.yCalibrationHandler handler = calhdl[x];
                            if (caltyp[x] <= 10)
                            {
                                value = handler((uval + colofs[x]) / coldiv[x], caltyp[x], calpar[x], calraw[x], calref[x]);
                            }
                            else if (caltyp[x] > 20)
                            {
                                value = handler(value, caltyp[x], calpar[x], calraw[x], calref[x]);
                            }
                        }
                        dat.Add(value);
                        x++;
                        if (x == _nCols)
                        {
                            _values.Add(dat);
                            dat.Clear();
                            x = 0;
                        }
                    }
                }
            }

            json = null;

            return(YAPI.SUCCESS);
        }
Пример #4
0
    private int loadStream()
    {
        YAPI.TJsonParser json = null;
        int res   = 0;
        int count = 0;

        YAPI.TJSONRECORD root    = default(YAPI.TJSONRECORD);
        YAPI.TJSONRECORD el      = default(YAPI.TJSONRECORD);
        string           name    = null;
        List <int>       coldiv  = new List <int>();
        List <int>       coltype = new List <int>();
        List <uint>      udat    = new List <uint>();
        List <double>    date    = new List <double>();
        List <double>    colscl  = new List <double>();


        int    x     = 0;
        int    y     = 0;
        int    i     = 0;
        int    j     = 0;
        double value = 0;

        res = dataLogger.getData(runNo, timeStamp, ref json);
        if ((res != YAPI.SUCCESS))
        {
            return(res);
        }

        nRows = 0;
        nCols = 0;
        columnNames.Clear();
        values = new double[1, 1];


        root = json.GetRootNode();

        for (i = 0; i <= root.membercount - 1; i++)
        {
            el   = root.members[i];
            name = el.name;

            if (name == "time")
            {
                timeStamp = el.ivalue;
            }
            else if (name == "UTC")
            {
                utcStamp = el.ivalue;
            }
            else if (name == "interval")
            {
                interval = el.ivalue;
            }
            else if (name == "nRows")
            {
                nRows = el.ivalue;
            }
            else if (name == "keys")
            {
                nCols = el.itemcount;
                for (j = 0; j <= nCols - 1; j++)
                {
                    columnNames.Add(el.items[j].svalue);
                }
            }
            else if (name == "div")
            {
                nCols = el.itemcount;
                for (j = 0; j <= nCols - 1; j++)
                {
                    coldiv.Add(el.items[j].ivalue);
                }
            }
            else if (name == "type")
            {
                nCols = el.itemcount;
                for (j = 0; j <= nCols - 1; j++)
                {
                    coltype.Add(el.items[j].ivalue);
                }
            }
            else if (name == "scal")
            {
                nCols = el.itemcount;
                for (j = 0; j <= nCols - 1; j++)
                {
                    colscl.Add(el.items[j].ivalue / 65536.0);
                }
            }
            else if (name == "data")
            {
                if (colscl.Count <= 0)
                {
                    for (j = 0; j <= nCols - 1; j++)
                    {
                        colscl.Add(1.0 / coldiv[j]);
                    }
                }



                udat.Clear();
                if (el.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRING)
                {
                    string sdat = el.svalue;
                    for (int p = 0; p < sdat.Length;)
                    {
                        uint val;
                        uint c = sdat[p++];
                        if (c >= 'a')
                        {
                            int srcpos = (int)(udat.Count - 1 - (c - 'a'));
                            if (srcpos < 0)
                            {
                                dataLogger.throw_friend(YAPI.IO_ERROR, "Unexpected JSON reply format");
                                return(YAPI.IO_ERROR);
                            }

                            val = udat[srcpos];
                        }
                        else
                        {
                            if (p + 2 > sdat.Length)
                            {
                                dataLogger.throw_friend(YAPI.IO_ERROR, "Unexpected JSON reply format");
                                return(YAPI.IO_ERROR);
                            }
                            val  = (c - '0');
                            c    = sdat[p++];
                            val += (c - '0') << 5;
                            c    = sdat[p++];
                            if (c == 'z')
                            {
                                c = '\\';
                            }
                            val += (c - '0') << 10;
                        }
                        udat.Add(val);
                    }
                }
                else
                {
                    count = el.itemcount;
                    for (j = 0; j <= count - 1; j++)
                    {
                        u32 tmp = (u32)(el.items[j].ivalue);
                        udat.Add(tmp);
                    }
                }
                values = new double[nRows, nCols];
                foreach (u32 uval in udat)
                {
                    value = uval;
                    if (coltype[x] == 0)
                    {
                        value = value * colscl[x];
                    }
                    else
                    {
                        if (coltype[x] == 1)
                        {
                            value = (value - 32767) * colscl[x];
                        }
                    }
                    values[y, x] = value;
                    x++;
                    if (x == nCols)
                    {
                        x = 0;
                        y++;
                    }
                }
            }
        }

        json = null;

        return(YAPI.SUCCESS);
    }
Пример #5
0
 public string _json_get_string(byte[] data)
 {
     Nullable<YAPI.TJSONRECORD> node;
     string json_str = YAPI.DefaultEncoding.GetString(data);
     YAPI.TJsonParser p = new YAPI.TJsonParser('[' + json_str + ']', false);
     node = p.GetRootNode();
     return node.Value.items[0].svalue;
 }