diff --git a/lib/obp60task/OBP60Formatter.cpp b/lib/obp60task/OBP60Formatter.cpp index 456eab0..ebb2142 100644 --- a/lib/obp60task/OBP60Formatter.cpp +++ b/lib/obp60task/OBP60Formatter.cpp @@ -49,7 +49,15 @@ String formatLongitude(double lon) { return String(degree, 0) + "\x90 " + String(minute, 4) + "' " + ((lon > 0) ? "E" : "W"); } -FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ +// Convert and format boat value from SI to user defined format (definition for compatibility purposes) +FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata) { + + return formatValue(value, commondata, false); // call with standard handling of user setting for simulation data +} + +// Convert and format boat value from SI to user defined format +// generate random simulation data; can be deselected to use conversion+formatting function even in simulation mode +FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool ignoreSimuDataSetting){ GwLog *logger = commondata.logger; FormattedData result; static int dayoffset = 0; @@ -66,9 +74,15 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ String windspeedFormat = commondata.config->getString(commondata.config->windspeedFormat); // [m/s|km/h|kn|bft] String tempFormat = commondata.config->getString(commondata.config->tempFormat); // [K|°C|°F] String dateFormat = commondata.config->getString(commondata.config->dateFormat); // [DE|GB|US] - bool usesimudata = commondata.config->getBool(commondata.config->useSimuData); // [on|off] String precision = commondata.config->getString(commondata.config->valueprecision); // [1|2] + bool usesimudata; + if (ignoreSimuDataSetting){ + usesimudata = false; // ignore user setting for simulation data; we want to format the boat value passed to this function + } else { + usesimudata = commondata.config->getBool(commondata.config->useSimuData); // [on|off] + } + // If boat value not valid if (! value->valid && !usesimudata){ result.svalue = "---"; @@ -881,11 +895,12 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ return result; } -// Helper method for conversion of boat data values from SI to user defined format +// Helper method for conversion of any data value from SI to user defined format double convertValue(const double &value, const String &name, const String &format, CommonData &commondata) { std::unique_ptr tmpBValue; // Temp variable to get converted data value from double result; // data value converted to user defined target data format + constexpr bool NO_SIMUDATA = true; // switch off simulation feature of function // prepare temporary BoatValue structure for use in tmpBValue = std::unique_ptr(new GwApi::BoatValue(name)); // we don't need boat value name for pure value conversion @@ -893,10 +908,11 @@ double convertValue(const double &value, const String &name, const String &forma tmpBValue->valid = true; tmpBValue->value = value; - result = formatValue(tmpBValue.get(), commondata).cvalue; // get value (converted) + result = formatValue(tmpBValue.get(), commondata, NO_SIMUDATA).cvalue; // get value (converted); ignore any simulation data setting return result; } +// Helper method for conversion of any data value from SI to user defined format double convertValue(const double &value, const String &format, CommonData &commondata) { double result; // data value converted to user defined target data format diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index 79d1ad9..02afba9 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -204,9 +204,8 @@ typedef struct{ // Formatter for boat values FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata); +FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool ignoreSimuDataSetting); // Helper method for conversion of any data value from SI to user defined format (defined in OBP60Formatter) double convertValue(const double &value, const String &format, CommonData &commondata); double convertValue(const double &value, const String &name, const String &format, CommonData &commondata); -// Helper method for conversion of boat data values from user defined format to SI (defined in OBP60Formatter) -double convertToSItemp(const double &value, const String &name, const String &format, CommonData &commondata);