diff --git a/CMakeLists.txt b/CMakeLists.txt index 40f819b605d47ef1805b71809de9e16eb927f141..efbae6bf223aec7241aa589287bf6b1008ec1b24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,11 +18,11 @@ add_executable(ecss_services src/main.cpp src/Message.cpp src/Service.cpp src/Services/TestService.cpp src/Services/MemoryManagementService.cpp src/Services/RequestVerificationService.cpp) -IF(EXISTS "${PROJECT_SOURCE_DIR}/lib/Catch2/CMakeLists.txt") +IF (EXISTS "${PROJECT_SOURCE_DIR}/lib/Catch2/CMakeLists.txt") add_subdirectory(lib/Catch2) add_executable(tests src/Message.cpp src/Services/TestService.cpp - src/Services/RequestVerificationService.cpp src/Services/MemoryManagementService.cpp - test/tests.cpp test/Message.cpp test/TestPlatform.cpp test/Services/TestService.cpp - test/Services/MemoryManagementService.cpp test/Services/RequestVerificationService.cpp) + src/Services/RequestVerificationService.cpp src/Services/MemoryManagementService.cpp + test/tests.cpp test/Message.cpp test/TestPlatform.cpp test/Services/TestService.cpp + test/Services/MemoryManagementService.cpp test/Services/RequestVerificationService.cpp) target_link_libraries(tests Catch2::Catch2) -ENDIF() +ENDIF () diff --git a/inc/Services/MemoryManagementService.hpp b/inc/Services/MemoryManagementService.hpp index 1d2de9be32b3589b84e84b07007f05380e81a062..41a8094b79468cd88f52a13f2aa39b20efaa5014 100644 --- a/inc/Services/MemoryManagementService.hpp +++ b/inc/Services/MemoryManagementService.hpp @@ -1,6 +1,13 @@ #ifndef ECSS_SERVICES_MEMMANGSERVICE_HPP #define ECSS_SERVICES_MEMMANGSERVICE_HPP +// Memory limits definitions +#define FIRST_ADRESS_FLASH 0x08000000 +#define LAST_ADDRESS_FLASH 0x0801FFFF // todo: Define the last memory address based on the MCU +#define FIRST_ADDRESS_SRAM 0x20000000 +#define SRAM_MEMORY_SIZE 16 // Specify the RAM size in kBytes + + #include "Service.hpp" #include <memory> #include <iostream> @@ -36,6 +43,7 @@ public: * @details This function loads new values to memory data areas * specified in the request * @param request: Provide the received message as a parameter + * @todo Only allow aligned memory address to be start addresses */ void loadRawData(Message &request); @@ -47,8 +55,21 @@ public: * @param request: Provide the received message as a parameter * @todo In later embedded version, implement error checking for address validity for * different memory types + * @todo Only allow aligned memory address to be start addresses */ void dumpRawData(Message &request); + + /** + * TC[6,9] check raw memory data + * + * @details This function reads the raw data from the specified memory and + * triggers a TM[6,10] report + * @param request: Provide the received message as a parameter + * @todo In later embedded version, implement error checking for address validity for + * different memory types + * @todo Only allow aligned memory address to be start addresses + */ + void checkRawData(Message &request); } rawDataMemorySubservice; }; diff --git a/src/Services/MemoryManagementService.cpp b/src/Services/MemoryManagementService.cpp index cd84b3dd01df44dac75852009ec90c587c500889..9cff6da2828649a175cb3b8797b6abc101d06f08 100644 --- a/src/Services/MemoryManagementService.cpp +++ b/src/Services/MemoryManagementService.cpp @@ -86,3 +86,45 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ mainService.storeMessage(report); // Save the report message request.resetRead(); // Reset the reading count } + +void MemoryManagementService::RawDataMemoryManagement::checkRawData(Message &request) { + // Check if we have the correct packet + assert(request.serviceType == 6); + assert(request.messageType == 9); + + // Create the report message object of telemetry message subtype 10 + Message report = mainService.createTM(10); + + // Variable declaration + uint8_t readData[ECSS_MAX_STRING_SIZE]; // Preallocate the array + + uint8_t memoryID = request.readEnum8(); // Read the memory ID from the request + // todo: Add checks depending on the memory type + + uint16_t iterationCount = request.readUint16(); // Get the iteration count + + // Append the data to report message + report.appendEnum8(memoryID); // Memory ID + report.appendUint16(iterationCount); // Iteration count + + // Iterate N times, as specified in the command message + for (std::size_t j = 0; j < iterationCount; j++) { + uint64_t startAddress = request.readUint64(); // Data length to read + uint16_t readLength = request.readUint16(); // Start address for the memory read + + // Read memory data and save them for checksum calculation + for (std::size_t i = 0; i < readLength; i++) { + readData[i] = *(reinterpret_cast<uint8_t *>(startAddress) + i); + } + + // This part is repeated N-times (N = iteration count) + report.appendUint64(startAddress); // Start address + report.appendUint16(readLength); // Save the read data + // todo: Calculate and append checksum in the report + //report.appendBits(16, /* checksum bits */); + } + // todo: implement and append the checksum part of the reporting packet + + mainService.storeMessage(report); // Save the report message + request.resetRead(); // Reset the reading count +}