//--- (YDualPower implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "powerState")
      {
        _powerState = (int)member.ivalue;
        return;
      }
      if (member.name == "powerControl")
      {
        _powerControl = (int)member.ivalue;
        return;
      }
      if (member.name == "extVoltage")
      {
        _extVoltage = (int)member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YWatchdog implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "state")
      {
        _state = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "stateAtPowerOn")
      {
        _stateAtPowerOn = (int)member.ivalue;
        return;
      }
      if (member.name == "maxTimeOnStateA")
      {
        _maxTimeOnStateA = member.ivalue;
        return;
      }
      if (member.name == "maxTimeOnStateB")
      {
        _maxTimeOnStateB = member.ivalue;
        return;
      }
      if (member.name == "output")
      {
        _output = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "pulseTimer")
      {
        _pulseTimer = member.ivalue;
        return;
      }
      if (member.name == "delayedPulseTimer")
      {
        if (member.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRUCT)
        {
          YAPI.TJSONRECORD submemb;
          for (int l = 0; l < member.membercount; l++)
          {
            submemb = member.members[l];
            if (submemb.name == "moving")
              _delayedPulseTimer.moving = (int)submemb.ivalue;
            else if (submemb.name == "target")
              _delayedPulseTimer.target = (int)submemb.ivalue;
            else if (submemb.name == "ms")
              _delayedPulseTimer.ms = (int)submemb.ivalue;
          }
        }
        return;
      }
      if (member.name == "countdown")
      {
        _countdown = member.ivalue;
        return;
      }
      if (member.name == "autoStart")
      {
        _autoStart = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "running")
      {
        _running = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "triggerDelay")
      {
        _triggerDelay = member.ivalue;
        return;
      }
      if (member.name == "triggerDuration")
      {
        _triggerDuration = member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (generated code: YDisplay implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "enabled")
      {
        _enabled = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "startupSeq")
      {
        _startupSeq = member.svalue;
        return;
      }
      if (member.name == "brightness")
      {
        _brightness = (int)member.ivalue;
        return;
      }
      if (member.name == "orientation")
      {
        _orientation = (int)member.ivalue;
        return;
      }
      if (member.name == "displayWidth")
      {
        _displayWidth = (int)member.ivalue;
        return;
      }
      if (member.name == "displayHeight")
      {
        _displayHeight = (int)member.ivalue;
        return;
      }
      if (member.name == "displayType")
      {
        _displayType = (int)member.ivalue;
        return;
      }
      if (member.name == "layerWidth")
      {
        _layerWidth = (int)member.ivalue;
        return;
      }
      if (member.name == "layerHeight")
      {
        _layerHeight = (int)member.ivalue;
        return;
      }
      if (member.name == "layerCount")
      {
        _layerCount = (int)member.ivalue;
        return;
      }
      if (member.name == "command")
      {
        _command = member.svalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YVoc implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      base._parseAttr(member);
    }
    //--- (YServo implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "position")
      {
        _position = (int)member.ivalue;
        return;
      }
      if (member.name == "enabled")
      {
        _enabled = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "range")
      {
        _range = (int)member.ivalue;
        return;
      }
      if (member.name == "neutral")
      {
        _neutral = (int)member.ivalue;
        return;
      }
      if (member.name == "move")
      {
        if (member.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRUCT)
        {
          YAPI.TJSONRECORD submemb;
          for (int l = 0; l < member.membercount; l++)
          {
            submemb = member.members[l];
            if (submemb.name == "moving")
              _move.moving = (int)submemb.ivalue;
            else if (submemb.name == "target")
              _move.target = (int)submemb.ivalue;
            else if (submemb.name == "ms")
              _move.ms = (int)submemb.ivalue;
          }
        }
        return;
      }
      if (member.name == "positionAtPowerOn")
      {
        _positionAtPowerOn = (int)member.ivalue;
        return;
      }
      if (member.name == "enabledAtPowerOn")
      {
        _enabledAtPowerOn = member.ivalue > 0 ? 1 : 0;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YColorLed implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "rgbColor")
      {
        _rgbColor = (int)member.ivalue;
        return;
      }
      if (member.name == "hslColor")
      {
        _hslColor = (int)member.ivalue;
        return;
      }
      if (member.name == "rgbMove")
      {
        if (member.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRUCT)
        {
          YAPI.TJSONRECORD submemb;
          for (int l = 0; l < member.membercount; l++)
          {
            submemb = member.members[l];
            if (submemb.name == "moving")
              _rgbMove.moving = (int)submemb.ivalue;
            else if (submemb.name == "target")
              _rgbMove.target = (int)submemb.ivalue;
            else if (submemb.name == "ms")
              _rgbMove.ms = (int)submemb.ivalue;
          }
        }
        return;
      }
      if (member.name == "hslMove")
      {
        if (member.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRUCT)
        {
          YAPI.TJSONRECORD submemb;
          for (int l = 0; l < member.membercount; l++)
          {
            submemb = member.members[l];
            if (submemb.name == "moving")
              _hslMove.moving = (int)submemb.ivalue;
            else if (submemb.name == "target")
              _hslMove.target = (int)submemb.ivalue;
            else if (submemb.name == "ms")
              _hslMove.ms = (int)submemb.ivalue;
          }
        }
        return;
      }
      if (member.name == "rgbColorAtPowerOn")
      {
        _rgbColorAtPowerOn = (int)member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (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;
    }
    //--- (generated code: YModule implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "productName")
      {
        _productName = member.svalue;
        return;
      }
      if (member.name == "serialNumber")
      {
        _serialNumber = member.svalue;
        return;
      }
      if (member.name == "productId")
      {
        _productId = (int)member.ivalue;
        return;
      }
      if (member.name == "productRelease")
      {
        _productRelease = (int)member.ivalue;
        return;
      }
      if (member.name == "firmwareRelease")
      {
        _firmwareRelease = member.svalue;
        return;
      }
      if (member.name == "persistentSettings")
      {
        _persistentSettings = (int)member.ivalue;
        return;
      }
      if (member.name == "luminosity")
      {
        _luminosity = (int)member.ivalue;
        return;
      }
      if (member.name == "beacon")
      {
        _beacon = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "upTime")
      {
        _upTime = member.ivalue;
        return;
      }
      if (member.name == "usbCurrent")
      {
        _usbCurrent = (int)member.ivalue;
        return;
      }
      if (member.name == "rebootCountdown")
      {
        _rebootCountdown = (int)member.ivalue;
        return;
      }
      if (member.name == "usbBandwidth")
      {
        _usbBandwidth = (int)member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
 public void setImmutableAttributes(ref YAPI.yDeviceSt infos)
 {
   _serialNumber = infos.serial;
   _productName = infos.productname;
   _productId = infos.deviceid;
 }
 protected int _parse(YAPI.TJSONRECORD j)
 {
   int i = 0;
   if ((j.recordtype != YAPI.TJSONRECORDTYPE.JSON_STRUCT)) return -1;
   for (i = 0; i < j.membercount; i++)
   {
     _parseAttr(j.members[i]);
   }
   _parserHelper();
   return 0;
 }
    //--- (generated code: YFunction implementation)

    protected virtual void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "logicalName")
      {
        _logicalName = member.svalue;
        return;
      }
      if (member.name == "advertisedValue")
      {
        _advertisedValue = member.svalue;
        return;
      }
    }
    // Return a pointer to our device caching object (may trigger a hub scan)
    protected YRETCODE _getDevice(ref YAPI.YDevice dev, ref string errMsg)
    {
      YRETCODE functionReturnValue = default(YRETCODE);
      YFUN_DESCR fundescr = default(YFUN_DESCR);
      YDEV_DESCR devdescr = default(YDEV_DESCR);
      YRETCODE res = default(YRETCODE);

      // Resolve function name
      res = _getDescriptor(ref fundescr, ref errMsg);
      if ((YAPI.YISERR(res)))
      {
        functionReturnValue = res;
        return functionReturnValue;
      }

      // Get device descriptor
      devdescr = YAPI.yapiGetDeviceByFunction(fundescr, ref errMsg);
      if ((YAPI.YISERR(devdescr)))
      {
        return devdescr;
      }

      // Get device object
      dev = YAPI.YDevice.getDevice(devdescr);

      functionReturnValue = YAPI.SUCCESS;
      return functionReturnValue;
    }
 public static void RegisterCalibrationHandler(int calibType, YAPI.yCalibrationHandler callback)
 {
   string key;
   key = calibType.ToString();
   YFunction._CalibHandlers.Add(key, callback);
 }
    //--- (YWakeUpSchedule implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "minutesA")
      {
        _minutesA = (int)member.ivalue;
        return;
      }
      if (member.name == "minutesB")
      {
        _minutesB = (int)member.ivalue;
        return;
      }
      if (member.name == "hours")
      {
        _hours = (int)member.ivalue;
        return;
      }
      if (member.name == "weekDays")
      {
        _weekDays = (int)member.ivalue;
        return;
      }
      if (member.name == "monthDays")
      {
        _monthDays = (int)member.ivalue;
        return;
      }
      if (member.name == "months")
      {
        _months = (int)member.ivalue;
        return;
      }
      if (member.name == "nextOccurence")
      {
        _nextOccurence = member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YPwmOutput implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "enabled")
      {
        _enabled = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "dutyCycle")
      {
        _dutyCycle = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "pulseDuration")
      {
        _pulseDuration = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "frequency")
      {
        _frequency = (int)member.ivalue;
        return;
      }
      if (member.name == "period")
      {
        _period = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "pwmTransition")
      {
        _pwmTransition = member.svalue;
        return;
      }
      if (member.name == "enabledAtPowerOn")
      {
        _enabledAtPowerOn = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "dutyCycleAtPowerOn")
      {
        _dutyCycleAtPowerOn = member.ivalue / 65536.0;
        return;
      }
      base._parseAttr(member);
    }
    //--- (generated code: YSensor implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "unit")
      {
        _unit = member.svalue;
        return;
      }
      if (member.name == "currentValue")
      {
        _currentValue = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "lowestValue")
      {
        _lowestValue = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "highestValue")
      {
        _highestValue = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "currentRawValue")
      {
        _currentRawValue = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "logFrequency")
      {
        _logFrequency = member.svalue;
        return;
      }
      if (member.name == "reportFrequency")
      {
        _reportFrequency = member.svalue;
        return;
      }
      if (member.name == "calibrationParam")
      {
        _calibrationParam = member.svalue;
        return;
      }
      if (member.name == "resolution")
      {
        _resolution = (member.ivalue > 100 ? 1.0 / Math.Round(65536.0 / member.ivalue) : 0.001 / Math.Round(67.0 / member.ivalue));
        return;
      }
      base._parseAttr(member);
    }
    //--- (YOsControl implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "shutdownCountdown")
      {
        _shutdownCountdown = (int)member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YTilt implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "axis")
      {
        _axis = (int)member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (generated code: YDataLogger implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "currentRunIndex")
      {
        _currentRunIndex = (int)member.ivalue;
        return;
      }
      if (member.name == "timeUTC")
      {
        _timeUTC = member.ivalue;
        return;
      }
      if (member.name == "recording")
      {
        _recording = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "autoStart")
      {
        _autoStart = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "clearHistory")
      {
        _clearHistory = member.ivalue > 0 ? 1 : 0;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YNetwork implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "readiness")
      {
        _readiness = (int)member.ivalue;
        return;
      }
      if (member.name == "macAddress")
      {
        _macAddress = member.svalue;
        return;
      }
      if (member.name == "ipAddress")
      {
        _ipAddress = member.svalue;
        return;
      }
      if (member.name == "subnetMask")
      {
        _subnetMask = member.svalue;
        return;
      }
      if (member.name == "router")
      {
        _router = member.svalue;
        return;
      }
      if (member.name == "ipConfig")
      {
        _ipConfig = member.svalue;
        return;
      }
      if (member.name == "primaryDNS")
      {
        _primaryDNS = member.svalue;
        return;
      }
      if (member.name == "secondaryDNS")
      {
        _secondaryDNS = member.svalue;
        return;
      }
      if (member.name == "userPassword")
      {
        _userPassword = member.svalue;
        return;
      }
      if (member.name == "adminPassword")
      {
        _adminPassword = member.svalue;
        return;
      }
      if (member.name == "discoverable")
      {
        _discoverable = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "wwwWatchdogDelay")
      {
        _wwwWatchdogDelay = (int)member.ivalue;
        return;
      }
      if (member.name == "callbackUrl")
      {
        _callbackUrl = member.svalue;
        return;
      }
      if (member.name == "callbackMethod")
      {
        _callbackMethod = (int)member.ivalue;
        return;
      }
      if (member.name == "callbackEncoding")
      {
        _callbackEncoding = (int)member.ivalue;
        return;
      }
      if (member.name == "callbackCredentials")
      {
        _callbackCredentials = member.svalue;
        return;
      }
      if (member.name == "callbackMinDelay")
      {
        _callbackMinDelay = (int)member.ivalue;
        return;
      }
      if (member.name == "callbackMaxDelay")
      {
        _callbackMaxDelay = (int)member.ivalue;
        return;
      }
      if (member.name == "poeCurrent")
      {
        _poeCurrent = (int)member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (generated code: YFiles implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "filesCount")
      {
        _filesCount = (int)member.ivalue;
        return;
      }
      if (member.name == "freeSpace")
      {
        _freeSpace = (int)member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YRealTimeClock implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "unixTime")
      {
        _unixTime = member.ivalue;
        return;
      }
      if (member.name == "dateTime")
      {
        _dateTime = member.svalue;
        return;
      }
      if (member.name == "utcOffset")
      {
        _utcOffset = (int)member.ivalue;
        return;
      }
      if (member.name == "timeSet")
      {
        _timeSet = member.ivalue > 0 ? 1 : 0;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YCompass implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "axis")
      {
        _axis = (int)member.ivalue;
        return;
      }
      if (member.name == "magneticHeading")
      {
        _magneticHeading = member.ivalue / 65536.0;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YAltitude implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "qnh")
      {
        _qnh = member.ivalue / 65536.0;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YTemperature implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "sensorType")
      {
        _sensorType = (int)member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YMagnetometer implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "xValue")
      {
        _xValue = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "yValue")
      {
        _yValue = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "zValue")
      {
        _zValue = member.ivalue / 65536.0;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YDigitalIO implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "portState")
      {
        _portState = (int)member.ivalue;
        return;
      }
      if (member.name == "portDirection")
      {
        _portDirection = (int)member.ivalue;
        return;
      }
      if (member.name == "portOpenDrain")
      {
        _portOpenDrain = (int)member.ivalue;
        return;
      }
      if (member.name == "portPolarity")
      {
        _portPolarity = (int)member.ivalue;
        return;
      }
      if (member.name == "portSize")
      {
        _portSize = (int)member.ivalue;
        return;
      }
      if (member.name == "outputVoltage")
      {
        _outputVoltage = (int)member.ivalue;
        return;
      }
      if (member.name == "command")
      {
        _command = member.svalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YWakeUpMonitor implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "powerDuration")
      {
        _powerDuration = (int)member.ivalue;
        return;
      }
      if (member.name == "sleepCountdown")
      {
        _sleepCountdown = (int)member.ivalue;
        return;
      }
      if (member.name == "nextWakeUp")
      {
        _nextWakeUp = member.ivalue;
        return;
      }
      if (member.name == "wakeUpReason")
      {
        _wakeUpReason = (int)member.ivalue;
        return;
      }
      if (member.name == "wakeUpState")
      {
        _wakeUpState = (int)member.ivalue;
        return;
      }
      if (member.name == "rtcTime")
      {
        _rtcTime = member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YAnButton implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "calibratedValue")
      {
        _calibratedValue = (int)member.ivalue;
        return;
      }
      if (member.name == "rawValue")
      {
        _rawValue = (int)member.ivalue;
        return;
      }
      if (member.name == "analogCalibration")
      {
        _analogCalibration = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "calibrationMax")
      {
        _calibrationMax = (int)member.ivalue;
        return;
      }
      if (member.name == "calibrationMin")
      {
        _calibrationMin = (int)member.ivalue;
        return;
      }
      if (member.name == "sensitivity")
      {
        _sensitivity = (int)member.ivalue;
        return;
      }
      if (member.name == "isPressed")
      {
        _isPressed = member.ivalue > 0 ? 1 : 0;
        return;
      }
      if (member.name == "lastTimePressed")
      {
        _lastTimePressed = member.ivalue;
        return;
      }
      if (member.name == "lastTimeReleased")
      {
        _lastTimeReleased = member.ivalue;
        return;
      }
      if (member.name == "pulseCounter")
      {
        _pulseCounter = member.ivalue;
        return;
      }
      if (member.name == "pulseTimer")
      {
        _pulseTimer = member.ivalue;
        return;
      }
      base._parseAttr(member);
    }
    //--- (YRefFrame implementation)

    protected override void _parseAttr(YAPI.TJSONRECORD member)
    {
      if (member.name == "mountPos")
      {
        _mountPos = (int)member.ivalue;
        return;
      }
      if (member.name == "bearing")
      {
        _bearing = member.ivalue / 65536.0;
        return;
      }
      if (member.name == "calibrationParam")
      {
        _calibrationParam = member.svalue;
        return;
      }
      base._parseAttr(member);
    }