Temperature scale is now configurable
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
<!-- Temperature Simulator Configuration (used for all simulation setups) -->
|
||||
<temperature_simconfig>
|
||||
<TemperatureScale value="Celsius" />
|
||||
<StaticTemperatureDefaultValue value="89" />
|
||||
<DynTemperatureSimPeriod value="100" />
|
||||
<DynTemperatureSimUnit value="us" />
|
||||
|
||||
@@ -153,6 +153,13 @@ void Configuration::setParameter(std::string name, std::string value)
|
||||
else if(name == "ErrorStoreMode")
|
||||
ErrorStoreMode = StringToEnum(value);
|
||||
// Temperature Simulation related
|
||||
else if (name == "TemperatureScale") {
|
||||
if (value != "Celsius" && value != "Fahrenheit" && value != "Kelvin") {
|
||||
SC_REPORT_FATAL("Configuration", ("Invalid value for parameter " + name + ".").c_str());
|
||||
throw;
|
||||
}
|
||||
temperatureSim.TemperatureScale = value;
|
||||
}
|
||||
else if (name == "StaticTemperatureDefaultValue")
|
||||
temperatureSim.StaticTemperatureDefaultValue = string2int(value);
|
||||
else if (name == "DynTemperatureSimPeriod")
|
||||
|
||||
@@ -47,6 +47,9 @@
|
||||
|
||||
struct TemperatureSimConfig {
|
||||
|
||||
// Temperature Scale
|
||||
std::string TemperatureScale;
|
||||
|
||||
// Static Temperature Simulation parameters
|
||||
int StaticTemperatureDefaultValue;
|
||||
|
||||
|
||||
@@ -39,13 +39,29 @@
|
||||
#include "TemperatureController.h"
|
||||
#include "../controller/core/configuration/Configuration.h"
|
||||
|
||||
double TemperatureController::temperatureConvert(double tKelvin)
|
||||
{
|
||||
if (temperatureScale == "Celsius") {
|
||||
return tKelvin - 273.15;
|
||||
}
|
||||
else if (temperatureScale == "Fahrenheit") {
|
||||
return (tKelvin - 273.15) * 1.8 + 32;
|
||||
}
|
||||
|
||||
return tKelvin;
|
||||
}
|
||||
|
||||
double TemperatureController::getTemperature(int deviceId, float currentPower)
|
||||
{
|
||||
if (dynamicTempSimEnabled == true) {
|
||||
currentPowerValues.at(deviceId) = currentPower;
|
||||
|
||||
// FIXME using the static temperature value until the vector of
|
||||
// temperatures is filled
|
||||
if (temperatureValues.empty())
|
||||
return staticTemperature;
|
||||
return temperatureValues.at(deviceId);
|
||||
return temperatureConvert(staticTemperature + 273.15);
|
||||
|
||||
return temperatureConvert(temperatureValues.at(deviceId));
|
||||
} else {
|
||||
printDebugMessage("Temperature is " + std::to_string(staticTemperature));
|
||||
return staticTemperature;
|
||||
|
||||
@@ -56,6 +56,8 @@ public:
|
||||
|
||||
SC_CTOR(TemperatureController)
|
||||
{
|
||||
temperatureScale = Configuration::getInstance().temperatureSim.TemperatureScale;
|
||||
|
||||
dynamicTempSimEnabled = Configuration::getInstance().DynamicTemperatureSimulation;
|
||||
|
||||
if (dynamicTempSimEnabled == true) {
|
||||
@@ -91,6 +93,9 @@ public:
|
||||
double getTemperature(int deviceId, float currentPower);
|
||||
|
||||
private:
|
||||
std::string temperatureScale;
|
||||
double temperatureConvert(double tKelvin);
|
||||
|
||||
double staticTemperature;
|
||||
|
||||
bool dynamicTempSimEnabled;
|
||||
|
||||
@@ -137,6 +137,7 @@ The XML code below shows a typic configuration:
|
||||
|
||||
<!-- Temperature Simulator Configuration (used for all simulation setups) -->
|
||||
<temperature_simconfig>
|
||||
<TemperatureScale value="Celsius" />
|
||||
<StaticTemperatureDefaultValue value="89" />
|
||||
<DynTemperatureSimPeriod value="100" />
|
||||
<DynTemperatureSimUnit value="ms" />
|
||||
@@ -249,6 +250,10 @@ Below are listed the configuration sections and configuration fields.
|
||||
- "0": static temperature during simulation
|
||||
|
||||
- **Temperature Simulator Configuration**
|
||||
- *TemperatureScale* (string)
|
||||
- "Celsius"
|
||||
- "Fahrenheit"
|
||||
- "Kelvin"
|
||||
- *StaticTemperatureDefaultValue* (int)
|
||||
- Temperature value for simulations with static temperature
|
||||
- *DynTemperatureSimPeriod* (double)
|
||||
|
||||
Reference in New Issue
Block a user