all versions written to version.txt file now
This commit is contained in:
@ -1,10 +1,12 @@
|
||||
#include "CoreController.h"
|
||||
#include "q7sConfig.h"
|
||||
#include "OBSWVersion.h"
|
||||
|
||||
#include "fsfw/FSFWVersion.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
#include "../memory/scratchApi.h"
|
||||
#include "../memory/SdCardManager.h"
|
||||
#include "bsp_q7s/memory/scratchApi.h"
|
||||
#include "bsp_q7s/memory/SdCardManager.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@ -46,6 +48,7 @@ ReturnValue_t CoreController::initialize() {
|
||||
sif::warning << "CoreController::initialize: Setting up alloc failure "
|
||||
"count failed" << std::endl;
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -180,6 +183,14 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::initializeAfterTaskCreation() {
|
||||
ReturnValue_t result = versionFileInit();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "CoreController::initialize: Version initialization failed" << std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::sdCardColdRedundantInit(SdCardManager* sdcMan,
|
||||
SdCardManager::SdStatusPair& statusPair) {
|
||||
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
|
||||
@ -254,3 +265,86 @@ ReturnValue_t CoreController::incrementAllocationFailureCount() {
|
||||
count++;
|
||||
return scratch::writeNumber(scratch::ALLOC_FAILURE_COUNT, count);
|
||||
}
|
||||
|
||||
ReturnValue_t CoreController::versionFileInit() {
|
||||
|
||||
std::string unameFileName = "/tmp/uname_version.txt";
|
||||
std::string unameCmd = "uname -a > " + unameFileName;
|
||||
int result = std::system(unameCmd.c_str());
|
||||
if(result != 0) {
|
||||
utility::handleSystemError(result, "CoreController::versionFileInit");
|
||||
}
|
||||
std::ifstream unameFile(unameFileName);
|
||||
std::string unameLine;
|
||||
if(not std::getline(unameFile, unameLine)) {
|
||||
sif::warning << "CoreController::versionFileInit: Retrieving uname line failed"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
std::string fullObswVersionString = "OBSW: v" + std::to_string(SW_VERSION) + "." +
|
||||
std::to_string(SW_SUBVERSION) + "." + std::to_string(SW_REVISION);
|
||||
std::string fullFsfwVersionString = "FSFW: v" + std::to_string(FSFW_VERSION) + "." +
|
||||
std::to_string(FSFW_SUBVERSION) + "." + std::to_string(FSFW_REVISION);
|
||||
std::string systemString = "System: " + unameLine;
|
||||
std::string mountPrefix = SdCardManager::instance()->getCurrentMountPrefix();
|
||||
std::string versionFilePath = mountPrefix + "/conf/version.txt";
|
||||
std::fstream versionFile;
|
||||
|
||||
if(not std::filesystem::exists(versionFilePath)) {
|
||||
sif::info << "Writing version file " << versionFilePath << ".." << std::endl;
|
||||
versionFile.open(versionFilePath, std::ios_base::out);
|
||||
versionFile << fullObswVersionString << std::endl;
|
||||
versionFile << fullFsfwVersionString << std::endl;
|
||||
versionFile << systemString << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
// Check whether any version has changed
|
||||
bool createNewFile = false;
|
||||
versionFile.open(versionFilePath);
|
||||
std::string currentVersionString;
|
||||
uint8_t idx = 0;
|
||||
while(std::getline(versionFile, currentVersionString)) {
|
||||
if(idx == 0) {
|
||||
if(currentVersionString != fullObswVersionString) {
|
||||
sif::info << "OBSW version changed" << std::endl;
|
||||
sif::info << "From " << currentVersionString << " to " <<
|
||||
fullObswVersionString << std::endl;
|
||||
createNewFile = true;
|
||||
}
|
||||
}
|
||||
else if(idx == 1) {
|
||||
if(currentVersionString != fullFsfwVersionString) {
|
||||
sif::info << "FSFW version changed" << std::endl;
|
||||
sif::info << "From " << currentVersionString << " to " <<
|
||||
fullFsfwVersionString << std::endl;
|
||||
createNewFile = true;
|
||||
}
|
||||
}
|
||||
else if(idx == 2) {
|
||||
if(currentVersionString != systemString) {
|
||||
sif::info << "System version changed" << std::endl;
|
||||
sif::info << "Old: " << currentVersionString << std::endl;
|
||||
sif::info << "New: " << systemString << std::endl;
|
||||
createNewFile = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sif::warning << "Invalid version file! Rewriting it.." << std::endl;
|
||||
createNewFile = true;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
// Overwrite file if necessary
|
||||
if(createNewFile) {
|
||||
sif::info << "Rewriting version.txt file with updated versions.." << std::endl;
|
||||
versionFile.close();
|
||||
versionFile.open(versionFilePath, std::ios_base::out | std::ios_base::trunc);
|
||||
versionFile << fullObswVersionString << std::endl;
|
||||
versionFile << fullFsfwVersionString << std::endl;
|
||||
versionFile << systemString << std::endl;
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ public:
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
ReturnValue_t initializeAfterTaskCreation() override;
|
||||
|
||||
ReturnValue_t executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t *data, size_t size) override;
|
||||
|
||||
@ -37,6 +39,9 @@ private:
|
||||
sd::SdCard sdCard, sd::SdStatus status, std::string sdString);
|
||||
ReturnValue_t sdCardColdRedundantInit(SdCardManager* sdcMan,
|
||||
SdCardManager::SdStatusPair& statusPair);
|
||||
|
||||
ReturnValue_t versionFileInit();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@ int obsw::obsw() {
|
||||
std::cout << "-- Compiled for Linux (TE0720) --" << std::endl;
|
||||
#endif
|
||||
std::cout << "-- OBSW " << SW_NAME << " v" << SW_VERSION << "." << SW_SUBVERSION <<
|
||||
"." << SW_SUBSUBVERSION << ", FSFW v" << FSFW_VERSION << "." << FSFW_SUBVERSION <<
|
||||
"." << SW_REVISION << ", FSFW v" << FSFW_VERSION << "." << FSFW_SUBVERSION <<
|
||||
FSFW_REVISION << "--" << std::endl;
|
||||
std::cout << "-- " << __DATE__ << " " << __TIME__ << " --" << std::endl;
|
||||
|
||||
|
Reference in New Issue
Block a user