retval replacements
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-08-29 16:05:05 +02:00
parent aa0da618ca
commit 86337d8f47
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
7 changed files with 57 additions and 58 deletions

View File

@ -25,6 +25,8 @@
#define RPI_TEST_GPS_HANDLER 0
#endif
using namespace returnvalue;
UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader)
: TestTask(objectId), reader(reader) {
mode = TestModes::SCEX;
@ -163,7 +165,7 @@ void UartTestClass::scexInit() {
uartCookie = new UartCookie(this->getObjectId(), devname, UartBaudRate::RATE_57600, 4096);
reader->setDebugMode(false);
ReturnValue_t result = reader->initializeInterface(uartCookie);
if (result != HasReturnvaluesIF::RETURN_OK) {
if (result != OK) {
sif::warning << "UartTestClass::scexInit: Initializing SCEX reader "
"UART IF failed"
<< std::endl;
@ -306,7 +308,7 @@ void UartTestClass::scexSimpleInit() {
void UartTestClass::scexSimplePeriodic() {
using namespace scex;
ReturnValue_t result = RETURN_OK;
ReturnValue_t result = OK;
if (not cmdSent) {
// Flush received and unread data
tcflush(serialPort, TCIFLUSH);
@ -315,7 +317,7 @@ void UartTestClass::scexSimplePeriodic() {
sif::info << "UartTestClass::scexSimplePeriodic: Sending command to SCEX" << std::endl;
prepareScexCmd(currCmd, false, tmpCmdBuf, &len);
result = dleEncoder.encode(tmpCmdBuf, len, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
if (result != HasReturnvaluesIF::RETURN_OK) {
if (result != OK) {
sif::warning << "UartTestClass::scexSimplePeriodic: Encoding failed" << std::endl;
return;
}
@ -368,17 +370,11 @@ int UartTestClass::prepareScexCmd(scex::Cmds cmd, bool tempCheck, uint8_t* cmdBu
cmdBuf[1] = 1;
cmdBuf[2] = 1;
uint16_t userDataLen = 0;
tmpCmdBuf[3] = (userDataLen >> 8) & 0xff;
tmpCmdBuf[4] = userDataLen & 0xff;
uint16_t crc = CRC::crc16ccitt(tmpCmdBuf.data(), 5);
tmpCmdBuf[5] = (crc >> 8) & 0xff;
tmpCmdBuf[6] = crc & 0xff;
ReturnValue_t result =
dleEncoder.encode(tmpCmdBuf.data(), 7, cmdBuf.data(), cmdBuf.size(), &encodedLen, true);
if (result != returnvalue::OK) {
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
return -1;
}
cmdBuf[3] = (userDataLen >> 8) & 0xff;
cmdBuf[4] = userDataLen & 0xff;
uint16_t crc = CRC::crc16ccitt(cmdBuf, 5);
cmdBuf[5] = (crc >> 8) & 0xff;
cmdBuf[6] = crc & 0xff;
return 0;
}

View File

@ -67,7 +67,7 @@ class UartTestClass : public TestTask {
std::array<uint8_t, 64> cmdBuf = {};
std::array<uint8_t, 4096> recBuf = {};
ScexDleParser* dleParser;
scex::Cmds cmdHelper;
scex::Cmds cmdHelper = scex::Cmds::INVALID;
uint8_t recvCnt = 0;
};

View File

@ -4,11 +4,13 @@
#include "fsfw/serviceinterface.h"
using namespace returnvalue;
ScexHelper::ScexHelper() {}
ReturnValue_t ScexHelper::serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const {
return RETURN_FAILED;
return FAILED;
}
size_t ScexHelper::getSerializedSize() const { return totalPacketLen; }
@ -16,7 +18,7 @@ size_t ScexHelper::getSerializedSize() const { return totalPacketLen; }
ReturnValue_t ScexHelper::deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
if (buffer == nullptr or size == nullptr) {
return RETURN_FAILED;
return FAILED;
}
if (*size < 7) {
return STREAM_TOO_SHORT;
@ -45,7 +47,7 @@ ReturnValue_t ScexHelper::deSerialize(const uint8_t** buffer, size_t* size,
if (CRC::crc16ccitt(start, totalPacketLen) != 0) {
return INVALID_CRC;
}
return RETURN_OK;
return OK;
}
scex::Cmds ScexHelper::getCmd() const { return cmd; }

View File

@ -7,12 +7,10 @@
#include <cstdint>
#include <fstream>
#include <iostream>
// ScexHelper helper;
// helper.deSerialize(data, ...);
// sif::info << helper << std::endl;
class ScexHelper : public HasReturnvaluesIF, public SerializeIF {
class ScexHelper : public SerializeIF {
public:
static const ReturnValue_t INVALID_CRC = HasReturnvaluesIF::makeReturnCode(0, 2);
static const ReturnValue_t INVALID_CRC = returnvalue::makeCode(0, 2);
ScexHelper();
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,

View File

@ -14,6 +14,8 @@
#include "OBSWConfig.h"
using namespace returnvalue;
ScexUartReader::ScexUartReader(object_id_t objectId)
: SystemObject(objectId),
decodeRingBuf(4096, true),
@ -58,7 +60,7 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
sif::info << "Received " << bytesRead
<< " bytes from the Solar Cell Experiment:" << std::endl;
}
if (result != HasReturnvaluesIF::RETURN_OK) {
if (result != OK) {
sif::warning << "ScexUartReader::performOperation: Passing data to DLE parser failed"
<< std::endl;
}
@ -67,13 +69,13 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
// task block comes here
sif::info << "task was stopped" << std::endl;
}
return RETURN_OK;
return OK;
}
ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
UartCookie *uartCookie = dynamic_cast<UartCookie *>(cookie);
if (uartCookie == nullptr) {
return RETURN_FAILED;
return FAILED;
}
std::string devname = uartCookie->getDeviceFile();
/* Get file descriptor */
@ -81,7 +83,7 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
if (serialPort < 0) {
sif::warning << "ScexUartReader::initializeInterface: open call failed with error [" << errno
<< ", " << strerror(errno) << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
return FAILED;
}
// Setting up UART parameters
tty.c_cflag &= ~PARENB; // Clear parity bit
@ -111,46 +113,46 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
}
// Flush received and unread data
tcflush(serialPort, TCIOFLUSH);
return RETURN_OK;
return OK;
}
ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendData,
size_t sendLen) {
if (sendData == nullptr or sendLen == 0) {
return HasReturnvaluesIF::RETURN_FAILED;
return FAILED;
}
lock->lockMutex();
if (state == States::NOT_READY or state == States::RUNNING) {
lock->unlockMutex();
return HasReturnvaluesIF::RETURN_FAILED;
return FAILED;
}
state = States::RUNNING;
lock->unlockMutex();
size_t encodedLen = 0;
ReturnValue_t result =
dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true);
if (result != HasReturnvaluesIF::RETURN_OK) {
if (result != OK) {
sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl;
return RETURN_FAILED;
return FAILED;
}
arrayprinter::print(cmdbuf.data(), encodedLen);
size_t bytesWritten = write(serialPort, cmdbuf.data(), encodedLen);
if (bytesWritten != encodedLen) {
sif::warning << "ScexUartReader::sendMessage: Sending ping command to solar experiment failed"
<< std::endl;
return RETURN_FAILED;
return FAILED;
}
result = semaphore->release();
if (result != HasReturnvaluesIF::RETURN_OK) {
if (result != OK) {
std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl;
}
return RETURN_OK;
return OK;
}
ReturnValue_t ScexUartReader::getSendSuccess(CookieIF *cookie) { return RETURN_OK; }
ReturnValue_t ScexUartReader::getSendSuccess(CookieIF *cookie) { return OK; }
ReturnValue_t ScexUartReader::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
return RETURN_OK;
return OK;
}
void ScexUartReader::setDebugMode(bool enable) { this->debugMode = enable; }
@ -158,10 +160,10 @@ void ScexUartReader::setDebugMode(bool enable) { this->debugMode = enable; }
ReturnValue_t ScexUartReader::finish() {
MutexGuard mg(lock);
if (state == States::IDLE) {
return HasReturnvaluesIF::RETURN_FAILED;
return FAILED;
}
state = States::FINISH;
return RETURN_OK;
return OK;
}
void ScexUartReader::foundDlePacketHandler(const ScexDleParser::Context &ctx) {
@ -178,11 +180,11 @@ void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
// sif::info << "Detected DLE encoded packet with decoded size " << len << std::endl;
MutexGuard mg(lock);
ReturnValue_t result = ipcQueue.insert(len);
if (result != RETURN_OK) {
if (result != OK) {
sif::warning << "ScexUartReader::handleFoundDlePacket: IPCQueue error" << std::endl;
}
result = ipcRingBuf.writeData(packet, len);
if (result != RETURN_OK) {
if (result != OK) {
sif::warning << "ScexUartReader::handleFoundDlePacket: IPCRingBuf error" << std::endl;
}
}
@ -192,13 +194,13 @@ ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **bu
MutexGuard mg(lock);
if (ipcQueue.empty()) {
*size = 0;
return RETURN_OK;
return OK;
}
ipcQueue.retrieve(size);
*buffer = ipcBuffer.data();
ReturnValue_t result = ipcRingBuf.readData(ipcBuffer.data(), *size, true);
if (result != RETURN_OK) {
if (result != OK) {
sif::warning << "ScexUartReader::readReceivedMessage: Reading RingBuffer failed" << std::endl;
}
return RETURN_OK;
return OK;
}

View File

@ -11,6 +11,7 @@
#include "mission/devices/devicedefinitions/ScexDefinitions.h"
using std::ofstream;
using namespace returnvalue;
ScexDeviceHandler::ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie,
SdCardMountedIF* sdcMan)
@ -26,11 +27,11 @@ void ScexDeviceHandler::doStartUp() {
void ScexDeviceHandler::doShutDown() { setMode(_MODE_POWER_DOWN); }
ReturnValue_t ScexDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
return RETURN_OK;
return OK;
}
ReturnValue_t ScexDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
return RETURN_OK;
return OK;
}
ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
@ -113,7 +114,7 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic
}
commandActive = true;
rawPacket = cmdBuf.data();
return RETURN_OK;
return OK;
}
void ScexDeviceHandler::fillCommandAndReplyMap() {
@ -144,14 +145,14 @@ ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remai
*foundId = helper.getCmd();
*foundLen = remainingSize;
return RETURN_OK;
return OK;
}
ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
// cmd auswertung (in file reinschreiben)
using namespace scex;
ReturnValue_t status = RETURN_OK;
ReturnValue_t status = OK;
auto oneFileHandler = [&](std::string cmdName) {
fileId = random_string(6);
std::ostringstream oss("/tmp/scex-", std::ostringstream::ate);
@ -162,12 +163,12 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
if (out.bad()) {
sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName
<< std::endl;
return RETURN_FAILED;
return FAILED;
}
if (debugMode) {
out << helper;
}
return RETURN_OK;
return OK;
};
auto multiFileHandler = [&](std::string cmdName) {
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
@ -181,7 +182,7 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
if (out.bad()) {
sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName
<< std::endl;
return RETURN_FAILED;
return FAILED;
}
} else {
ofstream out(fileName,
@ -191,7 +192,7 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
}
}
return RETURN_OK;
return OK;
};
switch (id) {
case (PING): {
@ -249,16 +250,16 @@ void ScexDeviceHandler::performOperationHook() {
}
uint32_t ScexDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
return RETURN_OK;
return OK;
}
ReturnValue_t ScexDeviceHandler::getSwitches(const uint8_t** switches, uint8_t* numberOfSwitches) {
return RETURN_OK;
return OK;
}
ReturnValue_t ScexDeviceHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
return RETURN_OK;
return OK;
}
std::string ScexDeviceHandler::random_string(std::string::size_type length) {

View File

@ -17,7 +17,7 @@ ReturnValue_t scex::prepareScexCmd(Cmds cmd, std::pair<uint8_t*, size_t> cmdBufP
if (cmdBuf == nullptr or (cmdBufPair.second < usrDataPair.second + HEADER_LEN + CRC_LEN) or
(usrDataPair.second > 0 and userData == nullptr)) {
cmdLen = 0;
return HasReturnvaluesIF::RETURN_FAILED;
return returnvalue::FAILED;
}
cmdBuf[0] = createCmdByte(cmd, tempCheck);
// These two fields are the packet counter and the total packet count. Those are 1 and 1 for each
@ -31,5 +31,5 @@ ReturnValue_t scex::prepareScexCmd(Cmds cmd, std::pair<uint8_t*, size_t> cmdBufP
cmdBuf[usrDataPair.second + HEADER_LEN] = (crc >> 8) & 0xff;
cmdBuf[usrDataPair.second + HEADER_LEN + 1] = crc & 0xff;
cmdLen = usrDataPair.second + HEADER_LEN + CRC_LEN;
return HasReturnvaluesIF::RETURN_OK;
return returnvalue::OK;
}