diff --git a/src/Services/MemMangService.cpp b/src/Services/MemMangService.cpp index a1394736fb730cd41218249c52bbf464915f39f5..060cfbfe8db250200ad3df9076756c302c6dd72d 100644 --- a/src/Services/MemMangService.cpp +++ b/src/Services/MemMangService.cpp @@ -4,7 +4,6 @@ // Define the constructors for the classes MemoryManagementService::MemoryManagementService() : rawDataMemorySubservice(this) { serviceType = 6; - std::cout << "Constructor creation debuffing MemMeang Service" << std::endl; } MemoryManagementService::RawDataMemoryManagement::RawDataMemoryManagement( @@ -47,28 +46,40 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ uint8_t *readData = nullptr; // Pointer to store the data read from the memory uint16_t iterationCount = 0; // Get the iteration count uint16_t readLength = 0; // Data length to read (updated for each new iteration) + uint16_t allocatedLength = 0; // Length allocated for the readData array uint64_t startAddress = 0; // Start address for the memory read (updated in each new iteration) uint8_t memoryID = request.readEnum8(); // Read the memory ID from the request - + // todo: Add checks depending on the memory type // Read the packet's values iterationCount = request.readUint16(); - startAddress = request.readUint64(); - readLength = request.readUint16(); // Append the data to report message report.appendEnum8(memoryID); // Memory ID report.appendUint16(iterationCount); // Iteration count - report.appendUint64(startAddress); // Start address - report.appendUint16(readLength); // Data read length - readData = static_cast<uint8_t *>( malloc(static_cast<std::size_t >(readLength)) ); - for (std::size_t i = 0; i < readLength; i++) { - readData[i] = *(reinterpret_cast<uint8_t *>(startAddress) + i); - } + // Iterate N times, as specified in the command message + for (std::size_t j = 0; j < iterationCount; j++) { + startAddress = request.readUint64(); + readLength = request.readUint16(); + + // Allocate more array space if needed + if (allocatedLength < readLength) { + readData = static_cast<uint8_t *>(realloc(readData, readLength)); + } - report.appendOctetString(readLength, readData); + // Read memory data, an octet at a time + 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); // Data read length + report.appendOctetString(readLength, readData); // Save the read data + } + // todo: implement and append the checksum part of the reporting packet mainService->storeMessage(report); // Save the report message report.resetRead(); // Reset the reading count diff --git a/src/main.cpp b/src/main.cpp index 121579e4313d2213dd97d8002b0069a9dc3d5a2b..4cd9a8ed064ae4badb2f46e5502797f43e4f8e8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,12 +29,21 @@ int main() { testService.onBoardConnection(receivedPacket); // ST[06] testing + char anotherStr[8] = "Fgthred"; + char yetAnotherStr[2] = "F"; MemoryManagementService memMangService; Message rcvPack = Message(6, 2, Message::TC, 1); rcvPack.appendEnum8(MemoryManagementService::MemoryID::RAM); // Memory ID - rcvPack.appendUint16(1); // Iteration count + rcvPack.appendUint16(3); // Iteration count rcvPack.appendUint64(reinterpret_cast<uint64_t >(string)); // Start address rcvPack.appendUint16(sizeof(string)/ sizeof(string[0])); // Data read length + + rcvPack.appendUint64(reinterpret_cast<uint64_t >(anotherStr)); + rcvPack.appendUint16(sizeof(anotherStr)/ sizeof(anotherStr[0])); + + rcvPack.appendUint64(reinterpret_cast<uint64_t >(yetAnotherStr)); + rcvPack.appendUint16(sizeof(yetAnotherStr)/ sizeof(yetAnotherStr[0])); + memMangService.rawDataMemorySubservice.dumpRawData(rcvPack); return 0;