fsfw-hal/common/gpio/GpioCookie.cpp

50 lines
1.5 KiB
C++
Raw Normal View History

2021-03-23 15:41:49 +01:00
#include "GpioCookie.h"
#include <fsfw/serviceinterface/ServiceInterface.h>
GpioCookie::GpioCookie() {
}
2021-04-01 15:48:30 +02:00
ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
if (gpioConfig == nullptr) {
2021-04-10 11:15:27 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "GpioCookie::addGpio: gpioConfig is nullpointer" << std::endl;
#else
sif::printWarning("GpioCookie::addGpio: gpioConfig is nullpointer\n");
#endif
2021-04-01 15:48:30 +02:00
return HasReturnvaluesIF::RETURN_FAILED;
}
auto gpioMapIter = gpioMap.find(gpioId);
if(gpioMapIter == gpioMap.end()) {
auto statusPair = gpioMap.emplace(gpioId, gpioConfig);
if (statusPair.second == false) {
2021-03-23 15:41:49 +01:00
#if FSFW_VERBOSE_LEVEL >= 1
2021-04-10 11:15:27 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId <<
2021-04-01 15:48:30 +02:00
" to GPIO map" << std::endl;
2021-04-10 11:15:27 +02:00
#else
sif::printWarning("GpioCookie::addGpio: Failed to add GPIO %d to GPIO map\n", gpioId);
#endif
2021-03-23 15:41:49 +01:00
#endif
2021-04-01 15:48:30 +02:00
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
2021-03-23 15:41:49 +01:00
#if FSFW_VERBOSE_LEVEL >= 1
2021-04-10 11:15:27 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "GpioCookie::addGpio: GPIO already exists in GPIO map " << std::endl;
#else
sif::printWarning("GpioCookie::addGpio: GPIO already exists in GPIO map\n");
#endif
2021-03-23 15:41:49 +01:00
#endif
2021-04-01 15:48:30 +02:00
return HasReturnvaluesIF::RETURN_FAILED;
2021-03-23 15:41:49 +01:00
}
GpioMap GpioCookie::getGpioMap() const {
2021-04-01 15:48:30 +02:00
return gpioMap;
2021-03-23 15:41:49 +01:00
}
2021-04-11 12:29:54 +02:00
GpioCookie::~GpioCookie() {
for(auto& config: gpioMap) {
delete(config.second);
}
}