diff --git a/extras/test/src/test_addPropertyReal.cpp b/extras/test/src/test_addPropertyReal.cpp index 27500c97f..5562c0706 100644 --- a/extras/test/src/test_addPropertyReal.cpp +++ b/extras/test/src/test_addPropertyReal.cpp @@ -36,17 +36,33 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino /**************************************************************************************/ - WHEN("the same int property is added multiple times") + WHEN("the same int16 property is added multiple times") { PropertyContainer property_container; - CloudInt int_property = 1; + CloudInt int16_property = 1; - Property * int_property_ptr_1 = &addPropertyToContainer(property_container, int_property, "int_property", Permission::ReadWrite); - Property * int_property_ptr_2 = &addPropertyToContainer(property_container, int_property, "int_property", Permission::ReadWrite); + Property * int16_property_ptr_1 = &addPropertyToContainer(property_container, int16_property, "int16_property", Permission::ReadWrite); + Property * int16_property_ptr_2 = &addPropertyToContainer(property_container, int16_property, "int16_property", Permission::ReadWrite); THEN("No new property is added and the first added property is returned instead of a new one") { - REQUIRE(int_property_ptr_1 == int_property_ptr_2); + REQUIRE(int16_property_ptr_1 == int16_property_ptr_2); + } + } + + /**************************************************************************************/ + + WHEN("the same int32 property is added multiple times") + { + PropertyContainer property_container; + + CloudInt int32_property = 1; + + Property * int32_property_ptr_1 = &addPropertyToContainer(property_container, int32_property, "int32_property", Permission::ReadWrite); + Property * int32_property_ptr_2 = &addPropertyToContainer(property_container, int32_property, "int32_property", Permission::ReadWrite); + + THEN("No new property is added and the first added property is returned instead of a new one") { + REQUIRE(int32_property_ptr_1 == int32_property_ptr_2); } } diff --git a/extras/test/src/test_callback.cpp b/extras/test/src/test_callback.cpp index b4b30e37d..7d3dbb25a 100644 --- a/extras/test/src/test_callback.cpp +++ b/extras/test/src/test_callback.cpp @@ -41,8 +41,8 @@ void externalCallbackV2() SCENARIO("A callback is registered via 'onUpdate' to be called on property change", "[ArduinoCloudThing::decode]") { PropertyContainer property_container; - - CloudInt test = 10; + + CloudInt test = 10; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(externalCallbackV2); /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ diff --git a/extras/test/src/test_decode.cpp b/extras/test/src/test_decode.cpp index fab8c18d4..17cd1f699 100644 --- a/extras/test/src/test_decode.cpp +++ b/extras/test/src/test_decode.cpp @@ -37,7 +37,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A boolean property is changed via CBOR message") { PropertyContainer property_container; - + CloudBool test = true; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); @@ -55,7 +55,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") { /*An integer identifier has been encoded instead of the name of the property in order to have a shorter payload*/ PropertyContainer property_container; - + CloudBool test = true; /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ addPropertyToContainer(property_container, test, "test", Permission::ReadWrite, 1); @@ -73,8 +73,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A positive int property is changed via CBOR message") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ @@ -88,8 +88,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A negative int property is changed via CBOR message") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 2: -7}] = 81 A2 00 64 74 65 73 74 02 26 */ @@ -105,7 +105,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A float property is changed via CBOR message") { PropertyContainer property_container; - + CloudFloat test = 0.0f; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); @@ -122,7 +122,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A String property is changed via CBOR message") { PropertyContainer property_container; - + CloudString str_test; str_test = "test"; addPropertyToContainer(property_container, str_test, "test", Permission::ReadWrite); @@ -139,7 +139,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A Location property is changed via CBOR message") { PropertyContainer property_container; - + CloudLocation location_test = CloudLocation(0, 1); addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite); @@ -157,7 +157,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A Color property is changed via CBOR message") { PropertyContainer property_container; - + CloudColor color_test = CloudColor(0.0, 0.0, 0.0); addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); @@ -181,7 +181,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") { /*An integer identifier has been encoded instead of the name of the property in order to have a shorter payload*/ PropertyContainer property_container; - + CloudColor color_test = CloudColor(0.0, 0.0, 0.0); /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ @@ -205,7 +205,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A ColoredLight property is changed via CBOR message") { PropertyContainer property_container; - + CloudColoredLight color_test = CloudColoredLight(false, 0.0, 0.0, 0.0); addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); @@ -229,7 +229,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A Television property is changed via CBOR message") { PropertyContainer property_container; - + CloudTelevision tv_test = CloudTelevision(false, 0, false, PlaybackCommands::Stop, InputValue::AUX1, 0); addPropertyToContainer(property_container, tv_test, "test", Permission::ReadWrite); @@ -255,7 +255,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A DimmedLight property is changed via CBOR message") { PropertyContainer property_container; - + CloudDimmedLight light_test = CloudDimmedLight(false, 0.0); addPropertyToContainer(property_container, light_test, "test", Permission::ReadWrite); @@ -277,7 +277,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A Light property is changed via CBOR message") { PropertyContainer property_container; - + CloudLight light_test; light_test = false; @@ -295,7 +295,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A ContactSensor property is changed via CBOR message") { PropertyContainer property_container; - + CloudContactSensor contact_test; contact_test = false; @@ -313,7 +313,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A MotionSensor property is changed via CBOR message") { PropertyContainer property_container; - + CloudMotionSensor motion_test; motion_test = false; @@ -331,7 +331,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A SmartPlug property is changed via CBOR message") { PropertyContainer property_container; - + CloudSmartPlug plug_test; plug_test = false; @@ -349,7 +349,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A Switch property is changed via CBOR message") { PropertyContainer property_container; - + CloudSwitch switch_test; switch_test = false; @@ -367,7 +367,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A Temperature property is changed via CBOR message") { PropertyContainer property_container; - + CloudTemperatureSensor test; test = 0.0f; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); @@ -414,8 +414,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t)); Schedule schedule_compare = Schedule(1633305600, 1633651200, 600, 1140850708); - Schedule value_schedule_test = schedule_test.getValue(); - + Schedule value_schedule_test = schedule_test.getValue(); + bool verify = (value_schedule_test == schedule_compare); REQUIRE(verify); REQUIRE(value_schedule_test.frm == schedule_compare.frm); @@ -431,11 +431,11 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("Multiple properties of different type are changed via CBOR message") { PropertyContainer property_container; - - CloudBool bool_test = false; - CloudInt int_test = 1; - CloudFloat float_test = 2.0f; - CloudString str_test; + + CloudBool bool_test = false; + CloudInt int_test = 1; + CloudFloat float_test = 2.0f; + CloudString str_test; str_test = ("str_test"); addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite); @@ -460,11 +460,11 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("Multiple properties of different type are synchronized via CBOR message. FORCE_CLOUD_SYNC is passed as synchronization function and as a consequence values contained in the incoming message are stored in the properties") { PropertyContainer property_container; - - CloudBool bool_test = false; - CloudInt int_test = 1; - CloudFloat float_test = 2.0f; - CloudString str_test; + + CloudBool bool_test = false; + CloudInt int_test = 1; + CloudFloat float_test = 2.0f; + CloudString str_test; str_test = ("str_test"); addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS); @@ -489,14 +489,14 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("Multiple primitive properties of different type are synchronized via CBOR message. FORCE_CLOUD_SYNC is passed as synchronization function and as a consequence values contained in the incoming message are stored in the properties") { PropertyContainer property_container; - + int int_test = 1; bool bool_test = false; float float_test = 2.0f; String str_test; str_test = "str_test"; - std::unique_ptr i(new CloudWrapperInt(int_test)); + std::unique_ptr i(new CloudWrapperInt(int_test)); std::unique_ptr b(new CloudWrapperBool(bool_test)); std::unique_ptr f(new CloudWrapperFloat(float_test)); std::unique_ptr s(new CloudWrapperString(str_test)); @@ -525,7 +525,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("Multiple String properties are changed via CBOR message") { PropertyContainer property_container; - + CloudString str_1("hello"), str_2("arduino"), str_3("cloud"), @@ -554,7 +554,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A payload containing a CBOR base name is parsed") { PropertyContainer property_container; - + CloudString str = "hello"; addPropertyToContainer(property_container, str, "test", Permission::ReadWrite); @@ -570,8 +570,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A payload containing a CBOR base time is parsed") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{-3: 123.456, 0: "test", 2: 1}] = 81 A3 22 FB 40 5E DD 2F 1A 9F BE 77 00 64 74 65 73 74 02 01 */ @@ -586,8 +586,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A payload containing a CBOR time is parsed") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{6: 123.456, 0: "test", 2: 1}] = 81 A3 06 FB 40 5E DD 2F 1A 9F BE 77 00 64 74 65 73 74 02 01 */ @@ -602,8 +602,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A payload containing a CBOR BaseVersion is parsed") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{-1: 1, 0: "test", 2: 1}] = 81 A3 20 01 00 64 74 65 73 74 02 01 */ @@ -618,8 +618,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A payload containing a CBOR BaseName, BaseTime and Time is parsed") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{-2: "base-name", -3: 654.321, 6: 123.456, 0: "test", 2: 1}] = @@ -636,8 +636,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") WHEN("A payload containing a invalid CBOR key is parsed") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{123: 123, 0: "test", 2: 1}] = 81 A3 18 7B 18 7B 00 64 74 65 73 74 02 01 */ diff --git a/extras/test/src/test_encode.cpp b/extras/test/src/test_encode.cpp index ecb3c54ee..a91803b89 100644 --- a/extras/test/src/test_encode.cpp +++ b/extras/test/src/test_encode.cpp @@ -57,12 +57,28 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]" /************************************************************************************/ - WHEN("A 'int' property is added") + WHEN("An 'int16' property is added") { PropertyContainer property_container; cbor::encode(property_container); - CloudInt int_test = 123; + CloudInt int_test = 123; + addPropertyToContainer(property_container, int_test, "test", Permission::ReadWrite); + + /* [{0: "test", 2: 123}] = 9F A2 00 64 74 65 73 74 02 18 7B FF */ + std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x18, 0x7B, 0xFF}; + std::vector const actual = cbor::encode(property_container); + REQUIRE(actual == expected); + } + + /************************************************************************************/ + + WHEN("An 'int32' property is added") + { + PropertyContainer property_container; + cbor::encode(property_container); + + CloudInt int_test = 123; addPropertyToContainer(property_container, int_test, "test", Permission::ReadWrite); /* [{0: "test", 2: 123}] = 9F A2 00 64 74 65 73 74 02 18 7B FF */ @@ -343,11 +359,11 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]" WHEN("Multiple properties are added") { PropertyContainer property_container; - - CloudInt int_test = 1; - CloudBool bool_test = false; - CloudFloat float_test = 2.0f; - CloudString str_test; + + CloudInt int_test = 1; + CloudBool bool_test = false; + CloudFloat float_test = 2.0f; + CloudString str_test; str_test = "str_test"; addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite); @@ -368,14 +384,14 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]" WHEN("Multiple primitive properties are added") { PropertyContainer property_container; - + int int_test = 1; bool bool_test = false; float float_test = 2.0f; String str_test; str_test = "str_test"; - std::unique_ptr i(new CloudWrapperInt(int_test)); + std::unique_ptr i(new CloudWrapperInt(int_test)); std::unique_ptr b(new CloudWrapperBool(bool_test)); std::unique_ptr f(new CloudWrapperFloat(float_test)); std::unique_ptr s(new CloudWrapperString(str_test)); @@ -448,17 +464,17 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]" { PropertyContainer property_container; - CloudInt int_0; int_0 = 1000000; - CloudInt int_1; int_1 = 1000001; - CloudInt int_2; int_2 = 1000002; - CloudInt int_3; int_3 = 1000003; - CloudInt int_4; int_4 = 1000004; - CloudInt int_5; int_5 = 1000005; - CloudInt int_6; int_6 = 1000006; - CloudInt int_7; int_7 = 1000007; - CloudInt int_8; int_8 = 1000008; - CloudInt int_9; int_9 = 1000009; - CloudInt int_A; int_A = 1000010; + CloudInt int_0; int_0 = 1000000; + CloudInt int_1; int_1 = 1000001; + CloudInt int_2; int_2 = 1000002; + CloudInt int_3; int_3 = 1000003; + CloudInt int_4; int_4 = 1000004; + CloudInt int_5; int_5 = 1000005; + CloudInt int_6; int_6 = 1000006; + CloudInt int_7; int_7 = 1000007; + CloudInt int_8; int_8 = 1000008; + CloudInt int_9; int_9 = 1000009; + CloudInt int_A; int_A = 1000010; CloudSchedule schedule = CloudSchedule(1633305600, 1633651200, 600, 1140850708); addPropertyToContainer(property_container, int_0, "int_value_0", Permission::ReadWrite); @@ -515,5 +531,4 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]" std::vector const actual_1 = cbor::encode(property_container); REQUIRE(actual_1 == expected_1); } - } diff --git a/extras/test/src/test_publishOnChange.cpp b/extras/test/src/test_publishOnChange.cpp index 2896e00b7..2e2e008db 100644 --- a/extras/test/src/test_publishOnChange.cpp +++ b/extras/test/src/test_publishOnChange.cpp @@ -17,9 +17,9 @@ SCENARIO("An Arduino cloud property is published on value change", "[ArduinoCloudThing::publishOnChange]") { PropertyContainer property_container; - - CloudInt test = 10; - int const DELTA = 6; + + CloudInt test = 10; + int const DELTA = 6; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishOnChange(DELTA,0); diff --git a/extras/test/src/test_publishOnChangeRateLimit.cpp b/extras/test/src/test_publishOnChangeRateLimit.cpp index 92f8bc40e..7652dbafa 100644 --- a/extras/test/src/test_publishOnChangeRateLimit.cpp +++ b/extras/test/src/test_publishOnChangeRateLimit.cpp @@ -17,8 +17,8 @@ SCENARIO("An Arduino cloud property is published on value change but the update rate is limited", "[ArduinoCloudThing::publishOnChange]") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; int const MIN_DELTA = 0; unsigned long const MIN_TIME_BETWEEN_UPDATES_ms = 500; /* No updates faster than 500 ms */ diff --git a/extras/test/src/test_readOnly.cpp b/extras/test/src/test_readOnly.cpp index 91bcf5cab..144da9da8 100644 --- a/extras/test/src/test_readOnly.cpp +++ b/extras/test/src/test_readOnly.cpp @@ -20,8 +20,8 @@ SCENARIO("An Arduino cloud property is marked 'read only'", "[ArduinoCloudThing::decode]") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::Read); /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ diff --git a/extras/test/src/test_writeOnChange.cpp b/extras/test/src/test_writeOnChange.cpp index 0896bbdfd..5f9edcecc 100644 --- a/extras/test/src/test_writeOnChange.cpp +++ b/extras/test/src/test_writeOnChange.cpp @@ -21,7 +21,7 @@ SCENARIO("An Arduino cloud property is marked 'write on change'", "[ArduinoCloud { PropertyContainer property_container; - CloudInt test = 0; + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).writeOnChange(); /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ diff --git a/extras/test/src/test_writeOnDemand.cpp b/extras/test/src/test_writeOnDemand.cpp index 5bd0c3782..a125b5d33 100644 --- a/extras/test/src/test_writeOnDemand.cpp +++ b/extras/test/src/test_writeOnDemand.cpp @@ -21,7 +21,7 @@ SCENARIO("An Arduino cloud property is marked 'write on demand'", "[ArduinoCloud { PropertyContainer property_container; - CloudInt test = 0; + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).writeOnDemand(); /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ diff --git a/extras/test/src/test_writeOnly.cpp b/extras/test/src/test_writeOnly.cpp index 6a45c3494..773eefc73 100644 --- a/extras/test/src/test_writeOnly.cpp +++ b/extras/test/src/test_writeOnly.cpp @@ -20,8 +20,8 @@ SCENARIO("An Arduino cloud property is marked 'write only'", "[ArduinoCloudThing::encode]") { PropertyContainer property_container; - - CloudInt test = 0; + + CloudInt test = 0; addPropertyToContainer(property_container, test, "test", Permission::Write); REQUIRE(cbor::encode(property_container).size() == 0); /* Since 'test' is 'write only' it should not be encoded */ diff --git a/library.properties b/library.properties index c044ef343..5097bbe44 100644 --- a/library.properties +++ b/library.properties @@ -6,6 +6,6 @@ sentence=This library allows connecting to the Arduino IoT Cloud service. paragraph=It provides a ConnectionManager to handle connection/disconnection, property-change updates and events callbacks. The supported boards are MKR GSM, MKR1000 and WiFi101. category=Communication url=https://github.com/arduino-libraries/ArduinoIoTCloud -architectures=mbed,samd,esp8266,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge +architectures=avr,mbed,samd,esp8266,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge includes=ArduinoIoTCloud.h -depends=Arduino_ConnectionHandler,Arduino_DebugUtils,Arduino_SecureElement,ArduinoMqttClient,ArduinoECCX08,RTCZero,Adafruit SleepyDog Library,ArduinoHttpClient +depends=Arduino_ConnectionHandler,Arduino_DebugUtils,Arduino_SecureElement,ArduinoMqttClient,ArduinoECCX08,ArduinoSTL,RTCZero,Adafruit SleepyDog Library,ArduinoHttpClient diff --git a/src/ArduinoIoTCloud.cpp b/src/ArduinoIoTCloud.cpp index a565cac44..5e0c4c151 100644 --- a/src/ArduinoIoTCloud.cpp +++ b/src/ArduinoIoTCloud.cpp @@ -62,121 +62,166 @@ void ArduinoIoTCloudClass::addCallback(ArduinoIoTCloudEvent const event, OnCloud _cloud_event_callback[static_cast(event)] = callback; } -/* The following methods are used for non-LoRa boards */ -Property& ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, Permission const permission) +/* The following methods are used for both LoRa and non-Lora boards */ +template <> Property& ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, int tag, Permission const permission) { - return addPropertyReal(property, name, -1, permission); + Property* p = new CloudWrapperBool(property); + return addPropertyToContainer(getThingPropertyContainer(), *p, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(float& property, String name, Permission const permission) +template <> Property& ArduinoIoTCloudClass::addPropertyReal(float& property, String name, int tag, Permission const permission) { - return addPropertyReal(property, name, -1, permission); + Property* p = new CloudWrapperFloat(property); + return addPropertyToContainer(getThingPropertyContainer(), *p, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(int& property, String name, Permission const permission) + +Property& ArduinoIoTCloudClass::addPropertyReal(String& property, String name, int tag, Permission const permission) { - return addPropertyReal(property, name, -1, permission); + Property* p = new CloudWrapperString(property); + return addPropertyToContainer(getThingPropertyContainer(), *p, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(unsigned int& property, String name, Permission const permission) +Property& ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, int tag, Permission const permission) { - return addPropertyReal(property, name, -1, permission); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(String& property, String name, Permission const permission) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudBool& property, String name, int tag, Permission const permission) { - return addPropertyReal(property, name, -1, permission); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, Permission const permission) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudColor& property, String name, int tag, Permission const permission) { - return addPropertyReal(property, name, -1, permission); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } - -/* The following methods are used for both LoRa and non-Lora boards */ -Property& ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, int tag, Permission const permission) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudColoredLight& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperBool(property); - return addPropertyReal(*p, name, tag, permission); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(float& property, String name, int tag, Permission const permission) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudContactSensor& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperFloat(property); - return addPropertyReal(*p, name, tag, permission); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(int& property, String name, int tag, Permission const permission) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudDimmedLight& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperInt(property); - return addPropertyReal(*p, name, tag, permission); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(unsigned int& property, String name, int tag, Permission const permission) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudFloat& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperUnsignedInt(property); - return addPropertyReal(*p, name, tag, permission); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(String& property, String name, int tag, Permission const permission) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudLight& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperString(property); - return addPropertyReal(*p, name, tag, permission); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -Property& ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, int tag, Permission const permission) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudLocation& property, String name, int tag, Permission const permission) { return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } - -/* The following methods are deprecated but still used for non-LoRa boards */ -void ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudMotionSensor& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperBool(property); - addPropertyRealInternal(*p, name, -1, permission_type, seconds, fn, minDelta, synFn); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -void ArduinoIoTCloudClass::addPropertyReal(float& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudSchedule& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperFloat(property); - addPropertyRealInternal(*p, name, -1, permission_type, seconds, fn, minDelta, synFn); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -void ArduinoIoTCloudClass::addPropertyReal(int& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudSmartPlug& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperInt(property); - addPropertyRealInternal(*p, name, -1, permission_type, seconds, fn, minDelta, synFn); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -void ArduinoIoTCloudClass::addPropertyReal(unsigned int& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudString& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperUnsignedInt(property); - addPropertyRealInternal(*p, name, -1, permission_type, seconds, fn, minDelta, synFn); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -void ArduinoIoTCloudClass::addPropertyReal(String& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudSwitch& property, String name, int tag, Permission const permission) { - Property* p = new CloudWrapperString(property); - addPropertyRealInternal(*p, name, -1, permission_type, seconds, fn, minDelta, synFn); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } -void ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +Property& ArduinoIoTCloudClass::addPropertyReal(CloudTelevision& property, String name, int tag, Permission const permission) { - addPropertyRealInternal(property, name, -1, permission_type, seconds, fn, minDelta, synFn); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); +} +Property& ArduinoIoTCloudClass::addPropertyReal(CloudTemperatureSensor& property, String name, int tag, Permission const permission) +{ + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } /* The following methods are deprecated but still used for both LoRa and non-LoRa boards */ -void ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +template <> void ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) { Property* p = new CloudWrapperBool(property); addPropertyRealInternal(*p, name, tag, permission_type, seconds, fn, minDelta, synFn); } -void ArduinoIoTCloudClass::addPropertyReal(float& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +template <> void ArduinoIoTCloudClass::addPropertyReal(float& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) { Property* p = new CloudWrapperFloat(property); addPropertyRealInternal(*p, name, tag, permission_type, seconds, fn, minDelta, synFn); } -void ArduinoIoTCloudClass::addPropertyReal(int& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) + +void ArduinoIoTCloudClass::addPropertyReal(String& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) { - Property* p = new CloudWrapperInt(property); + Property* p = new CloudWrapperString(property); addPropertyRealInternal(*p, name, tag, permission_type, seconds, fn, minDelta, synFn); } -void ArduinoIoTCloudClass::addPropertyReal(unsigned int& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +void ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) { - Property* p = new CloudWrapperUnsignedInt(property); - addPropertyRealInternal(*p, name, tag, permission_type, seconds, fn, minDelta, synFn); + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); } -void ArduinoIoTCloudClass::addPropertyReal(String& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +void ArduinoIoTCloudClass::addPropertyReal(CloudBool& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) { - Property* p = new CloudWrapperString(property); - addPropertyRealInternal(*p, name, tag, permission_type, seconds, fn, minDelta, synFn); + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); } -void ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +void ArduinoIoTCloudClass::addPropertyReal(CloudColor& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudColoredLight& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudContactSensor& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudDimmedLight& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudFloat& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudLight& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudLocation& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudMotionSensor& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudSchedule& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudSmartPlug& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudString& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudSwitch& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudTelevision& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) +{ + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); +} +void ArduinoIoTCloudClass::addPropertyReal(CloudTemperatureSensor& property, String name, int tag, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) { addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); } @@ -215,4 +260,3 @@ __attribute__((weak)) void setDebugMessageLevel(int const /* level */) { /* do nothing */ } - diff --git a/src/ArduinoIoTCloud.h b/src/ArduinoIoTCloud.h index 7c0bcc5f9..4be168dae 100644 --- a/src/ArduinoIoTCloud.h +++ b/src/ArduinoIoTCloud.h @@ -39,7 +39,6 @@ #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" @@ -108,40 +107,73 @@ class ArduinoIoTCloudClass /* The following methods are used for non-LoRa boards which can use the * name of the property to identify a given property within a CBOR message. */ - - void addPropertyReal(Property& property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(bool& property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(float& property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(int& property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(unsigned int& property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(String& property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - - Property& addPropertyReal(Property& property, String name, Permission const permission); - Property& addPropertyReal(bool& property, String name, Permission const permission); - Property& addPropertyReal(float& property, String name, Permission const permission); - Property& addPropertyReal(int& property, String name, Permission const permission); - Property& addPropertyReal(unsigned int& property, String name, Permission const permission); - Property& addPropertyReal(String& property, String name, Permission const permission); + template void addPropertyReal(T& property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) + { + addPropertyReal(property, name, -1, permission_type, seconds, fn, minDelta, synFn); + } + template Property& addPropertyReal(T& property, String name, Permission const permission) + { + return addPropertyReal(property, name, -1, permission); + } /* The following methods are for MKR WAN 1300/1310 LoRa boards since * they use a number to identify a given property within a CBOR message. * This approach reduces the required amount of data which is of great * important when using LoRa. */ - - void addPropertyReal(Property& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(bool& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(float& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(int& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(unsigned int& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - void addPropertyReal(String& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))); - - Property& addPropertyReal(Property& property, String name, int tag, Permission const permission); - Property& addPropertyReal(bool& property, String name, int tag, Permission const permission); - Property& addPropertyReal(float& property, String name, int tag, Permission const permission); - Property& addPropertyReal(int& property, String name, int tag, Permission const permission); - Property& addPropertyReal(unsigned int& property, String name, int tag, Permission const permission); + template __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(T& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) + { + Property* p = new CloudWrapperInt(property); + addPropertyRealInternal(*p, name, tag, permission_type, seconds, fn, minDelta, synFn); + } + template __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudInt& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS) + { + addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn); + } + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(String& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(Property& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudBool& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudColor& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudColoredLight& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudContactSensor& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudDimmedLight& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudFloat& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudLight& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudLocation& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudMotionSensor& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudSchedule& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudSmartPlug& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudString& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudSwitch& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudTelevision& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudTemperatureSensor& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS); + + template Property& addPropertyReal(T& property, String name, int tag, Permission const permission) + { + Property* p = new CloudWrapperInt(property); + return addPropertyToContainer(getThingPropertyContainer(), *p, name, permission, tag); + } + template Property& addPropertyReal(CloudInt& property, String name, int tag, Permission const permission) + { + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); + } Property& addPropertyReal(String& property, String name, int tag, Permission const permission); + Property& addPropertyReal(Property& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudBool& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudColor& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudColoredLight& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudContactSensor& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudDimmedLight& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudFloat& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudLight& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudLocation& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudMotionSensor& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudSchedule& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudSmartPlug& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudString& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudSwitch& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudTelevision& property, String name, int tag, Permission const permission); + Property& addPropertyReal(CloudTemperatureSensor& property, String name, int tag, Permission const permission); protected: diff --git a/src/ArduinoIoTCloudThing.cpp b/src/ArduinoIoTCloudThing.cpp index 9b3656b0f..c1326f952 100644 --- a/src/ArduinoIoTCloudThing.cpp +++ b/src/ArduinoIoTCloudThing.cpp @@ -20,7 +20,6 @@ #include "ArduinoIoTCloudThing.h" #include "interfaces/CloudProcess.h" #include "property/types/CloudWrapperInt.h" -#include "property/types/CloudWrapperUnsignedInt.h" /****************************************************************************** * CTOR/DTOR @@ -44,13 +43,13 @@ _utcOffsetExpireTimeProperty(nullptr) { void ArduinoCloudThing::begin() { Property* property; - property = new CloudWrapperInt(_utcOffset); + property = new CloudWrapperInt(_utcOffset); _utcOffsetProperty = &addPropertyToContainer(getPropertyContainer(), *property, "tz_offset", Permission::ReadWrite, -1); _utcOffsetProperty->writeOnDemand(); - property = new CloudWrapperUnsignedInt(_utcOffsetExpireTime); + property = new CloudWrapperInt(_utcOffsetExpireTime); _utcOffsetExpireTimeProperty = &addPropertyToContainer(getPropertyContainer(), *property, "tz_dst_until", diff --git a/src/cbor/CBORDecoder.h b/src/cbor/CBORDecoder.h index 5e9496b2a..76c946e97 100644 --- a/src/cbor/CBORDecoder.h +++ b/src/cbor/CBORDecoder.h @@ -23,6 +23,9 @@ ******************************************************************************/ #include +#ifdef __AVR_ARCH__ +# include // needed for std::list +#endif #undef max #undef min diff --git a/src/cbor/lib/tinycbor/src/cbor.h b/src/cbor/lib/tinycbor/src/cbor.h index 27a4fe4a8..c67c67958 100644 --- a/src/cbor/lib/tinycbor/src/cbor.h +++ b/src/cbor/lib/tinycbor/src/cbor.h @@ -25,6 +25,10 @@ #ifndef CBOR_H #define CBOR_H +#ifdef __AVR_ARCH__ +# include "cbor_avr.h" +#endif + #ifndef assert #include #endif diff --git a/src/cbor/lib/tinycbor/src/cbor_avr.h b/src/cbor/lib/tinycbor/src/cbor_avr.h new file mode 100644 index 000000000..009f8c128 --- /dev/null +++ b/src/cbor/lib/tinycbor/src/cbor_avr.h @@ -0,0 +1,13 @@ +#ifndef CBOR_AVR_H +#define CBOR_AVR_H + +#define FP_INFINITE INFINITY +#define FP_NAN NAN +#define PRIu64 "llu" +#define PRIx64 "llx" + +#define ssize_t int + +extern int fpclassify(double x); + +#endif /* CBOR_AVR_H */ \ No newline at end of file diff --git a/src/cbor/lib/tinycbor/src/open_memstream.c b/src/cbor/lib/tinycbor/src/open_memstream.c index b3e624d47..5c0da2e68 100644 --- a/src/cbor/lib/tinycbor/src/open_memstream.c +++ b/src/cbor/lib/tinycbor/src/open_memstream.c @@ -34,11 +34,11 @@ #include +#include "compilersupport_p.h" + typedef ssize_t RetType; typedef size_t LenType; -#include "compilersupport_p.h" - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" #pragma GCC diagnostic ignored "-Wreturn-type" diff --git a/src/property/Property.cpp b/src/property/Property.cpp index 6297c09cb..9c0a812a4 100644 --- a/src/property/Property.cpp +++ b/src/property/Property.cpp @@ -194,171 +194,12 @@ CborError Property::append(CborEncoder *encoder, bool lightPayload) { return CborNoError; } -CborError Property::appendAttribute(bool value, String attributeName, CborEncoder *encoder) { - return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) - { - CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::BooleanValue))); - CHECK_CBOR(cbor_encode_boolean(&mapEncoder, value)); - return CborNoError; - }, encoder); -} - -CborError Property::appendAttribute(int value, String attributeName, CborEncoder *encoder) { - return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) - { - CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Value))); - CHECK_CBOR(cbor_encode_int(&mapEncoder, value)); - return CborNoError; - }, encoder); -} - -CborError Property::appendAttribute(unsigned int value, String attributeName, CborEncoder *encoder) { - return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) - { - CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Value))); - CHECK_CBOR(cbor_encode_int(&mapEncoder, value)); - return CborNoError; - }, encoder); -} - -CborError Property::appendAttribute(float value, String attributeName, CborEncoder *encoder) { - return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) - { - CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Value))); - CHECK_CBOR(cbor_encode_float(&mapEncoder, value)); - return CborNoError; - }, encoder); -} - -CborError Property::appendAttribute(String value, String attributeName, CborEncoder *encoder) { - return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) - { - CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::StringValue))); - CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, value.c_str())); - return CborNoError; - }, encoder); -} - -CborError Property::appendAttributeName(String attributeName, std::functionappendValue, CborEncoder *encoder) -{ - if (attributeName != "") { - // when the attribute name string is not empty, the attribute identifier is incremented in order to be encoded in the message if the _lightPayload flag is set - _attributeIdentifier++; - } - CborEncoder mapEncoder; - unsigned int num_map_properties = _encode_timestamp ? 3 : 2; - CHECK_CBOR(cbor_encoder_create_map(encoder, &mapEncoder, num_map_properties)); - CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Name))); - - // if _lightPayload is true, the property and attribute identifiers will be encoded instead of the property name - if (_lightPayload) - { - // the most significant byte of the identifier to be encoded represent the property identifier - int completeIdentifier = _attributeIdentifier * 256; - // the least significant byte of the identifier to be encoded represent the attribute identifier - completeIdentifier += _identifier; - CHECK_CBOR(cbor_encode_int(&mapEncoder, completeIdentifier)); - } - else - { - String completeName = _name; - if (attributeName != "") { - completeName += ":" + attributeName; - } - CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, completeName.c_str())); - } - /* Encode the value */ - CHECK_CBOR(appendValue(mapEncoder)); - - /* Encode the timestamp if that has been required. */ - if(_encode_timestamp) - { - CHECK_CBOR(cbor_encode_int (&mapEncoder, static_cast(CborIntegerMapKey::Time))); - CHECK_CBOR(cbor_encode_uint(&mapEncoder, _timestamp)); - } - /* Close the container */ - CHECK_CBOR(cbor_encoder_close_container(encoder, &mapEncoder)); - return CborNoError; -} - void Property::setAttributesFromCloud(std::list * map_data_list) { _map_data_list = map_data_list; _attributeIdentifier = 0; setAttributesFromCloud(); } -void Property::setAttribute(bool& value, String attributeName) { - setAttribute(attributeName, [&value](CborMapData & md) { - // Manage the case to have boolean values received as integers 0/1 - if (md.bool_val.isSet()) { - value = md.bool_val.get(); - } else if (md.val.isSet()) { - if (md.val.get() == 0) { - value = false; - } else if (md.val.get() == 1) { - value = true; - } else { - /* This should not happen. Leave the previous value */ - } - } - }); -} - -void Property::setAttribute(int& value, String attributeName) { - setAttribute(attributeName, [&value](CborMapData & md) { - value = md.val.get(); - }); -} - -void Property::setAttribute(unsigned int& value, String attributeName) { - setAttribute(attributeName, [&value](CborMapData & md) { - value = md.val.get(); - }); -} - -void Property::setAttribute(float& value, String attributeName) { - setAttribute(attributeName, [&value](CborMapData & md) { - value = md.val.get(); - }); -} - -void Property::setAttribute(String& value, String attributeName) { - setAttribute(attributeName, [&value](CborMapData & md) { - value = md.str_val.get(); - }); -} - -void Property::setAttribute(String attributeName, std::functionsetValue) -{ - if (attributeName != "") { - _attributeIdentifier++; - } - - std::for_each(_map_data_list->begin(), - _map_data_list->end(), - [this, attributeName, setValue](CborMapData & map) - { - if (map.light_payload.isSet() && map.light_payload.get()) - { - // if a light payload is detected, the attribute identifier is retrieved from the cbor map and the corresponding attribute is updated - int attid = map.attribute_identifier.get(); - if (attid == _attributeIdentifier) { - setValue(map); - return; - } - } - else - { - // if a normal payload is detected, the name of the attribute to be updated is extracted directly from the cbor map - String an = map.attribute_name.get(); - if (an == attributeName) { - setValue(map); - return; - } - } - }); -} - void Property::updateLocalTimestamp() { if (isReadableByCloud()) { if (_get_time_func) { diff --git a/src/property/Property.h b/src/property/Property.h index 71a8447c9..59f313fc0 100644 --- a/src/property/Property.h +++ b/src/property/Property.h @@ -32,7 +32,6 @@ #undef max #undef min -# include #include #include "../cbor/lib/tinycbor/cbor-lib.h" @@ -185,19 +184,86 @@ class Property void updateLocalTimestamp(); CborError append(CborEncoder * encoder, bool lightPayload); - CborError appendAttribute(bool value, String attributeName = "", CborEncoder *encoder = nullptr); - CborError appendAttribute(int value, String attributeName = "", CborEncoder *encoder = nullptr); - CborError appendAttribute(unsigned int value, String attributeName = "", CborEncoder *encoder = nullptr); - CborError appendAttribute(float value, String attributeName = "", CborEncoder *encoder = nullptr); - CborError appendAttribute(String value, String attributeName = "", CborEncoder *encoder = nullptr); - CborError appendAttributeName(String attributeName, std::functionf, CborEncoder *encoder); - void setAttribute(String attributeName, std::functionsetValue); + template CborError appendAttribute(T value, String attributeName = "", CborEncoder *encoder = nullptr) { + return appendAttributeName(attributeName, encodeAppendedAttribute, value, encoder); + } + template CborError appendAttributeName(String attributeName, CborError(*appendValue)(CborEncoder& mapEncoder, const T), const T & value, CborEncoder *encoder) + { + if (attributeName != "") { + // when the attribute name string is not empty, the attribute identifier is incremented in order to be encoded in the message if the _lightPayload flag is set + _attributeIdentifier++; + } + CborEncoder mapEncoder; + unsigned int num_map_properties = _encode_timestamp ? 3 : 2; + CHECK_CBOR(cbor_encoder_create_map(encoder, &mapEncoder, num_map_properties)); + CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Name))); + + // if _lightPayload is true, the property and attribute identifiers will be encoded instead of the property name + if (_lightPayload) + { + // the most significant byte of the identifier to be encoded represent the property identifier + int completeIdentifier = _attributeIdentifier * 256; + // the least significant byte of the identifier to be encoded represent the attribute identifier + completeIdentifier += _identifier; + CHECK_CBOR(cbor_encode_int(&mapEncoder, completeIdentifier)); + } + else + { + String completeName = _name; + if (attributeName != "") { + completeName += ":" + attributeName; + } + CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, completeName.c_str())); + } + /* Encode the value */ + CHECK_CBOR(appendValue(mapEncoder, value)); + + /* Encode the timestamp if that has been required. */ + if(_encode_timestamp) + { + CHECK_CBOR(cbor_encode_int (&mapEncoder, static_cast(CborIntegerMapKey::Time))); + CHECK_CBOR(cbor_encode_uint(&mapEncoder, _timestamp)); + } + /* Close the container */ + CHECK_CBOR(cbor_encoder_close_container(encoder, &mapEncoder)); + return CborNoError; + } + template void setAttribute(const String attributeName, void(* const setValue)(CborMapData & md, T &), T & value) + { + if (attributeName != "") { + _attributeIdentifier++; + } + + std::list::iterator it = _map_data_list->begin(); + for (; it != _map_data_list->end(); ++it) { + CborMapData & map = *it; + if (map.light_payload.isSet() && map.light_payload.get()) + { + // if a light payload is detected, the attribute identifier is retrieved + // from the cbor map and the corresponding attribute is updated + int attid = map.attribute_identifier.get(); + if (attid == _attributeIdentifier) { + setValue(map, value); + return; + } + } + else + { + // if a normal payload is detected, the name of the attribute to be + // updated is extracted directly from the cbor map + String an = map.attribute_name.get(); + if (an == attributeName) { + setValue(map, value); + return; + } + } + } + } + + template void setAttribute(T& value, String attributeName = "") { + setAttribute(attributeName, setValueAttribute, value); + } void setAttributesFromCloud(std::list * map_data_list); - void setAttribute(bool& value, String attributeName = ""); - void setAttribute(int& value, String attributeName = ""); - void setAttribute(unsigned int& value, String attributeName = ""); - void setAttribute(float& value, String attributeName = ""); - void setAttribute(String& value, String attributeName = ""); virtual bool isDifferentFromCloud() = 0; virtual void fromCloudToLocal() = 0; @@ -217,6 +283,18 @@ class Property unsigned long _min_time_between_updates_millis; private: + template static CborError encodeAppendedAttribute(CborEncoder & mapEncoder, const T value) { + CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Value))); + CHECK_CBOR(cbor_encode_int(&mapEncoder, value)); + return CborNoError; + } + + template static void setValueAttribute(CborMapData & md, T & value) { + if (md.val.isSet()) { + value = md.val.get(); + } + } + Permission _permission; WritePolicy _write_policy; GetTimeCallbackFunc _get_time_func; @@ -248,6 +326,45 @@ class Property unsigned long _timestamp; }; +template <> inline CborError Property::encodeAppendedAttribute(CborEncoder & mapEncoder, const bool value) { + CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::BooleanValue))); + CHECK_CBOR(cbor_encode_boolean(&mapEncoder, value)); + return CborNoError; +} + +template <> inline CborError Property::encodeAppendedAttribute(CborEncoder & mapEncoder, const float value) { + CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Value))); + CHECK_CBOR(cbor_encode_float(&mapEncoder, value)); + return CborNoError; +} + +template <> inline CborError Property::encodeAppendedAttribute(CborEncoder & mapEncoder, const String value) { + CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::StringValue))); + CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, value.c_str())); + return CborNoError; +} + +template <> inline void Property::setValueAttribute(CborMapData & md, String & value) { + if (md.str_val.isSet()) { + value = md.str_val.get(); + } +} + +template <> inline void Property::setValueAttribute(CborMapData & md, bool & value) { + // Manage the case to have boolean values received as integers 0/1 + if (md.bool_val.isSet()) { + value = md.bool_val.get(); + } else if (md.val.isSet()) { + if (md.val.get() == 0) { + value = false; + } else if (md.val.get() == 1) { + value = true; + } else { + /* This should not happen. Leave the previous value */ + } + } +} + /****************************************************************************** PROTOTYPE FREE FUNCTIONs ******************************************************************************/ diff --git a/src/property/PropertyContainer.h b/src/property/PropertyContainer.h index 9dc3c86cd..5264f6aae 100644 --- a/src/property/PropertyContainer.h +++ b/src/property/PropertyContainer.h @@ -33,7 +33,6 @@ #include "types/CloudBool.h" #include "types/CloudFloat.h" #include "types/CloudInt.h" -#include "types/CloudUnsignedInt.h" #include "types/CloudString.h" #include "types/CloudLocation.h" #include "types/CloudSchedule.h" @@ -62,36 +61,36 @@ extern "C" unsigned long getTime(); typedef std::list PropertyContainer; -typedef CloudFloat CloudEnergy; -typedef CloudFloat CloudForce; -typedef CloudFloat CloudTemperature; -typedef CloudFloat CloudPower; +typedef CloudFloat CloudAcceleration; +typedef CloudFloat CloudAngle; +typedef CloudFloat CloudArea; +typedef CloudFloat CloudCapacitance; +typedef CloudInt CloudCounter; +typedef CloudFloat CloudDataRate; typedef CloudFloat CloudElectricCurrent; typedef CloudFloat CloudElectricPotential; typedef CloudFloat CloudElectricResistance; -typedef CloudFloat CloudCapacitance; -typedef CloudUnsignedInt CloudTime; +typedef CloudFloat CloudEnergy; +typedef CloudFloat CloudFlowRate; +typedef CloudFloat CloudForce; typedef CloudFloat CloudFrequency; -typedef CloudFloat CloudDataRate; typedef CloudFloat CloudHeartRate; -typedef CloudInt CloudCounter; -typedef CloudFloat CloudAcceleration; -typedef CloudFloat CloudArea; -typedef CloudFloat CloudLength; -typedef CloudFloat CloudVelocity; -typedef CloudFloat CloudMass; -typedef CloudFloat CloudVolume; -typedef CloudFloat CloudFlowRate; -typedef CloudFloat CloudAngle; typedef CloudFloat CloudIlluminance; -typedef CloudFloat CloudLuminousFlux; +typedef CloudInt CloudInformationContent; +typedef CloudFloat CloudLength; +typedef CloudFloat CloudLogarithmicQuantity; typedef CloudFloat CloudLuminance; +typedef CloudFloat CloudLuminousFlux; typedef CloudFloat CloudLuminousIntensity; -typedef CloudFloat CloudLogarithmicQuantity; -typedef CloudFloat CloudPressure; -typedef CloudInt CloudInformationContent; +typedef CloudFloat CloudMass; typedef CloudFloat CloudPercentage; +typedef CloudFloat CloudPower; +typedef CloudFloat CloudPressure; typedef CloudFloat CloudRelativeHumidity; +typedef CloudFloat CloudTemperature; +typedef CloudInt CloudTime; +typedef CloudFloat CloudVelocity; +typedef CloudFloat CloudVolume; /****************************************************************************** FUNCTION DECLARATION @@ -104,11 +103,9 @@ 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); - void updateTimestampOnLocallyChangedProperties(PropertyContainer & prop_cont); 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); diff --git a/src/property/types/CloudColor.h b/src/property/types/CloudColor.h index 54cb4f30f..53e4aa67c 100644 --- a/src/property/types/CloudColor.h +++ b/src/property/types/CloudColor.h @@ -36,6 +36,7 @@ class Color { Color(float h, float s, float b): hue(h), sat(s), bri(b) { setColorHSB(h, s, b); } + Color(const Color& r) : hue(r.hue), sat(r.sat), bri(r.bri) {} bool setColorHSB(float h, float s, float b) { if (h < 0 || h > 360 || s < 0 || s > 100 || b < 0 || b > 100) { diff --git a/src/property/types/CloudFloat.h b/src/property/types/CloudFloat.h index 514df7866..afbf64f75 100644 --- a/src/property/types/CloudFloat.h +++ b/src/property/types/CloudFloat.h @@ -42,6 +42,7 @@ class CloudFloat : public Property { CloudFloat(0.0f); } CloudFloat(float v) : _value(v), _cloud_value(v) {} + CloudFloat(const CloudFloat& r) : _value(r._value), _cloud_value(r._cloud_value) {} operator float() const { return _value; } diff --git a/src/property/types/CloudInt.h b/src/property/types/CloudInt.h index 37e4d3cae..1030bcff4 100644 --- a/src/property/types/CloudInt.h +++ b/src/property/types/CloudInt.h @@ -22,6 +22,8 @@ INCLUDE ******************************************************************************/ +#include + #include #include "../Property.h" @@ -29,22 +31,22 @@ CLASS DECLARATION ******************************************************************************/ - - +template class CloudInt : public Property { private: - int _value, - _cloud_value; + T _value, + _cloud_value; public: - CloudInt() { + CloudInt() { CloudInt(0); } - CloudInt(int v) : _value(v), _cloud_value(v) {} - operator int() const { + CloudInt(T v) : _value(v), _cloud_value(v) {} + CloudInt(const CloudInt& r) : _value(r._value), _cloud_value(r._cloud_value) {} + operator T() const { return _value; } virtual bool isDifferentFromCloud() { - return _value != _cloud_value && (abs(_value - _cloud_value) >= Property::_min_delta_property); + return _value != _cloud_value && ((std::max(_value , _cloud_value) - std::min(_value , _cloud_value)) >= Property::_min_delta_property); } virtual void fromCloudToLocal() { _value = _cloud_value; @@ -59,27 +61,27 @@ class CloudInt : public Property { setAttribute(_cloud_value, ""); } //modifiers - CloudInt& operator=(int v) { + CloudInt& operator=(T v) { _value = v; updateLocalTimestamp(); return *this; } CloudInt& operator=(CloudInt v) { - return operator=((int)v); + return operator=(static_cast(v)); } - CloudInt& operator+=(int v) { + CloudInt& operator+=(T v) { return operator=(_value += v); } - CloudInt& operator-=(int v) { + CloudInt& operator-=(T v) { return operator=(_value -= v); } - CloudInt& operator*=(int v) { + CloudInt& operator*=(T v) { return operator=(_value *= v); } - CloudInt& operator/=(int v) { + CloudInt& operator/=(T v) { return operator=(_value /= v); } - CloudInt& operator%=(int v) { + CloudInt& operator%=(T v) { return operator=(_value %= v); } CloudInt& operator++() { @@ -96,19 +98,19 @@ class CloudInt : public Property { operator=(_value - 1); return CloudInt(_value); } - CloudInt& operator&=(int v) { + CloudInt& operator&=(T v) { return operator=(_value &= v); } - CloudInt& operator|=(int v) { + CloudInt& operator|=(T v) { return operator=(_value |= v); } - CloudInt& operator^=(int v) { + CloudInt& operator^=(T v) { return operator=(_value ^= v); } - CloudInt& operator<<=(int v) { + CloudInt& operator<<=(T v) { return operator=(_value <<= v); } - CloudInt& operator>>=(int v) { + CloudInt& operator>>=(T v) { return operator=(_value >>= v); } //accessors @@ -128,95 +130,93 @@ class CloudInt : public Property { friend CloudInt operator+(CloudInt iw, CloudInt v) { return iw += v; } - friend CloudInt operator+(CloudInt iw, int v) { + friend CloudInt operator+(CloudInt iw, T v) { return iw += v; } - friend CloudInt operator+(int v, CloudInt iw) { + friend CloudInt operator+(T v, CloudInt iw) { return CloudInt(v) += iw; } friend CloudInt operator-(CloudInt iw, CloudInt v) { return iw -= v; } - friend CloudInt operator-(CloudInt iw, int v) { + friend CloudInt operator-(CloudInt iw, T v) { return iw -= v; } - friend CloudInt operator-(int v, CloudInt iw) { + friend CloudInt operator-(T v, CloudInt iw) { return CloudInt(v) -= iw; } friend CloudInt operator*(CloudInt iw, CloudInt v) { return iw *= v; } - friend CloudInt operator*(CloudInt iw, int v) { + friend CloudInt operator*(CloudInt iw, T v) { return iw *= v; } - friend CloudInt operator*(int v, CloudInt iw) { + friend CloudInt operator*(T v, CloudInt iw) { return CloudInt(v) *= iw; } friend CloudInt operator/(CloudInt iw, CloudInt v) { return iw /= v; } - friend CloudInt operator/(CloudInt iw, int v) { + friend CloudInt operator/(CloudInt iw, T v) { return iw /= v; } - friend CloudInt operator/(int v, CloudInt iw) { + friend CloudInt operator/(T v, CloudInt iw) { return CloudInt(v) /= iw; } friend CloudInt operator%(CloudInt iw, CloudInt v) { return iw %= v; } - friend CloudInt operator%(CloudInt iw, int v) { + friend CloudInt operator%(CloudInt iw, T v) { return iw %= v; } - friend CloudInt operator%(int v, CloudInt iw) { + friend CloudInt operator%(T v, CloudInt iw) { return CloudInt(v) %= iw; } friend CloudInt operator&(CloudInt iw, CloudInt v) { return iw &= v; } - friend CloudInt operator&(CloudInt iw, int v) { + friend CloudInt operator&(CloudInt iw, T v) { return iw &= v; } - friend CloudInt operator&(int v, CloudInt iw) { + friend CloudInt operator&(T v, CloudInt iw) { return CloudInt(v) &= iw; } friend CloudInt operator|(CloudInt iw, CloudInt v) { return iw |= v; } - friend CloudInt operator|(CloudInt iw, int v) { + friend CloudInt operator|(CloudInt iw, T v) { return iw |= v; } - friend CloudInt operator|(int v, CloudInt iw) { + friend CloudInt operator|(T v, CloudInt iw) { return CloudInt(v) |= iw; } friend CloudInt operator^(CloudInt iw, CloudInt v) { return iw ^= v; } - friend CloudInt operator^(CloudInt iw, int v) { + friend CloudInt operator^(CloudInt iw, T v) { return iw ^= v; } - friend CloudInt operator^(int v, CloudInt iw) { + friend CloudInt operator^(T v, CloudInt iw) { return CloudInt(v) ^= iw; } friend CloudInt operator<<(CloudInt iw, CloudInt v) { return iw <<= v; } - friend CloudInt operator<<(CloudInt iw, int v) { + friend CloudInt operator<<(CloudInt iw, T v) { return iw <<= v; } - friend CloudInt operator<<(int v, CloudInt iw) { + friend CloudInt operator<<(T v, CloudInt iw) { return CloudInt(v) <<= iw; } friend CloudInt operator>>(CloudInt iw, CloudInt v) { return iw >>= v; } - friend CloudInt operator>>(CloudInt iw, int v) { + friend CloudInt operator>>(CloudInt iw, T v) { return iw >>= v; } - friend CloudInt operator>>(int v, CloudInt iw) { + friend CloudInt operator>>(T 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..d7fbf0c38 100644 --- a/src/property/types/CloudLocation.h +++ b/src/property/types/CloudLocation.h @@ -37,6 +37,7 @@ class Location { float lat, lon; Location(float lat, float lon) : lat(lat), lon(lon) {} + Location(const Location& r) : lat(r.lat), lon(r.lon) {} Location& operator=(Location& aLocation) { lat = aLocation.lat; lon = aLocation.lon; diff --git a/src/property/types/CloudSchedule.h b/src/property/types/CloudSchedule.h index 9a9222968..1ddbc34e3 100644 --- a/src/property/types/CloudSchedule.h +++ b/src/property/types/CloudSchedule.h @@ -26,37 +26,38 @@ #include "../Property.h" #include "../../AIoTC_Const.h" #include "utility/time/TimeService.h" +#include #include /****************************************************************************** * DEFINE ******************************************************************************/ -#define SCHEDULE_UNIT_MASK 0xC0000000 +#define SCHEDULE_UNIT_MASK static_cast(0xC0000000) #define SCHEDULE_UNIT_SHIFT 30 -#define SCHEDULE_TYPE_MASK 0x3C000000 +#define SCHEDULE_TYPE_MASK static_cast(0x3C000000) #define SCHEDULE_TYPE_SHIFT 26 -#define SCHEDULE_MONTH_MASK 0x0000FF00 +#define SCHEDULE_MONTH_MASK static_cast(0x0000FF00) #define SCHEDULE_MONTH_SHIFT 8 -#define SCHEDULE_REP_MASK 0x03FFFFFF -#define SCHEDULE_WEEK_MASK 0x000000FF -#define SCHEDULE_DAY_MASK 0x000000FF +#define SCHEDULE_REP_MASK static_cast(0x03FFFFFF) +#define SCHEDULE_WEEK_MASK static_cast(0x000000FF) +#define SCHEDULE_DAY_MASK static_cast(0x000000FF) -#define SCHEDULE_ONE_SHOT 0xFFFFFFFF +#define SCHEDULE_ONE_SHOT static_cast(0xFFFFFFFF) /****************************************************************************** ENUM ******************************************************************************/ -enum class ScheduleUnit : int { +enum class ScheduleUnit : int32_t { Seconds = 0, Minutes = 1, Hours = 2, Days = 3 }; -enum class ScheduleType : int { +enum class ScheduleType : int32_t { OneShot = 0, FixedDelta = 1, Weekly = 2, @@ -64,7 +65,7 @@ enum class ScheduleType : int { Yearly = 4 }; -enum class ScheduleMonth : int { +enum class ScheduleMonth : int32_t { Jan = 0, Feb = 1, Mar = 2, @@ -79,7 +80,7 @@ enum class ScheduleMonth : int { Dec = 11 }; -enum class ScheduleWeekDay : int { +enum class ScheduleWeekDay : int32_t { Sun = 0, Mon = 1, Tue = 2, @@ -89,7 +90,7 @@ enum class ScheduleWeekDay : int { Sat = 6 }; -enum class ScheduleState : int { +enum class ScheduleState : int32_t { Inactive = 0, Active = 1 }; @@ -98,12 +99,12 @@ enum class ScheduleState : int { * TYPEDEF ******************************************************************************/ typedef struct ScheduleWeeklyMask { - ScheduleState& operator[](ScheduleWeekDay i) { return day[static_cast(i)];} + ScheduleState& operator[](ScheduleWeekDay i) { return day[static_cast(i)];} ScheduleState day[7]; }ScheduleWeeklyMask; -typedef unsigned int ScheduleTimeType; -typedef unsigned int ScheduleConfigurationType; +typedef uint32_t ScheduleTimeType; +typedef uint32_t ScheduleConfigurationType; /****************************************************************************** CLASS DECLARATION @@ -112,6 +113,7 @@ class Schedule { public: ScheduleTimeType frm, to, len, msk; Schedule(ScheduleTimeType s, ScheduleTimeType e, ScheduleTimeType d, ScheduleConfigurationType m): frm(s), to(e), len(d), msk(m) {} + Schedule(const Schedule& r) : frm(r.frm), to(r.to), len(r.len), msk(r.msk) {} bool isActive() { @@ -140,10 +142,10 @@ class Schedule { return 0; } - static ScheduleConfigurationType createFixedDeltaScheduleConfiguration(ScheduleUnit unit, unsigned int delta) { - int temp_unit = static_cast(unit); - int temp_type = static_cast(ScheduleType::FixedDelta); - unsigned int temp_delta = delta; + static ScheduleConfigurationType createFixedDeltaScheduleConfiguration(ScheduleUnit unit, uint32_t delta) { + int32_t temp_unit = static_cast(unit); + int32_t temp_type = static_cast(ScheduleType::FixedDelta); + uint32_t temp_delta = delta; if (temp_delta > SCHEDULE_REP_MASK) { temp_delta = SCHEDULE_REP_MASK; @@ -152,10 +154,10 @@ class Schedule { } static ScheduleConfigurationType createWeeklyScheduleConfiguration(ScheduleWeeklyMask weekMask) { - unsigned int temp_week = 0; - int temp_type = static_cast(ScheduleType::Weekly); + uint32_t temp_week = 0; + int32_t temp_type = static_cast(ScheduleType::Weekly); - for(int i = 0; i<7; i++) { + for(size_t i = 0; i<7; i++) { if(weekMask[static_cast(i)] == ScheduleState::Active) { temp_week |= 1 << i; } @@ -163,9 +165,9 @@ class Schedule { return (temp_type << SCHEDULE_TYPE_SHIFT) | temp_week; } - static ScheduleConfigurationType createMonthlyScheduleConfiguration(int dayOfTheMonth) { - int temp_day = dayOfTheMonth; - int temp_type = static_cast(ScheduleType::Monthly); + static ScheduleConfigurationType createMonthlyScheduleConfiguration(int32_t dayOfTheMonth) { + int32_t temp_day = dayOfTheMonth; + int32_t temp_type = static_cast(ScheduleType::Monthly); if(temp_day < 1) { temp_day = 1; @@ -177,10 +179,10 @@ class Schedule { return (temp_type << SCHEDULE_TYPE_SHIFT) | temp_day; } - static ScheduleConfigurationType createYearlyScheduleConfiguration(ScheduleMonth month, int dayOfTheMonth) { - unsigned int temp_day = createMonthlyScheduleConfiguration(dayOfTheMonth); - int temp_month = static_cast(month); - int temp_type = static_cast(ScheduleType::Yearly); + static ScheduleConfigurationType createYearlyScheduleConfiguration(ScheduleMonth month, int32_t dayOfTheMonth) { + uint32_t temp_day = createMonthlyScheduleConfiguration(dayOfTheMonth); + int32_t temp_month = static_cast(month); + int32_t temp_type = static_cast(ScheduleType::Yearly); return (temp_type << SCHEDULE_TYPE_SHIFT) | (temp_month << SCHEDULE_MONTH_SHIFT)| temp_day; } @@ -210,19 +212,19 @@ class Schedule { return static_cast((msk & SCHEDULE_TYPE_MASK) >> SCHEDULE_TYPE_SHIFT); } - unsigned int getScheduleRepetition(ScheduleConfigurationType msk) { + uint32_t getScheduleRepetition(ScheduleConfigurationType msk) { return (msk & SCHEDULE_REP_MASK); } - unsigned int getScheduleWeekMask(ScheduleConfigurationType msk) { + uint32_t getScheduleWeekMask(ScheduleConfigurationType msk) { return (msk & SCHEDULE_WEEK_MASK); } - unsigned int getScheduleDay(ScheduleConfigurationType msk) { + uint32_t getScheduleDay(ScheduleConfigurationType msk) { return (msk & SCHEDULE_DAY_MASK); } - unsigned int getScheduleMonth(ScheduleConfigurationType msk) { + uint32_t getScheduleMonth(ScheduleConfigurationType msk) { return ((msk & SCHEDULE_MONTH_MASK) >> SCHEDULE_MONTH_SHIFT); } @@ -278,21 +280,21 @@ class Schedule { } } - unsigned int getCurrentDayMask(time_t time) { + uint32_t getCurrentDayMask(time_t time) { struct tm * ptm; ptm = gmtime (&time); return 1 << ptm->tm_wday; } - unsigned int getCurrentDay(time_t time) { + uint32_t getCurrentDay(time_t time) { struct tm * ptm; ptm = gmtime (&time); return ptm->tm_mday; } - unsigned int getCurrentMonth(time_t time) { + uint32_t getCurrentMonth(time_t time) { struct tm * ptm; ptm = gmtime (&time); @@ -318,19 +320,19 @@ class Schedule { if(isScheduleFixed(msk) || isScheduleOneShot(msk)) { return true; } - + if(isScheduleWeekly(msk)) { - unsigned int currentDayMask = getCurrentDayMask(now); - unsigned int scheduleMask = getScheduleWeekMask(msk); - + uint32_t currentDayMask = getCurrentDayMask(now); + uint32_t scheduleMask = getScheduleWeekMask(msk); + if((currentDayMask & scheduleMask) != 0) { return true; } } if(isScheduleMonthly(msk)) { - unsigned int currentDay = getCurrentDay(now); - unsigned int scheduleDay = getScheduleDay(msk); + uint32_t currentDay = getCurrentDay(now); + uint32_t scheduleDay = getScheduleDay(msk); if(currentDay == scheduleDay) { return true; @@ -338,10 +340,10 @@ class Schedule { } if(isScheduleYearly(msk)) { - unsigned int currentDay = getCurrentDay(now); - unsigned int scheduleDay = getScheduleDay(msk); - unsigned int currentMonth = getCurrentMonth(now); - unsigned int scheduleMonth = getScheduleMonth(msk); + uint32_t currentDay = getCurrentDay(now); + uint32_t scheduleDay = getScheduleDay(msk); + uint32_t currentMonth = getCurrentMonth(now); + uint32_t scheduleMonth = getScheduleMonth(msk); if((currentDay == scheduleDay) && (currentMonth == scheduleMonth)) { return true; @@ -382,10 +384,9 @@ class CloudSchedule : public Property { _cloud_value; public: 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) {} + CloudSchedule(uint32_t frm, uint32_t to, uint32_t len, uint32_t msk) : _value(frm, to, len, msk), _cloud_value(frm, to, len, msk) {} virtual bool isDifferentFromCloud() { - return _value != _cloud_value; } @@ -413,9 +414,11 @@ class CloudSchedule : public Property { virtual void fromCloudToLocal() { _value = _cloud_value; } + virtual void fromLocalToCloud() { _cloud_value = _value; } + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { CHECK_CBOR_MULTI(appendAttribute(_value.frm, "frm", encoder)); CHECK_CBOR_MULTI(appendAttribute(_value.to, "to", encoder)); @@ -423,6 +426,7 @@ class CloudSchedule : public Property { CHECK_CBOR_MULTI(appendAttribute(_value.msk, "msk", encoder)); return CborNoError; } + virtual void setAttributesFromCloud() { setAttribute(_cloud_value.frm, "frm"); setAttribute(_cloud_value.to, "to"); 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/CloudWrapperInt.h b/src/property/types/CloudWrapperInt.h index 73623abfc..3b4613340 100644 --- a/src/property/types/CloudWrapperInt.h +++ b/src/property/types/CloudWrapperInt.h @@ -22,6 +22,8 @@ INCLUDE ******************************************************************************/ +#include + #include #include "CloudWrapperBase.h" @@ -29,15 +31,16 @@ CLASS DECLARATION ******************************************************************************/ +template class CloudWrapperInt : public CloudWrapperBase { private: - int &_primitive_value, - _cloud_value, - _local_value; + T &_primitive_value, + _cloud_value, + _local_value; public: - CloudWrapperInt(int& v) : _primitive_value(v), _cloud_value(v), _local_value(v) {} + CloudWrapperInt(T& 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); + 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; @@ -59,5 +62,4 @@ class CloudWrapperInt : public CloudWrapperBase { } }; - #endif /* CLOUDWRAPPERINT_H_ */ 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/automation/CloudTelevision.h b/src/property/types/automation/CloudTelevision.h index 75967dd4f..d7c0c6d5f 100644 --- a/src/property/types/automation/CloudTelevision.h +++ b/src/property/types/automation/CloudTelevision.h @@ -22,6 +22,8 @@ INCLUDE ******************************************************************************/ +#include + #include #include "../../Property.h" @@ -116,7 +118,6 @@ class Television { InputValue inp; int cha; - Television(bool const swi, int const vol, bool const mut, PlaybackCommands const pbc, InputValue const inp, int const cha): swi(swi), vol(vol), mut(mut), pbc(pbc), inp(inp), cha(cha) { } @@ -145,7 +146,6 @@ class CloudTelevision : public Property { CloudTelevision(bool const swi, int const vol, bool const mut, PlaybackCommands const pbc, InputValue const inp, int const cha) : _value(swi, vol, mut, pbc, inp, cha), _cloud_value(swi, vol, mut, pbc, inp, cha) {} virtual bool isDifferentFromCloud() { - return _value != _cloud_value; } @@ -183,7 +183,7 @@ class CloudTelevision : public Property { } uint8_t getVolume() { - return _value.vol; + return static_cast(_value.vol); } void setMute(bool const mut) { diff --git a/src/utility/time/TimeService.cpp b/src/utility/time/TimeService.cpp index 05290b211..5d87a00d1 100644 --- a/src/utility/time/TimeService.cpp +++ b/src/utility/time/TimeService.cpp @@ -19,11 +19,11 @@ * INCLUDE **************************************************************************************/ -#include - #include + #include "TimeService.h" #include "NTPUtils.h" +#include "AIoTC_Config.h" #include "AIoTC_Const.h" #ifdef ARDUINO_ARCH_SAMD @@ -112,7 +112,7 @@ TimeServiceClass::TimeServiceClass() : _con_hdl(nullptr) , _is_rtc_configured(false) , _is_tz_configured(false) -, _timezone_offset(24 * 60 * 60) +, _timezone_offset(static_cast(24) * 60 * 60) , _timezone_dst_until(0) , _last_sync_tick(0) , _sync_interval_ms(TIMESERVICE_NTP_SYNC_TIMEOUT_ms) @@ -324,7 +324,7 @@ bool TimeServiceClass::isTimeValid(unsigned long const time) bool TimeServiceClass::isTimeZoneOffsetValid(long const offset) { /* UTC offset can go from +14 to -12 hours */ - return ((offset < (14 * 60 * 60)) && (offset > (-12 * 60 * 60))); + return ((offset < (static_cast(14) * 60 * 60)) && (offset > (static_cast(-12) * 60 * 60))); } void TimeServiceClass::initRTC()