found the bug
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-10-04 23:04:50 +02:00
parent a44141c476
commit 1a192cd8fb
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
8 changed files with 60 additions and 44 deletions

View File

@ -23,7 +23,6 @@
#include "mission/devices/GyroADIS1650XHandler.h" #include "mission/devices/GyroADIS1650XHandler.h"
#include "mission/tmtc/TmFunnel.h" #include "mission/tmtc/TmFunnel.h"
#include "objects/systemObjectList.h" #include "objects/systemObjectList.h"
#include "tmtc/apid.h"
#include "tmtc/pusIds.h" #include "tmtc/pusIds.h"
/* UDP server includes */ /* UDP server includes */

View File

@ -4,7 +4,7 @@ RPiSdCardManager::RPiSdCardManager(std::string prefix) : prefix(std::move(prefix
const std::string& RPiSdCardManager::getCurrentMountPrefix() const { return prefix; } const std::string& RPiSdCardManager::getCurrentMountPrefix() const { return prefix; }
bool RPiSdCardManager::isSdCardMounted(sd::SdCard sdCard) { return true; } bool RPiSdCardManager::isSdCardUsable(sd::SdCard sdCard) { return true; }
std::optional<sd::SdCard> RPiSdCardManager::getPreferredSdCard() const { return std::nullopt; } std::optional<sd::SdCard> RPiSdCardManager::getPreferredSdCard() const { return std::nullopt; }

View File

@ -6,7 +6,7 @@ class RPiSdCardManager : public SdCardMountedIF {
public: public:
RPiSdCardManager(std::string prefix); RPiSdCardManager(std::string prefix);
const std::string& getCurrentMountPrefix() const override; const std::string& getCurrentMountPrefix() const override;
bool isSdCardMounted(sd::SdCard sdCard) override; bool isSdCardUsable(sd::SdCard sdCard) override;
std::optional<sd::SdCard> getPreferredSdCard() const override; std::optional<sd::SdCard> getPreferredSdCard() const override;
void setActiveSdCard(sd::SdCard sdCard) override; void setActiveSdCard(sd::SdCard sdCard) override;
std::optional<sd::SdCard> getActiveSdCard() const override; std::optional<sd::SdCard> getActiveSdCard() const override;

2
fsfw

@ -1 +1 @@
Subproject commit d1630cdc4c3fc801934f1e394efa80e898f8031b Subproject commit 1c53b60442f5b858b00938169ef1daba41ba272d

View File

@ -35,7 +35,7 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
while (true) { while (true) {
semaphore->acquire(); semaphore->acquire();
int bytesRead = 0; int bytesRead = 0;
debugMode = true; // debugMode = true;
while (true) { while (true) {
bytesRead = read(serialPort, reinterpret_cast<void *>(recBuf.data()), bytesRead = read(serialPort, reinterpret_cast<void *>(recBuf.data()),
static_cast<unsigned int>(recBuf.size())); static_cast<unsigned int>(recBuf.size()));
@ -50,24 +50,11 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
break; break;
} }
} }
size_t bytesRead = 0;
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
while (result != DleParser::NO_PACKET_FOUND) { while (result != DleParser::NO_PACKET_FOUND) {
result = dleParser.parseRingBuf(bytesRead); result = tryDleParsing();
if (result == returnvalue::OK) {
sif::info << "FOund dle packet, read " << bytesRead << " bytes" << std::endl;
// Packet found, advance read pointer.
auto& decodedPacket = dleParser.getContext().decodedPacket;
handleFoundDlePacket(decodedPacket.first, decodedPacket.second);
dleParser.confirmBytesRead(bytesRead);
} else if (result != DleParser::NO_PACKET_FOUND) {
sif::warning << "ScexUartReader::performOperation: Possible packet loss" << std::endl;
// Markers found at wrong place
// which might be a hint for a possibly lost packet.
dleParser.defaultErrorHandler();
dleParser.confirmBytesRead(bytesRead);
}
} }
TaskFactory::delayTask(400); TaskFactory::delayTask(400);
} else if (bytesRead < 0) { } else if (bytesRead < 0) {
sif::warning << "ScexUartReader::performOperation: read call failed with error [" << errno sif::warning << "ScexUartReader::performOperation: read call failed with error [" << errno
@ -77,15 +64,16 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
sif::error << "ScexUartReader::performOperation: Receive buffer too small for " << bytesRead sif::error << "ScexUartReader::performOperation: Receive buffer too small for " << bytesRead
<< " bytes" << std::endl; << " bytes" << std::endl;
} else if (bytesRead > 0) { } else if (bytesRead > 0) {
ReturnValue_t result = dleParser.passData(recBuf.data(), bytesRead);
if (debugMode) { if (debugMode) {
sif::info << "Received " << bytesRead sif::info << "Received " << bytesRead
<< " bytes from the Solar Cell Experiment:" << std::endl; << " bytes from the Solar Cell Experiment:" << std::endl;
} }
ReturnValue_t result = dleParser.passData(recBuf.data(), bytesRead);
if (result != OK) { if (result != OK) {
sif::warning << "ScexUartReader::performOperation: Passing data to DLE parser failed" sif::warning << "ScexUartReader::performOperation: Passing data to DLE parser failed"
<< std::endl; << std::endl;
} }
result = tryDleParsing();
} }
}; };
} }
@ -138,6 +126,7 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendData, ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendData,
size_t sendLen) { size_t sendLen) {
ReturnValue_t result;
if (sendData == nullptr or sendLen == 0) { if (sendData == nullptr or sendLen == 0) {
return FAILED; return FAILED;
} }
@ -146,13 +135,16 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD
lock->unlockMutex(); lock->unlockMutex();
return FAILED; return FAILED;
} }
tcflush(serialPort, TCIOFLUSH); tcflush(serialPort, TCIFLUSH);
state = States::RUNNING; state = States::RUNNING;
lock->unlockMutex(); lock->unlockMutex();
result = semaphore->release();
if (result != OK) {
std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl;
}
size_t encodedLen = 0; size_t encodedLen = 0;
ReturnValue_t result = result = dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true);
dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true);
if (result != OK) { if (result != OK) {
sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl; sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl;
return FAILED; return FAILED;
@ -163,10 +155,7 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD
<< std::endl; << std::endl;
return FAILED; return FAILED;
} }
result = semaphore->release();
if (result != OK) {
std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl;
}
return OK; return OK;
} }
@ -199,6 +188,30 @@ void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
} }
} }
ReturnValue_t ScexUartReader::tryDleParsing() {
size_t bytesRead = 0;
ReturnValue_t result = dleParser.parseRingBuf(bytesRead);
if (result == returnvalue::OK) {
// Packet found, advance read pointer.
auto &decodedPacket = dleParser.getContext().decodedPacket;
handleFoundDlePacket(decodedPacket.first, decodedPacket.second);
dleParser.confirmBytesRead(bytesRead);
} else if (result != DleParser::NO_PACKET_FOUND) {
sif::warning << "ScexUartReader::performOperation: Possible packet loss" << std::endl;
// Markers found at wrong place
// which might be a hint for a possibly lost packet.
dleParser.defaultErrorHandler();
dleParser.confirmBytesRead(bytesRead);
}
return result;
}
void ScexUartReader::reset() {
lock->lockMutex();
state = States::FINISH;
lock->unlockMutex();
}
ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) { size_t *size) {
MutexGuard mg(lock); MutexGuard mg(lock);

View File

@ -22,6 +22,7 @@ class ScexUartReader : public SystemObject, // strg+shift+n
enum class States { NOT_READY, IDLE, RUNNING, FINISH }; enum class States { NOT_READY, IDLE, RUNNING, FINISH };
ScexUartReader(object_id_t objectId); ScexUartReader(object_id_t objectId);
void reset();
ReturnValue_t finish(); ReturnValue_t finish();
void setDebugMode(bool enable); void setDebugMode(bool enable);
@ -47,6 +48,7 @@ class ScexUartReader : public SystemObject, // strg+shift+n
static void foundDlePacketHandler(const DleParser::Context &ctx); static void foundDlePacketHandler(const DleParser::Context &ctx);
void handleFoundDlePacket(uint8_t *packet, size_t len); void handleFoundDlePacket(uint8_t *packet, size_t len);
ReturnValue_t tryDleParsing();
ReturnValue_t performOperation(uint8_t operationCode = 0) override; ReturnValue_t performOperation(uint8_t operationCode = 0) override;

View File

@ -5,10 +5,10 @@
#include <algorithm> #include <algorithm>
#include <ctime> #include <ctime>
#include <iostream>
#include <fstream>
#include <random>
#include <filesystem> #include <filesystem>
#include <fstream>
#include <iostream>
#include <random>
#include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/CRC.h"
#include "mission/devices/devicedefinitions/ScexDefinitions.h" #include "mission/devices/devicedefinitions/ScexDefinitions.h"
@ -24,7 +24,10 @@ ScexDeviceHandler::~ScexDeviceHandler() {}
void ScexDeviceHandler::doStartUp() { setMode(MODE_ON); } void ScexDeviceHandler::doStartUp() { setMode(MODE_ON); }
void ScexDeviceHandler::doShutDown() { setMode(_MODE_POWER_DOWN); } void ScexDeviceHandler::doShutDown() {
reader.reset();
setMode(_MODE_POWER_DOWN);
}
ReturnValue_t ScexDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { return OK; } ReturnValue_t ScexDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { return OK; }
@ -348,18 +351,16 @@ void ScexDeviceHandler::modeChanged() {}
void ScexDeviceHandler::setPowerSwitcher(PowerSwitchIF& powerSwitcher, power::Switch_t switchId) { void ScexDeviceHandler::setPowerSwitcher(PowerSwitchIF& powerSwitcher, power::Switch_t switchId) {
DeviceHandlerBase::setPowerSwitcher(&powerSwitcher); DeviceHandlerBase::setPowerSwitcher(&powerSwitcher);
this->switchId = switchId; this->switchId = switchId;
} }
ReturnValue_t ScexDeviceHandler::initializeAfterTaskCreation() { ReturnValue_t ScexDeviceHandler::initializeAfterTaskCreation() {
auto mntPrefix = sdcMan.getCurrentMountPrefix();
std::filesystem::path fullFilePath = mntPrefix;
fullFilePath /= "scex";
bool fileExists = std::filesystem::exists(fullFilePath);
auto mntPrefix = sdcMan.getCurrentMountPrefix(); if (not fileExists) {
std::filesystem::path fullFilePath = mntPrefix; std::filesystem::create_directory(fullFilePath);
fullFilePath /= "scex"; }
bool fileExists = std::filesystem::exists(fullFilePath); return DeviceHandlerBase::initializeAfterTaskCreation();
if(not fileExists){
std::filesystem::create_directory(fullFilePath);
}
return DeviceHandlerBase::initializeAfterTaskCreation();
} }

View File

@ -1,14 +1,15 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_ #ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_ #define MISSION_DEVICES_DEVICEDEFINITIONS_SCEXDEFINITIONS_H_
#include "eive/objects.h"
#include "eive/eventSubsystemIds.h"
#include <fsfw/devicehandlers/DeviceHandlerIF.h> #include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <fsfw/events/Event.h> #include <fsfw/events/Event.h>
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
#include "eive/eventSubsystemIds.h"
#include "eive/objects.h"
// Definitions for the Solar Cell Experiment // Definitions for the Solar Cell Experiment
namespace scex { namespace scex {