diff --git a/extras/test/CMakeLists.txt b/extras/test/CMakeLists.txt index 9ded1d88a..ac113d2e8 100644 --- a/extras/test/CMakeLists.txt +++ b/extras/test/CMakeLists.txt @@ -46,6 +46,7 @@ set(TEST_SRCS set(TEST_UTIL_SRCS src/util/CBORTestUtil.cpp src/util/OTATestUtil.cpp + src/util/PropertyTestUtil.cpp ) set(TEST_DUT_SRCS diff --git a/extras/test/include/util/PropertyTestUtil.h b/extras/test/include/util/PropertyTestUtil.h new file mode 100644 index 000000000..62535122a --- /dev/null +++ b/extras/test/include/util/PropertyTestUtil.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +#ifndef PROPERTY_TEST_UTIL_H_ +#define PROPERTY_TEST_UTIL_H_ + +/************************************************************************************** + FUNCTION DECLARATION + **************************************************************************************/ + +extern "C" unsigned long getTime(); + +#endif /* PROPERTY_TEST_UTIL_H_ */ diff --git a/extras/test/src/test_addPropertyReal.cpp b/extras/test/src/test_addPropertyReal.cpp index 573f18802..1f97d172f 100644 --- a/extras/test/src/test_addPropertyReal.cpp +++ b/extras/test/src/test_addPropertyReal.cpp @@ -19,14 +19,14 @@ TEST CODE **************************************************************************************/ -SCENARIO("The same arduino cloud properties are added multiple times", "[ArduinoCloudThing::addPropertyReal]") { +SCENARIO("The same arduino cloud properties are added multiple times", "[ArduinoCloudThing::addPropertyToContainer]") { WHEN("The same bool property is added multiple times") { PropertyContainer property_container; CloudBool bool_property = false; - Property * bool_property_ptr_1 = &property_container.addPropertyReal(bool_property, "bool_property", Permission::ReadWrite); - Property * bool_property_ptr_2 = &property_container.addPropertyReal(bool_property, "bool_property", Permission::ReadWrite); + Property * bool_property_ptr_1 = &addPropertyToContainer(property_container, bool_property, "bool_property", Permission::ReadWrite); + Property * bool_property_ptr_2 = &addPropertyToContainer(property_container, bool_property, "bool_property", Permission::ReadWrite); THEN("No new property is added and the first added property is returned instead of a new one") { REQUIRE(bool_property_ptr_1 == bool_property_ptr_2); } @@ -39,8 +39,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino CloudInt int_property = 1; - Property * int_property_ptr_1 = &property_container.addPropertyReal(int_property, "int_property", Permission::ReadWrite); - Property * int_property_ptr_2 = &property_container.addPropertyReal(int_property, "int_property", Permission::ReadWrite); + 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); 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); @@ -54,8 +54,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino CloudFloat float_property = 1.0f; - Property * float_property_ptr_1 = &property_container.addPropertyReal(float_property, "float_property", Permission::ReadWrite); - Property * float_property_ptr_2 = &property_container.addPropertyReal(float_property, "float_property", Permission::ReadWrite); + Property * float_property_ptr_1 = &addPropertyToContainer(property_container, float_property, "float_property", Permission::ReadWrite); + Property * float_property_ptr_2 = &addPropertyToContainer(property_container, float_property, "float_property", Permission::ReadWrite); THEN("No new property is added and the first added property is returned instead of a new one") { REQUIRE(float_property_ptr_1 == float_property_ptr_2); @@ -69,8 +69,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino CloudString str_property; - Property * str_property_ptr_1 = &property_container.addPropertyReal(str_property, "str_property", Permission::ReadWrite); - Property * str_property_ptr_2 = &property_container.addPropertyReal(str_property, "str_property", Permission::ReadWrite); + Property * str_property_ptr_1 = &addPropertyToContainer(property_container, str_property, "str_property", Permission::ReadWrite); + Property * str_property_ptr_2 = &addPropertyToContainer(property_container, str_property, "str_property", Permission::ReadWrite); THEN("No new property is added and the first added property is returned instead of a new one") { REQUIRE(str_property_ptr_1 == str_property_ptr_2); diff --git a/extras/test/src/test_callback.cpp b/extras/test/src/test_callback.cpp index 2e8ce2557..1a345a37c 100644 --- a/extras/test/src/test_callback.cpp +++ b/extras/test/src/test_callback.cpp @@ -45,7 +45,7 @@ SCENARIO("A callback is registered via 'onUpdate' to be called on property chang thing.begin(&property_container); CloudInt test = 10; - property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(externalCallbackV2); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(externalCallbackV2); /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07}; @@ -75,7 +75,7 @@ SCENARIO("A (boolean) property is manipulated in the callback to its origin stat thing.begin(&property_container); cbor::encode(thing); - property_container.addPropertyReal(switch_turned_on, "switch_turned_on", Permission::ReadWrite).onUpdate(switch_callback); + addPropertyToContainer(property_container, switch_turned_on, "switch_turned_on", Permission::ReadWrite).onUpdate(switch_callback); /* [{0: "switch_turned_on", 4: true}] = 81 A2 00 70 73 77 69 74 63 68 5F 74 75 72 6E 65 64 5F 6F 6E 04 F5 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x70, 0x73, 0x77, 0x69, 0x74, 0x63, 0x68, 0x5F, 0x74, 0x75, 0x72, 0x6E, 0x65, 0x64, 0x5F, 0x6F, 0x6E, 0x04, 0xF5}; @@ -120,7 +120,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed ArduinoCloudThing thing; thing.begin(&property_container); - property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); test.setLastLocalChangeTimestamp(1550138809); @@ -148,7 +148,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed ArduinoCloudThing thing; thing.begin(&property_container); - property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); test = false; test.setLastLocalChangeTimestamp(1550138811); @@ -175,9 +175,9 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p ArduinoCloudThing thing; thing.begin(&property_container); - property_container.addPropertyReal(*p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + addPropertyToContainer(property_container, *p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); test = false; - property_container.updateTimestampOnLocallyChangedProperties(); + updateTimestampOnLocallyChangedProperties(property_container); //There is no RTC on test execution environment so we force the local timestamp p->setLastLocalChangeTimestamp(1550138809); @@ -206,9 +206,9 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p ArduinoCloudThing thing; thing.begin(&property_container); - property_container.addPropertyReal(*p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + addPropertyToContainer(property_container, *p, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); test = false; - property_container.updateTimestampOnLocallyChangedProperties(); + updateTimestampOnLocallyChangedProperties(property_container); //There is no RTC on test execution environment so we force the local timestamp p->setLastLocalChangeTimestamp(1550138811); @@ -234,7 +234,7 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl ArduinoCloudThing thing; thing.begin(&property_container); - property_container.addPropertyReal(location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); location_test.setLastLocalChangeTimestamp(1550138809); /* [{-3: 1550138810.00, 0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 82 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 68 74 65 73 74 3A 6C 61 74 02 02 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 03*/ @@ -266,7 +266,7 @@ SCENARIO("Object property: After a connection/reconnection an incoming cbor payl ArduinoCloudThing thing; thing.begin(&property_container); - property_container.addPropertyReal(location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); + addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(auto_sync_callback); location_test.setLastLocalChangeTimestamp(1550138811); /* [{-3: 1550138810.00, 0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 82 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 68 74 65 73 74 3A 6C 61 74 02 02 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 03*/ @@ -304,7 +304,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed ArduinoCloudThing thing; thing.begin(&property_container); - property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_device_sync_callback); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_device_sync_callback); /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; @@ -337,7 +337,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed ArduinoCloudThing thing; thing.begin(&property_container); - property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_cloud_sync_callback); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback).onSync(force_cloud_sync_callback); /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; @@ -364,7 +364,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed. ArduinoCloudThing thing; thing.begin(&property_container); - property_container.addPropertyReal(test, "test", Permission::ReadWrite).onUpdate(change_callback); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(change_callback); /* [{-3: 1550138810.00, 0: "test", 4: true}] = 81 A3 22 FB 41 D7 19 4F 6E 80 00 00 00 64 74 65 73 74 04 F5 */ uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x41, 0xD7, 0x19, 0x4F, 0x6E, 0x80, 0x00, 0x00, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; diff --git a/extras/test/src/test_decode.cpp b/extras/test/src/test_decode.cpp index a3e2cc2ad..e4093460e 100644 --- a/extras/test/src/test_decode.cpp +++ b/extras/test/src/test_decode.cpp @@ -40,7 +40,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudBool test = true; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 4: false}] = 81 A2 00 64 74 65 73 74 04 F4 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF4}; @@ -62,7 +62,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudBool test = true; /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ - property_container.addPropertyReal(test, "test", Permission::ReadWrite, 1); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite, 1); /* [{0: 1, 4: false}] = 81 A2 00 01 04 F4 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x01, 0x04, 0xF4}; @@ -82,7 +82,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudInt test = 0; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07}; @@ -97,7 +97,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudInt test = 0; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 2: -7}] = 81 A2 00 64 74 65 73 74 02 26 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x26}; @@ -117,7 +117,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudFloat test = 0.0f; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 2: 3.1459}] = 81 A2 00 64 74 65 73 74 02 FB 40 09 2A CD 9E 83 E4 26 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFB, 0x40, 0x09, 0x2A, 0xCD, 0x9E, 0x83, 0xE4, 0x26}; @@ -138,7 +138,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudString str_test; str_test = "test"; - property_container.addPropertyReal(str_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, str_test, "test", Permission::ReadWrite); /* [{0: "test", 3: "testtt"}] = 81 A2 00 64 74 65 73 74 03 66 74 65 73 74 74 74 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x03, 0x66, 0x74, 0x65, 0x73, 0x74, 0x74, 0x74}; @@ -157,7 +157,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudLocation location_test = CloudLocation(0, 1); - property_container.addPropertyReal(location_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite); /* [{0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 82 A2 00 68 74 65 73 74 3A 6C 61 74 02 02 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 03*/ uint8_t const payload[] = { 0x82, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0x02, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0x03 }; @@ -179,7 +179,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudColor color_test = CloudColor(0.0, 0.0, 0.0); - property_container.addPropertyReal(color_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); /* [{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ uint8_t const payload[] = {0x83, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; @@ -207,7 +207,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") 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*/ - property_container.addPropertyReal(color_test, "test", Permission::ReadWrite, 1); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite, 1); /* [{0: 257, 2: 2.0},{0: 513, 2: 2.0},{0: 769, 2: 2.0}] = 83 A2 00 19 01 01 02 FA 40 00 00 00 A2 00 19 02 01 02 FA 40 00 00 00 A2 00 19 03 01 02 FA 40 00 00 00 */ uint8_t const payload[] = {0x83, 0xA2, 0x00, 0x19, 0x01, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x02, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x03, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; @@ -233,7 +233,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudColoredLight color_test = CloudColoredLight(false, 0.0, 0.0, 0.0); - property_container.addPropertyReal(color_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; @@ -261,7 +261,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudTelevision tv_test = CloudTelevision(false, 0, false, PlaybackCommands::Stop, InputValue::AUX1, 0); - property_container.addPropertyReal(tv_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, tv_test, "test", Permission::ReadWrite); /* [{0: "test:swi", 4: true},{0: "test:vol", 2: 50},{0: "test:mut", 2: false},{0: "test:pbc", 2: 3},{0: "test:inp", 2: 55},{0: "test:cha", 2: 7}] = 9F A2 00 68 74 65 73 74 3A 73 77 69 04 F5 A2 00 68 74 65 73 74 3A 76 6F 6C 02 18 32 A2 00 68 74 65 73 74 3A 6D 75 74 04 F4 A2 00 68 74 65 73 74 3A 70 62 63 02 03 A2 00 68 74 65 73 74 3A 69 6E 70 02 18 37 A2 00 68 74 65 73 74 3A 63 68 61 02 07 FF */ uint8_t const payload[] = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x76, 0x6F, 0x6C, 0x02, 0x18, 0x32, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6D, 0x75, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x70, 0x62, 0x63, 0x02, 0x03, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x69, 0x6E, 0x70, 0x02, 0x18, 0x37, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x63, 0x68, 0x61, 0x02, 0x07, 0xFF}; @@ -290,7 +290,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudDimmedLight light_test = CloudDimmedLight(false, 0.0); - property_container.addPropertyReal(light_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, light_test, "test", Permission::ReadWrite); /* [{0: "test:swi", 4: true},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ uint8_t const payload[] = {0x82, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00}; @@ -316,7 +316,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudLight light_test; light_test = false; - property_container.addPropertyReal(light_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, light_test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; @@ -337,7 +337,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudContactSensor contact_test; contact_test = false; - property_container.addPropertyReal(contact_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, contact_test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; @@ -358,7 +358,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudMotionSensor motion_test; motion_test = false; - property_container.addPropertyReal(motion_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, motion_test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; @@ -379,7 +379,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudSmartPlug plug_test; plug_test = false; - property_container.addPropertyReal(plug_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, plug_test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; @@ -400,7 +400,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudSwitch switch_test; switch_test = false; - property_container.addPropertyReal(switch_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, switch_test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; @@ -420,7 +420,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudTemperature test; test = 0.0f; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 2: 3.1459}] = 81 A2 00 64 74 65 73 74 02 FB 40 09 2A CD 9E 83 E4 26 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFB, 0x40, 0x09, 0x2A, 0xCD, 0x9E, 0x83, 0xE4, 0x26}; @@ -446,10 +446,10 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudString str_test; str_test = ("str_test"); - property_container.addPropertyReal(bool_test, "bool_test", Permission::ReadWrite); - property_container.addPropertyReal(int_test, "int_test", Permission::ReadWrite); - property_container.addPropertyReal(float_test, "float_test", Permission::ReadWrite); - property_container.addPropertyReal(str_test, "str_test", Permission::ReadWrite); + addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite); + addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite); + addPropertyToContainer(property_container, float_test, "float_test", Permission::ReadWrite); + addPropertyToContainer(property_container, str_test, "str_test", Permission::ReadWrite); /* [{0: "bool_test", 4: true}, {0: "int_test", 2: 10}, {0: "float_test", 2: 20.0}, {0: "str_test", 3: "hello arduino"}] = 84 A2 00 69 62 6F 6F 6C 5F 74 65 73 74 04 F5 A2 00 68 69 6E 74 5F 74 65 73 74 02 0A A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 F9 4D 00 A2 00 68 73 74 72 5F 74 65 73 74 03 6D 68 65 6C 6C 6F 20 61 72 64 75 69 6E 6F @@ -476,10 +476,10 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") CloudString str_test; str_test = ("str_test"); - property_container.addPropertyReal(bool_test, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS); - property_container.addPropertyReal(int_test, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS); - property_container.addPropertyReal(float_test, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS); - property_container.addPropertyReal(str_test, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, float_test, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, str_test, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS); /* [{0: "bool_test", 4: true}, {0: "int_test", 2: 10}, {0: "float_test", 2: 20.0}, {0: "str_test", 3: "hello arduino"}] = 84 A2 00 69 62 6F 6F 6C 5F 74 65 73 74 04 F5 A2 00 68 69 6E 74 5F 74 65 73 74 02 0A A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 F9 4D 00 A2 00 68 73 74 72 5F 74 65 73 74 03 6D 68 65 6C 6C 6F 20 61 72 64 75 69 6E 6F @@ -511,12 +511,12 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") std::unique_ptr f(new CloudWrapperFloat(float_test)); std::unique_ptr s(new CloudWrapperString(str_test)); - property_container.addPropertyReal(*b, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS); - property_container.addPropertyReal(*i, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS); - property_container.addPropertyReal(*f, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS); - property_container.addPropertyReal(*s, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, *b, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, *i, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, *f, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS); + addPropertyToContainer(property_container, *s, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS); - property_container.updateTimestampOnLocallyChangedProperties(); + updateTimestampOnLocallyChangedProperties(property_container); /* [{0: "bool_test", 4: true}, {0: "int_test", 2: 10}, {0: "float_test", 2: 20.0}, {0: "str_test", 3: "hello arduino"}] = 84 A2 00 69 62 6F 6F 6C 5F 74 65 73 74 04 F5 A2 00 68 69 6E 74 5F 74 65 73 74 02 0A A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 F9 4D 00 A2 00 68 73 74 72 5F 74 65 73 74 03 6D 68 65 6C 6C 6F 20 61 72 64 75 69 6E 6F @@ -542,10 +542,10 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") str_3("cloud"), str_4("test"); - property_container.addPropertyReal(str_1, "str_1", Permission::ReadWrite); - property_container.addPropertyReal(str_2, "str_2", Permission::ReadWrite); - property_container.addPropertyReal(str_3, "str_3", Permission::ReadWrite); - property_container.addPropertyReal(str_4, "str_4", Permission::ReadWrite); + addPropertyToContainer(property_container, str_1, "str_1", Permission::ReadWrite); + addPropertyToContainer(property_container, str_2, "str_2", Permission::ReadWrite); + addPropertyToContainer(property_container, str_3, "str_3", Permission::ReadWrite); + addPropertyToContainer(property_container, str_4, "str_4", Permission::ReadWrite); /* [{0: "str_1", 3: "I'd like"}, {0: "str_2", 3: "a"}, {0: "str_3", 3: "cup"}, {0: "str_4", 3: "of coffee"}] = 84 A2 00 65 73 74 72 5F 31 03 68 49 27 64 20 6C 69 6B 65 A2 00 65 73 74 72 5F 32 03 61 61 A2 00 65 73 74 72 5F 33 03 63 63 75 70 A2 00 65 73 74 72 5F 34 03 69 6F 66 20 63 6F 66 66 65 65 @@ -570,7 +570,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudString str = "hello"; - property_container.addPropertyReal(str, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, str, "test", Permission::ReadWrite); /* [{-2: "some-test-base-name", 0: "test", 3: "test"}] = 81 A3 21 73 73 6F 6D 65 2D 74 65 73 74 2D 62 61 73 65 2D 6E 61 6D 65 00 64 74 65 73 74 03 64 74 65 73 74 */ uint8_t const payload[] = {0x81, 0xA3, 0x21, 0x73, 0x73, 0x6F, 0x6D, 0x65, 0x2D, 0x74, 0x65, 0x73, 0x74, 0x2D, 0x62, 0x61, 0x73, 0x65, 0x2D, 0x6E, 0x61, 0x6D, 0x65, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x03, 0x64, 0x74, 0x65, 0x73, 0x74}; @@ -589,7 +589,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudInt test = 0; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + 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 */ uint8_t const payload[] = {0x81, 0xA3, 0x22, 0xFB, 0x40, 0x5E, 0xDD, 0x2F, 0x1A, 0x9F, 0xBE, 0x77, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; @@ -608,7 +608,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudInt test = 0; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + 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 */ uint8_t const payload[] = {0x81, 0xA3, 0x06, 0xFB, 0x40, 0x5E, 0xDD, 0x2F, 0x1A, 0x9F, 0xBE, 0x77, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; @@ -627,7 +627,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudInt test = 0; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + 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 */ uint8_t const payload[] = {0x81, 0xA3, 0x20, 0x01, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; @@ -646,7 +646,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudInt test = 0; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{-2: "base-name", -3: 654.321, 6: 123.456, 0: "test", 2: 1}] = 81 A5 21 69 62 61 73 65 2D 6E 61 6D 65 22 FB 40 84 72 91 68 72 B0 21 06 FB 40 5E DD 2F 1A 9F BE 77 00 64 74 65 73 74 02 01 @@ -667,7 +667,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") thing.begin(&property_container); CloudInt test = 0; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + 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 */ uint8_t const payload[] = {0x81, 0xA3, 0x18, 0x7B, 0x18, 0x7B, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x01}; diff --git a/extras/test/src/test_encode.cpp b/extras/test/src/test_encode.cpp index b26def000..3302d9f01 100644 --- a/extras/test/src/test_encode.cpp +++ b/extras/test/src/test_encode.cpp @@ -32,7 +32,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") cbor::encode(thing); CloudBool test = true; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; @@ -53,7 +53,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudBool test = true; /*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/ - property_container.addPropertyReal(test, "test", Permission::ReadWrite, 1); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite, 1); /* [{0: 1, 4: true}] = 9F A2 00 01 04 F5 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x01, 0x04, 0xF5, 0xFF}; @@ -72,7 +72,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") cbor::encode(thing); CloudInt int_test = 123; - property_container.addPropertyReal(int_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, int_test, "test", Permission::ReadWrite); /* [{0: "test", 3: 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}; @@ -91,7 +91,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") cbor::encode(thing); CloudFloat float_test = 3.14159; - property_container.addPropertyReal(float_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, float_test, "test", Permission::ReadWrite); /* [{0: "test", 2: 3.141590118408203}] = 9F A2 00 64 74 65 73 74 02 FA 40 49 0F D0 FF */ std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x49, 0x0F, 0xD0, 0xFF}; @@ -111,7 +111,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudString string_test; string_test = "test"; - property_container.addPropertyReal(string_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, string_test, "test", Permission::ReadWrite); /* [{0: "test", 3: "test"}] = 9F A2 00 64 74 65 73 74 03 64 74 65 73 74 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x03, 0x64, 0x74, 0x65, 0x73, 0x74, 0xFF}; @@ -130,7 +130,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") cbor::encode(thing); CloudLocation location_test = CloudLocation(2.0f, 3.0f); - property_container.addPropertyReal(location_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite); /* [{0: "test:lat", 3: 2},{0: "test:lon", 3: 3}] = 9F A2 00 68 74 65 73 74 3A 6C 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 6C 6F 6E 02 FA 40 40 00 00 FF*/ std::vector const expected = { 0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6C, 0x6F, 0x6E, 0x02, 0xFA, 0x40, 0x40, 0x00, 0x00, 0xFF }; @@ -149,7 +149,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") cbor::encode(thing); CloudColor color_test = CloudColor(2.0, 2.0, 2.0); - property_container.addPropertyReal(color_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); /* [{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 9F A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; @@ -170,7 +170,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudColor color_test = CloudColor(2.0, 2.0, 2.0); /*The property is added with identifier 1 that will be used instead of the string "name" as property identifier */ - property_container.addPropertyReal(color_test, "test", Permission::ReadWrite, 1); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite, 1); /* [{0: 257, 2: 2.0},{0: 513, 2: 2.0},{0: 769, 2: 2.0}] = 9F A2 00 19 01 01 02 FA 40 00 00 00 A2 00 19 02 01 02 FA 40 00 00 00 A2 00 19 03 01 02 FA 40 00 00 00 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x19, 0x01, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x02, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x19, 0x03, 0x01, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; @@ -189,7 +189,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") cbor::encode(thing); CloudColoredLight color_test = CloudColoredLight(true, 2.0, 2.0, 2.0); - property_container.addPropertyReal(color_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; @@ -208,7 +208,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") cbor::encode(thing); CloudTelevision tv_test = CloudTelevision(true, 50, false, PlaybackCommands::Play, InputValue::TV, 7); - property_container.addPropertyReal(tv_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, tv_test, "test", Permission::ReadWrite); /* [{0: "test:swi", 4: true},{0: "test:vol", 2: 50},{0: "test:mut", 2: false},{0: "test:pbc", 2: 3},{0: "test:inp", 2: 55},{0: "test:cha", 2: 7}] = 9F A2 00 68 74 65 73 74 3A 73 77 69 04 F5 A2 00 68 74 65 73 74 3A 76 6F 6C 02 18 32 A2 00 68 74 65 73 74 3A 6D 75 74 04 F4 A2 00 68 74 65 73 74 3A 70 62 63 02 03 A2 00 68 74 65 73 74 3A 69 6E 70 02 18 37 A2 00 68 74 65 73 74 3A 63 68 61 02 07 FF */ std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x76, 0x6F, 0x6C, 0x02, 0x18, 0x32, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x6D, 0x75, 0x74, 0x04, 0xF4, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x70, 0x62, 0x63, 0x02, 0x03, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x69, 0x6E, 0x70, 0x02, 0x18, 0x37, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x63, 0x68, 0x61, 0x02, 0x07, 0xFF}; @@ -227,7 +227,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") cbor::encode(thing); CloudDimmedLight color_test = CloudDimmedLight(true, 2.0); - property_container.addPropertyReal(color_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite); /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 0.0},{0: "test:sat", 2: 0.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 00 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 00 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xFF }; @@ -247,7 +247,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudLight test; test = true; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; @@ -267,7 +267,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudContactSensor test; test = true; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; @@ -287,7 +287,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudMotionSensor test; test = true; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; @@ -307,7 +307,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudSmartPlug test; test = true; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; @@ -327,7 +327,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudTemperature float_test; float_test = 3.14159; - property_container.addPropertyReal(float_test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, float_test, "test", Permission::ReadWrite); /* [{0: "test", 2: 3.141590118408203}] = 9F A2 00 64 74 65 73 74 02 FA 40 49 0F D0 FF */ std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFA, 0x40, 0x49, 0x0F, 0xD0, 0xFF}; @@ -347,7 +347,7 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudSwitch test; test = true; - property_container.addPropertyReal(test, "test", Permission::ReadWrite); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite); /* [{0: "test", 4: true}] = 9F A2 00 64 74 65 73 74 04 F5 FF*/ std::vector const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5, 0xFF}; @@ -370,10 +370,10 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") CloudString str_test; str_test = "str_test"; - property_container.addPropertyReal(int_test, "int_test", Permission::ReadWrite); - property_container.addPropertyReal(bool_test, "bool_test", Permission::ReadWrite); - property_container.addPropertyReal(float_test, "float_test", Permission::ReadWrite); - property_container.addPropertyReal(str_test, "str_test", Permission::ReadWrite); + addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite); + addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite); + addPropertyToContainer(property_container, float_test, "float_test", Permission::ReadWrite); + addPropertyToContainer(property_container, str_test, "str_test", Permission::ReadWrite); /* [{0: "int_test", 2: 1}, {0: "bool_test", 4: false}, {0: "float_test", 2: 2.0}, {0: "str_test", 3: "str_test"}] = 9F A2 00 68 69 6E 74 5F 74 65 73 74 02 01 A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA 40 00 00 00 A2 00 68 73 74 72 5F 74 65 73 74 03 68 73 74 72 5F 74 65 73 74 FF @@ -403,12 +403,12 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") std::unique_ptr f(new CloudWrapperFloat(float_test)); std::unique_ptr s(new CloudWrapperString(str_test)); - property_container.addPropertyReal(*i, "int_test", Permission::ReadWrite); - property_container.addPropertyReal(*b, "bool_test", Permission::ReadWrite); - property_container.addPropertyReal(*f, "float_test", Permission::ReadWrite); - property_container.addPropertyReal(*s, "str_test", Permission::ReadWrite); + addPropertyToContainer(property_container, *i, "int_test", Permission::ReadWrite); + addPropertyToContainer(property_container, *b, "bool_test", Permission::ReadWrite); + addPropertyToContainer(property_container, *f, "float_test", Permission::ReadWrite); + addPropertyToContainer(property_container, *s, "str_test", Permission::ReadWrite); - property_container.updateTimestampOnLocallyChangedProperties(); + updateTimestampOnLocallyChangedProperties(property_container); /* [{0: "int_test", 2: 1}, {0: "bool_test", 4: false}, {0: "float_test", 2: 2.0}, {0: "str_test", 3: "str_test"}] = 9F A2 00 68 69 6E 74 5F 74 65 73 74 02 01 A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA A2 00 6A 66 6C 6F 61 74 5F 74 65 73 74 02 FA 40 00 00 00 A2 00 68 73 74 72 5F 74 65 73 74 03 68 73 74 72 5F 74 65 73 74 FF diff --git a/extras/test/src/test_publishEvery.cpp b/extras/test/src/test_publishEvery.cpp index 5bea3eb08..594f0bf36 100644 --- a/extras/test/src/test_publishEvery.cpp +++ b/extras/test/src/test_publishEvery.cpp @@ -26,7 +26,7 @@ SCENARIO("A Arduino cloud property is published periodically", "[ArduinoCloudThi CloudBool test = true; unsigned long const PUBLISH_INTERVAL_SEC = 1 * SECONDS; - property_container.addPropertyReal(test, "test", Permission::ReadWrite).publishEvery(PUBLISH_INTERVAL_SEC); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishEvery(PUBLISH_INTERVAL_SEC); WHEN("t = 0 ms, publish interval = 1000 ms, 1st call to 'encode'") { set_millis(0); diff --git a/extras/test/src/test_publishOnChange.cpp b/extras/test/src/test_publishOnChange.cpp index b549d5dd0..5f14bcd49 100644 --- a/extras/test/src/test_publishOnChange.cpp +++ b/extras/test/src/test_publishOnChange.cpp @@ -26,7 +26,7 @@ SCENARIO("A Arduino cloud property is published on value change", "[ArduinoCloud CloudInt test = 10; int const DELTA = 6; - property_container.addPropertyReal(test, "test", Permission::ReadWrite).publishOnChange(DELTA); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishOnChange(DELTA); WHEN("test = 10, delta = 6, the property is encoded for the 1st time") { THEN("The property should be encoded") { diff --git a/extras/test/src/test_publishOnChangeRateLimit.cpp b/extras/test/src/test_publishOnChangeRateLimit.cpp index cf22ac2bf..386affe07 100644 --- a/extras/test/src/test_publishOnChangeRateLimit.cpp +++ b/extras/test/src/test_publishOnChangeRateLimit.cpp @@ -27,7 +27,7 @@ SCENARIO("A Arduino cloud property is published on value change but the update r int const MIN_DELTA = 0; unsigned long const MIN_TIME_BETWEEN_UPDATES_ms = 500; /* No updates faster than 500 ms */ - property_container.addPropertyReal(test, "test", Permission::ReadWrite).publishOnChange(MIN_DELTA, MIN_TIME_BETWEEN_UPDATES_ms); + addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishOnChange(MIN_DELTA, MIN_TIME_BETWEEN_UPDATES_ms); WHEN("t = 0 ms, min time between updates = 500 ms, property not modified, 1st call to 'encode'") { set_millis(0); diff --git a/extras/test/src/test_readOnly.cpp b/extras/test/src/test_readOnly.cpp index e06969168..a9963eb58 100644 --- a/extras/test/src/test_readOnly.cpp +++ b/extras/test/src/test_readOnly.cpp @@ -24,7 +24,7 @@ SCENARIO("A Arduino cloud property is marked 'read only'", "[ArduinoCloudThing:: thing.begin(&property_container); CloudInt test = 0; - property_container.addPropertyReal(test, "test", Permission::Read); + addPropertyToContainer(property_container, test, "test", Permission::Read); /* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */ uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07}; diff --git a/extras/test/src/test_writeOnly.cpp b/extras/test/src/test_writeOnly.cpp index fcef2458c..d041e6836 100644 --- a/extras/test/src/test_writeOnly.cpp +++ b/extras/test/src/test_writeOnly.cpp @@ -23,7 +23,7 @@ SCENARIO("A Arduino cloud property is marked 'write only'", "[ArduinoCloudThing: thing.begin(&property_container); CloudInt test = 0; - property_container.addPropertyReal(test, "test", Permission::Write); + addPropertyToContainer(property_container, test, "test", Permission::Write); REQUIRE(cbor::encode(thing).size() == 0); /* Since 'test' is 'write only' it should not be encoded */ diff --git a/extras/test/src/util/PropertyTestUtil.cpp b/extras/test/src/util/PropertyTestUtil.cpp new file mode 100644 index 000000000..35717a385 --- /dev/null +++ b/extras/test/src/util/PropertyTestUtil.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + FUNCTION DEFINITION + **************************************************************************************/ + +unsigned long getTime() +{ + return 0; +} diff --git a/src/ArduinoIoTCloud.cpp b/src/ArduinoIoTCloud.cpp index 41bdfbc32..98f5c7145 100644 --- a/src/ArduinoIoTCloud.cpp +++ b/src/ArduinoIoTCloud.cpp @@ -27,7 +27,19 @@ void ArduinoIoTCloudClass::push() { - _property_container.requestUpdateForAllProperties(); + requestUpdateForAllProperties(_property_container); +} + +bool ArduinoIoTCloudClass::setTimestamp(String const & prop_name, unsigned long const timestamp) +{ + Property * p = getProperty(_property_container, prop_name); + + if (p == nullptr) + return false; + + p->setTimestamp(timestamp); + + return true; } void ArduinoIoTCloudClass::addCallback(ArduinoIoTCloudEvent const event, OnCloudEventCallback callback) @@ -52,9 +64,9 @@ void ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, int } if (seconds == ON_CHANGE) { - _property_container.addPropertyReal(property, name, permission, tag).publishOnChange(minDelta, DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate(fn).onSync(synFn); + addPropertyToContainer(_property_container, property, name, permission, tag).publishOnChange(minDelta, DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate(fn).onSync(synFn); } else { - _property_container.addPropertyReal(property, name, permission, tag).publishEvery(seconds).onUpdate(fn).onSync(synFn); + addPropertyToContainer(_property_container, property, name, permission, tag).publishEvery(seconds).onUpdate(fn).onSync(synFn); } } @@ -77,7 +89,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, Per Property& ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, int tag, Permission const permission) { Property* p = new CloudWrapperBool(property); - return _property_container.addPropertyReal(*p, name, permission, tag); + return addPropertyToContainer(_property_container, *p, name, permission, tag); } void ArduinoIoTCloudClass::addPropertyReal(float& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) @@ -99,7 +111,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(float& property, String name, Pe Property& ArduinoIoTCloudClass::addPropertyReal(float& property, String name, int tag, Permission const permission) { Property* p = new CloudWrapperFloat(property); - return _property_container.addPropertyReal(*p, name, permission, tag); + return addPropertyToContainer(_property_container, *p, name, permission, tag); } void ArduinoIoTCloudClass::addPropertyReal(int& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) @@ -121,7 +133,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(int& property, String name, Perm Property& ArduinoIoTCloudClass::addPropertyReal(int& property, String name, int tag, Permission const permission) { Property* p = new CloudWrapperInt(property); - return _property_container.addPropertyReal(*p, name, permission, tag); + return addPropertyToContainer(_property_container, *p, name, permission, tag); } void ArduinoIoTCloudClass::addPropertyReal(String& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property)) @@ -143,7 +155,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(String& property, String name, P Property& ArduinoIoTCloudClass::addPropertyReal(String& property, String name, int tag, Permission const permission) { Property* p = new CloudWrapperString(property); - return _property_container.addPropertyReal(*p, name, permission, tag); + return addPropertyToContainer(_property_container, *p, name, permission, tag); } /****************************************************************************** diff --git a/src/ArduinoIoTCloud.h b/src/ArduinoIoTCloud.h index c0ca4e5ed..58f73b0d7 100644 --- a/src/ArduinoIoTCloud.h +++ b/src/ArduinoIoTCloud.h @@ -88,6 +88,7 @@ class ArduinoIoTCloudClass virtual void printDebugInfo() = 0; void push(); + bool setTimestamp(String const & prop_name, unsigned long const timestamp); inline void setThingId (String const thing_id) { _thing_id = thing_id; }; inline String & getThingId () { return _thing_id; }; diff --git a/src/ArduinoIoTCloudLPWAN.cpp b/src/ArduinoIoTCloudLPWAN.cpp index dd15ef826..3cc166a72 100644 --- a/src/ArduinoIoTCloudLPWAN.cpp +++ b/src/ArduinoIoTCloudLPWAN.cpp @@ -63,7 +63,7 @@ int ArduinoIoTCloudLPWAN::begin(ConnectionHandler& connection, bool retry) void ArduinoIoTCloudLPWAN::update() { // Check if a primitive property wrapper is locally changed - _property_container.updateTimestampOnLocallyChangedProperties(); + updateTimestampOnLocallyChangedProperties(_property_container); ArduinoIoTConnectionStatus next_iot_status = _iot_status; diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 80688305f..92bf39570 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -50,7 +50,7 @@ const static int CONNECT_FAILURE_SUBSCRIBE = -1; LOCAL MODULE FUNCTIONS ******************************************************************************/ -static unsigned long getTime() +extern "C" unsigned long getTime() { return time_service.getTime(); } @@ -135,7 +135,6 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) _ota_topic_in = getTopic_ota_in(); _thing.begin(&_property_container); - _property_container.begin(getTime); printConnectionStatus(_iot_status); @@ -154,7 +153,7 @@ void ArduinoIoTCloudTCP::update() #endif /* OTA_ENABLED */ // Check if a primitive property wrapper is locally changed - _property_container.updateTimestampOnLocallyChangedProperties(); + updateTimestampOnLocallyChangedProperties(_property_container); if(checkPhyConnection() != NetworkConnectionState::CONNECTED) return; if(checkCloudConnection() != ArduinoIoTConnectionStatus::CONNECTED) return; diff --git a/src/cbor/ArduinoCloudThing.cpp b/src/cbor/ArduinoCloudThing.cpp index ad85cb552..dc92c66b5 100644 --- a/src/cbor/ArduinoCloudThing.cpp +++ b/src/cbor/ArduinoCloudThing.cpp @@ -60,7 +60,7 @@ int ArduinoCloudThing::encode(uint8_t * data, size_t const size, bool lightPaylo return -1; } - if (_property_container->appendChangedProperties(&arrayEncoder, lightPayload) < 1) { + if (appendChangedProperties(*_property_container, &arrayEncoder, lightPayload) < 1) { return -1; } @@ -398,7 +398,7 @@ void ArduinoCloudThing::freeMapDataList(std::list * map_data_list } void ArduinoCloudThing::updateProperty(String propertyName, unsigned long cloudChangeEventTime) { - Property* property = _property_container->getProperty(propertyName); + Property* property = getProperty(*_property_container, propertyName); if (property && property->isWriteableByCloud()) { property->setLastCloudChangeTimestamp(cloudChangeEventTime); property->setAttributesFromCloud(&_map_data_list); @@ -415,9 +415,9 @@ void ArduinoCloudThing::updateProperty(String propertyName, unsigned long cloudC String ArduinoCloudThing::getPropertyNameByIdentifier(int propertyIdentifier) { Property* property; if (propertyIdentifier > 255) { - property = _property_container->getProperty(propertyIdentifier & 255); + property = getProperty(*_property_container, propertyIdentifier & 255); } else { - property = _property_container->getProperty(propertyIdentifier); + property = getProperty(*_property_container, propertyIdentifier); } return property->name(); } diff --git a/src/property/Property.cpp b/src/property/Property.cpp index 72fdddf2f..f5e187946 100644 --- a/src/property/Property.cpp +++ b/src/property/Property.cpp @@ -45,7 +45,11 @@ Property::Property() _identifier(0), _attributeIdentifier(0), _lightPayload(false), - _update_requested(false) { + _update_requested(false), + _encode_timestamp(false), + _timestamp(0) +{ + } /****************************************************************************** @@ -85,6 +89,17 @@ Property & Property::publishOnDemand() { return (*this); } +Property & Property::encodeTimestamp() +{ + _encode_timestamp = true; + return (*this); +} + +void Property::setTimestamp(unsigned long const timestamp) +{ + _timestamp = timestamp; +} + bool Property::shouldBeUpdated() { if (!_has_been_updated_once) { return true; @@ -170,7 +185,8 @@ void Property::appendAttributeName(String attributeName, std::function(CborIntegerMapKey::Name)); // if _lightPayload is true, the property and attribute identifiers will be encoded instead of the property name @@ -187,7 +203,15 @@ void Property::appendAttributeName(String attributeName, std::function(CborIntegerMapKey::Time)); + cbor_encode_uint(&mapEncoder, _timestamp); + } + /* Close the container */ cbor_encoder_close_container(encoder, &mapEncoder); } diff --git a/src/property/Property.h b/src/property/Property.h index a5da5a1f1..fa4423d3f 100644 --- a/src/property/Property.h +++ b/src/property/Property.h @@ -139,6 +139,7 @@ class Property { Property & publishOnChange(float const min_delta_property, unsigned long const min_time_between_updates_millis = 0); Property & publishEvery(unsigned long const seconds); Property & publishOnDemand(); + Property & encodeTimestamp(); inline String name() const { return _name; @@ -153,6 +154,7 @@ class Property { return (_permission == Permission::Write) || (_permission == Permission::ReadWrite); } + void setTimestamp(unsigned long const timestamp); bool shouldBeUpdated(); void requestUpdate(); void execCallbackOnChange(); @@ -215,6 +217,9 @@ class Property { bool _lightPayload; /* Indicates whether a property update has been requested in case of the OnDemand update policy. */ bool _update_requested; + /* Indicates whether the timestamp shall be encoded in the property or not */ + bool _encode_timestamp; + unsigned long _timestamp; }; /****************************************************************************** diff --git a/src/property/PropertyContainer.cpp b/src/property/PropertyContainer.cpp index 07f07bdf7..f0ef98838 100644 --- a/src/property/PropertyContainer.cpp +++ b/src/property/PropertyContainer.cpp @@ -25,82 +25,63 @@ #include "types/CloudWrapperBase.h" -/****************************************************************************** - CTOR/DTOR - ******************************************************************************/ - -PropertyContainer::PropertyContainer() -: _numProperties{0} -, _numPrimitivesProperties{0} -, _get_time_func{nullptr} -{ - -} - /****************************************************************************** PUBLIC MEMBER FUNCTIONS ******************************************************************************/ -void PropertyContainer::begin(GetTimeCallbackFunc func) -{ - _get_time_func = func; -} - -Property & PropertyContainer::addPropertyReal(Property & property, String const & name, Permission const permission, int propertyIdentifier) +Property & addPropertyToContainer(PropertyContainer & prop_cont, Property & property, String const & name, Permission const permission, int propertyIdentifier, GetTimeCallbackFunc func) { /* Check whether or not the property already has been added to the container */ - Property * p = getProperty(name); + Property * p = getProperty(prop_cont, name); if(p != nullptr) return (*p); /* Initialize property and add it to the container */ - property.init(name, permission, _get_time_func); + property.init(name, permission, func); - if (property.isPrimitive()) { _numPrimitivesProperties++; } - _numProperties++; - addProperty(&property, propertyIdentifier); + addProperty(prop_cont, &property, propertyIdentifier); return property; } -Property * PropertyContainer::getProperty(String const & name) +Property * getProperty(PropertyContainer & prop_cont, String const & name) { std::list::iterator iter; - iter = std::find_if(_property_list.begin(), - _property_list.end(), + iter = std::find_if(prop_cont.begin(), + prop_cont.end(), [name](Property * p) -> bool { return (p->name() == name); }); - if (iter == _property_list.end()) + if (iter == prop_cont.end()) return nullptr; else return (*iter); } -Property * PropertyContainer::getProperty(int const identifier) +Property * getProperty(PropertyContainer & prop_cont, int const identifier) { std::list::iterator iter; - iter = std::find_if(_property_list.begin(), - _property_list.end(), + iter = std::find_if(prop_cont.begin(), + prop_cont.end(), [identifier](Property * p) -> bool { return (p->identifier() == identifier); }); - if (iter == _property_list.end()) + if (iter == prop_cont.end()) return nullptr; else return (*iter); } -int PropertyContainer::appendChangedProperties(CborEncoder * arrayEncoder, bool lightPayload) +int appendChangedProperties(PropertyContainer & prop_cont, CborEncoder * arrayEncoder, bool lightPayload) { int appendedProperties = 0; - std::for_each(_property_list.begin(), - _property_list.end(), + std::for_each(prop_cont.begin(), + prop_cont.end(), [arrayEncoder, lightPayload, &appendedProperties](Property * p) { if (p->shouldBeUpdated() && p->isReadableByCloud()) @@ -112,41 +93,38 @@ int PropertyContainer::appendChangedProperties(CborEncoder * arrayEncoder, bool return appendedProperties; } -void PropertyContainer::requestUpdateForAllProperties() +void requestUpdateForAllProperties(PropertyContainer & prop_cont) { - std::for_each(_property_list.begin(), - _property_list.end(), + std::for_each(prop_cont.begin(), + prop_cont.end(), [](Property * p) { p->requestUpdate(); }); } -void PropertyContainer::updateTimestampOnLocallyChangedProperties() +void updateTimestampOnLocallyChangedProperties(PropertyContainer & prop_cont) { /* This function updates the timestamps on the primitive properties * that have been modified locally since last cloud synchronization */ - if (_numPrimitivesProperties > 0) - { - std::for_each(_property_list.begin(), - _property_list.end(), - [](Property * p) + std::for_each(prop_cont.begin(), + prop_cont.end(), + [](Property * p) + { + CloudWrapperBase * pbase = reinterpret_cast(p); + if (pbase->isPrimitive() && pbase->isChangedLocally() && pbase->isReadableByCloud()) { - CloudWrapperBase * pbase = reinterpret_cast(p); - if (pbase->isPrimitive() && pbase->isChangedLocally() && pbase->isReadableByCloud()) - { - p->updateLocalTimestamp(); - } - }); - } + p->updateLocalTimestamp(); + } + }); } /****************************************************************************** PRIVATE MEMBER FUNCTIONS ******************************************************************************/ -void PropertyContainer::addProperty(Property * property_obj, int propertyIdentifier) +void addProperty(PropertyContainer & prop_cont, Property * property_obj, int propertyIdentifier) { if (propertyIdentifier != -1) { @@ -155,7 +133,7 @@ void PropertyContainer::addProperty(Property * property_obj, int propertyIdentif /* If property identifier is -1, an incremental value will be assigned as identifier. */ else { - property_obj->setIdentifier(_numProperties); + property_obj->setIdentifier(prop_cont.size() + 1); /* This is in order to stay compatible to the old system of first increasing _numProperties and then assigning it here. */ } - _property_list.push_back(property_obj); + prop_cont.push_back(property_obj); } diff --git a/src/property/PropertyContainer.h b/src/property/PropertyContainer.h index ae3aaa4b2..d7852dd6e 100644 --- a/src/property/PropertyContainer.h +++ b/src/property/PropertyContainer.h @@ -29,42 +29,41 @@ #include /****************************************************************************** - CLASS DECLARATION + DECLARATION OF getTime ******************************************************************************/ -class PropertyContainer -{ +#ifdef HAS_LORA +static unsigned long constexpr getTime() { return 0; } +#else +extern "C" unsigned long getTime(); +#endif -public: - - PropertyContainer(); +/****************************************************************************** + TYPEDEF + ******************************************************************************/ - - void begin(GetTimeCallbackFunc func); +typedef std::list PropertyContainer; +/****************************************************************************** + FUNCTION DECLARATION + ******************************************************************************/ - Property & addPropertyReal(Property & property, String const & name, Permission const permission, int propertyIdentifier = -1); +Property & addPropertyToContainer(PropertyContainer & prop_cont, + Property & property, + String const & name, + Permission const permission, + int propertyIdentifier = -1, + GetTimeCallbackFunc func = getTime); - Property * getProperty (String const & name); - Property * getProperty (int const identifier); - - - int appendChangedProperties(CborEncoder * arrayEncoder, bool lightPayload); - void updateTimestampOnLocallyChangedProperties(); - void requestUpdateForAllProperties(); - - - -private: +Property * getProperty(PropertyContainer & prop_cont, String const & name); +Property * getProperty(PropertyContainer & prop_cont, int const identifier); - int _numProperties; - int _numPrimitivesProperties; - GetTimeCallbackFunc _get_time_func; - std::list _property_list; - void addProperty(Property * property_obj, int propertyIdentifier); +int appendChangedProperties(PropertyContainer & prop_cont, CborEncoder * arrayEncoder, bool lightPayload); +void updateTimestampOnLocallyChangedProperties(PropertyContainer & prop_cont); +void requestUpdateForAllProperties(PropertyContainer & prop_cont); -}; +void addProperty(PropertyContainer & prop_cont, Property * property_obj, int propertyIdentifier); #endif /* ARDUINO_PROPERTY_CONTAINER_H_ */ \ No newline at end of file