Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#286 implementierung des mockings pro layer mit konfigurierbaren datensets #33

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions blickbox/sara/include/makros/ArdunioMakros.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#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
6 changes: 6 additions & 0 deletions blickbox/sara/include/makros/FMakro.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef F_MAKROS_HPP
#define F_MAKROS_HPP

#define F(str)

#endif //F_MAKROS_HPP
66 changes: 66 additions & 0 deletions blickbox/sara/include/mock/DHT.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#ifndef DHT_MOCK_HPP
#define DHT_MOCK_HPP

#include <types/Numbers.h>
#include <iostream>

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
132 changes: 132 additions & 0 deletions blickbox/sara/include/mock/SerialLoggerMock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#include <mock/SerialLoggerMock.hpp>
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;
// }
// }
}

}
115 changes: 115 additions & 0 deletions blickbox/sara/include/mock/SerialLoggerMock.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#ifndef SerialLogger_HPP
#define SerialLogger_HPP

#include "stubs/ArduinoStubs.hpp"
#include "makros/FMakro.hpp"
#include "types/String.h"
#include <iostream>

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

Loading