//--- (end of generated code: YFileRecord definitions)

    public YFileRecord(string data)
    {
      YAPI.TJsonParser p;
      Nullable<YAPI.TJSONRECORD> node;
      //--- (generated code: YFileRecord attributes initialization)
      //--- (end of generated code: YFileRecord attributes initialization)
      p = new YAPI.TJsonParser(data, false);
      node = p.GetChildNode(null, "name");
      this._name = node.Value.svalue;
      node = p.GetChildNode(null, "size");
      this._size = (int)node.Value.ivalue;
      node = p.GetChildNode(null, "crc");
      this._crc = (int)node.Value.ivalue;
    }
    //--- (end of generated code: YWlanRecord definitions)

    public YWlanRecord(string data)
    {
      YAPI.TJsonParser p;
      Nullable<YAPI.TJSONRECORD> node;
      //--- (generated code: YWlanRecord attributes initialization)
      //--- (end of generated code: YWlanRecord attributes initialization)
      p = new YAPI.TJsonParser(data, false);
      node = p.GetChildNode(null, "ssid");
      this._ssid = node.Value.svalue;
      node = p.GetChildNode(null, "sec");
      this._sec = node.Value.svalue;
      node = p.GetChildNode(null, "rssi");
      this._rssi = (int)node.Value.ivalue;
      node = p.GetChildNode(null, "channel");
      this._channel = (int)node.Value.ivalue;
    }
    //--- (end of generated code: YDataLogger implementation)


    public int getData(long runIdx, long timeIdx, ref YAPI.TJsonParser jsondata)
    {
      YAPI.YDevice dev = null;
      string errmsg = "";
      string query = null;
      string buffer = "";
      int res = 0;

      if (_dataLoggerURL == "") _dataLoggerURL = "/logger.json";

      // Resolve our reference to our device, load REST API
      res = _getDevice(ref dev, ref errmsg);
      if (YAPI.YISERR(res))
      {
        _throw(res, errmsg);
        return res;
      }

      if (timeIdx > 0)
      {
        query = "GET " + _dataLoggerURL + "?run=" + runIdx.ToString() + "&time=" + timeIdx.ToString() + " HTTP/1.1\r\n\r\n";
      }
      else
      {
        query = "GET " + _dataLoggerURL + " HTTP/1.1\r\n\r\n";
      }

      res = dev.HTTPRequest(query, ref buffer, ref errmsg);
      if (YAPI.YISERR(res))
      {
        res = YAPI.UpdateDeviceList(ref errmsg);
        if (YAPI.YISERR(res))
        {
          _throw(res, errmsg);
          return res;
        }

        res = dev.HTTPRequest("GET " + _dataLoggerURL + " HTTP/1.1\r\n\r\n", ref buffer, ref errmsg);
        if (YAPI.YISERR(res))
        {
          _throw(res, errmsg);
          return res;
        }
      }

      try
      {
        jsondata = new YAPI.TJsonParser(buffer);
      }
      catch (Exception e)
      {
        errmsg = "unexpected JSON structure: " + e.Message;
        _throw(YAPI.IO_ERROR, errmsg);
        return YAPI.IO_ERROR;
      }
      if (jsondata.httpcode == 404 && _dataLoggerURL != "/dataLogger.json")
      {
        // retry using backward-compatible datalogger URL
        _dataLoggerURL = "/dataLogger.json";
        return this.getData(runIdx, timeIdx, ref jsondata);
      }
      return YAPI.SUCCESS;
    }
 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;
 }
    protected List<string> _json_get_array(byte[] data)
    {
      string st = YAPI.DefaultEncoding.GetString(data);
      YAPI.TJsonParser p;

      if (!YAPI.ExceptionsDisabled) p = new YAPI.TJsonParser(st, false);
      else try
        {
          p = new YAPI.TJsonParser(st, false);
        }
        catch
        {

          return null;
        }


      return p.GetAllChilds(null);
    }
    protected string _json_get_key(byte[] data, string key)
    {
      Nullable<YAPI.TJSONRECORD> node;

      string st = YAPI.DefaultEncoding.GetString(data);
      YAPI.TJsonParser p;

      if (!YAPI.ExceptionsDisabled) p = new YAPI.TJsonParser(st, false);
      else try
        {
          p = new YAPI.TJsonParser(st, false);
        }
        catch
        {
          return "";
        }




      node = p.GetChildNode(null, key);

      return node.Value.svalue;
    }
    protected int _parse(string data)
    {
      YAPI.TJsonParser p;

      if (!YAPI.ExceptionsDisabled) p = new YAPI.TJsonParser(data, false);
      else try
        {
          p = new YAPI.TJsonParser(data, false);
        }
        catch
        {

          return YAPI.NOT_SUPPORTED;
        }

      Nullable<YAPI.TJSONRECORD> node, arr;
      YDataStream stream;
      double summaryMinVal = Double.MaxValue;
      double summaryMaxVal = -Double.MaxValue;
      double summaryTotalTime = 0;
      double summaryTotalAvg = 0;

      node = p.GetChildNode(null, "id");
      this._functionId = node.Value.svalue;
      node = p.GetChildNode(null, "unit");
      this._unit = node.Value.svalue;
      node = p.GetChildNode(null, "cal");
      this._calib = YAPI._decodeWords(node.Value.svalue);
      arr = p.GetChildNode(null, "streams");
      this._streams = new List<YDataStream>();
      this._preview = new List<YMeasure>();
      this._measures = new List<YMeasure>();
      for (int i = 0; i < arr.Value.itemcount; i++)
      {
        stream = _parent._findDataStream(this, arr.Value.items[i].svalue);
        if (_startTime > 0 && stream.get_startTimeUTC() + stream.get_duration() <= _startTime)
        {
          // this stream is too early, drop it
        }
        else if (_endTime > 0 && stream.get_startTimeUTC() > this._endTime)
        {
          // this stream is too late, drop it
        }
        else
        {
          _streams.Add(stream);
          if (stream.isClosed() && stream.get_startTimeUTC() >= this._startTime &&
             (this._endTime == 0 || stream.get_startTimeUTC() + stream.get_duration() <= this._endTime))
          {
            if (summaryMinVal > stream.get_minValue())
            {
              summaryMinVal = stream.get_minValue();
            }
            if (summaryMaxVal < stream.get_maxValue())
            {
              summaryMaxVal = stream.get_maxValue();
            }
            summaryTotalAvg += stream.get_averageValue() * stream.get_duration();
            summaryTotalTime += stream.get_duration();

            YMeasure rec = new YMeasure(
                                stream.get_startTimeUTC(),
                                stream.get_startTimeUTC() + stream.get_duration(),
                                stream.get_minValue(),
                                stream.get_averageValue(),
                                stream.get_maxValue());
            this._preview.Add(rec);
          }
        }
      }
      if ((this._streams.Count > 0) && (summaryTotalTime > 0))
      {
        // update time boundaries with actual data
        stream = this._streams[this._streams.Count - 1];
        UInt32 endtime = (UInt32)(stream.get_startTimeUTC() + stream.get_duration());
        UInt32 startTime = (UInt32)(this._streams[0].get_startTimeUTC() - stream.get_dataSamplesIntervalMs() / 1000);
        if (this._startTime < startTime)
        {
          this._startTime = startTime;
        }
        if (this._endTime == 0 || this._endTime > endtime)
        {
          this._endTime = endtime;
        }
        this._summary = new YMeasure(
                                    _startTime,
                                    _endTime,
                                    summaryMinVal,
                                    summaryTotalAvg / summaryTotalTime,
                                    summaryMaxVal);
      }
      this._progress = 0;
      return this.get_progress();
    }