added option to add CR for printf support

This commit is contained in:
Robin Müller 2021-01-08 02:06:27 +01:00
parent 4255176b5c
commit 2ef3e0aa7b
5 changed files with 26 additions and 17 deletions

View File

@ -377,11 +377,11 @@ ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId,
auto poolIter = localPoolMap.find(localPoolId);
if (poolIter == localPoolMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "HousekeepingManager::fechPoolEntry: Pool entry "
sif::warning << "HousekeepingManager::fetchPoolEntry: Pool entry "
"not found." << std::endl;
#else
fsfw::printWarning("HousekeepingManager::fechPoolEntry: Pool entry "
"not found.");
fsfw::printWarning("HousekeepingManager::fetchPoolEntry: Pool entry "
"not found.\n");
#endif
return HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND;
}
@ -393,7 +393,7 @@ ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId,
" Pool entry type conflict." << std::endl;
#else
fsfw::printWarning("HousekeepingManager::fetchPoolEntry:"
" Pool entry type conflict.");
" Pool entry type conflict.\n");
#endif
return HasLocalDataPoolIF::POOL_ENTRY_TYPE_CONFLICT;
}

View File

@ -110,13 +110,12 @@ void LocalPoolObjectBase::reportReadCommitError(const char* variableType,
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << variableType << ": " << type << " call | " << errMsg
<< " | Owner: " << std::hex << std::setw(8)
<< std::setfill('0') << objectId << " LPID: 0x" << lpId
<< std::dec << std::endl;
<< " | Owner: 0x" << std::hex << std::setw(8)
<< std::setfill('0') << objectId << std::dec << " LPID: " << lpId
<< std::endl;
#else
fsfw::printWarning("LocalPoolVariable: %s of local pool variable of "
"object 0x%08x and lp ID 0x%08x failed.\n\r",
type, objectId, lpId);
fsfw::printWarning("%s: %s call | %s | Owner: 0x%08x LPID: %lu\n",
variableType, type, errMsg, objectId, lpId);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
}

View File

@ -98,11 +98,11 @@ inline T& LocalPoolVector<T, vectorSize>::operator [](size_t i) {
// If this happens, I have to set some value. I consider this
// a configuration error, but I wont exit here.
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
sif::warning << "LocalPoolVector: Invalid index. Setting or returning"
" last value!" << std::endl;
#else
fsfw::printError("LocalPoolVector: Invalid index. Setting or returning"
" last value!\n\r");
fsfw::printWarning("LocalPoolVector: Invalid index. Setting or returning"
" last value!\n");
#endif
return value[vectorSize];
}
@ -115,11 +115,11 @@ inline const T& LocalPoolVector<T, vectorSize>::operator [](size_t i) const {
// If this happens, I have to set some value. I consider this
// a configuration error, but I wont exit here.
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalPoolVector: Invalid index. Setting or returning"
sif::warning << "LocalPoolVector: Invalid index. Setting or returning"
" last value!" << std::endl;
#else
fsfw::printError("LocalPoolVector: Invalid index. Setting or returning"
" last value!\n\r");
fsfw::printWarning("LocalPoolVector: Invalid index. Setting or returning"
" last value!\n");
#endif
return value[vectorSize];
}

View File

@ -10,7 +10,7 @@ fsfw::PrintLevel printLevel = fsfw::PrintLevel::DEBUG;
#if defined(WIN32) && FSFW_COLORED_OUTPUT == 1
bool consoleInitialized = false;
#endif /* defined(WIN32) && FSFW_COLORED_OUTPUT == 1 */
bool addCrAtEnd = false;
#if FSFW_DISABLE_PRINTOUT == 0
uint8_t printBuffer[fsfwconfig::FSFW_PRINT_BUFFER_SIZE];
@ -80,6 +80,10 @@ void fsfwPrint(fsfw::PrintLevel printType, const char* fmt, va_list arg) {
len += vsnprintf(bufferPosition + len, sizeof(printBuffer) - len, fmt, arg);
if(addCrAtEnd) {
len += sprintf(bufferPosition + len, "\r");
}
printf("%s", printBuffer);
}
@ -105,6 +109,10 @@ void fsfw::printDebug(const char *fmt, ...) {
va_end(args);
}
void fsfw::setToAddCrAtEnd(bool addCrAtEnd_) {
addCrAtEnd = addCrAtEnd_;
}
void fsfw::printError(const char *fmt, ...) {
va_list args;
va_start(args, fmt);

View File

@ -16,6 +16,8 @@ enum class PrintLevel {
void setPrintLevel(PrintLevel printLevel);
PrintLevel getPrintLevel();
void setToAddCrAtEnd(bool addCrAtEnd_);
/**
* These functions can be used like the C stdio printf and forward the
* supplied formatted string arguments to a printf function.