Merge branch 'dev-7.5.0' into higher-acs-modes-only-str
All checks were successful
EIVE/eive-obsw/pipeline/pr-dev-7.5.0 This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/pr-dev-7.5.0 This commit looks good
This commit is contained in:
@ -1,12 +1,9 @@
|
||||
#include "AcsController.h"
|
||||
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include <mission/acs/defs.h>
|
||||
#include <mission/config/torquer.h>
|
||||
|
||||
AcsController::AcsController(object_id_t objectId, bool enableHkSets)
|
||||
AcsController::AcsController(object_id_t objectId, bool enableHkSets, SdCardMountedIF &sdcMan)
|
||||
: ExtendedControllerBase(objectId),
|
||||
enableHkSets(enableHkSets),
|
||||
sdcMan(sdcMan),
|
||||
attitudeEstimation(&acsParameters),
|
||||
fusedRotationEstimation(&acsParameters),
|
||||
guidance(&acsParameters),
|
||||
@ -24,8 +21,7 @@ AcsController::AcsController(object_id_t objectId, bool enableHkSets)
|
||||
ctrlValData(this),
|
||||
actuatorCmdData(this),
|
||||
fusedRotRateData(this),
|
||||
fusedRotRateSourcesData(this),
|
||||
tleData(this) {}
|
||||
fusedRotRateSourcesData(this) {}
|
||||
|
||||
ReturnValue_t AcsController::initialize() {
|
||||
ReturnValue_t result = parameterHelper.initialize();
|
||||
@ -69,22 +65,27 @@ ReturnValue_t AcsController::executeAction(ActionId_t actionId, MessageQueueId_t
|
||||
if (size != 69 * 2) {
|
||||
return INVALID_PARAMETERS;
|
||||
}
|
||||
ReturnValue_t result = navigation.updateTle(data, data + 69);
|
||||
ReturnValue_t result = updateTle(data, data + 69, false);
|
||||
if (result != returnvalue::OK) {
|
||||
PoolReadGuard pg(&tleData);
|
||||
navigation.updateTle(tleData.line1.value, tleData.line2.value);
|
||||
return result;
|
||||
}
|
||||
{
|
||||
PoolReadGuard pg(&tleData);
|
||||
if (pg.getReadResult() == returnvalue::OK) {
|
||||
std::memcpy(tleData.line1.value, data, 69);
|
||||
std::memcpy(tleData.line2.value, data + 69, 69);
|
||||
tleData.setValidity(true, true);
|
||||
}
|
||||
result = writeTleToFs(data);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return HasActionsIF::EXECUTION_FINISHED;
|
||||
}
|
||||
case (READ_TLE): {
|
||||
uint8_t tle[69 * 2] = {};
|
||||
uint8_t line2[69] = {};
|
||||
ReturnValue_t result = readTleFromFs(tle, line2);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(tle + 69, line2, 69);
|
||||
actionHelper.reportData(commandedBy, actionId, tle, 69 * 2);
|
||||
return EXECUTION_FINISHED;
|
||||
}
|
||||
default: {
|
||||
return HasActionsIF::INVALID_ACTION_ID;
|
||||
}
|
||||
@ -132,6 +133,10 @@ void AcsController::performControlOperation() {
|
||||
}
|
||||
case InternalState::INITIAL_DELAY: {
|
||||
if (initialCountdown.hasTimedOut()) {
|
||||
uint8_t line1[69] = {};
|
||||
uint8_t line2[69] = {};
|
||||
readTleFromFs(line1, line2);
|
||||
updateTle(line1, line2, true);
|
||||
internalState = InternalState::READY;
|
||||
}
|
||||
return;
|
||||
@ -816,9 +821,6 @@ ReturnValue_t AcsController::initializeLocalDataPool(localpool::DataPool &localD
|
||||
localDataPoolMap.emplace(acsctrl::PoolIds::ROT_RATE_TOTAL_QUEST, &rotRateTotalQuest);
|
||||
localDataPoolMap.emplace(acsctrl::PoolIds::ROT_RATE_TOTAL_STR, &rotRateTotalStr);
|
||||
poolManager.subscribeForRegularPeriodicPacket({fusedRotRateSourcesData.getSid(), false, 10.0});
|
||||
// TLE Data
|
||||
localDataPoolMap.emplace(acsctrl::PoolIds::TLE_LINE_1, &line1);
|
||||
localDataPoolMap.emplace(acsctrl::PoolIds::TLE_LINE_2, &line2);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
@ -1046,6 +1048,67 @@ void AcsController::copySusData() {
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t AcsController::updateTle(const uint8_t *line1, const uint8_t *line2, bool fromFile) {
|
||||
ReturnValue_t result = navigation.updateTle(line1, line2);
|
||||
if (result != returnvalue::OK) {
|
||||
if (not fromFile) {
|
||||
uint8_t fileLine1[69] = {};
|
||||
uint8_t fileLine2[69] = {};
|
||||
readTleFromFs(fileLine1, fileLine2);
|
||||
navigation.updateTle(fileLine1, fileLine2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t AcsController::writeTleToFs(const uint8_t *tle) {
|
||||
auto mntPrefix = sdcMan.getCurrentMountPrefix();
|
||||
if (mntPrefix == nullptr or !sdcMan.isSdCardUsable(std::nullopt)) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
std::string path = mntPrefix + TLE_FILE;
|
||||
// Clear existing TLE from file
|
||||
std::ofstream tleFile(path.c_str(), std::ofstream::out | std::ofstream::trunc);
|
||||
if (tleFile.is_open()) {
|
||||
tleFile.write(reinterpret_cast<const char *>(tle), 69);
|
||||
tleFile << "\n";
|
||||
tleFile.write(reinterpret_cast<const char *>(tle + 69), 69);
|
||||
} else {
|
||||
return WRITE_FILE_FAILED;
|
||||
}
|
||||
tleFile.close();
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t AcsController::readTleFromFs(uint8_t *line1, uint8_t *line2) {
|
||||
auto mntPrefix = sdcMan.getCurrentMountPrefix();
|
||||
if (mntPrefix == nullptr or !sdcMan.isSdCardUsable(std::nullopt)) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
std::string path = mntPrefix + TLE_FILE;
|
||||
std::error_code e;
|
||||
if (std::filesystem::exists(path, e)) {
|
||||
// Read existing TLE from file
|
||||
std::fstream tleFile = std::fstream(path.c_str(), std::fstream::in);
|
||||
if (tleFile.is_open()) {
|
||||
std::string tleLine1, tleLine2;
|
||||
getline(tleFile, tleLine1);
|
||||
std::memcpy(line1, tleLine1.c_str(), 69);
|
||||
getline(tleFile, tleLine2);
|
||||
std::memcpy(line2, tleLine2.c_str(), 69);
|
||||
} else {
|
||||
triggerEvent(acs::TLE_FILE_READ_FAILED);
|
||||
return READ_FILE_FAILED;
|
||||
}
|
||||
tleFile.close();
|
||||
} else {
|
||||
triggerEvent(acs::TLE_FILE_READ_FAILED);
|
||||
return READ_FILE_FAILED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void AcsController::copyGyrData() {
|
||||
{
|
||||
PoolReadGuard pg(&sensorValues.gyr0AdisSet);
|
||||
|
Reference in New Issue
Block a user