retval replacements
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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; }
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user