2021-08-02 20:58:56 +02:00
|
|
|
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2021-07-13 19:19:25 +02:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
GpioCookie::GpioCookie() {}
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
|
2022-02-02 10:29:30 +01:00
|
|
|
if (gpioConfig == nullptr) {
|
2021-07-13 19:19:25 +02:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::warning << "GpioCookie::addGpio: gpioConfig is nullpointer" << std::endl;
|
2021-07-13 19:19:25 +02:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printWarning("GpioCookie::addGpio: gpioConfig is nullpointer\n");
|
2021-07-13 19:19:25 +02:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01: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-07-13 19:19:25 +02:00
|
|
|
#if FSFW_VERBOSE_LEVEL >= 1
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId << " to GPIO map"
|
|
|
|
<< std::endl;
|
2021-07-13 19:19:25 +02:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printWarning("GpioCookie::addGpio: Failed to add GPIO %d to GPIO map\n", gpioId);
|
2021-07-13 19:19:25 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
2021-07-13 19:19:25 +02:00
|
|
|
}
|
2022-02-02 10:29:30 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
2021-07-13 19:19:25 +02:00
|
|
|
#if FSFW_VERBOSE_LEVEL >= 1
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::warning << "GpioCookie::addGpio: GPIO already exists in GPIO map " << std::endl;
|
2021-07-13 19:19:25 +02:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printWarning("GpioCookie::addGpio: GPIO already exists in GPIO map\n");
|
2021-07-13 19:19:25 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
2021-07-13 19:19:25 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
GpioMap GpioCookie::getGpioMap() const { return gpioMap; }
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
GpioCookie::~GpioCookie() {
|
2022-02-02 10:29:30 +01:00
|
|
|
for (auto& config : gpioMap) {
|
|
|
|
delete (config.second);
|
|
|
|
}
|
2021-07-13 19:19:25 +02:00
|
|
|
}
|