From 8cddbf86d9b2f11195c723c8afe0095472d35ea1 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 23 Dec 2021 11:07:19 +0100 Subject: [PATCH] flash read command --- .../startracker/StarTrackerHandler.cpp | 6 ++--- .../devices/startracker/StarTrackerHandler.h | 4 ++-- bsp_q7s/devices/startracker/StrHelper.cpp | 21 +++++++++--------- bsp_q7s/devices/startracker/StrHelper.h | 22 +++++++++---------- mission/utility/Timestamp.cpp | 15 ++++++++++--- mission/utility/Timestamp.h | 3 +++ 6 files changed, 41 insertions(+), 30 deletions(-) diff --git a/bsp_q7s/devices/startracker/StarTrackerHandler.cpp b/bsp_q7s/devices/startracker/StarTrackerHandler.cpp index d55fb17a..9b97b422 100644 --- a/bsp_q7s/devices/startracker/StarTrackerHandler.cpp +++ b/bsp_q7s/devices/startracker/StarTrackerHandler.cpp @@ -1009,11 +1009,11 @@ ReturnValue_t StarTrackerHandler::executeReadCommand(const uint8_t* commandData, << std::endl; return result; } - uint16_t length; + uint32_t length; size = sizeof(length); const uint8_t* lengthPtr = commandData + ReadCmd::LENGTH_OFFSET; - result = SerializeAdapter::deSerialize(&address, lengthPtr, &size, - SerializeIF::Endianness::LITTLE); + result = SerializeAdapter::deSerialize(&length, lengthPtr, &size, + SerializeIF::Endianness::BIG); if (result != RETURN_OK) { sif::debug << "StarTrackerHandler::executeReadCommand: Deserialization of length failed" << std::endl; diff --git a/bsp_q7s/devices/startracker/StarTrackerHandler.h b/bsp_q7s/devices/startracker/StarTrackerHandler.h index 791ead0f..16b00d3b 100644 --- a/bsp_q7s/devices/startracker/StarTrackerHandler.h +++ b/bsp_q7s/devices/startracker/StarTrackerHandler.h @@ -151,9 +151,9 @@ private: public: static const uint8_t ADDRESS_OFFSET = 1; static const uint8_t LENGTH_OFFSET = 5; - static const uint8_t FILE_OFFSET = 7; + static const uint8_t FILE_OFFSET = 9; // Minimum length of a read command (region, address, length and filename) - static const size_t MIN_LENGTH = 9; + static const size_t MIN_LENGTH = 11; }; class UnlockCmd { diff --git a/bsp_q7s/devices/startracker/StrHelper.cpp b/bsp_q7s/devices/startracker/StrHelper.cpp index 4a6797f1..fa7b510f 100644 --- a/bsp_q7s/devices/startracker/StrHelper.cpp +++ b/bsp_q7s/devices/startracker/StrHelper.cpp @@ -154,14 +154,14 @@ ReturnValue_t StrHelper::startFlashWrite(std::string flashWriteFile_, uint8_t re return RETURN_OK; } -ReturnValue_t StrHelper::startFlashRead(std::string flashReadFile_, uint8_t region, - uint32_t address, uint16_t length) { - ReturnValue_t result = checkPath(flashReadFile_); +ReturnValue_t StrHelper::startFlashRead(std::string flashReadPath_, uint8_t region, + uint32_t address, uint32_t length) { + ReturnValue_t result = checkPath(flashReadPath_); if (result != RETURN_OK) { return result; } - flashReadFile = flashReadFile_; - if(not std::filesystem::exists(flashReadFile)) { + flashReadPath = flashReadPath_; + if(not std::filesystem::exists(flashReadPath)) { return FILE_NOT_EXISTS; } flashReadAddress = address; @@ -456,14 +456,13 @@ ReturnValue_t StrHelper::checkReply() { if (type != TMTC_ACTIONREPLY) { sif::warning << "StrHelper::checkReply: Received reply with invalid type ID" << std::endl; - triggerEvent(INVALID_TYPE_ID); - return RETURN_FAILED; + return INVALID_TYPE_ID; } uint8_t status = datalinkLayer.getStatusField(); if (status != ArcsecDatalinkLayer::STATUS_OK) { - triggerEvent(STATUS_ERROR); - sif::warning << "StrHelper::checkReply: Status failure" << std::endl; - return RETURN_FAILED; + sif::warning << "StrHelper::checkReply: Status failure: " + << static_cast(status) << std::endl; + return STATUS_ERROR; } return RETURN_OK; } @@ -511,7 +510,7 @@ ReturnValue_t StrHelper::checkFlashActionReply(uint8_t region_, uint32_t address if (address != address_) { return ADDRESS_MISMATCH; } - if (region != length_) { + if (length != length_) { return LENGTH_MISMATCH; } return RETURN_OK; diff --git a/bsp_q7s/devices/startracker/StrHelper.h b/bsp_q7s/devices/startracker/StrHelper.h index 13742778..ff2f3ca6 100644 --- a/bsp_q7s/devices/startracker/StrHelper.h +++ b/bsp_q7s/devices/startracker/StrHelper.h @@ -51,28 +51,24 @@ public: //! [EXPORT] : [COMMENT] Star tracker did not send replies (maybe device is powered off) //!P1: Position of upload or download packet for which no reply was sent static const Event STR_HELPER_NO_REPLY = MAKE_EVENT(10, severity::LOW); - //! [EXPORT] : [COMMENT] Received reply with invalid type ID - static const Event INVALID_TYPE_ID = MAKE_EVENT(11, severity::LOW); - //! [EXPORT] : [COMMENT] Status field in reply signals error - static const Event STATUS_ERROR = MAKE_EVENT(12, severity::LOW); //! [EXPORT] : [COMMENT] Error during decoding of received reply occurred //P1: Return value of decoding function //P2: Position of upload/download packet, or address of flash write/read request - static const Event STR_HELPER_DEC_ERROR = MAKE_EVENT(13, severity::LOW); + static const Event STR_HELPER_DEC_ERROR = MAKE_EVENT(11, severity::LOW); //! [EXPORT] : [COMMENT] Position mismatch //! P1: The expected position and thus the position for which the image upload/download failed - static const Event POSITION_MISMATCH = MAKE_EVENT(14, severity::LOW); + static const Event POSITION_MISMATCH = MAKE_EVENT(12, severity::LOW); //! [EXPORT] : [COMMENT] Specified file does not exist //!P1: Internal state of str helper - static const Event STR_HELPER_FILE_NOT_EXISTS = MAKE_EVENT(15, severity::LOW); + static const Event STR_HELPER_FILE_NOT_EXISTS = MAKE_EVENT(13, severity::LOW); //! [EXPORT] : [COMMENT] Sending packet to star tracker failed //!P1: Return code of communication interface sendMessage function //!P2: Position of upload/download packet, or address of flash write/read request for which sending failed - static const Event STR_HELPER_SENDING_PACKET_FAILED = MAKE_EVENT(16, severity::LOW); + static const Event STR_HELPER_SENDING_PACKET_FAILED = MAKE_EVENT(14, severity::LOW); //! [EXPORT] : [COMMENT] Communication interface requesting reply failed //!P1: Return code of failed request //!P1: Upload/download position, or address of flash write/read request for which transmission failed - static const Event STR_HELPER_REQUESTING_MSG_FAILED = MAKE_EVENT(17, severity::LOW); + static const Event STR_HELPER_REQUESTING_MSG_FAILED = MAKE_EVENT(15, severity::LOW); StrHelper(object_id_t objectId); virtual ~StrHelper(); @@ -116,8 +112,8 @@ public: * @param flashWriteAddress Start address of flash section to read * @param length Number of bytes to read from flash */ - ReturnValue_t startFlashRead(std::string flashReadFile_, uint8_t region, - uint32_t address, uint16_t length); + ReturnValue_t startFlashRead(std::string flashReadPath_, uint8_t region, + uint32_t address, uint32_t length); /** * @brief Can be used to interrupt a running data transfer. @@ -152,6 +148,10 @@ private: static const ReturnValue_t ADDRESS_MISMATCH = MAKE_RETURN_CODE(0xA5); //! [EXPORT] : [COMMENT] Length in flash write/read reply does not match expected length static const ReturnValue_t LENGTH_MISMATCH = MAKE_RETURN_CODE(0xA6); + //! [EXPORT] : [COMMENT] Status field in reply signals error + static const ReturnValue_t STATUS_ERROR = MAKE_RETURN_CODE(0xA7); + //! [EXPORT] : [COMMENT] Reply has invalid type ID (should be of action reply type) + static const ReturnValue_t INVALID_TYPE_ID = MAKE_RETURN_CODE(0xA8); // Size of one image part which can be sent per action request static const size_t SIZE_IMAGE_PART = 1024; diff --git a/mission/utility/Timestamp.cpp b/mission/utility/Timestamp.cpp index 36ddf4d8..c0848a59 100644 --- a/mission/utility/Timestamp.cpp +++ b/mission/utility/Timestamp.cpp @@ -12,8 +12,17 @@ Timestamp::~Timestamp() { } std::string Timestamp::str() { - return std::to_string(time.year) + "-" + std::to_string(time.month) + "-" - + std::to_string(time.day) + "--" + std::to_string(time.hour) + "-" - + std::to_string(time.minute) + "-" + std::to_string(time.second) + "-"; + timestamp << std::to_string(time.year) << "-" + << std::setw(2) << std::setfill('0') + << std::to_string(time.month) << "-" + << std::setw(2) << std::setfill('0') + << std::to_string(time.day) << "--" + << std::setw(2) << std::setfill('0') + << std::to_string(time.hour) << "-" + << std::setw(2) << std::setfill('0') + << std::to_string(time.minute) << "-" + << std::setw(2) << std::setfill('0') + << std::to_string(time.second) << "--"; + return timestamp.str(); } diff --git a/mission/utility/Timestamp.h b/mission/utility/Timestamp.h index 05dae31f..7146de53 100644 --- a/mission/utility/Timestamp.h +++ b/mission/utility/Timestamp.h @@ -2,6 +2,8 @@ #define MISSION_UTILITY_TIMESTAMP_H_ #include +#include +#include #include "fsfw/timemanager/Clock.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" @@ -21,6 +23,7 @@ public: std::string str(); private: + std::stringstream timestamp; Clock::TimeOfDay_t time; };