eive-obsw/linux/boardtest/LibgpiodTest.cpp

128 lines
4.5 KiB
C++
Raw Normal View History

2021-03-04 18:29:28 +01:00
#include "LibgpiodTest.h"
2021-06-08 16:45:25 +02:00
#include <fsfw/objectmanager/ObjectManager.h>
2022-01-17 15:58:27 +01:00
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
2021-03-04 18:29:28 +01:00
#include <fsfw/tasks/TaskFactory.h>
2022-01-17 15:58:27 +01:00
#include "devices/gpioIds.h"
2021-03-04 18:29:28 +01:00
2022-01-17 15:58:27 +01:00
LibgpiodTest::LibgpiodTest(object_id_t objectId, object_id_t gpioIfobjectId, GpioCookie* gpioCookie)
: TestTask(objectId) {
gpioInterface = ObjectManager::instance()->get<GpioIF>(gpioIfobjectId);
if (gpioInterface == nullptr) {
sif::error << "LibgpiodTest::LibgpiodTest: Invalid Gpio interface." << std::endl;
}
gpioInterface->addGpios(gpioCookie);
testCase = TestCases::BLINK;
2021-03-04 18:29:28 +01:00
}
2022-01-17 15:58:27 +01:00
LibgpiodTest::~LibgpiodTest() {}
2021-03-04 18:29:28 +01:00
ReturnValue_t LibgpiodTest::performPeriodicAction() {
2022-05-04 14:08:27 +02:00
gpio::Levels gpioState;
2022-01-17 15:58:27 +01:00
ReturnValue_t result;
2021-03-04 18:29:28 +01:00
2022-01-17 15:58:27 +01:00
switch (testCase) {
case (TestCases::READ): {
2022-05-04 14:08:27 +02:00
result = gpioInterface->readGpio(gpioIds::TEST_ID_0, gpioState);
2022-01-17 15:58:27 +01:00
if (result != RETURN_OK) {
sif::warning << "LibgpiodTest::performPeriodicAction: Failed to read gpio " << std::endl;
return RETURN_FAILED;
} else {
2022-05-04 14:08:27 +02:00
sif::debug << "LibgpiodTest::performPeriodicAction: MIO 0 state = " <<
static_cast<int>(gpioState) << std::endl;
2022-01-17 15:58:27 +01:00
}
break;
2021-03-04 18:29:28 +01:00
}
2022-01-17 15:58:27 +01:00
case (TestCases::LOOPBACK): {
break;
2021-03-04 18:29:28 +01:00
}
2022-01-17 15:58:27 +01:00
case (TestCases::BLINK): {
2022-05-04 14:08:27 +02:00
result = gpioInterface->readGpio(gpioIds::TEST_ID_0, gpioState);
2022-01-17 15:58:27 +01:00
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "LibgpiodTest::performPeriodicAction: Failed to read gpio " << std::endl;
return RETURN_FAILED;
}
2022-05-04 14:08:27 +02:00
if (gpioState == gpio::Levels::HIGH) {
2022-01-17 15:58:27 +01:00
result = gpioInterface->pullLow(gpioIds::TEST_ID_0);
2021-09-20 16:30:50 +02:00
if (result != HasReturnvaluesIF::RETURN_OK) {
2022-01-17 15:58:27 +01:00
sif::warning << "LibgpiodTest::performPeriodicAction: Could not pull GPIO low!"
<< std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
2021-09-20 16:30:50 +02:00
}
2022-05-04 14:08:27 +02:00
} else if (gpioState == gpio::Levels::LOW) {
2022-01-17 15:58:27 +01:00
result = gpioInterface->pullHigh(gpioIds::TEST_ID_0);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "LibgpiodTest::performPeriodicAction: Could not pull GPIO high!"
<< std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
2021-09-20 16:30:50 +02:00
}
2022-01-17 15:58:27 +01:00
} else {
sif::warning << "LibgpiodTest::performPeriodicAction: Invalid GPIO state" << std::endl;
}
2021-09-20 16:30:50 +02:00
2022-01-17 15:58:27 +01:00
break;
2021-09-20 16:30:50 +02:00
}
default:
2022-01-17 15:58:27 +01:00
sif::debug << "LibgpiodTest::performPeriodicAction: Invalid test case" << std::endl;
break;
}
2021-03-04 18:29:28 +01:00
2022-01-17 15:58:27 +01:00
return RETURN_OK;
2021-03-04 18:29:28 +01:00
}
ReturnValue_t LibgpiodTest::performOneShotAction() {
2022-05-04 14:08:27 +02:00
gpio::Levels gpioState;
2022-01-17 15:58:27 +01:00
ReturnValue_t result;
2021-03-04 18:29:28 +01:00
2022-01-17 15:58:27 +01:00
switch (testCase) {
case (TestCases::READ): {
break;
2021-03-04 18:29:28 +01:00
}
2022-01-17 15:58:27 +01:00
case (TestCases::BLINK): {
break;
2021-09-20 16:30:50 +02:00
}
2022-01-17 15:58:27 +01:00
case (TestCases::LOOPBACK): {
result = gpioInterface->pullHigh(gpioIds::TEST_ID_0);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "LibgpiodTest::performOneShotAction: "
"GPIO pulled high successfully for loopback test"
<< std::endl;
} else {
sif::warning << "LibgpiodTest::performOneShotAction: Could not pull GPIO high!"
<< std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
2022-05-04 14:08:27 +02:00
result = gpioInterface->readGpio(gpioIds::TEST_ID_1, gpioState);
if (result == HasReturnvaluesIF::RETURN_OK and gpioState == gpio::Levels::HIGH) {
2022-01-17 15:58:27 +01:00
sif::info << "LibgpiodTest::performOneShotAction: "
"GPIO state read successfully and is high"
<< std::endl;
} else {
sif::warning << "LibgpiodTest::performOneShotAction: GPIO read and is not high!"
<< std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
2021-03-04 18:29:28 +01:00
2022-01-17 15:58:27 +01:00
result = gpioInterface->pullLow(gpioIds::TEST_ID_0);
if (result == HasReturnvaluesIF::RETURN_OK) {
sif::info << "LibgpiodTest::performOneShotAction: "
"GPIO pulled low successfully for loopback test"
<< std::endl;
}
2022-05-04 14:08:27 +02:00
result = gpioInterface->readGpio(gpioIds::TEST_ID_1, gpioState);
if (result == HasReturnvaluesIF::RETURN_OK and gpioState == gpio::Levels::LOW) {
2022-01-17 15:58:27 +01:00
sif::info << "LibgpiodTest::performOneShotAction: "
"GPIO state read successfully and is low"
<< std::endl;
} else {
sif::warning << "LibgpiodTest::performOneShotAction: GPIO read and is not low!"
<< std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
break;
2021-03-04 18:29:28 +01:00
}
2022-01-17 15:58:27 +01:00
}
return HasReturnvaluesIF::RETURN_OK;
2021-03-04 18:29:28 +01:00
}