Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d5966e6

Browse files
committedMay 28, 2024
feat: AVR Compatibility
1 parent dd4c09d commit d5966e6

31 files changed

+570
-765
lines changed
 

‎extras/test/src/test_addPropertyReal.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,33 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino
3636

3737
/**************************************************************************************/
3838

39-
WHEN("the same int property is added multiple times")
39+
WHEN("the same int16 property is added multiple times")
4040
{
4141
PropertyContainer property_container;
4242

43-
CloudInt int_property = 1;
43+
CloudInt<int16_t> int16_property = 1;
4444

45-
Property * int_property_ptr_1 = &addPropertyToContainer(property_container, int_property, "int_property", Permission::ReadWrite);
46-
Property * int_property_ptr_2 = &addPropertyToContainer(property_container, int_property, "int_property", Permission::ReadWrite);
45+
Property * int16_property_ptr_1 = &addPropertyToContainer(property_container, int16_property, "int16_property", Permission::ReadWrite);
46+
Property * int16_property_ptr_2 = &addPropertyToContainer(property_container, int16_property, "int16_property", Permission::ReadWrite);
4747

4848
THEN("No new property is added and the first added property is returned instead of a new one") {
49-
REQUIRE(int_property_ptr_1 == int_property_ptr_2);
49+
REQUIRE(int16_property_ptr_1 == int16_property_ptr_2);
50+
}
51+
}
52+
53+
/**************************************************************************************/
54+
55+
WHEN("the same int32 property is added multiple times")
56+
{
57+
PropertyContainer property_container;
58+
59+
CloudInt<int32_t> int32_property = 1;
60+
61+
Property * int32_property_ptr_1 = &addPropertyToContainer(property_container, int32_property, "int32_property", Permission::ReadWrite);
62+
Property * int32_property_ptr_2 = &addPropertyToContainer(property_container, int32_property, "int32_property", Permission::ReadWrite);
63+
64+
THEN("No new property is added and the first added property is returned instead of a new one") {
65+
REQUIRE(int32_property_ptr_1 == int32_property_ptr_2);
5066
}
5167
}
5268

‎extras/test/src/test_callback.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ void externalCallbackV2()
4141
SCENARIO("A callback is registered via 'onUpdate' to be called on property change", "[ArduinoCloudThing::decode]")
4242
{
4343
PropertyContainer property_container;
44-
45-
CloudInt test = 10;
44+
45+
CloudInt<int> test = 10;
4646
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).onUpdate(externalCallbackV2);
4747

4848
/* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */

‎extras/test/src/test_decode.cpp

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
3737
WHEN("A boolean property is changed via CBOR message")
3838
{
3939
PropertyContainer property_container;
40-
40+
4141
CloudBool test = true;
4242
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
4343

@@ -55,7 +55,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
5555
{
5656
/*An integer identifier has been encoded instead of the name of the property in order to have a shorter payload*/
5757
PropertyContainer property_container;
58-
58+
5959
CloudBool test = true;
6060
/*The property is added with identifier 1 that will be used instead of the string "test" as property identifier*/
6161
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite, 1);
@@ -73,8 +73,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
7373
WHEN("A positive int property is changed via CBOR message")
7474
{
7575
PropertyContainer property_container;
76-
77-
CloudInt test = 0;
76+
77+
CloudInt<int> test = 0;
7878
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
7979

8080
/* [{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]")
8888
WHEN("A negative int property is changed via CBOR message")
8989
{
9090
PropertyContainer property_container;
91-
92-
CloudInt test = 0;
91+
92+
CloudInt<int> test = 0;
9393
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
9494

9595
/* [{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]")
105105
WHEN("A float property is changed via CBOR message")
106106
{
107107
PropertyContainer property_container;
108-
108+
109109
CloudFloat test = 0.0f;
110110
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
111111

@@ -122,7 +122,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
122122
WHEN("A String property is changed via CBOR message")
123123
{
124124
PropertyContainer property_container;
125-
125+
126126
CloudString str_test;
127127
str_test = "test";
128128
addPropertyToContainer(property_container, str_test, "test", Permission::ReadWrite);
@@ -139,7 +139,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
139139
WHEN("A Location property is changed via CBOR message")
140140
{
141141
PropertyContainer property_container;
142-
142+
143143
CloudLocation location_test = CloudLocation(0, 1);
144144
addPropertyToContainer(property_container, location_test, "test", Permission::ReadWrite);
145145

@@ -157,7 +157,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
157157
WHEN("A Color property is changed via CBOR message")
158158
{
159159
PropertyContainer property_container;
160-
160+
161161
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
162162

163163
addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite);
@@ -181,7 +181,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
181181
{
182182
/*An integer identifier has been encoded instead of the name of the property in order to have a shorter payload*/
183183
PropertyContainer property_container;
184-
184+
185185
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
186186

187187
/*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]")
205205
WHEN("A ColoredLight property is changed via CBOR message")
206206
{
207207
PropertyContainer property_container;
208-
208+
209209
CloudColoredLight color_test = CloudColoredLight(false, 0.0, 0.0, 0.0);
210210

211211
addPropertyToContainer(property_container, color_test, "test", Permission::ReadWrite);
@@ -229,7 +229,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
229229
WHEN("A Television property is changed via CBOR message")
230230
{
231231
PropertyContainer property_container;
232-
232+
233233
CloudTelevision tv_test = CloudTelevision(false, 0, false, PlaybackCommands::Stop, InputValue::AUX1, 0);
234234

235235
addPropertyToContainer(property_container, tv_test, "test", Permission::ReadWrite);
@@ -255,7 +255,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
255255
WHEN("A DimmedLight property is changed via CBOR message")
256256
{
257257
PropertyContainer property_container;
258-
258+
259259
CloudDimmedLight light_test = CloudDimmedLight(false, 0.0);
260260

261261
addPropertyToContainer(property_container, light_test, "test", Permission::ReadWrite);
@@ -277,7 +277,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
277277
WHEN("A Light property is changed via CBOR message")
278278
{
279279
PropertyContainer property_container;
280-
280+
281281
CloudLight light_test;
282282
light_test = false;
283283

@@ -295,7 +295,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
295295
WHEN("A ContactSensor property is changed via CBOR message")
296296
{
297297
PropertyContainer property_container;
298-
298+
299299
CloudContactSensor contact_test;
300300
contact_test = false;
301301

@@ -313,7 +313,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
313313
WHEN("A MotionSensor property is changed via CBOR message")
314314
{
315315
PropertyContainer property_container;
316-
316+
317317
CloudMotionSensor motion_test;
318318
motion_test = false;
319319

@@ -331,7 +331,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
331331
WHEN("A SmartPlug property is changed via CBOR message")
332332
{
333333
PropertyContainer property_container;
334-
334+
335335
CloudSmartPlug plug_test;
336336
plug_test = false;
337337

@@ -349,7 +349,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
349349
WHEN("A Switch property is changed via CBOR message")
350350
{
351351
PropertyContainer property_container;
352-
352+
353353
CloudSwitch switch_test;
354354
switch_test = false;
355355

@@ -367,7 +367,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
367367
WHEN("A Temperature property is changed via CBOR message")
368368
{
369369
PropertyContainer property_container;
370-
370+
371371
CloudTemperatureSensor test;
372372
test = 0.0f;
373373
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
@@ -414,8 +414,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
414414
CBORDecoder::decode(property_container, payload, sizeof(payload) / sizeof(uint8_t));
415415

416416
Schedule schedule_compare = Schedule(1633305600, 1633651200, 600, 1140850708);
417-
Schedule value_schedule_test = schedule_test.getValue();
418-
417+
Schedule value_schedule_test = schedule_test.getValue();
418+
419419
bool verify = (value_schedule_test == schedule_compare);
420420
REQUIRE(verify);
421421
REQUIRE(value_schedule_test.frm == schedule_compare.frm);
@@ -431,11 +431,11 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
431431
WHEN("Multiple properties of different type are changed via CBOR message")
432432
{
433433
PropertyContainer property_container;
434-
435-
CloudBool bool_test = false;
436-
CloudInt int_test = 1;
437-
CloudFloat float_test = 2.0f;
438-
CloudString str_test;
434+
435+
CloudBool bool_test = false;
436+
CloudInt<int> int_test = 1;
437+
CloudFloat float_test = 2.0f;
438+
CloudString str_test;
439439
str_test = ("str_test");
440440

441441
addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite);
@@ -460,11 +460,11 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
460460
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")
461461
{
462462
PropertyContainer property_container;
463-
464-
CloudBool bool_test = false;
465-
CloudInt int_test = 1;
466-
CloudFloat float_test = 2.0f;
467-
CloudString str_test;
463+
464+
CloudBool bool_test = false;
465+
CloudInt<int> int_test = 1;
466+
CloudFloat float_test = 2.0f;
467+
CloudString str_test;
468468
str_test = ("str_test");
469469

470470
addPropertyToContainer(property_container, bool_test, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS);
@@ -489,14 +489,14 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
489489
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")
490490
{
491491
PropertyContainer property_container;
492-
492+
493493
int int_test = 1;
494494
bool bool_test = false;
495495
float float_test = 2.0f;
496496
String str_test;
497497
str_test = "str_test";
498498

499-
std::unique_ptr<Property> i(new CloudWrapperInt(int_test));
499+
std::unique_ptr<Property> i(new CloudWrapperInt<int>(int_test));
500500
std::unique_ptr<Property> b(new CloudWrapperBool(bool_test));
501501
std::unique_ptr<Property> f(new CloudWrapperFloat(float_test));
502502
std::unique_ptr<Property> s(new CloudWrapperString(str_test));
@@ -525,7 +525,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
525525
WHEN("Multiple String properties are changed via CBOR message")
526526
{
527527
PropertyContainer property_container;
528-
528+
529529
CloudString str_1("hello"),
530530
str_2("arduino"),
531531
str_3("cloud"),
@@ -554,7 +554,7 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
554554
WHEN("A payload containing a CBOR base name is parsed")
555555
{
556556
PropertyContainer property_container;
557-
557+
558558
CloudString str = "hello";
559559
addPropertyToContainer(property_container, str, "test", Permission::ReadWrite);
560560

@@ -570,8 +570,8 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
570570
WHEN("A payload containing a CBOR base time is parsed")
571571
{
572572
PropertyContainer property_container;
573-
574-
CloudInt test = 0;
573+
574+
CloudInt<int> test = 0;
575575
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
576576

577577
/* [{-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]")
586586
WHEN("A payload containing a CBOR time is parsed")
587587
{
588588
PropertyContainer property_container;
589-
590-
CloudInt test = 0;
589+
590+
CloudInt<int> test = 0;
591591
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
592592

593593
/* [{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]")
602602
WHEN("A payload containing a CBOR BaseVersion is parsed")
603603
{
604604
PropertyContainer property_container;
605-
606-
CloudInt test = 0;
605+
606+
CloudInt<int> test = 0;
607607
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
608608

609609
/* [{-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]")
618618
WHEN("A payload containing a CBOR BaseName, BaseTime and Time is parsed")
619619
{
620620
PropertyContainer property_container;
621-
622-
CloudInt test = 0;
621+
622+
CloudInt<int> test = 0;
623623
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
624624

625625
/* [{-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]")
636636
WHEN("A payload containing a invalid CBOR key is parsed")
637637
{
638638
PropertyContainer property_container;
639-
640-
CloudInt test = 0;
639+
640+
CloudInt<int> test = 0;
641641
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite);
642642

643643
/* [{123: 123, 0: "test", 2: 1}] = 81 A3 18 7B 18 7B 00 64 74 65 73 74 02 01 */

‎extras/test/src/test_encode.cpp

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,28 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]"
5757

5858
/************************************************************************************/
5959

60-
WHEN("A 'int' property is added")
60+
WHEN("An 'int16' property is added")
6161
{
6262
PropertyContainer property_container;
6363
cbor::encode(property_container);
6464

65-
CloudInt int_test = 123;
65+
CloudInt<int16_t> int_test = 123;
66+
addPropertyToContainer(property_container, int_test, "test", Permission::ReadWrite);
67+
68+
/* [{0: "test", 2: 123}] = 9F A2 00 64 74 65 73 74 02 18 7B FF */
69+
std::vector<uint8_t> const expected = {0x9F, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x18, 0x7B, 0xFF};
70+
std::vector<uint8_t> const actual = cbor::encode(property_container);
71+
REQUIRE(actual == expected);
72+
}
73+
74+
/************************************************************************************/
75+
76+
WHEN("An 'int32' property is added")
77+
{
78+
PropertyContainer property_container;
79+
cbor::encode(property_container);
80+
81+
CloudInt<int32_t> int_test = 123;
6682
addPropertyToContainer(property_container, int_test, "test", Permission::ReadWrite);
6783

6884
/* [{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]"
343359
WHEN("Multiple properties are added")
344360
{
345361
PropertyContainer property_container;
346-
347-
CloudInt int_test = 1;
348-
CloudBool bool_test = false;
349-
CloudFloat float_test = 2.0f;
350-
CloudString str_test;
362+
363+
CloudInt<int> int_test = 1;
364+
CloudBool bool_test = false;
365+
CloudFloat float_test = 2.0f;
366+
CloudString str_test;
351367
str_test = "str_test";
352368

353369
addPropertyToContainer(property_container, int_test, "int_test", Permission::ReadWrite);
@@ -368,14 +384,14 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]"
368384
WHEN("Multiple primitive properties are added")
369385
{
370386
PropertyContainer property_container;
371-
387+
372388
int int_test = 1;
373389
bool bool_test = false;
374390
float float_test = 2.0f;
375391
String str_test;
376392
str_test = "str_test";
377393

378-
std::unique_ptr<Property> i(new CloudWrapperInt(int_test));
394+
std::unique_ptr<Property> i(new CloudWrapperInt<int>(int_test));
379395
std::unique_ptr<Property> b(new CloudWrapperBool(bool_test));
380396
std::unique_ptr<Property> f(new CloudWrapperFloat(float_test));
381397
std::unique_ptr<Property> s(new CloudWrapperString(str_test));
@@ -448,17 +464,17 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]"
448464
{
449465
PropertyContainer property_container;
450466

451-
CloudInt int_0; int_0 = 1000000;
452-
CloudInt int_1; int_1 = 1000001;
453-
CloudInt int_2; int_2 = 1000002;
454-
CloudInt int_3; int_3 = 1000003;
455-
CloudInt int_4; int_4 = 1000004;
456-
CloudInt int_5; int_5 = 1000005;
457-
CloudInt int_6; int_6 = 1000006;
458-
CloudInt int_7; int_7 = 1000007;
459-
CloudInt int_8; int_8 = 1000008;
460-
CloudInt int_9; int_9 = 1000009;
461-
CloudInt int_A; int_A = 1000010;
467+
CloudInt<int> int_0; int_0 = 1000000;
468+
CloudInt<int> int_1; int_1 = 1000001;
469+
CloudInt<int> int_2; int_2 = 1000002;
470+
CloudInt<int> int_3; int_3 = 1000003;
471+
CloudInt<int> int_4; int_4 = 1000004;
472+
CloudInt<int> int_5; int_5 = 1000005;
473+
CloudInt<int> int_6; int_6 = 1000006;
474+
CloudInt<int> int_7; int_7 = 1000007;
475+
CloudInt<int> int_8; int_8 = 1000008;
476+
CloudInt<int> int_9; int_9 = 1000009;
477+
CloudInt<int> int_A; int_A = 1000010;
462478
CloudSchedule schedule = CloudSchedule(1633305600, 1633651200, 600, 1140850708);
463479

464480
addPropertyToContainer(property_container, int_0, "int_value_0", Permission::ReadWrite);
@@ -515,5 +531,4 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]"
515531
std::vector<uint8_t> const actual_1 = cbor::encode(property_container);
516532
REQUIRE(actual_1 == expected_1);
517533
}
518-
519534
}

‎extras/test/src/test_publishOnChange.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
SCENARIO("An Arduino cloud property is published on value change", "[ArduinoCloudThing::publishOnChange]")
1818
{
1919
PropertyContainer property_container;
20-
21-
CloudInt test = 10;
22-
int const DELTA = 6;
20+
21+
CloudInt<int> test = 10;
22+
int const DELTA = 6;
2323

2424
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishOnChange(DELTA,0);
2525

‎extras/test/src/test_publishOnChangeRateLimit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
SCENARIO("An Arduino cloud property is published on value change but the update rate is limited", "[ArduinoCloudThing::publishOnChange]")
1818
{
1919
PropertyContainer property_container;
20-
21-
CloudInt test = 0;
20+
21+
CloudInt<int> test = 0;
2222
int const MIN_DELTA = 0;
2323
unsigned long const MIN_TIME_BETWEEN_UPDATES_ms = 500; /* No updates faster than 500 ms */
2424

‎extras/test/src/test_readOnly.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
SCENARIO("An Arduino cloud property is marked 'read only'", "[ArduinoCloudThing::decode]")
2121
{
2222
PropertyContainer property_container;
23-
24-
CloudInt test = 0;
23+
24+
CloudInt<int> test = 0;
2525
addPropertyToContainer(property_container, test, "test", Permission::Read);
2626

2727
/* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */

‎extras/test/src/test_writeOnChange.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SCENARIO("An Arduino cloud property is marked 'write on change'", "[ArduinoCloud
2121
{
2222
PropertyContainer property_container;
2323

24-
CloudInt test = 0;
24+
CloudInt<int> test = 0;
2525
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).writeOnChange();
2626

2727
/* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */

‎extras/test/src/test_writeOnDemand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SCENARIO("An Arduino cloud property is marked 'write on demand'", "[ArduinoCloud
2121
{
2222
PropertyContainer property_container;
2323

24-
CloudInt test = 0;
24+
CloudInt<int> test = 0;
2525
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).writeOnDemand();
2626

2727
/* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */

‎extras/test/src/test_writeOnly.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
SCENARIO("An Arduino cloud property is marked 'write only'", "[ArduinoCloudThing::encode]")
2121
{
2222
PropertyContainer property_container;
23-
24-
CloudInt test = 0;
23+
24+
CloudInt<int> test = 0;
2525
addPropertyToContainer(property_container, test, "test", Permission::Write);
2626

2727
REQUIRE(cbor::encode(property_container).size() == 0); /* Since 'test' is 'write only' it should not be encoded */

‎library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ sentence=This library allows connecting to the Arduino IoT Cloud service.
66
paragraph=It provides a ConnectionManager to handle connection/disconnection, property-change updates and events callbacks. The supported boards are MKR GSM, MKR1000 and WiFi101.
77
category=Communication
88
url=https://github.com/arduino-libraries/ArduinoIoTCloud
9-
architectures=mbed,samd,esp8266,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge
9+
architectures=avr,mbed,samd,esp8266,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge
1010
includes=ArduinoIoTCloud.h
11-
depends=Arduino_ConnectionHandler,Arduino_DebugUtils,Arduino_SecureElement,ArduinoMqttClient,ArduinoECCX08,RTCZero,Adafruit SleepyDog Library,ArduinoHttpClient
11+
depends=Arduino_ConnectionHandler,Arduino_DebugUtils,Arduino_SecureElement,ArduinoMqttClient,ArduinoECCX08,ArduinoSTL,RTCZero,Adafruit SleepyDog Library,ArduinoHttpClient

‎src/ArduinoIoTCloud.cpp

Lines changed: 106 additions & 62 deletions
Large diffs are not rendered by default.

‎src/ArduinoIoTCloud.h

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "property/types/CloudWrapperBool.h"
4040
#include "property/types/CloudWrapperFloat.h"
4141
#include "property/types/CloudWrapperInt.h"
42-
#include "property/types/CloudWrapperUnsignedInt.h"
4342
#include "property/types/CloudWrapperString.h"
4443

4544
#include "utility/time/TimeService.h"
@@ -108,40 +107,73 @@ class ArduinoIoTCloudClass
108107
/* The following methods are used for non-LoRa boards which can use the
109108
* name of the property to identify a given property within a CBOR message.
110109
*/
111-
112-
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.")));
113-
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.")));
114-
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.")));
115-
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.")));
116-
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.")));
117-
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.")));
118-
119-
Property& addPropertyReal(Property& property, String name, Permission const permission);
120-
Property& addPropertyReal(bool& property, String name, Permission const permission);
121-
Property& addPropertyReal(float& property, String name, Permission const permission);
122-
Property& addPropertyReal(int& property, String name, Permission const permission);
123-
Property& addPropertyReal(unsigned int& property, String name, Permission const permission);
124-
Property& addPropertyReal(String& property, String name, Permission const permission);
110+
template <typename T> 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)
111+
{
112+
addPropertyReal(property, name, -1, permission_type, seconds, fn, minDelta, synFn);
113+
}
114+
template <typename T> Property& addPropertyReal(T& property, String name, Permission const permission)
115+
{
116+
return addPropertyReal(property, name, -1, permission);
117+
}
125118

126119
/* The following methods are for MKR WAN 1300/1310 LoRa boards since
127120
* they use a number to identify a given property within a CBOR message.
128121
* This approach reduces the required amount of data which is of great
129122
* important when using LoRa.
130123
*/
131-
132-
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.")));
133-
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.")));
134-
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.")));
135-
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.")));
136-
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.")));
137-
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.")));
138-
139-
Property& addPropertyReal(Property& property, String name, int tag, Permission const permission);
140-
Property& addPropertyReal(bool& property, String name, int tag, Permission const permission);
141-
Property& addPropertyReal(float& property, String name, int tag, Permission const permission);
142-
Property& addPropertyReal(int& property, String name, int tag, Permission const permission);
143-
Property& addPropertyReal(unsigned int& property, String name, int tag, Permission const permission);
124+
template <typename T> __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)
125+
{
126+
Property* p = new CloudWrapperInt<T>(property);
127+
addPropertyRealInternal(*p, name, tag, permission_type, seconds, fn, minDelta, synFn);
128+
}
129+
template <typename T> __attribute__((deprecated("Use addProperty(property, Permission::ReadWrite) instead."))) void addPropertyReal(CloudInt<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)
130+
{
131+
addPropertyRealInternal(property, name, tag, permission_type, seconds, fn, minDelta, synFn);
132+
}
133+
__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);
134+
__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);
135+
__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);
136+
__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);
137+
__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);
138+
__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);
139+
__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);
140+
__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);
141+
__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);
142+
__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);
143+
__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);
144+
__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);
145+
__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);
146+
__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);
147+
__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);
148+
__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);
149+
__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);
150+
151+
template <typename T> Property& addPropertyReal(T& property, String name, int tag, Permission const permission)
152+
{
153+
Property* p = new CloudWrapperInt<T>(property);
154+
return addPropertyToContainer(getThingPropertyContainer(), *p, name, permission, tag);
155+
}
156+
template <typename T> Property& addPropertyReal(CloudInt<T>& property, String name, int tag, Permission const permission)
157+
{
158+
return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag);
159+
}
144160
Property& addPropertyReal(String& property, String name, int tag, Permission const permission);
161+
Property& addPropertyReal(Property& property, String name, int tag, Permission const permission);
162+
Property& addPropertyReal(CloudBool& property, String name, int tag, Permission const permission);
163+
Property& addPropertyReal(CloudColor& property, String name, int tag, Permission const permission);
164+
Property& addPropertyReal(CloudColoredLight& property, String name, int tag, Permission const permission);
165+
Property& addPropertyReal(CloudContactSensor& property, String name, int tag, Permission const permission);
166+
Property& addPropertyReal(CloudDimmedLight& property, String name, int tag, Permission const permission);
167+
Property& addPropertyReal(CloudFloat& property, String name, int tag, Permission const permission);
168+
Property& addPropertyReal(CloudLight& property, String name, int tag, Permission const permission);
169+
Property& addPropertyReal(CloudLocation& property, String name, int tag, Permission const permission);
170+
Property& addPropertyReal(CloudMotionSensor& property, String name, int tag, Permission const permission);
171+
Property& addPropertyReal(CloudSchedule& property, String name, int tag, Permission const permission);
172+
Property& addPropertyReal(CloudSmartPlug& property, String name, int tag, Permission const permission);
173+
Property& addPropertyReal(CloudString& property, String name, int tag, Permission const permission);
174+
Property& addPropertyReal(CloudSwitch& property, String name, int tag, Permission const permission);
175+
Property& addPropertyReal(CloudTelevision& property, String name, int tag, Permission const permission);
176+
Property& addPropertyReal(CloudTemperatureSensor& property, String name, int tag, Permission const permission);
145177

146178
protected:
147179

‎src/ArduinoIoTCloudThing.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "ArduinoIoTCloudThing.h"
2121
#include "interfaces/CloudProcess.h"
2222
#include "property/types/CloudWrapperInt.h"
23-
#include "property/types/CloudWrapperUnsignedInt.h"
2423

2524
/******************************************************************************
2625
* CTOR/DTOR
@@ -44,13 +43,13 @@ _utcOffsetExpireTimeProperty(nullptr) {
4443
void ArduinoCloudThing::begin() {
4544
Property* property;
4645

47-
property = new CloudWrapperInt(_utcOffset);
46+
property = new CloudWrapperInt<int>(_utcOffset);
4847
_utcOffsetProperty = &addPropertyToContainer(getPropertyContainer(),
4948
*property,
5049
"tz_offset",
5150
Permission::ReadWrite, -1);
5251
_utcOffsetProperty->writeOnDemand();
53-
property = new CloudWrapperUnsignedInt(_utcOffsetExpireTime);
52+
property = new CloudWrapperInt<unsigned int>(_utcOffsetExpireTime);
5453
_utcOffsetExpireTimeProperty = &addPropertyToContainer(getPropertyContainer(),
5554
*property,
5655
"tz_dst_until",

‎src/cbor/CBORDecoder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
******************************************************************************/
2424

2525
#include <Arduino.h>
26+
#ifdef __AVR_ARCH__
27+
# include <ArduinoSTL.h> // needed for std::list
28+
#endif
2629

2730
#undef max
2831
#undef min

‎src/cbor/lib/tinycbor/src/cbor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#ifndef CBOR_H
2626
#define CBOR_H
2727

28+
#ifdef __AVR_ARCH__
29+
# include "cbor_avr.h"
30+
#endif
31+
2832
#ifndef assert
2933
#include <assert.h>
3034
#endif

‎src/cbor/lib/tinycbor/src/cbor_avr.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef CBOR_AVR_H
2+
#define CBOR_AVR_H
3+
4+
#define FP_INFINITE INFINITY
5+
#define FP_NAN NAN
6+
#define PRIu64 "llu"
7+
#define PRIx64 "llx"
8+
9+
#define ssize_t int
10+
11+
extern int fpclassify(double x);
12+
13+
#endif /* CBOR_AVR_H */

‎src/cbor/lib/tinycbor/src/open_memstream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434

3535
#include <unistd.h>
3636

37+
#include "compilersupport_p.h"
38+
3739
typedef ssize_t RetType;
3840
typedef size_t LenType;
3941

40-
#include "compilersupport_p.h"
41-
4242
#pragma GCC diagnostic push
4343
#pragma GCC diagnostic ignored "-Wpedantic"
4444
#pragma GCC diagnostic ignored "-Wreturn-type"

‎src/property/Property.cpp

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -194,171 +194,12 @@ CborError Property::append(CborEncoder *encoder, bool lightPayload) {
194194
return CborNoError;
195195
}
196196

197-
CborError Property::appendAttribute(bool value, String attributeName, CborEncoder *encoder) {
198-
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
199-
{
200-
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::BooleanValue)));
201-
CHECK_CBOR(cbor_encode_boolean(&mapEncoder, value));
202-
return CborNoError;
203-
}, encoder);
204-
}
205-
206-
CborError Property::appendAttribute(int value, String attributeName, CborEncoder *encoder) {
207-
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
208-
{
209-
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
210-
CHECK_CBOR(cbor_encode_int(&mapEncoder, value));
211-
return CborNoError;
212-
}, encoder);
213-
}
214-
215-
CborError Property::appendAttribute(unsigned int value, String attributeName, CborEncoder *encoder) {
216-
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
217-
{
218-
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
219-
CHECK_CBOR(cbor_encode_int(&mapEncoder, value));
220-
return CborNoError;
221-
}, encoder);
222-
}
223-
224-
CborError Property::appendAttribute(float value, String attributeName, CborEncoder *encoder) {
225-
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
226-
{
227-
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
228-
CHECK_CBOR(cbor_encode_float(&mapEncoder, value));
229-
return CborNoError;
230-
}, encoder);
231-
}
232-
233-
CborError Property::appendAttribute(String value, String attributeName, CborEncoder *encoder) {
234-
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
235-
{
236-
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::StringValue)));
237-
CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, value.c_str()));
238-
return CborNoError;
239-
}, encoder);
240-
}
241-
242-
CborError Property::appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>appendValue, CborEncoder *encoder)
243-
{
244-
if (attributeName != "") {
245-
// 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
246-
_attributeIdentifier++;
247-
}
248-
CborEncoder mapEncoder;
249-
unsigned int num_map_properties = _encode_timestamp ? 3 : 2;
250-
CHECK_CBOR(cbor_encoder_create_map(encoder, &mapEncoder, num_map_properties));
251-
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Name)));
252-
253-
// if _lightPayload is true, the property and attribute identifiers will be encoded instead of the property name
254-
if (_lightPayload)
255-
{
256-
// the most significant byte of the identifier to be encoded represent the property identifier
257-
int completeIdentifier = _attributeIdentifier * 256;
258-
// the least significant byte of the identifier to be encoded represent the attribute identifier
259-
completeIdentifier += _identifier;
260-
CHECK_CBOR(cbor_encode_int(&mapEncoder, completeIdentifier));
261-
}
262-
else
263-
{
264-
String completeName = _name;
265-
if (attributeName != "") {
266-
completeName += ":" + attributeName;
267-
}
268-
CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, completeName.c_str()));
269-
}
270-
/* Encode the value */
271-
CHECK_CBOR(appendValue(mapEncoder));
272-
273-
/* Encode the timestamp if that has been required. */
274-
if(_encode_timestamp)
275-
{
276-
CHECK_CBOR(cbor_encode_int (&mapEncoder, static_cast<int>(CborIntegerMapKey::Time)));
277-
CHECK_CBOR(cbor_encode_uint(&mapEncoder, _timestamp));
278-
}
279-
/* Close the container */
280-
CHECK_CBOR(cbor_encoder_close_container(encoder, &mapEncoder));
281-
return CborNoError;
282-
}
283-
284197
void Property::setAttributesFromCloud(std::list<CborMapData> * map_data_list) {
285198
_map_data_list = map_data_list;
286199
_attributeIdentifier = 0;
287200
setAttributesFromCloud();
288201
}
289202

290-
void Property::setAttribute(bool& value, String attributeName) {
291-
setAttribute(attributeName, [&value](CborMapData & md) {
292-
// Manage the case to have boolean values received as integers 0/1
293-
if (md.bool_val.isSet()) {
294-
value = md.bool_val.get();
295-
} else if (md.val.isSet()) {
296-
if (md.val.get() == 0) {
297-
value = false;
298-
} else if (md.val.get() == 1) {
299-
value = true;
300-
} else {
301-
/* This should not happen. Leave the previous value */
302-
}
303-
}
304-
});
305-
}
306-
307-
void Property::setAttribute(int& value, String attributeName) {
308-
setAttribute(attributeName, [&value](CborMapData & md) {
309-
value = md.val.get();
310-
});
311-
}
312-
313-
void Property::setAttribute(unsigned int& value, String attributeName) {
314-
setAttribute(attributeName, [&value](CborMapData & md) {
315-
value = md.val.get();
316-
});
317-
}
318-
319-
void Property::setAttribute(float& value, String attributeName) {
320-
setAttribute(attributeName, [&value](CborMapData & md) {
321-
value = md.val.get();
322-
});
323-
}
324-
325-
void Property::setAttribute(String& value, String attributeName) {
326-
setAttribute(attributeName, [&value](CborMapData & md) {
327-
value = md.str_val.get();
328-
});
329-
}
330-
331-
void Property::setAttribute(String attributeName, std::function<void (CborMapData & md)>setValue)
332-
{
333-
if (attributeName != "") {
334-
_attributeIdentifier++;
335-
}
336-
337-
std::for_each(_map_data_list->begin(),
338-
_map_data_list->end(),
339-
[this, attributeName, setValue](CborMapData & map)
340-
{
341-
if (map.light_payload.isSet() && map.light_payload.get())
342-
{
343-
// if a light payload is detected, the attribute identifier is retrieved from the cbor map and the corresponding attribute is updated
344-
int attid = map.attribute_identifier.get();
345-
if (attid == _attributeIdentifier) {
346-
setValue(map);
347-
return;
348-
}
349-
}
350-
else
351-
{
352-
// if a normal payload is detected, the name of the attribute to be updated is extracted directly from the cbor map
353-
String an = map.attribute_name.get();
354-
if (an == attributeName) {
355-
setValue(map);
356-
return;
357-
}
358-
}
359-
});
360-
}
361-
362203
void Property::updateLocalTimestamp() {
363204
if (isReadableByCloud()) {
364205
if (_get_time_func) {

‎src/property/Property.h

Lines changed: 130 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#undef max
3333
#undef min
3434

35-
# include <functional>
3635
#include <list>
3736

3837
#include "../cbor/lib/tinycbor/cbor-lib.h"
@@ -185,19 +184,86 @@ class Property
185184

186185
void updateLocalTimestamp();
187186
CborError append(CborEncoder * encoder, bool lightPayload);
188-
CborError appendAttribute(bool value, String attributeName = "", CborEncoder *encoder = nullptr);
189-
CborError appendAttribute(int value, String attributeName = "", CborEncoder *encoder = nullptr);
190-
CborError appendAttribute(unsigned int value, String attributeName = "", CborEncoder *encoder = nullptr);
191-
CborError appendAttribute(float value, String attributeName = "", CborEncoder *encoder = nullptr);
192-
CborError appendAttribute(String value, String attributeName = "", CborEncoder *encoder = nullptr);
193-
CborError appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>f, CborEncoder *encoder);
194-
void setAttribute(String attributeName, std::function<void (CborMapData & md)>setValue);
187+
template <typename T> CborError appendAttribute(T value, String attributeName = "", CborEncoder *encoder = nullptr) {
188+
return appendAttributeName<T>(attributeName, encodeAppendedAttribute<T>, value, encoder);
189+
}
190+
template <typename T> CborError appendAttributeName(String attributeName, CborError(*appendValue)(CborEncoder& mapEncoder, const T), const T & value, CborEncoder *encoder)
191+
{
192+
if (attributeName != "") {
193+
// 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
194+
_attributeIdentifier++;
195+
}
196+
CborEncoder mapEncoder;
197+
unsigned int num_map_properties = _encode_timestamp ? 3 : 2;
198+
CHECK_CBOR(cbor_encoder_create_map(encoder, &mapEncoder, num_map_properties));
199+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Name)));
200+
201+
// if _lightPayload is true, the property and attribute identifiers will be encoded instead of the property name
202+
if (_lightPayload)
203+
{
204+
// the most significant byte of the identifier to be encoded represent the property identifier
205+
int completeIdentifier = _attributeIdentifier * 256;
206+
// the least significant byte of the identifier to be encoded represent the attribute identifier
207+
completeIdentifier += _identifier;
208+
CHECK_CBOR(cbor_encode_int(&mapEncoder, completeIdentifier));
209+
}
210+
else
211+
{
212+
String completeName = _name;
213+
if (attributeName != "") {
214+
completeName += ":" + attributeName;
215+
}
216+
CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, completeName.c_str()));
217+
}
218+
/* Encode the value */
219+
CHECK_CBOR(appendValue(mapEncoder, value));
220+
221+
/* Encode the timestamp if that has been required. */
222+
if(_encode_timestamp)
223+
{
224+
CHECK_CBOR(cbor_encode_int (&mapEncoder, static_cast<int>(CborIntegerMapKey::Time)));
225+
CHECK_CBOR(cbor_encode_uint(&mapEncoder, _timestamp));
226+
}
227+
/* Close the container */
228+
CHECK_CBOR(cbor_encoder_close_container(encoder, &mapEncoder));
229+
return CborNoError;
230+
}
231+
template <typename T> void setAttribute(const String attributeName, void(* const setValue)(CborMapData & md, T &), T & value)
232+
{
233+
if (attributeName != "") {
234+
_attributeIdentifier++;
235+
}
236+
237+
std::list<CborMapData>::iterator it = _map_data_list->begin();
238+
for (; it != _map_data_list->end(); ++it) {
239+
CborMapData & map = *it;
240+
if (map.light_payload.isSet() && map.light_payload.get())
241+
{
242+
// if a light payload is detected, the attribute identifier is retrieved
243+
// from the cbor map and the corresponding attribute is updated
244+
int attid = map.attribute_identifier.get();
245+
if (attid == _attributeIdentifier) {
246+
setValue(map, value);
247+
return;
248+
}
249+
}
250+
else
251+
{
252+
// if a normal payload is detected, the name of the attribute to be
253+
// updated is extracted directly from the cbor map
254+
String an = map.attribute_name.get();
255+
if (an == attributeName) {
256+
setValue(map, value);
257+
return;
258+
}
259+
}
260+
}
261+
}
262+
263+
template <typename T> void setAttribute(T& value, String attributeName = "") {
264+
setAttribute<T>(attributeName, setValueAttribute<T>, value);
265+
}
195266
void setAttributesFromCloud(std::list<CborMapData> * map_data_list);
196-
void setAttribute(bool& value, String attributeName = "");
197-
void setAttribute(int& value, String attributeName = "");
198-
void setAttribute(unsigned int& value, String attributeName = "");
199-
void setAttribute(float& value, String attributeName = "");
200-
void setAttribute(String& value, String attributeName = "");
201267

202268
virtual bool isDifferentFromCloud() = 0;
203269
virtual void fromCloudToLocal() = 0;
@@ -217,6 +283,18 @@ class Property
217283
unsigned long _min_time_between_updates_millis;
218284

219285
private:
286+
template <typename T> static CborError encodeAppendedAttribute(CborEncoder & mapEncoder, const T value) {
287+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
288+
CHECK_CBOR(cbor_encode_int(&mapEncoder, value));
289+
return CborNoError;
290+
}
291+
292+
template <typename T> static void setValueAttribute(CborMapData & md, T & value) {
293+
if (md.val.isSet()) {
294+
value = md.val.get();
295+
}
296+
}
297+
220298
Permission _permission;
221299
WritePolicy _write_policy;
222300
GetTimeCallbackFunc _get_time_func;
@@ -248,6 +326,45 @@ class Property
248326
unsigned long _timestamp;
249327
};
250328

329+
template <> inline CborError Property::encodeAppendedAttribute<bool>(CborEncoder & mapEncoder, const bool value) {
330+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::BooleanValue)));
331+
CHECK_CBOR(cbor_encode_boolean(&mapEncoder, value));
332+
return CborNoError;
333+
}
334+
335+
template <> inline CborError Property::encodeAppendedAttribute<float>(CborEncoder & mapEncoder, const float value) {
336+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
337+
CHECK_CBOR(cbor_encode_float(&mapEncoder, value));
338+
return CborNoError;
339+
}
340+
341+
template <> inline CborError Property::encodeAppendedAttribute<String>(CborEncoder & mapEncoder, const String value) {
342+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::StringValue)));
343+
CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, value.c_str()));
344+
return CborNoError;
345+
}
346+
347+
template <> inline void Property::setValueAttribute<String>(CborMapData & md, String & value) {
348+
if (md.str_val.isSet()) {
349+
value = md.str_val.get();
350+
}
351+
}
352+
353+
template <> inline void Property::setValueAttribute<bool>(CborMapData & md, bool & value) {
354+
// Manage the case to have boolean values received as integers 0/1
355+
if (md.bool_val.isSet()) {
356+
value = md.bool_val.get();
357+
} else if (md.val.isSet()) {
358+
if (md.val.get() == 0) {
359+
value = false;
360+
} else if (md.val.get() == 1) {
361+
value = true;
362+
} else {
363+
/* This should not happen. Leave the previous value */
364+
}
365+
}
366+
}
367+
251368
/******************************************************************************
252369
PROTOTYPE FREE FUNCTIONs
253370
******************************************************************************/

‎src/property/PropertyContainer.h

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "types/CloudBool.h"
3434
#include "types/CloudFloat.h"
3535
#include "types/CloudInt.h"
36-
#include "types/CloudUnsignedInt.h"
3736
#include "types/CloudString.h"
3837
#include "types/CloudLocation.h"
3938
#include "types/CloudSchedule.h"
@@ -62,36 +61,36 @@ extern "C" unsigned long getTime();
6261

6362
typedef std::list<Property *> PropertyContainer;
6463

65-
typedef CloudFloat CloudEnergy;
66-
typedef CloudFloat CloudForce;
67-
typedef CloudFloat CloudTemperature;
68-
typedef CloudFloat CloudPower;
64+
typedef CloudFloat CloudAcceleration;
65+
typedef CloudFloat CloudAngle;
66+
typedef CloudFloat CloudArea;
67+
typedef CloudFloat CloudCapacitance;
68+
typedef CloudInt<int32_t> CloudCounter;
69+
typedef CloudFloat CloudDataRate;
6970
typedef CloudFloat CloudElectricCurrent;
7071
typedef CloudFloat CloudElectricPotential;
7172
typedef CloudFloat CloudElectricResistance;
72-
typedef CloudFloat CloudCapacitance;
73-
typedef CloudUnsignedInt CloudTime;
73+
typedef CloudFloat CloudEnergy;
74+
typedef CloudFloat CloudFlowRate;
75+
typedef CloudFloat CloudForce;
7476
typedef CloudFloat CloudFrequency;
75-
typedef CloudFloat CloudDataRate;
7677
typedef CloudFloat CloudHeartRate;
77-
typedef CloudInt CloudCounter;
78-
typedef CloudFloat CloudAcceleration;
79-
typedef CloudFloat CloudArea;
80-
typedef CloudFloat CloudLength;
81-
typedef CloudFloat CloudVelocity;
82-
typedef CloudFloat CloudMass;
83-
typedef CloudFloat CloudVolume;
84-
typedef CloudFloat CloudFlowRate;
85-
typedef CloudFloat CloudAngle;
8678
typedef CloudFloat CloudIlluminance;
87-
typedef CloudFloat CloudLuminousFlux;
79+
typedef CloudInt<int32_t> CloudInformationContent;
80+
typedef CloudFloat CloudLength;
81+
typedef CloudFloat CloudLogarithmicQuantity;
8882
typedef CloudFloat CloudLuminance;
83+
typedef CloudFloat CloudLuminousFlux;
8984
typedef CloudFloat CloudLuminousIntensity;
90-
typedef CloudFloat CloudLogarithmicQuantity;
91-
typedef CloudFloat CloudPressure;
92-
typedef CloudInt CloudInformationContent;
85+
typedef CloudFloat CloudMass;
9386
typedef CloudFloat CloudPercentage;
87+
typedef CloudFloat CloudPower;
88+
typedef CloudFloat CloudPressure;
9489
typedef CloudFloat CloudRelativeHumidity;
90+
typedef CloudFloat CloudTemperature;
91+
typedef CloudInt<uint32_t> CloudTime;
92+
typedef CloudFloat CloudVelocity;
93+
typedef CloudFloat CloudVolume;
9594

9695
/******************************************************************************
9796
FUNCTION DECLARATION
@@ -104,11 +103,9 @@ Property & addPropertyToContainer(PropertyContainer & prop_cont,
104103
int propertyIdentifier = -1,
105104
GetTimeCallbackFunc func = getTime);
106105

107-
108106
Property * getProperty(PropertyContainer & prop_cont, String const & name);
109107
Property * getProperty(PropertyContainer & prop_cont, int const identifier);
110108

111-
112109
void updateTimestampOnLocallyChangedProperties(PropertyContainer & prop_cont);
113110
void requestUpdateForAllProperties(PropertyContainer & prop_cont);
114111
void updateProperty(PropertyContainer & prop_cont, String propertyName, unsigned long cloudChangeEventTime, bool const is_sync_message, std::list<CborMapData> * map_data_list);

‎src/property/types/CloudColor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Color {
3636
Color(float h, float s, float b): hue(h), sat(s), bri(b) {
3737
setColorHSB(h, s, b);
3838
}
39+
Color(const Color& r) : hue(r.hue), sat(r.sat), bri(r.bri) {}
3940

4041
bool setColorHSB(float h, float s, float b) {
4142
if (h < 0 || h > 360 || s < 0 || s > 100 || b < 0 || b > 100) {

‎src/property/types/CloudFloat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CloudFloat : public Property {
4242
CloudFloat(0.0f);
4343
}
4444
CloudFloat(float v) : _value(v), _cloud_value(v) {}
45+
CloudFloat(const CloudFloat& r) : _value(r._value), _cloud_value(r._cloud_value) {}
4546
operator float() const {
4647
return _value;
4748
}

‎src/property/types/CloudInt.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,31 @@
2222
INCLUDE
2323
******************************************************************************/
2424

25+
#include <stdint.h>
26+
2527
#include <Arduino.h>
2628
#include "../Property.h"
2729

2830
/******************************************************************************
2931
CLASS DECLARATION
3032
******************************************************************************/
3133

32-
33-
34+
template <typename T>
3435
class CloudInt : public Property {
3536
private:
36-
int _value,
37-
_cloud_value;
37+
T _value,
38+
_cloud_value;
3839
public:
39-
CloudInt() {
40+
CloudInt() {
4041
CloudInt(0);
4142
}
42-
CloudInt(int v) : _value(v), _cloud_value(v) {}
43-
operator int() const {
43+
CloudInt(T v) : _value(v), _cloud_value(v) {}
44+
CloudInt(const CloudInt& r) : _value(r._value), _cloud_value(r._cloud_value) {}
45+
operator T() const {
4446
return _value;
4547
}
4648
virtual bool isDifferentFromCloud() {
47-
return _value != _cloud_value && (abs(_value - _cloud_value) >= Property::_min_delta_property);
49+
return _value != _cloud_value && ((std::max(_value , _cloud_value) - std::min(_value , _cloud_value)) >= Property::_min_delta_property);
4850
}
4951
virtual void fromCloudToLocal() {
5052
_value = _cloud_value;
@@ -59,27 +61,27 @@ class CloudInt : public Property {
5961
setAttribute(_cloud_value, "");
6062
}
6163
//modifiers
62-
CloudInt& operator=(int v) {
64+
CloudInt& operator=(T v) {
6365
_value = v;
6466
updateLocalTimestamp();
6567
return *this;
6668
}
6769
CloudInt& operator=(CloudInt v) {
68-
return operator=((int)v);
70+
return operator=(static_cast<T>(v));
6971
}
70-
CloudInt& operator+=(int v) {
72+
CloudInt& operator+=(T v) {
7173
return operator=(_value += v);
7274
}
73-
CloudInt& operator-=(int v) {
75+
CloudInt& operator-=(T v) {
7476
return operator=(_value -= v);
7577
}
76-
CloudInt& operator*=(int v) {
78+
CloudInt& operator*=(T v) {
7779
return operator=(_value *= v);
7880
}
79-
CloudInt& operator/=(int v) {
81+
CloudInt& operator/=(T v) {
8082
return operator=(_value /= v);
8183
}
82-
CloudInt& operator%=(int v) {
84+
CloudInt& operator%=(T v) {
8385
return operator=(_value %= v);
8486
}
8587
CloudInt& operator++() {
@@ -96,19 +98,19 @@ class CloudInt : public Property {
9698
operator=(_value - 1);
9799
return CloudInt(_value);
98100
}
99-
CloudInt& operator&=(int v) {
101+
CloudInt& operator&=(T v) {
100102
return operator=(_value &= v);
101103
}
102-
CloudInt& operator|=(int v) {
104+
CloudInt& operator|=(T v) {
103105
return operator=(_value |= v);
104106
}
105-
CloudInt& operator^=(int v) {
107+
CloudInt& operator^=(T v) {
106108
return operator=(_value ^= v);
107109
}
108-
CloudInt& operator<<=(int v) {
110+
CloudInt& operator<<=(T v) {
109111
return operator=(_value <<= v);
110112
}
111-
CloudInt& operator>>=(int v) {
113+
CloudInt& operator>>=(T v) {
112114
return operator=(_value >>= v);
113115
}
114116
//accessors
@@ -128,95 +130,93 @@ class CloudInt : public Property {
128130
friend CloudInt operator+(CloudInt iw, CloudInt v) {
129131
return iw += v;
130132
}
131-
friend CloudInt operator+(CloudInt iw, int v) {
133+
friend CloudInt operator+(CloudInt iw, T v) {
132134
return iw += v;
133135
}
134-
friend CloudInt operator+(int v, CloudInt iw) {
136+
friend CloudInt operator+(T v, CloudInt iw) {
135137
return CloudInt(v) += iw;
136138
}
137139
friend CloudInt operator-(CloudInt iw, CloudInt v) {
138140
return iw -= v;
139141
}
140-
friend CloudInt operator-(CloudInt iw, int v) {
142+
friend CloudInt operator-(CloudInt iw, T v) {
141143
return iw -= v;
142144
}
143-
friend CloudInt operator-(int v, CloudInt iw) {
145+
friend CloudInt operator-(T v, CloudInt iw) {
144146
return CloudInt(v) -= iw;
145147
}
146148
friend CloudInt operator*(CloudInt iw, CloudInt v) {
147149
return iw *= v;
148150
}
149-
friend CloudInt operator*(CloudInt iw, int v) {
151+
friend CloudInt operator*(CloudInt iw, T v) {
150152
return iw *= v;
151153
}
152-
friend CloudInt operator*(int v, CloudInt iw) {
154+
friend CloudInt operator*(T v, CloudInt iw) {
153155
return CloudInt(v) *= iw;
154156
}
155157
friend CloudInt operator/(CloudInt iw, CloudInt v) {
156158
return iw /= v;
157159
}
158-
friend CloudInt operator/(CloudInt iw, int v) {
160+
friend CloudInt operator/(CloudInt iw, T v) {
159161
return iw /= v;
160162
}
161-
friend CloudInt operator/(int v, CloudInt iw) {
163+
friend CloudInt operator/(T v, CloudInt iw) {
162164
return CloudInt(v) /= iw;
163165
}
164166
friend CloudInt operator%(CloudInt iw, CloudInt v) {
165167
return iw %= v;
166168
}
167-
friend CloudInt operator%(CloudInt iw, int v) {
169+
friend CloudInt operator%(CloudInt iw, T v) {
168170
return iw %= v;
169171
}
170-
friend CloudInt operator%(int v, CloudInt iw) {
172+
friend CloudInt operator%(T v, CloudInt iw) {
171173
return CloudInt(v) %= iw;
172174
}
173175
friend CloudInt operator&(CloudInt iw, CloudInt v) {
174176
return iw &= v;
175177
}
176-
friend CloudInt operator&(CloudInt iw, int v) {
178+
friend CloudInt operator&(CloudInt iw, T v) {
177179
return iw &= v;
178180
}
179-
friend CloudInt operator&(int v, CloudInt iw) {
181+
friend CloudInt operator&(T v, CloudInt iw) {
180182
return CloudInt(v) &= iw;
181183
}
182184
friend CloudInt operator|(CloudInt iw, CloudInt v) {
183185
return iw |= v;
184186
}
185-
friend CloudInt operator|(CloudInt iw, int v) {
187+
friend CloudInt operator|(CloudInt iw, T v) {
186188
return iw |= v;
187189
}
188-
friend CloudInt operator|(int v, CloudInt iw) {
190+
friend CloudInt operator|(T v, CloudInt iw) {
189191
return CloudInt(v) |= iw;
190192
}
191193
friend CloudInt operator^(CloudInt iw, CloudInt v) {
192194
return iw ^= v;
193195
}
194-
friend CloudInt operator^(CloudInt iw, int v) {
196+
friend CloudInt operator^(CloudInt iw, T v) {
195197
return iw ^= v;
196198
}
197-
friend CloudInt operator^(int v, CloudInt iw) {
199+
friend CloudInt operator^(T v, CloudInt iw) {
198200
return CloudInt(v) ^= iw;
199201
}
200202
friend CloudInt operator<<(CloudInt iw, CloudInt v) {
201203
return iw <<= v;
202204
}
203-
friend CloudInt operator<<(CloudInt iw, int v) {
205+
friend CloudInt operator<<(CloudInt iw, T v) {
204206
return iw <<= v;
205207
}
206-
friend CloudInt operator<<(int v, CloudInt iw) {
208+
friend CloudInt operator<<(T v, CloudInt iw) {
207209
return CloudInt(v) <<= iw;
208210
}
209211
friend CloudInt operator>>(CloudInt iw, CloudInt v) {
210212
return iw >>= v;
211213
}
212-
friend CloudInt operator>>(CloudInt iw, int v) {
214+
friend CloudInt operator>>(CloudInt iw, T v) {
213215
return iw >>= v;
214216
}
215-
friend CloudInt operator>>(int v, CloudInt iw) {
217+
friend CloudInt operator>>(T v, CloudInt iw) {
216218
return CloudInt(v) >>= iw;
217219
}
218-
219220
};
220221

221-
222222
#endif /* CLOUDINT_H_ */

‎src/property/types/CloudLocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Location {
3737
float lat,
3838
lon;
3939
Location(float lat, float lon) : lat(lat), lon(lon) {}
40+
Location(const Location& r) : lat(r.lat), lon(r.lon) {}
4041
Location& operator=(Location& aLocation) {
4142
lat = aLocation.lat;
4243
lon = aLocation.lon;

‎src/property/types/CloudSchedule.h

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,46 @@
2626
#include "../Property.h"
2727
#include "../../AIoTC_Const.h"
2828
#include "utility/time/TimeService.h"
29+
#include <stdint.h>
2930
#include <time.h>
3031

3132
/******************************************************************************
3233
* DEFINE
3334
******************************************************************************/
34-
#define SCHEDULE_UNIT_MASK 0xC0000000
35+
#define SCHEDULE_UNIT_MASK static_cast<uint32_t>(0xC0000000)
3536
#define SCHEDULE_UNIT_SHIFT 30
3637

37-
#define SCHEDULE_TYPE_MASK 0x3C000000
38+
#define SCHEDULE_TYPE_MASK static_cast<uint32_t>(0x3C000000)
3839
#define SCHEDULE_TYPE_SHIFT 26
3940

40-
#define SCHEDULE_MONTH_MASK 0x0000FF00
41+
#define SCHEDULE_MONTH_MASK static_cast<uint32_t>(0x0000FF00)
4142
#define SCHEDULE_MONTH_SHIFT 8
4243

43-
#define SCHEDULE_REP_MASK 0x03FFFFFF
44-
#define SCHEDULE_WEEK_MASK 0x000000FF
45-
#define SCHEDULE_DAY_MASK 0x000000FF
44+
#define SCHEDULE_REP_MASK static_cast<uint32_t>(0x03FFFFFF)
45+
#define SCHEDULE_WEEK_MASK static_cast<uint32_t>(0x000000FF)
46+
#define SCHEDULE_DAY_MASK static_cast<uint32_t>(0x000000FF)
4647

47-
#define SCHEDULE_ONE_SHOT 0xFFFFFFFF
48+
#define SCHEDULE_ONE_SHOT static_cast<uint32_t>(0xFFFFFFFF)
4849

4950
/******************************************************************************
5051
ENUM
5152
******************************************************************************/
52-
enum class ScheduleUnit : int {
53+
enum class ScheduleUnit : int32_t {
5354
Seconds = 0,
5455
Minutes = 1,
5556
Hours = 2,
5657
Days = 3
5758
};
5859

59-
enum class ScheduleType : int {
60+
enum class ScheduleType : int32_t {
6061
OneShot = 0,
6162
FixedDelta = 1,
6263
Weekly = 2,
6364
Monthly = 3,
6465
Yearly = 4
6566
};
6667

67-
enum class ScheduleMonth : int {
68+
enum class ScheduleMonth : int32_t {
6869
Jan = 0,
6970
Feb = 1,
7071
Mar = 2,
@@ -79,7 +80,7 @@ enum class ScheduleMonth : int {
7980
Dec = 11
8081
};
8182

82-
enum class ScheduleWeekDay : int {
83+
enum class ScheduleWeekDay : int32_t {
8384
Sun = 0,
8485
Mon = 1,
8586
Tue = 2,
@@ -89,7 +90,7 @@ enum class ScheduleWeekDay : int {
8990
Sat = 6
9091
};
9192

92-
enum class ScheduleState : int {
93+
enum class ScheduleState : int32_t {
9394
Inactive = 0,
9495
Active = 1
9596
};
@@ -98,12 +99,12 @@ enum class ScheduleState : int {
9899
* TYPEDEF
99100
******************************************************************************/
100101
typedef struct ScheduleWeeklyMask {
101-
ScheduleState& operator[](ScheduleWeekDay i) { return day[static_cast<int>(i)];}
102+
ScheduleState& operator[](ScheduleWeekDay i) { return day[static_cast<int32_t>(i)];}
102103
ScheduleState day[7];
103104
}ScheduleWeeklyMask;
104105

105-
typedef unsigned int ScheduleTimeType;
106-
typedef unsigned int ScheduleConfigurationType;
106+
typedef uint32_t ScheduleTimeType;
107+
typedef uint32_t ScheduleConfigurationType;
107108

108109
/******************************************************************************
109110
CLASS DECLARATION
@@ -112,6 +113,7 @@ class Schedule {
112113
public:
113114
ScheduleTimeType frm, to, len, msk;
114115
Schedule(ScheduleTimeType s, ScheduleTimeType e, ScheduleTimeType d, ScheduleConfigurationType m): frm(s), to(e), len(d), msk(m) {}
116+
Schedule(const Schedule& r) : frm(r.frm), to(r.to), len(r.len), msk(r.msk) {}
115117

116118
bool isActive() {
117119

@@ -140,10 +142,10 @@ class Schedule {
140142
return 0;
141143
}
142144

143-
static ScheduleConfigurationType createFixedDeltaScheduleConfiguration(ScheduleUnit unit, unsigned int delta) {
144-
int temp_unit = static_cast<int>(unit);
145-
int temp_type = static_cast<int>(ScheduleType::FixedDelta);
146-
unsigned int temp_delta = delta;
145+
static ScheduleConfigurationType createFixedDeltaScheduleConfiguration(ScheduleUnit unit, uint32_t delta) {
146+
int32_t temp_unit = static_cast<int32_t>(unit);
147+
int32_t temp_type = static_cast<int32_t>(ScheduleType::FixedDelta);
148+
uint32_t temp_delta = delta;
147149

148150
if (temp_delta > SCHEDULE_REP_MASK) {
149151
temp_delta = SCHEDULE_REP_MASK;
@@ -152,20 +154,20 @@ class Schedule {
152154
}
153155

154156
static ScheduleConfigurationType createWeeklyScheduleConfiguration(ScheduleWeeklyMask weekMask) {
155-
unsigned int temp_week = 0;
156-
int temp_type = static_cast<int>(ScheduleType::Weekly);
157+
uint32_t temp_week = 0;
158+
int32_t temp_type = static_cast<int32_t>(ScheduleType::Weekly);
157159

158-
for(int i = 0; i<7; i++) {
160+
for(size_t i = 0; i<7; i++) {
159161
if(weekMask[static_cast<ScheduleWeekDay>(i)] == ScheduleState::Active) {
160162
temp_week |= 1 << i;
161163
}
162164
}
163165
return (temp_type << SCHEDULE_TYPE_SHIFT) | temp_week;
164166
}
165167

166-
static ScheduleConfigurationType createMonthlyScheduleConfiguration(int dayOfTheMonth) {
167-
int temp_day = dayOfTheMonth;
168-
int temp_type = static_cast<int>(ScheduleType::Monthly);
168+
static ScheduleConfigurationType createMonthlyScheduleConfiguration(int32_t dayOfTheMonth) {
169+
int32_t temp_day = dayOfTheMonth;
170+
int32_t temp_type = static_cast<int32_t>(ScheduleType::Monthly);
169171

170172
if(temp_day < 1) {
171173
temp_day = 1;
@@ -177,10 +179,10 @@ class Schedule {
177179
return (temp_type << SCHEDULE_TYPE_SHIFT) | temp_day;
178180
}
179181

180-
static ScheduleConfigurationType createYearlyScheduleConfiguration(ScheduleMonth month, int dayOfTheMonth) {
181-
unsigned int temp_day = createMonthlyScheduleConfiguration(dayOfTheMonth);
182-
int temp_month = static_cast<int>(month);
183-
int temp_type = static_cast<int>(ScheduleType::Yearly);
182+
static ScheduleConfigurationType createYearlyScheduleConfiguration(ScheduleMonth month, int32_t dayOfTheMonth) {
183+
uint32_t temp_day = createMonthlyScheduleConfiguration(dayOfTheMonth);
184+
int32_t temp_month = static_cast<int32_t>(month);
185+
int32_t temp_type = static_cast<int32_t>(ScheduleType::Yearly);
184186

185187
return (temp_type << SCHEDULE_TYPE_SHIFT) | (temp_month << SCHEDULE_MONTH_SHIFT)| temp_day;
186188
}
@@ -210,19 +212,19 @@ class Schedule {
210212
return static_cast<ScheduleType>((msk & SCHEDULE_TYPE_MASK) >> SCHEDULE_TYPE_SHIFT);
211213
}
212214

213-
unsigned int getScheduleRepetition(ScheduleConfigurationType msk) {
215+
uint32_t getScheduleRepetition(ScheduleConfigurationType msk) {
214216
return (msk & SCHEDULE_REP_MASK);
215217
}
216218

217-
unsigned int getScheduleWeekMask(ScheduleConfigurationType msk) {
219+
uint32_t getScheduleWeekMask(ScheduleConfigurationType msk) {
218220
return (msk & SCHEDULE_WEEK_MASK);
219221
}
220222

221-
unsigned int getScheduleDay(ScheduleConfigurationType msk) {
223+
uint32_t getScheduleDay(ScheduleConfigurationType msk) {
222224
return (msk & SCHEDULE_DAY_MASK);
223225
}
224226

225-
unsigned int getScheduleMonth(ScheduleConfigurationType msk) {
227+
uint32_t getScheduleMonth(ScheduleConfigurationType msk) {
226228
return ((msk & SCHEDULE_MONTH_MASK) >> SCHEDULE_MONTH_SHIFT);
227229
}
228230

@@ -278,21 +280,21 @@ class Schedule {
278280
}
279281
}
280282

281-
unsigned int getCurrentDayMask(time_t time) {
283+
uint32_t getCurrentDayMask(time_t time) {
282284
struct tm * ptm;
283285
ptm = gmtime (&time);
284286

285287
return 1 << ptm->tm_wday;
286288
}
287289

288-
unsigned int getCurrentDay(time_t time) {
290+
uint32_t getCurrentDay(time_t time) {
289291
struct tm * ptm;
290292
ptm = gmtime (&time);
291293

292294
return ptm->tm_mday;
293295
}
294296

295-
unsigned int getCurrentMonth(time_t time) {
297+
uint32_t getCurrentMonth(time_t time) {
296298
struct tm * ptm;
297299
ptm = gmtime (&time);
298300

@@ -318,30 +320,30 @@ class Schedule {
318320
if(isScheduleFixed(msk) || isScheduleOneShot(msk)) {
319321
return true;
320322
}
321-
323+
322324
if(isScheduleWeekly(msk)) {
323-
unsigned int currentDayMask = getCurrentDayMask(now);
324-
unsigned int scheduleMask = getScheduleWeekMask(msk);
325-
325+
uint32_t currentDayMask = getCurrentDayMask(now);
326+
uint32_t scheduleMask = getScheduleWeekMask(msk);
327+
326328
if((currentDayMask & scheduleMask) != 0) {
327329
return true;
328330
}
329331
}
330332

331333
if(isScheduleMonthly(msk)) {
332-
unsigned int currentDay = getCurrentDay(now);
333-
unsigned int scheduleDay = getScheduleDay(msk);
334+
uint32_t currentDay = getCurrentDay(now);
335+
uint32_t scheduleDay = getScheduleDay(msk);
334336

335337
if(currentDay == scheduleDay) {
336338
return true;
337339
}
338340
}
339341

340342
if(isScheduleYearly(msk)) {
341-
unsigned int currentDay = getCurrentDay(now);
342-
unsigned int scheduleDay = getScheduleDay(msk);
343-
unsigned int currentMonth = getCurrentMonth(now);
344-
unsigned int scheduleMonth = getScheduleMonth(msk);
343+
uint32_t currentDay = getCurrentDay(now);
344+
uint32_t scheduleDay = getScheduleDay(msk);
345+
uint32_t currentMonth = getCurrentMonth(now);
346+
uint32_t scheduleMonth = getScheduleMonth(msk);
345347

346348
if((currentDay == scheduleDay) && (currentMonth == scheduleMonth)) {
347349
return true;
@@ -382,10 +384,9 @@ class CloudSchedule : public Property {
382384
_cloud_value;
383385
public:
384386
CloudSchedule() : _value(0, 0, 0, 0), _cloud_value(0, 0, 0, 0) {}
385-
CloudSchedule(unsigned int frm, unsigned int to, unsigned int len, unsigned int msk) : _value(frm, to, len, msk), _cloud_value(frm, to, len, msk) {}
387+
CloudSchedule(uint32_t frm, uint32_t to, uint32_t len, uint32_t msk) : _value(frm, to, len, msk), _cloud_value(frm, to, len, msk) {}
386388

387389
virtual bool isDifferentFromCloud() {
388-
389390
return _value != _cloud_value;
390391
}
391392

@@ -413,16 +414,19 @@ class CloudSchedule : public Property {
413414
virtual void fromCloudToLocal() {
414415
_value = _cloud_value;
415416
}
417+
416418
virtual void fromLocalToCloud() {
417419
_cloud_value = _value;
418420
}
421+
419422
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
420423
CHECK_CBOR_MULTI(appendAttribute(_value.frm, "frm", encoder));
421424
CHECK_CBOR_MULTI(appendAttribute(_value.to, "to", encoder));
422425
CHECK_CBOR_MULTI(appendAttribute(_value.len, "len", encoder));
423426
CHECK_CBOR_MULTI(appendAttribute(_value.msk, "msk", encoder));
424427
return CborNoError;
425428
}
429+
426430
virtual void setAttributesFromCloud() {
427431
setAttribute(_cloud_value.frm, "frm");
428432
setAttribute(_cloud_value.to, "to");

‎src/property/types/CloudUnsignedInt.h

Lines changed: 0 additions & 222 deletions
This file was deleted.

‎src/property/types/CloudWrapperInt.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,25 @@
2222
INCLUDE
2323
******************************************************************************/
2424

25+
#include <stdint.h>
26+
2527
#include <Arduino.h>
2628
#include "CloudWrapperBase.h"
2729

2830
/******************************************************************************
2931
CLASS DECLARATION
3032
******************************************************************************/
3133

34+
template <typename T>
3235
class CloudWrapperInt : public CloudWrapperBase {
3336
private:
34-
int &_primitive_value,
35-
_cloud_value,
36-
_local_value;
37+
T &_primitive_value,
38+
_cloud_value,
39+
_local_value;
3740
public:
38-
CloudWrapperInt(int& v) : _primitive_value(v), _cloud_value(v), _local_value(v) {}
41+
CloudWrapperInt(T& v) : _primitive_value(v), _cloud_value(v), _local_value(v) {}
3942
virtual bool isDifferentFromCloud() {
40-
return _primitive_value != _cloud_value && (abs(_primitive_value - _cloud_value) >= Property::_min_delta_property);
43+
return _primitive_value != _cloud_value && ((std::max(_primitive_value , _cloud_value) - std::min(_primitive_value , _cloud_value)) >= Property::_min_delta_property);
4144
}
4245
virtual void fromCloudToLocal() {
4346
_primitive_value = _cloud_value;
@@ -59,5 +62,4 @@ class CloudWrapperInt : public CloudWrapperBase {
5962
}
6063
};
6164

62-
6365
#endif /* CLOUDWRAPPERINT_H_ */

‎src/property/types/CloudWrapperUnsignedInt.h

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎src/property/types/automation/CloudTelevision.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
INCLUDE
2323
******************************************************************************/
2424

25+
#include <stdint.h>
26+
2527
#include <Arduino.h>
2628
#include "../../Property.h"
2729

@@ -116,7 +118,6 @@ class Television {
116118
InputValue inp;
117119
int cha;
118120

119-
120121
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) {
121122
}
122123

@@ -145,7 +146,6 @@ class CloudTelevision : public Property {
145146
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) {}
146147

147148
virtual bool isDifferentFromCloud() {
148-
149149
return _value != _cloud_value;
150150
}
151151

@@ -183,7 +183,7 @@ class CloudTelevision : public Property {
183183
}
184184

185185
uint8_t getVolume() {
186-
return _value.vol;
186+
return static_cast<uint8_t>(_value.vol);
187187
}
188188

189189
void setMute(bool const mut) {

‎src/utility/time/TimeService.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
* INCLUDE
2020
**************************************************************************************/
2121

22-
#include <AIoTC_Config.h>
23-
2422
#include <time.h>
23+
2524
#include "TimeService.h"
2625
#include "NTPUtils.h"
26+
#include "AIoTC_Config.h"
2727
#include "AIoTC_Const.h"
2828

2929
#ifdef ARDUINO_ARCH_SAMD
@@ -112,7 +112,7 @@ TimeServiceClass::TimeServiceClass()
112112
: _con_hdl(nullptr)
113113
, _is_rtc_configured(false)
114114
, _is_tz_configured(false)
115-
, _timezone_offset(24 * 60 * 60)
115+
, _timezone_offset(static_cast<long>(24) * 60 * 60)
116116
, _timezone_dst_until(0)
117117
, _last_sync_tick(0)
118118
, _sync_interval_ms(TIMESERVICE_NTP_SYNC_TIMEOUT_ms)
@@ -324,7 +324,7 @@ bool TimeServiceClass::isTimeValid(unsigned long const time)
324324
bool TimeServiceClass::isTimeZoneOffsetValid(long const offset)
325325
{
326326
/* UTC offset can go from +14 to -12 hours */
327-
return ((offset < (14 * 60 * 60)) && (offset > (-12 * 60 * 60)));
327+
return ((offset < (static_cast<long>(14) * 60 * 60)) && (offset > (static_cast<long>(-12) * 60 * 60)));
328328
}
329329

330330
void TimeServiceClass::initRTC()

0 commit comments

Comments
 (0)
Please sign in to comment.