CMake added *.c* wildcard to compile extern c files; Added calculation for absoluteHumidity
This commit is contained in:
@@ -16,7 +16,7 @@ add_custom_command(OUTPUT ${HUMIDITYSERVER_CODEGEN_SOURCES}
|
|||||||
DEPENDS ${HUMIDITYSERVER_HEADERS_PATHS}
|
DEPENDS ${HUMIDITYSERVER_HEADERS_PATHS}
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB HUMIDITYSERVER_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
|
file(GLOB HUMIDITYSERVER_SOURCES ${PROJECT_SOURCE_DIR}/*.c*)
|
||||||
|
|
||||||
list(APPEND HUMIDITYSERVER_SOURCES ${HUMIDITYSERVER_CODEGEN_SOURCES})
|
list(APPEND HUMIDITYSERVER_SOURCES ${HUMIDITYSERVER_CODEGEN_SOURCES})
|
||||||
|
|
||||||
|
80
RestServer/humidityserver/src/calculate.c
Normal file
80
RestServer/humidityserver/src/calculate.c
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h> /* link against math lib */
|
||||||
|
#include "calculate.h"
|
||||||
|
|
||||||
|
#define R 8314.3 //J/(kmol*K) (universelle Gaskonstante)
|
||||||
|
#define mw 18.016 //kg/kmol (Molekulargewicht des Wasserdampfes)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Bezeichnungen:
|
||||||
|
r = relative Luftfeuchte
|
||||||
|
T = Temperatur in °C
|
||||||
|
TK = Temperatur in Kelvin (TK = T + 273.15)
|
||||||
|
TD = Taupunkttemperatur in °C
|
||||||
|
DD = Dampfdruck in hPa
|
||||||
|
SDD = Sättigungsdampfdruck in hPa
|
||||||
|
|
||||||
|
Parameter:
|
||||||
|
a = 7.5, b = 237.3 für T >= 0
|
||||||
|
a = 7.6, b = 240.7 für T < 0 über Wasser (Taupunkt)
|
||||||
|
a = 9.5, b = 265.5 für T < 0 über Eis (Frostpunkt)
|
||||||
|
|
||||||
|
R* = 8314.3 J/(kmol*K) (universelle Gaskonstante)
|
||||||
|
mw = 18.016 kg/kmol (Molekulargewicht des Wasserdampfes)
|
||||||
|
AF = absolute Feuchte in g Wasserdampf pro m3 Luft
|
||||||
|
|
||||||
|
Formeln:
|
||||||
|
|
||||||
|
SDD(T) = 6.1078 * 10^((a*T)/(b+T))
|
||||||
|
DD(r,T) = r/100 * SDD(T)
|
||||||
|
r(T,TD) = 100 * SDD(TD) / SDD(T)
|
||||||
|
TD(r,T) = b*v/(a-v) mit v(r,T) = log10(DD(r,T)/6.1078)
|
||||||
|
AF(r,TK) = 10^5 * mw/R* * DD(r,T)/TK; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK
|
||||||
|
*/
|
||||||
|
|
||||||
|
static float sdd(float temperature) {
|
||||||
|
//select constant based on input temperature
|
||||||
|
float a = 7.5, b = 237.3;
|
||||||
|
if (temperature >= 0) {
|
||||||
|
a = 7.6;
|
||||||
|
b = 240.7;
|
||||||
|
}
|
||||||
|
return 6.1078 * pow(10, (a * temperature) / (b + temperature));
|
||||||
|
}
|
||||||
|
|
||||||
|
static float dd(float relativeHumidity, float temperature) {
|
||||||
|
return relativeHumidity / 100 * sdd(temperature);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CURRENTLY UNUSED
|
||||||
|
|
||||||
|
static float r(float temperature, float dewTemperature) {
|
||||||
|
// This is optional. Necessary with dew point measurements.
|
||||||
|
return 100 * sdd(dewTemperature) / sdd(temperature);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float v(float relativeHumidity, float temperature) {
|
||||||
|
log10(dd(relativeHumidity, temperature)/6.1078);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float td(float relativeHumidity, float temperature) {
|
||||||
|
//select constant based on input temperature
|
||||||
|
float a = 7.5, b = 237.3;
|
||||||
|
if (temperature >= 0) {
|
||||||
|
a = 7.6;
|
||||||
|
b = 240.7;
|
||||||
|
}
|
||||||
|
return b * v(relativeHumidity, temperature) / (a - v(relativeHumidity, temperature));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
static float af(float relativeHumidity, float temperature) {
|
||||||
|
float tk = temperature + 273.15;
|
||||||
|
return pow(10, 5) * mw/R * dd(relativeHumidity, temperature) / tk;
|
||||||
|
}
|
||||||
|
|
||||||
|
float absoluteHumidityFloat(float temperature, float humidity) {
|
||||||
|
return af(humidity, temperature);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
15
RestServer/humidityserver/src/calculate.h
Normal file
15
RestServer/humidityserver/src/calculate.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef calculate_H
|
||||||
|
#define calculate_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float absoluteHumidityFloat(float temperature, float humidity);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@@ -2,7 +2,7 @@
|
|||||||
// For more information, please visit: https://github.com/loentar/ngrest
|
// For more information, please visit: https://github.com/loentar/ngrest
|
||||||
|
|
||||||
#include "humidityserver.h"
|
#include "humidityserver.h"
|
||||||
|
#include "calculate.h"
|
||||||
/*std::string humidityserver::echo(const std::string& text)
|
/*std::string humidityserver::echo(const std::string& text)
|
||||||
{
|
{
|
||||||
return "Hi, " + text;
|
return "Hi, " + text;
|
||||||
@@ -10,5 +10,5 @@
|
|||||||
|
|
||||||
float humidityserver::absolutehumidity(float temperature, float humidity) {
|
float humidityserver::absolutehumidity(float temperature, float humidity) {
|
||||||
|
|
||||||
return temperature + humidity;
|
return absoluteHumidityFloat(temperature, humidity);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user