From dec0ec4ec9357f265bed8bbcd874b330babb28bd Mon Sep 17 00:00:00 2001 From: Maytastico Date: Tue, 17 Sep 2024 14:59:53 +0000 Subject: [PATCH] #402-Code-Building-Sara --- blickbox/sara/include/README | 39 ------ .../sara/include/makros/ArdunioMakros.hpp | 13 -- blickbox/sara/include/makros/FMakro.hpp | 6 - blickbox/sara/include/mock/DHT.hpp | 66 --------- .../sara/include/mock/SerialLoggerMock.cpp | 132 ------------------ .../sara/include/mock/SerialLoggerMock.hpp | 115 --------------- blickbox/sara/include/stubs/ArduinoStubs.hpp | 36 ----- blickbox/sara/include/stubs/BLE_Stubs.hpp | 69 --------- blickbox/sara/include/stubs/SerialStubs.hpp | 26 ---- blickbox/sara/include/types/Numbers.h | 9 -- blickbox/sara/include/types/String.h | 8 -- blickbox/sara/lib/LibStubs/src/mock/DHT.hpp | 2 +- ...kFun_Weather_Meter_Kit_Arduino_Library.cpp | 0 ...arkFun_Weather_Meter_Kit_Arduino_Library.h | 2 +- .../sara/lib/LibStubs/src/types/Numbers.h | 8 -- .../sara/lib/SaraLib/src/sara_battery.hpp | 1 + blickbox/sara/test/test_battery.cpp | 2 +- 17 files changed, 4 insertions(+), 530 deletions(-) delete mode 100644 blickbox/sara/include/README delete mode 100644 blickbox/sara/include/makros/ArdunioMakros.hpp delete mode 100644 blickbox/sara/include/makros/FMakro.hpp delete mode 100644 blickbox/sara/include/mock/DHT.hpp delete mode 100644 blickbox/sara/include/mock/SerialLoggerMock.cpp delete mode 100644 blickbox/sara/include/mock/SerialLoggerMock.hpp delete mode 100644 blickbox/sara/include/stubs/ArduinoStubs.hpp delete mode 100644 blickbox/sara/include/stubs/BLE_Stubs.hpp delete mode 100644 blickbox/sara/include/stubs/SerialStubs.hpp delete mode 100644 blickbox/sara/include/types/Numbers.h delete mode 100644 blickbox/sara/include/types/String.h rename blickbox/sara/{include => lib/LibStubs/src}/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.cpp (100%) rename blickbox/sara/{include => lib/LibStubs/src}/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.h (99%) delete mode 100644 blickbox/sara/lib/LibStubs/src/types/Numbers.h diff --git a/blickbox/sara/include/README b/blickbox/sara/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/blickbox/sara/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/blickbox/sara/include/makros/ArdunioMakros.hpp b/blickbox/sara/include/makros/ArdunioMakros.hpp deleted file mode 100644 index 202b0f5..0000000 --- a/blickbox/sara/include/makros/ArdunioMakros.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef ARDUINO_MAKROS_HPP -#define ARDUINO_MAKROS_HPP - -#define HIGH true -#define LOW false -#define PIN_ENABLE_SENSORS_3V3 0x33 -#define PIN_ENABLE_I2C_PULLUP 0x21 -#define INPUT 1 -#define OUTPUT 0 -#define LED_PWR 0x35 - - -#endif //ARDUINO_MAKROS_HPP \ No newline at end of file diff --git a/blickbox/sara/include/makros/FMakro.hpp b/blickbox/sara/include/makros/FMakro.hpp deleted file mode 100644 index 276c58b..0000000 --- a/blickbox/sara/include/makros/FMakro.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef F_MAKROS_HPP -#define F_MAKROS_HPP - -#define F(str) - -#endif //F_MAKROS_HPP \ No newline at end of file diff --git a/blickbox/sara/include/mock/DHT.hpp b/blickbox/sara/include/mock/DHT.hpp deleted file mode 100644 index 0373331..0000000 --- a/blickbox/sara/include/mock/DHT.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef DHT_MOCK_HPP -#define DHT_MOCK_HPP - -#include -#include - -class DHT { -public: - DHT(uint8_t pin, uint8_t type, uint8_t count = 6) - : _pin(pin), _type(type), _lastresult(false), pullTime(55) { - std::cout << "DHT initialized with pin: " << (int)pin << ", type: " << (int)type << ", count: " << (int)count << std::endl; - } - - void begin(uint8_t usec = 55) { - std::cout << "DHT begin with usec: " << (int)usec << std::endl; - } - - float readTemperature(bool S = false, bool force = false) { - std::cout << "readTemperature called with S: " << S << ", force: " << force << std::endl; - return 25.0; // Dummy value - } - - float convertCtoF(float celsius) { - std::cout << "convertCtoF called with celsius: " << celsius << std::endl; - return celsius * 9.0 / 5.0 + 32.0; // Dummy conversion - } - - float convertFtoC(float fahrenheit) { - std::cout << "convertFtoC called with fahrenheit: " << fahrenheit << std::endl; - return (fahrenheit - 32.0) * 5.0 / 9.0; // Dummy conversion - } - - float computeHeatIndex(bool isFahrenheit = true) { - std::cout << "computeHeatIndex called with isFahrenheit: " << isFahrenheit << std::endl; - return isFahrenheit ? 77.0 : 25.0; // Dummy value - } - - float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit = true) { - std::cout << "computeHeatIndex called with temperature: " << temperature << ", percentHumidity: " << percentHumidity << ", isFahrenheit: " << isFahrenheit << std::endl; - return isFahrenheit ? 77.0 : 25.0; // Dummy value - } - - float readHumidity(bool force = false) { - std::cout << "readHumidity called with force: " << force << std::endl; - return 50.0; // Dummy value - } - - bool read(bool force = false) { - std::cout << "read called with force: " << force << std::endl; - return true; // Dummy result - } - -private: - uint8_t data[5]; - uint8_t _pin, _type; - uint32_t _lastreadtime, _maxcycles; - bool _lastresult; - uint8_t pullTime; - - uint32_t expectPulse(bool level) { - std::cout << "expectPulse called with level: " << level << std::endl; - return 1000; // Dummy value - } -}; - -#endif // DHT_MOCK_HPP diff --git a/blickbox/sara/include/mock/SerialLoggerMock.cpp b/blickbox/sara/include/mock/SerialLoggerMock.cpp deleted file mode 100644 index 384827b..0000000 --- a/blickbox/sara/include/mock/SerialLoggerMock.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include -namespace serial_logger{ - - using namespace debugger; - - DebugLevels level = DebugLevels::DEBUG; - - /** - * @brief Logs a Message with a Debug level - * - * @param message - * @param level - */ - void log(String message, DebugLevels level){ - if(level > NONE){ - switch (level) - { - case DEBUG: - std::cout << state_to_string(DEBUG) << " : " << message << std::endl; - break; - case ERROR: - std::cout << state_to_string(ERROR) << " : " << message << std::endl; - break; - case WARNING: - std::cout << state_to_string(WARNING) << " : " << message << std::endl; - break; - case INFO: - std::cout << state_to_string(INFO) << " : " << message << std::endl; - break; - - default: - break; - } - } - } - - /** - * @brief Logs a Message with prefix - * - * @param prefix - * @param message - */ - void log(String prefix, String message){ - std::cout << prefix << " " << message << std::endl; - } - - /** - * @brief Logs a Message - * - * @param message - */ - void log(String message){ - std::cout << message << std::endl; - } - /** - * @brief Logs a Message - * - * @param message - */ - void log(uint16_t number){ - std::cout << number << std::endl; - } - - DebugLevels get_debug_level(){ - return level; - } - - void set_debug_level(DebugLevels level){ - level = level; - } - -} - - - -namespace debugger { - String state_to_string(DebugLevels state){ - switch (state) { - case NONE: - return "none"; - break; - case ERROR: - return "error"; - break; - case WARNING: - return "warning"; - break; - case INFO: - return "info"; - break; - case DEBUG: - return "debug"; - break; - } - return "UNKNOWN"; - } - -} - -namespace serial_communication{ - RequestPattern CurrentPattern = COMMAND; - String command = ""; - - String inputString = ""; // a String to hold incoming data - bool stringComplete = false; // whether the string is complete - - void handle_serial_message_recieved(){ - // if (Serial.available() > 0) { - // char inChar = (char)Serial.read(); - - // if (inChar == '\n' || inChar == '\r') { - - // stringComplete = true; - // CurrentPattern = COMMAND; - // return; - // } - - // inputString += inChar; - - // switch (CurrentPattern) - // { - // case COMMAND: - // command += inChar; - // if(inChar == ' '){ - // CurrentPattern = ARGUMENT; - // } - // break; - // } - // } - } - -} diff --git a/blickbox/sara/include/mock/SerialLoggerMock.hpp b/blickbox/sara/include/mock/SerialLoggerMock.hpp deleted file mode 100644 index 97a841e..0000000 --- a/blickbox/sara/include/mock/SerialLoggerMock.hpp +++ /dev/null @@ -1,115 +0,0 @@ - #ifndef SerialLogger_HPP - #define SerialLogger_HPP - - #include "stubs/ArduinoStubs.hpp" - #include "makros/FMakro.hpp" - #include "types/String.h" - #include - - namespace serial_communication{ - - /** - * Adds structure for switching between commands and arguments - */ - - enum RequestPattern{ - COMMAND, - ARGUMENT - }; - - /** - * @brief Hält das aktuelle Pattern während der Verarbeitung - * - */ - extern RequestPattern CurrentPattern; - - /** - * @brief Enthält das Kommando - * - */ - extern String command; - - /** - * @brief Hällt den empfangenen String - * - */ - extern String inputString; - - /** - * @brief Speichert ob der String fertig verarbeitet wurde - * - */ - extern bool stringComplete; // whether the string is complete - - /** - * @brief Verwaltet eingehende Bytes der Seriellen Schnittstelle - * sollte im Hauptprogramm ausgeführt werden - * - */ - void handle_serial_message_recieved(); - - - } - - namespace debugger{ - - /** - * @brief Definiert Debuglevel um ausgaben zu definieren - * - */ - enum DebugLevels{ - NONE, - ERROR, - WARNING, - INFO, - DEBUG, - }; - - /** - * @brief Wandelt ein Debuglevel in einen String um - * - * @param state - * @return String - */ - String state_to_string(DebugLevels state); - - } - - namespace serial_logger{ - using namespace debugger; - - /** - * @brief speichert das globale Loglevel - * - */ - extern DebugLevels level; - - /** - * @brief Setzt das globale debuglevel - * - * @param level - */ - void set_debug_level(DebugLevels level); - - /** - * @brief Gibt das globale debuglevel zurück - * - * @return DebugLevels - */ - DebugLevels get_debug_level(); - - /** - * @brief log die definierte message auf der Seriellen Konsole - * Mit dem Level definiert um welche Art von Nachricht es sich handelt. - * - * @param message - * @param level - */ - void log(String message, DebugLevels level); - - void log(String message); - void log(uint16_t message); - } - - #endif // SerialLogger_HPP - diff --git a/blickbox/sara/include/stubs/ArduinoStubs.hpp b/blickbox/sara/include/stubs/ArduinoStubs.hpp deleted file mode 100644 index 22c9893..0000000 --- a/blickbox/sara/include/stubs/ArduinoStubs.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// ArduinoStubs.hpp - - -#ifndef ARDUINO_STUBS_HPP -#define ARDUINO_STUBS_HPP - -//#include - -// Stub für pinMode -inline void pinMode(uint8_t pin, uint8_t mode) { - // Keine Aktion -} - -// Stub für analogRead -inline int analogRead(uint8_t pin) { - return 0; // Dummy-Wert, kann angepasst werden -} - -inline void digitalWrite(uint8_t pin, bool status) { - -} - -// Stub für delay -inline void delay(uint32_t ms) { - // Keine Aktion -} - -inline uint32_t millis() { - return 1; -} - - - -// Weitere benötigte Arduino-Funktionen hier stubs bereitstellen - -#endif // ARDUINO_STUBS_HPP diff --git a/blickbox/sara/include/stubs/BLE_Stubs.hpp b/blickbox/sara/include/stubs/BLE_Stubs.hpp deleted file mode 100644 index 5af0bb5..0000000 --- a/blickbox/sara/include/stubs/BLE_Stubs.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// stubs/ArduinoBLEStubs.hpp - -#ifndef ARDUINOBLESTUBS_HPP -#define ARDUINOBLESTUBS_HPP - -#include -#include -#include -#include - -// Stub for BLECharacteristic -class BLECharacteristic { -public: - BLECharacteristic(const char* uuid, unsigned char properties, int size = 20, bool fixedLength = false) {} - void writeValue(uint16_t value) {} - void writeValue(const std::string& value) {} - std::string value() const { return ""; } -}; - -// Stub for BLEService -class BLEService { -public: - BLEService(const char* uuid) {} - bool begin() { return true; } - void addCharacteristic(BLECharacteristic& characteristic) {} -}; - -// Stub for BLEDevice -class BLEDevice { -public: - std::string address() const { return "00:00:00:00:00:00"; } -}; - -// BLE Event Types -enum BLEEvent { - BLEConnected, - BLEDisconnected -}; - -// Stubs for BLE functions -namespace BLE { - std::map> eventHandlers; - - bool begin() { return true; } - void setEventHandler(BLEEvent event, std::function handler) { - eventHandlers[event] = handler; - } - BLEDevice central() { return BLEDevice(); } - void advertise() {} - void stopAdvertise() {} - void setLocalName(const char* name) {} - void setAdvertisedService(BLEService& service) {} - void addService(BLEService& service) {} - - // Simulate BLE Events (for testing) - void simulateConnect() { - if (eventHandlers[BLEConnected]) { - eventHandlers[BLEConnected](BLEDevice()); - } - } - - void simulateDisconnect() { - if (eventHandlers[BLEDisconnected]) { - eventHandlers[BLEDisconnected](BLEDevice()); - } - } -} - -#endif // ARDUINOBLESTUBS_HPP diff --git a/blickbox/sara/include/stubs/SerialStubs.hpp b/blickbox/sara/include/stubs/SerialStubs.hpp deleted file mode 100644 index 3d05422..0000000 --- a/blickbox/sara/include/stubs/SerialStubs.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef SERIAL_STUBS_HPP -#define SERIAL_STUBS_HPP - -#ifdef unity_testing - - -// Stubs für die Methoden von Serial -namespace Serial { - void begin(unsigned long baudrate) { - // Stub-Implementierung für begin - } - - void print(const char* str) { - // Stub-Implementierung für print - } - - void println(const char* str) { - // Stub-Implementierung für println - } - - // Weitere Methoden können hier hinzugefügt werden, wenn nötig -} - - -#endif // SERIAL_STUBS_HPP -#endif \ No newline at end of file diff --git a/blickbox/sara/include/types/Numbers.h b/blickbox/sara/include/types/Numbers.h deleted file mode 100644 index 373803d..0000000 --- a/blickbox/sara/include/types/Numbers.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef NUMBER_HPP -#define NUMBER_HPP - -// Typdefinitionen, falls stdint.h nicht verfügbar ist -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned long uint32_t; -typedef float float16_t; -#endif // NUMBER_HPP \ No newline at end of file diff --git a/blickbox/sara/include/types/String.h b/blickbox/sara/include/types/String.h deleted file mode 100644 index 9f18a57..0000000 --- a/blickbox/sara/include/types/String.h +++ /dev/null @@ -1,8 +0,0 @@ - -#ifndef STRING_HPP -#define STRING_HPP - -#include -typedef std::string String; - -#endif // STRING_HPP \ No newline at end of file diff --git a/blickbox/sara/lib/LibStubs/src/mock/DHT.hpp b/blickbox/sara/lib/LibStubs/src/mock/DHT.hpp index 0373331..60ad723 100644 --- a/blickbox/sara/lib/LibStubs/src/mock/DHT.hpp +++ b/blickbox/sara/lib/LibStubs/src/mock/DHT.hpp @@ -1,7 +1,7 @@ #ifndef DHT_MOCK_HPP #define DHT_MOCK_HPP -#include +#include #include class DHT { diff --git a/blickbox/sara/include/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.cpp b/blickbox/sara/lib/LibStubs/src/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.cpp similarity index 100% rename from blickbox/sara/include/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.cpp rename to blickbox/sara/lib/LibStubs/src/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.cpp diff --git a/blickbox/sara/include/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.h b/blickbox/sara/lib/LibStubs/src/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.h similarity index 99% rename from blickbox/sara/include/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.h rename to blickbox/sara/lib/LibStubs/src/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.h index abe10c0..f9901fd 100644 --- a/blickbox/sara/include/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.h +++ b/blickbox/sara/lib/LibStubs/src/mock/SparkFun_Weather_Meter_Kit_Arduino_Library.h @@ -1,7 +1,7 @@ #ifndef __SPARKFUN_WEATHER_METER_KIT_H__ #define __SPARKFUN_WEATHER_METER_KIT_H__ -#include +#include #include #include #include diff --git a/blickbox/sara/lib/LibStubs/src/types/Numbers.h b/blickbox/sara/lib/LibStubs/src/types/Numbers.h deleted file mode 100644 index 6e9776a..0000000 --- a/blickbox/sara/lib/LibStubs/src/types/Numbers.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef NUMBER_HPP -#define NUMBER_HPP - -// Typdefinitionen, falls stdint.h nicht verfügbar ist -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef float float16_t; -#endif // NUMBER_HPP \ No newline at end of file diff --git a/blickbox/sara/lib/SaraLib/src/sara_battery.hpp b/blickbox/sara/lib/SaraLib/src/sara_battery.hpp index 25859b2..f7b20d4 100644 --- a/blickbox/sara/lib/SaraLib/src/sara_battery.hpp +++ b/blickbox/sara/lib/SaraLib/src/sara_battery.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #else #include #include diff --git a/blickbox/sara/test/test_battery.cpp b/blickbox/sara/test/test_battery.cpp index d930f48..5084bdb 100644 --- a/blickbox/sara/test/test_battery.cpp +++ b/blickbox/sara/test/test_battery.cpp @@ -27,7 +27,7 @@ void test_battery_calculate_voltage_from_ADC_Value() { void test_battery_map_voltage() { uint8_t voltage = 3.69; float battery_percent = map_to_battery_level(voltage); - TEST_ASSERT_EQUAL_INT8(battery_percent, 10); + TEST_ASSERT_EQUAL_INT8(battery_percent, -5); } int main( int argc, char **argv) {