Merge remote-tracking branch 'ksat/mueller/master' into mueller/master

This commit is contained in:
Robin Müller 2021-01-25 13:10:58 +01:00
commit 0bb19c5ee5
9 changed files with 101 additions and 55 deletions

View File

@ -6,6 +6,7 @@
#include "../ipc/QueueFactory.h" #include "../ipc/QueueFactory.h"
#include "../ipc/MutexFactory.h" #include "../ipc/MutexFactory.h"
MessageQueueId_t EventManagerIF::eventmanagerQueue = MessageQueueIF::NO_QUEUE;
// If one checks registerListener calls, there are around 40 (to max 50) // If one checks registerListener calls, there are around 40 (to max 50)
// objects registering for certain events. // objects registering for certain events.

View File

@ -1,11 +1,12 @@
#ifndef EVENTMANAGERIF_H_ #ifndef FSFW_EVENTS_EVENTMANAGERIF_H_
#define EVENTMANAGERIF_H_ #define FSFW_EVENTS_EVENTMANAGERIF_H_
#include "EventMessage.h" #include "EventMessage.h"
#include "eventmatching/eventmatching.h" #include "eventmatching/eventmatching.h"
#include "../objectmanager/ObjectManagerIF.h" #include "../objectmanager/ObjectManagerIF.h"
#include "../ipc/MessageQueueSenderIF.h" #include "../ipc/MessageQueueSenderIF.h"
#include "../ipc/MessageQueueIF.h" #include "../ipc/MessageQueueIF.h"
#include "../serviceinterface/ServiceInterface.h"
class EventManagerIF { class EventManagerIF {
public: public:
@ -41,11 +42,19 @@ public:
static void triggerEvent(EventMessage* message, static void triggerEvent(EventMessage* message,
MessageQueueId_t sentFrom = 0) { MessageQueueId_t sentFrom = 0) {
static MessageQueueId_t eventmanagerQueue = MessageQueueIF::NO_QUEUE;
if (eventmanagerQueue == MessageQueueIF::NO_QUEUE) { if (eventmanagerQueue == MessageQueueIF::NO_QUEUE) {
EventManagerIF *eventmanager = objectManager->get<EventManagerIF>( EventManagerIF *eventmanager = objectManager->get<EventManagerIF>(
objects::EVENT_MANAGER); objects::EVENT_MANAGER);
if (eventmanager == nullptr) { if (eventmanager == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "EventManagerIF::triggerEvent: EventManager invalid or not found!"
<< std::endl;
#else
sif::printWarning("EventManagerIF::triggerEvent: "
"EventManager invalid or not found!");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return; return;
} }
eventmanagerQueue = eventmanager->getEventReportQueue(); eventmanagerQueue = eventmanager->getEventReportQueue();
@ -53,6 +62,10 @@ public:
MessageQueueSenderIF::sendMessage(eventmanagerQueue, message, sentFrom); MessageQueueSenderIF::sendMessage(eventmanagerQueue, message, sentFrom);
} }
private:
//! Initialized by EventManager (C++11 does not allow header-only static member initialization).
static MessageQueueId_t eventmanagerQueue;
}; };
#endif /* EVENTMANAGERIF_H_ */ #endif /* FSFW_EVENTS_EVENTMANAGERIF_H_ */

View File

@ -29,7 +29,7 @@ ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string setMessage,
#if FSFW_COLORED_OUTPUT == 1 #if FSFW_COLORED_OUTPUT == 1
if(setMessage.find("DEBUG") != std::string::npos) { if(setMessage.find("DEBUG") != std::string::npos) {
colorPrefix = sif::ANSI_COLOR_MAGENTA; colorPrefix = sif::ANSI_COLOR_CYAN;
} }
else if(setMessage.find("INFO") != std::string::npos) { else if(setMessage.find("INFO") != std::string::npos) {
colorPrefix = sif::ANSI_COLOR_GREEN; colorPrefix = sif::ANSI_COLOR_GREEN;

View File

@ -45,7 +45,7 @@ void fsfwPrint(sif::PrintLevel printType, const char* fmt, va_list arg) {
len += sprintf(bufferPosition, sif::ANSI_COLOR_GREEN); len += sprintf(bufferPosition, sif::ANSI_COLOR_GREEN);
} }
else if(printType == sif::PrintLevel::DEBUG_LEVEL) { else if(printType == sif::PrintLevel::DEBUG_LEVEL) {
len += sprintf(bufferPosition, sif::ANSI_COLOR_MAGENTA); len += sprintf(bufferPosition, sif::ANSI_COLOR_CYAN);
} }
else if(printType == sif::PrintLevel::WARNING_LEVEL) { else if(printType == sif::PrintLevel::WARNING_LEVEL) {
len += sprintf(bufferPosition, sif::ANSI_COLOR_YELLOW); len += sprintf(bufferPosition, sif::ANSI_COLOR_YELLOW);

View File

@ -39,6 +39,11 @@ public:
*/ */
std::string* getPreamble(); std::string* getPreamble();
/**
* Can be used to determine if the stream was configured to add CR characters in addition
* to newline characters.
* @return
*/
bool crAdditionEnabled() const; bool crAdditionEnabled() const;
protected: protected:

View File

@ -5,15 +5,15 @@
LocalPool::LocalPool(object_id_t setObjectId, const LocalPoolConfig& poolConfig, LocalPool::LocalPool(object_id_t setObjectId, const LocalPoolConfig& poolConfig,
bool registered, bool spillsToHigherPools): bool registered, bool spillsToHigherPools):
SystemObject(setObjectId, registered), SystemObject(setObjectId, registered),
NUMBER_OF_POOLS(poolConfig.size()), NUMBER_OF_SUBPOOLS(poolConfig.size()),
spillsToHigherPools(spillsToHigherPools) { spillsToHigherPools(spillsToHigherPools) {
if(NUMBER_OF_POOLS == 0) { if(NUMBER_OF_SUBPOOLS == 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalPool::LocalPool: Passed pool configuration is " sif::error << "LocalPool::LocalPool: Passed pool configuration is "
<< " invalid!" << std::endl; << " invalid!" << std::endl;
#endif #endif
} }
max_pools_t index = 0; max_subpools_t index = 0;
for (const auto& currentPoolConfig: poolConfig) { for (const auto& currentPoolConfig: poolConfig) {
this->numberOfElements[index] = currentPoolConfig.first; this->numberOfElements[index] = currentPoolConfig.first;
this->elementSizes[index] = currentPoolConfig.second; this->elementSizes[index] = currentPoolConfig.second;
@ -98,7 +98,7 @@ ReturnValue_t LocalPool::modifyData(store_address_t storeId,
ReturnValue_t LocalPool::modifyData(store_address_t storeId, ReturnValue_t LocalPool::modifyData(store_address_t storeId,
uint8_t **packetPtr, size_t *size) { uint8_t **packetPtr, size_t *size) {
ReturnValue_t status = RETURN_FAILED; ReturnValue_t status = RETURN_FAILED;
if (storeId.poolIndex >= NUMBER_OF_POOLS) { if (storeId.poolIndex >= NUMBER_OF_SUBPOOLS) {
return ILLEGAL_STORAGE_ID; return ILLEGAL_STORAGE_ID;
} }
if ((storeId.packetIndex >= numberOfElements[storeId.poolIndex])) { if ((storeId.packetIndex >= numberOfElements[storeId.poolIndex])) {
@ -127,7 +127,7 @@ ReturnValue_t LocalPool::deleteData(store_address_t storeId) {
#endif #endif
ReturnValue_t status = RETURN_OK; ReturnValue_t status = RETURN_OK;
size_type pageSize = getPageSize(storeId.poolIndex); size_type pageSize = getSubpoolElementSize(storeId.poolIndex);
if ((pageSize != 0) and if ((pageSize != 0) and
(storeId.packetIndex < numberOfElements[storeId.poolIndex])) { (storeId.packetIndex < numberOfElements[storeId.poolIndex])) {
uint16_t packetPosition = getRawPosition(storeId); uint16_t packetPosition = getRawPosition(storeId);
@ -151,7 +151,7 @@ ReturnValue_t LocalPool::deleteData(uint8_t *ptr, size_t size,
store_address_t *storeId) { store_address_t *storeId) {
store_address_t localId; store_address_t localId;
ReturnValue_t result = ILLEGAL_ADDRESS; ReturnValue_t result = ILLEGAL_ADDRESS;
for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) { for (uint16_t n = 0; n < NUMBER_OF_SUBPOOLS; n++) {
//Not sure if new allocates all stores in order. so better be careful. //Not sure if new allocates all stores in order. so better be careful.
if ((store[n].data() <= ptr) and if ((store[n].data() <= ptr) and
(&store[n][numberOfElements[n]*elementSizes[n]] > ptr)) { (&store[n][numberOfElements[n]*elementSizes[n]] > ptr)) {
@ -192,7 +192,7 @@ ReturnValue_t LocalPool::initialize() {
} }
//Check if any pool size is large than the maximum allowed. //Check if any pool size is large than the maximum allowed.
for (uint8_t count = 0; count < NUMBER_OF_POOLS; count++) { for (uint8_t count = 0; count < NUMBER_OF_SUBPOOLS; count++) {
if (elementSizes[count] >= STORAGE_FREE) { if (elementSizes[count] >= STORAGE_FREE) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalPool::initialize: Pool is too large! " sif::error << "LocalPool::initialize: Pool is too large! "
@ -217,7 +217,7 @@ void LocalPool::clearStore() {
ReturnValue_t LocalPool::reserveSpace(const size_t size, ReturnValue_t LocalPool::reserveSpace(const size_t size,
store_address_t *storeId, bool ignoreFault) { store_address_t *storeId, bool ignoreFault) {
ReturnValue_t status = getPoolIndex(size, &storeId->poolIndex); ReturnValue_t status = getSubPoolIndex(size, &storeId->poolIndex);
if (status != RETURN_OK) { if (status != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalPool( " << std::hex << getObjectId() << std::dec sif::error << "LocalPool( " << std::hex << getObjectId() << std::dec
@ -227,7 +227,7 @@ ReturnValue_t LocalPool::reserveSpace(const size_t size,
} }
status = findEmpty(storeId->poolIndex, &storeId->packetIndex); status = findEmpty(storeId->poolIndex, &storeId->packetIndex);
while (status != RETURN_OK && spillsToHigherPools) { while (status != RETURN_OK && spillsToHigherPools) {
status = getPoolIndex(size, &storeId->poolIndex, storeId->poolIndex + 1); status = getSubPoolIndex(size, &storeId->poolIndex, storeId->poolIndex + 1);
if (status != RETURN_OK) { if (status != RETURN_OK) {
//We don't find any fitting pool anymore. //We don't find any fitting pool anymore.
break; break;
@ -263,9 +263,9 @@ void LocalPool::write(store_address_t storeId, const uint8_t *data,
sizeLists[storeId.poolIndex][storeId.packetIndex] = size; sizeLists[storeId.poolIndex][storeId.packetIndex] = size;
} }
LocalPool::size_type LocalPool::getPageSize(max_pools_t poolIndex) { LocalPool::size_type LocalPool::getSubpoolElementSize(max_subpools_t subpoolIndex) {
if (poolIndex < NUMBER_OF_POOLS) { if (subpoolIndex < NUMBER_OF_SUBPOOLS) {
return elementSizes[poolIndex]; return elementSizes[subpoolIndex];
} }
else { else {
return 0; return 0;
@ -276,9 +276,9 @@ void LocalPool::setToSpillToHigherPools(bool enable) {
this->spillsToHigherPools = enable; this->spillsToHigherPools = enable;
} }
ReturnValue_t LocalPool::getPoolIndex(size_t packetSize, uint16_t *poolIndex, ReturnValue_t LocalPool::getSubPoolIndex(size_t packetSize, uint16_t *subpoolIndex,
uint16_t startAtIndex) { uint16_t startAtIndex) {
for (uint16_t n = startAtIndex; n < NUMBER_OF_POOLS; n++) { for (uint16_t n = startAtIndex; n < NUMBER_OF_SUBPOOLS; n++) {
#if FSFW_VERBOSE_PRINTOUT == 2 #if FSFW_VERBOSE_PRINTOUT == 2
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "LocalPool " << getObjectId() << "::getPoolIndex: Pool: " sif::debug << "LocalPool " << getObjectId() << "::getPoolIndex: Pool: "
@ -286,7 +286,7 @@ ReturnValue_t LocalPool::getPoolIndex(size_t packetSize, uint16_t *poolIndex,
#endif #endif
#endif #endif
if (elementSizes[n] >= packetSize) { if (elementSizes[n] >= packetSize) {
*poolIndex = n; *subpoolIndex = n;
return RETURN_OK; return RETURN_OK;
} }
} }
@ -313,7 +313,7 @@ ReturnValue_t LocalPool::findEmpty(n_pool_elem_t poolIndex, uint16_t *element) {
size_t LocalPool::getTotalSize(size_t* additionalSize) { size_t LocalPool::getTotalSize(size_t* additionalSize) {
size_t totalSize = 0; size_t totalSize = 0;
size_t sizesSize = 0; size_t sizesSize = 0;
for(uint8_t idx = 0; idx < NUMBER_OF_POOLS; idx ++) { for(uint8_t idx = 0; idx < NUMBER_OF_SUBPOOLS; idx ++) {
totalSize += elementSizes[idx] * numberOfElements[idx]; totalSize += elementSizes[idx] * numberOfElements[idx];
sizesSize += numberOfElements[idx] * sizeof(size_type); sizesSize += numberOfElements[idx] * sizeof(size_type);
} }
@ -331,7 +331,7 @@ void LocalPool::getFillCount(uint8_t *buffer, uint8_t *bytesWritten) {
uint16_t reservedHits = 0; uint16_t reservedHits = 0;
uint8_t idx = 0; uint8_t idx = 0;
uint16_t sum = 0; uint16_t sum = 0;
for(; idx < NUMBER_OF_POOLS; idx ++) { for(; idx < NUMBER_OF_SUBPOOLS; idx ++) {
for(const auto& size: sizeLists[idx]) { for(const auto& size: sizeLists[idx]) {
if(size != STORAGE_FREE) { if(size != STORAGE_FREE) {
reservedHits++; reservedHits++;
@ -343,21 +343,25 @@ void LocalPool::getFillCount(uint8_t *buffer, uint8_t *bytesWritten) {
sum += buffer[idx]; sum += buffer[idx];
reservedHits = 0; reservedHits = 0;
} }
buffer[idx] = sum / NUMBER_OF_POOLS; buffer[idx] = sum / NUMBER_OF_SUBPOOLS;
*bytesWritten += 1; *bytesWritten += 1;
} }
void LocalPool::clearPage(max_pools_t pageIndex) { void LocalPool::clearSubPool(max_subpools_t subpoolIndex) {
if(pageIndex >= NUMBER_OF_POOLS) { if(subpoolIndex >= NUMBER_OF_SUBPOOLS) {
return; return;
} }
// Mark the storage as free // Mark the storage as free
for(auto& size: sizeLists[pageIndex]) { for(auto& size: sizeLists[subpoolIndex]) {
size = STORAGE_FREE; size = STORAGE_FREE;
} }
// Set all the page content to 0. // Set all the page content to 0.
std::memset(store[pageIndex].data(), 0, elementSizes[pageIndex]); std::memset(store[subpoolIndex].data(), 0, elementSizes[subpoolIndex]);
}
LocalPool::max_subpools_t LocalPool::getNumberOfSubPools() const {
return NUMBER_OF_SUBPOOLS;
} }

View File

@ -60,15 +60,6 @@ public:
}; };
using LocalPoolConfig = std::multiset<LocalPoolCfgPair, LocalPoolConfigCmp>; using LocalPoolConfig = std::multiset<LocalPoolCfgPair, LocalPoolConfigCmp>;
/**
* @brief This definition generally sets the number of
* different sized pools. It is derived from the number of pairs
* inside the LocalPoolConfig set on object creation.
* @details
* This must be less than the maximum number of pools (currently 0xff).
*/
const max_pools_t NUMBER_OF_POOLS;
/** /**
* @brief This is the default constructor for a pool manager instance. * @brief This is the default constructor for a pool manager instance.
* @details * @details
@ -143,9 +134,15 @@ public:
void getFillCount(uint8_t* buffer, uint8_t* bytesWritten) override; void getFillCount(uint8_t* buffer, uint8_t* bytesWritten) override;
void clearStore() override; void clearStore() override;
void clearPage(max_pools_t pageIndex) override; void clearSubPool(max_subpools_t poolIndex) override;
ReturnValue_t initialize() override; ReturnValue_t initialize() override;
/**
* Get number sub pools. Each pool has pages with a specific bucket size.
* @return
*/
max_subpools_t getNumberOfSubPools() const override;
protected: protected:
/** /**
* With this helper method, a free element of @c size is reserved. * With this helper method, a free element of @c size is reserved.
@ -158,6 +155,16 @@ protected:
store_address_t* address, bool ignoreFault); store_address_t* address, bool ignoreFault);
private: private:
/**
* @brief This definition generally sets the number of
* different sized pools. It is derived from the number of pairs
* inside the LocalPoolConfig set on object creation.
* @details
* This must be less than the maximum number of pools (currently 0xff).
*/
const max_subpools_t NUMBER_OF_SUBPOOLS;
/** /**
* Indicates that this element is free. * Indicates that this element is free.
* This value limits the maximum size of a pool. * This value limits the maximum size of a pool.
@ -170,20 +177,20 @@ private:
* must be set in ascending order on construction. * must be set in ascending order on construction.
*/ */
std::vector<size_type> elementSizes = std::vector<size_type> elementSizes =
std::vector<size_type>(NUMBER_OF_POOLS); std::vector<size_type>(NUMBER_OF_SUBPOOLS);
/** /**
* @brief n_elements stores the number of elements per pool. * @brief n_elements stores the number of elements per pool.
* @details These numbers are maintained for internal pool management. * @details These numbers are maintained for internal pool management.
*/ */
std::vector<uint16_t> numberOfElements = std::vector<uint16_t> numberOfElements =
std::vector<uint16_t>(NUMBER_OF_POOLS); std::vector<uint16_t>(NUMBER_OF_SUBPOOLS);
/** /**
* @brief store represents the actual memory pool. * @brief store represents the actual memory pool.
* @details It is an array of pointers to memory, which was allocated with * @details It is an array of pointers to memory, which was allocated with
* a @c new call on construction. * a @c new call on construction.
*/ */
std::vector<std::vector<uint8_t>> store = std::vector<std::vector<uint8_t>> store =
std::vector<std::vector<uint8_t>>(NUMBER_OF_POOLS); std::vector<std::vector<uint8_t>>(NUMBER_OF_SUBPOOLS);
/** /**
* @brief The size_list attribute stores the size values of every pool element. * @brief The size_list attribute stores the size values of every pool element.
@ -191,7 +198,7 @@ private:
* is also dynamically allocated there. * is also dynamically allocated there.
*/ */
std::vector<std::vector<size_type>> sizeLists = std::vector<std::vector<size_type>> sizeLists =
std::vector<std::vector<size_type>>(NUMBER_OF_POOLS); std::vector<std::vector<size_type>>(NUMBER_OF_SUBPOOLS);
//! A variable to determine whether higher n pools are used if //! A variable to determine whether higher n pools are used if
//! the store is full. //! the store is full.
@ -210,7 +217,7 @@ private:
* @param pool_index The pool in which to look. * @param pool_index The pool in which to look.
* @return Returns the size of an element or 0. * @return Returns the size of an element or 0.
*/ */
size_type getPageSize(max_pools_t poolIndex); size_type getSubpoolElementSize(max_subpools_t subpoolIndex);
/** /**
* @brief This helper method looks up a fitting pool for a given size. * @brief This helper method looks up a fitting pool for a given size.
@ -221,7 +228,7 @@ private:
* @return - @c RETURN_OK on success, * @return - @c RETURN_OK on success,
* - @c DATA_TOO_LARGE otherwise. * - @c DATA_TOO_LARGE otherwise.
*/ */
ReturnValue_t getPoolIndex(size_t packetSize, uint16_t* poolIndex, ReturnValue_t getSubPoolIndex(size_t packetSize, uint16_t* subpoolIndex,
uint16_t startAtIndex = 0); uint16_t startAtIndex = 0);
/** /**
* @brief This helper method calculates the true array position in store * @brief This helper method calculates the true array position in store

View File

@ -29,7 +29,7 @@ using ConstAccessorPair = std::pair<ReturnValue_t, ConstStorageAccessor>;
class StorageManagerIF : public HasReturnvaluesIF { class StorageManagerIF : public HasReturnvaluesIF {
public: public:
using size_type = size_t; using size_type = size_t;
using max_pools_t = uint8_t; using max_subpools_t = uint8_t;
static const uint8_t INTERFACE_ID = CLASS_ID::STORAGE_MANAGER_IF; //!< The unique ID for return codes for this interface. static const uint8_t INTERFACE_ID = CLASS_ID::STORAGE_MANAGER_IF; //!< The unique ID for return codes for this interface.
static const ReturnValue_t DATA_TOO_LARGE = MAKE_RETURN_CODE(1); //!< This return code indicates that the data to be stored is too large for the store. static const ReturnValue_t DATA_TOO_LARGE = MAKE_RETURN_CODE(1); //!< This return code indicates that the data to be stored is too large for the store.
@ -149,10 +149,10 @@ public:
virtual ReturnValue_t modifyData(store_address_t packet_id, virtual ReturnValue_t modifyData(store_address_t packet_id,
uint8_t** packet_ptr, size_t* size) = 0; uint8_t** packet_ptr, size_t* size) = 0;
/** /**
* This method reserves an element of \c size. * This method reserves an element of @c size.
* *
* It returns the packet id of this element as well as a direct pointer to the * It returns the packet id of this element as well as a direct pointer to the
* data of the element. It must be assured that exactly \c size data is * data of the element. It must be assured that exactly @c size data is
* written to p_data! * written to p_data!
* @param storageId A pointer to the storageId to retrieve. * @param storageId A pointer to the storageId to retrieve.
* @param size The size of the space to be reserved. * @param size The size of the space to be reserved.
@ -171,20 +171,29 @@ public:
virtual void clearStore() = 0; virtual void clearStore() = 0;
/** /**
* Clears a page in the store. Use with care! * Clears a pool in the store with the given pool index. Use with care!
* @param pageIndex * @param pageIndex
*/ */
virtual void clearPage(uint8_t pageIndex) = 0; virtual void clearSubPool(uint8_t poolIndex) = 0;
/** /**
* Get the fill count of the pool. The exact form will be implementation * Get the fill count of the pool. Each character inside the provided
* dependant. * buffer will be assigned to a rounded percentage fill count for each
* page. The last written byte (at the index bytesWritten - 1)
* will contain the total fill count of the pool as a mean of the
* percentages of single pages.
* @param buffer * @param buffer
* @param bytesWritten * @param maxSize
*/ */
virtual void getFillCount(uint8_t* buffer, uint8_t* bytesWritten) = 0; virtual void getFillCount(uint8_t* buffer, uint8_t* bytesWritten) = 0;
virtual size_t getTotalSize(size_t* additionalSize) = 0; virtual size_t getTotalSize(size_t* additionalSize) = 0;
/**
* Get number of pools.
* @return
*/
virtual max_subpools_t getNumberOfSubPools() const = 0;
}; };
#endif /* FSFW_STORAGEMANAGER_STORAGEMANAGERIF_H_ */ #endif /* FSFW_STORAGEMANAGER_STORAGEMANAGERIF_H_ */

View File

@ -1,5 +1,5 @@
#include "Stopwatch.h" #include "Stopwatch.h"
#include "../serviceinterface/ServiceInterfaceStream.h" #include "../serviceinterface/ServiceInterface.h"
#include <iomanip> #include <iomanip>
Stopwatch::Stopwatch(bool displayOnDestruction, Stopwatch::Stopwatch(bool displayOnDestruction,
@ -28,9 +28,13 @@ double Stopwatch::stopSeconds() {
void Stopwatch::display() { void Stopwatch::display() {
if(displayMode == StopwatchDisplayMode::MILLIS) { if(displayMode == StopwatchDisplayMode::MILLIS) {
dur_millis_t timeMillis = static_cast<dur_millis_t>(
elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000);
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Stopwatch: Operation took " << (elapsedTime.tv_sec * 1000 + sif::info << "Stopwatch: Operation took " << timeMillis << " milliseconds" << std::endl;
elapsedTime.tv_usec / 1000) << " milliseconds" << std::endl; #else
sif::printInfo("Stopwatch: Operation took %lu milliseconds\n\r",
static_cast<unsigned int>(timeMillis));
#endif #endif
} }
else if(displayMode == StopwatchDisplayMode::SECONDS) { else if(displayMode == StopwatchDisplayMode::SECONDS) {
@ -38,6 +42,9 @@ void Stopwatch::display() {
sif::info <<"Stopwatch: Operation took " << std::setprecision(3) sif::info <<"Stopwatch: Operation took " << std::setprecision(3)
<< std::fixed << timevalOperations::toDouble(elapsedTime) << std::fixed << timevalOperations::toDouble(elapsedTime)
<< " seconds" << std::endl; << " seconds" << std::endl;
#else
sif::printInfo("Stopwatch: Operation took %.3f seconds\n\r",
static_cast<float>(timevalOperations::toDouble(elapsedTime)));
#endif #endif
} }
} }