From 67351d5adab86b55e05e43a54a8eb5b5e8dab477 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 16 Apr 2023 11:25:10 +0200 Subject: [PATCH] set time for star tracker --- mission/acs/str/StarTrackerHandler.cpp | 38 ++++++++++++++++++++++++-- mission/acs/str/StarTrackerHandler.h | 6 ++-- mission/acs/str/strHelpers.h | 2 +- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index d40e5fab..69ceab3a 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -331,6 +331,11 @@ ReturnValue_t StarTrackerHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id = startracker::REQ_VERSION; return buildCommandFromCommand(*id, nullptr, 0); } + case(FwBootState::SET_TIME): { + bootState = FwBootState::WAIT_FOR_EXECUTION; + *id = startracker::SET_TIME; + return buildCommandFromCommand(*id, nullptr, 0); + } case (FwBootState::LOGLEVEL): { bootState = FwBootState::WAIT_FOR_EXECUTION; *id = startracker::LOGLEVEL; @@ -441,6 +446,16 @@ ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t devi preparePingRequest(); return returnvalue::OK; } + case(startracker::SET_TIME): { + SetTimeActionRequest setTimeRequest; + time_t epoch; + timeval tv; + Clock::getClock(&tv); + epoch = tv.tv_sec; + setTimeRequest.unixTime = epoch; + arc_pack_settime_action_req(&setTimeRequest, commandBuffer, &rawPacketLen); + return returnvalue::OK; + } case (startracker::REQ_TIME): { prepareTimeRequest(); return returnvalue::OK; @@ -637,6 +652,8 @@ void StarTrackerHandler::fillCommandAndReplyMap() { startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::LOGLEVEL, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); + this->insertInCommandAndReplyMap(startracker::SET_TIME, 3, nullptr, + startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::LOGSUBSCRIPTION, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::DEBUG_CAMERA, 3, nullptr, @@ -1349,6 +1366,10 @@ ReturnValue_t StarTrackerHandler::scanForActionReply(uint8_t replyId, DeviceComm *foundId = startracker::UPLOAD_IMAGE; break; } + case(ARC_ACTION_REQ_SETTIME_ID): { + *foundId = startracker::SET_TIME; + break; + } case (startracker::ID::CHECKSUM): { *foundId = startracker::CHECKSUM; break; @@ -1851,7 +1872,7 @@ ReturnValue_t StarTrackerHandler::handleSetParamReply(const uint8_t* rawFrame) { return SET_PARAM_FAILED; } if (internalState != InternalState::IDLE) { - handleStartup(*(rawFrame + PARAMETER_ID_OFFSET)); + handleStartup(*rawFrame, *(rawFrame + PARAMETER_ID_OFFSET)); } return returnvalue::OK; } @@ -2038,7 +2059,18 @@ ReturnValue_t StarTrackerHandler::handleActionReplySet(const uint8_t* rawFrame, return result; } -void StarTrackerHandler::handleStartup(uint8_t parameterId) { +void StarTrackerHandler::handleStartup(uint8_t tmType, uint8_t parameterId) { + switch(tmType) { + case(TMTC_ACTIONREPLY): { + case(ARC_ACTION_REQ_SETTIME_ID): { + bootState = FwBootState::LOGLEVEL; + return; + } + default: { + break; + } + } + } switch (parameterId) { case (startracker::ID::LOG_LEVEL): { bootState = FwBootState::LIMITS; @@ -2048,7 +2080,7 @@ void StarTrackerHandler::handleStartup(uint8_t parameterId) { bootState = FwBootState::TRACKING; break; } - case (startracker::ID::TRACKING): { + case (ARC_PARAM_TRACKING_ID): { bootState = FwBootState::MOUNTING; break; } diff --git a/mission/acs/str/StarTrackerHandler.h b/mission/acs/str/StarTrackerHandler.h index a74bff44..13855161 100644 --- a/mission/acs/str/StarTrackerHandler.h +++ b/mission/acs/str/StarTrackerHandler.h @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -16,7 +17,7 @@ #include "fsfw/timemanager/Countdown.h" extern "C" { -#include +#include } /** @@ -267,6 +268,7 @@ class StarTrackerHandler : public DeviceHandlerBase { BOOT_DELAY, REQ_VERSION, VERIFY_BOOT, + SET_TIME, LOGLEVEL, LIMITS, TRACKING, @@ -471,7 +473,7 @@ class StarTrackerHandler : public DeviceHandlerBase { /** * @brief Handles the startup state machine */ - void handleStartup(uint8_t parameterId); + void handleStartup(uint8_t tmType, uint8_t parameterId); /** * @brief Handles telemtry replies and fills the appropriate dataset diff --git a/mission/acs/str/strHelpers.h b/mission/acs/str/strHelpers.h index 69729df5..21038a91 100644 --- a/mission/acs/str/strHelpers.h +++ b/mission/acs/str/strHelpers.h @@ -326,6 +326,7 @@ static const DeviceCommandId_t DEBUG_CAMERA = 83; static const DeviceCommandId_t FIRMWARE_UPDATE = 84; static const DeviceCommandId_t DISABLE_TIMESTAMP_GENERATION = 85; static const DeviceCommandId_t ENABLE_TIMESTAMP_GENERATION = 86; +static constexpr DeviceCommandId_t SET_TIME = 87; static const DeviceCommandId_t NONE = 0xFFFFFFFF; static const uint32_t VERSION_SET_ID = REQ_VERSION; @@ -396,7 +397,6 @@ static const uint8_t ALGO = 16; static const uint8_t REBOOT = 7; static const uint8_t UPLOAD_IMAGE = 10; static const uint8_t POWER = 11; -static const uint8_t SET_TIME = 14; static const uint8_t SUBSCRIPTION = 18; static const uint8_t SOLUTION = 24; static const uint8_t TEMPERATURE = 27;