Compare commits
112 Commits
add_cfdp_s
...
a84c770dfb
Author | SHA1 | Date | |
---|---|---|---|
a84c770dfb | |||
9546495507 | |||
e227b5dead | |||
9db5f893d7 | |||
4b3e753e19 | |||
36607c8764 | |||
b88e6c0713 | |||
6ee2c65187 | |||
2b6c996364 | |||
dabb488c9d | |||
![]() |
16b125ef6c | ||
![]() |
10f8a0fd0e | ||
![]() |
48a24d7dba | ||
e0671a395e | |||
665be0d417 | |||
![]() |
e7df520780 | ||
dd610f0d7e | |||
0987a160c9 | |||
ceeb0c5388 | |||
91f7184ebb | |||
e1a85b47c5 | |||
a3eb870ba0 | |||
ed2263b5f7 | |||
dccc2f0ba7 | |||
350fbc385c | |||
c9b343ebcd | |||
81c33d2dc6 | |||
29c74283f1 | |||
c51d2df43d | |||
d3b83f3cf9 | |||
60229da670 | |||
5c56eda610 | |||
3d1be94e12 | |||
8e65d2d3fc | |||
8374d495fa | |||
e02879184b | |||
![]() |
70a3749dbe | ||
87b68e84be | |||
7000ba05c5 | |||
9948c4f31d | |||
784a0140f4 | |||
635432d7ba | |||
e8050183f4 | |||
7d44aab98e | |||
4489a61a00 | |||
b1a56a71cd | |||
6d0d04ac23 | |||
8f3edc90ba | |||
7b5334ccec | |||
a58016859b | |||
0df8d35802 | |||
823c6ec5fc | |||
bc6b29e652 | |||
d986ab7720 | |||
bdd7d59d82 | |||
edf33cc10a | |||
6db5011b14 | |||
97494a84df | |||
40adca5f1d | |||
a8167f5431 | |||
41f3d7cf9a | |||
e6e1936293 | |||
15f35f200a | |||
6b20bb197a | |||
215d01b3ca | |||
dfe49cc1e5 | |||
73eb11f4f1 | |||
924c150af2 | |||
469eba3ce2 | |||
fd2916af11 | |||
afd375a7f8 | |||
5454169e20 | |||
7d0377845b | |||
882da68a2f | |||
04a1fe7f10 | |||
5f79f987ae | |||
1183e5739d | |||
e3697d6d8c | |||
406b77ea81 | |||
8a9eb27458 | |||
1ac372cb89 | |||
fb36dc4501 | |||
ba5e2ad8bb | |||
5a6c81130d | |||
22e29144b6 | |||
52bff3985f | |||
![]() |
133820f463 | ||
![]() |
8d3fceea8f | ||
3704d2b829 | |||
6073abb12d | |||
47bec654a0 | |||
b2c102b2c1 | |||
4202205182 | |||
c8472beb5f | |||
1a4a85ceb2 | |||
7922bf76da | |||
bb88490cc6 | |||
296c587e3d | |||
0ff81294e7 | |||
b6e243b8b3 | |||
3bbcc42d39 | |||
fc4324a2fa | |||
54c028f913 | |||
1f6a5e635f | |||
c5b4b01362 | |||
c5420c7b53 | |||
3e422f51bd | |||
d1be0f9843 | |||
![]() |
b83259592a | ||
a7a4e0f219 | |||
bdc5f593e2 | |||
10f7185e81 |
@@ -9,12 +9,13 @@ using gpioId_t = uint16_t;
|
|||||||
|
|
||||||
namespace gpio {
|
namespace gpio {
|
||||||
|
|
||||||
enum Levels {
|
enum Levels: uint8_t {
|
||||||
LOW = 0,
|
LOW = 0,
|
||||||
HIGH = 1
|
HIGH = 1,
|
||||||
|
NONE = 99
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Direction {
|
enum Direction: uint8_t {
|
||||||
IN = 0,
|
IN = 0,
|
||||||
OUT = 1
|
OUT = 1
|
||||||
};
|
};
|
||||||
@@ -24,15 +25,18 @@ enum GpioOperation {
|
|||||||
WRITE
|
WRITE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum GpioTypes {
|
enum class GpioTypes {
|
||||||
NONE,
|
NONE,
|
||||||
GPIO_REGULAR,
|
GPIO_REGULAR_BY_CHIP,
|
||||||
|
GPIO_REGULAR_BY_LABEL,
|
||||||
|
GPIO_REGULAR_BY_LINE_NAME,
|
||||||
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);
|
using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value,
|
||||||
|
void* args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +60,7 @@ public:
|
|||||||
GpioBase() = default;
|
GpioBase() = default;
|
||||||
|
|
||||||
GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
int initValue):
|
gpio::Levels initValue):
|
||||||
gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {}
|
gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {}
|
||||||
|
|
||||||
virtual~ GpioBase() {};
|
virtual~ GpioBase() {};
|
||||||
@@ -65,34 +69,90 @@ public:
|
|||||||
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
|
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
|
||||||
std::string consumer;
|
std::string consumer;
|
||||||
gpio::Direction direction = gpio::Direction::IN;
|
gpio::Direction direction = gpio::Direction::IN;
|
||||||
int initValue = 0;
|
gpio::Levels initValue = gpio::Levels::NONE;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GpiodRegular: public GpioBase {
|
class GpiodRegularBase: public GpioBase {
|
||||||
public:
|
public:
|
||||||
GpiodRegular() :
|
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
GpioBase(gpio::GpioTypes::GPIO_REGULAR, std::string(), gpio::Direction::IN, 0) {
|
gpio::Levels initValue, int lineNum):
|
||||||
}
|
GpioBase(gpioType, consumer, direction, initValue), lineNum(lineNum) {
|
||||||
;
|
|
||||||
|
|
||||||
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_,
|
|
||||||
gpio::Direction direction_, int initValue_) :
|
|
||||||
GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, direction_, initValue_),
|
|
||||||
chipname(chipname_), lineNum(lineNum_) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_) :
|
// line number will be configured at a later point for the open by line name configuration
|
||||||
GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, gpio::Direction::IN, 0),
|
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
chipname(chipname_), lineNum(lineNum_) {
|
gpio::Levels initValue): GpioBase(gpioType, consumer, direction, initValue) {
|
||||||
}
|
}
|
||||||
std::string chipname;
|
|
||||||
int lineNum = 0;
|
int lineNum = 0;
|
||||||
struct gpiod_line* lineHandle = nullptr;
|
struct gpiod_line* lineHandle = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GpiodRegularByChip: public GpiodRegularBase {
|
||||||
|
public:
|
||||||
|
GpiodRegularByChip() :
|
||||||
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
|
||||||
|
std::string(), gpio::Direction::IN, gpio::LOW, 0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_,
|
||||||
|
gpio::Direction direction_, gpio::Levels initValue_) :
|
||||||
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
|
||||||
|
consumer_, direction_, initValue_, lineNum_),
|
||||||
|
chipname(chipname_){
|
||||||
|
}
|
||||||
|
|
||||||
|
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_) :
|
||||||
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_,
|
||||||
|
gpio::Direction::IN, gpio::LOW, lineNum_),
|
||||||
|
chipname(chipname_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string chipname;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GpiodRegularByLabel: public GpiodRegularBase {
|
||||||
|
public:
|
||||||
|
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_,
|
||||||
|
gpio::Direction direction_, gpio::Levels initValue_) :
|
||||||
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
|
||||||
|
direction_, initValue_, lineNum_),
|
||||||
|
label(label_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_) :
|
||||||
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
|
||||||
|
gpio::Direction::IN, gpio::LOW, lineNum_),
|
||||||
|
label(label_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string label;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Passing this GPIO configuration to the GPIO IF object will try to open the GPIO by its
|
||||||
|
* line name. This line name can be set in the device tree and must be unique. Otherwise
|
||||||
|
* the driver will open the first line with the given name.
|
||||||
|
*/
|
||||||
|
class GpiodRegularByLineName: public GpiodRegularBase {
|
||||||
|
public:
|
||||||
|
GpiodRegularByLineName(std::string lineName_, std::string consumer_, gpio::Direction direction_,
|
||||||
|
gpio::Levels initValue_) :
|
||||||
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_,
|
||||||
|
initValue_), lineName(lineName_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
GpiodRegularByLineName(std::string lineName_, std::string consumer_) :
|
||||||
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_,
|
||||||
|
gpio::Direction::IN, gpio::LOW), lineName(lineName_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string lineName;
|
||||||
|
};
|
||||||
|
|
||||||
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_, gpio::Levels initValue_,
|
||||||
gpio::gpio_cb_t callback, void* callbackArgs):
|
gpio::gpio_cb_t callback, void* callbackArgs):
|
||||||
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
||||||
callback(callback), callbackArgs(callbackArgs) {}
|
callback(callback), callbackArgs(callbackArgs) {}
|
||||||
|
@@ -73,7 +73,7 @@ ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(
|
|||||||
switch (internalState) {
|
switch (internalState) {
|
||||||
case(InternalState::STATE_NONE):
|
case(InternalState::STATE_NONE):
|
||||||
case(InternalState::STATE_NORMAL): {
|
case(InternalState::STATE_NORMAL): {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return DeviceHandlerBase::NOTHING_TO_SEND;
|
||||||
}
|
}
|
||||||
case(InternalState::STATE_FIRST_CONTACT): {
|
case(InternalState::STATE_FIRST_CONTACT): {
|
||||||
*id = MGMLIS3MDL::IDENTIFY_DEVICE;
|
*id = MGMLIS3MDL::IDENTIFY_DEVICE;
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h"
|
#include "LinuxLibgpioIF.h"
|
||||||
|
|
||||||
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
||||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||||
|
|
||||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -20,7 +21,7 @@ LinuxLibgpioIF::~LinuxLibgpioIF() {
|
|||||||
ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
if(gpioCookie == nullptr) {
|
if(gpioCookie == nullptr) {
|
||||||
sif::error << "LinuxLibgpioIF::initialize: Invalid cookie" << std::endl;
|
sif::error << "LinuxLibgpioIF::addGpios: Invalid cookie" << std::endl;
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,16 +46,33 @@ ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
|
|||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
||||||
for(auto& gpioConfig: mapToAdd) {
|
for(auto& gpioConfig: mapToAdd) {
|
||||||
switch(gpioConfig.second->gpioType) {
|
auto& gpioType = gpioConfig.second->gpioType;
|
||||||
|
switch(gpioType) {
|
||||||
case(gpio::GpioTypes::NONE): {
|
case(gpio::GpioTypes::NONE): {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
case(gpio::GpioTypes::GPIO_REGULAR): {
|
case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP): {
|
||||||
GpiodRegular* regularGpio = dynamic_cast<GpiodRegular*>(gpioConfig.second);
|
auto regularGpio = dynamic_cast<GpiodRegularByChip*>(gpioConfig.second);
|
||||||
if(regularGpio == nullptr) {
|
if(regularGpio == nullptr) {
|
||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
configureRegularGpio(gpioConfig.first, regularGpio);
|
configureGpioByChip(gpioConfig.first, *regularGpio);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):{
|
||||||
|
auto regularGpio = dynamic_cast<GpiodRegularByLabel*>(gpioConfig.second);
|
||||||
|
if(regularGpio == nullptr) {
|
||||||
|
return GPIO_INVALID_INSTANCE;
|
||||||
|
}
|
||||||
|
configureGpioByLabel(gpioConfig.first, *regularGpio);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME):{
|
||||||
|
auto regularGpio = dynamic_cast<GpiodRegularByLineName*>(gpioConfig.second);
|
||||||
|
if(regularGpio == nullptr) {
|
||||||
|
return GPIO_INVALID_INSTANCE;
|
||||||
|
}
|
||||||
|
configureGpioByLineName(gpioConfig.first, *regularGpio);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(gpio::GpioTypes::CALLBACK): {
|
case(gpio::GpioTypes::CALLBACK): {
|
||||||
@@ -70,57 +88,88 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
|
|||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular *regularGpio) {
|
ReturnValue_t LinuxLibgpioIF::configureGpioByLabel(gpioId_t gpioId,
|
||||||
std::string chipname;
|
GpiodRegularByLabel &gpioByLabel) {
|
||||||
|
std::string& label = gpioByLabel.label;
|
||||||
|
struct gpiod_chip* chip = gpiod_chip_open_by_label(label.c_str());
|
||||||
|
if (chip == nullptr) {
|
||||||
|
sif::warning << "LinuxLibgpioIF::configureGpioByLabel: Failed to open gpio from gpio "
|
||||||
|
<< "group with label " << label << ". Gpio ID: " << gpioId << std::endl;
|
||||||
|
return RETURN_FAILED;
|
||||||
|
|
||||||
|
}
|
||||||
|
std::string failOutput = "label: " + label;
|
||||||
|
return configureRegularGpio(gpioId, chip, gpioByLabel, failOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId,
|
||||||
|
GpiodRegularByChip &gpioByChip) {
|
||||||
|
std::string& chipname = gpioByChip.chipname;
|
||||||
|
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname.c_str());
|
||||||
|
if (chip == nullptr) {
|
||||||
|
sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip "
|
||||||
|
<< chipname << ". Gpio ID: " << gpioId << std::endl;
|
||||||
|
return RETURN_FAILED;
|
||||||
|
}
|
||||||
|
std::string failOutput = "chipname: " + chipname;
|
||||||
|
return configureRegularGpio(gpioId, chip, gpioByChip, failOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
|
||||||
|
GpiodRegularByLineName &gpioByLineName) {
|
||||||
|
std::string& lineName = gpioByLineName.lineName;
|
||||||
|
char chipname[MAX_CHIPNAME_LENGTH];
|
||||||
|
unsigned int lineOffset;
|
||||||
|
|
||||||
|
int result = gpiod_ctxless_find_line(lineName.c_str(), chipname, MAX_CHIPNAME_LENGTH,
|
||||||
|
&lineOffset);
|
||||||
|
if (result != LINE_FOUND) {
|
||||||
|
parseFindeLineResult(result, lineName);
|
||||||
|
return RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpioByLineName.lineNum = static_cast<int>(lineOffset);
|
||||||
|
|
||||||
|
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname);
|
||||||
|
if (chip == nullptr) {
|
||||||
|
sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip "
|
||||||
|
<< chipname << ". <Gpio ID: " << gpioId << std::endl;
|
||||||
|
return RETURN_FAILED;
|
||||||
|
}
|
||||||
|
std::string failOutput = "line name: " + lineName;
|
||||||
|
return configureRegularGpio(gpioId, chip, gpioByLineName, failOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
||||||
|
GpiodRegularBase& regularGpio, std::string failOutput) {
|
||||||
unsigned int lineNum;
|
unsigned int lineNum;
|
||||||
struct gpiod_chip *chip;
|
|
||||||
gpio::Direction direction;
|
gpio::Direction direction;
|
||||||
std::string consumer;
|
std::string consumer;
|
||||||
struct gpiod_line *lineHandle;
|
struct gpiod_line *lineHandle;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
chipname = regularGpio->chipname;
|
lineNum = regularGpio.lineNum;
|
||||||
chip = gpiod_chip_open_by_name(chipname.c_str());
|
|
||||||
if (!chip) {
|
|
||||||
sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open chip "
|
|
||||||
<< chipname << ". Gpio ID: " << gpioId << std::endl;
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
lineNum = regularGpio->lineNum;
|
|
||||||
lineHandle = gpiod_chip_get_line(chip, lineNum);
|
lineHandle = gpiod_chip_get_line(chip, lineNum);
|
||||||
if (!lineHandle) {
|
if (!lineHandle) {
|
||||||
sif::debug << "LinuxLibgpioIF::configureRegularGpio: Failed to open line " << std::endl;
|
sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open line " << std::endl;
|
||||||
sif::debug << "GPIO ID: " << gpioId << ", line number: " << lineNum <<
|
sif::warning << "GPIO ID: " << gpioId << ", line number: " << lineNum <<
|
||||||
", chipname: " << chipname << std::endl;
|
", " << failOutput << std::endl;
|
||||||
sif::debug << "Check if linux GPIO configuration has changed. " << std::endl;
|
sif::warning << "Check if Linux GPIO configuration has changed. " << std::endl;
|
||||||
gpiod_chip_close(chip);
|
gpiod_chip_close(chip);
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
direction = regularGpio->direction;
|
direction = regularGpio.direction;
|
||||||
consumer = regularGpio->consumer;
|
consumer = regularGpio.consumer;
|
||||||
/* Configure direction and add a description to the GPIO */
|
/* Configure direction and add a description to the GPIO */
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case(gpio::OUT): {
|
case(gpio::OUT): {
|
||||||
result = gpiod_line_request_output(lineHandle, consumer.c_str(),
|
result = gpiod_line_request_output(lineHandle, consumer.c_str(),
|
||||||
regularGpio->initValue);
|
regularGpio.initValue);
|
||||||
if (result < 0) {
|
|
||||||
sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " << lineNum <<
|
|
||||||
" from GPIO instance with ID: " << gpioId << std::endl;
|
|
||||||
gpiod_line_release(lineHandle);
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case(gpio::IN): {
|
case(gpio::IN): {
|
||||||
result = gpiod_line_request_input(lineHandle, consumer.c_str());
|
result = gpiod_line_request_input(lineHandle, consumer.c_str());
|
||||||
if (result < 0) {
|
|
||||||
sif::error << "LinuxLibgpioIF::configureGpios: Failed to request line "
|
|
||||||
<< lineNum << " from GPIO instance with ID: " << gpioId << std::endl;
|
|
||||||
gpiod_line_release(lineHandle);
|
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -129,12 +178,24 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, GpiodRegular
|
|||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result < 0) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " <<
|
||||||
|
lineNum << " from GPIO instance with ID: " << gpioId << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printError("LinuxLibgpioIF::configureRegularGpio: "
|
||||||
|
"Failed to request line %d from GPIO instance with ID: %d\n", lineNum, gpioId);
|
||||||
|
#endif
|
||||||
|
gpiod_line_release(lineHandle);
|
||||||
|
return RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Write line handle to GPIO configuration instance so it can later be used to set or
|
* Write line handle to GPIO configuration instance so it can later be used to set or
|
||||||
* read states of GPIOs.
|
* read states of GPIOs.
|
||||||
*/
|
*/
|
||||||
regularGpio->lineHandle = lineHandle;
|
regularGpio.lineHandle = lineHandle;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,8 +206,15 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
|||||||
return UNKNOWN_GPIO_ID;
|
return UNKNOWN_GPIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIO_REGULAR) {
|
auto gpioType = gpioMapIter->second->gpioType;
|
||||||
return driveGpio(gpioId, dynamic_cast<GpiodRegular*>(gpioMapIter->second), 1);
|
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
|
||||||
|
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
|
||||||
|
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||||
|
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
||||||
|
if(regularGpio == nullptr) {
|
||||||
|
return GPIO_TYPE_FAILURE;
|
||||||
|
}
|
||||||
|
return driveGpio(gpioId, *regularGpio, gpio::HIGH);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
@@ -154,7 +222,7 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
|||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
||||||
1, gpioCallback->callbackArgs);
|
gpio::Levels::HIGH, gpioCallback->callbackArgs);
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
@@ -163,12 +231,23 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
|||||||
ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
|
ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
|
||||||
gpioMapIter = gpioMap.find(gpioId);
|
gpioMapIter = gpioMap.find(gpioId);
|
||||||
if (gpioMapIter == gpioMap.end()) {
|
if (gpioMapIter == gpioMap.end()) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "LinuxLibgpioIF::pullLow: Unknown GPIO ID " << gpioId << std::endl;
|
sif::warning << "LinuxLibgpioIF::pullLow: Unknown GPIO ID " << gpioId << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("LinuxLibgpioIF::pullLow: Unknown GPIO ID %d\n", gpioId);
|
||||||
|
#endif
|
||||||
return UNKNOWN_GPIO_ID;
|
return UNKNOWN_GPIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIO_REGULAR) {
|
auto& gpioType = gpioMapIter->second->gpioType;
|
||||||
return driveGpio(gpioId, dynamic_cast<GpiodRegular*>(gpioMapIter->second), 0);
|
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
|
||||||
|
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
|
||||||
|
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||||
|
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
||||||
|
if(regularGpio == nullptr) {
|
||||||
|
return GPIO_TYPE_FAILURE;
|
||||||
|
}
|
||||||
|
return driveGpio(gpioId, *regularGpio, gpio::LOW);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
@@ -176,22 +255,23 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
|
|||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
||||||
0, gpioCallback->callbackArgs);
|
gpio::Levels::LOW, gpioCallback->callbackArgs);
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
||||||
GpiodRegular* regularGpio, unsigned int logicLevel) {
|
GpiodRegularBase& regularGpio, gpio::Levels logicLevel) {
|
||||||
if(regularGpio == nullptr) {
|
int result = gpiod_line_set_value(regularGpio.lineHandle, logicLevel);
|
||||||
return GPIO_TYPE_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int result = gpiod_line_set_value(regularGpio->lineHandle, logicLevel);
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId <<
|
sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId <<
|
||||||
" to logic level " << logicLevel << std::endl;
|
" to logic level " << logicLevel << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID %d to "
|
||||||
|
"logic level %d\n", gpioId, logicLevel);
|
||||||
|
#endif
|
||||||
return DRIVE_GPIO_FAILURE;
|
return DRIVE_GPIO_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,22 +281,33 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
|||||||
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
|
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
|
||||||
gpioMapIter = gpioMap.find(gpioId);
|
gpioMapIter = gpioMap.find(gpioId);
|
||||||
if (gpioMapIter == gpioMap.end()){
|
if (gpioMapIter == gpioMap.end()){
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "LinuxLibgpioIF::readGpio: Unknown GPIOD ID " << gpioId << std::endl;
|
sif::warning << "LinuxLibgpioIF::readGpio: Unknown GPIOD ID " << gpioId << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("LinuxLibgpioIF::readGpio: Unknown GPIOD ID %d\n", gpioId);
|
||||||
|
#endif
|
||||||
return UNKNOWN_GPIO_ID;
|
return UNKNOWN_GPIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gpioMapIter->second->gpioType == gpio::GpioTypes::GPIO_REGULAR) {
|
auto gpioType = gpioMapIter->second->gpioType;
|
||||||
GpiodRegular* regularGpio = dynamic_cast<GpiodRegular*>(gpioMapIter->second);
|
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
|
||||||
|
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
|
||||||
|
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
|
||||||
|
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
|
||||||
if(regularGpio == nullptr) {
|
if(regularGpio == nullptr) {
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
|
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
|
if(gpioCallback->callback == nullptr) {
|
||||||
|
return GPIO_INVALID_INSTANCE;
|
||||||
|
}
|
||||||
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ,
|
||||||
|
gpio::Levels::NONE, gpioCallback->callbackArgs);
|
||||||
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,13 +316,15 @@ 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::GPIO_REGULAR): {
|
case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
|
||||||
auto regularGpio = dynamic_cast<GpiodRegular*>(gpioConfig.second);
|
case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
|
||||||
|
case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
|
||||||
|
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioConfig.second);
|
||||||
if(regularGpio == nullptr) {
|
if(regularGpio == nullptr) {
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
/* Check for conflicts and remove duplicates if necessary */
|
// Check for conflicts and remove duplicates if necessary
|
||||||
result = checkForConflictsRegularGpio(gpioConfig.first, regularGpio, mapToAdd);
|
result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
status = result;
|
status = result;
|
||||||
}
|
}
|
||||||
@@ -242,15 +335,22 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
|
|||||||
if(callbackGpio == nullptr) {
|
if(callbackGpio == nullptr) {
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
/* Check for conflicts and remove duplicates if necessary */
|
// Check for conflicts and remove duplicates if necessary
|
||||||
result = checkForConflictsCallbackGpio(gpioConfig.first, callbackGpio, mapToAdd);
|
result = checkForConflictsById(gpioConfig.first,
|
||||||
|
gpioConfig.second->gpioType, mapToAdd);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
status = result;
|
status = result;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "Invalid GPIO type detected for GPIO ID " << gpioConfig.first
|
||||||
|
<< std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("Invalid GPIO type detected for GPIO ID %d\n", gpioConfig.first);
|
||||||
|
#endif
|
||||||
|
status = GPIO_TYPE_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,48 +358,86 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::checkForConflictsRegularGpio(gpioId_t gpioIdToCheck,
|
ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
|
||||||
GpiodRegular* gpioToCheck, GpioMap& mapToAdd) {
|
gpio::GpioTypes expectedType, GpioMap& mapToAdd) {
|
||||||
/* 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::GPIO_REGULAR) {
|
auto& gpioType = gpioMapIter->second->gpioType;
|
||||||
sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for different "
|
bool eraseDuplicateDifferentType = false;
|
||||||
"GPIO type" << gpioIdToCheck << ". Removing duplicate." << std::endl;
|
switch(expectedType) {
|
||||||
mapToAdd.erase(gpioIdToCheck);
|
case(gpio::GpioTypes::NONE): {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
break;
|
||||||
}
|
}
|
||||||
auto ownRegularGpio = dynamic_cast<GpiodRegular*>(gpioMapIter->second);
|
case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
|
||||||
if(ownRegularGpio == nullptr) {
|
case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
|
||||||
return GPIO_TYPE_FAILURE;
|
case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
|
||||||
|
if(gpioType == gpio::GpioTypes::NONE or gpioType == gpio::GpioTypes::CALLBACK) {
|
||||||
|
eraseDuplicateDifferentType = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(gpio::GpioTypes::CALLBACK): {
|
||||||
|
if(gpioType != gpio::GpioTypes::CALLBACK) {
|
||||||
|
eraseDuplicateDifferentType = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(eraseDuplicateDifferentType) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for "
|
||||||
|
"different GPIO type " << gpioIdToCheck <<
|
||||||
|
". Removing duplicate from map to add" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("LinuxLibgpioIF::checkForConflicts: ID already exists for "
|
||||||
|
"different GPIO type %d. Removing duplicate from map to add\n", gpioIdToCheck);
|
||||||
|
#endif
|
||||||
|
mapToAdd.erase(gpioIdToCheck);
|
||||||
|
return GPIO_DUPLICATE_DETECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove element from map to add because a entry for this GPIO
|
// Remove element from map to add because a entry for this GPIO already exists
|
||||||
already exists */
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition"
|
sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO "
|
||||||
<< " detected. Duplicate will be removed from map to add." << std::endl;
|
"definition with ID " << gpioIdToCheck << " detected. " <<
|
||||||
|
"Duplicate will be removed from map to add" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition "
|
||||||
|
"with ID %d detected. Duplicate will be removed from map to add\n", gpioIdToCheck);
|
||||||
|
#endif
|
||||||
mapToAdd.erase(gpioIdToCheck);
|
mapToAdd.erase(gpioIdToCheck);
|
||||||
|
return GPIO_DUPLICATE_DETECTED;
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t LinuxLibgpioIF::checkForConflictsCallbackGpio(gpioId_t gpioIdToCheck,
|
void LinuxLibgpioIF::parseFindeLineResult(int result, std::string& lineName) {
|
||||||
GpioCallback *callbackGpio, GpioMap& mapToAdd) {
|
switch (result) {
|
||||||
/* Cross check with private map */
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
gpioMapIter = gpioMap.find(gpioIdToCheck);
|
case LINE_NOT_EXISTS:
|
||||||
if(gpioMapIter != gpioMap.end()) {
|
case LINE_ERROR: {
|
||||||
if(gpioMapIter->second->gpioType != gpio::GpioTypes::CALLBACK) {
|
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Line with name " << lineName <<
|
||||||
sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for different "
|
" does not exist" << std::endl;
|
||||||
"GPIO type" << gpioIdToCheck << ". Removing duplicate." << std::endl;
|
break;
|
||||||
mapToAdd.erase(gpioIdToCheck);
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove element from map to add because a entry for this GPIO
|
|
||||||
already exists */
|
|
||||||
sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition"
|
|
||||||
<< " detected. Duplicate will be removed from map to add." << std::endl;
|
|
||||||
mapToAdd.erase(gpioIdToCheck);
|
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
default: {
|
||||||
|
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
|
||||||
|
"with name " << lineName << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
case LINE_NOT_EXISTS:
|
||||||
|
case LINE_ERROR: {
|
||||||
|
sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Line with name %s "
|
||||||
|
"does not exist\n", lineName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
|
||||||
|
"with name %s\n", lineName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,18 +1,19 @@
|
|||||||
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
||||||
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
||||||
|
|
||||||
#include "../../common/gpio/GpioIF.h"
|
#include "fsfw/returnvalues/FwClassIds.h"
|
||||||
#include <returnvalues/classIds.h>
|
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||||
#include <fsfw/objectmanager/SystemObject.h>
|
#include "fsfw/objectmanager/SystemObject.h"
|
||||||
|
|
||||||
class GpioCookie;
|
class GpioCookie;
|
||||||
|
class GpiodRegularIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class implements the GpioIF for a linux based system. The
|
* @brief This class implements the GpioIF for a linux based system.
|
||||||
* implementation is based on the libgpiod lib which requires linux 4.8
|
* @details
|
||||||
* or higher.
|
* This implementation is based on the libgpiod lib which requires Linux 4.8 or higher.
|
||||||
* @note The Petalinux SDK from Xilinx supports libgpiod since Petalinux
|
* @note
|
||||||
* 2019.1.
|
* The Petalinux SDK from Xilinx supports libgpiod since Petalinux 2019.1.
|
||||||
*/
|
*/
|
||||||
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
||||||
public:
|
public:
|
||||||
@@ -27,6 +28,8 @@ public:
|
|||||||
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 3);
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 3);
|
||||||
static constexpr ReturnValue_t GPIO_INVALID_INSTANCE =
|
static constexpr ReturnValue_t GPIO_INVALID_INSTANCE =
|
||||||
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 4);
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 4);
|
||||||
|
static constexpr ReturnValue_t GPIO_DUPLICATE_DETECTED =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 5);
|
||||||
|
|
||||||
LinuxLibgpioIF(object_id_t objectId);
|
LinuxLibgpioIF(object_id_t objectId);
|
||||||
virtual ~LinuxLibgpioIF();
|
virtual ~LinuxLibgpioIF();
|
||||||
@@ -37,7 +40,13 @@ public:
|
|||||||
ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override;
|
ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Holds the information and configuration of all used GPIOs */
|
|
||||||
|
static const size_t MAX_CHIPNAME_LENGTH = 11;
|
||||||
|
static const int LINE_NOT_EXISTS = 0;
|
||||||
|
static const int LINE_ERROR = -1;
|
||||||
|
static const int LINE_FOUND = 1;
|
||||||
|
|
||||||
|
// Holds the information and configuration of all used GPIOs
|
||||||
GpioUnorderedMap gpioMap;
|
GpioUnorderedMap gpioMap;
|
||||||
GpioUnorderedMapIter gpioMapIter;
|
GpioUnorderedMapIter gpioMapIter;
|
||||||
|
|
||||||
@@ -47,9 +56,15 @@ private:
|
|||||||
* @param gpioId The GPIO ID of the GPIO to drive.
|
* @param gpioId The GPIO ID of the GPIO to drive.
|
||||||
* @param logiclevel The logic level to set. O or 1.
|
* @param logiclevel The logic level to set. O or 1.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegular* regularGpio, unsigned int logiclevel);
|
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio,
|
||||||
|
gpio::Levels logicLevel);
|
||||||
|
|
||||||
ReturnValue_t configureRegularGpio(gpioId_t gpioId, GpiodRegular* regularGpio);
|
ReturnValue_t configureGpioByLabel(gpioId_t gpioId, GpiodRegularByLabel& gpioByLabel);
|
||||||
|
ReturnValue_t configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip);
|
||||||
|
ReturnValue_t configureGpioByLineName(gpioId_t gpioId,
|
||||||
|
GpiodRegularByLineName &gpioByLineName);
|
||||||
|
ReturnValue_t configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
||||||
|
GpiodRegularBase& regularGpio, std::string failOutput);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function checks if GPIOs are already registered and whether
|
* @brief This function checks if GPIOs are already registered and whether
|
||||||
@@ -62,16 +77,15 @@ private:
|
|||||||
*/
|
*/
|
||||||
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
||||||
|
|
||||||
ReturnValue_t checkForConflictsRegularGpio(gpioId_t gpiodId, GpiodRegular* regularGpio,
|
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type,
|
||||||
GpioMap& mapToAdd);
|
GpioMap& mapToAdd);
|
||||||
ReturnValue_t checkForConflictsCallbackGpio(gpioId_t gpiodId, GpioCallback* regularGpio,
|
|
||||||
GpioMap& mapToAdd);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t configureGpios(GpioMap& mapToAdd);
|
ReturnValue_t configureGpios(GpioMap& mapToAdd);
|
||||||
|
|
||||||
|
void parseFindeLineResult(int result, std::string& lineName);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LINUX_GPIO_LINUXLIBGPIOIF_H_ */
|
#endif /* LINUX_GPIO_LINUXLIBGPIOIF_H_ */
|
||||||
|
@@ -12,7 +12,7 @@ ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int
|
|||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpiodRegular* config = new GpiodRegular();
|
auto config = new GpiodRegularByChip();
|
||||||
/* Default chipname for Raspberry Pi. There is still gpiochip1 for expansion, but most users
|
/* Default chipname for Raspberry Pi. There is still gpiochip1 for expansion, but most users
|
||||||
will not need this */
|
will not need this */
|
||||||
config->chipname = "gpiochip0";
|
config->chipname = "gpiochip0";
|
||||||
|
@@ -141,8 +141,8 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
|||||||
if(sendLen > spiCookie->getMaxBufferSize()) {
|
if(sendLen > spiCookie->getMaxBufferSize()) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "SpiComIF::sendMessage: Too much data sent, send length" << sendLen <<
|
sif::warning << "SpiComIF::sendMessage: Too much data sent, send length " << sendLen <<
|
||||||
"larger than maximum buffer length" << spiCookie->getMaxBufferSize() << std::endl;
|
"larger than maximum buffer length " << spiCookie->getMaxBufferSize() << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("SpiComIF::sendMessage: Too much data sent, send length %lu larger "
|
sif::printWarning("SpiComIF::sendMessage: Too much data sent, send length %lu larger "
|
||||||
"than maximum buffer length %lu!\n", static_cast<unsigned long>(sendLen),
|
"than maximum buffer length %lu!\n", static_cast<unsigned long>(sendLen),
|
||||||
@@ -197,12 +197,26 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
|||||||
if(gpioId != gpio::NO_GPIO) {
|
if(gpioId != gpio::NO_GPIO) {
|
||||||
result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl;
|
sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printError("SpiComIF::sendMessage: Failed to lock mutex\n");
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
ReturnValue_t result = gpioComIF->pullLow(gpioId);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "SpiComIF::sendMessage: Pulling low CS pin failed" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("SpiComIF::sendMessage: Pulling low CS pin failed");
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
gpioComIF->pullLow(gpioId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute transfer */
|
/* Execute transfer */
|
||||||
@@ -213,7 +227,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
|
|||||||
utility::handleIoctlError("SpiComIF::sendMessage: ioctl error.");
|
utility::handleIoctlError("SpiComIF::sendMessage: ioctl error.");
|
||||||
result = FULL_DUPLEX_TRANSFER_FAILED;
|
result = FULL_DUPLEX_TRANSFER_FAILED;
|
||||||
}
|
}
|
||||||
#if FSFW_HAL_LINUX_SPI_WIRETAPPING == 1
|
#if FSFW_HAL_SPI_WIRETAPPING == 1
|
||||||
performSpiWiretapping(spiCookie);
|
performSpiWiretapping(spiCookie);
|
||||||
#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */
|
#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */
|
||||||
}
|
}
|
||||||
@@ -384,11 +398,11 @@ GpioIF* SpiComIF::getGpioInterface() {
|
|||||||
void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) {
|
void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) {
|
||||||
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode));
|
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode));
|
||||||
if(retval != 0) {
|
if(retval != 0) {
|
||||||
utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI mode failed!");
|
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI mode failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = ioctl(spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
|
retval = ioctl(spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
|
||||||
if(retval != 0) {
|
if(retval != 0) {
|
||||||
utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI speed failed!");
|
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,15 @@
|
|||||||
#cmakedefine FSFW_ADD_MONITORING
|
#cmakedefine FSFW_ADD_MONITORING
|
||||||
#cmakedefine FSFW_ADD_SGP4_PROPAGATOR
|
#cmakedefine FSFW_ADD_SGP4_PROPAGATOR
|
||||||
|
|
||||||
|
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
|
||||||
|
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Can be used for low-level debugging of the SPI bus
|
||||||
|
#ifndef FSFW_HAL_SPI_WIRETAPPING
|
||||||
|
#define FSFW_HAL_SPI_WIRETAPPING 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef FSFW_HAL_L3GD20_GYRO_DEBUG
|
#ifndef FSFW_HAL_L3GD20_GYRO_DEBUG
|
||||||
#define FSFW_HAL_L3GD20_GYRO_DEBUG 0
|
#define FSFW_HAL_L3GD20_GYRO_DEBUG 0
|
||||||
#endif /* FSFW_HAL_L3GD20_GYRO_DEBUG */
|
#endif /* FSFW_HAL_L3GD20_GYRO_DEBUG */
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Base class to implement reconfiguration and failure handling for
|
* @brief Base class to implement reconfiguration and failure handling for
|
||||||
* redundant devices by monitoring their modes health states.
|
* redundant devices by monitoring their modes and health states.
|
||||||
* @details
|
* @details
|
||||||
* Documentation: Dissertation Baetz p.156, 157.
|
* Documentation: Dissertation Baetz p.156, 157.
|
||||||
*
|
*
|
||||||
|
@@ -85,9 +85,10 @@ public:
|
|||||||
* Called by DHB in the GET_WRITE doGetWrite().
|
* Called by DHB in the GET_WRITE doGetWrite().
|
||||||
* Get send confirmation that the data in sendMessage() was sent successfully.
|
* Get send confirmation that the data in sendMessage() was sent successfully.
|
||||||
* @param cookie
|
* @param cookie
|
||||||
* @return - @c RETURN_OK if data was sent successfull
|
* @return
|
||||||
* - Everything else triggers falure event with
|
* - @c RETURN_OK if data was sent successfully but a reply is expected
|
||||||
* returnvalue as parameter 1
|
* - NO_REPLY_EXPECTED if data was sent successfully and no reply is expected
|
||||||
|
* - Everything else to indicate failure
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0;
|
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0;
|
||||||
|
|
||||||
|
@@ -334,8 +334,7 @@ protected:
|
|||||||
* - @c RETURN_OK to send command after #rawPacket and #rawPacketLen
|
* - @c RETURN_OK to send command after #rawPacket and #rawPacketLen
|
||||||
* have been set.
|
* have been set.
|
||||||
* - @c HasActionsIF::EXECUTION_COMPLETE to generate a finish reply immediately. This can
|
* - @c HasActionsIF::EXECUTION_COMPLETE to generate a finish reply immediately. This can
|
||||||
* be used if no reply is expected. Otherwise, the developer can call #actionHelper.finish
|
* be used if no reply is expected
|
||||||
* to finish the command handling.
|
|
||||||
* - Anything else triggers an event with the return code as a parameter as well as a
|
* - Anything else triggers an event with the return code as a parameter as well as a
|
||||||
* step reply failed with the return code
|
* step reply failed with the return code
|
||||||
*/
|
*/
|
||||||
|
@@ -120,7 +120,8 @@ public:
|
|||||||
static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5);
|
static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5);
|
||||||
static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA6);
|
static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA6);
|
||||||
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xA7);
|
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xA7);
|
||||||
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8); //!< Used to indicate that this is a command-only command.
|
//!< Used to indicate that this is a command-only command.
|
||||||
|
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8);
|
||||||
static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9);
|
static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9);
|
||||||
static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA);
|
static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA);
|
||||||
|
|
||||||
|
@@ -2,43 +2,42 @@
|
|||||||
|
|
||||||
|
|
||||||
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
|
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
|
||||||
bool resetAutomatically): resetAutomatically(resetAutomatically),
|
bool resetAutomatically): resetAutomatically(resetAutomatically),
|
||||||
counter(divider), divider(divider) {
|
counter(divider), divider(divider) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeriodicOperationDivider::checkAndIncrement() {
|
bool PeriodicOperationDivider::checkAndIncrement() {
|
||||||
bool opNecessary = check();
|
counter++;
|
||||||
if(opNecessary) {
|
bool opNecessary = check();
|
||||||
if(resetAutomatically) {
|
if(opNecessary) {
|
||||||
counter = 0;
|
if(resetAutomatically) {
|
||||||
}
|
resetCounter();
|
||||||
return opNecessary;
|
}
|
||||||
}
|
}
|
||||||
counter ++;
|
return opNecessary;
|
||||||
return opNecessary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeriodicOperationDivider::check() {
|
bool PeriodicOperationDivider::check() {
|
||||||
if(counter >= divider) {
|
if(counter >= divider) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PeriodicOperationDivider::resetCounter() {
|
void PeriodicOperationDivider::resetCounter() {
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
|
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
|
||||||
divider = newDivider;
|
divider = newDivider;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PeriodicOperationDivider::getCounter() const {
|
uint32_t PeriodicOperationDivider::getCounter() const {
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PeriodicOperationDivider::getDivider() const {
|
uint32_t PeriodicOperationDivider::getDivider() const {
|
||||||
return divider;
|
return divider;
|
||||||
}
|
}
|
||||||
|
@@ -13,51 +13,51 @@
|
|||||||
*/
|
*/
|
||||||
class PeriodicOperationDivider {
|
class PeriodicOperationDivider {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Initialize with the desired divider and specify whether the internal
|
* Initialize with the desired divider and specify whether the internal
|
||||||
* counter will be reset automatically.
|
* counter will be reset automatically.
|
||||||
* @param divider
|
* @param divider
|
||||||
* @param resetAutomatically
|
* @param resetAutomatically
|
||||||
*/
|
*/
|
||||||
PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true);
|
PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether operation is necessary.
|
* Check whether operation is necessary.
|
||||||
* If an operation is necessary and the class has been
|
* If an operation is necessary and the class has been
|
||||||
* configured to be reset automatically, the counter will be reset.
|
* configured to be reset automatically, the counter will be reset.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* -@c true if the counter is larger or equal to the divider
|
* -@c true if the counter is larger or equal to the divider
|
||||||
* -@c false otherwise
|
* -@c false otherwise
|
||||||
*/
|
*/
|
||||||
bool checkAndIncrement();
|
bool checkAndIncrement();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether an operation is necessary.
|
* Checks whether an operation is necessary.
|
||||||
* This function will not increment the counter!
|
* This function will not increment the counter!
|
||||||
* @return
|
* @return
|
||||||
* -@c true if the counter is larger or equal to the divider
|
* -@c true if the counter is larger or equal to the divider
|
||||||
* -@c false otherwise
|
* -@c false otherwise
|
||||||
*/
|
*/
|
||||||
bool check();
|
bool check();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to reset the counter to 0 manually.
|
* Can be used to reset the counter to 0 manually.
|
||||||
*/
|
*/
|
||||||
void resetCounter();
|
void resetCounter();
|
||||||
uint32_t getCounter() const;
|
uint32_t getCounter() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to set a new divider value.
|
* Can be used to set a new divider value.
|
||||||
* @param newDivider
|
* @param newDivider
|
||||||
*/
|
*/
|
||||||
void setDivider(uint32_t newDivider);
|
void setDivider(uint32_t newDivider);
|
||||||
uint32_t getDivider() const;
|
uint32_t getDivider() const;
|
||||||
private:
|
private:
|
||||||
bool resetAutomatically = true;
|
bool resetAutomatically = true;
|
||||||
uint32_t counter = 0;
|
uint32_t counter = 0;
|
||||||
uint32_t divider = 0;
|
uint32_t divider = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -81,7 +81,7 @@ public:
|
|||||||
* @param args Any other arguments which an implementation might require
|
* @param args Any other arguments which an implementation might require
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t deleteFile(const char* repositoryPath,
|
virtual ReturnValue_t removeFile(const char* repositoryPath,
|
||||||
const char* filename, void* args = nullptr) = 0;
|
const char* filename, void* args = nullptr) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
#include "fsfw/osal/common/TcpTmTcServer.h"
|
|
||||||
#include "fsfw/osal/common/TcpTmTcBridge.h"
|
|
||||||
#include "fsfw/osal/common/tcpipHelpers.h"
|
|
||||||
|
|
||||||
#include "fsfw/platform.h"
|
#include "fsfw/platform.h"
|
||||||
|
#include "fsfw/FSFW.h"
|
||||||
|
|
||||||
|
#include "TcpTmTcServer.h"
|
||||||
|
#include "TcpTmTcBridge.h"
|
||||||
|
#include "tcpipHelpers.h"
|
||||||
|
|
||||||
#include "fsfw/container/SharedRingBuffer.h"
|
#include "fsfw/container/SharedRingBuffer.h"
|
||||||
#include "fsfw/ipc/MessageQueueSenderIF.h"
|
#include "fsfw/ipc/MessageQueueSenderIF.h"
|
||||||
#include "fsfw/ipc/MutexGuard.h"
|
#include "fsfw/ipc/MutexGuard.h"
|
||||||
|
@@ -16,6 +16,7 @@ target_sources(${LIB_FSFW_NAME}
|
|||||||
Timer.cpp
|
Timer.cpp
|
||||||
tcpipHelpers.cpp
|
tcpipHelpers.cpp
|
||||||
unixUtility.cpp
|
unixUtility.cpp
|
||||||
|
CommandExecutor.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
185
src/fsfw/osal/linux/CommandExecutor.cpp
Normal file
185
src/fsfw/osal/linux/CommandExecutor.cpp
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
#include "CommandExecutor.h"
|
||||||
|
|
||||||
|
#include "fsfw/serviceinterface.h"
|
||||||
|
#include "fsfw/container/SimpleRingBuffer.h"
|
||||||
|
#include "fsfw/container/DynamicFIFO.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
CommandExecutor::CommandExecutor(const size_t maxSize):
|
||||||
|
readVec(maxSize) {
|
||||||
|
waiter.events = POLLIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::load(std::string command, bool blocking, bool printOutput) {
|
||||||
|
if(state == States::PENDING) {
|
||||||
|
return COMMAND_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentCmd = command;
|
||||||
|
this->blocking = blocking;
|
||||||
|
this->printOutput = printOutput;
|
||||||
|
if(state == States::IDLE) {
|
||||||
|
state = States::COMMAND_LOADED;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::execute() {
|
||||||
|
if(state == States::IDLE) {
|
||||||
|
return NO_COMMAND_LOADED_OR_PENDING;
|
||||||
|
}
|
||||||
|
else if(state == States::PENDING) {
|
||||||
|
return COMMAND_PENDING;
|
||||||
|
}
|
||||||
|
currentCmdFile = popen(currentCmd.c_str(), "r");
|
||||||
|
if(currentCmdFile == nullptr) {
|
||||||
|
lastError = errno;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
if(blocking) {
|
||||||
|
return executeBlocking();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currentFd = fileno(currentCmdFile);
|
||||||
|
waiter.fd = currentFd;
|
||||||
|
}
|
||||||
|
state = States::PENDING;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::close() {
|
||||||
|
if(state == States::PENDING) {
|
||||||
|
// Attempt to close process, irrespective of if it is running or not
|
||||||
|
if(currentCmdFile != nullptr) {
|
||||||
|
pclose(currentCmdFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandExecutor::printLastError(std::string funcName) const {
|
||||||
|
if(lastError != 0) {
|
||||||
|
sif::error << funcName << " pclose failed with code " <<
|
||||||
|
lastError << ": " << strerror(lastError) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandExecutor::setRingBuffer(SimpleRingBuffer *ringBuffer,
|
||||||
|
DynamicFIFO<uint16_t>* sizesFifo) {
|
||||||
|
this->ringBuffer = ringBuffer;
|
||||||
|
this->sizesFifo = sizesFifo;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::check(bool& bytesRead) {
|
||||||
|
if(blocking) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
switch(state) {
|
||||||
|
case(States::IDLE):
|
||||||
|
case(States::COMMAND_LOADED): {
|
||||||
|
return NO_COMMAND_LOADED_OR_PENDING;
|
||||||
|
}
|
||||||
|
case(States::PENDING): {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = poll(&waiter, 1, 0);
|
||||||
|
switch(result) {
|
||||||
|
case(0): {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(1): {
|
||||||
|
if (waiter.revents & POLLIN) {
|
||||||
|
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
|
||||||
|
if(readBytes == 0) {
|
||||||
|
// Should not happen
|
||||||
|
sif::warning << "CommandExecutor::check: "
|
||||||
|
"No bytes read after poll event.." << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(readBytes > 0) {
|
||||||
|
bytesRead = true;
|
||||||
|
if(printOutput) {
|
||||||
|
// It is assumed the command output is line terminated
|
||||||
|
sif::info << currentCmd << " | " << readVec.data();
|
||||||
|
}
|
||||||
|
if(ringBuffer != nullptr) {
|
||||||
|
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(
|
||||||
|
readVec.data()), readBytes);
|
||||||
|
}
|
||||||
|
if(sizesFifo != nullptr) {
|
||||||
|
if(not sizesFifo->full()) {
|
||||||
|
sizesFifo->insert(readBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BYTES_READ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Should also not happen
|
||||||
|
sif::warning << "CommandExecutor::check: Error " << errno << ": " <<
|
||||||
|
strerror(errno) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(waiter.revents & POLLERR) {
|
||||||
|
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
|
||||||
|
return COMMAND_ERROR;
|
||||||
|
}
|
||||||
|
else if(waiter.revents & POLLHUP) {
|
||||||
|
int result = pclose(currentCmdFile);
|
||||||
|
if(result != 0) {
|
||||||
|
lastError = result;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
state = States::IDLE;
|
||||||
|
currentCmdFile = nullptr;
|
||||||
|
currentFd = 0;
|
||||||
|
return EXECUTION_FINISHED;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandExecutor::reset() {
|
||||||
|
CommandExecutor::close();
|
||||||
|
currentCmdFile = nullptr;
|
||||||
|
currentFd = 0;
|
||||||
|
state = States::IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CommandExecutor::getLastError() const {
|
||||||
|
return this->lastError;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandExecutor::States CommandExecutor::getCurrentState() const {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CommandExecutor::executeBlocking() {
|
||||||
|
while(fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
|
||||||
|
std::string output(readVec.data());
|
||||||
|
if(printOutput) {
|
||||||
|
sif::info << currentCmd << " | " << output;
|
||||||
|
}
|
||||||
|
if(ringBuffer != nullptr) {
|
||||||
|
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());
|
||||||
|
}
|
||||||
|
if(sizesFifo != nullptr) {
|
||||||
|
if(not sizesFifo->full()) {
|
||||||
|
sizesFifo->insert(output.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int result = pclose(currentCmdFile);
|
||||||
|
if(result != 0) {
|
||||||
|
lastError = result;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
134
src/fsfw/osal/linux/CommandExecutor.h
Normal file
134
src/fsfw/osal/linux/CommandExecutor.h
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
#ifndef FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||||
|
#define FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||||
|
|
||||||
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include "fsfw/returnvalues/FwClassIds.h"
|
||||||
|
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class SimpleRingBuffer;
|
||||||
|
template <typename T> class DynamicFIFO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper class to execute shell commands in blocking and non-blocking mode
|
||||||
|
* @details
|
||||||
|
* This class is able to execute processes by using the Linux popen call. It also has the
|
||||||
|
* capability of writing the read output of a process into a provided ring buffer.
|
||||||
|
*
|
||||||
|
* The executor works by first loading the command which should be executed and specifying
|
||||||
|
* whether it should be executed blocking or non-blocking. After that, execution can be started
|
||||||
|
* with the execute command. In blocking mode, the execute command will block until the command
|
||||||
|
* has finished
|
||||||
|
*/
|
||||||
|
class CommandExecutor {
|
||||||
|
public:
|
||||||
|
enum class States {
|
||||||
|
IDLE,
|
||||||
|
COMMAND_LOADED,
|
||||||
|
PENDING
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL;
|
||||||
|
|
||||||
|
//! [EXPORT] : [COMMENT] Execution of the current command has finished
|
||||||
|
static constexpr ReturnValue_t EXECUTION_FINISHED =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0);
|
||||||
|
|
||||||
|
//! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries
|
||||||
|
//! to load another command but a command is still pending
|
||||||
|
static constexpr ReturnValue_t COMMAND_PENDING =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
|
||||||
|
//! [EXPORT] : [COMMENT] Some bytes have been read from the executing process
|
||||||
|
static constexpr ReturnValue_t BYTES_READ =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
|
||||||
|
//! [EXPORT] : [COMMENT] Command execution failed
|
||||||
|
static constexpr ReturnValue_t COMMAND_ERROR =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
|
||||||
|
//! [EXPORT] : [COMMENT]
|
||||||
|
static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 4);
|
||||||
|
static constexpr ReturnValue_t PCLOSE_CALL_ERROR =
|
||||||
|
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor. Is initialized with maximum size of internal buffer to read data from the
|
||||||
|
* executed process.
|
||||||
|
* @param maxSize
|
||||||
|
*/
|
||||||
|
CommandExecutor(const size_t maxSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a new command which should be executed
|
||||||
|
* @param command
|
||||||
|
* @param blocking
|
||||||
|
* @param printOutput
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t load(std::string command, bool blocking, bool printOutput = true);
|
||||||
|
/**
|
||||||
|
* Execute the loaded command.
|
||||||
|
* @return
|
||||||
|
* - In blocking mode, it will return RETURN_FAILED if
|
||||||
|
* the result of the system call was not 0. The error value can be accessed using
|
||||||
|
* getLastError
|
||||||
|
* - In non-blocking mode, this call will start
|
||||||
|
* the execution and then return RETURN_OK
|
||||||
|
*/
|
||||||
|
ReturnValue_t execute();
|
||||||
|
/**
|
||||||
|
* Only used in non-blocking mode. Checks the currently running command.
|
||||||
|
* @param bytesRead Will be set to the number of bytes read, if bytes have been read
|
||||||
|
* @return
|
||||||
|
* - BYTES_READ if bytes have been read from the executing process. It is recommended to call
|
||||||
|
* check again after this
|
||||||
|
* - RETURN_OK execution is pending, but no bytes have been read from the executing process
|
||||||
|
* - RETURN_FAILED if execution has failed, error value can be accessed using getLastError
|
||||||
|
* - EXECUTION_FINISHED if the process was executed successfully
|
||||||
|
* - COMMAND_ERROR internal poll error
|
||||||
|
*/
|
||||||
|
ReturnValue_t check(bool& bytesRead);
|
||||||
|
/**
|
||||||
|
* Abort the current command. Should normally not be necessary, check can be used to find
|
||||||
|
* out whether command execution was successful
|
||||||
|
* @return RETURN_OK
|
||||||
|
*/
|
||||||
|
ReturnValue_t close();
|
||||||
|
|
||||||
|
States getCurrentState() const;
|
||||||
|
int getLastError() const;
|
||||||
|
void printLastError(std::string funcName) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign a ring buffer and a FIFO which will be filled by the executor with the output
|
||||||
|
* read from the started process
|
||||||
|
* @param ringBuffer
|
||||||
|
* @param sizesFifo
|
||||||
|
*/
|
||||||
|
void setRingBuffer(SimpleRingBuffer* ringBuffer, DynamicFIFO<uint16_t>* sizesFifo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the executor. This calls close internally and then reset the state machine so new
|
||||||
|
* commands can be loaded and executed
|
||||||
|
*/
|
||||||
|
void reset();
|
||||||
|
private:
|
||||||
|
std::string currentCmd;
|
||||||
|
bool blocking = true;
|
||||||
|
FILE* currentCmdFile = nullptr;
|
||||||
|
int currentFd = 0;
|
||||||
|
bool printOutput = true;
|
||||||
|
std::vector<char> readVec;
|
||||||
|
struct pollfd waiter {};
|
||||||
|
SimpleRingBuffer* ringBuffer = nullptr;
|
||||||
|
DynamicFIFO<uint16_t>* sizesFifo = nullptr;
|
||||||
|
|
||||||
|
States state = States::IDLE;
|
||||||
|
int lastError = 0;
|
||||||
|
|
||||||
|
ReturnValue_t executeBlocking();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_ */
|
@@ -285,10 +285,10 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
|||||||
|
|
||||||
utility::printUnixErrorGeneric(CLASS_NAME, "sendMessageFromMessageQueue", "EBADF");
|
utility::printUnixErrorGeneric(CLASS_NAME, "sendMessageFromMessageQueue", "EBADF");
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "mq_send to: " << sendTo << " sent from "
|
sif::warning << "mq_send to " << sendTo << " sent from "
|
||||||
<< sentFrom << "failed" << std::endl;
|
<< sentFrom << " failed" << std::endl;
|
||||||
#else
|
#else
|
||||||
sif::printWarning("mq_send to: %d sent from %d failed\n", sendTo, sentFrom);
|
sif::printWarning("mq_send to %d sent from %d failed\n", sendTo, sentFrom);
|
||||||
#endif
|
#endif
|
||||||
return DESTINATION_INVALID;
|
return DESTINATION_INVALID;
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ int Timer::setTimer(uint32_t intervalMs) {
|
|||||||
timer.it_value.tv_nsec = (intervalMs * 1000000) % (1000000000);
|
timer.it_value.tv_nsec = (intervalMs * 1000000) % (1000000000);
|
||||||
timer.it_interval.tv_sec = 0;
|
timer.it_interval.tv_sec = 0;
|
||||||
timer.it_interval.tv_nsec = 0;
|
timer.it_interval.tv_nsec = 0;
|
||||||
|
set = true;
|
||||||
return timer_settime(timerId, 0, &timer, NULL);
|
return timer_settime(timerId, 0, &timer, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,3 +44,14 @@ int Timer::getTimer(uint32_t* remainingTimeMs){
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Timer::isSet() const {
|
||||||
|
return this->set;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::resetTimer() {
|
||||||
|
if(not this->set) {
|
||||||
|
set = false;
|
||||||
|
}
|
||||||
|
setTimer(0);
|
||||||
|
}
|
||||||
|
@@ -38,7 +38,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
int getTimer(uint32_t* remainingTimeMs);
|
int getTimer(uint32_t* remainingTimeMs);
|
||||||
|
|
||||||
|
bool isSet() const;
|
||||||
|
void resetTimer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool set = true;
|
||||||
timer_t timerId;
|
timer_t timerId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -41,8 +41,7 @@ ReturnValue_t Service5EventReporting::performService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::debug << "Service5EventReporting::generateEventReport:"
|
sif::warning << "Service5EventReporting::generateEventReport: Too many events" << std::endl;
|
||||||
" Too many events" << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
@@ -64,8 +63,11 @@ ReturnValue_t Service5EventReporting::generateEventReport(
|
|||||||
requestQueue->getDefaultDestination(),requestQueue->getId());
|
requestQueue->getDefaultDestination(),requestQueue->getId());
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::debug << "Service5EventReporting::generateEventReport:"
|
sif::warning << "Service5EventReporting::generateEventReport: "
|
||||||
" Could not send TM packet" << std::endl;
|
"Could not send TM packet" << std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("Service5EventReporting::generateEventReport: "
|
||||||
|
"Could not send TM packet\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@@ -33,8 +33,8 @@ ReturnValue_t Service8FunctionManagement::getMessageQueueAndObject(
|
|||||||
if(tcDataLen < sizeof(object_id_t)) {
|
if(tcDataLen < sizeof(object_id_t)) {
|
||||||
return CommandingServiceBase::INVALID_TC;
|
return CommandingServiceBase::INVALID_TC;
|
||||||
}
|
}
|
||||||
SerializeAdapter::deSerialize(objectId, &tcData,
|
// Can't fail, size was checked before
|
||||||
&tcDataLen, SerializeIF::Endianness::BIG);
|
SerializeAdapter::deSerialize(objectId, &tcData, &tcDataLen, SerializeIF::Endianness::BIG);
|
||||||
|
|
||||||
return checkInterfaceAndAcquireMessageQueue(id,objectId);
|
return checkInterfaceAndAcquireMessageQueue(id,objectId);
|
||||||
}
|
}
|
||||||
|
@@ -72,10 +72,12 @@ enum: uint8_t {
|
|||||||
PUS_SERVICE_3, //PUS3
|
PUS_SERVICE_3, //PUS3
|
||||||
PUS_SERVICE_9, //PUS9
|
PUS_SERVICE_9, //PUS9
|
||||||
FILE_SYSTEM, //FILS
|
FILE_SYSTEM, //FILS
|
||||||
|
LINUX_OSAL, //UXOS
|
||||||
HAL_SPI, //HSPI
|
HAL_SPI, //HSPI
|
||||||
HAL_UART, //HURT
|
HAL_UART, //HURT
|
||||||
HAL_I2C, //HI2C
|
HAL_I2C, //HI2C
|
||||||
HAL_GPIO, //HGIO
|
HAL_GPIO, //HGIO
|
||||||
|
FIXED_SLOT_TASK_IF, //FTIF
|
||||||
MGM_LIS3MDL, //MGMLIS3
|
MGM_LIS3MDL, //MGMLIS3
|
||||||
MGM_RM3100, //MGMRM3100
|
MGM_RM3100, //MGMRM3100
|
||||||
FW_CLASS_ID_COUNT // [EXPORT] : [END]
|
FW_CLASS_ID_COUNT // [EXPORT] : [END]
|
||||||
|
@@ -22,9 +22,9 @@ public:
|
|||||||
* @param number
|
* @param number
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static constexpr ReturnValue_t makeReturnCode(uint8_t interfaceId,
|
static constexpr ReturnValue_t makeReturnCode(uint8_t classId,
|
||||||
uint8_t number) {
|
uint8_t number) {
|
||||||
return (static_cast<ReturnValue_t>(interfaceId) << 8) + number;
|
return (static_cast<ReturnValue_t>(classId) << 8) + number;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -62,7 +62,8 @@ protected:
|
|||||||
struct ChildInfo {
|
struct ChildInfo {
|
||||||
MessageQueueId_t commandQueue;
|
MessageQueueId_t commandQueue;
|
||||||
Mode_t mode;
|
Mode_t mode;
|
||||||
Submode_t submode;bool healthChanged;
|
Submode_t submode;
|
||||||
|
bool healthChanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
Mode_t mode;
|
Mode_t mode;
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
#include "fsfw/tasks/FixedSlotSequence.h"
|
#include "fsfw/tasks/FixedSlotSequence.h"
|
||||||
|
#include "fsfw/tasks/FixedTimeslotTaskIF.h"
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
@@ -92,10 +93,9 @@ void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
|||||||
ReturnValue_t FixedSlotSequence::checkSequence() const {
|
ReturnValue_t FixedSlotSequence::checkSequence() const {
|
||||||
if(slotList.empty()) {
|
if(slotList.empty()) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "FixedSlotSequence::checkSequence:"
|
sif::warning << "FixedSlotSequence::checkSequence: Slot list is empty!" << std::endl;
|
||||||
<< " Slot list is empty!" << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return FixedTimeslotTaskIF::SLOT_LIST_EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(customCheckFunction != nullptr) {
|
if(customCheckFunction != nullptr) {
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
#define FSFW_TASKS_FIXEDSLOTSEQUENCE_H_
|
#define FSFW_TASKS_FIXEDSLOTSEQUENCE_H_
|
||||||
|
|
||||||
#include "FixedSequenceSlot.h"
|
#include "FixedSequenceSlot.h"
|
||||||
#include "../objectmanager/SystemObject.h"
|
#include "fsfw/objectmanager/SystemObject.h"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
@@ -136,6 +136,7 @@ public:
|
|||||||
* @details
|
* @details
|
||||||
* Checks if timing is ok (must be ascending) and if all handlers were found.
|
* Checks if timing is ok (must be ascending) and if all handlers were found.
|
||||||
* @return
|
* @return
|
||||||
|
* - SLOT_LIST_EMPTY if the slot list is empty
|
||||||
*/
|
*/
|
||||||
ReturnValue_t checkSequence() const;
|
ReturnValue_t checkSequence() const;
|
||||||
|
|
||||||
@@ -147,6 +148,7 @@ public:
|
|||||||
* The general check will be continued for now if the custom check function
|
* The general check will be continued for now if the custom check function
|
||||||
* fails but a diagnostic debug output will be given.
|
* fails but a diagnostic debug output will be given.
|
||||||
* @param customCheckFunction
|
* @param customCheckFunction
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
void addCustomCheck(ReturnValue_t (*customCheckFunction)(const SlotList &));
|
void addCustomCheck(ReturnValue_t (*customCheckFunction)(const SlotList &));
|
||||||
|
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
#define FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_
|
#define FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_
|
||||||
|
|
||||||
#include "PeriodicTaskIF.h"
|
#include "PeriodicTaskIF.h"
|
||||||
#include "../objectmanager/ObjectManagerIF.h"
|
#include "fsfw/objectmanager/ObjectManagerIF.h"
|
||||||
|
#include "fsfw/returnvalues/FwClassIds.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Following the same principle as the base class IF.
|
* @brief Following the same principle as the base class IF.
|
||||||
@@ -12,6 +13,8 @@ class FixedTimeslotTaskIF : public PeriodicTaskIF {
|
|||||||
public:
|
public:
|
||||||
virtual ~FixedTimeslotTaskIF() {}
|
virtual ~FixedTimeslotTaskIF() {}
|
||||||
|
|
||||||
|
static constexpr ReturnValue_t SLOT_LIST_EMPTY = HasReturnvaluesIF::makeReturnCode(
|
||||||
|
CLASS_ID::FIXED_SLOT_TASK_IF, 0);
|
||||||
/**
|
/**
|
||||||
* Add an object with a slot time and the execution step to the task.
|
* Add an object with a slot time and the execution step to the task.
|
||||||
* The execution step will be passed to the object (e.g. as an operation
|
* The execution step will be passed to the object (e.g. as an operation
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
#ifndef FRAMEWORK_TASKS_TYPEDEF_H_
|
#ifndef FSFW_TASKS_TYPEDEF_H_
|
||||||
#define FRAMEWORK_TASKS_TYPEDEF_H_
|
#define FSFW_TASKS_TYPEDEF_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
typedef const char* TaskName;
|
typedef const char* TaskName;
|
||||||
typedef uint32_t TaskPriority;
|
typedef uint32_t TaskPriority;
|
||||||
@@ -7,4 +10,4 @@ typedef size_t TaskStackSize;
|
|||||||
typedef double TaskPeriod;
|
typedef double TaskPeriod;
|
||||||
typedef void (*TaskDeadlineMissedFunction)();
|
typedef void (*TaskDeadlineMissedFunction)();
|
||||||
|
|
||||||
#endif /* FRAMEWORK_TASKS_TYPEDEF_H_ */
|
#endif /* FSFW_TASKS_TYPEDEF_H_ */
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
SpacePacketBase::SpacePacketBase( const uint8_t* set_address ) {
|
SpacePacketBase::SpacePacketBase(const uint8_t* setAddress) {
|
||||||
this->data = (SpacePacketPointer*) set_address;
|
this->data = reinterpret_cast<SpacePacketPointer*>(const_cast<uint8_t*>(setAddress));
|
||||||
}
|
}
|
||||||
|
|
||||||
SpacePacketBase::~SpacePacketBase() {
|
SpacePacketBase::~SpacePacketBase() {
|
||||||
@@ -15,10 +15,21 @@ uint8_t SpacePacketBase::getPacketVersionNumber( void ) {
|
|||||||
return (this->data->header.packet_id_h & 0b11100000) >> 5;
|
return (this->data->header.packet_id_h & 0b11100000) >> 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
|
ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
|
||||||
bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
|
bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
|
||||||
|
if(data == nullptr) {
|
||||||
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "SpacePacketBase::initSpacePacketHeader: Data pointer is invalid"
|
||||||
|
<< std::endl;
|
||||||
|
#else
|
||||||
|
sif::printWarning("SpacePacketBase::initSpacePacketHeader: Data pointer is invalid!\n");
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
//reset header to zero:
|
//reset header to zero:
|
||||||
memset(data,0, sizeof(this->data->header) );
|
memset(data, 0, sizeof(this->data->header) );
|
||||||
//Set TC/TM bit.
|
//Set TC/TM bit.
|
||||||
data->header.packet_id_h = ((isTelecommand? 1 : 0)) << 4;
|
data->header.packet_id_h = ((isTelecommand? 1 : 0)) << 4;
|
||||||
//Set secondaryHeader bit
|
//Set secondaryHeader bit
|
||||||
@@ -27,7 +38,7 @@ void SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
|
|||||||
//Always initialize as standalone packets.
|
//Always initialize as standalone packets.
|
||||||
data->header.sequence_control_h = 0b11000000;
|
data->header.sequence_control_h = 0b11000000;
|
||||||
setPacketSequenceCount(sequenceCount);
|
setPacketSequenceCount(sequenceCount);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpacePacketBase::isTelecommand( void ) {
|
bool SpacePacketBase::isTelecommand( void ) {
|
||||||
@@ -54,6 +65,11 @@ void SpacePacketBase::setAPID( uint16_t new_apid ) {
|
|||||||
this->data->header.packet_id_l = ( new_apid & 0x00FF );
|
this->data->header.packet_id_l = ( new_apid & 0x00FF );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpacePacketBase::setSequenceFlags( uint8_t sequenceflags ) {
|
||||||
|
this->data->header.sequence_control_h &= 0x3F;
|
||||||
|
this->data->header.sequence_control_h |= sequenceflags << 6;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t SpacePacketBase::getPacketSequenceControl( void ) {
|
uint16_t SpacePacketBase::getPacketSequenceControl( void ) {
|
||||||
return ( (this->data->header.sequence_control_h) << 8 )
|
return ( (this->data->header.sequence_control_h) << 8 )
|
||||||
+ this->data->header.sequence_control_l;
|
+ this->data->header.sequence_control_l;
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
#define FSFW_TMTCPACKET_SPACEPACKETBASE_H_
|
#define FSFW_TMTCPACKET_SPACEPACKETBASE_H_
|
||||||
|
|
||||||
#include "ccsds_header.h"
|
#include "ccsds_header.h"
|
||||||
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +84,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool isTelecommand( void );
|
bool isTelecommand( void );
|
||||||
|
|
||||||
void initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader,
|
ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader,
|
||||||
uint16_t apid, uint16_t sequenceCount = 0);
|
uint16_t apid, uint16_t sequenceCount = 0);
|
||||||
/**
|
/**
|
||||||
* The CCSDS header provides a secondary header flag (the fifth-highest bit),
|
* The CCSDS header provides a secondary header flag (the fifth-highest bit),
|
||||||
@@ -109,6 +111,13 @@ public:
|
|||||||
* ignored.
|
* ignored.
|
||||||
*/
|
*/
|
||||||
void setAPID( uint16_t setAPID );
|
void setAPID( uint16_t setAPID );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the sequence flags of a packet, which are bit 17 and 18 in the space packet header.
|
||||||
|
* @param The sequence flags to set
|
||||||
|
*/
|
||||||
|
void setSequenceFlags( uint8_t sequenceflags );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the CCSDS packet sequence control field, which are the third and
|
* Returns the CCSDS packet sequence control field, which are the third and
|
||||||
* the fourth byte of the CCSDS primary header.
|
* the fourth byte of the CCSDS primary header.
|
||||||
|
@@ -53,11 +53,14 @@ uint8_t* TmPacketPusC::getPacketTimeRaw() const{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
|
ReturnValue_t TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
|
||||||
uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId,
|
uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId,
|
||||||
uint8_t timeRefField) {
|
uint8_t timeRefField) {
|
||||||
//Set primary header:
|
//Set primary header:
|
||||||
initSpacePacketHeader(false, true, apid);
|
ReturnValue_t result = initSpacePacketHeader(false, true, apid);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
//Set data Field Header:
|
//Set data Field Header:
|
||||||
//First, set to zero.
|
//First, set to zero.
|
||||||
memset(&tmData->dataField, 0, sizeof(tmData->dataField));
|
memset(&tmData->dataField, 0, sizeof(tmData->dataField));
|
||||||
@@ -76,6 +79,7 @@ void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
|
|||||||
timeStamper->addTimeStamp(tmData->dataField.time,
|
timeStamper->addTimeStamp(tmData->dataField.time,
|
||||||
sizeof(tmData->dataField.time));
|
sizeof(tmData->dataField.time));
|
||||||
}
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TmPacketPusC::setSourceDataSize(uint16_t size) {
|
void TmPacketPusC::setSourceDataSize(uint16_t size) {
|
||||||
|
@@ -100,7 +100,7 @@ protected:
|
|||||||
* @param subservice PUS Subservice
|
* @param subservice PUS Subservice
|
||||||
* @param packetSubcounter Additional subcounter used.
|
* @param packetSubcounter Additional subcounter used.
|
||||||
*/
|
*/
|
||||||
void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
|
ReturnValue_t initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
|
||||||
uint16_t packetSubcounter, uint16_t destinationId = 0, uint8_t timeRefField = 0);
|
uint16_t packetSubcounter, uint16_t destinationId = 0, uint8_t timeRefField = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -43,27 +43,55 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t sourceDataSize = 0;
|
size_t sourceDataSize = 0;
|
||||||
if (content != NULL) {
|
if (content != nullptr) {
|
||||||
sourceDataSize += content->getSerializedSize();
|
sourceDataSize += content->getSerializedSize();
|
||||||
}
|
}
|
||||||
if (header != NULL) {
|
if (header != nullptr) {
|
||||||
sourceDataSize += header->getSerializedSize();
|
sourceDataSize += header->getSerializedSize();
|
||||||
}
|
}
|
||||||
uint8_t *p_data = NULL;
|
uint8_t *pData = nullptr;
|
||||||
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
|
size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
|
||||||
(getPacketMinimumSize() + sourceDataSize), &p_data);
|
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData);
|
||||||
if (returnValue != store->RETURN_OK) {
|
if (returnValue != store->RETURN_OK) {
|
||||||
|
#if FSFW_VERBOSE_LEVEL >= 1
|
||||||
|
switch(returnValue) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
case(StorageManagerIF::DATA_STORAGE_FULL): {
|
||||||
|
sif::warning << "TmPacketStoredPusC::TmPacketStoredPusC: Store full for packet with "
|
||||||
|
"size " << sizeToReserve << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(StorageManagerIF::DATA_TOO_LARGE): {
|
||||||
|
sif::warning << "TmPacketStoredPusC::TmPacketStoredPusC: Data with size " <<
|
||||||
|
sizeToReserve << " too large" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
case(StorageManagerIF::DATA_STORAGE_FULL): {
|
||||||
|
sif::printWarning("TmPacketStoredPusC::TmPacketStoredPusC: Store full for packet with "
|
||||||
|
"size %d\n", sizeToReserve);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(StorageManagerIF::DATA_TOO_LARGE): {
|
||||||
|
sif::printWarning("TmPacketStoredPusC::TmPacketStoredPusC: Data with size "
|
||||||
|
"%d too large\n", sizeToReserve);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
TmPacketStoredBase::checkAndReportLostTm();
|
TmPacketStoredBase::checkAndReportLostTm();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
setData(p_data);
|
setData(pData);
|
||||||
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
|
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
|
||||||
uint8_t *putDataHere = getSourceData();
|
uint8_t *putDataHere = getSourceData();
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
if (header != NULL) {
|
if (header != nullptr) {
|
||||||
header->serialize(&putDataHere, &size, sourceDataSize,
|
header->serialize(&putDataHere, &size, sourceDataSize,
|
||||||
SerializeIF::Endianness::BIG);
|
SerializeIF::Endianness::BIG);
|
||||||
}
|
}
|
||||||
if (content != NULL) {
|
if (content != nullptr) {
|
||||||
content->serialize(&putDataHere, &size, sourceDataSize,
|
content->serialize(&putDataHere, &size, sourceDataSize,
|
||||||
SerializeIF::Endianness::BIG);
|
SerializeIF::Endianness::BIG);
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ class TmTcBridge : public AcceptsTelemetryIF,
|
|||||||
public:
|
public:
|
||||||
static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20;
|
static constexpr uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20;
|
||||||
static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15;
|
static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15;
|
||||||
static constexpr uint8_t LIMIT_DOWNLINK_PACKETS_STORED = 20;
|
static constexpr uint8_t LIMIT_DOWNLINK_PACKETS_STORED = 200;
|
||||||
|
|
||||||
static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5;
|
static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5;
|
||||||
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
|
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
|
||||||
|
Reference in New Issue
Block a user