bpx handler now working
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,5 +1,100 @@
|
||||
#include <linux/boardtest/I2cTestClass.h>
|
||||
#include "I2cTestClass.h"
|
||||
#include <fsfw_hal/linux/UnixFileGuard.h>
|
||||
#include "fsfw/serviceinterface.h"
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
|
||||
I2cTestClass::I2cTestClass(object_id_t objectId) : TestTask(objectId) {}
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
|
||||
ReturnValue_t I2cTestClass::performPeriodicAction() { return HasReturnvaluesIF::RETURN_OK; }
|
||||
I2cTestClass::I2cTestClass(object_id_t objectId, std::string i2cdev)
|
||||
: TestTask(objectId), i2cdev(i2cdev) {
|
||||
mode = TestModes::BPX_BATTERY;
|
||||
}
|
||||
|
||||
ReturnValue_t I2cTestClass::initialize() {
|
||||
if(mode == TestModes::BPX_BATTERY) {
|
||||
battInit();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t I2cTestClass::performPeriodicAction() {
|
||||
if(mode == TestModes::BPX_BATTERY) {
|
||||
battPeriodic();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void I2cTestClass::battInit() {
|
||||
sif::info << "I2cTestClass: BPX Initialization" << std::endl;
|
||||
UnixFileGuard fileHelper(i2cdev, &bpxInfo.fd, O_RDWR, "I2cTestClass::sendMessage");
|
||||
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "Opening I2C device" << i2cdev << " failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
// Receive back port, error byte and ping reply
|
||||
recvLen = 3;
|
||||
result = i2cRead(bpxInfo.fd, replyBuf.data(), recvLen);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
sif::info << "Ping reply:" << std::endl;
|
||||
arrayprinter::print(replyBuf.data(), recvLen);
|
||||
if(replyBuf[2] != 0x42) {
|
||||
sif::warning << "Received ping reply not expected value 0x42" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void I2cTestClass::battPeriodic() {
|
||||
UnixFileGuard fileHelper(i2cdev, &bpxInfo.fd, O_RDWR, "I2cTestClass::sendMessage");
|
||||
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "Opening I2C device" << i2cdev << " failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
// Receive back HK set
|
||||
recvLen = 23;
|
||||
result = i2cRead(bpxInfo.fd, replyBuf.data(), recvLen);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
sif::info << "HK reply:" << std::endl;
|
||||
arrayprinter::print(replyBuf.data(), recvLen);
|
||||
}
|
||||
|
||||
ReturnValue_t I2cTestClass::i2cWrite(int fd, uint8_t* data, size_t len) {
|
||||
if (write(fd, data, len) != static_cast<ssize_t>(len)) {
|
||||
sif::error << "Failed to write to I2C bus" << std::endl;
|
||||
sif::error << "Error " << errno << ": " << strerror(errno) << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t I2cTestClass::i2cRead(int fd, uint8_t* data, size_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;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -3,13 +3,40 @@
|
||||
|
||||
#include <test/testtasks/TestTask.h>
|
||||
|
||||
#include "mission/devices/devicedefinitions/BpxBatteryDefinitions.h"
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
class I2cTestClass : public TestTask {
|
||||
public:
|
||||
I2cTestClass(object_id_t objectId);
|
||||
I2cTestClass(object_id_t objectId, std::string i2cdev);
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
ReturnValue_t performPeriodicAction() override;
|
||||
|
||||
private:
|
||||
enum TestModes {
|
||||
NONE,
|
||||
BPX_BATTERY
|
||||
};
|
||||
struct I2cInfo {
|
||||
int addr = 0;
|
||||
int fd = 0;
|
||||
};
|
||||
|
||||
TestModes mode = TestModes::NONE;
|
||||
void battInit();
|
||||
void battPeriodic();
|
||||
|
||||
I2cInfo bpxInfo = { .addr = 0x07, .fd = 0 };
|
||||
std::string i2cdev;
|
||||
size_t sendLen = 0;
|
||||
size_t recvLen = 0;
|
||||
std::array<uint8_t, 64> cmdBuf = {};
|
||||
std::array<uint8_t, 64> replyBuf = {};
|
||||
|
||||
ReturnValue_t i2cWrite(int fd, uint8_t* data, size_t len);
|
||||
ReturnValue_t i2cRead(int fd, uint8_t* data, size_t len);
|
||||
};
|
||||
|
||||
#endif /* LINUX_BOARDTEST_I2CTESTCLASS_H_ */
|
||||
|
@ -17,6 +17,25 @@
|
||||
UartTestClass::UartTestClass(object_id_t objectId) : TestTask(objectId) {}
|
||||
|
||||
ReturnValue_t UartTestClass::initialize() {
|
||||
if (mode == TestModes::GPS) {
|
||||
gpsInit();
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartTestClass::performOneShotAction() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartTestClass::performPeriodicAction() {
|
||||
if(mode == TestModes::GPS) {
|
||||
gpsPeriodic();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void UartTestClass::gpsInit() {
|
||||
#if RPI_TEST_GPS_DEVICE == 1
|
||||
int result = lwgps_init(&gpsData);
|
||||
if (result == 0) {
|
||||
@ -62,16 +81,9 @@ ReturnValue_t UartTestClass::initialize() {
|
||||
// Flush received and unread data. Those are old NMEA strings which are not relevant anymore
|
||||
tcflush(serialPort, TCIFLUSH);
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartTestClass::performOneShotAction() {
|
||||
#if RPI_TEST_GPS_DEVICE == 1
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t UartTestClass::performPeriodicAction() {
|
||||
void UartTestClass::gpsPeriodic() {
|
||||
#if RPI_TEST_GPS_DEVICE == 1
|
||||
int bytesRead = 0;
|
||||
do {
|
||||
@ -107,5 +119,4 @@ ReturnValue_t UartTestClass::performPeriodicAction() {
|
||||
}
|
||||
} while (bytesRead > 0);
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -17,6 +17,15 @@ class UartTestClass : public TestTask {
|
||||
ReturnValue_t performPeriodicAction() override;
|
||||
|
||||
private:
|
||||
enum TestModes {
|
||||
GPS,
|
||||
// Solar Cell Experiment
|
||||
SCE
|
||||
};
|
||||
|
||||
void gpsInit();
|
||||
void gpsPeriodic();
|
||||
TestModes mode = TestModes::GPS;
|
||||
lwgps_t gpsData = {};
|
||||
struct termios tty = {};
|
||||
int serialPort = 0;
|
||||
|
Reference in New Issue
Block a user