From a0e863a720ed888be88d21b70880dbd2a4f57dfc Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 11:42:07 +0100 Subject: [PATCH 01/46] Added ModuleNames --- edge/lib/brittany/src/modules/ModuleNames.h | 37 ++++++++++++++++++++ edge/test/brittany/main.cpp | 2 ++ edge/test/brittany/modules/ModuleNamesTest.h | 13 +++++++ 3 files changed, 52 insertions(+) create mode 100644 edge/lib/brittany/src/modules/ModuleNames.h create mode 100644 edge/test/brittany/modules/ModuleNamesTest.h diff --git a/edge/lib/brittany/src/modules/ModuleNames.h b/edge/lib/brittany/src/modules/ModuleNames.h new file mode 100644 index 0000000..ae3722c --- /dev/null +++ b/edge/lib/brittany/src/modules/ModuleNames.h @@ -0,0 +1,37 @@ +#ifndef MODULE_NAMES_H +#define MODULE_NAMES_H + +#include "hw/ComponentHw.h" +#include +#include +#include + +/** + * @brief Enum to define the module names used by the system. + */ +enum class ModuleNames { + Temperature, + Humidity, + Light +}; + +/** + * @brief Return the Module name as a string. + * + * @param moduleName the ModuleNames value. + * @return std::string A string that represent the passed value. + */ +inline std::string module_as_string(ModuleNames moduleName) { + switch (moduleName) { + case ModuleNames::Temperature: + return "temperature"; + case ModuleNames::Humidity: + return "humidity"; + case ModuleNames::Light: + return "light"; + default: + return ""; + } +} + +#endif // MODULE_NAMES_H \ No newline at end of file diff --git a/edge/test/brittany/main.cpp b/edge/test/brittany/main.cpp index 84ea07b..ef27fbb 100644 --- a/edge/test/brittany/main.cpp +++ b/edge/test/brittany/main.cpp @@ -10,6 +10,7 @@ #include "hw/MockDigitalLightHwTest.h" #include "hw/MockTempHumSensorHwTest.h" #include "modules/MockDigitalLightModuleTest.h" +#include "modules/ModuleNamesTest.h" #include "edge/EdgeTest.h" #include "edge/ThingDescriptorTest.h" #include "utilTest.h" @@ -32,6 +33,7 @@ void test_operation_handler() { void test_modules() { test_ComponentModuleTest(); //ModuleTest + test_ModuleNamesTest(); //ModuleNamesTest } void test_edge() { diff --git a/edge/test/brittany/modules/ModuleNamesTest.h b/edge/test/brittany/modules/ModuleNamesTest.h new file mode 100644 index 0000000..06a62c5 --- /dev/null +++ b/edge/test/brittany/modules/ModuleNamesTest.h @@ -0,0 +1,13 @@ +#include +#include "modules/ModuleNames.h" + +void test_module_as_string() { + TEST_ASSERT_EQUAL_STRING("light", module_as_string(ModuleNames::Light).c_str()); + TEST_ASSERT_EQUAL_STRING("temperature", module_as_string(ModuleNames::Temperature).c_str()); + TEST_ASSERT_EQUAL_STRING("humidity", module_as_string(ModuleNames::Humidity).c_str()); + TEST_ASSERT_EQUAL_STRING("", module_as_string(ModuleNames(104131)).c_str()); +} + +void test_ModuleNamesTest() { + RUN_TEST(test_module_as_string); +} \ No newline at end of file From eec3a3540e288703375ce347ce3ccbb18decad73 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 12:03:42 +0100 Subject: [PATCH 02/46] Mock Digital Light module will now always have name light --- .../mock-digital-light/modules/MockDigitalLightModule.h | 4 +++- edge/src/modules/mock-digital-light.h | 2 +- edge/test/brittany/edge/EdgeTest.h | 3 +-- edge/test/brittany/edge/ThingDescriptorTest.h | 6 ++---- edge/test/brittany/modules/MockDigitalLightModuleTest.h | 8 +++++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h b/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h index aac5f1c..e69cce5 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h @@ -8,6 +8,7 @@ #include "mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h" #include "mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h" #include "mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h" +#include "modules/ModuleNames.h" #define MOCK_IS_ON_HANDLER_MODULE_NAME "isOn" #define MOCK_TURN_ON_HANDLER_MODULE_NAME "turnOn" @@ -17,7 +18,8 @@ class MockDigitalLightModule : public ComponentModule { public: - MockDigitalLightModule(std::string name, std::list components): ComponentModule(name, components) { + MockDigitalLightModule(std::list components) + : ComponentModule(module_as_string(ModuleNames::Light), components) { _handlers.push_back( new MockIsOnDigitalLightHandler( MOCK_IS_ON_HANDLER_MODULE_NAME, diff --git a/edge/src/modules/mock-digital-light.h b/edge/src/modules/mock-digital-light.h index f2d46c6..df0216a 100644 --- a/edge/src/modules/mock-digital-light.h +++ b/edge/src/modules/mock-digital-light.h @@ -8,7 +8,7 @@ Edge* edge() { MockDigitalLightHw* light1 = new MockDigitalLightHw("1", 1); std::list lights = std::list({light0, light1}); std::list modules; - modules.push_back(new MockDigitalLightModule("light", lights)); + modules.push_back(new MockDigitalLightModule(lights)); return new Edge("Mock Digital Light Edge", modules); } diff --git a/edge/test/brittany/edge/EdgeTest.h b/edge/test/brittany/edge/EdgeTest.h index 5f86a74..dad2578 100644 --- a/edge/test/brittany/edge/EdgeTest.h +++ b/edge/test/brittany/edge/EdgeTest.h @@ -8,7 +8,6 @@ #define EDGE_MOCK_TITLE "MockEdge" #define EDGE_MOCK_MODULE_NAME "mock-module" -#define EDGE_MOCK_DIGITAL_LIGHT_MODULE_NAME "light-module" #define MOCK_LIGHT_IN_EDGE_NAME "light" #define MOCK_LIGHT_IN_EDGE_PIN 5 @@ -115,7 +114,7 @@ void test_edge_list() { Edge* edge = new Edge(EDGE_MOCK_TITLE, std::list({ new MockModule(EDGE_MOCK_MODULE_NAME), - new MockDigitalLightModule(EDGE_MOCK_DIGITAL_LIGHT_MODULE_NAME, mockDigitalLights) + new MockDigitalLightModule(mockDigitalLights) }) ); test_edge_title(edge); diff --git a/edge/test/brittany/edge/ThingDescriptorTest.h b/edge/test/brittany/edge/ThingDescriptorTest.h index 7d95fa5..d86429b 100644 --- a/edge/test/brittany/edge/ThingDescriptorTest.h +++ b/edge/test/brittany/edge/ThingDescriptorTest.h @@ -5,7 +5,6 @@ #include "mock-digital-light/modules/MockDigitalLightModule.h" #define EDGE_MOCK_TITLE_TD "MockEdge" -#define MOCK_MODULE_TD_NAME "light-module" #define MOCK_LIGHT_TD_0_ID "0" #define MOCK_LIGHT_TD_1_ID "1" @@ -59,7 +58,7 @@ void contains_modules() { TEST_ASSERT_TRUE(modulesArray.isArray()); Json::Value moduleObj = modulesArray[0]; TEST_ASSERT_TRUE(moduleObj.isMember("module")); - TEST_ASSERT_EQUAL_STRING(MOCK_MODULE_TD_NAME, moduleObj["module"].asCString()); + TEST_ASSERT_EQUAL_STRING(module_as_string(ModuleNames::Light).c_str(), moduleObj["module"].asCString()); TEST_ASSERT_TRUE(moduleObj.isMember("components")); Json::Value moduleComponents = moduleObj["components"]; TEST_ASSERT_TRUE(moduleComponents.isArray()); @@ -87,7 +86,7 @@ void check_actions_and_properties(Json::Value object, std::string names[], int s for(std::string c : tdComponents) { Json::Value name = object[names[i] + "-" + c]; TEST_ASSERT_TRUE(name.isMember("module")); - TEST_ASSERT_EQUAL_STRING(MOCK_MODULE_TD_NAME, name["module"].asCString()); + TEST_ASSERT_EQUAL_STRING(module_as_string(ModuleNames::Light).c_str(), name["module"].asCString()); TEST_ASSERT_TRUE(name.isMember("forms")); Json::Value forms = name["forms"]; TEST_ASSERT_TRUE(forms.isArray()); @@ -148,7 +147,6 @@ void setup_thing_descriptor_test() { tdEdge = new Edge(EDGE_MOCK_TITLE_TD, std::list({ new MockDigitalLightModule( - MOCK_MODULE_TD_NAME, std::list({mockLight0, mockLight1}) )} ) diff --git a/edge/test/brittany/modules/MockDigitalLightModuleTest.h b/edge/test/brittany/modules/MockDigitalLightModuleTest.h index 674ae85..0380216 100644 --- a/edge/test/brittany/modules/MockDigitalLightModuleTest.h +++ b/edge/test/brittany/modules/MockDigitalLightModuleTest.h @@ -7,7 +7,6 @@ #include "mock-digital-light/modules/MockDigitalLightModule.h" #include "modules/Module.h" -#define MOCK_MODULE_NAME "light" #define MOCK_LIGHT_IN_MODULE_NAME_0 "light0" #define MOCK_LIGHT_IN_MODULE_NAME_1 "light1" @@ -26,7 +25,7 @@ void setup_module_test() { lightInModule1 = new MockDigitalLightHw(MOCK_LIGHT_IN_MODULE_NAME_1, MOCK_LIGHT_IN_MODULE_PIN_1); components.push_back(lightInModule0); components.push_back(lightInModule1); - moduleTest = new MockDigitalLightModule(MOCK_MODULE_NAME, components); + moduleTest = new MockDigitalLightModule(components); } void post_module_test() { @@ -87,7 +86,10 @@ void test_is_on_handler_in_module(OperationHandler* handler, std::string compone // TEST void test_module_name() { - TEST_ASSERT_EQUAL_STRING(MOCK_MODULE_NAME, moduleTest -> name().c_str()); + TEST_ASSERT_EQUAL_STRING( + module_as_string(ModuleNames::Light).c_str(), + moduleTest -> name().c_str() + ); } // TEST From d33c48314ca4904e134748b6a9e3880cd53268c7 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 12:14:22 +0100 Subject: [PATCH 03/46] restore id always shows app in action properties and events --- .../brittany/src/thing-descriptor/ThingDescriptorBuilder.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h b/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h index 93d3682..b18c682 100644 --- a/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h +++ b/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h @@ -73,10 +73,7 @@ class ThingDescriptorBuilder { std::string("http://") + ip + ":" + std::to_string(port) + h -> path() + "?id=" + c.id(); object["forms"][0]["contentType"] = "application/json"; std::string objectName; - std::string name = h -> name(); - if(cm->components().size() != 1) { - name += "-" + c.id(); - } + std::string name = h -> name() + "-" + c.id(); std::string type = type_to_string(h -> outputType()); switch (h -> operationType()) { case OperationType::ACTION: From 517fd415458bcfd178c2ede231493cf54ad0bfa8 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 12:24:40 +0100 Subject: [PATCH 04/46] Added Sensor Temp and Hum interfaces --- .../sensors/HumiditySensorHwInterface.h | 30 +++++++++++++++++++ .../sensors/TemperatureSensorHwInterface.h | 29 ++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h create mode 100644 edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h diff --git a/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h b/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h new file mode 100644 index 0000000..37380ca --- /dev/null +++ b/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h @@ -0,0 +1,30 @@ +#ifndef BRITTANY_HUMIDITY_SENSOR_HW_INTERFACE_H +#define BRITTANY_HUMIDITY_SENSOR_HW_INTERFACE_H + +#include +#include "../ComponentHw.h" +#include "../feature/OnePin.h" +#include "../feature/Humidity.h" + + +/** + * @brief An interface to create a component that represents a sensor that can + * obtain humidity(air) values. + */ +class HumiditySensorHwInterface : + public ComponentHw, + public OnePin, + public Humidity { + +public: + + HumiditySensorHwInterface(std::string id, uint8_t pin) : + ComponentHw(id), + OnePin(pin), + Humidity() { + + }; + +}; + +#endif //BRITTANY_HUMIDITY_SENSOR_HW_INTERFACE_H \ No newline at end of file diff --git a/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h b/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h new file mode 100644 index 0000000..619ee0d --- /dev/null +++ b/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h @@ -0,0 +1,29 @@ +#ifndef BRITTANY_TEMPERATURE_SENSOR_HW_INTERFACE_H +#define BRITTANY_TEMPERATURE_SENSOR_HW_INTERFACE_H + +#include +#include "../ComponentHw.h" +#include "../feature/OnePin.h" +#include "../feature/Temperature.h" + +/** + * @brief An interface to create a component that represents a sensor that can + * obtain temperature(air) values. + */ +class TemperatureSensorHwInterface : + public ComponentHw, + public OnePin, + public Temperature{ + +public: + + TemperatureSensorHwInterface(std::string id, uint8_t pin) : + ComponentHw(id), + OnePin(pin), + Temperature() { + + }; + +}; + +#endif //BRITTANY_TEMPERATURE_SENSOR_HW_INTERFACE_H \ No newline at end of file From 1e0050fdadda2530846f0784ce8e108ad02215d7 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 12:25:50 +0100 Subject: [PATCH 05/46] Removed OnePin constructore from Temp and Hum Interfaces --- .../src/hw/interfaces/sensors/HumiditySensorHwInterface.h | 5 +---- .../src/hw/interfaces/sensors/TemperatureSensorHwInterface.h | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h b/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h index 37380ca..b541385 100644 --- a/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h +++ b/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h @@ -3,7 +3,6 @@ #include #include "../ComponentHw.h" -#include "../feature/OnePin.h" #include "../feature/Humidity.h" @@ -13,14 +12,12 @@ */ class HumiditySensorHwInterface : public ComponentHw, - public OnePin, public Humidity { public: - HumiditySensorHwInterface(std::string id, uint8_t pin) : + HumiditySensorHwInterface(std::string id) : ComponentHw(id), - OnePin(pin), Humidity() { }; diff --git a/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h b/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h index 619ee0d..636970c 100644 --- a/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h +++ b/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h @@ -12,14 +12,12 @@ */ class TemperatureSensorHwInterface : public ComponentHw, - public OnePin, public Temperature{ public: - TemperatureSensorHwInterface(std::string id, uint8_t pin) : + TemperatureSensorHwInterface(std::string id) : ComponentHw(id), - OnePin(pin), Temperature() { }; From 5a090a565cdeb86c9a0d380775786b304f90987b Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 12:51:10 +0100 Subject: [PATCH 06/46] added random min max function --- edge/lib/brittany/src/util.h | 18 ++++++++++++++++++ edge/test/brittany/utilTest.h | 13 +++++++++++++ 2 files changed, 31 insertions(+) diff --git a/edge/lib/brittany/src/util.h b/edge/lib/brittany/src/util.h index d2a8733..1ce2d33 100644 --- a/edge/lib/brittany/src/util.h +++ b/edge/lib/brittany/src/util.h @@ -5,6 +5,7 @@ #include #include #include +#include enum class ContentResult { Ok, @@ -68,4 +69,21 @@ inline std::optional find_by_id(std::list list, std::string id) { return std::nullopt; } +/** + * @brief Return a random number from min to max (inclusive) + * + * @param min the min number that could be returned. + * @param max the max number that could be returned. + * @return int the random number. + */ +inline int random(int min, int max) { + static bool first = true; + if (first) + { + srand( time(NULL) ); //seeding for the first time only! + first = false; + } + return min + rand() % (( max + 1 ) - min); +} + #endif //BRITTANY_UTIL_H \ No newline at end of file diff --git a/edge/test/brittany/utilTest.h b/edge/test/brittany/utilTest.h index 69123bf..a193ffc 100644 --- a/edge/test/brittany/utilTest.h +++ b/edge/test/brittany/utilTest.h @@ -4,6 +4,7 @@ #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "util.h" +#define UTIL_TEST_RANDOM_ATTEMPT 100 #define COMPONENT_0_NAME "name0" #define COMPONENT_1_NAME "name1" #define COMPONENT_2_NAME "name2" @@ -37,8 +38,20 @@ void test_util_find_by_id() { TEST_ASSERT_FALSE(find_by_id(list, "the game").has_value()); } +void test_util_random() { + TEST_ASSERT_EQUAL(1, random(1,1)); + TEST_ASSERT_EQUAL(2, random(2,2)); + int min = 0; + int max = 20; + for(int i = 0; i <= UTIL_TEST_RANDOM_ATTEMPT; i++) { + int r = random(min, max); + TEST_ASSERT_TRUE(r >= min && r<= max); + } +} + void test_util() { setup_util_test(); RUN_TEST(test_util_find_by_id); + RUN_TEST(test_util_random); post_util_test(); } From 42b83ae81f35c2208da101f95721d2596c6b6f5e Mon Sep 17 00:00:00 2001 From: ElisaTronetti Date: Wed, 12 Jan 2022 14:05:56 +0000 Subject: [PATCH 07/46] Changed import of .h files --- edge/build.gradle.kts | 2 +- edge/lib/brittany-concrete/src/web-server/Esp8266WebServer.h | 3 ++- edge/src/main.cpp | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/edge/build.gradle.kts b/edge/build.gradle.kts index ef3c6cb..8aa2646 100644 --- a/edge/build.gradle.kts +++ b/edge/build.gradle.kts @@ -11,5 +11,5 @@ tasks.register("testRealHw") { } tasks.register("upload") { - commandLine("pio", "run", "-e", "nodemcuv2", "-t", "upload") + commandLine("pio", "run", "-e", "mock-digital-light", "-t", "upload", "-t", "monitor") } diff --git a/edge/lib/brittany-concrete/src/web-server/Esp8266WebServer.h b/edge/lib/brittany-concrete/src/web-server/Esp8266WebServer.h index 28308d7..2d06d60 100644 --- a/edge/lib/brittany-concrete/src/web-server/Esp8266WebServer.h +++ b/edge/lib/brittany-concrete/src/web-server/Esp8266WebServer.h @@ -3,10 +3,11 @@ #include "web-server/WebServer.h" #include "edge/Edge.h" -#include "ESP8266WebServer.h" +#include #include "HttpStatusCodes_C++.h" #include "json_util.h" #include "util/DebugPrint.h" +#include /** * @brief ESP8266WebServer implementation of web server. diff --git a/edge/src/main.cpp b/edge/src/main.cpp index 3680852..74c6c45 100644 --- a/edge/src/main.cpp +++ b/edge/src/main.cpp @@ -6,6 +6,7 @@ #include "modules/Module.h" #include "modules/dht22.h" #include "modules/mock-digital-light.h" +#include Esp8266WebServer* server; From f0e93285d3109383ce1431331f89f5ff9d42057e Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 15:30:51 +0100 Subject: [PATCH 08/46] Added MockTemperatureSensorHw --- .../hw/MockTemperatureSensorHw.h | 43 +++++++++++++++ .../sensors/TemperatureSensorHwInterface.h | 5 +- .../brittany/hw/MockTemperatureSensorHwTest.h | 52 +++++++++++++++++++ edge/test/brittany/main.cpp | 2 + 4 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 edge/lib/brittany-mock/src/mock-temperature-sensor/hw/MockTemperatureSensorHw.h create mode 100644 edge/test/brittany/hw/MockTemperatureSensorHwTest.h diff --git a/edge/lib/brittany-mock/src/mock-temperature-sensor/hw/MockTemperatureSensorHw.h b/edge/lib/brittany-mock/src/mock-temperature-sensor/hw/MockTemperatureSensorHw.h new file mode 100644 index 0000000..292360f --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-temperature-sensor/hw/MockTemperatureSensorHw.h @@ -0,0 +1,43 @@ +#ifndef MOCK_TEMPERATURE_SENSOR_HW_H +#define MOCK_TEMPERATURE_SENSOR_HW_H + +#include "hw/interfaces/sensors/TemperatureSensorHwInterface.h" + +#define MOCK_MAX_TEMPERATURE_CELSIUS 40 + +/** + * @brief Mock Implementation of a temperature sensor hw. + */ +class MockTemperatureSensorHw : public TemperatureSensorHwInterface { + +public: + + /** + * @brief Construct a new MockTemperatureSensorHw object. + * + * @param id the hw id. + */ + MockTemperatureSensorHw(std::string id) : TemperatureSensorHwInterface(id) { }; + + std::optional temperatureCelsius() { + return random(0, MOCK_MAX_TEMPERATURE_CELSIUS); + } + + std::optional temperatureKelvin() { + std::optional tempC = temperatureCelsius(); + if(tempC.has_value()){ + return std::optional(Temperature::fromCToK(tempC.value())); + } + return std::nullopt; + } + + std::optional temperatureFahrenheit(){ + std::optional tempC = temperatureCelsius(); + if(tempC.has_value()){ + return std::optional(Temperature::fromCToF(tempC.value())); + } + return std::nullopt; + } + +}; +#endif //MOCK_TEMPERATURE_SENSOR_HW_H diff --git a/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h b/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h index 636970c..f364812 100644 --- a/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h +++ b/edge/lib/brittany/src/hw/interfaces/sensors/TemperatureSensorHwInterface.h @@ -2,9 +2,8 @@ #define BRITTANY_TEMPERATURE_SENSOR_HW_INTERFACE_H #include -#include "../ComponentHw.h" -#include "../feature/OnePin.h" -#include "../feature/Temperature.h" +#include "hw/ComponentHw.h" +#include "hw/feature/Temperature.h" /** * @brief An interface to create a component that represents a sensor that can diff --git a/edge/test/brittany/hw/MockTemperatureSensorHwTest.h b/edge/test/brittany/hw/MockTemperatureSensorHwTest.h new file mode 100644 index 0000000..258c456 --- /dev/null +++ b/edge/test/brittany/hw/MockTemperatureSensorHwTest.h @@ -0,0 +1,52 @@ +#include +#include +#include "mock-temperature-sensor/hw/MockTemperatureSensorHw.h" + +#define MOCK_TEMPERATURE_TEST_ATTEMPT 100 +#define MOCK_TEMPERATURE_SENSOR_NAME "jotaro" + +MockTemperatureSensorHw mockTemperatureSensor = + MockTemperatureSensorHw(MOCK_TEMPERATURE_SENSOR_NAME); + + +void mock_temperature_value_is_valid(int value, int min, int max) { + TEST_ASSERT_TRUE(value <= max && value >= min); +} + +void test_mock_temperature_celsius() { + std::optional tempC = mockTemperatureSensor.temperatureCelsius(); + TEST_ASSERT_TRUE(tempC.has_value()); + mock_temperature_value_is_valid(tempC.value(), 0, MOCK_MAX_TEMPERATURE_CELSIUS); +} + +void test_mock_temperature_fahrenheit() { + std::optional tempF = mockTemperatureSensor.temperatureFahrenheit(); + TEST_ASSERT_TRUE(tempF.has_value()); + mock_temperature_value_is_valid( + tempF.value(), + Temperature::fromCToF(0), + Temperature::fromCToF(MOCK_MAX_TEMPERATURE_CELSIUS) + ); +} + +void test_mock_temperature_kelvin() { + std::optional tempK = mockTemperatureSensor.temperatureKelvin(); + TEST_ASSERT_TRUE(tempK.has_value()); + mock_temperature_value_is_valid( + tempK.value(), + Temperature::fromCToK(0), + Temperature::fromCToK(MOCK_MAX_TEMPERATURE_CELSIUS) + ); +} + +void test_mock_temperature() { + for(int i = 0; i < MOCK_TEMPERATURE_TEST_ATTEMPT; i++) { + test_mock_temperature_celsius(); + test_mock_temperature_fahrenheit(); + test_mock_temperature_kelvin(); + } +} + +void test_MockTemperatureSensorHwTest() { + RUN_TEST(test_mock_temperature); +} diff --git a/edge/test/brittany/main.cpp b/edge/test/brittany/main.cpp index ef27fbb..9d4ffc6 100644 --- a/edge/test/brittany/main.cpp +++ b/edge/test/brittany/main.cpp @@ -9,6 +9,7 @@ #include "hw/OnePinTest.h" #include "hw/MockDigitalLightHwTest.h" #include "hw/MockTempHumSensorHwTest.h" +#include "hw/MockTemperatureSensorHwTest.h" #include "modules/MockDigitalLightModuleTest.h" #include "modules/ModuleNamesTest.h" #include "edge/EdgeTest.h" @@ -20,6 +21,7 @@ void test_hw() { test_OnePin(); //OnePinTest test_MockDigitalLightHw(); //MockDigitalLightHwTest test_MockTempHumSensorHwTest(); //MockTempHumSensorHwTest + test_MockTemperatureSensorHwTest(); //MockTemperatureSensoreHwTest } void test_operation_handler() { From 49d894f68954189a4e51e4c74e85608d99e0c7e5 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 15:47:31 +0100 Subject: [PATCH 09/46] Added MockHumiditySensorHw --- .../hw/MockHumiditySensorHw.h | 28 ++++++++++++++++++ .../hw/MockTemperatureSensorHw.h | 2 +- .../sensors/HumiditySensorHwInterface.h | 5 ++-- .../brittany/hw/MockHumiditySensorHwTest.h | 29 +++++++++++++++++++ edge/test/brittany/main.cpp | 2 ++ 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 edge/lib/brittany-mock/src/mock-humidity-sensor/hw/MockHumiditySensorHw.h create mode 100644 edge/test/brittany/hw/MockHumiditySensorHwTest.h diff --git a/edge/lib/brittany-mock/src/mock-humidity-sensor/hw/MockHumiditySensorHw.h b/edge/lib/brittany-mock/src/mock-humidity-sensor/hw/MockHumiditySensorHw.h new file mode 100644 index 0000000..d388930 --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-humidity-sensor/hw/MockHumiditySensorHw.h @@ -0,0 +1,28 @@ +#ifndef MOCK_HUMIDITY_SENSOR_HW_H +#define MOCK_HUMIDITY_SENSOR_HW_H + +#include "hw/interfaces/sensors/HumiditySensorHwInterface.h" +#include "util.h" + +#define MOCK_MAX_HUMIDITY 100 + +/** + * @brief Mock Implementation of a humidity sensor hw. + */ +class MockHumiditySensorHw : public HumiditySensorHwInterface { + +public: + + /** + * @brief Construct a new MockHumiditySensorHw object. + * + * @param id the hw id. + */ + MockHumiditySensorHw(std::string id) : HumiditySensorHwInterface(id) { }; + + std::optional humidity() { + return std::optional(random(0, MOCK_MAX_HUMIDITY)); + } + +}; +#endif //MOCK_HUMIDITY_SENSOR_HW_H diff --git a/edge/lib/brittany-mock/src/mock-temperature-sensor/hw/MockTemperatureSensorHw.h b/edge/lib/brittany-mock/src/mock-temperature-sensor/hw/MockTemperatureSensorHw.h index 292360f..64b6c99 100644 --- a/edge/lib/brittany-mock/src/mock-temperature-sensor/hw/MockTemperatureSensorHw.h +++ b/edge/lib/brittany-mock/src/mock-temperature-sensor/hw/MockTemperatureSensorHw.h @@ -20,7 +20,7 @@ class MockTemperatureSensorHw : public TemperatureSensorHwInterface { MockTemperatureSensorHw(std::string id) : TemperatureSensorHwInterface(id) { }; std::optional temperatureCelsius() { - return random(0, MOCK_MAX_TEMPERATURE_CELSIUS); + return std::optional(random(0, MOCK_MAX_TEMPERATURE_CELSIUS)); } std::optional temperatureKelvin() { diff --git a/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h b/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h index b541385..4e8dd25 100644 --- a/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h +++ b/edge/lib/brittany/src/hw/interfaces/sensors/HumiditySensorHwInterface.h @@ -2,9 +2,8 @@ #define BRITTANY_HUMIDITY_SENSOR_HW_INTERFACE_H #include -#include "../ComponentHw.h" -#include "../feature/Humidity.h" - +#include "hw/ComponentHw.h" +#include "hw/feature/Humidity.h" /** * @brief An interface to create a component that represents a sensor that can diff --git a/edge/test/brittany/hw/MockHumiditySensorHwTest.h b/edge/test/brittany/hw/MockHumiditySensorHwTest.h new file mode 100644 index 0000000..0a89461 --- /dev/null +++ b/edge/test/brittany/hw/MockHumiditySensorHwTest.h @@ -0,0 +1,29 @@ +#include +#include +#include "mock-humidity-sensor/hw/MockHumiditySensorHw.h" + +#define MOCK_HUMIDITY_TEST_ATTEMPT 100 +#define MOCK_HUMIDITY_SENSOR_NAME "jotaro" + +MockHumiditySensorHw mockHumiditySensor = + MockHumiditySensorHw(MOCK_HUMIDITY_SENSOR_NAME); + +void mock_humidity_value_is_valid(int value, int min, int max) { + TEST_ASSERT_TRUE(value <= max && value >= min); +} + +void test_mock_humidity_value() { + std::optional hum = mockHumiditySensor.humidity(); + TEST_ASSERT_TRUE(hum.has_value()); + mock_temperature_value_is_valid(hum.value(), 0, MOCK_MAX_HUMIDITY); +} + +void test_mock_humidity_sensor() { + for(int i = 0; i < MOCK_TEMPERATURE_TEST_ATTEMPT; i++) { + test_mock_humidity_value(); + } +} + +void test_MockHumiditySensorHwTest() { + RUN_TEST(test_mock_humidity_sensor); +} diff --git a/edge/test/brittany/main.cpp b/edge/test/brittany/main.cpp index 9d4ffc6..a0b225f 100644 --- a/edge/test/brittany/main.cpp +++ b/edge/test/brittany/main.cpp @@ -10,6 +10,7 @@ #include "hw/MockDigitalLightHwTest.h" #include "hw/MockTempHumSensorHwTest.h" #include "hw/MockTemperatureSensorHwTest.h" +#include "hw/MockHumiditySensorHwTest.h" #include "modules/MockDigitalLightModuleTest.h" #include "modules/ModuleNamesTest.h" #include "edge/EdgeTest.h" @@ -22,6 +23,7 @@ void test_hw() { test_MockDigitalLightHw(); //MockDigitalLightHwTest test_MockTempHumSensorHwTest(); //MockTempHumSensorHwTest test_MockTemperatureSensorHwTest(); //MockTemperatureSensoreHwTest + test_MockHumiditySensorHwTest(); //MockTemperatureSensoreHwTest } void test_operation_handler() { From 1b0e71477c45b15d6f336b191cc7dca597aeea60 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 15:48:33 +0100 Subject: [PATCH 10/46] deleted useless handler, how did it get here? --- .../MockGetTemperatureHandler.h | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 edge/lib/brittany-mock/src/mock-temp-hum-sensor/operaion-handler/MockGetTemperatureHandler.h diff --git a/edge/lib/brittany-mock/src/mock-temp-hum-sensor/operaion-handler/MockGetTemperatureHandler.h b/edge/lib/brittany-mock/src/mock-temp-hum-sensor/operaion-handler/MockGetTemperatureHandler.h deleted file mode 100644 index 37b1850..0000000 --- a/edge/lib/brittany-mock/src/mock-temp-hum-sensor/operaion-handler/MockGetTemperatureHandler.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef BRITTANY_DHT22_GET_TEMPERATURE_HANDLER_H -#define BRITTANY_DHT22_GET_TEMPERATURE_HANDLER_H - -#include -#include - -class DHT22GetTemperatureHandler : public DHT22Handler { - -public: - - DHT22GetTemperatureHandler( - std::string name, - std::string path, - std::list components - ); - -private: - - std::optional sub_operation(DHT22SensorHw* hw, Json::Value args); - - std::list _components; -}; - -#endif //BRITTANY_DHT22_GET_TEMPERATURE_HANDLER_H From 7183f0c26e48c2830a8ff8e4c0fc45dc3e34238d Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 16:34:47 +0100 Subject: [PATCH 11/46] Applied DRY by adding an intermediate operation handler interface for value returned --- .../dht22/operation-handler/DHT22Handler.h | 20 ++-------- .../RetrieveValueFromComponentInterface.h | 37 +++++++++++++++++++ edge/lib/brittany/src/util.h | 6 --- 3 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h diff --git a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22Handler.h b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22Handler.h index a59649c..33c7192 100644 --- a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22Handler.h +++ b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22Handler.h @@ -3,34 +3,22 @@ #include #include -#include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h" +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" #include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h" -class DHT22Handler : public ValueReturnedAfterActionHandlerInterface { +class DHT22Handler : public RetrieveValueFromComponentInterface { public: DHT22Handler(std::string name, std::string path, std::list components) - : ValueReturnedAfterActionHandlerInterface (name, path, OperationType::PROPERTY, Type::NUMBER) { - _components = components; + : RetrieveValueFromComponentInterface (name, path, components) { + }; private: - std::optional retrieveValue(Json::Value args) { - std::optional oc = find_by_id(_components, args["id"].asCString()); - if(oc.has_value()) { - std::optional opt_value = sub_operation(oc.value(), args); - if(opt_value.has_value()) { - return opt_value.value(); - } - } - return std::nullopt; - } - virtual std::optional sub_operation(DHT22SensorHw* hw, Json::Value args) = 0; - std::list _components; }; #endif //BRITTANY_DHT22_HANDLER_H diff --git a/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h b/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h new file mode 100644 index 0000000..7f6201e --- /dev/null +++ b/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h @@ -0,0 +1,37 @@ +#ifndef RETRIEVE_VALUE_FROM_COMPONENT_INTERFACE_H +#define RETRIEVE_VALUE_FROM_COMPONENT_INTERFACE_H + +#include +#include +#include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h" + +template + +class RetrieveValueFromComponentInterface : public ValueReturnedAfterActionHandlerInterface { + +public: + + RetrieveValueFromComponentInterface(std::string name, std::string path, std::list components) + : ValueReturnedAfterActionHandlerInterface (name, path, OperationType::PROPERTY, Type::NUMBER) { + _components = components; + }; + +private: + + std::optional retrieveValue(Json::Value args) { + std::optional oc = find_by_id(_components, args["id"].asCString()); + if(oc.has_value()) { + std::optional opt_value = sub_operation(oc.value(), args); + if(opt_value.has_value()) { + return opt_value.value(); + } + } + return std::nullopt; + } + + virtual std::optional sub_operation(C* hw, Json::Value args) = 0; + + std::list _components; +}; + +#endif //RETRIEVE_VALUE_FROM_COMPONENT_INTERFACE_H diff --git a/edge/lib/brittany/src/util.h b/edge/lib/brittany/src/util.h index 1ce2d33..6bef109 100644 --- a/edge/lib/brittany/src/util.h +++ b/edge/lib/brittany/src/util.h @@ -77,12 +77,6 @@ inline std::optional find_by_id(std::list list, std::string id) { * @return int the random number. */ inline int random(int min, int max) { - static bool first = true; - if (first) - { - srand( time(NULL) ); //seeding for the first time only! - first = false; - } return min + rand() % (( max + 1 ) - min); } From d90dd3b75dda49c00fce965f44bf66b89d0c9d4f Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 17:36:53 +0100 Subject: [PATCH 12/46] Added MockHumidityHandler --- .../operation-handler/MockHumidityHandler.h | 26 +++++++ edge/test/brittany/main.cpp | 2 + .../MockHumidityHandlerTest.h | 68 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h create mode 100644 edge/test/brittany/operation-handler/MockHumidityHandlerTest.h diff --git a/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h b/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h new file mode 100644 index 0000000..8d3efdb --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h @@ -0,0 +1,26 @@ +#ifndef MOCK_HUMIDITY_HANDLER_H +#define MOCK_HUMIDITY_HANDLER_H + +#include +#include +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" +#include "mock-humidity-sensor/hw/MockHumiditySensorHw.h" + +class MockHumidityHandler : public RetrieveValueFromComponentInterface { + +public: + + MockHumidityHandler(std::string name, std::string path, std::list components) + : RetrieveValueFromComponentInterface (name, path, components) { + + }; + +private: + + std::optional sub_operation(MockHumiditySensorHw* hw, Json::Value args) { + return hw-> humidity(); + } + +}; + +#endif // MOCK_HUMIDITY_HANDLER_H \ No newline at end of file diff --git a/edge/test/brittany/main.cpp b/edge/test/brittany/main.cpp index a0b225f..69ea5d7 100644 --- a/edge/test/brittany/main.cpp +++ b/edge/test/brittany/main.cpp @@ -2,6 +2,7 @@ #include "operation-handler/OperationHandlerResultTest.h" #include "operation-handler/OperationHandlerTest.h" #include "operation-handler/MockDigitalLightHandlersTest.h" +#include "operation-handler/MockHumidityHandlerTest.h" #include "operation-handler/util/ValueReturnedResultTest.h" #include "operation-handler/util/ValueReturnedResultFactoryTest.h" #include "operation-handler/types/TypeTest.h" @@ -30,6 +31,7 @@ void test_operation_handler() { test_OperationHandlerResult(); //OperationHandlerResultTest test_OperationHandler(); //OperationHandlerTest test_MockDigitalLightHandlersTest(); //MockDigitalLightHandlersTest + test_MockHumidityHandler(); //MockHumidityHandlerTest test_ValueReturnedResultTest(); //ValueReturnedResultTest test_ValueReturnedResultFactoryTest(); //ValueReturnedResultFactoryTest test_Type(); //TypeTest diff --git a/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h b/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h new file mode 100644 index 0000000..f44431b --- /dev/null +++ b/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h @@ -0,0 +1,68 @@ +#include +#include +#include "mock-humidity-sensor/operation-handler/MockHumidityHandler.h" +#include "mock-humidity-sensor/hw/MockHumiditySensorHw.h" + +#define MOCK_HUMIDITY_SENSOR_NAME_IN_HANDLER "sensor" +#define MOCK_HUMIDITY_HANDLER_NAME "humidity" + +MockHumidityHandler* mockHumidityHandler; +MockHumiditySensorHw* mockHumSensor; + +Json::Value argsMockHumSensor; +Json::Value argsMockHumSensorBadReq; +Json::Value argsMockHumSensorNotFound; + +void setup_mock_humidity_handler() { + mockHumSensor = new MockHumiditySensorHw(MOCK_HUMIDITY_SENSOR_NAME_IN_HANDLER); + argsMockHumSensor["id"] = MOCK_HUMIDITY_SENSOR_NAME_IN_HANDLER; + argsMockHumSensorBadReq["za"] = "warudo"; + argsMockHumSensorNotFound["id"] = "giogia"; + std::list list = {mockHumSensor}; + mockHumidityHandler = new MockHumidityHandler( + MOCK_HUMIDITY_HANDLER_NAME, + as_route(MOCK_HUMIDITY_HANDLER_NAME), + list + ); +} + +void post_mock_humidity_handler() { + delete mockHumSensor; +} + +void test_mock_humidity_handler_success() { + OperationHandlerResult r = mockHumidityHandler -> handle(argsMockHumSensor); + TEST_ASSERT_EQUAL(HttpStatus::OK, r.code()); + float c = r.content().asFloat(); + TEST_ASSERT_TRUE(c >= 0 && c <= MOCK_MAX_HUMIDITY); +} + +void test_mock_humidity_handler_not_found() { + OperationHandlerResult r = mockHumidityHandler -> handle(argsMockHumSensorNotFound); + TEST_ASSERT_EQUAL(HttpStatus::NotFound, r.code()); + TEST_ASSERT_EQUAL_STRING( + phrase(ContentResult::ResourceNotFound).c_str(), + r.content().asCString() + ); +} + +void test_mock_humidity_handler_bad_req() { + OperationHandlerResult r = mockHumidityHandler -> handle(argsMockHumSensorBadReq); + TEST_ASSERT_EQUAL(HttpStatus::BadRequest, r.code()); + TEST_ASSERT_EQUAL_STRING( + phrase(ContentResult::BadRequest).c_str(), + r.content().asCString() + ); +} + +void test_mock_humidity_handler_handle() { + test_mock_humidity_handler_success(); + test_mock_humidity_handler_not_found(); + test_mock_humidity_handler_bad_req(); +} + +void test_MockHumidityHandler() { + setup_mock_humidity_handler(); + RUN_TEST(test_mock_humidity_handler_handle); + post_mock_humidity_handler(); +} \ No newline at end of file From 594e4a76db360fa0a1b7e9e11899a67570f74899 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 19:15:48 +0100 Subject: [PATCH 13/46] Added MockHumidityModule --- .../modules/MockHumidityModule.h | 30 ++++++++++++ .../modules/MockDigitalLightModuleTest.h | 1 - .../brittany/modules/MockHumidityModuleTest.h | 46 +++++++++++++++++++ .../MockHumidityHandlerTest.h | 36 ++++++++++----- 4 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h create mode 100644 edge/test/brittany/modules/MockHumidityModuleTest.h diff --git a/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h b/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h new file mode 100644 index 0000000..6a54f6d --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h @@ -0,0 +1,30 @@ +#ifndef BRITTANY_MOCK_HUMIDITY_MODULE_H +#define BRITTANY_MOCK_HUMIDITY_MODULE_H + +#include +#include "operation-handler/OperationHandler.h" +#include "mock-humidity-sensor/hw/MockHumiditySensorHw.h" +#include "mock-humidity-sensor/operation-handler/MockHumidityHandler.h" +#include "modules/ComponentModule.h" +#include "modules/ModuleNames.h" + +#define MOCK_HUMIDITY_HANDLER_NAME "humidity" + +class MockHumidityModule : public ComponentModule { + +public: + + MockHumidityModule(std::list components) + : ComponentModule(module_as_string(ModuleNames::Humidity), components) { + _handlers.push_back( + new MockHumidityHandler( + MOCK_HUMIDITY_HANDLER_NAME, + as_route(MOCK_HUMIDITY_HANDLER_NAME), + components + ) + ); + }; + +}; + +#endif //BRITTANY_MOCK_HUMIDITY_MODULE_H \ No newline at end of file diff --git a/edge/test/brittany/modules/MockDigitalLightModuleTest.h b/edge/test/brittany/modules/MockDigitalLightModuleTest.h index 0380216..10485cb 100644 --- a/edge/test/brittany/modules/MockDigitalLightModuleTest.h +++ b/edge/test/brittany/modules/MockDigitalLightModuleTest.h @@ -5,7 +5,6 @@ #include "mock/operation-handler/MockOperationHandler.h" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "mock-digital-light/modules/MockDigitalLightModule.h" -#include "modules/Module.h" #define MOCK_LIGHT_IN_MODULE_NAME_0 "light0" #define MOCK_LIGHT_IN_MODULE_NAME_1 "light1" diff --git a/edge/test/brittany/modules/MockHumidityModuleTest.h b/edge/test/brittany/modules/MockHumidityModuleTest.h new file mode 100644 index 0000000..138e4f2 --- /dev/null +++ b/edge/test/brittany/modules/MockHumidityModuleTest.h @@ -0,0 +1,46 @@ +#ifndef MOCK_HUMIDITY_MODULE_TEST_H +#define MOCK_HUMIDITY_MODULE_TEST_H + +#include +#include +#include "mock-humidity-sensor/modules/MockHumidityModule.h" +#include "../operation-handler/MockHumidityHandlerTest.h" + +MockHumidityModule* mockHumidityModule; + +void setup_humidity_module_test(std::list components) { + mockHumidityModule = new MockHumidityModule(components); +} + +void post_humidity_module_test() { + delete mockHumidityModule; +} + +void test_humidity_module_name() { + TEST_ASSERT_EQUAL_STRING( + module_as_string(ModuleNames::Humidity).c_str(), + mockHumidityModule -> name().c_str() + ); +} + +void test_humidity_module_components() { + std::list comps = mockHumidityModule -> components(); + TEST_ASSERT_EQUAL(1, comps.size()); + TEST_ASSERT_EQUAL_STRING(MOCK_HUMIDITY_SENSOR_NAME_IN_HANDLER, comps.front().id().c_str()); +} + +void test_humidity_module_get_handlers() { + std::list handlers = mockHumidityModule -> handlers(); + TEST_ASSERT_EQUAL(1, handlers.size()); + test_mock_humidity_handler_handle_using_handler(handlers.front()); +} + +void test_MockHumidityModule(std::list components) { + setup_humidity_module_test(components); + RUN_TEST(test_humidity_module_name); + RUN_TEST(test_humidity_module_components); + RUN_TEST(test_humidity_module_get_handlers); + post_humidity_module_test(); +} + +#endif // MOCK_HUMIDITY_MODULE_TEST_H \ No newline at end of file diff --git a/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h b/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h index f44431b..2e57554 100644 --- a/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h +++ b/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h @@ -1,8 +1,12 @@ +#ifndef MOCK_HUMIDITY_HANDLER_TEST_H +#define MOCK_HUMIDITY_HANDLER_TEST_H + #include #include #include "mock-humidity-sensor/operation-handler/MockHumidityHandler.h" #include "mock-humidity-sensor/hw/MockHumiditySensorHw.h" + #define MOCK_HUMIDITY_SENSOR_NAME_IN_HANDLER "sensor" #define MOCK_HUMIDITY_HANDLER_NAME "humidity" @@ -18,11 +22,10 @@ void setup_mock_humidity_handler() { argsMockHumSensor["id"] = MOCK_HUMIDITY_SENSOR_NAME_IN_HANDLER; argsMockHumSensorBadReq["za"] = "warudo"; argsMockHumSensorNotFound["id"] = "giogia"; - std::list list = {mockHumSensor}; mockHumidityHandler = new MockHumidityHandler( MOCK_HUMIDITY_HANDLER_NAME, as_route(MOCK_HUMIDITY_HANDLER_NAME), - list + {mockHumSensor} ); } @@ -30,15 +33,15 @@ void post_mock_humidity_handler() { delete mockHumSensor; } -void test_mock_humidity_handler_success() { - OperationHandlerResult r = mockHumidityHandler -> handle(argsMockHumSensor); +void test_mock_humidity_handler_success(OperationHandler* h) { + OperationHandlerResult r = h -> handle(argsMockHumSensor); TEST_ASSERT_EQUAL(HttpStatus::OK, r.code()); float c = r.content().asFloat(); TEST_ASSERT_TRUE(c >= 0 && c <= MOCK_MAX_HUMIDITY); } -void test_mock_humidity_handler_not_found() { - OperationHandlerResult r = mockHumidityHandler -> handle(argsMockHumSensorNotFound); +void test_mock_humidity_handler_not_found(OperationHandler* h) { + OperationHandlerResult r = h -> handle(argsMockHumSensorNotFound); TEST_ASSERT_EQUAL(HttpStatus::NotFound, r.code()); TEST_ASSERT_EQUAL_STRING( phrase(ContentResult::ResourceNotFound).c_str(), @@ -46,8 +49,8 @@ void test_mock_humidity_handler_not_found() { ); } -void test_mock_humidity_handler_bad_req() { - OperationHandlerResult r = mockHumidityHandler -> handle(argsMockHumSensorBadReq); +void test_mock_humidity_handler_bad_req(OperationHandler* h) { + OperationHandlerResult r = h -> handle(argsMockHumSensorBadReq); TEST_ASSERT_EQUAL(HttpStatus::BadRequest, r.code()); TEST_ASSERT_EQUAL_STRING( phrase(ContentResult::BadRequest).c_str(), @@ -55,14 +58,23 @@ void test_mock_humidity_handler_bad_req() { ); } +void test_mock_humidity_handler_handle_using_handler(OperationHandler* h) { + test_mock_humidity_handler_success(h); + test_mock_humidity_handler_not_found(h); + test_mock_humidity_handler_bad_req(h); +} + +#include "../modules/MockHumidityModuleTest.h" + void test_mock_humidity_handler_handle() { - test_mock_humidity_handler_success(); - test_mock_humidity_handler_not_found(); - test_mock_humidity_handler_bad_req(); + test_mock_humidity_handler_handle_using_handler(mockHumidityHandler); } void test_MockHumidityHandler() { setup_mock_humidity_handler(); RUN_TEST(test_mock_humidity_handler_handle); + test_MockHumidityModule({mockHumSensor}); post_mock_humidity_handler(); -} \ No newline at end of file +} + +#endif // MOCK_HUMIDITY_HANDLER_TEST_H \ No newline at end of file From 33fd8db5d1b23a86c5c553043b749329808cb070 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 12 Jan 2022 19:37:50 +0100 Subject: [PATCH 14/46] Added Humidity module to main --- edge/platformio.ini | 6 +++++- edge/src/main.cpp | 1 + .../src/modules/mock-temperature-humidity-sensor.h | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 edge/src/modules/mock-temperature-humidity-sensor.h diff --git a/edge/platformio.ini b/edge/platformio.ini index b2de5a0..f9c3d68 100644 --- a/edge/platformio.ini +++ b/edge/platformio.ini @@ -44,4 +44,8 @@ build_flags = -D BRITTANY_MAIN_MOCK_DIGITAL_LIGHT [env:dht22] extends = env:nodemcuv2 -build_flags = -D BRITTANY_MAIN_DHT22 \ No newline at end of file +build_flags = -D BRITTANY_MAIN_DHT22 + +[env:mock-temperature-humidity-sensor] +extends = env:nodemcuv2 +build_flags = -D BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_SENSOR diff --git a/edge/src/main.cpp b/edge/src/main.cpp index 3680852..7d315de 100644 --- a/edge/src/main.cpp +++ b/edge/src/main.cpp @@ -6,6 +6,7 @@ #include "modules/Module.h" #include "modules/dht22.h" #include "modules/mock-digital-light.h" +#include "modules/mock-temperature-humidity-sensor.h" Esp8266WebServer* server; diff --git a/edge/src/modules/mock-temperature-humidity-sensor.h b/edge/src/modules/mock-temperature-humidity-sensor.h new file mode 100644 index 0000000..32fb076 --- /dev/null +++ b/edge/src/modules/mock-temperature-humidity-sensor.h @@ -0,0 +1,14 @@ +#ifdef BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_SENSOR + +#include "mock-humidity-sensor/hw/MockHumiditySensorHw.h" +#include "mock-humidity-sensor/modules/MockHumidityModule.h" + +Edge* edge() { + MockHumiditySensorHw* humSensor = new MockHumiditySensorHw("hum"); + std::list sensors = std::list({humSensor}); + std::list modules; + modules.push_back(new MockHumidityModule(sensors)); + return new Edge("Mock Humidity and Temperature Edge", modules); +} + +#endif \ No newline at end of file From 0aa0f66204fef71dcb944b4672b9c9a60448409a Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 12:03:58 +0100 Subject: [PATCH 15/46] Added MockTemperature Handler --- .../MockTemperatureHandler.h | 32 ++++++ edge/test/brittany/main.cpp | 2 + .../MockTemperatureHandlerTest.h | 102 ++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h create mode 100644 edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h diff --git a/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h b/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h new file mode 100644 index 0000000..487a1fc --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h @@ -0,0 +1,32 @@ +#define BRITTANY_MOCK_TEMPERATURE_HANDLER +#include +#include +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" +#include "mock-temperature-sensor/hw/MockTemperatureSensorHw.h" + +class MockTemperatureHandler : public RetrieveValueFromComponentInterface { + +public: + + MockTemperatureHandler(std::string name, std::string path, std::list components) + : RetrieveValueFromComponentInterface (name, path, components) { + + }; + +private: + + std::optional sub_operation(MockTemperatureSensorHw* hw, Json::Value args) { + if(args.isMember("unit")) { + if(args["unit"] == "C" || args["unit"] == "c") { + return hw -> temperatureCelsius(); + } else if(args["unit"] == "K" || args["unit"] == "k") { + return hw -> temperatureKelvin(); + } else if(args["unit"] == "F" || args["unit"] == "f") { + return hw -> temperatureFahrenheit(); + } + return std::nullopt; + } + return hw -> temperatureCelsius(); + } + +}; \ No newline at end of file diff --git a/edge/test/brittany/main.cpp b/edge/test/brittany/main.cpp index 69ea5d7..6bac815 100644 --- a/edge/test/brittany/main.cpp +++ b/edge/test/brittany/main.cpp @@ -3,6 +3,7 @@ #include "operation-handler/OperationHandlerTest.h" #include "operation-handler/MockDigitalLightHandlersTest.h" #include "operation-handler/MockHumidityHandlerTest.h" +#include "operation-handler/MockTemperatureHandlerTest.h" #include "operation-handler/util/ValueReturnedResultTest.h" #include "operation-handler/util/ValueReturnedResultFactoryTest.h" #include "operation-handler/types/TypeTest.h" @@ -32,6 +33,7 @@ void test_operation_handler() { test_OperationHandler(); //OperationHandlerTest test_MockDigitalLightHandlersTest(); //MockDigitalLightHandlersTest test_MockHumidityHandler(); //MockHumidityHandlerTest + test_MockTemperatureHandler(); //MockTemperatureHandlerTest test_ValueReturnedResultTest(); //ValueReturnedResultTest test_ValueReturnedResultFactoryTest(); //ValueReturnedResultFactoryTest test_Type(); //TypeTest diff --git a/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h b/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h new file mode 100644 index 0000000..e2bf163 --- /dev/null +++ b/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h @@ -0,0 +1,102 @@ +#ifndef MOCK_TEMPERATURE_HANDLER_TEST_H +#define MOCK_TEMPERATURE_HANDLER_TEST_H + +#include +#include +#include "mock-temperature-sensor/operation-handler/MockTemperatureHandler.h" +#include "mock-temperature-sensor/hw/MockTemperatureSensorHw.h" + +#define MOCK_TEMPERATURE_SENSOR_NAME_IN_HANDLER "sensor" +#define MOCK_TEMPERATURE_HANDLER_NAME "temperature" + +MockTemperatureHandler* mockTemperatureHandler; +MockTemperatureSensorHw* mockTempSensor; + +Json::Value argsMockTempSensor; +Json::Value argsMockTempSensorBadReq; +Json::Value argsMockTempSensorNotFound; + +void setup_mock_temperature_handler() { + mockTempSensor = new MockTemperatureSensorHw(MOCK_TEMPERATURE_SENSOR_NAME_IN_HANDLER); + argsMockTempSensor["id"] = MOCK_TEMPERATURE_SENSOR_NAME_IN_HANDLER; + argsMockTempSensorBadReq["za"] = "warudo"; + argsMockTempSensorNotFound["id"] = "giogia"; + mockTemperatureHandler = new MockTemperatureHandler( + MOCK_TEMPERATURE_HANDLER_NAME, + as_route(MOCK_TEMPERATURE_HANDLER_NAME), + {mockTempSensor} + ); +} + +void post_mock_temperature_handler() { + delete mockTempSensor; +} + +void check_temp_value_is_correct(OperationHandlerResult r, float min, float max) { + TEST_ASSERT_EQUAL(HttpStatus::OK, r.code()); + float c = r.content().asFloat(); + TEST_ASSERT_TRUE(c >= min && c <= max); +} + +void test_mock_temperature_handler_success(OperationHandler* h) { + check_temp_value_is_correct( + h -> handle(argsMockTempSensor), + 0, + MOCK_MAX_TEMPERATURE_CELSIUS + ); + argsMockTempSensor["unit"] = "f"; + check_temp_value_is_correct( + h -> handle(argsMockTempSensor), + Temperature::fromCToF(0), + Temperature::fromCToF(MOCK_MAX_TEMPERATURE_CELSIUS) + ); + argsMockTempSensor["unit"] = "k"; + check_temp_value_is_correct( + h -> handle(argsMockTempSensor), + Temperature::fromCToK(0), + Temperature::fromCToK(MOCK_MAX_TEMPERATURE_CELSIUS) + ); + argsMockTempSensor["unit"] = "c"; + check_temp_value_is_correct( + h -> handle(argsMockTempSensor), + 0, + MOCK_MAX_TEMPERATURE_CELSIUS + ); +} + +void test_mock_temperature_handler_not_found(OperationHandler* h) { + OperationHandlerResult r = h -> handle(argsMockTempSensorNotFound); + TEST_ASSERT_EQUAL(HttpStatus::NotFound, r.code()); + TEST_ASSERT_EQUAL_STRING( + phrase(ContentResult::ResourceNotFound).c_str(), + r.content().asCString() + ); +} + +void test_mock_temperature_handler_bad_req(OperationHandler* h) { + OperationHandlerResult r = h -> handle(argsMockTempSensorBadReq); + TEST_ASSERT_EQUAL(HttpStatus::BadRequest, r.code()); + TEST_ASSERT_EQUAL_STRING( + phrase(ContentResult::BadRequest).c_str(), + r.content().asCString() + ); +} + +void test_mock_temperature_handler_handle_using_handler(OperationHandler* h) { + test_mock_temperature_handler_success(h); + test_mock_temperature_handler_not_found(h); + test_mock_temperature_handler_bad_req(h); +} + +void test_mock_temperature_handler_handle() { + test_mock_temperature_handler_handle_using_handler(mockTemperatureHandler); +} + +void test_MockTemperatureHandler() { + setup_mock_temperature_handler(); + RUN_TEST(test_mock_temperature_handler_handle); + //test_MockTemperatureModule({mockTempSensor}); + post_mock_temperature_handler(); +} + +#endif // MOCK_TEMPERATURE_HANDLER_TEST_H \ No newline at end of file From 556e3226e49400079c469e215ea55208c1924d7f Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 12:16:25 +0100 Subject: [PATCH 16/46] Added MockTemperature Module --- .../modules/MockTemperatureModule.h | 30 ++++++++++++ .../MockTemperatureHandler.h | 8 +++- .../modules/MockTemperatureModelTest.h | 46 +++++++++++++++++++ .../MockTemperatureHandlerTest.h | 4 +- 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h create mode 100644 edge/test/brittany/modules/MockTemperatureModelTest.h diff --git a/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h b/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h new file mode 100644 index 0000000..46c392b --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h @@ -0,0 +1,30 @@ +#ifndef BRITTANY_MOCK_TEMPERATURE_MODULE_H +#define BRITTANY_MOCK_TEMPERATURE_MODULE_H + +#include +#include "operation-handler/OperationHandler.h" +#include "mock-temperature-sensor/hw/MockTemperatureSensorHw.h" +#include "mock-temperature-sensor/operation-handler/MockTemperatureHandler.h" +#include "modules/ComponentModule.h" +#include "modules/ModuleNames.h" + +#define MOCK_TEMPERATURE_HANDLER_NAME "temperature" + +class MockTemperatureModule : public ComponentModule { + +public: + + MockTemperatureModule(std::list components) + : ComponentModule(module_as_string(ModuleNames::Temperature), components) { + _handlers.push_back( + new MockTemperatureHandler( + MOCK_TEMPERATURE_HANDLER_NAME, + as_route(MOCK_TEMPERATURE_HANDLER_NAME), + components + ) + ); + }; + +}; + +#endif //BRITTANY_MOCK_TEMPERATURE_MODULE_H \ No newline at end of file diff --git a/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h b/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h index 487a1fc..f3a4937 100644 --- a/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h +++ b/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h @@ -1,4 +1,6 @@ -#define BRITTANY_MOCK_TEMPERATURE_HANDLER +#ifndef BRITTANY_MOCK_TEMPERATURE_HANDLER_H +#define BRITTANY_MOCK_TEMPERATURE_HANDLER_H + #include #include #include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" @@ -29,4 +31,6 @@ class MockTemperatureHandler : public RetrieveValueFromComponentInterface temperatureCelsius(); } -}; \ No newline at end of file +}; + +#endif // BRITTANY_MOCK_TEMPERATURE_HANDLER_H \ No newline at end of file diff --git a/edge/test/brittany/modules/MockTemperatureModelTest.h b/edge/test/brittany/modules/MockTemperatureModelTest.h new file mode 100644 index 0000000..fc1bb75 --- /dev/null +++ b/edge/test/brittany/modules/MockTemperatureModelTest.h @@ -0,0 +1,46 @@ +#ifndef MOCK_TEMPERATURE_MODULE_TEST_H +#define MOCK_TEMPERATURE_MODULE_TEST_H + +#include +#include +#include "mock-temperature-sensor/modules/MockTemperatureModule.h" +#include "../operation-handler/MockTemperatureHandlerTest.h" + +MockTemperatureModule* mockTemperatureModule; + +void setup_temperature_module_test(std::list components) { + mockTemperatureModule = new MockTemperatureModule(components); +} + +void post_temperature_module_test() { + delete mockTemperatureModule; +} + +void test_temperature_module_name() { + TEST_ASSERT_EQUAL_STRING( + module_as_string(ModuleNames::Temperature).c_str(), + mockTemperatureModule -> name().c_str() + ); +} + +void test_temperature_module_components() { + std::list comps = mockTemperatureModule -> components(); + TEST_ASSERT_EQUAL(1, comps.size()); + TEST_ASSERT_EQUAL_STRING(MOCK_TEMPERATURE_SENSOR_NAME_IN_HANDLER, comps.front().id().c_str()); +} + +void test_temperature_module_get_handlers() { + std::list handlers = mockTemperatureModule -> handlers(); + TEST_ASSERT_EQUAL(1, handlers.size()); + test_mock_temperature_handler_handle_using_handler(handlers.front()); +} + +void test_MockTemperatureModule(std::list components) { + setup_temperature_module_test(components); + RUN_TEST(test_temperature_module_name); + RUN_TEST(test_temperature_module_components); + RUN_TEST(test_temperature_module_get_handlers); + post_temperature_module_test(); +} + +#endif // MOCK_TEMPERATURE_MODULE_TEST_H \ No newline at end of file diff --git a/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h b/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h index e2bf163..4d69f3b 100644 --- a/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h +++ b/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h @@ -88,6 +88,8 @@ void test_mock_temperature_handler_handle_using_handler(OperationHandler* h) { test_mock_temperature_handler_bad_req(h); } +#include "../modules/MockTemperatureModelTest.h" + void test_mock_temperature_handler_handle() { test_mock_temperature_handler_handle_using_handler(mockTemperatureHandler); } @@ -95,7 +97,7 @@ void test_mock_temperature_handler_handle() { void test_MockTemperatureHandler() { setup_mock_temperature_handler(); RUN_TEST(test_mock_temperature_handler_handle); - //test_MockTemperatureModule({mockTempSensor}); + test_MockTemperatureModule({mockTempSensor}); post_mock_temperature_handler(); } From b94897c0d55592b84a4c03033de37c489d61ed8e Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 12:44:11 +0100 Subject: [PATCH 17/46] Added Temperature Mock module to main --- edge/src/modules/mock-temperature-humidity-sensor.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/edge/src/modules/mock-temperature-humidity-sensor.h b/edge/src/modules/mock-temperature-humidity-sensor.h index 32fb076..72ee360 100644 --- a/edge/src/modules/mock-temperature-humidity-sensor.h +++ b/edge/src/modules/mock-temperature-humidity-sensor.h @@ -1,14 +1,17 @@ -#ifdef BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_SENSOR +//#ifdef BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_SENSOR +#include "mock-temperature-sensor/hw/MockTemperatureSensorHw.h" +#include "mock-temperature-sensor/modules/MockTemperatureModule.h" #include "mock-humidity-sensor/hw/MockHumiditySensorHw.h" #include "mock-humidity-sensor/modules/MockHumidityModule.h" Edge* edge() { MockHumiditySensorHw* humSensor = new MockHumiditySensorHw("hum"); - std::list sensors = std::list({humSensor}); + MockTemperatureSensorHw* tempSensor = new MockTemperatureSensorHw("temp"); std::list modules; - modules.push_back(new MockHumidityModule(sensors)); + modules.push_back(new MockHumidityModule({humSensor})); + modules.push_back(new MockTemperatureModule({tempSensor})); return new Edge("Mock Humidity and Temperature Edge", modules); } -#endif \ No newline at end of file +//#endif \ No newline at end of file From b000787d0d6fd820b1b9a466e5e796c4e7566b93 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 15:12:51 +0100 Subject: [PATCH 18/46] Forgot to add the ifndef to the new module --- edge/src/modules/mock-temperature-humidity-sensor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/edge/src/modules/mock-temperature-humidity-sensor.h b/edge/src/modules/mock-temperature-humidity-sensor.h index 72ee360..ffa2c51 100644 --- a/edge/src/modules/mock-temperature-humidity-sensor.h +++ b/edge/src/modules/mock-temperature-humidity-sensor.h @@ -1,4 +1,4 @@ -//#ifdef BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_SENSOR +#ifdef BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_SENSOR #include "mock-temperature-sensor/hw/MockTemperatureSensorHw.h" #include "mock-temperature-sensor/modules/MockTemperatureModule.h" @@ -14,4 +14,4 @@ Edge* edge() { return new Edge("Mock Humidity and Temperature Edge", modules); } -//#endif \ No newline at end of file +#endif \ No newline at end of file From 73b5023f4b13255203dbdc88f19c6a23ffab0b61 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 15:31:13 +0100 Subject: [PATCH 19/46] removed deprectaed mock hum tem sensor --- .../hw/MockTempHumSensorHw.h | 59 ----------------- .../brittany/hw/MockTempHumSensorHwTest.h | 64 ------------------- edge/test/brittany/main.cpp | 2 - 3 files changed, 125 deletions(-) delete mode 100644 edge/lib/brittany-mock/src/mock-temp-hum-sensor/hw/MockTempHumSensorHw.h delete mode 100644 edge/test/brittany/hw/MockTempHumSensorHwTest.h diff --git a/edge/lib/brittany-mock/src/mock-temp-hum-sensor/hw/MockTempHumSensorHw.h b/edge/lib/brittany-mock/src/mock-temp-hum-sensor/hw/MockTempHumSensorHw.h deleted file mode 100644 index 7117b80..0000000 --- a/edge/lib/brittany-mock/src/mock-temp-hum-sensor/hw/MockTempHumSensorHw.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef BRITTANY_MOCK_TEMP_HUM_SENSOR_HW_H -#define BRITTANY_MOCK_TEMP_HUM_SENSOR_HW_H - -#include "hw/interfaces/TempHumHwInterface.h" -#include -#include - -/** - * @brief Mock Implemenattion of a Mock temperature and Humidity sensor. - * - */ -class MockTempHumSensorHw : public TempHumHwInterface { - -public: - - /** - * @brief Construct a new Mock Temp Hum Sensor Hw object - * - * @param id the hw id. - * @param pin the hw pin. - * @param celsius_value the mock value to return as celsius. - * @param humidity_value the mock value to return as humidity. - */ - MockTempHumSensorHw( - std::string id, - uint8_t pin, - std::optional celsius_value, - std::optional humidity_value) : TempHumHwInterface(id, pin) { - _celsius_value = celsius_value; - _humidity_value = humidity_value; - }; - - std::optional temperatureCelsius() { - return _celsius_value; - }; - - std::optional temperatureKelvin() { - return temperatureCelsius().has_value() - ? std::optional(Temperature::fromCToK(temperatureCelsius().value())) - : std::nullopt; - }; - - std::optional temperatureFahrenheit() { - return temperatureCelsius().has_value() - ? std::optional(Temperature::fromCToF(temperatureCelsius().value())) - : std::nullopt; - }; - - std::optional humidity() { - return _humidity_value; - }; - -private: - - std::optional _celsius_value; - std::optional _humidity_value; - -}; -#endif //BRITTANY_MOCK_TEMP_HUM_SENSOR_HW_H diff --git a/edge/test/brittany/hw/MockTempHumSensorHwTest.h b/edge/test/brittany/hw/MockTempHumSensorHwTest.h deleted file mode 100644 index 0252b8a..0000000 --- a/edge/test/brittany/hw/MockTempHumSensorHwTest.h +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include "mock-temp-hum-sensor/hw/MockTempHumSensorHw.h" - -#define MOCK_TEMP_HUM_SENSOR_NAME "temp-hum" -#define MOCK_TEMP_HUM_SENSOR_PIN 0 -#define MOCK_TEMP_HUM_SENSOR_CELSIUS 12.5 -#define MOCK_TEMP_HUM_SENSOR_HUMIDITY 50 - -MockTempHumSensorHw tempHum = - MockTempHumSensorHw( - MOCK_TEMP_HUM_SENSOR_NAME, - MOCK_TEMP_HUM_SENSOR_PIN, - MOCK_TEMP_HUM_SENSOR_CELSIUS, - MOCK_TEMP_HUM_SENSOR_HUMIDITY - ); - -MockTempHumSensorHw brokenTempHum = - MockTempHumSensorHw( - MOCK_TEMP_HUM_SENSOR_NAME, - MOCK_TEMP_HUM_SENSOR_PIN, - std::nullopt, - std::nullopt - ); - - -void test_mock_celsius() { - TEST_ASSERT_EQUAL_FLOAT( - MOCK_TEMP_HUM_SENSOR_CELSIUS, - tempHum.temperatureCelsius().value() - ); - TEST_ASSERT_FALSE(brokenTempHum.temperatureCelsius().has_value()); -} - -void test_mock_fahrenheit() { - TEST_ASSERT_EQUAL_FLOAT( - MOCK_TEMP_HUM_SENSOR_CELSIUS * 1.8 + 32, - tempHum.temperatureFahrenheit().value() - ); - TEST_ASSERT_FALSE(brokenTempHum.temperatureFahrenheit().has_value()); -} - -void test_mock_kelvin() { - TEST_ASSERT_EQUAL_FLOAT( - MOCK_TEMP_HUM_SENSOR_CELSIUS + 273.15, - tempHum.temperatureKelvin().value() - ); - TEST_ASSERT_FALSE(brokenTempHum.temperatureKelvin().has_value()); -} - -void test_mock_humidity() { - TEST_ASSERT_EQUAL_FLOAT( - MOCK_TEMP_HUM_SENSOR_HUMIDITY, - tempHum.humidity().value() - ); - TEST_ASSERT_FALSE(brokenTempHum.humidity().has_value()); -} - -void test_MockTempHumSensorHwTest() { - RUN_TEST(test_mock_celsius); - RUN_TEST(test_mock_fahrenheit); - RUN_TEST(test_mock_kelvin); - RUN_TEST(test_mock_humidity); -} diff --git a/edge/test/brittany/main.cpp b/edge/test/brittany/main.cpp index 6bac815..3afd1d8 100644 --- a/edge/test/brittany/main.cpp +++ b/edge/test/brittany/main.cpp @@ -10,7 +10,6 @@ #include "hw/ComponentHwTest.h" #include "hw/OnePinTest.h" #include "hw/MockDigitalLightHwTest.h" -#include "hw/MockTempHumSensorHwTest.h" #include "hw/MockTemperatureSensorHwTest.h" #include "hw/MockHumiditySensorHwTest.h" #include "modules/MockDigitalLightModuleTest.h" @@ -23,7 +22,6 @@ void test_hw() { test_ComponentHw(); //ComponentHwTest test_OnePin(); //OnePinTest test_MockDigitalLightHw(); //MockDigitalLightHwTest - test_MockTempHumSensorHwTest(); //MockTempHumSensorHwTest test_MockTemperatureSensorHwTest(); //MockTemperatureSensoreHwTest test_MockHumiditySensorHwTest(); //MockTemperatureSensoreHwTest } From 0a4b9d06de2ce1f0fa09c364070bd1262fc7510a Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 16:32:42 +0100 Subject: [PATCH 20/46] Added SwitchableActuatorHwInterface --- .../actuators/SwitchableActuatorHwInterface.h | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 edge/lib/brittany/src/hw/interfaces/actuators/SwitchableActuatorHwInterface.h diff --git a/edge/lib/brittany/src/hw/interfaces/actuators/SwitchableActuatorHwInterface.h b/edge/lib/brittany/src/hw/interfaces/actuators/SwitchableActuatorHwInterface.h new file mode 100644 index 0000000..e135115 --- /dev/null +++ b/edge/lib/brittany/src/hw/interfaces/actuators/SwitchableActuatorHwInterface.h @@ -0,0 +1,28 @@ +#ifndef BRITTANY_SWITCHABLE_ACTUATOR_HW_INTERFACE_H +#define BRITTANY_SWITCHABLE_ACTUATOR_HW_INTERFACE_H + +#include +#include "hw/ComponentHw.h" +#include "hw/feature/Switchable.h" + +/** + * @brief An interface to create a component that represent an actuator that can be turned on and off. + */ +class SwitchableActuatorHwInterface : public ComponentHw, public Switchable { + +public: + + /** + * @brief Construct a new Switchable Actuator Hw Interface object. + * + * @param id + */ + SwitchableActuatorHwInterface(std::string id) : + ComponentHw(id), + Switchable() { + + }; + +}; + +#endif //BRITTANY_SWITCHABLE_ACTUATOR_HW_INTERFACE_H \ No newline at end of file From 9eed1295e449799a8a03dc3fa234ae996ec7c026 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 16:32:56 +0100 Subject: [PATCH 21/46] Added MockSwitchableHw --- .../src/mock-switchable/hw/MockSwitchableHw.h | 41 +++++++++++++++++++ edge/test/brittany/hw/MockSwitchableHwTest.h | 30 ++++++++++++++ edge/test/brittany/main.cpp | 2 + 3 files changed, 73 insertions(+) create mode 100644 edge/lib/brittany-mock/src/mock-switchable/hw/MockSwitchableHw.h create mode 100644 edge/test/brittany/hw/MockSwitchableHwTest.h diff --git a/edge/lib/brittany-mock/src/mock-switchable/hw/MockSwitchableHw.h b/edge/lib/brittany-mock/src/mock-switchable/hw/MockSwitchableHw.h new file mode 100644 index 0000000..fd3f89f --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-switchable/hw/MockSwitchableHw.h @@ -0,0 +1,41 @@ +#ifndef MOCK_SWITCHABLE_HW_H +#define MOCK_SWITCHABLE_HW_H + +#include +#include "hw/interfaces/actuators/SwitchableActuatorHwInterface.h" + +/** + * @brief Represent a MockHw that can be turned on and off. + */ +class MockSwitchableHw : public SwitchableActuatorHwInterface { + +public: + + /** + * @brief Construct a new Mock Switchable Hw object. + * + * @param id the id of the hw. + */ + MockSwitchableHw(std::string id) : SwitchableActuatorHwInterface(id) { + _isOn = false; + }; + + void on() { + _isOn = true; + } + + void off() { + _isOn = false; + } + + bool isOn() { + return _isOn; + } + +private: + + bool _isOn; + +}; + +#endif //MOCK_SWITCHABLE_HW_H diff --git a/edge/test/brittany/hw/MockSwitchableHwTest.h b/edge/test/brittany/hw/MockSwitchableHwTest.h new file mode 100644 index 0000000..53b31a1 --- /dev/null +++ b/edge/test/brittany/hw/MockSwitchableHwTest.h @@ -0,0 +1,30 @@ +#include +#include "mock-switchable/hw/MockSwitchableHw.h" + +#define MOCK_SWITCHABLE_HW_ID "switch" + +MockSwitchableHw mockSwitchableHw = MockSwitchableHw(MOCK_SWITCHABLE_HW_ID); + +void mock_switchable_hw_is_on_must_be(bool must_be) { + if(must_be) { + TEST_ASSERT_TRUE(mockSwitchableHw.isOn()); + } else { + TEST_ASSERT_FALSE(mockSwitchableHw.isOn()); + } +} + +void test_mock_switchable_hw_is_off() { + mock_switchable_hw_is_on_must_be(false); +} + +void test_mock_switchable_hw_is_on() { + mock_switchable_hw_is_on_must_be(true); +} + +void test_MockSwitchableHwTest() { + RUN_TEST(test_mock_switchable_hw_is_off); + mockSwitchableHw.on(); + RUN_TEST(test_mock_switchable_hw_is_on); + mockSwitchableHw.off(); + RUN_TEST(test_mock_switchable_hw_is_off); +} diff --git a/edge/test/brittany/main.cpp b/edge/test/brittany/main.cpp index 3afd1d8..0d51a6e 100644 --- a/edge/test/brittany/main.cpp +++ b/edge/test/brittany/main.cpp @@ -9,6 +9,7 @@ #include "operation-handler/types/TypeTest.h" #include "hw/ComponentHwTest.h" #include "hw/OnePinTest.h" +#include "hw/MockSwitchableHwTest.h" #include "hw/MockDigitalLightHwTest.h" #include "hw/MockTemperatureSensorHwTest.h" #include "hw/MockHumiditySensorHwTest.h" @@ -22,6 +23,7 @@ void test_hw() { test_ComponentHw(); //ComponentHwTest test_OnePin(); //OnePinTest test_MockDigitalLightHw(); //MockDigitalLightHwTest + test_MockSwitchableHwTest(); //MockSwitchableHwTest test_MockTemperatureSensorHwTest(); //MockTemperatureSensoreHwTest test_MockHumiditySensorHwTest(); //MockTemperatureSensoreHwTest } From 17ee387eb2964df4e7ebd25ef229aec0b09271bc Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 17:20:43 +0100 Subject: [PATCH 22/46] TurnOffHandler Dryied --- .../MockTurnOffDigitalLightHandler.h | 20 +++----- .../RetrieveValueFromComponentInterface.h | 48 +++++++++++++++++-- .../interfaces/TurnOffHandlerInterface.cpp | 15 ------ .../interfaces/TurnOffHandlerInterface.h | 35 +++++--------- 4 files changed, 64 insertions(+), 54 deletions(-) delete mode 100644 edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.cpp diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h index d1362d0..c6cfc95 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h @@ -5,12 +5,11 @@ #include #include #include "operation-handler/interfaces/TurnOffHandlerInterface.h" -#include "operation-handler/interfaces/TurnOffHandlerInterface.cpp" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" #include "util.h" -class MockTurnOffDigitalLightHandler : public TurnOffHandlerInterface { +class MockTurnOffDigitalLightHandler : public TurnOffHandlerInterface { public: @@ -18,24 +17,17 @@ class MockTurnOffDigitalLightHandler : public TurnOffHandlerInterface { std::string name, std::string path, std::list components - ): TurnOffHandlerInterface(name, path) { - _components = components; + ): TurnOffHandlerInterface(name, path, components) { + }; private: - bool turnOff(std::string id) { - std::optional oc = find_by_id(_components, id); - if(oc.has_value()) { - oc.value() -> off(); - return true; - } else { - return false; - } + std::optional sub_operation(MockDigitalLightHw* hw, Json::Value args) { + hw -> off(); + return std::optional(phrase(ContentResult::Ok)); }; - std::list _components; - }; #endif //BRITTANY_MOCK_TURN_OFF_DIGITAL_LIGHT_HANDLER_INTERFACE_H diff --git a/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h b/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h index 7f6201e..fab0eb3 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h @@ -11,8 +11,50 @@ class RetrieveValueFromComponentInterface : public ValueReturnedAfterActionHandl public: - RetrieveValueFromComponentInterface(std::string name, std::string path, std::list components) - : ValueReturnedAfterActionHandlerInterface (name, path, OperationType::PROPERTY, Type::NUMBER) { + /** + * @brief Construct a new Retrieve Value From Component Interface object. + * + * @param name the name of the operation handler. + * @param path the path used for the operation handler. + * @param operationType the operation type. + * @param returnedType the returned type. + * @param components the list of components. + */ + RetrieveValueFromComponentInterface( + std::string name, + std::string path, + OperationType operationType, + Type returnedType, + std::list components + ) + : ValueReturnedAfterActionHandlerInterface ( + name, + path, + operationType, + returnedType + ) { + _components = components; + }; + + /** + * @brief Construct a new Retrieve Value From Component Interface object. + * Simplified Constructor that set the handler to a property and return a number. + * + * @param name + * @param path + * @param components + */ + RetrieveValueFromComponentInterface( + std::string name, + std::string path, + std::list components + ) + : ValueReturnedAfterActionHandlerInterface ( + name, + path, + OperationType::PROPERTY, + Type::NUMBER + ) { _components = components; }; @@ -29,7 +71,7 @@ class RetrieveValueFromComponentInterface : public ValueReturnedAfterActionHandl return std::nullopt; } - virtual std::optional sub_operation(C* hw, Json::Value args) = 0; + virtual std::optional sub_operation(C* hw, Json::Value args) = 0; std::list _components; }; diff --git a/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.cpp b/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.cpp deleted file mode 100644 index 50fc45a..0000000 --- a/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "TurnOffHandlerInterface.h" -#include "HttpStatusCodes_C++.h" -#include "util.h" - -TurnOffHandlerInterface::TurnOffHandlerInterface(std::string name, std::string path) -: ValueReturnedAfterActionHandlerInterface(name, path, OperationType::ACTION, Type::STRING) { - //does nothing -} - - std::optional TurnOffHandlerInterface::retrieveValue(Json::Value args) { - if(turnOff(args["id"].asCString())){ - return std::optional(phrase(ContentResult::Ok)); - } - return std::nullopt; -} \ No newline at end of file diff --git a/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.h b/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.h index d87db89..a03750a 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.h @@ -5,35 +5,26 @@ #include #include #include -#include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h" +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" +template /** * @brief Operation Handler Interface whose objective is to turn off a component. */ -class TurnOffHandlerInterface : public ValueReturnedAfterActionHandlerInterface { +class TurnOffHandlerInterface : public RetrieveValueFromComponentInterface { public: - TurnOffHandlerInterface(std::string name, std::string path); - - - /** - * @brief Calls the turnOff method. - * - * @param args the arguments passed from operation. - * @return std::optional a string with an "Ok." message if everything worked. - * Empty otherise. - */ - std::optional retrieveValue(Json::Value args); - - /** - * @brief turn off the chosen component. - * - * @param id the id of the component to turn off. - * @return true if the operation succeed. - * @return false if the operation fails. - */ - virtual bool turnOff(std::string id) = 0; + TurnOffHandlerInterface(std::string name, std::string path, std::list components) + : RetrieveValueFromComponentInterface( + name, + path, + OperationType::ACTION, + Type::STRING, + components + ) { + //does nothing + } }; From b1cbd0e11064ab49305e4d973eef418d655b90ca Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 17:37:22 +0100 Subject: [PATCH 23/46] Dryied TurnOnHandler --- .../MockTurnOnDigitalLightHandler.h | 24 ++++++------- .../interfaces/TurnOnHandlerInterface.cpp | 15 -------- .../interfaces/TurnOnHandlerInterface.h | 34 +++++++------------ 3 files changed, 23 insertions(+), 50 deletions(-) delete mode 100644 edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.cpp diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h index b6dab08..b76f7ad 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h @@ -5,12 +5,11 @@ #include #include #include "operation-handler/interfaces/TurnOnHandlerInterface.h" -#include "operation-handler/interfaces/TurnOnHandlerInterface.cpp" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" #include "util.h" -class MockTurnOnDigitalLightHandler : public TurnOnHandlerInterface { +class MockTurnOnDigitalLightHandler : public TurnOnHandlerInterface { public: @@ -18,24 +17,21 @@ class MockTurnOnDigitalLightHandler : public TurnOnHandlerInterface { std::string name, std::string path, std::list components - ): TurnOnHandlerInterface(name, path) { - _components = components; + ): TurnOnHandlerInterface( + name, + path, + components + ) { + }; private: - bool turnOn(std::string id) { - std::optional oc = find_by_id(_components, id); - if(oc.has_value()) { - oc.value() -> on(); - return true; - } else { - return false; - } + std::optional sub_operation(MockDigitalLightHw* hw, Json::Value args) { + hw -> on(); + return std::optional(phrase(ContentResult::Ok)); }; - std::list _components; - }; #endif //BRITTANY_MOCK_TURN_ON_DIGITAL_LIGHT_HANDLER_INTERFACE_H diff --git a/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.cpp b/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.cpp deleted file mode 100644 index dca594e..0000000 --- a/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "TurnOnHandlerInterface.h" -#include "HttpStatusCodes_C++.h" -#include "util.h" - -TurnOnHandlerInterface::TurnOnHandlerInterface(std::string name, std::string path) -: ValueReturnedAfterActionHandlerInterface(name, path, OperationType::ACTION, Type::STRING) { - //does nothing -} - -std::optional TurnOnHandlerInterface::retrieveValue(Json::Value args) { - if(turnOn(args["id"].asCString())) { - return std::optional(phrase(ContentResult::Ok)); - } - return std::nullopt; -} diff --git a/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.h b/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.h index 61a5224..563d234 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.h @@ -7,34 +7,26 @@ #include #include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h" +template /** * @brief Operation Handler Interface whose objective is to turn on a component. - * */ -class TurnOnHandlerInterface : public ValueReturnedAfterActionHandlerInterface { +class TurnOnHandlerInterface : public RetrieveValueFromComponentInterface { public: - TurnOnHandlerInterface(std::string name,std::string path); - - /** - * @brief Calls the turnOn method. - * - * @param args the arguments passed from operation. - * @return std::optional a string with an "Ok." message if everything worked. - * Empty otherise. - */ - std::optional retrieveValue(Json::Value args); - - /** - * @brief turn on the chosen component. - * - * @param id the id of the component to turn on. - * @return true if the operation succeed. - * @return false if the operation fails. - */ - virtual bool turnOn(std::string id) = 0; + TurnOnHandlerInterface(std::string name, std::string path, std::list components) + : RetrieveValueFromComponentInterface( + name, + path, + OperationType::ACTION, + Type::STRING, + components + ) { + //does nothing + } }; + #endif //BRITTANY_TURN_ON_HANDLER_INTERFACE_H From 9e8ef6c13f2931bab18842cca316a2ec990f51ec Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 17:59:41 +0100 Subject: [PATCH 24/46] Removed two identical class TurnOnHandler and TurnOffHandler --- .../MockTurnOffDigitalLightHandler.h | 13 ++++++-- .../MockTurnOnDigitalLightHandler.h | 11 ++++--- .../interfaces/TurnOffHandlerInterface.h | 31 ------------------ .../interfaces/TurnOnHandlerInterface.h | 32 ------------------- 4 files changed, 17 insertions(+), 70 deletions(-) delete mode 100644 edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.h delete mode 100644 edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.h diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h index c6cfc95..3027725 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h @@ -4,12 +4,13 @@ #include #include #include -#include "operation-handler/interfaces/TurnOffHandlerInterface.h" +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" #include "util.h" -class MockTurnOffDigitalLightHandler : public TurnOffHandlerInterface { +class MockTurnOffDigitalLightHandler +: public RetrieveValueFromComponentInterface { public: @@ -17,7 +18,13 @@ class MockTurnOffDigitalLightHandler : public TurnOffHandlerInterface components - ): TurnOffHandlerInterface(name, path, components) { + ): RetrieveValueFromComponentInterface( + name, + path, + OperationType::ACTION, + Type::STRING, + components + ) { }; diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h index b76f7ad..f66313a 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h @@ -4,12 +4,13 @@ #include #include #include -#include "operation-handler/interfaces/TurnOnHandlerInterface.h" +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" #include "util.h" -class MockTurnOnDigitalLightHandler : public TurnOnHandlerInterface { +class MockTurnOnDigitalLightHandler +: public RetrieveValueFromComponentInterface { public: @@ -17,13 +18,15 @@ class MockTurnOnDigitalLightHandler : public TurnOnHandlerInterface components - ): TurnOnHandlerInterface( + ): RetrieveValueFromComponentInterface( name, path, + OperationType::ACTION, + Type::STRING, components ) { - }; + } private: diff --git a/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.h b/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.h deleted file mode 100644 index a03750a..0000000 --- a/edge/lib/brittany/src/operation-handler/interfaces/TurnOffHandlerInterface.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef BRITTANY_TURN_OFF_HANDLER_INTERFACE_H -#define BRITTANY_TURN_OFF_HANDLER_INTERFACE_H - -#include -#include -#include -#include -#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" - -template -/** - * @brief Operation Handler Interface whose objective is to turn off a component. - */ -class TurnOffHandlerInterface : public RetrieveValueFromComponentInterface { - -public: - - TurnOffHandlerInterface(std::string name, std::string path, std::list components) - : RetrieveValueFromComponentInterface( - name, - path, - OperationType::ACTION, - Type::STRING, - components - ) { - //does nothing - } - -}; - -#endif //BRITTANY_TURN_OFF_HANDLER_INTERFACE_H diff --git a/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.h b/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.h deleted file mode 100644 index 563d234..0000000 --- a/edge/lib/brittany/src/operation-handler/interfaces/TurnOnHandlerInterface.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef BRITTANY_TURN_ON_HANDLER_INTERFACE_H -#define BRITTANY_TURN_ON_HANDLER_INTERFACE_H - -#include -#include -#include -#include -#include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h" - -template -/** - * @brief Operation Handler Interface whose objective is to turn on a component. - */ -class TurnOnHandlerInterface : public RetrieveValueFromComponentInterface { - -public: - - TurnOnHandlerInterface(std::string name, std::string path, std::list components) - : RetrieveValueFromComponentInterface( - name, - path, - OperationType::ACTION, - Type::STRING, - components - ) { - //does nothing - } - -}; - - -#endif //BRITTANY_TURN_ON_HANDLER_INTERFACE_H From b51d926957756c08e975d585af2c09b1f986f04b Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 18:05:53 +0100 Subject: [PATCH 25/46] MockIsOnHandler now uses a better class as superclass --- .../MockIsOnDigitalLightHandler.h | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h index 125839c..8dcb2b3 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h @@ -4,14 +4,15 @@ #include #include #include -#include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h" +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" #include "HttpStatusCodes_C++.h" #include "util.h" #include -class MockIsOnDigitalLightHandler : public ValueReturnedAfterActionHandlerInterface { +class MockIsOnDigitalLightHandler +: public RetrieveValueFromComponentInterface { public: @@ -19,26 +20,21 @@ class MockIsOnDigitalLightHandler : public ValueReturnedAfterActionHandlerInterf std::string name, std::string path, std::list components - ): ValueReturnedAfterActionHandlerInterface( + ): RetrieveValueFromComponentInterface( name, path, OperationType::PROPERTY, - Type::BOOLEAN + Type::BOOLEAN, + components ) { - _components = components; + }; private: - std::optional retrieveValue(Json::Value args) { - std::optional oc = find_by_id(_components, args["id"].asCString()); - if(oc.has_value()){ - return std::optional(oc.value() -> isOn()); - } - return std::nullopt; + std::optional sub_operation(MockDigitalLightHw* hw, Json::Value args) { + return std::optional(hw -> isOn()); } - - std::list _components; }; From 8f2cf000c2633ad87610b15e429c622cdcb00069 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 18:30:46 +0100 Subject: [PATCH 26/46] Re-added turnOn Handler in its new form --- .../MockTurnOnDigitalLightHandler.h | 18 ++------ .../components/TurnOnSwitchableHandler.h | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h index f66313a..08a540c 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h @@ -4,13 +4,13 @@ #include #include #include -#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" +#include "operation-handler/interfaces/components/TurnOnSwitchableHandler.h" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" #include "util.h" class MockTurnOnDigitalLightHandler -: public RetrieveValueFromComponentInterface { +: public TurnOnSwitchableHandler { public: @@ -18,23 +18,13 @@ class MockTurnOnDigitalLightHandler std::string name, std::string path, std::list components - ): RetrieveValueFromComponentInterface( + ): TurnOnSwitchableHandler( name, path, - OperationType::ACTION, - Type::STRING, components ) { - + } - -private: - - std::optional sub_operation(MockDigitalLightHw* hw, Json::Value args) { - hw -> on(); - return std::optional(phrase(ContentResult::Ok)); - }; - }; #endif //BRITTANY_MOCK_TURN_ON_DIGITAL_LIGHT_HANDLER_INTERFACE_H diff --git a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h new file mode 100644 index 0000000..9108c4e --- /dev/null +++ b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h @@ -0,0 +1,41 @@ +#ifndef BRITTANY_TURN_ON_SWITCHABLE_HANDLER_H +#define BRITTANY_TURN_ON_SWITCHABLE_HANDLER_H + +#include +#include +#include +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" +#include "operation-handler/OperationHandlerResult.h" +#include "util.h" + +template + +class TurnOnSwitchableHandler +: public RetrieveValueFromComponentInterface { + +public: + + TurnOnSwitchableHandler( + std::string name, + std::string path, + std::list components + ): RetrieveValueFromComponentInterface( + name, + path, + OperationType::ACTION, + Type::STRING, + components + ) { + + } + +private: + + std::optional sub_operation(C* hw, Json::Value args) { + hw -> on(); + return std::optional(phrase(ContentResult::Ok)); + }; + +}; + +#endif //BRITTANY_TURN_ON_SWITCHABLE_HANDLER_H From 552f74a59bced20eb1ac660c58375801ce30dc12 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 18:36:11 +0100 Subject: [PATCH 27/46] Re-added turnOff Handler in its new form --- .../MockTurnOffDigitalLightHandler.h | 16 ++------ .../MockTurnOnDigitalLightHandler.h | 5 +-- .../components/TurnOffSwitchableHandler.h | 41 +++++++++++++++++++ 3 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h index 3027725..a8e5871 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h @@ -4,13 +4,12 @@ #include #include #include -#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" +#include "operation-handler/interfaces/components/TurnOffSwitchableHandler.h" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" #include "util.h" -class MockTurnOffDigitalLightHandler -: public RetrieveValueFromComponentInterface { +class MockTurnOffDigitalLightHandler: public TurnOffSwitchableHandler { public: @@ -18,23 +17,14 @@ class MockTurnOffDigitalLightHandler std::string name, std::string path, std::list components - ): RetrieveValueFromComponentInterface( + ): TurnOffSwitchableHandler( name, path, - OperationType::ACTION, - Type::STRING, components ) { }; -private: - - std::optional sub_operation(MockDigitalLightHw* hw, Json::Value args) { - hw -> off(); - return std::optional(phrase(ContentResult::Ok)); - }; - }; #endif //BRITTANY_MOCK_TURN_OFF_DIGITAL_LIGHT_HANDLER_INTERFACE_H diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h index 08a540c..7dfadaf 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h @@ -9,8 +9,7 @@ #include "operation-handler/OperationHandlerResult.h" #include "util.h" -class MockTurnOnDigitalLightHandler -: public TurnOnSwitchableHandler { +class MockTurnOnDigitalLightHandler: public TurnOnSwitchableHandler { public: @@ -23,7 +22,7 @@ class MockTurnOnDigitalLightHandler path, components ) { - + } }; diff --git a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h new file mode 100644 index 0000000..6bcb718 --- /dev/null +++ b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h @@ -0,0 +1,41 @@ +#ifndef BRITTANY_TURN_OFF_SWITCHABLE_HANDLER_H +#define BRITTANY_TURN_OFF_SWITCHABLE_HANDLER_H + +#include +#include +#include +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" +#include "operation-handler/OperationHandlerResult.h" +#include "util.h" + +template + +class TurnOffSwitchableHandler +: public RetrieveValueFromComponentInterface { + +public: + + TurnOffSwitchableHandler( + std::string name, + std::string path, + std::list components + ): RetrieveValueFromComponentInterface( + name, + path, + OperationType::ACTION, + Type::STRING, + components + ) { + + } + +private: + + std::optional sub_operation(C* hw, Json::Value args) { + hw -> off(); + return std::optional(phrase(ContentResult::Ok)); + }; + +}; + +#endif //BRITTANY_TURN_OFF_SWITCHABLE_HANDLER_H From 72daf67845c81346bb871491b92dcb589f410bb2 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Thu, 13 Jan 2022 18:47:58 +0100 Subject: [PATCH 28/46] Re-added isOn Handler in its new form --- .../MockIsOnDigitalLightHandler.h | 16 ++------ .../components/IsOnSwitchableHandler.h | 38 +++++++++++++++++++ .../components/TurnOffSwitchableHandler.h | 1 - .../components/TurnOnSwitchableHandler.h | 1 - 4 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 edge/lib/brittany/src/operation-handler/interfaces/components/IsOnSwitchableHandler.h diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h index 8dcb2b3..d02f021 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h @@ -4,15 +4,14 @@ #include #include #include -#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" +#include "operation-handler/interfaces/components/IsOnSwitchableHandler.h" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" #include "HttpStatusCodes_C++.h" #include "util.h" #include -class MockIsOnDigitalLightHandler -: public RetrieveValueFromComponentInterface { +class MockIsOnDigitalLightHandler: public IsOnSwitchableHandler { public: @@ -20,22 +19,13 @@ class MockIsOnDigitalLightHandler std::string name, std::string path, std::list components - ): RetrieveValueFromComponentInterface( + ): IsOnSwitchableHandler( name, path, - OperationType::PROPERTY, - Type::BOOLEAN, components ) { }; - -private: - - std::optional sub_operation(MockDigitalLightHw* hw, Json::Value args) { - return std::optional(hw -> isOn()); - } - }; #endif //BRITTANY_MOCK_IS_ON_DIGITAL_LIGHT_HANDLER_INTERFACE_H diff --git a/edge/lib/brittany/src/operation-handler/interfaces/components/IsOnSwitchableHandler.h b/edge/lib/brittany/src/operation-handler/interfaces/components/IsOnSwitchableHandler.h new file mode 100644 index 0000000..6c33682 --- /dev/null +++ b/edge/lib/brittany/src/operation-handler/interfaces/components/IsOnSwitchableHandler.h @@ -0,0 +1,38 @@ +#ifndef BRITTANY_IS_ON_SWITCHABLE_HANDLER_H +#define BRITTANY_IS_ON_SWITCHABLE_HANDLER_H + +#include +#include +#include +#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" +#include "util.h" + +template + +class IsOnSwitchableHandler: public RetrieveValueFromComponentInterface { + +public: + + IsOnSwitchableHandler( + std::string name, + std::string path, + std::list components + ): RetrieveValueFromComponentInterface( + name, + path, + OperationType::PROPERTY, + Type::BOOLEAN, + components + ) { + + } + +private: + + std::optional sub_operation(C* hw, Json::Value args) { + return std::optional(hw -> isOn()); + } + +}; + +#endif //BRITTANY_IS_ON_SWITCHABLE_HANDLER_H diff --git a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h index 6bcb718..b27b9a2 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h @@ -5,7 +5,6 @@ #include #include #include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" -#include "operation-handler/OperationHandlerResult.h" #include "util.h" template diff --git a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h index 9108c4e..a823d23 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h @@ -5,7 +5,6 @@ #include #include #include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h" -#include "operation-handler/OperationHandlerResult.h" #include "util.h" template From 3b290d07c2351334ef33a2022df26289fcd3bb58 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 11:48:15 +0100 Subject: [PATCH 29/46] upload task now lets you choose the environment to upload --- edge/build.gradle.kts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/edge/build.gradle.kts b/edge/build.gradle.kts index ef3c6cb..1b1ab80 100644 --- a/edge/build.gradle.kts +++ b/edge/build.gradle.kts @@ -11,5 +11,20 @@ tasks.register("testRealHw") { } tasks.register("upload") { - commandLine("pio", "run", "-e", "nodemcuv2", "-t", "upload") + val envs: List = File("platformio.ini").readLines().filter{ + it.matches(Regex("\\[env:.*\\]")) + }.map{ + it.substringAfter("[env:").substringBefore("]") + }.filter { + it != "native" && it != "nodemcuv2" + } + println("Please select the environment to upload: [0-" + (envs.size - 1).toString() + "]\n") + for ((i, item) in envs.withIndex()) { + println(i.toString() + ". " + item) + } + + val userInput = readLine()?.toIntOrNull() + if(userInput != null && userInput >= 0 && userInput < envs.size) { + commandLine("pio", "run", "-e", envs[userInput], "-t", "upload") + } } From e9716ea95cef65f9b6eccb6709530d52b60b38bb Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 11:48:59 +0100 Subject: [PATCH 30/46] Added Temperature actuator module --- .../modules/MockTemperatureCoolerModule.h | 44 +++++++++++++++++++ .../modules/MockTemperatureHeaterModule.h | 44 +++++++++++++++++++ edge/platformio.ini | 4 ++ edge/src/main.cpp | 1 + .../mock-temperature-humidity-actuator.h | 17 +++++++ 5 files changed, 110 insertions(+) create mode 100644 edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureCoolerModule.h create mode 100644 edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureHeaterModule.h create mode 100644 edge/src/modules/mock-temperature-humidity-actuator.h diff --git a/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureCoolerModule.h b/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureCoolerModule.h new file mode 100644 index 0000000..317701b --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureCoolerModule.h @@ -0,0 +1,44 @@ +#ifndef BRITTANY_MOCK_TEMPERATURE_COOLER_MODULE_H +#define BRITTANY_MOCK_TEMPERATURE_COOLER_MODULE_H + +#include + +#include "operation-handler/interfaces/components/TurnOffSwitchableHandler.h" +#include "operation-handler/interfaces/components/TurnOnSwitchableHandler.h" +#include "operation-handler/interfaces/components/IsOnSwitchableHandler.h" +#include "mock-switchable/hw/MockSwitchableHw.h" +#include "modules/ComponentModule.h" +#include "modules/ModuleNames.h" + +class MockTemperatureCoolerModule : public ComponentModule { + +public: + + MockTemperatureCoolerModule(std::list components) + : ComponentModule(module_as_string(ModuleNames::Temperature), components) { + _handlers.push_back( + new TurnOnSwitchableHandler( + "coolOn", + as_route("coolOn"), + components + ) + ); + _handlers.push_back( + new TurnOffSwitchableHandler( + "coolOff", + as_route("coolOff"), + components + ) + ); + _handlers.push_back( + new IsOnSwitchableHandler( + "isCoolOn", + as_route("isCoolOn"), + components + ) + ); + }; + +}; + +#endif //BRITTANY_MOCK_TEMPERATURE_COOLER_MODULE_H \ No newline at end of file diff --git a/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureHeaterModule.h b/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureHeaterModule.h new file mode 100644 index 0000000..a71396d --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureHeaterModule.h @@ -0,0 +1,44 @@ +#ifndef BRITTANY_MOCK_TEMPERATURE_HEATER_MODULE_H +#define BRITTANY_MOCK_TEMPERATURE_HEATER_MODULE_H + +#include + +#include "operation-handler/interfaces/components/TurnOffSwitchableHandler.h" +#include "operation-handler/interfaces/components/TurnOnSwitchableHandler.h" +#include "operation-handler/interfaces/components/IsOnSwitchableHandler.h" +#include "mock-switchable/hw/MockSwitchableHw.h" +#include "modules/ComponentModule.h" +#include "modules/ModuleNames.h" + +class MockTemperatureHeaterModule : public ComponentModule { + +public: + + MockTemperatureHeaterModule(std::list components) + : ComponentModule(module_as_string(ModuleNames::Temperature), components) { + _handlers.push_back( + new TurnOnSwitchableHandler( + "heatOn", + as_route("heatOn"), + components + ) + ); + _handlers.push_back( + new TurnOffSwitchableHandler( + "heatOff", + as_route("heatOff"), + components + ) + ); + _handlers.push_back( + new IsOnSwitchableHandler( + "isHeatOn", + as_route("isHeatOn"), + components + ) + ); + }; + +}; + +#endif //BRITTANY_MOCK_TEMPERATURE_HEATER_MODULE_H \ No newline at end of file diff --git a/edge/platformio.ini b/edge/platformio.ini index f9c3d68..a23ec94 100644 --- a/edge/platformio.ini +++ b/edge/platformio.ini @@ -49,3 +49,7 @@ build_flags = -D BRITTANY_MAIN_DHT22 [env:mock-temperature-humidity-sensor] extends = env:nodemcuv2 build_flags = -D BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_SENSOR + +[env:mock-temperature-humidity-actuator] +extends = env:nodemcuv2 +build_flags = -D BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_ACTUATOR \ No newline at end of file diff --git a/edge/src/main.cpp b/edge/src/main.cpp index 7d315de..03c2a4b 100644 --- a/edge/src/main.cpp +++ b/edge/src/main.cpp @@ -7,6 +7,7 @@ #include "modules/dht22.h" #include "modules/mock-digital-light.h" #include "modules/mock-temperature-humidity-sensor.h" +#include "modules/mock-temperature-humidity-actuator.h" Esp8266WebServer* server; diff --git a/edge/src/modules/mock-temperature-humidity-actuator.h b/edge/src/modules/mock-temperature-humidity-actuator.h new file mode 100644 index 0000000..5a24e75 --- /dev/null +++ b/edge/src/modules/mock-temperature-humidity-actuator.h @@ -0,0 +1,17 @@ +#ifdef BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_ACTUATOR + +#include "edge/Edge.h" +#include "mock-switchable/hw/MockSwitchableHw.h" +#include "mock-temperature-actuator/modules/MockTemperatureCoolerModule.h" +#include "mock-temperature-actuator/modules/MockTemperatureHeaterModule.h" + +Edge* edge() { + MockSwitchableHw* heater = new MockSwitchableHw("heater"); + MockSwitchableHw* cooler = new MockSwitchableHw("cooler"); + std::list modules; + modules.push_back(new MockTemperatureHeaterModule({heater})); + modules.push_back(new MockTemperatureCoolerModule({cooler})); + return new Edge("Mock Temperature Edge that can increase and lower the temperature.", modules); +} + +#endif \ No newline at end of file From 9afa993b1cfa18f5b8ce512f01b9d4fe4d26f8c7 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 14:37:43 +0100 Subject: [PATCH 31/46] Added humidifer module --- .../modules/MockHumidifierModule.h | 43 +++++++++++++++++++ .../mock-temperature-humidity-actuator.h | 3 ++ 2 files changed, 46 insertions(+) create mode 100644 edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h diff --git a/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h new file mode 100644 index 0000000..a97bb51 --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h @@ -0,0 +1,43 @@ +#ifndef BRITTANY_MOCK_HUMIDIFIER_MODULE_H +#define BRITTANY_MOCK_HUMIDIFIER_MODULE_H + +#include +#include "operation-handler/interfaces/components/TurnOffSwitchableHandler.h" +#include "operation-handler/interfaces/components/TurnOnSwitchableHandler.h" +#include "operation-handler/interfaces/components/IsOnSwitchableHandler.h" +#include "mock-switchable/hw/MockSwitchableHw.h" +#include "modules/ComponentModule.h" +#include "modules/ModuleNames.h" + +class MockHumidifierModule : public ComponentModule { + +public: + + MockHumidifierModule(std::list components) + : ComponentModule(module_as_string(ModuleNames::Humidity), components) { + _handlers.push_back( + new TurnOnSwitchableHandler( + "humidifyOn", + as_route("humidifyOn"), + components + ) + ); + _handlers.push_back( + new TurnOffSwitchableHandler( + "humidifyOff", + as_route("humidifyOff"), + components + ) + ); + _handlers.push_back( + new TurnOffSwitchableHandler( + "isHumidifyOn", + as_route("isHumidifyOn"), + components + ) + ); + }; + +}; + +#endif //BRITTANY_MOCK_HUMIDIFIER_MODULE_H \ No newline at end of file diff --git a/edge/src/modules/mock-temperature-humidity-actuator.h b/edge/src/modules/mock-temperature-humidity-actuator.h index 5a24e75..fe7154a 100644 --- a/edge/src/modules/mock-temperature-humidity-actuator.h +++ b/edge/src/modules/mock-temperature-humidity-actuator.h @@ -4,13 +4,16 @@ #include "mock-switchable/hw/MockSwitchableHw.h" #include "mock-temperature-actuator/modules/MockTemperatureCoolerModule.h" #include "mock-temperature-actuator/modules/MockTemperatureHeaterModule.h" +#include "mock-humidity-actuator/modules/MockHumidifierModule.h" Edge* edge() { MockSwitchableHw* heater = new MockSwitchableHw("heater"); MockSwitchableHw* cooler = new MockSwitchableHw("cooler"); + MockSwitchableHw* humidifier = new MockSwitchableHw("humidifier"); std::list modules; modules.push_back(new MockTemperatureHeaterModule({heater})); modules.push_back(new MockTemperatureCoolerModule({cooler})); + modules.push_back(new MockHumidifierModule({humidifier})); return new Edge("Mock Temperature Edge that can increase and lower the temperature.", modules); } From fd61b47aeb63f86427c9f18ec03bd9484848d72b Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 14:53:52 +0100 Subject: [PATCH 32/46] Added dehumidifer module --- .../modules/MockDehumidifierModule.h | 43 +++++++++++++++++++ .../modules/MockHumidifierModule.h | 2 +- .../mock-temperature-humidity-actuator.h | 6 ++- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockDehumidifierModule.h diff --git a/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockDehumidifierModule.h b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockDehumidifierModule.h new file mode 100644 index 0000000..0fae3e7 --- /dev/null +++ b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockDehumidifierModule.h @@ -0,0 +1,43 @@ +#ifndef BRITTANY_MOCK_DEHUMIDIFIER_MODULE_H +#define BRITTANY_MOCK_DEHUMIDIFIER_MODULE_H + +#include +#include "operation-handler/interfaces/components/TurnOffSwitchableHandler.h" +#include "operation-handler/interfaces/components/TurnOnSwitchableHandler.h" +#include "operation-handler/interfaces/components/IsOnSwitchableHandler.h" +#include "mock-switchable/hw/MockSwitchableHw.h" +#include "modules/ComponentModule.h" +#include "modules/ModuleNames.h" + +class MockDehumidifierModule : public ComponentModule { + +public: + + MockDehumidifierModule(std::list components) + : ComponentModule(module_as_string(ModuleNames::Humidity), components) { + _handlers.push_back( + new TurnOnSwitchableHandler( + "dehumidifyOn", + as_route("dehumidifyOn"), + components + ) + ); + _handlers.push_back( + new TurnOffSwitchableHandler( + "dehumidifyOff", + as_route("dehumidifyOff"), + components + ) + ); + _handlers.push_back( + new IsOnSwitchableHandler( + "isDehumidifyOn", + as_route("isDehumidifyOn"), + components + ) + ); + }; + +}; + +#endif //BRITTANY_MOCK_DEHUMIDIFIER_MODULE_H \ No newline at end of file diff --git a/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h index a97bb51..267718d 100644 --- a/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h +++ b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h @@ -30,7 +30,7 @@ class MockHumidifierModule : public ComponentModule { ) ); _handlers.push_back( - new TurnOffSwitchableHandler( + new IsOnSwitchableHandler( "isHumidifyOn", as_route("isHumidifyOn"), components diff --git a/edge/src/modules/mock-temperature-humidity-actuator.h b/edge/src/modules/mock-temperature-humidity-actuator.h index fe7154a..96861c2 100644 --- a/edge/src/modules/mock-temperature-humidity-actuator.h +++ b/edge/src/modules/mock-temperature-humidity-actuator.h @@ -5,16 +5,20 @@ #include "mock-temperature-actuator/modules/MockTemperatureCoolerModule.h" #include "mock-temperature-actuator/modules/MockTemperatureHeaterModule.h" #include "mock-humidity-actuator/modules/MockHumidifierModule.h" +#include "mock-humidity-actuator/modules/MockDehumidifierModule.h" Edge* edge() { MockSwitchableHw* heater = new MockSwitchableHw("heater"); MockSwitchableHw* cooler = new MockSwitchableHw("cooler"); MockSwitchableHw* humidifier = new MockSwitchableHw("humidifier"); + MockSwitchableHw* dehumidifier = new MockSwitchableHw("dehumidifier"); std::list modules; modules.push_back(new MockTemperatureHeaterModule({heater})); modules.push_back(new MockTemperatureCoolerModule({cooler})); modules.push_back(new MockHumidifierModule({humidifier})); - return new Edge("Mock Temperature Edge that can increase and lower the temperature.", modules); + modules.push_back(new MockDehumidifierModule({dehumidifier})); + std::string edge_desc = "Mock Temperature Edge that can increase and lower the temperature and the humidity."; + return new Edge(edge_desc, modules); } #endif \ No newline at end of file From 455798f2899b546ff04f6345366ef8cb7105afd9 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 15:02:25 +0100 Subject: [PATCH 33/46] Added constructor that does not ask for the path to OperatioHandler, used in MockOperationHandler --- .../brittany-mock/src/mock/modules/MockModule.h | 5 +---- .../mock/operation-handler/MockOperationHandler.h | 4 ++-- .../src/operation-handler/OperationHandler.cpp | 14 ++++++++++++++ .../src/operation-handler/OperationHandler.h | 14 ++++++++++++++ .../operation-handler/OperationHandlerTest.h | 11 ++++------- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/edge/lib/brittany-mock/src/mock/modules/MockModule.h b/edge/lib/brittany-mock/src/mock/modules/MockModule.h index 32f2450..db524db 100644 --- a/edge/lib/brittany-mock/src/mock/modules/MockModule.h +++ b/edge/lib/brittany-mock/src/mock/modules/MockModule.h @@ -19,10 +19,7 @@ class MockModule : public Module { MockModule(std::string name): Module(name) { _handlers.push_back( - new MockOperationHandler( - OPERATION_HANDLER_IN_MOCK_MODULE_NAME, - as_route(OPERATION_HANDLER_IN_MOCK_MODULE_NAME) - ) + new MockOperationHandler(OPERATION_HANDLER_IN_MOCK_MODULE_NAME) ); }; diff --git a/edge/lib/brittany-mock/src/mock/operation-handler/MockOperationHandler.h b/edge/lib/brittany-mock/src/mock/operation-handler/MockOperationHandler.h index f9ced7c..21ba627 100644 --- a/edge/lib/brittany-mock/src/mock/operation-handler/MockOperationHandler.h +++ b/edge/lib/brittany-mock/src/mock/operation-handler/MockOperationHandler.h @@ -14,8 +14,8 @@ class MockOperationHandler: public OperationHandler { public: - MockOperationHandler(std::string name, std::string path) : - OperationHandler(name, path, OperationType::PROPERTY, Type::INTEGER) { + MockOperationHandler(std::string name) : + OperationHandler(name, OperationType::PROPERTY, Type::INTEGER) { _value = 0; }; diff --git a/edge/lib/brittany/src/operation-handler/OperationHandler.cpp b/edge/lib/brittany/src/operation-handler/OperationHandler.cpp index 0e436bd..7193df8 100644 --- a/edge/lib/brittany/src/operation-handler/OperationHandler.cpp +++ b/edge/lib/brittany/src/operation-handler/OperationHandler.cpp @@ -1,4 +1,5 @@ #include "OperationHandler.h" +#include "util.h" OperationHandler::OperationHandler( std::string name, @@ -12,6 +13,19 @@ OperationHandler::OperationHandler( _outputType = outputType; } + +OperationHandler::OperationHandler( + std::string name, + OperationType operationType, + Type outputType +) { + _name = name; + _path = as_route(name); + _operationType = operationType; + _outputType = outputType; +} + + std::string OperationHandler::name() { return _name; } diff --git a/edge/lib/brittany/src/operation-handler/OperationHandler.h b/edge/lib/brittany/src/operation-handler/OperationHandler.h index d1d6490..e46f40d 100644 --- a/edge/lib/brittany/src/operation-handler/OperationHandler.h +++ b/edge/lib/brittany/src/operation-handler/OperationHandler.h @@ -31,6 +31,20 @@ class OperationHandler { Type outputType ); + + /** + * @brief Construct a new Operation Handler object. + * + * @param name The name of the OperationHandler. Will also be the path with a "/" in front. + * @param operationTye The operation type of the OperationHandler. + * @param outputType The type of the Output. + */ + OperationHandler( + std::string name, + OperationType operationType, + Type outputType + ); + /** * @brief Return the name of the OperationHandler. * diff --git a/edge/test/brittany/operation-handler/OperationHandlerTest.h b/edge/test/brittany/operation-handler/OperationHandlerTest.h index 5c2944d..c1ec45f 100644 --- a/edge/test/brittany/operation-handler/OperationHandlerTest.h +++ b/edge/test/brittany/operation-handler/OperationHandlerTest.h @@ -1,20 +1,17 @@ #include #include "mock/operation-handler/MockOperationHandler.h" +#include "util.h" -#define OPERATION_HANDLER_NAME "Operation" -#define OPERATION_HANDLER_PATH "/operation" +#define OPERATION_HANDLER_NAME "operation" -MockOperationHandler mockOperationHandler = MockOperationHandler( - OPERATION_HANDLER_NAME, - OPERATION_HANDLER_PATH -); +MockOperationHandler mockOperationHandler = MockOperationHandler(OPERATION_HANDLER_NAME); void test_operation_handler_name() { TEST_ASSERT_EQUAL_STRING(OPERATION_HANDLER_NAME, mockOperationHandler.name().c_str()); } void test_operation_handler_path() { - TEST_ASSERT_EQUAL_STRING(OPERATION_HANDLER_PATH, mockOperationHandler.path().c_str()); + TEST_ASSERT_EQUAL_STRING(as_route(OPERATION_HANDLER_NAME).c_str(), mockOperationHandler.path().c_str()); } void test_operation_handler_operation_type() { From 790ae68d3079d25353325ebd8b2fb2b30687262c Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 15:53:32 +0100 Subject: [PATCH 34/46] removed path from almost all operation-handler --- .../src/temp-hum-sensor/dht22/modules/DHT22Module.h | 12 ++---------- .../operation-handler/DHT22GetHumidityHandler.cpp | 3 +-- .../operation-handler/DHT22GetHumidityHandler.h | 1 - .../operation-handler/DHT22GetTemperatureHandler.cpp | 3 +-- .../operation-handler/DHT22GetTemperatureHandler.h | 6 +----- .../dht22/operation-handler/DHT22Handler.h | 4 ++-- .../modules/MockDigitalLightModule.h | 3 --- .../operation-handler/MockIsOnDigitalLightHandler.h | 2 -- .../MockTurnOffDigitalLightHandler.h | 2 -- .../MockTurnOnDigitalLightHandler.h | 2 -- .../modules/MockDehumidifierModule.h | 3 --- .../modules/MockHumidifierModule.h | 3 --- .../modules/MockHumidityModule.h | 1 - .../operation-handler/MockHumidityHandler.h | 4 ++-- .../modules/MockTemperatureCoolerModule.h | 3 --- .../modules/MockTemperatureHeaterModule.h | 3 --- .../modules/MockTemperatureModule.h | 1 - .../operation-handler/MockTemperatureHandler.h | 4 ++-- .../interfaces/RetrieveValueFromComponentInterface.h | 12 +++--------- .../ValueReturnedAfterActionHandlerInterface.h | 3 --- .../interfaces/ValueReturnedHandlerInterface.h | 3 --- .../interfaces/components/IsOnSwitchableHandler.h | 2 -- .../interfaces/components/TurnOffSwitchableHandler.h | 2 -- .../interfaces/components/TurnOnSwitchableHandler.h | 2 -- .../operation-handler/MockDigitalLightHandlersTest.h | 3 --- .../operation-handler/MockHumidityHandlerTest.h | 1 - .../operation-handler/MockTemperatureHandlerTest.h | 1 - 27 files changed, 14 insertions(+), 75 deletions(-) diff --git a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/modules/DHT22Module.h b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/modules/DHT22Module.h index 30df621..7c171d7 100644 --- a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/modules/DHT22Module.h +++ b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/modules/DHT22Module.h @@ -16,18 +16,10 @@ class DHT22Module : public ComponentModule { DHT22Module(std::string name, std::list components): ComponentModule(name, components) { _handlers.push_back( - new DHT22GetTemperatureHandler( - DHT22_GET_TEMPERATURE_HANDLER_NAME, - as_route(DHT22_GET_TEMPERATURE_HANDLER_NAME), - components - ) + new DHT22GetTemperatureHandler(DHT22_GET_TEMPERATURE_HANDLER_NAME, components) ); _handlers.push_back( - new DHT22GetHumidityHandler( - DHT22_GET_HUMIDITY_HANDLER_NAME, - as_route(DHT22_GET_HUMIDITY_HANDLER_NAME), - components - ) + new DHT22GetHumidityHandler(DHT22_GET_HUMIDITY_HANDLER_NAME, components) ); }; diff --git a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.cpp b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.cpp index 036c386..a9d6836 100644 --- a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.cpp +++ b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.cpp @@ -3,9 +3,8 @@ DHT22GetHumidityHandler::DHT22GetHumidityHandler( std::string name, - std::string path, std::list components -): DHT22Handler(name, path, components) { +): DHT22Handler(name, components) { } diff --git a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.h b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.h index fd12c9e..ed74ad6 100644 --- a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.h +++ b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.h @@ -12,7 +12,6 @@ class DHT22GetHumidityHandler : public DHT22Handler { DHT22GetHumidityHandler( std::string name, - std::string path, std::list components ); diff --git a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.cpp b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.cpp index 059fa95..bc1d947 100644 --- a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.cpp +++ b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.cpp @@ -3,9 +3,8 @@ DHT22GetTemperatureHandler::DHT22GetTemperatureHandler( std::string name, - std::string path, std::list components -): DHT22Handler(name, path, components) { +): DHT22Handler(name, components) { } diff --git a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.h b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.h index 3a25b10..24f0476 100644 --- a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.h +++ b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.h @@ -10,11 +10,7 @@ class DHT22GetTemperatureHandler : public DHT22Handler { public: - DHT22GetTemperatureHandler( - std::string name, - std::string path, - std::list components - ); + DHT22GetTemperatureHandler(std::string name, std::list components); private: diff --git a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22Handler.h b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22Handler.h index 33c7192..28fffe4 100644 --- a/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22Handler.h +++ b/edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22Handler.h @@ -10,8 +10,8 @@ class DHT22Handler : public RetrieveValueFromComponentInterface components) - : RetrieveValueFromComponentInterface (name, path, components) { + DHT22Handler(std::string name, std::list components) + : RetrieveValueFromComponentInterface (name, components) { }; diff --git a/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h b/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h index e69cce5..1e2c303 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h @@ -23,21 +23,18 @@ class MockDigitalLightModule : public ComponentModule { _handlers.push_back( new MockIsOnDigitalLightHandler( MOCK_IS_ON_HANDLER_MODULE_NAME, - as_route(MOCK_IS_ON_HANDLER_MODULE_NAME), components ) ); _handlers.push_back( new MockTurnOnDigitalLightHandler( MOCK_TURN_ON_HANDLER_MODULE_NAME, - as_route(MOCK_TURN_ON_HANDLER_MODULE_NAME), components ) ); _handlers.push_back( new MockTurnOffDigitalLightHandler( MOCK_TURN_OFF_HANDLER_MODULE_NAME, - as_route(MOCK_TURN_OFF_HANDLER_MODULE_NAME), components ) ); diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h index d02f021..d9f6a53 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h @@ -17,11 +17,9 @@ class MockIsOnDigitalLightHandler: public IsOnSwitchableHandler components ): IsOnSwitchableHandler( name, - path, components ) { diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h index a8e5871..04d2e6b 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h @@ -15,11 +15,9 @@ class MockTurnOffDigitalLightHandler: public TurnOffSwitchableHandler components ): TurnOffSwitchableHandler( name, - path, components ) { diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h index 7dfadaf..013754b 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h @@ -15,11 +15,9 @@ class MockTurnOnDigitalLightHandler: public TurnOnSwitchableHandler components ): TurnOnSwitchableHandler( name, - path, components ) { diff --git a/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockDehumidifierModule.h b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockDehumidifierModule.h index 0fae3e7..920a7ff 100644 --- a/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockDehumidifierModule.h +++ b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockDehumidifierModule.h @@ -18,21 +18,18 @@ class MockDehumidifierModule : public ComponentModule { _handlers.push_back( new TurnOnSwitchableHandler( "dehumidifyOn", - as_route("dehumidifyOn"), components ) ); _handlers.push_back( new TurnOffSwitchableHandler( "dehumidifyOff", - as_route("dehumidifyOff"), components ) ); _handlers.push_back( new IsOnSwitchableHandler( "isDehumidifyOn", - as_route("isDehumidifyOn"), components ) ); diff --git a/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h index 267718d..a3dd978 100644 --- a/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h +++ b/edge/lib/brittany-mock/src/mock-humidity-actuator/modules/MockHumidifierModule.h @@ -18,21 +18,18 @@ class MockHumidifierModule : public ComponentModule { _handlers.push_back( new TurnOnSwitchableHandler( "humidifyOn", - as_route("humidifyOn"), components ) ); _handlers.push_back( new TurnOffSwitchableHandler( "humidifyOff", - as_route("humidifyOff"), components ) ); _handlers.push_back( new IsOnSwitchableHandler( "isHumidifyOn", - as_route("isHumidifyOn"), components ) ); diff --git a/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h b/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h index 6a54f6d..b080e8c 100644 --- a/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h +++ b/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h @@ -19,7 +19,6 @@ class MockHumidityModule : public ComponentModule { _handlers.push_back( new MockHumidityHandler( MOCK_HUMIDITY_HANDLER_NAME, - as_route(MOCK_HUMIDITY_HANDLER_NAME), components ) ); diff --git a/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h b/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h index 8d3efdb..dc544f6 100644 --- a/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h +++ b/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h @@ -10,8 +10,8 @@ class MockHumidityHandler : public RetrieveValueFromComponentInterface components) - : RetrieveValueFromComponentInterface (name, path, components) { + MockHumidityHandler(std::string name, std::list components) + : RetrieveValueFromComponentInterface (name, components) { }; diff --git a/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureCoolerModule.h b/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureCoolerModule.h index 317701b..9b1160e 100644 --- a/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureCoolerModule.h +++ b/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureCoolerModule.h @@ -19,21 +19,18 @@ class MockTemperatureCoolerModule : public ComponentModule { _handlers.push_back( new TurnOnSwitchableHandler( "coolOn", - as_route("coolOn"), components ) ); _handlers.push_back( new TurnOffSwitchableHandler( "coolOff", - as_route("coolOff"), components ) ); _handlers.push_back( new IsOnSwitchableHandler( "isCoolOn", - as_route("isCoolOn"), components ) ); diff --git a/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureHeaterModule.h b/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureHeaterModule.h index a71396d..af31921 100644 --- a/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureHeaterModule.h +++ b/edge/lib/brittany-mock/src/mock-temperature-actuator/modules/MockTemperatureHeaterModule.h @@ -19,21 +19,18 @@ class MockTemperatureHeaterModule : public ComponentModule { _handlers.push_back( new TurnOnSwitchableHandler( "heatOn", - as_route("heatOn"), components ) ); _handlers.push_back( new TurnOffSwitchableHandler( "heatOff", - as_route("heatOff"), components ) ); _handlers.push_back( new IsOnSwitchableHandler( "isHeatOn", - as_route("isHeatOn"), components ) ); diff --git a/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h b/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h index 46c392b..a735ef4 100644 --- a/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h +++ b/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h @@ -19,7 +19,6 @@ class MockTemperatureModule : public ComponentModule { _handlers.push_back( new MockTemperatureHandler( MOCK_TEMPERATURE_HANDLER_NAME, - as_route(MOCK_TEMPERATURE_HANDLER_NAME), components ) ); diff --git a/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h b/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h index f3a4937..8ef0ac5 100644 --- a/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h +++ b/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h @@ -10,8 +10,8 @@ class MockTemperatureHandler : public RetrieveValueFromComponentInterface components) - : RetrieveValueFromComponentInterface (name, path, components) { + MockTemperatureHandler(std::string name, std::list components) + : RetrieveValueFromComponentInterface (name, components) { }; diff --git a/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h b/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h index fab0eb3..7e354d5 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/RetrieveValueFromComponentInterface.h @@ -15,21 +15,18 @@ class RetrieveValueFromComponentInterface : public ValueReturnedAfterActionHandl * @brief Construct a new Retrieve Value From Component Interface object. * * @param name the name of the operation handler. - * @param path the path used for the operation handler. - * @param operationType the operation type. + * @param operationType the operation type. * @param returnedType the returned type. * @param components the list of components. */ RetrieveValueFromComponentInterface( std::string name, - std::string path, OperationType operationType, Type returnedType, std::list components ) : ValueReturnedAfterActionHandlerInterface ( name, - path, operationType, returnedType ) { @@ -40,18 +37,15 @@ class RetrieveValueFromComponentInterface : public ValueReturnedAfterActionHandl * @brief Construct a new Retrieve Value From Component Interface object. * Simplified Constructor that set the handler to a property and return a number. * - * @param name - * @param path - * @param components + * @param name the name of the operation handler. + * @param components the list of components. */ RetrieveValueFromComponentInterface( std::string name, - std::string path, std::list components ) : ValueReturnedAfterActionHandlerInterface ( name, - path, OperationType::PROPERTY, Type::NUMBER ) { diff --git a/edge/lib/brittany/src/operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h b/edge/lib/brittany/src/operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h index dbe7927..dbefa0f 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h @@ -25,18 +25,15 @@ class ValueReturnedAfterActionHandlerInterface : public ValueReturnedHandlerInte * @brief Construct a new Value Returned After Action Handler Interface object. * * @param name the name of the handler. - * @param path the path of the handler. * @param operationType the operationType of the handler. * @param outputType the output type of the handler. */ ValueReturnedAfterActionHandlerInterface( std::string name, - std::string path, OperationType operationType, Type outputType ) : ValueReturnedHandlerInterface( name, - path, operationType, outputType ) {}; diff --git a/edge/lib/brittany/src/operation-handler/interfaces/ValueReturnedHandlerInterface.h b/edge/lib/brittany/src/operation-handler/interfaces/ValueReturnedHandlerInterface.h index e56af51..e4e8798 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/ValueReturnedHandlerInterface.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/ValueReturnedHandlerInterface.h @@ -29,16 +29,13 @@ class ValueReturnedHandlerInterface : public OperationHandler { * @brief Construct a new Value Returned Handler Interface object * * @param name the name of the handler. - * @param path the path(route) of the handler. */ ValueReturnedHandlerInterface( std::string name, - std::string path, OperationType operationType, Type outputType ) : OperationHandler( name, - path, operationType, outputType ) { diff --git a/edge/lib/brittany/src/operation-handler/interfaces/components/IsOnSwitchableHandler.h b/edge/lib/brittany/src/operation-handler/interfaces/components/IsOnSwitchableHandler.h index 6c33682..4e8d2fa 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/components/IsOnSwitchableHandler.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/components/IsOnSwitchableHandler.h @@ -15,11 +15,9 @@ class IsOnSwitchableHandler: public RetrieveValueFromComponentInterface IsOnSwitchableHandler( std::string name, - std::string path, std::list components ): RetrieveValueFromComponentInterface( name, - path, OperationType::PROPERTY, Type::BOOLEAN, components diff --git a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h index b27b9a2..68734f9 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOffSwitchableHandler.h @@ -16,11 +16,9 @@ class TurnOffSwitchableHandler TurnOffSwitchableHandler( std::string name, - std::string path, std::list components ): RetrieveValueFromComponentInterface( name, - path, OperationType::ACTION, Type::STRING, components diff --git a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h index a823d23..a391049 100644 --- a/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h +++ b/edge/lib/brittany/src/operation-handler/interfaces/components/TurnOnSwitchableHandler.h @@ -16,11 +16,9 @@ class TurnOnSwitchableHandler TurnOnSwitchableHandler( std::string name, - std::string path, std::list components ): RetrieveValueFromComponentInterface( name, - path, OperationType::ACTION, Type::STRING, components diff --git a/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h b/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h index 00bc3a8..2a2c221 100644 --- a/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h +++ b/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h @@ -33,17 +33,14 @@ void setup_mock_light_handler_test() { light_list.push_front(light1); turnOffDigitalLightHandler = new MockTurnOffDigitalLightHandler( MOCK_TURN_OFF_LIGHT_NAME, - as_route(MOCK_TURN_OFF_LIGHT_NAME), light_list ); turnOnDigitalLightHandler = new MockTurnOnDigitalLightHandler( MOCK_TURN_ON_LIGHT_NAME, - as_route(MOCK_TURN_ON_LIGHT_NAME), light_list ); isOnDigitalLightHandler = new MockIsOnDigitalLightHandler( MOCK_IS_ON_LIGHT_NAME, - as_route(MOCK_IS_ON_LIGHT_NAME), light_list ); args0["id"] = LIGHT_0_NAME; diff --git a/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h b/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h index 2e57554..4e09769 100644 --- a/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h +++ b/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h @@ -24,7 +24,6 @@ void setup_mock_humidity_handler() { argsMockHumSensorNotFound["id"] = "giogia"; mockHumidityHandler = new MockHumidityHandler( MOCK_HUMIDITY_HANDLER_NAME, - as_route(MOCK_HUMIDITY_HANDLER_NAME), {mockHumSensor} ); } diff --git a/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h b/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h index 4d69f3b..f889232 100644 --- a/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h +++ b/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h @@ -23,7 +23,6 @@ void setup_mock_temperature_handler() { argsMockTempSensorNotFound["id"] = "giogia"; mockTemperatureHandler = new MockTemperatureHandler( MOCK_TEMPERATURE_HANDLER_NAME, - as_route(MOCK_TEMPERATURE_HANDLER_NAME), {mockTempSensor} ); } From aa5e2566e677071775cdb8db45aa60aa522b4d91 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 16:26:13 +0100 Subject: [PATCH 35/46] mock digital light handler names are now hard coded in the class --- .../modules/MockDigitalLightModule.h | 25 +++---------------- .../MockIsOnDigitalLightHandler.h | 10 ++------ .../MockTurnOffDigitalLightHandler.h | 10 ++------ .../MockTurnOnDigitalLightHandler.h | 10 ++------ .../src/operation-handler/HandlerNames.h | 0 edge/test/brittany/edge/EdgeTest.h | 10 ++++---- .../modules/MockDigitalLightModuleTest.h | 6 ++--- .../MockDigitalLightHandlersTest.h | 25 +++++-------------- 8 files changed, 23 insertions(+), 73 deletions(-) create mode 100644 edge/lib/brittany/src/operation-handler/HandlerNames.h diff --git a/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h b/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h index 1e2c303..336e960 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/modules/MockDigitalLightModule.h @@ -10,34 +10,15 @@ #include "mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h" #include "modules/ModuleNames.h" -#define MOCK_IS_ON_HANDLER_MODULE_NAME "isOn" -#define MOCK_TURN_ON_HANDLER_MODULE_NAME "turnOn" -#define MOCK_TURN_OFF_HANDLER_MODULE_NAME "turnOff" - class MockDigitalLightModule : public ComponentModule { public: MockDigitalLightModule(std::list components) : ComponentModule(module_as_string(ModuleNames::Light), components) { - _handlers.push_back( - new MockIsOnDigitalLightHandler( - MOCK_IS_ON_HANDLER_MODULE_NAME, - components - ) - ); - _handlers.push_back( - new MockTurnOnDigitalLightHandler( - MOCK_TURN_ON_HANDLER_MODULE_NAME, - components - ) - ); - _handlers.push_back( - new MockTurnOffDigitalLightHandler( - MOCK_TURN_OFF_HANDLER_MODULE_NAME, - components - ) - ); + _handlers.push_back(new MockIsOnDigitalLightHandler(components)); + _handlers.push_back(new MockTurnOnDigitalLightHandler(components)); + _handlers.push_back(new MockTurnOffDigitalLightHandler(components)); }; }; diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h index d9f6a53..f576ac0 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h @@ -15,14 +15,8 @@ class MockIsOnDigitalLightHandler: public IsOnSwitchableHandler components - ): IsOnSwitchableHandler( - name, - components - ) { - + MockIsOnDigitalLightHandler(std::list components) + : IsOnSwitchableHandler("isOn", components) { }; }; diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h index 04d2e6b..c34474c 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h @@ -3,7 +3,6 @@ #include #include -#include #include "operation-handler/interfaces/components/TurnOffSwitchableHandler.h" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" @@ -13,13 +12,8 @@ class MockTurnOffDigitalLightHandler: public TurnOffSwitchableHandler components - ): TurnOffSwitchableHandler( - name, - components - ) { + MockTurnOffDigitalLightHandler(std::list components) + : TurnOffSwitchableHandler("turnOff", components) { }; diff --git a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h index 013754b..6b91d63 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h @@ -3,7 +3,6 @@ #include #include -#include #include "operation-handler/interfaces/components/TurnOnSwitchableHandler.h" #include "mock-digital-light/hw/MockDigitalLightHw.h" #include "operation-handler/OperationHandlerResult.h" @@ -13,13 +12,8 @@ class MockTurnOnDigitalLightHandler: public TurnOnSwitchableHandler components - ): TurnOnSwitchableHandler( - name, - components - ) { + MockTurnOnDigitalLightHandler(std::list components) + : TurnOnSwitchableHandler("turnOn", components) { } }; diff --git a/edge/lib/brittany/src/operation-handler/HandlerNames.h b/edge/lib/brittany/src/operation-handler/HandlerNames.h new file mode 100644 index 0000000..e69de29 diff --git a/edge/test/brittany/edge/EdgeTest.h b/edge/test/brittany/edge/EdgeTest.h index dad2578..acb0133 100644 --- a/edge/test/brittany/edge/EdgeTest.h +++ b/edge/test/brittany/edge/EdgeTest.h @@ -26,15 +26,15 @@ void test_string_element_is_in_list(std::list list, std::string str void test_light_module_available_path(Edge* edge) { test_string_element_is_in_list( edge -> availablePaths(), - as_route(MOCK_IS_ON_LIGHT_NAME) + "/isOn" ); test_string_element_is_in_list( edge -> availablePaths(), - as_route(MOCK_TURN_OFF_LIGHT_NAME) + "/turnOff" ); test_string_element_is_in_list( edge -> availablePaths(), - as_route(MOCK_TURN_ON_LIGHT_NAME) + "/turnOn" ); } @@ -93,10 +93,10 @@ void test_edge_execute_working(Edge* edge) { TEST_ASSERT_EQUAL(INCREMENT_VALUE_TEST, result0.content().asInt()); Json::Value args; args["id"] = MOCK_LIGHT_IN_EDGE_NAME; - auto result1 = edge -> execute(as_route(MOCK_TURN_ON_HANDLER_MODULE_NAME), args); + auto result1 = edge -> execute("/turnOn", args); check_edge_result_code_is_ok(result1); TEST_ASSERT_EQUAL_STRING(phrase(ContentResult::Ok).c_str(), result1.content().asCString()); - auto result = edge -> execute(as_route(MOCK_IS_ON_HANDLER_MODULE_NAME), args); + auto result = edge -> execute("/isOn", args); check_edge_result_code_is_ok(result); TEST_ASSERT_TRUE(result.content().asBool()); } diff --git a/edge/test/brittany/modules/MockDigitalLightModuleTest.h b/edge/test/brittany/modules/MockDigitalLightModuleTest.h index 10485cb..4a01a8b 100644 --- a/edge/test/brittany/modules/MockDigitalLightModuleTest.h +++ b/edge/test/brittany/modules/MockDigitalLightModuleTest.h @@ -55,7 +55,7 @@ void test_turn_on_turn_off_handler_in_module(OperationHandler* handler, std::str } void test_is_on_is_off_handler_in_module(OperationHandler* handler, std::string component_name, bool isOn) { - check_handler_path(handler, as_route(MOCK_IS_ON_HANDLER_MODULE_NAME)); + check_handler_path(handler, "/isOn"); Json::Value args; args["id"] = component_name; OperationHandlerResult result = handler->handle(args); @@ -68,11 +68,11 @@ void test_is_on_is_off_handler_in_module(OperationHandler* handler, std::string } void test_turn_on_handler_in_module(OperationHandler* handler, std::string component_name) { - test_turn_on_turn_off_handler_in_module(handler, as_route(MOCK_TURN_ON_HANDLER_MODULE_NAME), component_name); + test_turn_on_turn_off_handler_in_module(handler, "/turnOn", component_name); } void test_turn_off_handler_in_module(OperationHandler* handler, std::string component_name) { - test_turn_on_turn_off_handler_in_module(handler, as_route(MOCK_TURN_OFF_HANDLER_MODULE_NAME), component_name); + test_turn_on_turn_off_handler_in_module(handler, "/turnOff", component_name); } void test_is_off_handler_in_module(OperationHandler* handler, std::string component_name) { diff --git a/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h b/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h index 2a2c221..ae846ed 100644 --- a/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h +++ b/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h @@ -10,10 +10,6 @@ #define LIGHT_1_NAME "light1" #define LIGHT_1_PIN 11 -#define MOCK_TURN_OFF_LIGHT_NAME "turnOff" -#define MOCK_TURN_ON_LIGHT_NAME "turnOn" -#define MOCK_IS_ON_LIGHT_NAME "isOn" - MockDigitalLightHw* light0; MockDigitalLightHw* light1; std::list light_list; @@ -31,18 +27,9 @@ void setup_mock_light_handler_test() { light1 = new MockDigitalLightHw(LIGHT_1_NAME, LIGHT_1_PIN); light_list.push_front(light0); light_list.push_front(light1); - turnOffDigitalLightHandler = new MockTurnOffDigitalLightHandler( - MOCK_TURN_OFF_LIGHT_NAME, - light_list - ); - turnOnDigitalLightHandler = new MockTurnOnDigitalLightHandler( - MOCK_TURN_ON_LIGHT_NAME, - light_list - ); - isOnDigitalLightHandler = new MockIsOnDigitalLightHandler( - MOCK_IS_ON_LIGHT_NAME, - light_list - ); + turnOffDigitalLightHandler = new MockTurnOffDigitalLightHandler(light_list); + turnOnDigitalLightHandler = new MockTurnOnDigitalLightHandler(light_list); + isOnDigitalLightHandler = new MockIsOnDigitalLightHandler(light_list); args0["id"] = LIGHT_0_NAME; args1["id"] = LIGHT_1_NAME; argsNotFound["id"] = "the game"; @@ -98,13 +85,13 @@ void test_handle_with_different_args(T h) { //TEST void test_mock_turn_off_digital_light_handler() { - test_handler_name_and_path(turnOffDigitalLightHandler, MOCK_TURN_OFF_LIGHT_NAME); + test_handler_name_and_path(turnOffDigitalLightHandler, "turnOff"); test_handle_with_different_args(turnOffDigitalLightHandler); } //TEST void test_mock_turn_on_digital_light_handler(){ - test_handler_name_and_path(turnOnDigitalLightHandler, MOCK_TURN_ON_LIGHT_NAME); + test_handler_name_and_path(turnOnDigitalLightHandler, "turnOn"); test_handle_with_different_args(turnOnDigitalLightHandler); } @@ -114,7 +101,7 @@ void light_state_check(OperationHandlerResult result, bool isOn) { } void is_on_handler_state_must_be(bool isOn) { - test_handler_name_and_path(isOnDigitalLightHandler, MOCK_IS_ON_LIGHT_NAME); + test_handler_name_and_path(isOnDigitalLightHandler, "isOn"); light_state_check(isOnDigitalLightHandler->handle(args0), isOn); light_state_check(isOnDigitalLightHandler->handle(args1), isOn); check_result_is_not_found(isOnDigitalLightHandler->handle(argsNotFound)); From a33fda0f1fc8bd38a3effab2393c47f3a7ce1ab6 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 16:43:13 +0100 Subject: [PATCH 36/46] temperature and humidity sensor handlers are now hardcoded --- .../mock-humidity-sensor/modules/MockHumidityModule.h | 9 +-------- .../operation-handler/MockHumidityHandler.h | 4 ++-- .../modules/MockTemperatureModule.h | 9 +-------- .../operation-handler/MockTemperatureHandler.h | 4 ++-- .../brittany/operation-handler/MockHumidityHandlerTest.h | 6 +----- .../operation-handler/MockTemperatureHandlerTest.h | 6 +----- 6 files changed, 8 insertions(+), 30 deletions(-) diff --git a/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h b/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h index b080e8c..86ebba8 100644 --- a/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h +++ b/edge/lib/brittany-mock/src/mock-humidity-sensor/modules/MockHumidityModule.h @@ -8,20 +8,13 @@ #include "modules/ComponentModule.h" #include "modules/ModuleNames.h" -#define MOCK_HUMIDITY_HANDLER_NAME "humidity" - class MockHumidityModule : public ComponentModule { public: MockHumidityModule(std::list components) : ComponentModule(module_as_string(ModuleNames::Humidity), components) { - _handlers.push_back( - new MockHumidityHandler( - MOCK_HUMIDITY_HANDLER_NAME, - components - ) - ); + _handlers.push_back(new MockHumidityHandler(components)); }; }; diff --git a/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h b/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h index dc544f6..007f7ff 100644 --- a/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h +++ b/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h @@ -10,8 +10,8 @@ class MockHumidityHandler : public RetrieveValueFromComponentInterface components) - : RetrieveValueFromComponentInterface (name, components) { + MockHumidityHandler(std::list components) + : RetrieveValueFromComponentInterface ("humidity", components) { }; diff --git a/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h b/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h index a735ef4..02e4397 100644 --- a/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h +++ b/edge/lib/brittany-mock/src/mock-temperature-sensor/modules/MockTemperatureModule.h @@ -8,20 +8,13 @@ #include "modules/ComponentModule.h" #include "modules/ModuleNames.h" -#define MOCK_TEMPERATURE_HANDLER_NAME "temperature" - class MockTemperatureModule : public ComponentModule { public: MockTemperatureModule(std::list components) : ComponentModule(module_as_string(ModuleNames::Temperature), components) { - _handlers.push_back( - new MockTemperatureHandler( - MOCK_TEMPERATURE_HANDLER_NAME, - components - ) - ); + _handlers.push_back(new MockTemperatureHandler(components)); }; }; diff --git a/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h b/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h index 8ef0ac5..67cccab 100644 --- a/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h +++ b/edge/lib/brittany-mock/src/mock-temperature-sensor/operation-handler/MockTemperatureHandler.h @@ -10,8 +10,8 @@ class MockTemperatureHandler : public RetrieveValueFromComponentInterface components) - : RetrieveValueFromComponentInterface (name, components) { + MockTemperatureHandler(std::list components) + : RetrieveValueFromComponentInterface ("temperature", components) { }; diff --git a/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h b/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h index 4e09769..52ce97a 100644 --- a/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h +++ b/edge/test/brittany/operation-handler/MockHumidityHandlerTest.h @@ -8,7 +8,6 @@ #define MOCK_HUMIDITY_SENSOR_NAME_IN_HANDLER "sensor" -#define MOCK_HUMIDITY_HANDLER_NAME "humidity" MockHumidityHandler* mockHumidityHandler; MockHumiditySensorHw* mockHumSensor; @@ -22,10 +21,7 @@ void setup_mock_humidity_handler() { argsMockHumSensor["id"] = MOCK_HUMIDITY_SENSOR_NAME_IN_HANDLER; argsMockHumSensorBadReq["za"] = "warudo"; argsMockHumSensorNotFound["id"] = "giogia"; - mockHumidityHandler = new MockHumidityHandler( - MOCK_HUMIDITY_HANDLER_NAME, - {mockHumSensor} - ); + mockHumidityHandler = new MockHumidityHandler({mockHumSensor}); } void post_mock_humidity_handler() { diff --git a/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h b/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h index f889232..5ad46d9 100644 --- a/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h +++ b/edge/test/brittany/operation-handler/MockTemperatureHandlerTest.h @@ -7,7 +7,6 @@ #include "mock-temperature-sensor/hw/MockTemperatureSensorHw.h" #define MOCK_TEMPERATURE_SENSOR_NAME_IN_HANDLER "sensor" -#define MOCK_TEMPERATURE_HANDLER_NAME "temperature" MockTemperatureHandler* mockTemperatureHandler; MockTemperatureSensorHw* mockTempSensor; @@ -21,10 +20,7 @@ void setup_mock_temperature_handler() { argsMockTempSensor["id"] = MOCK_TEMPERATURE_SENSOR_NAME_IN_HANDLER; argsMockTempSensorBadReq["za"] = "warudo"; argsMockTempSensorNotFound["id"] = "giogia"; - mockTemperatureHandler = new MockTemperatureHandler( - MOCK_TEMPERATURE_HANDLER_NAME, - {mockTempSensor} - ); + mockTemperatureHandler = new MockTemperatureHandler({mockTempSensor}); } void post_mock_temperature_handler() { From fd74adeddb3f6691d414d214a6b4c0a0ed11b637 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 16:58:02 +0100 Subject: [PATCH 37/46] removed deprecated ArgsMockModule, MockModule name now hardcoded --- .../src/mock/modules/MockModule.h | 4 +- .../MockArgsOperationHandler.h | 41 ------------------- .../operation-handler/MockOperationHandler.h | 4 +- .../operation-handler/OperationHandlerTest.h | 8 ++-- 4 files changed, 6 insertions(+), 51 deletions(-) delete mode 100644 edge/lib/brittany-mock/src/mock/operation-handler/MockArgsOperationHandler.h diff --git a/edge/lib/brittany-mock/src/mock/modules/MockModule.h b/edge/lib/brittany-mock/src/mock/modules/MockModule.h index db524db..60a0df0 100644 --- a/edge/lib/brittany-mock/src/mock/modules/MockModule.h +++ b/edge/lib/brittany-mock/src/mock/modules/MockModule.h @@ -18,9 +18,7 @@ class MockModule : public Module { public: MockModule(std::string name): Module(name) { - _handlers.push_back( - new MockOperationHandler(OPERATION_HANDLER_IN_MOCK_MODULE_NAME) - ); + _handlers.push_back(new MockOperationHandler()); }; }; diff --git a/edge/lib/brittany-mock/src/mock/operation-handler/MockArgsOperationHandler.h b/edge/lib/brittany-mock/src/mock/operation-handler/MockArgsOperationHandler.h deleted file mode 100644 index 514d2fa..0000000 --- a/edge/lib/brittany-mock/src/mock/operation-handler/MockArgsOperationHandler.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef BRITTANY_MOCK_ARGS_OPERATION_HANDLER_H -#define BRITTANY_MOCK_ARGS_OPERATION_HANDLER_H - -#include -#include -#include "operation-handler/OperationHandlerResult.h" -#include "operation-handler/OperationHandler.h" -#include "HttpStatusCodes_C++.h" -#include "json_util.h" - -/** - * @brief Class that represents a mock OperationHandler that sends back - * the arguments as a JSON string used only for testing purposes. - */ -class MockArgsOperationHandler: public OperationHandler { - -public: - - MockArgsOperationHandler(std::string name, std::string path) : - OperationHandler(name, path, OperationType::PROPERTY, Type::INTEGER) { - - }; - - OperationHandlerResult handle(Json::Value args) { - const std::string output = stringify(args); - stdOutStrategy(output.c_str()); - return OperationHandlerResult(HttpStatus::OK, output); - }; - -private: - - /** - * @brief Describe how to print to the std output the content. - * - * @param content The content to print on the std output. - */ - virtual void stdOutStrategy(std::string content) = 0; - -}; - -#endif //BRITTANY_OPERATION_HANDLER_H \ No newline at end of file diff --git a/edge/lib/brittany-mock/src/mock/operation-handler/MockOperationHandler.h b/edge/lib/brittany-mock/src/mock/operation-handler/MockOperationHandler.h index 21ba627..3e34ad9 100644 --- a/edge/lib/brittany-mock/src/mock/operation-handler/MockOperationHandler.h +++ b/edge/lib/brittany-mock/src/mock/operation-handler/MockOperationHandler.h @@ -14,8 +14,8 @@ class MockOperationHandler: public OperationHandler { public: - MockOperationHandler(std::string name) : - OperationHandler(name, OperationType::PROPERTY, Type::INTEGER) { + MockOperationHandler() : + OperationHandler("value", OperationType::PROPERTY, Type::INTEGER) { _value = 0; }; diff --git a/edge/test/brittany/operation-handler/OperationHandlerTest.h b/edge/test/brittany/operation-handler/OperationHandlerTest.h index c1ec45f..e93f4db 100644 --- a/edge/test/brittany/operation-handler/OperationHandlerTest.h +++ b/edge/test/brittany/operation-handler/OperationHandlerTest.h @@ -2,16 +2,14 @@ #include "mock/operation-handler/MockOperationHandler.h" #include "util.h" -#define OPERATION_HANDLER_NAME "operation" - -MockOperationHandler mockOperationHandler = MockOperationHandler(OPERATION_HANDLER_NAME); +MockOperationHandler mockOperationHandler = MockOperationHandler(); void test_operation_handler_name() { - TEST_ASSERT_EQUAL_STRING(OPERATION_HANDLER_NAME, mockOperationHandler.name().c_str()); + TEST_ASSERT_EQUAL_STRING("value", mockOperationHandler.name().c_str()); } void test_operation_handler_path() { - TEST_ASSERT_EQUAL_STRING(as_route(OPERATION_HANDLER_NAME).c_str(), mockOperationHandler.path().c_str()); + TEST_ASSERT_EQUAL_STRING("/value", mockOperationHandler.path().c_str()); } void test_operation_handler_operation_type() { From 52731446ad58a16d582f83f68df44580223a37ab Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 17:23:56 +0100 Subject: [PATCH 38/46] MockDigitalLight now does not have a pin anymore --- .../src/digital-light/hw/DigitalLightHw.cpp | 2 +- .../src/digital-light/hw/DigitalLightHw.h | 3 ++- .../src/mock-digital-light/hw/MockDigitalLightHw.h | 4 +++- .../brittany/src/hw/interfaces/DigitalLightHwInterface.h | 7 ++----- edge/src/modules/mock-digital-light.h | 4 ++-- edge/test/brittany/edge/EdgeTest.h | 6 +----- edge/test/brittany/edge/ThingDescriptorTest.h | 4 ++-- edge/test/brittany/hw/MockDigitalLightHwTest.h | 8 +------- edge/test/brittany/modules/MockDigitalLightModuleTest.h | 7 ++----- .../operation-handler/MockDigitalLightHandlersTest.h | 6 ++---- edge/test/brittany/utilTest.h | 3 +-- 11 files changed, 19 insertions(+), 35 deletions(-) diff --git a/edge/lib/brittany-concrete/src/digital-light/hw/DigitalLightHw.cpp b/edge/lib/brittany-concrete/src/digital-light/hw/DigitalLightHw.cpp index 33e081b..007ee76 100644 --- a/edge/lib/brittany-concrete/src/digital-light/hw/DigitalLightHw.cpp +++ b/edge/lib/brittany-concrete/src/digital-light/hw/DigitalLightHw.cpp @@ -1,7 +1,7 @@ #include "DigitalLightHw.h" #include -DigitalLightHw::DigitalLightHw(std::string id, uint8_t pin) : DigitalLightHwInterface(id, pin) { +DigitalLightHw::DigitalLightHw(std::string id, uint8_t pin) : DigitalLightHwInterface(id), OnePin(pin) { pinMode(pin, OUTPUT); } diff --git a/edge/lib/brittany-concrete/src/digital-light/hw/DigitalLightHw.h b/edge/lib/brittany-concrete/src/digital-light/hw/DigitalLightHw.h index 1e12d5b..3667c0a 100644 --- a/edge/lib/brittany-concrete/src/digital-light/hw/DigitalLightHw.h +++ b/edge/lib/brittany-concrete/src/digital-light/hw/DigitalLightHw.h @@ -2,12 +2,13 @@ #define BRITTANY_DIGITAL_LIGHT_HW_H #include "hw/interfaces/DigitalLightHwInterface.h" +#include "hw/feature/OnePin.h" /** * @brief Concrete implementation of a Digital Light component. * */ -class DigitalLightHw : public DigitalLightHwInterface { +class DigitalLightHw : public DigitalLightHwInterface, public OnePin { public: diff --git a/edge/lib/brittany-mock/src/mock-digital-light/hw/MockDigitalLightHw.h b/edge/lib/brittany-mock/src/mock-digital-light/hw/MockDigitalLightHw.h index fe0cde6..912bf85 100644 --- a/edge/lib/brittany-mock/src/mock-digital-light/hw/MockDigitalLightHw.h +++ b/edge/lib/brittany-mock/src/mock-digital-light/hw/MockDigitalLightHw.h @@ -12,7 +12,9 @@ class MockDigitalLightHw : public DigitalLightHwInterface { public: - MockDigitalLightHw(std::string id, uint8_t pin) : DigitalLightHwInterface(id, pin){ } + MockDigitalLightHw(std::string id) : DigitalLightHwInterface(id) { + _isOn = false; + } void on() { _isOn = true; diff --git a/edge/lib/brittany/src/hw/interfaces/DigitalLightHwInterface.h b/edge/lib/brittany/src/hw/interfaces/DigitalLightHwInterface.h index 2c23429..4a96806 100644 --- a/edge/lib/brittany/src/hw/interfaces/DigitalLightHwInterface.h +++ b/edge/lib/brittany/src/hw/interfaces/DigitalLightHwInterface.h @@ -8,9 +8,8 @@ /** * @brief An interface to create a component that represent a digital light. - * */ -class DigitalLightHwInterface : public ComponentHw, public OnePin, public Switchable { +class DigitalLightHwInterface : public ComponentHw, public Switchable { public: @@ -18,11 +17,9 @@ class DigitalLightHwInterface : public ComponentHw, public OnePin, public Switch * @brief Construct a new Digital Light Hw Interface object. * * @param id the unique id of the component. - * @param pin the pin attached to the component. */ - DigitalLightHwInterface(std::string id, uint8_t pin) : + DigitalLightHwInterface(std::string id) : ComponentHw(id), - OnePin(pin), Switchable() { }; diff --git a/edge/src/modules/mock-digital-light.h b/edge/src/modules/mock-digital-light.h index df0216a..febd1d7 100644 --- a/edge/src/modules/mock-digital-light.h +++ b/edge/src/modules/mock-digital-light.h @@ -4,8 +4,8 @@ #include "mock-digital-light/modules/MockDigitalLightModule.h" Edge* edge() { - MockDigitalLightHw* light0 = new MockDigitalLightHw("0", 0); - MockDigitalLightHw* light1 = new MockDigitalLightHw("1", 1); + MockDigitalLightHw* light0 = new MockDigitalLightHw("0"); + MockDigitalLightHw* light1 = new MockDigitalLightHw("1"); std::list lights = std::list({light0, light1}); std::list modules; modules.push_back(new MockDigitalLightModule(lights)); diff --git a/edge/test/brittany/edge/EdgeTest.h b/edge/test/brittany/edge/EdgeTest.h index acb0133..24b355a 100644 --- a/edge/test/brittany/edge/EdgeTest.h +++ b/edge/test/brittany/edge/EdgeTest.h @@ -10,7 +10,6 @@ #define EDGE_MOCK_MODULE_NAME "mock-module" #define MOCK_LIGHT_IN_EDGE_NAME "light" -#define MOCK_LIGHT_IN_EDGE_PIN 5 #define TESTING_EXECUTE_ATTEMPT 10 #define INCREMENT_VALUE_TEST 6 @@ -46,10 +45,7 @@ void test_mock_module_available_path(Edge* edge) { } void setup_test_edge() { - mockLightInEdge = new MockDigitalLightHw( - MOCK_LIGHT_IN_EDGE_NAME, - MOCK_LIGHT_IN_EDGE_PIN - ); + mockLightInEdge = new MockDigitalLightHw(MOCK_LIGHT_IN_EDGE_NAME); mockDigitalLights.push_back(mockLightInEdge); } diff --git a/edge/test/brittany/edge/ThingDescriptorTest.h b/edge/test/brittany/edge/ThingDescriptorTest.h index d86429b..b256290 100644 --- a/edge/test/brittany/edge/ThingDescriptorTest.h +++ b/edge/test/brittany/edge/ThingDescriptorTest.h @@ -142,8 +142,8 @@ void contains_all_elements() { } void setup_thing_descriptor_test() { - mockLight0 = new MockDigitalLightHw(MOCK_LIGHT_TD_0_ID, 0); - mockLight1 = new MockDigitalLightHw(MOCK_LIGHT_TD_1_ID, 1); + mockLight0 = new MockDigitalLightHw(MOCK_LIGHT_TD_0_ID); + mockLight1 = new MockDigitalLightHw(MOCK_LIGHT_TD_1_ID); tdEdge = new Edge(EDGE_MOCK_TITLE_TD, std::list({ new MockDigitalLightModule( diff --git a/edge/test/brittany/hw/MockDigitalLightHwTest.h b/edge/test/brittany/hw/MockDigitalLightHwTest.h index dfea3d8..8345086 100644 --- a/edge/test/brittany/hw/MockDigitalLightHwTest.h +++ b/edge/test/brittany/hw/MockDigitalLightHwTest.h @@ -2,18 +2,13 @@ #include "mock-digital-light/hw/MockDigitalLightHw.h" #define DIGITAL_LIGHT_ID "light" -#define DIGITAL_LIGHT_PIN 10 -MockDigitalLightHw mockDigitalLight = MockDigitalLightHw(DIGITAL_LIGHT_ID, DIGITAL_LIGHT_PIN); +MockDigitalLightHw mockDigitalLight = MockDigitalLightHw(DIGITAL_LIGHT_ID); void test_get_mock_digital_light_id() { TEST_ASSERT_EQUAL_STRING(mockDigitalLight.id().c_str(), DIGITAL_LIGHT_ID); } -void test_get_mock_digital_light_pin() { - TEST_ASSERT_EQUAL(mockDigitalLight.pin(), DIGITAL_LIGHT_PIN); -} - void test_mock_digital_light_is_on() { TEST_ASSERT_TRUE(mockDigitalLight.isOn()); } @@ -34,7 +29,6 @@ void test_mock_digital_light_off_operation() { void test_MockDigitalLightHw() { RUN_TEST(test_get_mock_digital_light_id); - RUN_TEST(test_get_mock_digital_light_pin); RUN_TEST(test_mock_digital_light_is_off); // test that light is initally off. RUN_TEST(test_mock_digital_light_on_operation); RUN_TEST(test_mock_digital_light_off_operation); diff --git a/edge/test/brittany/modules/MockDigitalLightModuleTest.h b/edge/test/brittany/modules/MockDigitalLightModuleTest.h index 4a01a8b..c5bf6ff 100644 --- a/edge/test/brittany/modules/MockDigitalLightModuleTest.h +++ b/edge/test/brittany/modules/MockDigitalLightModuleTest.h @@ -9,9 +9,6 @@ #define MOCK_LIGHT_IN_MODULE_NAME_0 "light0" #define MOCK_LIGHT_IN_MODULE_NAME_1 "light1" -#define MOCK_LIGHT_IN_MODULE_PIN_0 1 -#define MOCK_LIGHT_IN_MODULE_PIN_1 2 - MockDigitalLightHw* lightInModule0; MockDigitalLightHw* lightInModule1; MockDigitalLightModule* moduleTest; @@ -20,8 +17,8 @@ std::list components; std::list lightNames = {MOCK_LIGHT_IN_MODULE_NAME_0, MOCK_LIGHT_IN_MODULE_NAME_1}; void setup_module_test() { - lightInModule0 = new MockDigitalLightHw(MOCK_LIGHT_IN_MODULE_NAME_0, MOCK_LIGHT_IN_MODULE_PIN_0); - lightInModule1 = new MockDigitalLightHw(MOCK_LIGHT_IN_MODULE_NAME_1, MOCK_LIGHT_IN_MODULE_PIN_1); + lightInModule0 = new MockDigitalLightHw(MOCK_LIGHT_IN_MODULE_NAME_0); + lightInModule1 = new MockDigitalLightHw(MOCK_LIGHT_IN_MODULE_NAME_1); components.push_back(lightInModule0); components.push_back(lightInModule1); moduleTest = new MockDigitalLightModule(components); diff --git a/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h b/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h index ae846ed..371415a 100644 --- a/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h +++ b/edge/test/brittany/operation-handler/MockDigitalLightHandlersTest.h @@ -6,9 +6,7 @@ #include "util.h" #define LIGHT_0_NAME "light0" -#define LIGHT_0_PIN 10 #define LIGHT_1_NAME "light1" -#define LIGHT_1_PIN 11 MockDigitalLightHw* light0; MockDigitalLightHw* light1; @@ -23,8 +21,8 @@ Json::Value argsNotFound; Json::Value argsBadRequest; void setup_mock_light_handler_test() { - light0 = new MockDigitalLightHw(LIGHT_0_NAME, LIGHT_0_PIN); - light1 = new MockDigitalLightHw(LIGHT_1_NAME, LIGHT_1_PIN); + light0 = new MockDigitalLightHw(LIGHT_0_NAME); + light1 = new MockDigitalLightHw(LIGHT_1_NAME); light_list.push_front(light0); light_list.push_front(light1); turnOffDigitalLightHandler = new MockTurnOffDigitalLightHandler(light_list); diff --git a/edge/test/brittany/utilTest.h b/edge/test/brittany/utilTest.h index a193ffc..b9dedf6 100644 --- a/edge/test/brittany/utilTest.h +++ b/edge/test/brittany/utilTest.h @@ -8,7 +8,6 @@ #define COMPONENT_0_NAME "name0" #define COMPONENT_1_NAME "name1" #define COMPONENT_2_NAME "name2" -#define COMPONENT_2_PIN 10 ComponentHw* component0; ComponentHw* component1; @@ -19,7 +18,7 @@ std::list list_of_light; void setup_util_test() { component0 = new ComponentHw(COMPONENT_0_NAME); component1 = new ComponentHw(COMPONENT_1_NAME); - component2 = new MockDigitalLightHw(COMPONENT_2_NAME, COMPONENT_2_PIN); + component2 = new MockDigitalLightHw(COMPONENT_2_NAME); list.push_front(component0); list.push_front(component1); list.push_front(component2); From cd1ce003ce8b7706c89ad1fe77c886484b07c44c Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Fri, 14 Jan 2022 17:36:12 +0100 Subject: [PATCH 39/46] Moved modules in main in two different folders --- edge/src/main.cpp | 8 ++++---- edge/src/modules/{dht22.h => concrete/concrete-dht22.h} | 0 edge/src/modules/{ => mock}/mock-digital-light.h | 0 .../{ => mock}/mock-temperature-humidity-actuator.h | 0 .../modules/{ => mock}/mock-temperature-humidity-sensor.h | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename edge/src/modules/{dht22.h => concrete/concrete-dht22.h} (100%) rename edge/src/modules/{ => mock}/mock-digital-light.h (100%) rename edge/src/modules/{ => mock}/mock-temperature-humidity-actuator.h (100%) rename edge/src/modules/{ => mock}/mock-temperature-humidity-sensor.h (100%) diff --git a/edge/src/main.cpp b/edge/src/main.cpp index 03c2a4b..4a52ac0 100644 --- a/edge/src/main.cpp +++ b/edge/src/main.cpp @@ -4,10 +4,10 @@ #include "web-server/Esp8266WebServer.h" #include "wifi_secret.h" #include "modules/Module.h" -#include "modules/dht22.h" -#include "modules/mock-digital-light.h" -#include "modules/mock-temperature-humidity-sensor.h" -#include "modules/mock-temperature-humidity-actuator.h" +#include "modules/concrete/concrete-dht22.h" +#include "modules/mock/mock-digital-light.h" +#include "modules/mock/mock-temperature-humidity-sensor.h" +#include "modules/mock/mock-temperature-humidity-actuator.h" Esp8266WebServer* server; diff --git a/edge/src/modules/dht22.h b/edge/src/modules/concrete/concrete-dht22.h similarity index 100% rename from edge/src/modules/dht22.h rename to edge/src/modules/concrete/concrete-dht22.h diff --git a/edge/src/modules/mock-digital-light.h b/edge/src/modules/mock/mock-digital-light.h similarity index 100% rename from edge/src/modules/mock-digital-light.h rename to edge/src/modules/mock/mock-digital-light.h diff --git a/edge/src/modules/mock-temperature-humidity-actuator.h b/edge/src/modules/mock/mock-temperature-humidity-actuator.h similarity index 100% rename from edge/src/modules/mock-temperature-humidity-actuator.h rename to edge/src/modules/mock/mock-temperature-humidity-actuator.h diff --git a/edge/src/modules/mock-temperature-humidity-sensor.h b/edge/src/modules/mock/mock-temperature-humidity-sensor.h similarity index 100% rename from edge/src/modules/mock-temperature-humidity-sensor.h rename to edge/src/modules/mock/mock-temperature-humidity-sensor.h From f3566b1ee99264df96b7a60ef775392284d861b0 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Mon, 17 Jan 2022 11:45:36 +0100 Subject: [PATCH 40/46] Added temperature and humidity edge --- edge/platformio.ini | 6 +++- edge/src/main.cpp | 1 + .../modules/mock/mock-temperature-humidity.h | 31 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 edge/src/modules/mock/mock-temperature-humidity.h diff --git a/edge/platformio.ini b/edge/platformio.ini index a23ec94..cc0c61e 100644 --- a/edge/platformio.ini +++ b/edge/platformio.ini @@ -52,4 +52,8 @@ build_flags = -D BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_SENSOR [env:mock-temperature-humidity-actuator] extends = env:nodemcuv2 -build_flags = -D BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_ACTUATOR \ No newline at end of file +build_flags = -D BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY_ACTUATOR + +[env:mock-temperature-humidity] +extends = env:nodemcuv2 +build_flags = -D BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY diff --git a/edge/src/main.cpp b/edge/src/main.cpp index 4a52ac0..4ec0140 100644 --- a/edge/src/main.cpp +++ b/edge/src/main.cpp @@ -6,6 +6,7 @@ #include "modules/Module.h" #include "modules/concrete/concrete-dht22.h" #include "modules/mock/mock-digital-light.h" +#include "modules/mock/mock-temperature-humidity.h" #include "modules/mock/mock-temperature-humidity-sensor.h" #include "modules/mock/mock-temperature-humidity-actuator.h" diff --git a/edge/src/modules/mock/mock-temperature-humidity.h b/edge/src/modules/mock/mock-temperature-humidity.h new file mode 100644 index 0000000..fdf4958 --- /dev/null +++ b/edge/src/modules/mock/mock-temperature-humidity.h @@ -0,0 +1,31 @@ +#ifdef BRITTANY_MAIN_MOCK_TEMPERATURE_HUMIDITY + +#include "mock-switchable/hw/MockSwitchableHw.h" +#include "mock-temperature-actuator/modules/MockTemperatureCoolerModule.h" +#include "mock-temperature-actuator/modules/MockTemperatureHeaterModule.h" +#include "mock-humidity-actuator/modules/MockHumidifierModule.h" +#include "mock-humidity-actuator/modules/MockDehumidifierModule.h" +#include "mock-temperature-sensor/hw/MockTemperatureSensorHw.h" +#include "mock-temperature-sensor/modules/MockTemperatureModule.h" +#include "mock-humidity-sensor/hw/MockHumiditySensorHw.h" +#include "mock-humidity-sensor/modules/MockHumidityModule.h" + +Edge* edge() { + MockSwitchableHw* heater = new MockSwitchableHw("heater"); + MockSwitchableHw* cooler = new MockSwitchableHw("cooler"); + MockSwitchableHw* humidifier = new MockSwitchableHw("humidifier"); + MockSwitchableHw* dehumidifier = new MockSwitchableHw("dehumidifier"); + MockHumiditySensorHw* humSensor = new MockHumiditySensorHw("hum"); + MockTemperatureSensorHw* tempSensor = new MockTemperatureSensorHw("temp"); + std::list modules; + modules.push_back(new MockTemperatureHeaterModule({heater})); + modules.push_back(new MockTemperatureCoolerModule({cooler})); + modules.push_back(new MockHumidifierModule({humidifier})); + modules.push_back(new MockDehumidifierModule({dehumidifier})); + modules.push_back(new MockHumidityModule({humSensor})); + modules.push_back(new MockTemperatureModule({tempSensor})); + std::string edge_desc = "Mock Temperature Edge for handling temperature and humidity."; + return new Edge(edge_desc, modules); +} + +#endif \ No newline at end of file From aafe601e104a3b7db0570a44415eaad46b97ca27 Mon Sep 17 00:00:00 2001 From: ElisaTronetti Date: Wed, 19 Jan 2022 09:32:48 +0000 Subject: [PATCH 41/46] Solved merge conflict in build.gradle --- edge/build.gradle.kts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/edge/build.gradle.kts b/edge/build.gradle.kts index 7ab6940..c770f5e 100644 --- a/edge/build.gradle.kts +++ b/edge/build.gradle.kts @@ -11,9 +11,7 @@ tasks.register("testRealHw") { } tasks.register("upload") { -<<<<<<< HEAD - commandLine("pio", "run", "-e", "mock-digital-light", "-t", "upload", "-t", "monitor") -======= + val envs: List = File("platformio.ini").readLines().filter{ it.matches(Regex("\\[env:.*\\]")) }.map{ @@ -30,5 +28,4 @@ tasks.register("upload") { if(userInput != null && userInput >= 0 && userInput < envs.size) { commandLine("pio", "run", "-e", envs[userInput], "-t", "upload") } ->>>>>>> f3566b1ee99264df96b7a60ef775392284d861b0 } From f2b5d7972c909015ed425ab7e89635261d9fee03 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 19 Jan 2022 12:23:41 +0100 Subject: [PATCH 42/46] Fixed modules bug in td generation --- .../thing-descriptor/ThingDescriptorBuilder.h | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h b/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h index b18c682..45cf139 100644 --- a/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h +++ b/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h @@ -7,6 +7,8 @@ #include "modules/ComponentModule.h" #include "hw/ComponentHw.h" #include +#include +#include using namespace TD; @@ -50,15 +52,29 @@ class ThingDescriptorBuilder { } static void add_modules(Json::Value &td, std::list modules) { - int i, j = 0; + std::unordered_map> map; for(Module* m : modules) { - td["modules"][0]["module"] = m -> name(); ComponentModule* cm = static_cast*>(m); - j = 0; - for(ComponentHw h : cm -> components()) { - td["modules"][0]["components"][j++] = h.id(); + if(map.find(cm -> name()) == map.end()) { + map.insert_or_assign(cm -> name(), cm -> components()); + } else { + std::list components = map[cm -> name()]; + for(ComponentHw c : cm -> components()) { + components.push_back(c); + } + map.insert_or_assign(cm -> name(), components); + } + } + int i = 0; + for(const std::pair> n : map) { + td["modules"][i]["module"] = n.first.c_str(); + int j = 0; + for(ComponentHw c : n.second) { + Serial.println(c.id().c_str()); + td["modules"][i]["components"][j] = c.id().c_str(); + j++; } - i++; + i++; } } From 5b066055bb5a78783c5be1ed4082dad046c5255b Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 19 Jan 2022 12:47:39 +0100 Subject: [PATCH 43/46] simplified modules add operation on td build --- .../thing-descriptor/ThingDescriptorBuilder.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h b/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h index 45cf139..b8d3406 100644 --- a/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h +++ b/edge/lib/brittany/src/thing-descriptor/ThingDescriptorBuilder.h @@ -8,7 +8,6 @@ #include "hw/ComponentHw.h" #include #include -#include using namespace TD; @@ -55,24 +54,21 @@ class ThingDescriptorBuilder { std::unordered_map> map; for(Module* m : modules) { ComponentModule* cm = static_cast*>(m); + std::list components; if(map.find(cm -> name()) == map.end()) { - map.insert_or_assign(cm -> name(), cm -> components()); + components = cm -> components(); } else { - std::list components = map[cm -> name()]; - for(ComponentHw c : cm -> components()) { - components.push_back(c); - } - map.insert_or_assign(cm -> name(), components); + components = map[cm -> name()]; + components.splice(components.end(), cm -> components()); } + map.insert_or_assign(cm -> name(), components); } int i = 0; for(const std::pair> n : map) { td["modules"][i]["module"] = n.first.c_str(); int j = 0; for(ComponentHw c : n.second) { - Serial.println(c.id().c_str()); - td["modules"][i]["components"][j] = c.id().c_str(); - j++; + td["modules"][i]["components"][j++] = c.id().c_str(); } i++; } From bbe8e9da04156d0703a66231f9a796825603f411 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 19 Jan 2022 12:54:57 +0100 Subject: [PATCH 44/46] changed humidity module name to airHumidity --- edge/lib/brittany/src/modules/ModuleNames.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edge/lib/brittany/src/modules/ModuleNames.h b/edge/lib/brittany/src/modules/ModuleNames.h index ae3722c..a335df8 100644 --- a/edge/lib/brittany/src/modules/ModuleNames.h +++ b/edge/lib/brittany/src/modules/ModuleNames.h @@ -26,7 +26,7 @@ inline std::string module_as_string(ModuleNames moduleName) { case ModuleNames::Temperature: return "temperature"; case ModuleNames::Humidity: - return "humidity"; + return "airHumidity"; case ModuleNames::Light: return "light"; default: From 0edc2480dde471e172d1362a13cee2b557d04916 Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 19 Jan 2022 13:00:00 +0100 Subject: [PATCH 45/46] Added test for multiple modules name in td, fixed airHumidity test --- edge/test/brittany/edge/ThingDescriptorTest.h | 9 ++++++++- edge/test/brittany/modules/ModuleNamesTest.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/edge/test/brittany/edge/ThingDescriptorTest.h b/edge/test/brittany/edge/ThingDescriptorTest.h index b256290..593fe90 100644 --- a/edge/test/brittany/edge/ThingDescriptorTest.h +++ b/edge/test/brittany/edge/ThingDescriptorTest.h @@ -7,12 +7,14 @@ #define EDGE_MOCK_TITLE_TD "MockEdge" #define MOCK_LIGHT_TD_0_ID "0" #define MOCK_LIGHT_TD_1_ID "1" +#define MOCK_LIGHT_TD_2_ID "2" #define TD_IP_TEST "127.0.0.1" #define TD_PORT_TEST 80 MockDigitalLightHw* mockLight0; MockDigitalLightHw* mockLight1; +MockDigitalLightHw* mockLight2; Edge* tdEdge; @@ -64,6 +66,7 @@ void contains_modules() { TEST_ASSERT_TRUE(moduleComponents.isArray()); TEST_ASSERT_EQUAL_STRING(MOCK_LIGHT_TD_0_ID, moduleComponents[0].asCString()); TEST_ASSERT_EQUAL_STRING(MOCK_LIGHT_TD_1_ID, moduleComponents[1].asCString()); + TEST_ASSERT_EQUAL_STRING(MOCK_LIGHT_TD_2_ID, moduleComponents[2].asCString()); } void check_additional_actions(Json::Value action) { @@ -144,17 +147,21 @@ void contains_all_elements() { void setup_thing_descriptor_test() { mockLight0 = new MockDigitalLightHw(MOCK_LIGHT_TD_0_ID); mockLight1 = new MockDigitalLightHw(MOCK_LIGHT_TD_1_ID); + mockLight2 = new MockDigitalLightHw(MOCK_LIGHT_TD_2_ID); tdEdge = new Edge(EDGE_MOCK_TITLE_TD, std::list({ new MockDigitalLightModule( std::list({mockLight0, mockLight1}) + ), + new MockDigitalLightModule( + std::list({mockLight2}) )} ) ); } void post_thing_descriptor_test() { - delete mockLight0, mockLight1, tdEdge; + delete mockLight0, mockLight1, mockLight2, tdEdge; } void test_ThingDescriptor() { diff --git a/edge/test/brittany/modules/ModuleNamesTest.h b/edge/test/brittany/modules/ModuleNamesTest.h index 06a62c5..f45cde3 100644 --- a/edge/test/brittany/modules/ModuleNamesTest.h +++ b/edge/test/brittany/modules/ModuleNamesTest.h @@ -4,7 +4,7 @@ void test_module_as_string() { TEST_ASSERT_EQUAL_STRING("light", module_as_string(ModuleNames::Light).c_str()); TEST_ASSERT_EQUAL_STRING("temperature", module_as_string(ModuleNames::Temperature).c_str()); - TEST_ASSERT_EQUAL_STRING("humidity", module_as_string(ModuleNames::Humidity).c_str()); + TEST_ASSERT_EQUAL_STRING("airHumidity", module_as_string(ModuleNames::Humidity).c_str()); TEST_ASSERT_EQUAL_STRING("", module_as_string(ModuleNames(104131)).c_str()); } From ff494b98f491337ed05afe8a3c00d2540520eaef Mon Sep 17 00:00:00 2001 From: Angelo Filaseta Date: Wed, 19 Jan 2022 13:43:37 +0100 Subject: [PATCH 46/46] changed ait humidity handler name --- .../operation-handler/MockHumidityHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h b/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h index 007f7ff..c2b3f7c 100644 --- a/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h +++ b/edge/lib/brittany-mock/src/mock-humidity-sensor/operation-handler/MockHumidityHandler.h @@ -11,7 +11,7 @@ class MockHumidityHandler : public RetrieveValueFromComponentInterface components) - : RetrieveValueFromComponentInterface ("humidity", components) { + : RetrieveValueFromComponentInterface ("airHumidity", components) { };