diff --git a/extras/test/CMakeLists.txt b/extras/test/CMakeLists.txt index dfe322324..04b36a1d2 100644 --- a/extras/test/CMakeLists.txt +++ b/extras/test/CMakeLists.txt @@ -95,6 +95,8 @@ set(TEST_UTIL_SRCS set(TEST_DUT_SRCS ../../src/property/Property.cpp + ../../src/property/types/PropertyPrimitive.cpp + ../../src/property/types/CloudWrapperBase.cpp ../../src/property/PropertyContainer.cpp ../../src/cbor/CBORDecoder.cpp ../../src/cbor/CBOREncoder.cpp diff --git a/extras/test/src/test_CloudFloat.cpp b/extras/test/src/test_CloudFloat.cpp index 7f6437c40..7af0a9d32 100644 --- a/extras/test/src/test_CloudFloat.cpp +++ b/extras/test/src/test_CloudFloat.cpp @@ -10,7 +10,7 @@ #include -#include +#include /************************************************************************************** TEST CODE diff --git a/extras/test/src/test_CloudWrapperFloat.cpp b/extras/test/src/test_CloudWrapperFloat.cpp index aa4f6a295..c2af8f9e7 100644 --- a/extras/test/src/test_CloudWrapperFloat.cpp +++ b/extras/test/src/test_CloudWrapperFloat.cpp @@ -10,7 +10,7 @@ #include -#include +#include /************************************************************************************** TEST CODE diff --git a/extras/test/src/test_addPropertyReal.cpp b/extras/test/src/test_addPropertyReal.cpp index 27f647da5..8c5959104 100644 --- a/extras/test/src/test_addPropertyReal.cpp +++ b/extras/test/src/test_addPropertyReal.cpp @@ -10,11 +10,6 @@ #include -#include -#include -#include -#include - /************************************************************************************** TEST CODE **************************************************************************************/ diff --git a/extras/test/src/test_callback.cpp b/extras/test/src/test_callback.cpp index ae065ea66..5f7424784 100644 --- a/extras/test/src/test_callback.cpp +++ b/extras/test/src/test_callback.cpp @@ -11,7 +11,6 @@ #include #include #include -#include "types/CloudWrapperBool.h" #include /************************************************************************************** diff --git a/extras/test/src/test_decode.cpp b/extras/test/src/test_decode.cpp index 63306af87..622743a64 100644 --- a/extras/test/src/test_decode.cpp +++ b/extras/test/src/test_decode.cpp @@ -14,18 +14,9 @@ #include #include -#include "types/CloudWrapperBool.h" -#include "types/CloudWrapperFloat.h" -#include "types/CloudWrapperInt.h" #include "types/CloudWrapperString.h" #include "types/automation/CloudColoredLight.h" -#include "types/automation/CloudContactSensor.h" #include "types/automation/CloudDimmedLight.h" -#include "types/automation/CloudLight.h" -#include "types/automation/CloudMotionSensor.h" -#include "types/automation/CloudSmartPlug.h" -#include "types/automation/CloudSwitch.h" -#include "types/automation/CloudTemperatureSensor.h" #include "types/automation/CloudTelevision.h" using namespace Catch; diff --git a/extras/test/src/test_encode.cpp b/extras/test/src/test_encode.cpp index 581d87dfa..b3e6ca101 100644 --- a/extras/test/src/test_encode.cpp +++ b/extras/test/src/test_encode.cpp @@ -11,9 +11,6 @@ #include #include -#include "types/CloudWrapperBool.h" -#include "types/CloudWrapperFloat.h" -#include "types/CloudWrapperInt.h" #include "types/CloudWrapperString.h" /************************************************************************************** diff --git a/src/ArduinoIoTCloud.h b/src/ArduinoIoTCloud.h index 19e94555d..eca58fb6a 100644 --- a/src/ArduinoIoTCloud.h +++ b/src/ArduinoIoTCloud.h @@ -39,10 +39,6 @@ #include "property/Property.h" #include "property/PropertyContainer.h" -#include "property/types/CloudWrapperBool.h" -#include "property/types/CloudWrapperFloat.h" -#include "property/types/CloudWrapperInt.h" -#include "property/types/CloudWrapperUnsignedInt.h" #include "property/types/CloudWrapperString.h" #include "utility/time/TimeService.h" diff --git a/src/ArduinoIoTCloudThing.cpp b/src/ArduinoIoTCloudThing.cpp index 20ddc382d..64c6d7cc5 100644 --- a/src/ArduinoIoTCloudThing.cpp +++ b/src/ArduinoIoTCloudThing.cpp @@ -19,8 +19,6 @@ #include "ArduinoIoTCloudThing.h" #include "interfaces/CloudProcess.h" -#include "property/types/CloudWrapperInt.h" -#include "property/types/CloudWrapperUnsignedInt.h" /****************************************************************************** * CTOR/DTOR diff --git a/src/property/Property.h b/src/property/Property.h index 329d99e32..608b918de 100644 --- a/src/property/Property.h +++ b/src/property/Property.h @@ -117,10 +117,6 @@ enum class Permission { Read, Write, ReadWrite }; -enum class Type { - Bool, Int, Float, String -}; - enum class UpdatePolicy { OnChange, TimeInterval, OnDemand }; diff --git a/src/property/PropertyContainer.h b/src/property/PropertyContainer.h index 9dc3c86cd..bb5231aba 100644 --- a/src/property/PropertyContainer.h +++ b/src/property/PropertyContainer.h @@ -30,10 +30,8 @@ #undef min #include -#include "types/CloudBool.h" -#include "types/CloudFloat.h" -#include "types/CloudInt.h" -#include "types/CloudUnsignedInt.h" +#include "types/PropertyPrimitive.h" + #include "types/CloudString.h" #include "types/CloudLocation.h" #include "types/CloudSchedule.h" @@ -41,13 +39,7 @@ #include "types/CloudWrapperBase.h" #include "types/automation/CloudColoredLight.h" -#include "types/automation/CloudContactSensor.h" #include "types/automation/CloudDimmedLight.h" -#include "types/automation/CloudLight.h" -#include "types/automation/CloudMotionSensor.h" -#include "types/automation/CloudSmartPlug.h" -#include "types/automation/CloudSwitch.h" -#include "types/automation/CloudTemperatureSensor.h" #include "types/automation/CloudTelevision.h" /****************************************************************************** @@ -62,6 +54,16 @@ extern "C" unsigned long getTime(); typedef std::list PropertyContainer; +typedef PropertyPrimitive CloudBool; +typedef PropertyPrimitive CloudFloat; +typedef PropertyPrimitive CloudInt; +typedef PropertyPrimitive CloudUnsignedInt; + +typedef CloudWrapperProperty CloudWrapperBool; +typedef CloudWrapperProperty CloudWrapperFloat; +typedef CloudWrapperProperty CloudWrapperInt; +typedef CloudWrapperProperty CloudWrapperUnsignedInt; + typedef CloudFloat CloudEnergy; typedef CloudFloat CloudForce; typedef CloudFloat CloudTemperature; @@ -93,6 +95,13 @@ typedef CloudInt CloudInformationContent; typedef CloudFloat CloudPercentage; typedef CloudFloat CloudRelativeHumidity; +typedef CloudBool CloudContactSensor; +typedef CloudBool CloudLight; +typedef CloudBool CloudMotionSensor; +typedef CloudBool CloudSmartPlug; +typedef CloudBool CloudSwitch; +typedef CloudFloat CloudTemperatureSensor; + /****************************************************************************** FUNCTION DECLARATION ******************************************************************************/ @@ -104,7 +113,7 @@ Property & addPropertyToContainer(PropertyContainer & prop_cont, int propertyIdentifier = -1, GetTimeCallbackFunc func = getTime); - + Property * getProperty(PropertyContainer & prop_cont, String const & name); Property * getProperty(PropertyContainer & prop_cont, int const identifier); @@ -114,4 +123,4 @@ void requestUpdateForAllProperties(PropertyContainer & prop_cont); void updateProperty(PropertyContainer & prop_cont, String propertyName, unsigned long cloudChangeEventTime, bool const is_sync_message, std::list * map_data_list); String getPropertyNameByIdentifier(PropertyContainer & prop_cont, int propertyIdentifier); -#endif /* ARDUINO_PROPERTY_CONTAINER_H_ */ \ No newline at end of file +#endif /* ARDUINO_PROPERTY_CONTAINER_H_ */ diff --git a/src/property/types/CloudBool.h b/src/property/types/CloudBool.h deleted file mode 100644 index 3434656fc..000000000 --- a/src/property/types/CloudBool.h +++ /dev/null @@ -1,78 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDBOOL_H_ -#define CLOUDBOOL_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "../Property.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - - - -class CloudBool : public Property { - protected: - bool _value, - _cloud_value; - public: - CloudBool() { - CloudBool(false); - } - CloudBool(bool v) : _value(v), _cloud_value(v) {} - operator bool() const { - return _value; - } - virtual bool isDifferentFromCloud() { - return _value != _cloud_value; - } - virtual void fromCloudToLocal() { - _value = _cloud_value; - } - virtual void fromLocalToCloud() { - _cloud_value = _value; - } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { - return appendAttribute(_value, "", encoder); - } - virtual void setAttributesFromCloud() { - setAttribute(_cloud_value, ""); - } - //modifiers - CloudBool& operator=(bool v) { - _value = v; - updateLocalTimestamp(); - return *this; - } - CloudBool& operator=(CloudBool v) { - return operator=((bool)v); - } - //accessors - CloudBool operator!() const { - return CloudBool(!_value); - } - //friends -}; - - -#endif /* CLOUDBOOL_H_ */ diff --git a/src/property/types/CloudColor.h b/src/property/types/CloudColor.h index 54cb4f30f..def952e2c 100644 --- a/src/property/types/CloudColor.h +++ b/src/property/types/CloudColor.h @@ -161,7 +161,7 @@ class CloudColor : public Property { CloudColor() : _value(0, 0, 0), _cloud_value(0, 0, 0) {} CloudColor(float hue, float saturation, float brightness) : _value(hue, saturation, brightness), _cloud_value(hue, saturation, brightness) {} - virtual bool isDifferentFromCloud() { + bool isDifferentFromCloud() override { return _value != _cloud_value; } @@ -182,23 +182,23 @@ class CloudColor : public Property { return _value; } - virtual void fromCloudToLocal() { + void fromCloudToLocal() override { _value = _cloud_value; } - virtual void fromLocalToCloud() { + void fromLocalToCloud() override { _cloud_value = _value; } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CborError appendAttributesToCloud(CborEncoder *encoder) override { CHECK_CBOR_MULTI(appendAttribute(_value.hue, "hue", encoder)); CHECK_CBOR_MULTI(appendAttribute(_value.sat, "sat", encoder)); CHECK_CBOR_MULTI(appendAttribute(_value.bri, "bri", encoder)); return CborNoError; } - virtual void setAttributesFromCloud() { + void setAttributesFromCloud() override { setAttribute(_cloud_value.hue, "hue"); setAttribute(_cloud_value.sat, "sat"); setAttribute(_cloud_value.bri, "bri"); } }; -#endif /* CLOUDCOLOR_H_ */ \ No newline at end of file +#endif /* CLOUDCOLOR_H_ */ diff --git a/src/property/types/CloudFloat.h b/src/property/types/CloudFloat.h deleted file mode 100644 index 1918f9669..000000000 --- a/src/property/types/CloudFloat.h +++ /dev/null @@ -1,188 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDFLOAT_H_ -#define CLOUDFLOAT_H_ - -#include -#include "../math_utils.h" - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "../Property.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - - - -class CloudFloat : public Property { - protected: - float _value, - _cloud_value; - public: - CloudFloat() { - CloudFloat(0.0f); - } - CloudFloat(float v) : _value(v), _cloud_value(v) {} - operator float() const { - return _value; - } - virtual bool isDifferentFromCloud() { - return arduino::math::ieee754_different(_value, _cloud_value, Property::_min_delta_property); - } - virtual void fromCloudToLocal() { - _value = _cloud_value; - } - virtual void fromLocalToCloud() { - _cloud_value = _value; - } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { - return appendAttribute(_value, "", encoder); - } - virtual void setAttributesFromCloud() { - setAttribute(_cloud_value, ""); - } - //modifiers - CloudFloat& operator=(float v) { - _value = v; - updateLocalTimestamp(); - return *this; - } - CloudFloat& operator=(CloudFloat v) { - return operator=((float)v); - } - CloudFloat& operator+=(float v) { - return operator=(_value += v); - } - CloudFloat& operator-=(float v) { - return operator=(_value -= v); - } - CloudFloat& operator*=(float v) { - return operator=(_value *= v); - } - CloudFloat& operator/=(float v) { - return operator=(_value /= v); - } - CloudFloat& operator++() { - return operator=(_value + 1.0f); - } - CloudFloat& operator--() { - return operator=(_value - 1.0f); - } - CloudFloat operator++(int) { - operator=(_value + 1.0f); - return CloudFloat(_value); - } - CloudFloat operator--(int) { - operator=(_value - 1.0f); - return CloudFloat(_value); - } - - //friends - friend CloudFloat operator+(CloudFloat iw, CloudFloat v) { - return iw += v; - } - friend CloudFloat operator+(CloudFloat iw, float v) { - return iw += v; - } - friend CloudFloat operator+(CloudFloat iw, int v) { - return iw += (float)v; - } - friend CloudFloat operator+(CloudFloat iw, double v) { - return iw += (float)v; - } - friend CloudFloat operator+(float v, CloudFloat iw) { - return CloudFloat(v) += iw; - } - friend CloudFloat operator+(int v, CloudFloat iw) { - return CloudFloat(v) += iw; - } - friend CloudFloat operator+(double v, CloudFloat iw) { - return CloudFloat(v) += iw; - } - friend CloudFloat operator-(CloudFloat iw, CloudFloat v) { - return iw -= v; - } - friend CloudFloat operator-(CloudFloat iw, float v) { - return iw -= v; - } - friend CloudFloat operator-(CloudFloat iw, int v) { - return iw -= (float)v; - } - friend CloudFloat operator-(CloudFloat iw, double v) { - return iw -= (float)v; - } - friend CloudFloat operator-(float v, CloudFloat iw) { - return CloudFloat(v) -= iw; - } - friend CloudFloat operator-(int v, CloudFloat iw) { - return CloudFloat(v) -= iw; - } - friend CloudFloat operator-(double v, CloudFloat iw) { - return CloudFloat(v) -= iw; - } - friend CloudFloat operator*(CloudFloat iw, CloudFloat v) { - return iw *= v; - } - friend CloudFloat operator*(CloudFloat iw, float v) { - return iw *= v; - } - friend CloudFloat operator*(CloudFloat iw, int v) { - return iw *= (float)v; - } - friend CloudFloat operator*(CloudFloat iw, double v) { - return iw *= (float)v; - } - friend CloudFloat operator*(float v, CloudFloat iw) { - return CloudFloat(v) *= iw; - } - friend CloudFloat operator*(int v, CloudFloat iw) { - return CloudFloat(v) *= iw; - } - friend CloudFloat operator*(double v, CloudFloat iw) { - return CloudFloat(v) *= iw; - } - friend CloudFloat operator/(CloudFloat iw, CloudFloat v) { - return iw /= v; - } - friend CloudFloat operator/(CloudFloat iw, float v) { - return iw /= v; - } - friend CloudFloat operator/(CloudFloat iw, int v) { - return iw /= (float)v; - } - friend CloudFloat operator/(CloudFloat iw, double v) { - return iw /= (float)v; - } - friend CloudFloat operator/(float v, CloudFloat iw) { - return CloudFloat(v) /= iw; - } - friend CloudFloat operator/(int v, CloudFloat iw) { - return CloudFloat(v) /= iw; - } - friend CloudFloat operator/(double v, CloudFloat iw) { - return CloudFloat(v) /= iw; - } -}; - - -#endif /* CLOUDFLOAT_H_ */ diff --git a/src/property/types/CloudInt.h b/src/property/types/CloudInt.h deleted file mode 100644 index 37e4d3cae..000000000 --- a/src/property/types/CloudInt.h +++ /dev/null @@ -1,222 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDINT_H_ -#define CLOUDINT_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "../Property.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - - - -class CloudInt : public Property { - private: - int _value, - _cloud_value; - public: - CloudInt() { - CloudInt(0); - } - CloudInt(int v) : _value(v), _cloud_value(v) {} - operator int() const { - return _value; - } - virtual bool isDifferentFromCloud() { - return _value != _cloud_value && (abs(_value - _cloud_value) >= Property::_min_delta_property); - } - virtual void fromCloudToLocal() { - _value = _cloud_value; - } - virtual void fromLocalToCloud() { - _cloud_value = _value; - } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { - return appendAttribute(_value, "", encoder); - } - virtual void setAttributesFromCloud() { - setAttribute(_cloud_value, ""); - } - //modifiers - CloudInt& operator=(int v) { - _value = v; - updateLocalTimestamp(); - return *this; - } - CloudInt& operator=(CloudInt v) { - return operator=((int)v); - } - CloudInt& operator+=(int v) { - return operator=(_value += v); - } - CloudInt& operator-=(int v) { - return operator=(_value -= v); - } - CloudInt& operator*=(int v) { - return operator=(_value *= v); - } - CloudInt& operator/=(int v) { - return operator=(_value /= v); - } - CloudInt& operator%=(int v) { - return operator=(_value %= v); - } - CloudInt& operator++() { - return operator=(++_value); - } - CloudInt& operator--() { - return operator=(--_value); - } - CloudInt operator++(int) { - operator=(_value + 1); - return CloudInt(_value); - } - CloudInt operator--(int) { - operator=(_value - 1); - return CloudInt(_value); - } - CloudInt& operator&=(int v) { - return operator=(_value &= v); - } - CloudInt& operator|=(int v) { - return operator=(_value |= v); - } - CloudInt& operator^=(int v) { - return operator=(_value ^= v); - } - CloudInt& operator<<=(int v) { - return operator=(_value <<= v); - } - CloudInt& operator>>=(int v) { - return operator=(_value >>= v); - } - //accessors - CloudInt operator+() const { - return CloudInt(+_value); - } - CloudInt operator-() const { - return CloudInt(-_value); - } - CloudInt operator!() const { - return CloudInt(!_value); - } - CloudInt operator~() const { - return CloudInt(~_value); - } - //friends - friend CloudInt operator+(CloudInt iw, CloudInt v) { - return iw += v; - } - friend CloudInt operator+(CloudInt iw, int v) { - return iw += v; - } - friend CloudInt operator+(int v, CloudInt iw) { - return CloudInt(v) += iw; - } - friend CloudInt operator-(CloudInt iw, CloudInt v) { - return iw -= v; - } - friend CloudInt operator-(CloudInt iw, int v) { - return iw -= v; - } - friend CloudInt operator-(int v, CloudInt iw) { - return CloudInt(v) -= iw; - } - friend CloudInt operator*(CloudInt iw, CloudInt v) { - return iw *= v; - } - friend CloudInt operator*(CloudInt iw, int v) { - return iw *= v; - } - friend CloudInt operator*(int v, CloudInt iw) { - return CloudInt(v) *= iw; - } - friend CloudInt operator/(CloudInt iw, CloudInt v) { - return iw /= v; - } - friend CloudInt operator/(CloudInt iw, int v) { - return iw /= v; - } - friend CloudInt operator/(int v, CloudInt iw) { - return CloudInt(v) /= iw; - } - friend CloudInt operator%(CloudInt iw, CloudInt v) { - return iw %= v; - } - friend CloudInt operator%(CloudInt iw, int v) { - return iw %= v; - } - friend CloudInt operator%(int v, CloudInt iw) { - return CloudInt(v) %= iw; - } - friend CloudInt operator&(CloudInt iw, CloudInt v) { - return iw &= v; - } - friend CloudInt operator&(CloudInt iw, int v) { - return iw &= v; - } - friend CloudInt operator&(int v, CloudInt iw) { - return CloudInt(v) &= iw; - } - friend CloudInt operator|(CloudInt iw, CloudInt v) { - return iw |= v; - } - friend CloudInt operator|(CloudInt iw, int v) { - return iw |= v; - } - friend CloudInt operator|(int v, CloudInt iw) { - return CloudInt(v) |= iw; - } - friend CloudInt operator^(CloudInt iw, CloudInt v) { - return iw ^= v; - } - friend CloudInt operator^(CloudInt iw, int v) { - return iw ^= v; - } - friend CloudInt operator^(int v, CloudInt iw) { - return CloudInt(v) ^= iw; - } - friend CloudInt operator<<(CloudInt iw, CloudInt v) { - return iw <<= v; - } - friend CloudInt operator<<(CloudInt iw, int v) { - return iw <<= v; - } - friend CloudInt operator<<(int v, CloudInt iw) { - return CloudInt(v) <<= iw; - } - friend CloudInt operator>>(CloudInt iw, CloudInt v) { - return iw >>= v; - } - friend CloudInt operator>>(CloudInt iw, int v) { - return iw >>= v; - } - friend CloudInt operator>>(int v, CloudInt iw) { - return CloudInt(v) >>= iw; - } - -}; - - -#endif /* CLOUDINT_H_ */ diff --git a/src/property/types/CloudLocation.h b/src/property/types/CloudLocation.h index cd4f0dc67..346df0cb0 100644 --- a/src/property/types/CloudLocation.h +++ b/src/property/types/CloudLocation.h @@ -63,7 +63,7 @@ class CloudLocation : public Property { public: CloudLocation() : _value(0, 0), _cloud_value(0, 0) {} CloudLocation(float lat, float lon) : _value(lat, lon), _cloud_value(lat, lon) {} - virtual bool isDifferentFromCloud() { + bool isDifferentFromCloud() override { float const distance = Location::distance(_value, _cloud_value); return _value != _cloud_value && (abs(distance) >= Property::_min_delta_property); } @@ -83,18 +83,18 @@ class CloudLocation : public Property { return _value; } - virtual void fromCloudToLocal() { + void fromCloudToLocal() override { _value = _cloud_value; } - virtual void fromLocalToCloud() { + void fromLocalToCloud() override { _cloud_value = _value; } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CborError appendAttributesToCloud(CborEncoder *encoder) override { CHECK_CBOR_MULTI(appendAttribute(_value.lat, "lat", encoder)); CHECK_CBOR_MULTI(appendAttribute(_value.lon, "lon", encoder)); return CborNoError; } - virtual void setAttributesFromCloud() { + void setAttributesFromCloud() override { setAttribute(_cloud_value.lat, "lat"); setAttribute(_cloud_value.lon, "lon"); } diff --git a/src/property/types/CloudSchedule.h b/src/property/types/CloudSchedule.h index 9a9222968..a117ead27 100644 --- a/src/property/types/CloudSchedule.h +++ b/src/property/types/CloudSchedule.h @@ -318,11 +318,11 @@ class Schedule { if(isScheduleFixed(msk) || isScheduleOneShot(msk)) { return true; } - + if(isScheduleWeekly(msk)) { unsigned int currentDayMask = getCurrentDayMask(now); unsigned int scheduleMask = getScheduleWeekMask(msk); - + if((currentDayMask & scheduleMask) != 0) { return true; } @@ -384,7 +384,7 @@ class CloudSchedule : public Property { CloudSchedule() : _value(0, 0, 0, 0), _cloud_value(0, 0, 0, 0) {} CloudSchedule(unsigned int frm, unsigned int to, unsigned int len, unsigned int msk) : _value(frm, to, len, msk), _cloud_value(frm, to, len, msk) {} - virtual bool isDifferentFromCloud() { + bool isDifferentFromCloud() override { return _value != _cloud_value; } @@ -410,20 +410,20 @@ class CloudSchedule : public Property { return _value.isActive(); } - virtual void fromCloudToLocal() { + void fromCloudToLocal() override { _value = _cloud_value; } - virtual void fromLocalToCloud() { + void fromLocalToCloud() override { _cloud_value = _value; } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CborError appendAttributesToCloud(CborEncoder *encoder) override { CHECK_CBOR_MULTI(appendAttribute(_value.frm, "frm", encoder)); CHECK_CBOR_MULTI(appendAttribute(_value.to, "to", encoder)); CHECK_CBOR_MULTI(appendAttribute(_value.len, "len", encoder)); CHECK_CBOR_MULTI(appendAttribute(_value.msk, "msk", encoder)); return CborNoError; } - virtual void setAttributesFromCloud() { + void setAttributesFromCloud() override { setAttribute(_cloud_value.frm, "frm"); setAttribute(_cloud_value.to, "to"); setAttribute(_cloud_value.len, "len"); diff --git a/src/property/types/CloudString.h b/src/property/types/CloudString.h index f884720c0..f9f764d33 100644 --- a/src/property/types/CloudString.h +++ b/src/property/types/CloudString.h @@ -49,19 +49,19 @@ class CloudString : public Property { void clear() { _value = PropertyActions::CLEAR; } - virtual bool isDifferentFromCloud() { + bool isDifferentFromCloud() override { return _value != _cloud_value; } - virtual void fromCloudToLocal() { + void fromCloudToLocal() override { _value = _cloud_value; } - virtual void fromLocalToCloud() { + void fromLocalToCloud() override { _cloud_value = _value; } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CborError appendAttributesToCloud(CborEncoder *encoder) override { return appendAttribute(_value, "", encoder); } - virtual void setAttributesFromCloud() { + void setAttributesFromCloud() override { setAttribute(_cloud_value, ""); } //modifiers diff --git a/src/property/types/CloudUnsignedInt.h b/src/property/types/CloudUnsignedInt.h deleted file mode 100644 index 40bed697a..000000000 --- a/src/property/types/CloudUnsignedInt.h +++ /dev/null @@ -1,222 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDUINT_H_ -#define CLOUDUINT_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "../Property.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - - - -class CloudUnsignedInt : public Property { - private: - unsigned int _value, - _cloud_value; - public: - CloudUnsignedInt() { - CloudUnsignedInt(0); - } - CloudUnsignedInt(unsigned int v) : _value(v), _cloud_value(v) {} - operator unsigned int() const { - return _value; - } - virtual bool isDifferentFromCloud() { - return _value != _cloud_value && ((std::max(_value , _cloud_value) - std::min(_value , _cloud_value)) >= Property::_min_delta_property); - } - virtual void fromCloudToLocal() { - _value = _cloud_value; - } - virtual void fromLocalToCloud() { - _cloud_value = _value; - } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { - return appendAttribute(_value, "", encoder); - } - virtual void setAttributesFromCloud() { - setAttribute(_cloud_value, ""); - } - //modifiers - CloudUnsignedInt& operator=(unsigned int v) { - _value = v; - updateLocalTimestamp(); - return *this; - } - CloudUnsignedInt& operator=(CloudUnsignedInt v) { - return operator=((unsigned int)v); - } - CloudUnsignedInt& operator+=(unsigned int v) { - return operator=(_value += v); - } - CloudUnsignedInt& operator-=(unsigned int v) { - return operator=(_value -= v); - } - CloudUnsignedInt& operator*=(unsigned int v) { - return operator=(_value *= v); - } - CloudUnsignedInt& operator/=(unsigned int v) { - return operator=(_value /= v); - } - CloudUnsignedInt& operator%=(unsigned int v) { - return operator=(_value %= v); - } - CloudUnsignedInt& operator++() { - return operator=(++_value); - } - CloudUnsignedInt& operator--() { - return operator=(--_value); - } - CloudUnsignedInt operator++(int) { - operator=(_value + 1); - return CloudUnsignedInt(_value); - } - CloudUnsignedInt operator--(int) { - operator=(_value - 1); - return CloudUnsignedInt(_value); - } - CloudUnsignedInt& operator&=(unsigned int v) { - return operator=(_value &= v); - } - CloudUnsignedInt& operator|=(unsigned int v) { - return operator=(_value |= v); - } - CloudUnsignedInt& operator^=(unsigned int v) { - return operator=(_value ^= v); - } - CloudUnsignedInt& operator<<=(unsigned int v) { - return operator=(_value <<= v); - } - CloudUnsignedInt& operator>>=(unsigned int v) { - return operator=(_value >>= v); - } - //accessors - CloudUnsignedInt operator+() const { - return CloudUnsignedInt(+_value); - } - CloudUnsignedInt operator-() const { - return CloudUnsignedInt(-_value); - } - CloudUnsignedInt operator!() const { - return CloudUnsignedInt(!_value); - } - CloudUnsignedInt operator~() const { - return CloudUnsignedInt(~_value); - } - //friends - friend CloudUnsignedInt operator+(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw += v; - } - friend CloudUnsignedInt operator+(CloudUnsignedInt iw, unsigned int v) { - return iw += v; - } - friend CloudUnsignedInt operator+(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) += iw; - } - friend CloudUnsignedInt operator-(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw -= v; - } - friend CloudUnsignedInt operator-(CloudUnsignedInt iw, unsigned int v) { - return iw -= v; - } - friend CloudUnsignedInt operator-(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) -= iw; - } - friend CloudUnsignedInt operator*(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw *= v; - } - friend CloudUnsignedInt operator*(CloudUnsignedInt iw, unsigned int v) { - return iw *= v; - } - friend CloudUnsignedInt operator*(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) *= iw; - } - friend CloudUnsignedInt operator/(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw /= v; - } - friend CloudUnsignedInt operator/(CloudUnsignedInt iw, unsigned int v) { - return iw /= v; - } - friend CloudUnsignedInt operator/(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) /= iw; - } - friend CloudUnsignedInt operator%(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw %= v; - } - friend CloudUnsignedInt operator%(CloudUnsignedInt iw, unsigned int v) { - return iw %= v; - } - friend CloudUnsignedInt operator%(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) %= iw; - } - friend CloudUnsignedInt operator&(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw &= v; - } - friend CloudUnsignedInt operator&(CloudUnsignedInt iw, unsigned int v) { - return iw &= v; - } - friend CloudUnsignedInt operator&(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) &= iw; - } - friend CloudUnsignedInt operator|(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw |= v; - } - friend CloudUnsignedInt operator|(CloudUnsignedInt iw, unsigned int v) { - return iw |= v; - } - friend CloudUnsignedInt operator|(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) |= iw; - } - friend CloudUnsignedInt operator^(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw ^= v; - } - friend CloudUnsignedInt operator^(CloudUnsignedInt iw, unsigned int v) { - return iw ^= v; - } - friend CloudUnsignedInt operator^(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) ^= iw; - } - friend CloudUnsignedInt operator<<(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw <<= v; - } - friend CloudUnsignedInt operator<<(CloudUnsignedInt iw, unsigned int v) { - return iw <<= v; - } - friend CloudUnsignedInt operator<<(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) <<= iw; - } - friend CloudUnsignedInt operator>>(CloudUnsignedInt iw, CloudUnsignedInt v) { - return iw >>= v; - } - friend CloudUnsignedInt operator>>(CloudUnsignedInt iw, unsigned int v) { - return iw >>= v; - } - friend CloudUnsignedInt operator>>(unsigned int v, CloudUnsignedInt iw) { - return CloudUnsignedInt(v) >>= iw; - } - -}; - - -#endif /* CLOUDUINT_H_ */ diff --git a/src/property/types/CloudWrapperBase.cpp b/src/property/types/CloudWrapperBase.cpp new file mode 100644 index 000000000..0a65208b8 --- /dev/null +++ b/src/property/types/CloudWrapperBase.cpp @@ -0,0 +1,8 @@ +#include "CloudWrapperBase.h" +#include "../math_utils.h" + +// template specialization for float CloudWrapperProperty to handle nan values +template<> +bool CloudWrapperProperty::isDifferentFromCloud() { + return arduino::math::ieee754_different(_primitive_value, _cloud_value, Property::_min_delta_property); +} diff --git a/src/property/types/CloudWrapperBase.h b/src/property/types/CloudWrapperBase.h index 9efd86100..f4d0552c8 100644 --- a/src/property/types/CloudWrapperBase.h +++ b/src/property/types/CloudWrapperBase.h @@ -23,16 +23,52 @@ ******************************************************************************/ #include -#include "../Property.h" +#include "PropertyPrimitive.h" /****************************************************************************** CLASS DECLARATION ******************************************************************************/ -class CloudWrapperBase : public Property { +class CloudWrapperBaseInterface { public: virtual bool isChangedLocally() = 0; }; +class CloudWrapperBase : public Property, public CloudWrapperBaseInterface { + public: + virtual bool isChangedLocally() = 0; +}; + +template +class CloudWrapperProperty : public PropertyPrimitive, public CloudWrapperBaseInterface { +public: + CloudWrapperProperty(T& value) + : PropertyPrimitive(value), _primitive_value(value) { } + + bool isDifferentFromCloud() override { + return _primitive_value != PropertyPrimitive::_cloud_value; + } + + void fromCloudToLocal() override { + _primitive_value = PropertyPrimitive::_cloud_value; + } + void fromLocalToCloud() override { + PropertyPrimitive::_cloud_value = _primitive_value; + } + + CborError appendAttributesToCloud(CborEncoder *encoder) override { + return PropertyPrimitive::appendAttribute(_primitive_value, "", encoder); + } + void setAttributesFromCloud() override { + PropertyPrimitive::setAttribute(PropertyPrimitive::_cloud_value, ""); + } + + bool isChangedLocally() override { + return _primitive_value != PropertyPrimitive::_value; + } +protected: + T &_primitive_value; +}; + #endif /* CLOUDWRAPPERBASE_H_ */ diff --git a/src/property/types/CloudWrapperBool.h b/src/property/types/CloudWrapperBool.h deleted file mode 100644 index 8fffd4209..000000000 --- a/src/property/types/CloudWrapperBool.h +++ /dev/null @@ -1,63 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDWRAPPERBOOL_H_ -#define CLOUDWRAPPERBOOL_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "CloudWrapperBase.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - -class CloudWrapperBool : public CloudWrapperBase { - private: - bool &_primitive_value, - _cloud_value, - _local_value; - public: - CloudWrapperBool(bool& v) : _primitive_value(v), _cloud_value(v), _local_value(v) {} - virtual bool isDifferentFromCloud() { - return _primitive_value != _cloud_value; - } - virtual void fromCloudToLocal() { - _primitive_value = _cloud_value; - } - virtual void fromLocalToCloud() { - _cloud_value = _primitive_value; - } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { - return appendAttribute(_primitive_value, "", encoder); - } - virtual void setAttributesFromCloud() { - setAttribute(_cloud_value, ""); - } - virtual bool isPrimitive() { - return true; - } - virtual bool isChangedLocally() { - return _primitive_value != _local_value; - } -}; - - -#endif /* CLOUDWRAPPERBOOL_H_ */ diff --git a/src/property/types/CloudWrapperFloat.h b/src/property/types/CloudWrapperFloat.h deleted file mode 100644 index 4e8d97986..000000000 --- a/src/property/types/CloudWrapperFloat.h +++ /dev/null @@ -1,66 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDWRAPPERFLOAT_H_ -#define CLOUDWRAPPERFLOAT_H_ - -#include -#include "../math_utils.h" - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "CloudWrapperBase.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - -class CloudWrapperFloat : public CloudWrapperBase { - private: - float &_primitive_value, - _cloud_value, - _local_value; - public: - CloudWrapperFloat(float& v) : _primitive_value(v), _cloud_value(v), _local_value(v) {} - virtual bool isDifferentFromCloud() { - return arduino::math::ieee754_different(_primitive_value, _cloud_value, Property::_min_delta_property); - } - virtual void fromCloudToLocal() { - _primitive_value = _cloud_value; - } - virtual void fromLocalToCloud() { - _cloud_value = _primitive_value; - } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { - return appendAttribute(_primitive_value, "", encoder); - } - virtual void setAttributesFromCloud() { - setAttribute(_cloud_value, ""); - } - virtual bool isPrimitive() { - return true; - } - virtual bool isChangedLocally() { - return _primitive_value != _local_value; - } -}; - - -#endif /* CLOUWRAPPERFLOAT_H_ */ diff --git a/src/property/types/CloudWrapperInt.h b/src/property/types/CloudWrapperInt.h deleted file mode 100644 index 73623abfc..000000000 --- a/src/property/types/CloudWrapperInt.h +++ /dev/null @@ -1,63 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDWRAPPERINT_H_ -#define CLOUDWRAPPERINT_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "CloudWrapperBase.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - -class CloudWrapperInt : public CloudWrapperBase { - private: - int &_primitive_value, - _cloud_value, - _local_value; - public: - CloudWrapperInt(int& v) : _primitive_value(v), _cloud_value(v), _local_value(v) {} - virtual bool isDifferentFromCloud() { - return _primitive_value != _cloud_value && (abs(_primitive_value - _cloud_value) >= Property::_min_delta_property); - } - virtual void fromCloudToLocal() { - _primitive_value = _cloud_value; - } - virtual void fromLocalToCloud() { - _cloud_value = _primitive_value; - } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { - return appendAttribute(_primitive_value, "", encoder); - } - virtual void setAttributesFromCloud() { - setAttribute(_cloud_value, ""); - } - virtual bool isPrimitive() { - return true; - } - virtual bool isChangedLocally() { - return _primitive_value != _local_value; - } -}; - - -#endif /* CLOUDWRAPPERINT_H_ */ diff --git a/src/property/types/CloudWrapperString.h b/src/property/types/CloudWrapperString.h index 7c75db0db..5d65c9cf8 100644 --- a/src/property/types/CloudWrapperString.h +++ b/src/property/types/CloudWrapperString.h @@ -40,25 +40,25 @@ class CloudWrapperString : public CloudWrapperBase { _cloud_value(v), _local_value(v) { } - virtual bool isDifferentFromCloud() { + bool isDifferentFromCloud() override { return _primitive_value != _cloud_value; } - virtual void fromCloudToLocal() { + void fromCloudToLocal() override { _primitive_value = _cloud_value; } - virtual void fromLocalToCloud() { + void fromLocalToCloud() override { _cloud_value = _primitive_value; } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CborError appendAttributesToCloud(CborEncoder *encoder) override { return appendAttribute(_primitive_value, "", encoder); } - virtual void setAttributesFromCloud() { + void setAttributesFromCloud() override { setAttribute(_cloud_value, ""); } - virtual bool isPrimitive() { + bool isPrimitive() override { return true; } - virtual bool isChangedLocally() { + bool isChangedLocally() override { return _primitive_value != _local_value; } }; diff --git a/src/property/types/CloudWrapperUnsignedInt.h b/src/property/types/CloudWrapperUnsignedInt.h deleted file mode 100644 index 34ed01ef3..000000000 --- a/src/property/types/CloudWrapperUnsignedInt.h +++ /dev/null @@ -1,63 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDWRAPPERUINT_H_ -#define CLOUDWRAPPERUINT_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "CloudWrapperBase.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - -class CloudWrapperUnsignedInt : public CloudWrapperBase { - private: - unsigned int &_primitive_value, - _cloud_value, - _local_value; - public: - CloudWrapperUnsignedInt(unsigned int& v) : _primitive_value(v), _cloud_value(v), _local_value(v) {} - virtual bool isDifferentFromCloud() { - return _primitive_value != _cloud_value && ((std::max(_primitive_value , _cloud_value) - std::min(_primitive_value , _cloud_value)) >= Property::_min_delta_property); - } - virtual void fromCloudToLocal() { - _primitive_value = _cloud_value; - } - virtual void fromLocalToCloud() { - _cloud_value = _primitive_value; - } - virtual CborError appendAttributesToCloud(CborEncoder *encoder) { - return appendAttribute(_primitive_value, "", encoder); - } - virtual void setAttributesFromCloud() { - setAttribute(_cloud_value, ""); - } - virtual bool isPrimitive() { - return true; - } - virtual bool isChangedLocally() { - return _primitive_value != _local_value; - } -}; - - -#endif /* CLOUDWRAPPERINT_H_ */ diff --git a/src/property/types/PropertyPrimitive.cpp b/src/property/types/PropertyPrimitive.cpp new file mode 100644 index 000000000..21925459f --- /dev/null +++ b/src/property/types/PropertyPrimitive.cpp @@ -0,0 +1,10 @@ +#include "PropertyPrimitive.h" + +#include "../math_utils.h" + + +// template specialization for float Properties to handle nan values +template<> +bool PropertyPrimitive::isDifferentFromCloud() { + return arduino::math::ieee754_different(_value, _cloud_value, Property::_min_delta_property); +} diff --git a/src/property/types/PropertyPrimitive.h b/src/property/types/PropertyPrimitive.h new file mode 100644 index 000000000..f611ff73e --- /dev/null +++ b/src/property/types/PropertyPrimitive.h @@ -0,0 +1,195 @@ +#pragma once + +#include "../Property.h" + +template +class PropertyPrimitive: public Property { +public: + PropertyPrimitive() { + PropertyPrimitive(0); + } + PropertyPrimitive(T v) : _value(v), _cloud_value(v) {} + operator T() const { + return _value; + } + virtual bool isDifferentFromCloud() { + return _value != _cloud_value && (abs(float(_value - _cloud_value)) >= Property::_min_delta_property); + } + virtual void fromCloudToLocal() { + _value = _cloud_value; + } + virtual void fromLocalToCloud() { + _cloud_value = _value; + } + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_value, "", encoder); + } + virtual void setAttributesFromCloud() { + setAttribute(_cloud_value, ""); + } + + //modifiers + PropertyPrimitive& operator=(T v) { + _value = v; + updateLocalTimestamp(); + return *this; + } + PropertyPrimitive& operator=(PropertyPrimitive v) { + return operator=((T)v); + } + PropertyPrimitive& operator+=(T v) { + return operator=(_value += v); + } + PropertyPrimitive& operator-=(T v) { + return operator=(_value -= v); + } + PropertyPrimitive& operator*=(T v) { + return operator=(_value *= v); + } + PropertyPrimitive& operator/=(T v) { + return operator=(_value /= v); + } + PropertyPrimitive& operator%=(T v) { + return operator=(_value %= v); + } + PropertyPrimitive& operator++() { + return operator=(++_value); + } + PropertyPrimitive& operator--() { + return operator=(--_value); + } + PropertyPrimitive operator++(int) { + operator=(_value + 1); + return PropertyPrimitive(_value); + } + PropertyPrimitive operator--(int) { + operator=(_value - 1); + return PropertyPrimitive(_value); + } + PropertyPrimitive& operator&=(T v) { + return operator=(_value &= v); + } + PropertyPrimitive& operator|=(T v) { + return operator=(_value |= v); + } + PropertyPrimitive& operator^=(T v) { + return operator=(_value ^= v); + } + PropertyPrimitive& operator<<=(T v) { + return operator=(_value <<= v); + } + PropertyPrimitive& operator>>=(T v) { + return operator=(_value >>= v); + } + + //accessors + PropertyPrimitive operator+() const { + return PropertyPrimitive(+_value); + } + PropertyPrimitive operator-() const { + return PropertyPrimitive(-_value); + } + PropertyPrimitive operator!() const { + return PropertyPrimitive(!_value); + } + PropertyPrimitive operator~() const { + return PropertyPrimitive(~_value); + } + + //friends + // TODO second parameter should not be T, but another template? + friend PropertyPrimitive operator+(PropertyPrimitive iw, PropertyPrimitive v) { + return iw += v; // FIXME this should return a new property primitive + } + friend PropertyPrimitive operator+(PropertyPrimitive iw, T v) { // TODO may not be required -> T can become property primitive + return iw += v; + } + friend PropertyPrimitive operator+(T v, PropertyPrimitive iw) { // TODO may not be required -> T can become property primitive + return PropertyPrimitive(v) += iw; // FIXME this doesn't seem to make sense + } + friend PropertyPrimitive operator-(PropertyPrimitive iw, PropertyPrimitive v) { + return iw -= v; + } + friend PropertyPrimitive operator-(PropertyPrimitive iw, T v) { + return iw -= v; + } + friend PropertyPrimitive operator-(T v, PropertyPrimitive iw) { + return PropertyPrimitive(v) -= iw; + } + friend PropertyPrimitive operator*(PropertyPrimitive iw, PropertyPrimitive v) { + return iw *= v; + } + friend PropertyPrimitive operator*(PropertyPrimitive iw, T v) { + return iw *= v; + } + friend PropertyPrimitive operator*(T v, PropertyPrimitive iw) { + return PropertyPrimitive(v) *= iw; + } + friend PropertyPrimitive operator/(PropertyPrimitive iw, PropertyPrimitive v) { + return iw /= v; + } + friend PropertyPrimitive operator/(PropertyPrimitive iw, T v) { + return iw /= v; + } + friend PropertyPrimitive operator/(T v, PropertyPrimitive iw) { + return PropertyPrimitive(v) /= iw; + } + friend PropertyPrimitive operator%(PropertyPrimitive iw, PropertyPrimitive v) { + return iw %= v; + } + friend PropertyPrimitive operator%(PropertyPrimitive iw, T v) { + return iw %= v; + } + friend PropertyPrimitive operator%(T v, PropertyPrimitive iw) { + return PropertyPrimitive(v) %= iw; + } + friend PropertyPrimitive operator&(PropertyPrimitive iw, PropertyPrimitive v) { + return iw &= v; + } + friend PropertyPrimitive operator&(PropertyPrimitive iw, T v) { + return iw &= v; + } + friend PropertyPrimitive operator&(T v, PropertyPrimitive iw) { + return PropertyPrimitive(v) &= iw; + } + friend PropertyPrimitive operator|(PropertyPrimitive iw, PropertyPrimitive v) { + return iw |= v; + } + friend PropertyPrimitive operator|(PropertyPrimitive iw, T v) { + return iw |= v; + } + friend PropertyPrimitive operator|(T v, PropertyPrimitive iw) { + return PropertyPrimitive(v) |= iw; + } + friend PropertyPrimitive operator^(PropertyPrimitive iw, PropertyPrimitive v) { + return iw ^= v; + } + friend PropertyPrimitive operator^(PropertyPrimitive iw, T v) { + return iw ^= v; + } + friend PropertyPrimitive operator^(T v, PropertyPrimitive iw) { + return PropertyPrimitive(v) ^= iw; + } + friend PropertyPrimitive operator<<(PropertyPrimitive iw, PropertyPrimitive v) { + return iw <<= v; + } + friend PropertyPrimitive operator<<(PropertyPrimitive iw, T v) { + return iw <<= v; + } + friend PropertyPrimitive operator<<(T v, PropertyPrimitive iw) { + return PropertyPrimitive(v) <<= iw; + } + friend PropertyPrimitive operator>>(PropertyPrimitive iw, PropertyPrimitive v) { + return iw >>= v; + } + friend PropertyPrimitive operator>>(PropertyPrimitive iw, T v) { + return iw >>= v; + } + friend PropertyPrimitive operator>>(T v, PropertyPrimitive iw) { + return PropertyPrimitive(v) >>= iw; + } + +protected: + T _value, + _cloud_value; +}; diff --git a/src/property/types/automation/CloudContactSensor.h b/src/property/types/automation/CloudContactSensor.h deleted file mode 100644 index 351eaed73..000000000 --- a/src/property/types/automation/CloudContactSensor.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDCONTACTSENSOR_H_ -#define CLOUDCONTACTSENSOR_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "../CloudBool.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - - - -class CloudContactSensor : public CloudBool { - private: - public: - operator bool() const { - return _value; - } - CloudContactSensor& operator=(bool v) { - CloudBool::operator=(v); - return *this; - } -}; - - -#endif /* CLOUDCONTACTSENSOR_H_ */ diff --git a/src/property/types/automation/CloudLight.h b/src/property/types/automation/CloudLight.h deleted file mode 100644 index 358527b37..000000000 --- a/src/property/types/automation/CloudLight.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDLIGHT_H_ -#define CLOUDLIGHT_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "../CloudBool.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - - - -class CloudLight : public CloudBool { - private: - public: - operator bool() const { - return _value; - } - CloudLight& operator=(bool v) { - CloudBool::operator=(v); - return *this; - } -}; - - -#endif /* CLOUDLIGHT_H_ */ diff --git a/src/property/types/automation/CloudMotionSensor.h b/src/property/types/automation/CloudMotionSensor.h deleted file mode 100644 index 3831d3d27..000000000 --- a/src/property/types/automation/CloudMotionSensor.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDMOTIONSENSOR_H_ -#define CLOUDMOTIONSENSOR_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "../CloudBool.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - - - -class CloudMotionSensor : public CloudBool { - private: - public: - operator bool() const { - return _value; - } - CloudMotionSensor& operator=(bool v) { - CloudBool::operator=(v); - return *this; - } -}; - - -#endif /* CLOUDMOTIONSENSOR_H_ */ diff --git a/src/property/types/automation/CloudSmartPlug.h b/src/property/types/automation/CloudSmartPlug.h deleted file mode 100644 index 99c7886fb..000000000 --- a/src/property/types/automation/CloudSmartPlug.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDSMARTPLUG_H_ -#define CLOUDSMARTPLUG_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "../CloudBool.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - - - -class CloudSmartPlug : public CloudBool { - private: - public: - operator bool() const { - return _value; - } - CloudSmartPlug& operator=(bool v) { - CloudBool::operator=(v); - return *this; - } -}; - - -#endif /* CLOUDSMARTPLUG_H_ */ diff --git a/src/property/types/automation/CloudSwitch.h b/src/property/types/automation/CloudSwitch.h deleted file mode 100644 index d22345d88..000000000 --- a/src/property/types/automation/CloudSwitch.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUDSWITCH_H_ -#define CLOUDSWITCH_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include -#include "../CloudBool.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - - - -class CloudSwitch : public CloudBool { - private: - public: - operator bool() const { - return _value; - } - CloudSwitch& operator=(bool v) { - CloudBool::operator=(v); - return *this; - } -}; - - -#endif /* CLOUDSWITCH_H_ */ diff --git a/src/property/types/automation/CloudTemperatureSensor.h b/src/property/types/automation/CloudTemperatureSensor.h deleted file mode 100644 index 69ce33eb8..000000000 --- a/src/property/types/automation/CloudTemperatureSensor.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// This file is part of ArduinoCloudThing -// -// Copyright 2019 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of ArduinoCloudThing. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to modify or -// otherwise use the software for commercial activities involving the Arduino -// software without disclosing the source code of your own applications. To purchase -// a commercial license, send an email to license@arduino.cc. -// - -#ifndef CLOUD_TEMPERATURE_SENSOR_H_ -#define CLOUD_TEMPERATURE_SENSOR_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include "../CloudFloat.h" - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - -class CloudTemperatureSensor : public CloudFloat -{ - public: - - CloudTemperatureSensor & operator = (float v) - { - CloudFloat::operator=(v); - return *this; - } -}; - -#endif /* CLOUD_TEMPERATURE_SENSOR_H_ */