applied auto-formatter
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
This commit is contained in:
@ -1,26 +1,27 @@
|
||||
#include "I2cTestClass.h"
|
||||
#include <fsfw_hal/linux/UnixFileGuard.h>
|
||||
#include "fsfw/serviceinterface.h"
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
#include <fsfw_hal/linux/UnixFileGuard.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
#include "fsfw/serviceinterface.h"
|
||||
|
||||
I2cTestClass::I2cTestClass(object_id_t objectId, std::string i2cdev)
|
||||
: TestTask(objectId), i2cdev(i2cdev) {
|
||||
: TestTask(objectId), i2cdev(i2cdev) {
|
||||
mode = TestModes::BPX_BATTERY;
|
||||
}
|
||||
|
||||
ReturnValue_t I2cTestClass::initialize() {
|
||||
if(mode == TestModes::BPX_BATTERY) {
|
||||
if (mode == TestModes::BPX_BATTERY) {
|
||||
battInit();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t I2cTestClass::performPeriodicAction() {
|
||||
if(mode == TestModes::BPX_BATTERY) {
|
||||
if (mode == TestModes::BPX_BATTERY) {
|
||||
battPeriodic();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -33,25 +34,25 @@ void I2cTestClass::battInit() {
|
||||
sif::error << "Opening I2C device" << i2cdev << " failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
if(ioctl(bpxInfo.fd, I2C_SLAVE, bpxInfo.addr) < 0) {
|
||||
if (ioctl(bpxInfo.fd, I2C_SLAVE, bpxInfo.addr) < 0) {
|
||||
sif::error << "Failed to acquire bus access and/or talk to slave" << std::endl;
|
||||
}
|
||||
cmdBuf[0] = BpxBattery::PORT_PING;
|
||||
cmdBuf[1] = 0x42;
|
||||
sendLen = 2;
|
||||
ReturnValue_t result = i2cWrite(bpxInfo.fd, cmdBuf.data(), sendLen);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
// Receive back port, error byte and ping reply
|
||||
recvLen = 3;
|
||||
result = i2cRead(bpxInfo.fd, replyBuf.data(), recvLen);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
sif::info << "Ping reply:" << std::endl;
|
||||
arrayprinter::print(replyBuf.data(), recvLen);
|
||||
if(replyBuf[2] != 0x42) {
|
||||
if (replyBuf[2] != 0x42) {
|
||||
sif::warning << "Received ping reply not expected value 0x42" << std::endl;
|
||||
}
|
||||
}
|
||||
@ -62,19 +63,19 @@ void I2cTestClass::battPeriodic() {
|
||||
sif::error << "Opening I2C device" << i2cdev << " failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
if(ioctl(bpxInfo.fd, I2C_SLAVE, bpxInfo.addr) < 0) {
|
||||
if (ioctl(bpxInfo.fd, I2C_SLAVE, bpxInfo.addr) < 0) {
|
||||
sif::error << "Failed to acquire bus access and/or talk to slave" << std::endl;
|
||||
}
|
||||
cmdBuf[0] = BpxBattery::PORT_GET_HK;
|
||||
sendLen = 1;
|
||||
ReturnValue_t result = i2cWrite(bpxInfo.fd, cmdBuf.data(), sendLen);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
// Receive back HK set
|
||||
recvLen = 23;
|
||||
result = i2cRead(bpxInfo.fd, replyBuf.data(), recvLen);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
sif::info << "HK reply:" << std::endl;
|
||||
@ -91,7 +92,7 @@ ReturnValue_t I2cTestClass::i2cWrite(int fd, uint8_t* data, size_t len) {
|
||||
}
|
||||
|
||||
ReturnValue_t I2cTestClass::i2cRead(int fd, uint8_t* data, size_t len) {
|
||||
if( read (fd, data, len) != static_cast<ssize_t>(len)) {
|
||||
if (read(fd, data, len) != static_cast<ssize_t>(len)) {
|
||||
sif::error << "Failed to read from I2C bus" << std::endl;
|
||||
sif::error << "Error " << errno << ": " << strerror(errno) << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
|
@ -3,9 +3,10 @@
|
||||
|
||||
#include <test/testtasks/TestTask.h>
|
||||
|
||||
#include "mission/devices/devicedefinitions/BpxBatteryDefinitions.h"
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include "mission/devices/devicedefinitions/BpxBatteryDefinitions.h"
|
||||
|
||||
class I2cTestClass : public TestTask {
|
||||
public:
|
||||
@ -15,10 +16,7 @@ class I2cTestClass : public TestTask {
|
||||
ReturnValue_t performPeriodicAction() override;
|
||||
|
||||
private:
|
||||
enum TestModes {
|
||||
NONE,
|
||||
BPX_BATTERY
|
||||
};
|
||||
enum TestModes { NONE, BPX_BATTERY };
|
||||
struct I2cInfo {
|
||||
int addr = 0;
|
||||
int fd = 0;
|
||||
@ -28,7 +26,7 @@ class I2cTestClass : public TestTask {
|
||||
void battInit();
|
||||
void battPeriodic();
|
||||
|
||||
I2cInfo bpxInfo = { .addr = 0x07, .fd = 0 };
|
||||
I2cInfo bpxInfo = {.addr = 0x07, .fd = 0};
|
||||
std::string i2cdev;
|
||||
size_t sendLen = 0;
|
||||
size_t recvLen = 0;
|
||||
|
@ -24,12 +24,10 @@ ReturnValue_t UartTestClass::initialize() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartTestClass::performOneShotAction() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
ReturnValue_t UartTestClass::performOneShotAction() { return HasReturnvaluesIF::RETURN_OK; }
|
||||
|
||||
ReturnValue_t UartTestClass::performPeriodicAction() {
|
||||
if(mode == TestModes::GPS) {
|
||||
if (mode == TestModes::GPS) {
|
||||
gpsPeriodic();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
Reference in New Issue
Block a user