// access to all fields bool EnoceanDevice::accessField(PropertyAccessMode aMode, ApiValuePtr aPropValue, PropertyDescriptorPtr aPropertyDescriptor) { if (aPropertyDescriptor->hasObjectKey(enoceanDevice_key)) { if (aMode==access_read) { // read properties switch (aPropertyDescriptor->fieldKey()) { case profileVariants_key: aPropValue->setType(apivalue_object); // make object (incoming object is NULL) return getProfileVariants(aPropValue); case profile_key: aPropValue->setInt32Value(getEEProfile()); return true; case packetage_key: // Note lastPacketTime is set to now at startup, so additionally check lastRSSI if (lastPacketTime==Never || lastRSSI<=-999) aPropValue->setNull(); else aPropValue->setDoubleValue((double)(MainLoop::now()-lastPacketTime)/Second); return true; case rssi_key: if (lastRSSI<=-999) aPropValue->setNull(); else aPropValue->setInt32Value(lastRSSI); return true; case repeaterCount_key: if (lastRSSI<=-999) aPropValue->setNull(); else aPropValue->setUint8Value(lastRepeaterCount); return true; } } else { // write properties switch (aPropertyDescriptor->fieldKey()) { case profile_key: setProfileVariant(aPropValue->int32Value()); return true; } } } // not my field, let base class handle it return inherited::accessField(aMode, aPropValue, aPropertyDescriptor); }
// access to all fields bool ChannelBehaviour::accessField(PropertyAccessMode aMode, ApiValuePtr aPropValue, PropertyDescriptorPtr aPropertyDescriptor) { if (aPropertyDescriptor->hasObjectKey(channel_Key)) { if (aMode==access_read) { // read properties switch (aPropertyDescriptor->fieldKey()) { // Description properties case name_key+descriptions_key_offset: aPropValue->setStringValue(getName()); return true; case channelIndex_key+descriptions_key_offset: aPropValue->setUint8Value(channelIndex); return true; case min_key+descriptions_key_offset: aPropValue->setDoubleValue(getMin()); return true; case max_key+descriptions_key_offset: aPropValue->setDoubleValue(getMax()); return true; case resolution_key+descriptions_key_offset: aPropValue->setDoubleValue(getResolution()); return true; // Settings properties // - none for now // States properties case value_key+states_key_offset: // get value of channel, possibly calculating it if needed (color conversions) aPropValue->setDoubleValue(getChannelValueCalculated()); return true; case age_key+states_key_offset: if (channelLastSync==Never) aPropValue->setNull(); // no value known else aPropValue->setDoubleValue((double)(MainLoop::now()-channelLastSync)/Second); return true; } } else { // write properties switch (aPropertyDescriptor->fieldKey()) { // Settings properties // - none for now // States properties case value_key+states_key_offset: setChannelValue(aPropValue->doubleValue(), 0, true); // always apply, no transition time return true; } } } // single class level properties only, don't call inherited return false; }
bool SensorBehaviour::accessField(PropertyAccessMode aMode, ApiValuePtr aPropValue, PropertyDescriptorPtr aPropertyDescriptor) { if (aPropertyDescriptor->hasObjectKey(sensor_key)) { if (aMode==access_read) { // read properties switch (aPropertyDescriptor->fieldKey()) { // Description properties case sensorType_key+descriptions_key_offset: aPropValue->setUint16Value(sensorType); return true; case sensorUsage_key+descriptions_key_offset: aPropValue->setUint16Value(sensorUsage); return true; case min_key+descriptions_key_offset: aPropValue->setDoubleValue(min); return true; case max_key+descriptions_key_offset: aPropValue->setDoubleValue(max); return true; case resolution_key+descriptions_key_offset: aPropValue->setDoubleValue(resolution); return true; case updateInterval_key+descriptions_key_offset: aPropValue->setDoubleValue((double)updateInterval/Second); return true; case aliveSignInterval_key+descriptions_key_offset: aPropValue->setDoubleValue((double)aliveSignInterval/Second); return true; // Settings properties case group_key+settings_key_offset: aPropValue->setUint16Value(sensorGroup); return true; case minPushInterval_key+settings_key_offset: aPropValue->setDoubleValue((double)minPushInterval/Second); return true; case changesOnlyInterval_key+settings_key_offset: aPropValue->setDoubleValue((double)changesOnlyInterval/Second); return true; // States properties case value_key+states_key_offset: // value if (lastUpdate==Never) aPropValue->setNull(); else aPropValue->setDoubleValue(currentValue); return true; case age_key+states_key_offset: // age if (lastUpdate==Never) aPropValue->setNull(); else aPropValue->setDoubleValue((double)(MainLoop::now()-lastUpdate)/Second); return true; } } else { // write properties switch (aPropertyDescriptor->fieldKey()) { // Settings properties case group_key+settings_key_offset: setPVar(sensorGroup, (DsGroup)aPropValue->int32Value()); return true; case minPushInterval_key+settings_key_offset: setPVar(minPushInterval, (MLMicroSeconds)(aPropValue->doubleValue()*Second)); return true; case changesOnlyInterval_key+settings_key_offset: setPVar(changesOnlyInterval, (MLMicroSeconds)(aPropValue->doubleValue()*Second)); return true; } } } // not my field, let base class handle it return inherited::accessField(aMode, aPropValue, aPropertyDescriptor); }
// access to all fields bool ChannelBehaviour::accessField(PropertyAccessMode aMode, ApiValuePtr aPropValue, PropertyDescriptorPtr aPropertyDescriptor) { if (aPropertyDescriptor->hasObjectKey(channel_Key)) { if (aMode==access_read) { // read properties switch (aPropertyDescriptor->fieldKey()) { // Description properties case name_key+descriptions_key_offset: aPropValue->setStringValue(getName()); return true; case channelIndex_key+descriptions_key_offset: if (aPropertyDescriptor->getApiVersion()>=3) return false; // property does not exist any more in v3 and later aPropValue->setUint8Value(channelIndex); return true; case dsIndex_key+descriptions_key_offset: aPropValue->setUint8Value(channelIndex); return true; case channelType_key+descriptions_key_offset: aPropValue->setUint8Value(getChannelType()); return true; case siunit_key+descriptions_key_offset: aPropValue->setStringValue(valueUnitName(getChannelUnit(), false)); return true; case unitsymbol_key+descriptions_key_offset: aPropValue->setStringValue(valueUnitName(getChannelUnit(), true)); return true; case min_key+descriptions_key_offset: aPropValue->setDoubleValue(getMin()); return true; case max_key+descriptions_key_offset: aPropValue->setDoubleValue(getMax()); return true; case resolution_key+descriptions_key_offset: aPropValue->setDoubleValue(getResolution()); return true; // Settings properties // - none for now // States properties case value_key+states_key_offset: // get value of channel, possibly calculating it if needed (color conversions) aPropValue->setDoubleValue(getChannelValueCalculated()); return true; case age_key+states_key_offset: if (channelLastSync==Never) aPropValue->setNull(); // no value known else aPropValue->setDoubleValue((double)(MainLoop::now()-channelLastSync)/Second); // time of last sync (does not necessarily relate to currently visible "value", as this might be a to-be-applied new value already) return true; } } else { // write properties switch (aPropertyDescriptor->fieldKey()) { // Settings properties // - none for now // States properties case value_key+states_key_offset: setChannelValue(aPropValue->doubleValue(), output.transitionTime, true); // always apply, default transition time (normally 0, unless set in outputState) return true; } } } // single class level properties only, don't call inherited return false; }