eive-obsw/linux/boardtest/LibgpiodTest.cpp

100 lines
3.3 KiB
C++
Raw Normal View History

#include "LibgpiodTest.h"
2021-02-14 12:23:29 +01:00
#include <fsfwconfig/devices/gpioIds.h>
2021-02-14 09:25:40 +01:00
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include <fsfw/objectmanager/ObjectManagerIF.h>
2021-02-22 18:46:45 +01:00
#include <fsfw/tasks/TaskFactory.h>
2021-02-14 09:25:40 +01:00
2021-02-14 12:23:29 +01:00
LibgpiodTest::LibgpiodTest(object_id_t objectId, object_id_t gpioIfobjectId,
GpioCookie* gpioCookie):
2021-02-14 09:25:40 +01:00
TestTask(objectId) {
gpioInterface = objectManager->get<GpioIF>(gpioIfobjectId);
if (gpioInterface == nullptr) {
sif::error << "LibgpiodTest::LibgpiodTest: Invalid Gpio interface." << std::endl;
2021-02-14 09:25:40 +01:00
}
2021-02-23 13:24:05 +01:00
gpioInterface->addGpios(gpioCookie);
2021-02-22 17:36:44 +01:00
testCase = TestCases::LOOPBACK;
2021-02-14 09:25:40 +01:00
}
LibgpiodTest::~LibgpiodTest() {
2021-02-14 09:25:40 +01:00
}
ReturnValue_t LibgpiodTest::performPeriodicAction() {
2021-02-14 09:25:40 +01:00
int gpioState;
ReturnValue_t result;
2021-02-22 12:40:12 +01:00
switch(testCase) {
2021-02-22 12:57:41 +01:00
case(TestCases::READ): {
2021-02-22 17:36:44 +01:00
result = gpioInterface->readGpio(gpioIds::TEST_ID_0, &gpioState);
2021-02-22 12:40:12 +01:00
if (result != RETURN_OK) {
sif::debug << "LibgpiodTest::performPeriodicAction: Failed to read gpio "
<< std::endl;
return RETURN_FAILED;
}
else {
sif::debug << "LibgpiodTest::performPeriodicAction: MIO 0 state = " << gpioState
<< std::endl;
}
break;
}
2021-02-22 12:57:41 +01:00
case(TestCases::LOOPBACK): {
2021-02-22 17:36:44 +01:00
break;
2021-02-14 09:25:40 +01:00
}
}
2021-02-22 12:40:12 +01:00
2021-02-14 09:25:40 +01:00
return RETURN_OK;
}
2021-02-22 17:36:44 +01:00
ReturnValue_t LibgpiodTest::performOneShotAction() {
int gpioState;
ReturnValue_t result;
switch(testCase) {
case(TestCases::READ): {
break;
}
case(TestCases::LOOPBACK): {
result = gpioInterface->pullHigh(gpioIds::TEST_ID_0);
if(result == HasReturnvaluesIF::RETURN_OK) {
2021-02-23 14:44:16 +01:00
sif::info << "LibgpiodTest::performOneShotAction: "
2021-02-22 17:36:44 +01:00
"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;
}
result = gpioInterface->readGpio(gpioIds::TEST_ID_1, &gpioState);
if(result == HasReturnvaluesIF::RETURN_OK and gpioState == 1) {
2021-02-23 14:44:16 +01:00
sif::info << "LibgpiodTest::performOneShotAction: "
2021-02-22 17:36:44 +01:00
"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-02-22 18:46:45 +01:00
result = gpioInterface->pullLow(gpioIds::TEST_ID_0);
if(result == HasReturnvaluesIF::RETURN_OK) {
2021-02-23 14:44:16 +01:00
sif::info << "LibgpiodTest::performOneShotAction: "
2021-02-22 18:46:45 +01:00
"GPIO pulled low successfully for loopback test" << std::endl;
}
result = gpioInterface->readGpio(gpioIds::TEST_ID_1, &gpioState);
if(result == HasReturnvaluesIF::RETURN_OK and gpioState == 0) {
2021-02-23 14:44:16 +01:00
sif::info << "LibgpiodTest::performOneShotAction: "
2021-02-22 18:46:45 +01:00
"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;
}
2021-02-22 17:36:44 +01:00
break;
}
}
return HasReturnvaluesIF::RETURN_OK;
}