2021-02-14 11:03:53 +01:00
|
|
|
#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-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) {
|
2021-02-14 11:03:53 +01:00
|
|
|
sif::error << "LibgpiodTest::LibgpiodTest: Invalid Gpio interface." << std::endl;
|
2021-02-14 09:25:40 +01:00
|
|
|
}
|
|
|
|
gpioInterface->initialize(gpioCookie);
|
2021-02-22 17:36:44 +01:00
|
|
|
testCase = TestCases::LOOPBACK;
|
2021-02-14 09:25:40 +01:00
|
|
|
}
|
|
|
|
|
2021-02-14 11:03:53 +01:00
|
|
|
LibgpiodTest::~LibgpiodTest() {
|
2021-02-14 09:25:40 +01:00
|
|
|
}
|
|
|
|
|
2021-02-14 11:03:53 +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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
result = gpioInterface->readGpio(gpioIds::TEST_ID_1, &gpioState);
|
|
|
|
if(result == HasReturnvaluesIF::RETURN_OK and gpioState == 1) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|