diff --git a/CMakeLists.txt b/CMakeLists.txt index f667453e666b9f7af0db4d4ecc632c2077b7202a..810fb26f2782e19125dada4b8d651c4025ad71fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,10 +14,10 @@ add_custom_target(check WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/ci") # Specify the .cpp files for the executables -add_executable(ecss_services src/main.cpp src/Message.cpp src/Service.cpp src/Services/TestService.cpp src/Services/MemMangService.cpp) +add_executable(ecss_services src/main.cpp src/Message.cpp src/Service.cpp src/Services/TestService.cpp src/Services/MemoryManagementService.cpp) 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/MemMangService.cpp test/tests.cpp test/Message.cpp test/TestPlatform.cpp test/Services/TestService.cpp test/Services/MemMangService.cpp) +add_executable(tests src/Message.cpp src/Services/TestService.cpp src/Services/MemoryManagementService.cpp test/tests.cpp test/Message.cpp test/TestPlatform.cpp test/Services/TestService.cpp test/Services/MemoryManagementService.cpp) target_link_libraries(tests Catch2::Catch2) ENDIF() diff --git a/inc/Message.hpp b/inc/Message.hpp index 53bfb031d2e13fe83ccdb5b5cb57d1f5b884ae0d..ce2c59444540b6becd2955b73842abf58e723cbf 100644 --- a/inc/Message.hpp +++ b/inc/Message.hpp @@ -194,7 +194,7 @@ public: */ void appendUint64(uint64_t value) { appendWord(static_cast<uint32_t >(value >> 32)); - return appendWord(static_cast<uint32_t >(value)); + appendWord(static_cast<uint32_t >(value)); } /** @@ -383,16 +383,15 @@ public: /** * Fetches a N-byte string from the current position in the message * - * * PTC = 7, PFC = 0 */ - void readOctetString(uint8_t *byteString, uint16_t size) { + void readOctetString(uint8_t *byteString, uint16_t size) { assert(size < ECSS_MAX_STRING_SIZE); for (std::size_t i = 0; i < size; i++) { byteString[i] = readByte(); } - } + } /** * Reset the message reading status, and start reading data from it again diff --git a/inc/Services/MemMangService.hpp b/inc/Services/MemoryManagementService.hpp similarity index 91% rename from inc/Services/MemMangService.hpp rename to inc/Services/MemoryManagementService.hpp index 3f4030b6ef178a2f50ec03f3078e7db63b8f5078..1d2de9be32b3589b84e84b07007f05380e81a062 100644 --- a/inc/Services/MemMangService.hpp +++ b/inc/Services/MemoryManagementService.hpp @@ -25,10 +25,11 @@ public: */ class RawDataMemoryManagement { private: - MemoryManagementService *mainService; // Used to access main class's members + MemoryManagementService &mainService; // Used to access main class's members public: - explicit RawDataMemoryManagement(MemoryManagementService *parent); + explicit RawDataMemoryManagement(MemoryManagementService &parent); + /** * TC[6,2] load raw values to memory * diff --git a/src/Services/MemMangService.cpp b/src/Services/MemoryManagementService.cpp similarity index 91% rename from src/Services/MemMangService.cpp rename to src/Services/MemoryManagementService.cpp index d5d0bb7ee2bf36f543a77f726264d9d33af2a2a8..72c086a5235e66cb800df007d17b73dbdd046849 100644 --- a/src/Services/MemMangService.cpp +++ b/src/Services/MemoryManagementService.cpp @@ -1,14 +1,14 @@ -#include "Services/MemMangService.hpp" +#include "Services/MemoryManagementService.hpp" #include <iostream> #include <cerrno> // Define the constructors for the classes -MemoryManagementService::MemoryManagementService() : rawDataMemorySubservice(this) { +MemoryManagementService::MemoryManagementService() : rawDataMemorySubservice(*this) { serviceType = 6; } MemoryManagementService::RawDataMemoryManagement::RawDataMemoryManagement( - MemoryManagementService *parent) : mainService(parent) {} + MemoryManagementService &parent) : mainService(parent) {} // Function declarations for the raw data memory management subservice @@ -38,6 +38,7 @@ void MemoryManagementService::RawDataMemoryManagement::loadRawData(Message &requ // Allocate more array space if needed if (allocatedLength < dataLength) { + // todo: In embedded implementation use the malloc, due to FreeRTOS constraints tempMemory = static_cast<uint8_t *>(realloc(readData, dataLength)); if (tempMemory == nullptr) { // todo: Add error logging and reporting @@ -68,7 +69,7 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ assert(request.messageType == 5); // Create the report message object of telemetry message subtype 6 - Message report = mainService->createTM(6); + Message report = mainService.createTM(6); // Variable declaration uint8_t *readData = nullptr, *tempMemory = nullptr;; // Pointer to store the read data @@ -89,6 +90,7 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ // Allocate more array space if needed if (allocatedLength < readLength) { + // todo: In embedded implementation use the malloc, due to FreeRTOS constraints tempMemory = static_cast<uint8_t *>(realloc(readData, readLength)); if (tempMemory == nullptr) { // todo: Add error logging and reporting @@ -111,7 +113,7 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ } // todo: implement and append the checksum part of the reporting packet - mainService->storeMessage(report); // Save the report message + mainService.storeMessage(report); // Save the report message request.resetRead(); // Reset the reading count free(readData); // Free the allocated memory } diff --git a/src/main.cpp b/src/main.cpp index 108bd54544b93bfcf5f8e062a9e23305f55cc829..d1a628e2f096860828513438193cf7579d694aba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include <iostream> #include <Services/TestService.hpp> #include "Message.hpp" -#include "Services/MemMangService.hpp" +#include "Services/MemoryManagementService.hpp" int main() { Message packet = Message(0, 0, Message::TC, 1); diff --git a/test/Services/MemMangService.cpp b/test/Services/MemoryManagementService.cpp similarity index 98% rename from test/Services/MemMangService.cpp rename to test/Services/MemoryManagementService.cpp index 8d7f63f4c4dfd62eaf3d6ed82ba5d71a28b503ad..824866cb0891f0a3516495e67e993e1ffca7766e 100644 --- a/test/Services/MemMangService.cpp +++ b/test/Services/MemoryManagementService.cpp @@ -1,5 +1,5 @@ #include <catch2/catch.hpp> -#include <Services/MemMangService.hpp> +#include <Services/MemoryManagementService.hpp> #include <Message.hpp> #include "ServiceTests.hpp"