Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public override int _parserHelper()
 {
     int position;
     int maxpos;
     List<int> iCalib = new List<int>();
     int iRaw;
     int iRef;
     double fRaw;
     double fRef;
     this._caltyp = -1;
     this._scale = -1;
     this._isScal32 = false;
     this._calpar.Clear();
     this._calraw.Clear();
     this._calref.Clear();
     // Store inverted resolution, to provide better rounding
     if (this._resolution > 0) {
         this._iresol = Math.Round(1.0 / this._resolution);
     } else {
         this._iresol = 10000;
         this._resolution = 0.0001;
     }
     // Old format: supported when there is no calibration
     if (this._calibrationParam == "" || this._calibrationParam == "0") {
         this._caltyp = 0;
         return 0;
     }
     if ((this._calibrationParam).IndexOf(",") >= 0) {
         iCalib = YAPI._decodeFloats(this._calibrationParam);
         this._caltyp = ((iCalib[0]) / (1000));
         if (this._caltyp > 0) {
             if (this._caltyp < YAPI.YOCTO_CALIB_TYPE_OFS) {
                 this._caltyp = -1;
                 return 0;
             }
             this._calhdl = YAPI._getCalibrationHandler(this._caltyp);
             if (!(this._calhdl != null)) {
                 this._caltyp = -1;
                 return 0;
             }
         }
         this._isScal = true;
         this._isScal32 = true;
         this._offset = 0;
         this._scale = 1000;
         maxpos = iCalib.Count;
         this._calpar.Clear();
         position = 1;
         while (position < maxpos) {
             this._calpar.Add(iCalib[position]);
             position = position + 1;
         }
         this._calraw.Clear();
         this._calref.Clear();
         position = 1;
         while (position + 1 < maxpos) {
             fRaw = iCalib[position];
             fRaw = fRaw / 1000.0;
             fRef = iCalib[position + 1];
             fRef = fRef / 1000.0;
             this._calraw.Add(fRaw);
             this._calref.Add(fRef);
             position = position + 2;
         }
     } else {
         iCalib = YAPI._decodeWords(this._calibrationParam);
         if (iCalib.Count < 2) {
             this._caltyp = -1;
             return 0;
         }
         this._isScal = (iCalib[1] > 0);
         if (this._isScal) {
             this._offset = iCalib[0];
             if (this._offset > 32767) {
                 this._offset = this._offset - 65536;
             }
             this._scale = iCalib[1];
             this._decexp = 0;
         } else {
             this._offset = 0;
             this._scale = 1;
             this._decexp = 1.0;
             position = iCalib[0];
             while (position > 0) {
                 this._decexp = this._decexp * 10;
                 position = position - 1;
             }
         }
         if (iCalib.Count == 2) {
             this._caltyp = 0;
             return 0;
         }
         this._caltyp = iCalib[2];
         this._calhdl = YAPI._getCalibrationHandler(this._caltyp);
         if (this._caltyp <= 10) {
             maxpos = this._caltyp;
         } else {
             if (this._caltyp <= 20) {
                 maxpos = this._caltyp - 10;
             } else {
                 maxpos = 5;
             }
         }
         maxpos = 3 + 2 * maxpos;
         if (maxpos > iCalib.Count) {
             maxpos = iCalib.Count;
         }
         this._calpar.Clear();
         this._calraw.Clear();
         this._calref.Clear();
         position = 3;
         while (position + 1 < maxpos) {
             iRaw = iCalib[position];
             iRef = iCalib[position + 1];
             this._calpar.Add(iRaw);
             this._calpar.Add(iRef);
             if (this._isScal) {
                 fRaw = iRaw;
                 fRaw = (fRaw - this._offset) / this._scale;
                 fRef = iRef;
                 fRef = (fRef - this._offset) / this._scale;
                 this._calraw.Add(fRaw);
                 this._calref.Add(fRef);
             } else {
                 this._calraw.Add(YAPI._decimalToDouble(iRaw));
                 this._calref.Add(YAPI._decimalToDouble(iRef));
             }
             position = position + 2;
         }
     }
     return 0;
 }
Exemplo n.º 3
0
 //--- (generated code: YDataStream implementation)
 public virtual int _initFromDataSet(YDataSet dataset, List<int> encoded)
 {
     int val;
     int i;
     int maxpos;
     int iRaw;
     int iRef;
     double fRaw;
     double fRef;
     double duration_float;
     List<int> iCalib = new List<int>();
     // decode sequence header to extract data
     this._runNo = encoded[0] + (((encoded[1]) << (16)));
     this._utcStamp = encoded[2] + (((encoded[3]) << (16)));
     val = encoded[4];
     this._isAvg = (((val) & (0x100)) == 0);
     this._samplesPerHour = ((val) & (0xff));
     if (((val) & (0x100)) != 0) {
         this._samplesPerHour = this._samplesPerHour * 3600;
     } else {
         if (((val) & (0x200)) != 0) {
             this._samplesPerHour = this._samplesPerHour * 60;
         }
     }
     val = encoded[5];
     if (val > 32767) {
         val = val - 65536;
     }
     this._decimals = val;
     this._offset = val;
     this._scale = encoded[6];
     this._isScal = (this._scale != 0);
     this._isScal32 = (encoded.Count >= 14);
     val = encoded[7];
     this._isClosed = (val != 0xffff);
     if (val == 0xffff) {
         val = 0;
     }
     this._nRows = val;
     duration_float = this._nRows * 3600 / this._samplesPerHour;
     this._duration = (int) Math.Round(duration_float);
     // precompute decoding parameters
     this._decexp = 1.0;
     if (this._scale == 0) {
         i = 0;
         while (i < this._decimals) {
             this._decexp = this._decexp * 10.0;
             i = i + 1;
         }
     }
     iCalib = dataset.get_calibration();
     this._caltyp = iCalib[0];
     if (this._caltyp != 0) {
         this._calhdl = YAPI._getCalibrationHandler(this._caltyp);
         maxpos = iCalib.Count;
         this._calpar.Clear();
         this._calraw.Clear();
         this._calref.Clear();
         if (this._isScal32) {
             i = 1;
             while (i < maxpos) {
                 this._calpar.Add(iCalib[i]);
                 i = i + 1;
             }
             i = 1;
             while (i + 1 < maxpos) {
                 fRaw = iCalib[i];
                 fRaw = fRaw / 1000.0;
                 fRef = iCalib[i + 1];
                 fRef = fRef / 1000.0;
                 this._calraw.Add(fRaw);
                 this._calref.Add(fRef);
                 i = i + 2;
             }
         } else {
             i = 1;
             while (i + 1 < maxpos) {
                 iRaw = iCalib[i];
                 iRef = iCalib[i + 1];
                 this._calpar.Add(iRaw);
                 this._calpar.Add(iRef);
                 if (this._isScal) {
                     fRaw = iRaw;
                     fRaw = (fRaw - this._offset) / this._scale;
                     fRef = iRef;
                     fRef = (fRef - this._offset) / this._scale;
                     this._calraw.Add(fRaw);
                     this._calref.Add(fRef);
                 } else {
                     this._calraw.Add(YAPI._decimalToDouble(iRaw));
                     this._calref.Add(YAPI._decimalToDouble(iRef));
                 }
                 i = i + 2;
             }
         }
     }
     // preload column names for backward-compatibility
     this._functionId = dataset.get_functionId();
     if (this._isAvg) {
         this._columnNames.Clear();
         this._columnNames.Add(""+this._functionId+"_min");
         this._columnNames.Add(""+this._functionId+"_avg");
         this._columnNames.Add(""+this._functionId+"_max");
         this._nCols = 3;
     } else {
         this._columnNames.Clear();
         this._columnNames.Add(this._functionId);
         this._nCols = 1;
     }
     // decode min/avg/max values for the sequence
     if (this._nRows > 0) {
         if (this._isScal32) {
             this._avgVal = this._decodeAvg(encoded[8] + (((((encoded[9]) ^ (0x8000))) << (16))), 1);
             this._minVal = this._decodeVal(encoded[10] + (((encoded[11]) << (16))));
             this._maxVal = this._decodeVal(encoded[12] + (((encoded[13]) << (16))));
         } else {
             this._minVal = this._decodeVal(encoded[8]);
             this._maxVal = this._decodeVal(encoded[9]);
             this._avgVal = this._decodeAvg(encoded[10] + (((encoded[11]) << (16))), this._nRows);
         }
     }
     return 0;
 }
Exemplo n.º 4
0
    public override int _parserHelper()
    {
      int position = 0;
      int maxpos = 0;
      List<int> iCalib = new List<int>();
      int iRaw = 0;
      int iRef = 0;
      double fRaw = 0;
      double fRef = 0;
      // Store inverted resolution, to provide better rounding
      if (this._resolution > 0)
      {
        this._iresol = Math.Round(1.0 / this._resolution);
      }
      else
      {
        return 0;
      }

      this._scale = -1;
      this._calpar.Clear();
      this._calraw.Clear();
      this._calref.Clear();

      // Old format: supported when there is no calibration
      if (this._calibrationParam == "" || this._calibrationParam == "0")
      {
        this._caltyp = 0;
        return 0;
      }
      // Old format: calibrated value will be provided by the device
      if ((this._calibrationParam).IndexOf(",") >= 0)
      {
        this._caltyp = -1;
        return 0;
      }
      // New format, decode parameters
      iCalib = YAPI._decodeWords(this._calibrationParam);
      // In case of unknown format, calibrated value will be provided by the device
      if (iCalib.Count < 2)
      {
        this._caltyp = -1;
        return 0;
      }

      // Save variable format (scale for scalar, or decimal exponent)
      this._isScal = (iCalib[1] > 0);
      if (this._isScal)
      {
        this._offset = iCalib[0];
        if (this._offset > 32767)
        {
          this._offset = this._offset - 65536;
        }
        this._scale = iCalib[1];
        this._decexp = 0;
      }
      else
      {
        this._offset = 0;
        this._scale = 1;
        this._decexp = 1.0;
        position = iCalib[0];
        while (position > 0)
        {
          this._decexp = this._decexp * 10;
          position = position - 1;
        }
      }

      // Shortcut when there is no calibration parameter
      if (iCalib.Count == 2)
      {
        this._caltyp = 0;
        return 0;
      }

      this._caltyp = iCalib[2];
      this._calhdl = YAPI._getCalibrationHandler(this._caltyp);
      // parse calibration points
      position = 3;
      if (this._caltyp <= 10)
      {
        maxpos = this._caltyp;
      }
      else
      {
        if (this._caltyp <= 20)
        {
          maxpos = this._caltyp - 10;
        }
        else
        {
          maxpos = 5;
        }
      }
      maxpos = 3 + 2 * maxpos;
      if (maxpos > iCalib.Count)
      {
        maxpos = iCalib.Count;
      }
      this._calpar.Clear();
      this._calraw.Clear();
      this._calref.Clear();
      while (position + 1 < maxpos)
      {
        iRaw = iCalib[position];
        iRef = iCalib[position + 1];
        this._calpar.Add(iRaw);
        this._calpar.Add(iRef);
        if (this._isScal)
        {
          fRaw = iRaw;
          fRaw = (fRaw - this._offset) / this._scale;
          fRef = iRef;
          fRef = (fRef - this._offset) / this._scale;
          this._calraw.Add(fRaw);
          this._calref.Add(fRef);
        }
        else
        {
          this._calraw.Add(YAPI._decimalToDouble(iRaw));
          this._calref.Add(YAPI._decimalToDouble(iRef));
        }
        position = position + 2;
      }



      return 0;
    }