diff --git a/inc/Services/MemMangService.hpp b/inc/Services/MemMangService.hpp index 5d8cd70fc78f57b763a4a3a2ea7bea43b0588b3a..e58765b7f1f44262f8e5840d5680fb94bd748e63 100644 --- a/inc/Services/MemMangService.hpp +++ b/inc/Services/MemMangService.hpp @@ -2,18 +2,50 @@ #define ECSS_SERVICES_MEMMANGSERVICE_HPP #include "Service.hpp" +#include <memory> -class MemMangService : public Service { +class MemoryManagementService : public Service { public: - MemMangService() { + MemoryManagementService() { serviceType = 6; } - void loadRawMemData(Message &requset); + // Memory type ID's + enum MemoryID { + RAM = 0, + FLASH = 1, + EXTERNAL = 2 + }; - void dumpRawMemData(Message &request); + class RawDataMemoryManagement { + private: + /** + * TM[6,6] dumped raw memory data report + * + * @details This report is triggered through TC[6,5] + */ + void dumpedRawDataReport(); + MemoryManagementService *mainService; // Used to access main class's members - uint32_t dumpedRawMemData(); + public: + /** + * TC[6,2] load raw values to memory + * + * @details This function loads new values to memory data areas + * specified in the request + * @param request: Provide the received message as a parameter + */ + void loadRawData(Message &request); + + /** + * TC[6,5] read raw memory values + * + * @details This function reads the raw data from the RAM memory and + * triggers a TM[6,6] report + * @param request: Provide the received message as a parameter + */ + void dumpRawData(Message &request); + }; }; #endif //ECSS_SERVICES_MEMMANGSERVICE_HPP diff --git a/src/Services/MemMangService.cpp b/src/Services/MemMangService.cpp index c2bef396b0e4f9bfb9f72ef5383f01907d983557..1ac3df71392401669f185ca4bec7c5a718aa9ba9 100644 --- a/src/Services/MemMangService.cpp +++ b/src/Services/MemMangService.cpp @@ -1,13 +1,40 @@ #include "Services/MemMangService.hpp" +#include <iostream> -void MemMangService::loadRawMemData(Message &requset) { +void MemoryManagementService::RawDataMemoryManagement::loadRawData(Message &request) { } -void MemMangService::dumpRawMemData(Message &request) { +void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &request) { + Message report = mainService->createTM(6); // Create the report message object of telemetry message subtype 6 + uint8_t iterationCount = 0; // Get the iteration count + uint8_t *readData = nullptr; // Pointer to store the data read from the memory + uint16_t readLength = 0; // Data length to read (updated for each new iteration) + uint32_t startAddress = 0; // Start address for the memory read (updated in each new iteration) + + // Read the packet's values + iterationCount = request.readUint8(); + startAddress = request.readUint32(); + readLength = request.readUint16(); + + readData = (uint8_t *)malloc(static_cast<std::size_t >(readLength + 1)); + for (std::size_t i = 0; i < readLength; i++) { + readData[i] = *(uint8_t *)(startAddress + i); + } + readData[readLength] = '\0'; + + report.appendUint8(iterationCount); // Iteration count + report.appendUint32(startAddress); // Start address + report.appendUint16(readLength); // Data read length + + //report.appendString(readLength, static_cast<const char *>(readData)); + // todo: add the rest of data fields + + // todo: complete the function and fully specify it + mainService->storeMessage(report); } -uint32_t MemMangService::dumpedRawMemData() { +void MemoryManagementService::RawDataMemoryManagement::dumpedRawDataReport() { } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index cc24193a9f71cec7719e7ce55e85cecf1e3aa968..9d72df8f242e6f04b0c81e46ed3b2f123373bebc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include <iostream> #include <Services/TestService.hpp> #include "Message.hpp" +#include "Services/MemMangService.hpp" int main() { Message packet = Message(0, 0, Message::TC, 1); @@ -27,5 +28,13 @@ int main() { receivedPacket.appendUint16(7); testService.onBoardConnection(receivedPacket); + // ST[06] testing + MemoryManagementService::RawDataMemoryManagement memMangService; + Message rcvPack = Message(6, 2, Message::TC, 1); + rcvPack.appendUint8(1); // Iteration count + rcvPack.appendUint32(0x45327845); // Start address + rcvPack.appendUint16(0); // Data read length + memMangService.dumpRawData(rcvPack); + return 0; }