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 <fsfw/serviceinterface/ServiceInterface.h>
#include "fsfw/serviceinterface/ServiceInterface.h"
GpioCookie::GpioCookie() {
}

View File

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

View File

@ -1,5 +1,5 @@
#ifndef LINUX_GPIO_GPIOIF_H_
#define LINUX_GPIO_GPIOIF_H_
#ifndef COMMON_GPIO_GPIOIF_H_
#define COMMON_GPIO_GPIOIF_H_
#include "gpioDefinitions.h"
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
@ -51,4 +51,4 @@ public:
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_
#define LINUX_GPIO_GPIODEFINITIONS_H_
#ifndef COMMON_GPIO_GPIODEFINITIONS_H_
#define COMMON_GPIO_GPIODEFINITIONS_H_
#include <string>
#include <unordered_map>
#include <map>
using gpioId_t = uint16_t;
@ -25,11 +26,14 @@ enum GpioOperation {
enum GpioTypes {
NONE,
GPIOD_REGULAR,
GPIO_REGULAR,
CALLBACK
};
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 {
public:
GpiodRegular(): GpioBase(gpio::GpioTypes::GPIOD_REGULAR, std::string(),
GpiodRegular(): GpioBase(gpio::GpioTypes::GPIO_REGULAR, std::string(),
gpio::Direction::IN, 0) {};
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_,
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_) {}
std::string chipname;
int lineNum = 0;
@ -81,18 +85,18 @@ public:
class GpioCallback: public GpioBase {
public:
GpioCallback(std::string consumer, gpio::Direction direction_, int initValue_,
void (* callback) (gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args),
void* callbackArgs):
gpio::gpio_cb_t callback, void* callbackArgs):
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
callback(callback), callbackArgs(callbackArgs) {}
void (* callback) (gpioId_t gpioId, gpio::GpioOperation gpioOp,
int value, void* args) = nullptr;
gpio::gpio_cb_t callback = 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 GpioUnorderedMapIter = GpioUnorderedMap::iterator;
#endif /* LINUX_GPIO_GPIODEFINITIONS_H_ */

View File

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

View File

@ -38,8 +38,8 @@ public:
private:
/* Holds the information and configuration of all used GPIOs */
GpioMap gpioMap;
GpioMapIter gpioMapIter;
GpioUnorderedMap gpioMap;
GpioUnorderedMapIter gpioMapIter;
/**
* @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();
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) {
sif::debug << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
<< "to Uart device map" << std::endl;
sif::debug << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
<< "to UART device map" << std::endl;
return RETURN_FAILED;
}
}
else {
sif::debug << "UartComIF::initializeInterface: Uart device " << deviceFile << "already in "
sif::debug << "UartComIF::initializeInterface: UART device " << deviceFile << " already in "
<< "use" << std::endl;
return RETURN_FAILED;
}