mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-01-26 16:13:07 +01:00
OBP60Formatter: add option to switch of creation of simulation data and use pure conversion/formatting function
This commit is contained in:
@@ -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 <formatValue> 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<GwApi::BoatValue> tmpBValue; // Temp variable to get converted data value from <OBP60Formatter::formatValue>
|
||||
double result; // data value converted to user defined target data format
|
||||
constexpr bool NO_SIMUDATA = true; // switch off simulation feature of <formatValue> function
|
||||
|
||||
// prepare temporary BoatValue structure for use in <formatValue>
|
||||
tmpBValue = std::unique_ptr<GwApi::BoatValue>(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
|
||||
|
||||
Reference in New Issue
Block a user