fmi2Status FMU2Wrapper::setDebugLogging(fmi2Boolean loggingOn, size_t nCategories, const fmi2String categories[]) { fmi2Status ret = fmi2OK; if (_logger == NULL) { LogSettings logSettings = _globalSettings.getLogSettings(); FMU2Logger::initialize(this, logSettings, loggingOn); _logger = Logger::getInstance(); } else { _logger->setEnabled(loggingOn); } if (nCategories == 0) { _logCategories = loggingOn? 0xFFFF: 0x0000; _logger->setAll(loggingOn? LL_DEBUG: LL_ERROR); } else { int i, j, nSupported = sizeof(_LogCategoryFMUNames) / sizeof(fmi2String); for (i = 0; i < nCategories; i++) { if (strcmp(categories[i], "logAll") == 0) { _logCategories = loggingOn? 0xFFFF: 0x0000; _logger->setAll(loggingOn? LL_DEBUG: LL_ERROR); continue; } for (j = 0; j < nSupported; j++) { if (strcmp(categories[i], _LogCategoryFMUNames[j]) == 0) { if (loggingOn) _logCategories |= (1 << j); else _logCategories &= ~(1 << j); switch (j) { case logEvents: _logger->set(LC_EVENTS, loggingOn? LL_DEBUG: LL_ERROR); break; case logNonlinearSystems: _logger->set(LC_NLS, loggingOn? LL_DEBUG: LL_ERROR); break; } break; } } // warn about unsupported log category if (j == nSupported) { unsigned int logCategories_bak = _logCategories; _logCategories = 0xFFFF; FMU2_LOG(this, fmi2Warning, logStatusWarning, "Unsupported log category \"%s\"", categories[i]); _logCategories = logCategories_bak; ret = fmi2Warning; } } } return ret; }
fmi2Status FMU2Wrapper::setString(const fmi2ValueReference vr[], size_t nvr, const fmi2String value[]) { if (nvr > _string_buffer.size()) { FMU2_LOG(this, fmi2Error, logStatusError, "Attempt to set %d fmi2String; FMU only has %d", nvr, _string_buffer.size()); return fmi2Error; } for (size_t i = 0; i < nvr; i++) _string_buffer[i] = string(value[i]); // convert to string _model->setString(vr, nvr, &_string_buffer[0]); _need_update = true; return fmi2OK; }
fmi2Status FMU2Wrapper::getString(const fmi2ValueReference vr[], size_t nvr, fmi2String value[]) { if (nvr > _string_buffer.size()) { FMU2_LOG(this, fmi2Error, logStatusError, "Attempt to get %d fmi2String; FMU only has %d", nvr, _string_buffer.size()); return fmi2Error; } if (_need_update) updateModel(); _model->getString(vr, nvr, &_string_buffer[0]); for (size_t i = 0; i < nvr; i++) value[i] = _string_buffer[i].c_str(); // convert to fmi2String return fmi2OK; }
void FMU2Logger::writeInternal(string msg, LogCategory cat, LogLevel lvl, LogStructure ls) { LogCategoryFMU category; fmi2Status status; if (ls == LS_END) return; // determine FMI status and category from LogLevel switch (lvl) { case LL_ERROR: status = fmi2Error; category = logStatusError; break; case LL_WARNING: status = fmi2Warning; category = logStatusWarning; break; default: status = fmi2OK; category = logStatusWarning; } // override FMU category with matching LogCategory switch (cat) { case LC_NLS: category = logNonlinearSystems; break; case LC_EVENTS: category = logEvents; break; } // call FMU log function FMU2_LOG(_wrapper, status, category, msg.c_str()); }
fmi2Status FMU2Wrapper::setDebugLogging(fmi2Boolean loggingOn, size_t nCategories, const fmi2String categories[]) { fmi2Status ret = fmi2OK; if (nCategories == 0) _logCategories = loggingOn? 0xFFFF: 0x0000; else { int i, j, nSupported = sizeof(_logCategoryNames) / sizeof(fmi2String); for (i = 0; i < nCategories; i++) { if (strcmp(categories[i], "logAll") == 0) { _logCategories = loggingOn? 0xFFFF: 0x0000; continue; } for (j = 0; j < nSupported; j++) { if (strcmp(categories[i], _logCategoryNames[j]) == 0) { if (loggingOn) _logCategories |= (1 << j); else _logCategories &= ~(1 << j); break; } } // warn about unsupported log category if (j == nSupported) { unsigned int logCategories_bak = _logCategories; _logCategories = 0xFFFF; FMU2_LOG(this, fmi2Warning, logStatusWarning, "Unsupported log category \"%s\"", categories[i]); _logCategories = logCategories_bak; ret = fmi2Warning; } } } return ret; }