safety mechanism on reboots #308
@ -3,6 +3,7 @@
|
||||
#include <fsfw/events/EventManager.h>
|
||||
#include <fsfw/filesystem/HasFileSystemIF.h>
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
|
||||
#include "OBSWVersion.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
@ -932,6 +933,9 @@ ReturnValue_t CoreController::actionReboot(const uint8_t *data, size_t size) {
|
||||
ReturnValue_t CoreController::gracefulShutdownTasks(xsc::Chip chip, xsc::Copy copy,
|
||||
bool &protOpPerformed) {
|
||||
sdcMan->setBlocking(true);
|
||||
sdcMan->markUnusable();
|
||||
// Wait two seconds to ensure no one uses the SD cards
|
||||
TaskFactory::delayTask(2000);
|
||||
// Attempt graceful shutdown by unmounting and switching off SD cards
|
||||
sdcMan->switchOffSdCard(sd::SdCard::SLOT_0);
|
||||
sdcMan->switchOffSdCard(sd::SdCard::SLOT_1);
|
||||
|
@ -459,7 +459,14 @@ void SdCardManager::setBlocking(bool blocking) { this->blocking = blocking; }
|
||||
|
||||
void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = print; }
|
||||
|
||||
bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) {
|
||||
bool SdCardManager::isSdCardUsable(std::optional<sd::SdCard> sdCard) {
|
||||
{
|
||||
MutexGuard mg(mutex);
|
||||
if (markedUnusable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
SdCardManager::SdStatePair active;
|
||||
ReturnValue_t result = this->getSdCardsStatus(active);
|
||||
|
||||
@ -467,20 +474,30 @@ bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) {
|
||||
sif::debug << "SdCardManager::isSdCardMounted: Failed to get SD card active state";
|
||||
return false;
|
||||
}
|
||||
if (not sdCard) {
|
||||
if (active.first == sd::MOUNTED or active.second == sd::MOUNTED) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (sdCard == sd::SLOT_0) {
|
||||
if (active.first == sd::MOUNTED) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (sdCard == sd::SLOT_1) {
|
||||
}
|
||||
if (sdCard == sd::SLOT_1) {
|
||||
if (active.second == sd::MOUNTED) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
sif::debug << "SdCardManager::isSdCardMounted: Unknown SD card specified" << std::endl;
|
||||
}
|
||||
if (sdCard == sd::BOTH) {
|
||||
if (active.first == sd::MOUNTED && active.second == sd::MOUNTED) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -560,5 +577,13 @@ void SdCardManager::setActiveSdCard(sd::SdCard sdCard) {
|
||||
|
||||
std::optional<sd::SdCard> SdCardManager::getActiveSdCard() const {
|
||||
MutexGuard mg(mutex);
|
||||
if (markedUnusable) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return sdInfo.active;
|
||||
}
|
||||
|
||||
void SdCardManager::markUnusable() {
|
||||
MutexGuard mg(mutex);
|
||||
markedUnusable = true;
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
*
|
||||
* @return true if mounted, otherwise false
|
||||
*/
|
||||
bool isSdCardUsable(sd::SdCard sdCard) override;
|
||||
bool isSdCardUsable(std::optional<sd::SdCard> sdCard) override;
|
||||
|
||||
ReturnValue_t isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly);
|
||||
|
||||
@ -214,12 +214,15 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
|
||||
ReturnValue_t performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError);
|
||||
|
||||
void markUnusable();
|
||||
|
||||
private:
|
||||
CommandExecutor cmdExecutor;
|
||||
Operations currentOp = Operations::IDLE;
|
||||
bool blocking = false;
|
||||
bool sdCardActive = true;
|
||||
bool printCmdOutput = true;
|
||||
bool markedUnusable = false;
|
||||
MutexIF* mutex = nullptr;
|
||||
|
||||
SdCardManager();
|
||||
|
2
fsfw
2
fsfw
@ -1 +1 @@
|
||||
Subproject commit b0c5a49b504708ec9130228100d7bbd49025598d
|
||||
Subproject commit 1f05e6b297af8a6d310394e959c4d0cf13632831
|
@ -1917,6 +1917,11 @@ ReturnValue_t PlocSupervisorHandler::checkMramPacketApid() {
|
||||
}
|
||||
|
||||
ReturnValue_t PlocSupervisorHandler::handleMramDumpFile(DeviceCommandId_t id) {
|
||||
#ifdef XIPHOS_Q7S
|
||||
if (not sdcMan->getActiveSdCard()) {
|
||||
return HasFileSystemIF::FILESYSTEM_INACTIVE;
|
||||
}
|
||||
#endif
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
uint16_t packetLen = readSpacePacketLength(spacePacketBuffer);
|
||||
uint8_t sequenceFlags = readSequenceFlags(spacePacketBuffer);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "PlocSupvHelper.h"
|
||||
|
||||
#include <etl/crc16_ccitt.h>
|
||||
#include <fsfw/filesystem/HasFileSystemIF.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <filesystem>
|
||||
@ -748,6 +749,11 @@ uint32_t PlocSupvHelper::getFileSize(std::string filename) {
|
||||
|
||||
ReturnValue_t PlocSupvHelper::handleEventBufferReception(ploc::SpTmReader& reader) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
#ifdef XIPHOS_Q7S
|
||||
if (not sdcMan->getActiveSdCard()) {
|
||||
return HasFileSystemIF::FILESYSTEM_INACTIVE;
|
||||
}
|
||||
#endif
|
||||
std::string filename = Filenaming::generateAbsoluteFilename(
|
||||
eventBufferReq.path, eventBufferReq.filename, timestamping);
|
||||
std::ofstream file(filename, std::ios_base::app | std::ios_base::out);
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "StrHelper.h"
|
||||
|
||||
#include <fsfw/filesystem/HasFileSystemIF.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
@ -176,6 +178,11 @@ void StrHelper::disableTimestamping() { timestamping = false; }
|
||||
void StrHelper::enableTimestamping() { timestamping = true; }
|
||||
|
||||
ReturnValue_t StrHelper::performImageDownload() {
|
||||
#ifdef XIPHOS_Q7S
|
||||
if (not sdcMan->getActiveSdCard()) {
|
||||
return HasFileSystemIF::FILESYSTEM_INACTIVE;
|
||||
}
|
||||
#endif
|
||||
ReturnValue_t result;
|
||||
#if OBSW_DEBUG_STARTRACKER == 1
|
||||
ProgressPrinter progressPrinter("Image download", ImageDownload::LAST_POSITION);
|
||||
@ -244,6 +251,11 @@ ReturnValue_t StrHelper::performImageUpload() {
|
||||
uint32_t imageSize = 0;
|
||||
struct UploadActionRequest uploadReq;
|
||||
uploadReq.position = 0;
|
||||
#ifdef XIPHOS_Q7S
|
||||
if (not sdcMan->getActiveSdCard()) {
|
||||
return HasFileSystemIF::FILESYSTEM_INACTIVE;
|
||||
}
|
||||
#endif
|
||||
std::memset(&uploadReq.data, 0, sizeof(uploadReq.data));
|
||||
if (not std::filesystem::exists(uploadImage.uploadFile)) {
|
||||
triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState));
|
||||
@ -315,6 +327,11 @@ ReturnValue_t StrHelper::performFirmwareUpdate() {
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::performFlashWrite() {
|
||||
#ifdef XIPHOS_Q7S
|
||||
if (not sdcMan->getActiveSdCard()) {
|
||||
return HasFileSystemIF::FILESYSTEM_INACTIVE;
|
||||
}
|
||||
#endif
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
uint32_t size = 0;
|
||||
uint32_t bytesWritten = 0;
|
||||
@ -394,6 +411,11 @@ ReturnValue_t StrHelper::performFlashWrite() {
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::performFlashRead() {
|
||||
#ifdef XIPHOS_Q7S
|
||||
if (not sdcMan->getActiveSdCard()) {
|
||||
return HasFileSystemIF::FILESYSTEM_INACTIVE;
|
||||
}
|
||||
#endif
|
||||
ReturnValue_t result;
|
||||
#if OBSW_DEBUG_STARTRACKER == 1
|
||||
ProgressPrinter progressPrinter("Flash read", flashRead.size);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "ScexDeviceHandler.h"
|
||||
|
||||
#include <fsfw/filesystem/HasFileSystemIF.h>
|
||||
#include <linux/devices/ScexHelper.h>
|
||||
#include <mission/memory/SdCardMountedIF.h>
|
||||
|
||||
@ -200,6 +201,10 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
|
||||
|
||||
ReturnValue_t status = OK;
|
||||
auto oneFileHandler = [&](std::string cmdName) {
|
||||
auto activeSd = sdcMan.getActiveSdCard();
|
||||
if (not activeSd) {
|
||||
return HasFileSystemIF::FILESYSTEM_INACTIVE;
|
||||
}
|
||||
fileId = date_time_string();
|
||||
std::ostringstream oss;
|
||||
auto prefix = sdcMan.getCurrentMountPrefix();
|
||||
@ -216,6 +221,10 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
|
||||
};
|
||||
auto multiFileHandler = [&](std::string cmdName) {
|
||||
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
|
||||
auto activeSd = sdcMan.getActiveSdCard();
|
||||
if (not activeSd) {
|
||||
return HasFileSystemIF::FILESYSTEM_INACTIVE;
|
||||
}
|
||||
fileId = date_time_string();
|
||||
std::ostringstream oss;
|
||||
auto prefix = sdcMan.getCurrentMountPrefix();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "SolarArrayDeploymentHandler.h"
|
||||
|
||||
#include <fsfw/filesystem/HasFileSystemIF.h>
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
|
||||
#include <filesystem>
|
||||
|
@ -10,7 +10,7 @@ class SdCardMountedIF {
|
||||
public:
|
||||
virtual ~SdCardMountedIF(){};
|
||||
virtual const std::string& getCurrentMountPrefix() const = 0;
|
||||
virtual bool isSdCardUsable(sd::SdCard sdCard) = 0;
|
||||
virtual bool isSdCardUsable(std::optional<sd::SdCard> sdCard) = 0;
|
||||
virtual std::optional<sd::SdCard> getPreferredSdCard() const = 0;
|
||||
virtual void setActiveSdCard(sd::SdCard sdCard) = 0;
|
||||
virtual std::optional<sd::SdCard> getActiveSdCard() const = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user