small fixes and refactoring

This commit is contained in:
Robin Müller 2021-06-05 14:42:20 +02:00
parent 5ff344eee2
commit a35fdbc5dc
No known key found for this signature in database
GPG Key ID: BE6480244DFE612C
7 changed files with 35 additions and 29 deletions

View File

@ -1,5 +1,6 @@
#include "GpioCookie.h" #include "GpioCookie.h"
#include <fsfw/serviceinterface/ServiceInterface.h> #include "fsfw/serviceinterface/ServiceInterface.h"
GpioCookie::GpioCookie() { GpioCookie::GpioCookie() {
} }

View File

@ -1,8 +1,9 @@
#ifndef LINUX_GPIO_GPIOCOOKIE_H_ #ifndef COMMON_GPIO_GPIOCOOKIE_H_
#define LINUX_GPIO_GPIOCOOKIE_H_ #define COMMON_GPIO_GPIOCOOKIE_H_
#include "GpioIF.h" #include "GpioIF.h"
#include "gpioDefinitions.h" #include "gpioDefinitions.h"
#include <fsfw/devicehandlers/CookieIF.h> #include <fsfw/devicehandlers/CookieIF.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
@ -37,4 +38,4 @@ private:
GpioMap gpioMap; GpioMap gpioMap;
}; };
#endif /* LINUX_GPIO_GPIOCOOKIE_H_ */ #endif /* COMMON_GPIO_GPIOCOOKIE_H_ */

View File

@ -1,5 +1,5 @@
#ifndef LINUX_GPIO_GPIOIF_H_ #ifndef COMMON_GPIO_GPIOIF_H_
#define LINUX_GPIO_GPIOIF_H_ #define COMMON_GPIO_GPIOIF_H_
#include "gpioDefinitions.h" #include "gpioDefinitions.h"
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
@ -51,4 +51,4 @@ public:
virtual ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) = 0; virtual ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) = 0;
}; };
#endif /* LINUX_GPIO_GPIOIF_H_ */ #endif /* COMMON_GPIO_GPIOIF_H_ */

View File

@ -1,8 +1,9 @@
#ifndef LINUX_GPIO_GPIODEFINITIONS_H_ #ifndef COMMON_GPIO_GPIODEFINITIONS_H_
#define LINUX_GPIO_GPIODEFINITIONS_H_ #define COMMON_GPIO_GPIODEFINITIONS_H_
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <map>
using gpioId_t = uint16_t; using gpioId_t = uint16_t;
@ -25,11 +26,14 @@ enum GpioOperation {
enum GpioTypes { enum GpioTypes {
NONE, NONE,
GPIOD_REGULAR, GPIO_REGULAR,
CALLBACK CALLBACK
}; };
static constexpr gpioId_t NO_GPIO = -1; static constexpr gpioId_t NO_GPIO = -1;
using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args);
} }
/** /**
@ -66,12 +70,12 @@ public:
class GpiodRegular: public GpioBase { class GpiodRegular: public GpioBase {
public: public:
GpiodRegular(): GpioBase(gpio::GpioTypes::GPIOD_REGULAR, std::string(), GpiodRegular(): GpioBase(gpio::GpioTypes::GPIO_REGULAR, std::string(),
gpio::Direction::IN, 0) {}; gpio::Direction::IN, 0) {};
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_, GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_,
gpio::Direction direction_, int initValue_): gpio::Direction direction_, int initValue_):
GpioBase(gpio::GpioTypes::GPIOD_REGULAR, consumer_, direction_, initValue_), GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, direction_, initValue_),
chipname(chipname_), lineNum(lineNum_) {} chipname(chipname_), lineNum(lineNum_) {}
std::string chipname; std::string chipname;
int lineNum = 0; int lineNum = 0;
@ -81,18 +85,18 @@ public:
class GpioCallback: public GpioBase { class GpioCallback: public GpioBase {
public: public:
GpioCallback(std::string consumer, gpio::Direction direction_, int initValue_, GpioCallback(std::string consumer, gpio::Direction direction_, int initValue_,
void (* callback) (gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args), gpio::gpio_cb_t callback, void* callbackArgs):
void* callbackArgs):
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_), GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
callback(callback), callbackArgs(callbackArgs) {} callback(callback), callbackArgs(callbackArgs) {}
void (* callback) (gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::gpio_cb_t callback = nullptr;
int value, void* args) = nullptr;
void* callbackArgs = nullptr; void* callbackArgs = nullptr;
}; };
using GpioMap = std::unordered_map<gpioId_t, GpioBase*>; using GpioMap = std::map<gpioId_t, GpioBase*>;
using GpioUnorderedMap = std::unordered_map<gpioId_t, GpioBase*>;
using GpioMapIter = GpioMap::iterator; using GpioMapIter = GpioMap::iterator;
using GpioUnorderedMapIter = GpioUnorderedMap::iterator;
#endif /* LINUX_GPIO_GPIODEFINITIONS_H_ */ #endif /* LINUX_GPIO_GPIODEFINITIONS_H_ */

View File

@ -49,7 +49,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
case(gpio::GpioTypes::NONE): { case(gpio::GpioTypes::NONE): {
return GPIO_INVALID_INSTANCE; return GPIO_INVALID_INSTANCE;
} }
case(gpio::GpioTypes::GPIOD_REGULAR): { case(gpio::GpioTypes::GPIO_REGULAR): {
GpiodRegular* regularGpio = dynamic_cast<GpiodRegular*>(gpioConfig.second); GpiodRegular* regularGpio = dynamic_cast<GpiodRegular*>(gpioConfig.second);
if(regularGpio == nullptr) { if(regularGpio == nullptr) {
return GPIO_INVALID_INSTANCE; return GPIO_INVALID_INSTANCE;
@ -145,7 +145,7 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
return UNKNOWN_GPIO_ID; return UNKNOWN_GPIO_ID;
} }
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIOD_REGULAR) { if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIO_REGULAR) {
return driveGpio(gpioId, dynamic_cast<GpiodRegular*>(gpioMapIter->second), 1); return driveGpio(gpioId, dynamic_cast<GpiodRegular*>(gpioMapIter->second), 1);
} }
else { else {
@ -166,7 +166,7 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
return UNKNOWN_GPIO_ID; return UNKNOWN_GPIO_ID;
} }
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIOD_REGULAR) { if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIO_REGULAR) {
return driveGpio(gpioId, dynamic_cast<GpiodRegular*>(gpioMapIter->second), 0); return driveGpio(gpioId, dynamic_cast<GpiodRegular*>(gpioMapIter->second), 0);
} }
else { else {
@ -203,7 +203,7 @@ ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
return UNKNOWN_GPIO_ID; return UNKNOWN_GPIO_ID;
} }
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIOD_REGULAR) { if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIO_REGULAR) {
GpiodRegular* regularGpio = dynamic_cast<GpiodRegular*>(gpioMapIter->second); GpiodRegular* regularGpio = dynamic_cast<GpiodRegular*>(gpioMapIter->second);
if(regularGpio == nullptr) { if(regularGpio == nullptr) {
return GPIO_TYPE_FAILURE; return GPIO_TYPE_FAILURE;
@ -223,7 +223,7 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
for(auto& gpioConfig: mapToAdd) { for(auto& gpioConfig: mapToAdd) {
switch(gpioConfig.second->gpioType) { switch(gpioConfig.second->gpioType) {
case(gpio::GpioTypes::GPIOD_REGULAR): { case(gpio::GpioTypes::GPIO_REGULAR): {
auto regularGpio = dynamic_cast<GpiodRegular*>(gpioConfig.second); auto regularGpio = dynamic_cast<GpiodRegular*>(gpioConfig.second);
if(regularGpio == nullptr) { if(regularGpio == nullptr) {
return GPIO_TYPE_FAILURE; return GPIO_TYPE_FAILURE;
@ -261,7 +261,7 @@ ReturnValue_t LinuxLibgpioIF::checkForConflictsRegularGpio(gpioId_t gpioIdToChec
/* Cross check with private map */ /* Cross check with private map */
gpioMapIter = gpioMap.find(gpioIdToCheck); gpioMapIter = gpioMap.find(gpioIdToCheck);
if(gpioMapIter != gpioMap.end()) { if(gpioMapIter != gpioMap.end()) {
if(gpioMapIter->second->gpioType != gpio::GpioTypes::GPIOD_REGULAR) { if(gpioMapIter->second->gpioType != gpio::GpioTypes::GPIO_REGULAR) {
sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for different " sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for different "
"GPIO type" << gpioIdToCheck << ". Removing duplicate." << std::endl; "GPIO type" << gpioIdToCheck << ". Removing duplicate." << std::endl;
mapToAdd.erase(gpioIdToCheck); mapToAdd.erase(gpioIdToCheck);

View File

@ -38,8 +38,8 @@ public:
private: private:
/* Holds the information and configuration of all used GPIOs */ /* Holds the information and configuration of all used GPIOs */
GpioMap gpioMap; GpioUnorderedMap gpioMap;
GpioMapIter gpioMapIter; GpioUnorderedMapIter gpioMapIter;
/** /**
* @brief This functions drives line of a GPIO specified by the GPIO ID. * @brief This functions drives line of a GPIO specified by the GPIO ID.

View File

@ -38,15 +38,15 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF * cookie) {
} }
size_t maxReplyLen = uartCookie->getMaxReplyLen(); size_t maxReplyLen = uartCookie->getMaxReplyLen();
UartElements_t uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0}; UartElements_t uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0};
std::pair status = uartDeviceMap.emplace(deviceFile, uartElements); auto status = uartDeviceMap.emplace(deviceFile, uartElements);
if (status.second == false) { if (status.second == false) {
sif::debug << "UartComIF::initializeInterface: Failed to insert device " << deviceFile sif::debug << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
<< "to Uart device map" << std::endl; << "to UART device map" << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
} }
else { else {
sif::debug << "UartComIF::initializeInterface: Uart device " << deviceFile << "already in " sif::debug << "UartComIF::initializeInterface: UART device " << deviceFile << " already in "
<< "use" << std::endl; << "use" << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }