diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d08363d95eae3c3a0ae8689310404d58d4bf678..71a9f50c7e7ae4cccb7cae6072a0baa40e842cd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,22 +17,19 @@ add_custom_target(check add_library(common OBJECT src/ErrorHandler.cpp src/Message.cpp - src/Services/EventReportService.cpp src/MessageParser.cpp src/Helpers/CRCHelper.cpp src/Services/EventReportService.cpp src/Services/MemoryManagementService.cpp src/Services/ParameterService.cpp src/Services/RequestVerificationService.cpp - src/Services/TestService.cpp - ) + src/Services/TestService.cpp) # Specify the .cpp files for the executables add_executable(ecss_services src/main.cpp $<TARGET_OBJECTS:common> - src/Platform/x86/Service.cpp - ) + src/Platform/x86/Service.cpp) IF (EXISTS "${PROJECT_SOURCE_DIR}/lib/Catch2/CMakeLists.txt") # Gather all the .cpp files corresponding to tests @@ -46,4 +43,4 @@ IF (EXISTS "${PROJECT_SOURCE_DIR}/lib/Catch2/CMakeLists.txt") ${test_SRC}) target_link_libraries(tests Catch2::Catch2) -ENDIF() +ENDIF () diff --git a/inc/ECSS_Definitions.hpp b/inc/ECSS_Definitions.hpp index baee71ec54496ccaf12154891507276735a0640f..3a2eeedba9ebd9fd6e080c054e485a7936880ae5 100644 --- a/inc/ECSS_Definitions.hpp +++ b/inc/ECSS_Definitions.hpp @@ -6,6 +6,9 @@ #define ECSS_MAX_STRING_SIZE 256 +// 7.4.1 +#define CCSDS_PACKET_VERSION 0 + // 7.4.4.1c #define ECSS_PUS_VERSION 2 diff --git a/inc/ErrorHandler.hpp b/inc/ErrorHandler.hpp index 56223cacaecfa11b03c0a12b0e3626d0d3d0b7c0..b18ae74466fa8750ca1c4a7b9e4e68eeec3a6062 100644 --- a/inc/ErrorHandler.hpp +++ b/inc/ErrorHandler.hpp @@ -81,7 +81,15 @@ public: * changes. */ enum ExecutionErrorType { - UnknownExecutionError = 0 + UnknownExecutionError = 0, + /** + * Checksum comparison failed + */ + ChecksumFailed = 1, + /** + * Address of a memory is out of the defined range for the type of memory + */ + AddressOutOfRange = 2, }; /** diff --git a/inc/Platform/STM32F7/MemoryAddressLimits.hpp b/inc/Platform/STM32F7/MemoryAddressLimits.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e30651f9373d45912404ca7f33ceceed060b2002 --- /dev/null +++ b/inc/Platform/STM32F7/MemoryAddressLimits.hpp @@ -0,0 +1,18 @@ +#ifndef ECSS_SERVICES_MEMORYADDRESSLIMITS_STM32F7_HPP +#define ECSS_SERVICES_MEMORYADDRESSLIMITS_STM32F7_HPP + +// Memory limits definitions +#define DTCMRAM_LOWER_LIM 0x20000000UL +#define DTCMRAM_UPPER_LIM 0x20020000UL +#define ITCMRAM_LOWER_LIM 0x00000000UL +#define ITCMRAM_UPPER_LIM 0x00010000UL +#define RAM_D1_LOWER_LIM 0x24000000UL +#define RAM_D1_UPPER_LIM 0x24080000UL +#define RAM_D2_LOWER_LIM 0x30000000UL +#define RAM_D2_UPPER_LIM 0x30048000UL +#define RAM_D3_LOWER_LIM 0x38000000UL +#define RAM_D3_UPPER_LIM 0x38010000UL +#define FLASH_LOWER_LIM 0x08000000UL +#define FLASH_UPPER_LIM 0x08200000UL + +#endif //ECSS_SERVICES_MEMORYADDRESSLIMITS_STM32F7_HPP diff --git a/inc/Services/EventReportService.hpp b/inc/Services/EventReportService.hpp index 454bd24b828d7dd30cfce1d8f83ca435facf8f3b..52a2b51798b1065681592a169074d72739f9398b 100644 --- a/inc/Services/EventReportService.hpp +++ b/inc/Services/EventReportService.hpp @@ -20,9 +20,20 @@ private: static const uint16_t numberOfEvents = 7; std::bitset<numberOfEvents> stateOfEvents; public: + // Variables that count the event occurrences per severity level + uint16_t lowSeverityReportsCount; + uint16_t mediumSeverityReportCount; + uint16_t highSeverityReportCount; + + uint16_t disabledEventsCount; + EventReportService() { stateOfEvents.set(); serviceType = 5; + lowSeverityReportsCount = 0; + mediumSeverityReportCount = 0; + highSeverityReportCount = 0; + disabledEventsCount = 0; } /** @@ -145,6 +156,13 @@ public: std::bitset<numberOfEvents> getStateOfEvents() { return stateOfEvents; } + /** + * Getter for count of disabled events + */ + uint16_t getDisabledEventsCount(){ + uint16_t numberOfDisabledEvents = stateOfEvents.size() - stateOfEvents.count(); + return numberOfDisabledEvents; + } }; diff --git a/inc/Services/MemoryManagementService.hpp b/inc/Services/MemoryManagementService.hpp index 1d2de9be32b3589b84e84b07007f05380e81a062..5cd3c16da1f43a2f62d741553052dbae2eeb319c 100644 --- a/inc/Services/MemoryManagementService.hpp +++ b/inc/Services/MemoryManagementService.hpp @@ -1,17 +1,25 @@ #ifndef ECSS_SERVICES_MEMMANGSERVICE_HPP #define ECSS_SERVICES_MEMMANGSERVICE_HPP -#include "Service.hpp" #include <memory> #include <iostream> +#include "Service.hpp" +#include "Helpers/CRCHelper.hpp" +#include "ErrorHandler.hpp" +#include "Platform/STM32F7/MemoryAddressLimits.hpp" + class MemoryManagementService : public Service { public: // Memory type ID's enum MemoryID { - RAM = 0, - FLASH = 1, - EXTERNAL = 2 + DTCMRAM = 0, + RAM_D1, + RAM_D2, + RAM_D3, + ITCMRAM, + FLASH, + EXTERNAL }; MemoryManagementService(); @@ -35,7 +43,8 @@ public: * * @details This function loads new values to memory data areas * specified in the request - * @param request: Provide the received message as a parameter + * @param request Provide the received message as a parameter + * @todo Only allow aligned memory address to be start addresses */ void loadRawData(Message &request); @@ -44,12 +53,47 @@ public: * * @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 + * @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; + +private: + /** + * Check whether the provided address is valid or not, based on the defined limit values + * + * @param memId The ID of the memory to check is passed + * @param address Takes the address to be checked for validity + */ + bool addressValidator(MemoryManagementService::MemoryID memId, uint64_t address); + + /** + * Check if the provided memory ID is valid + * + * @param memId The memory ID for validation + */ + bool memoryIdValidator(MemoryManagementService::MemoryID memId); + + /** + * Validate the data according to checksum calculation + * + */ + bool dataValidator(const uint8_t *data, uint16_t checksum, uint16_t length); }; #endif //ECSS_SERVICES_MEMMANGSERVICE_HPP diff --git a/inc/Services/RequestVerificationService.hpp b/inc/Services/RequestVerificationService.hpp index 67b0f5b102028497d04322f26121bef7cbc67c41..a664e1147414260a3ca07118670f58d0869dc28b 100644 --- a/inc/Services/RequestVerificationService.hpp +++ b/inc/Services/RequestVerificationService.hpp @@ -6,12 +6,13 @@ /** * Implementation of the ST[01] request verification service * - * Note: ST[01]'s messages should not contain calls to the ErrorHandler, as the ErrorHandler - * calls ST[01] functions again. Doing so would risk an infinite recursive loop. + * Note:For the time being, the cause(routing, acceptance, execution), that functions of ST[01] + * should be called, hasn't been implemented yet. In main.cpp there are some random calls with + * dummy values. * * @todo All telemetry packets shall have a telemetry packet secondary header - * @todo See if it would be more efficient to use Messages as arguments instead of individual - * parameters + * @todo See if the deduced data defined from the standard should still be ignored. This deduced + * data exists only in reports that send failure signs(for example the TM[1,2]) */ class RequestVerificationService : public Service { public: @@ -21,79 +22,53 @@ public: /** * TM[1,1] successful acceptance verification report - * Send report when the Cubesat accepts successfully commands * - * Note:The parameters are the necessary information, defined from the standard, that the report - * should contain + * @param request Contains the necessary data to send the report. + * The data is actually some data members of Message that contain the basic info + * of the telecommand packet that accepted successfully * - * @param apid Application process ID - * @param seqFlag Sequence flags - * @param packetSeqCount Packet sequence count */ - void successAcceptanceVerification(Message::PacketType packetType, bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, uint16_t packetSeqCount); + void successAcceptanceVerification(const Message &request); /** * TM[1,2] failed acceptance verification report - *Send report when the Cubesat don't accept commands * - * Note:The parameters are the necessary information, defined from the standard, that the report - * should contain - * - * @param apid Application process ID - * @param seqFlag Sequence flags - * @param packetSeqCount Packet sequence count + * @param request Contains the necessary data to send the report. + * The data is actually some data members of Message that contain the basic + * info of the telecommand packet that failed to be accepted */ - void failAcceptanceVerification(Message::PacketType packetType, bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, uint16_t packetSeqCount, - uint16_t errorCode); + void failAcceptanceVerification(const Message &request); /** - * TM[1,7] successful completion of execution verification report - * Send report when the Cubesat completes an execution + * TM[1,7] successful completion of execution verification report * - * Note:The parameters are the necessary information, defined from the standard, that the report - * should contain + * @param request Contains the necessary data to send the report. + * The data is actually data members of Message that contain the basic info of the + * telecommand packet that executed successfully * - * @param apid Application process ID - * @param seqFlag Sequence flags - * @param packetSeqCount Packet sequence count - */ - void successExecutionVerification(Message::PacketType packetType, bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, uint16_t packetSeqCount); + */ + void successExecutionVerification(const Message &request); /** - * TM[1,8] failed completion of execution verification report - * Send report when the Cubesat don't complete an execution + * TM[1,8] failed completion of execution verification report * - * Note:The parameters are the necessary information, defined from the standard, that the report - * should contain + * @param request Contains the necessary data to send the report. + * The data is actually some data members of Message that contain the basic info of the + * telecommand packet that failed to be executed * - * @param apid Application process ID - * @param seqFlag Sequence flags - * @param packetSeqCount Packet sequence count - */ - void failExecutionVerification(Message::PacketType packetType, - bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, uint16_t packetSeqCount, - uint16_t errorCode); + */ + void failExecutionVerification(const Message &request); /** - * TM[1,10] failed routing verification report - * Send report when the routing of a request has failed + * TM[1,10] failed routing verification report * - * Note:The parameters are the necessary information, defined from the standard, that the report - * should contain + * @param request Contains the necessary data to send the report. + * The data is actually some data members of Message that contain the basic info of the + * telecommand packet that failed the routing * - * @param apid Application process ID - * @param seqFlag Sequence flags - * @param packetSeqCount Packet sequence count - */ - void failRoutingVerification(Message::PacketType packetType, - bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, uint16_t packetSeqCount, - uint16_t errorCode); + */ + void failRoutingVerification(const Message &request); /** * It is responsible to call the suitable function that execute the proper subservice. The @@ -104,7 +79,7 @@ public: * * @todo Error handling for the switch() in the implementation of this execute function */ - void execute(Message &message); + void execute(const Message &message); /** * The purpose of this instance is to access the execute function of this service when a diff --git a/src/ErrorHandler.cpp b/src/ErrorHandler.cpp index d278b1edcd06e67b2c24faea34c6b9f45f0975df..d689ab1a1835c08c4a2908c6822cd1513b3ac422 100644 --- a/src/ErrorHandler.cpp +++ b/src/ErrorHandler.cpp @@ -9,42 +9,21 @@ static RequestVerificationService requestVerificationService; template<> void ErrorHandler::reportError(const Message &message, AcceptanceErrorType errorCode) { - requestVerificationService.failAcceptanceVerification( - message.packetType, - true, - message.applicationId, - ECSS_SEQUENCE_FLAGS, - message.packetSequenceCount, - static_cast<uint16_t>(errorCode) - ); + requestVerificationService.failAcceptanceVerification(message); logError(message, errorCode); } template<> void ErrorHandler::reportError(const Message &message, ExecutionErrorType errorCode) { - requestVerificationService.failExecutionVerification( - message.packetType, - true, - message.applicationId, - ECSS_SEQUENCE_FLAGS, - message.packetSequenceCount, - static_cast<uint16_t>(errorCode) - ); + requestVerificationService.failExecutionVerification(message); logError(message, errorCode); } template<> void ErrorHandler::reportError(const Message &message, RoutingErrorType errorCode) { - requestVerificationService.failRoutingVerification( - message.packetType, - true, - message.applicationId, - ECSS_SEQUENCE_FLAGS, - message.packetSequenceCount, - static_cast<uint16_t>(errorCode) - ); + requestVerificationService.failRoutingVerification(message); logError(message, errorCode); } diff --git a/src/Platform/x86/Service.cpp b/src/Platform/x86/Service.cpp index 07403e438e1ff884b430c5eafff7d92a7d63c63c..ff9d9d95de57f749996cb8a2fcd7853cebda7813 100644 --- a/src/Platform/x86/Service.cpp +++ b/src/Platform/x86/Service.cpp @@ -4,7 +4,9 @@ void Service::storeMessage(const Message &message) { // Just print it to the screen - std::cout << "New " << ((message.packetType == Message::TM) ? "TM" : "TC") << "[" << std::dec + std::cout << "New " << ((message.packetType == Message::TM) ? "TM" : "TC") << "[" + << std::hex + // << std::dec << static_cast<int>(message.serviceType) << "," << static_cast<int>(message.messageType) << "] message!\n"; //std::cout << std::hex << std::setfill('0') << std::setw(2); diff --git a/src/Services/EventReportService.cpp b/src/Services/EventReportService.cpp index 4f9d50be6627a4ddc03c0e33629326b66aa1fccf..f30a875bd36d15224ed1e7fb2e6d167f982aad39 100644 --- a/src/Services/EventReportService.cpp +++ b/src/Services/EventReportService.cpp @@ -20,6 +20,7 @@ void EventReportService::lowSeverityAnomalyReport(Event eventID, const uint8_t *data, uint8_t length) { // TM[5,2] + lowSeverityReportsCount++; Message report = createTM(2); report.appendEnum16(eventID); report.appendString(length, data); @@ -30,6 +31,7 @@ EventReportService::lowSeverityAnomalyReport(Event eventID, const uint8_t *data, void EventReportService::mediumSeverityAnomalyReport(Event eventID, const uint8_t *data, uint8_t length) { // TM[5,3] + mediumSeverityReportCount++; Message report = createTM(3); report.appendEnum16(eventID); report.appendString(length, data); @@ -41,6 +43,7 @@ void EventReportService::highSeverityAnomalyReport(Event eventID, const uint8_t *data, uint8_t length) { // TM[5,4] + highSeverityReportCount++; Message report = createTM(4); report.appendEnum16(eventID); report.appendString(length, data); diff --git a/src/Services/MemoryManagementService.cpp b/src/Services/MemoryManagementService.cpp index cd84b3dd01df44dac75852009ec90c587c500889..05bd9bdfea50fb1de15ef10b3f8daf919d701c50 100644 --- a/src/Services/MemoryManagementService.cpp +++ b/src/Services/MemoryManagementService.cpp @@ -25,25 +25,49 @@ void MemoryManagementService::RawDataMemoryManagement::loadRawData(Message &requ assert(request.serviceType == 6); assert(request.messageType == 2); - // Variable declaration - uint8_t readData[ECSS_MAX_STRING_SIZE]; // Preallocate the array - - uint8_t memoryID = request.readEnum8(); // Read the memory ID from the request - uint16_t iterationCount = request.readUint16(); // Get the iteration count - - if (memoryID == MemoryManagementService::MemoryID::RAM) { - for (std::size_t j = 0; j < iterationCount; j++) { - uint64_t startAddress = request.readUint64(); // Start address of the memory - uint16_t dataLength = request.readOctetString(readData); // Data length to load - // todo: Error logging has to be included, if memory allocation above fails - // todo: Continue only if the checksum passes (when the checksum will be implemented) - - for (std::size_t i = 0; i < dataLength; i++) { - *(reinterpret_cast<uint8_t *>(startAddress) + i) = readData[i]; + // Read the memory ID from the request + auto memoryID = MemoryManagementService::MemoryID(request.readEnum8()); + + // Check for a valid memory ID first + if (mainService.memoryIdValidator(MemoryManagementService::MemoryID(memoryID))) { + // Variable declaration + uint8_t readData[ECSS_MAX_STRING_SIZE]; // Preallocate the array + uint16_t iterationCount = request.readUint16(); // Get the iteration count + + if (memoryID == MemoryManagementService::MemoryID::FLASH) { + // todo: Define FLASH specific access code when we transfer to embedded + } else { + for (std::size_t j = 0; j < iterationCount; j++) { + uint64_t startAddress = request.readUint64(); // Start address of the memory + uint16_t dataLength = request.readOctetString(readData); // Data length to load + uint16_t checksum = request.readBits(16); // Get the CRC checksum from the message + + // Continue only if the checksum passes + if (mainService.dataValidator(readData, checksum, dataLength)) { + if (mainService.addressValidator(memoryID, startAddress) && + mainService.addressValidator(memoryID, startAddress + dataLength)) { + for (std::size_t i = 0; i < dataLength; i++) { + *(reinterpret_cast<uint8_t *>(startAddress) + i) = readData[i]; + } + + // Read the loaded data for checksum validation and perform a check + for (std::size_t i = 0; i < dataLength; i++) { + readData[i] = *(reinterpret_cast<uint8_t *>(startAddress) + i); + } + if (checksum != CRCHelper::calculateCRC(readData, dataLength)) { + ErrorHandler::reportError(request, ErrorHandler::ChecksumFailed); + } + } else { + ErrorHandler::reportError(request, ErrorHandler::ChecksumFailed); + } + } else { + ErrorHandler::reportError(request, ErrorHandler::ChecksumFailed); + continue; // Continue to the next command + } } } - } else if (memoryID == MemoryManagementService::MemoryID::FLASH) { - // todo: Define FLASH specific access code when we transfer to embedded + } else { + // todo: Send a failed start of execution } } @@ -54,35 +78,156 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ // Create the report message object of telemetry message subtype 6 Message report = mainService.createTM(6); + uint8_t memoryID = request.readEnum8(); // Read the memory ID from the request - // Variable declaration - uint8_t readData[ECSS_MAX_STRING_SIZE]; // Preallocate the array + // Check for a valid memory ID first + if (mainService.memoryIdValidator(MemoryManagementService::MemoryID(memoryID))) { + // Variable declaration + uint8_t readData[ECSS_MAX_STRING_SIZE]; // Preallocate the array + uint16_t iterationCount = request.readUint16(); // Get the iteration count - uint8_t memoryID = request.readEnum8(); // Read the memory ID from the request - // todo: Add checks depending on the memory type + // Append the data to report message + report.appendEnum8(memoryID); // Memory ID + report.appendUint16(iterationCount); // Iteration count - uint16_t iterationCount = request.readUint16(); // Get the 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, an octet at a time, checking for a valid address first + if (mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), + startAddress) && + mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), + startAddress + readLength)) { + 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.appendOctetString(readLength, readData); // Save the read data + report.appendBits(16, CRCHelper::calculateCRC(readData, readLength)); + } else { + ErrorHandler::reportError(request, ErrorHandler::AddressOutOfRange); + } + } - // Append the data to report message - report.appendEnum8(memoryID); // Memory ID - report.appendUint16(iterationCount); // Iteration count + mainService.storeMessage(report); // Save the report message + request.resetRead(); // Reset the reading count + } else { + // todo: Send a failed start of execution + } +} - // 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 +void MemoryManagementService::RawDataMemoryManagement::checkRawData(Message &request) { + // Check if we have the correct packet + assert(request.serviceType == 6); + assert(request.messageType == 9); - // 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); + // Create the report message object of telemetry message subtype 10 + Message report = mainService.createTM(10); + uint8_t memoryID = request.readEnum8(); // Read the memory ID from the request + + if (mainService.memoryIdValidator(MemoryManagementService::MemoryID(memoryID))) { + // Variable declaration + uint8_t readData[ECSS_MAX_STRING_SIZE]; // Preallocate the array + 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 + + // Check whether the first and the last addresses are within the limits + if (mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), + startAddress) && + mainService.addressValidator(MemoryManagementService::MemoryID(memoryID), + startAddress + readLength)) { + // 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 + report.appendBits(16, CRCHelper::calculateCRC(readData, readLength)); // Append CRC + } else { + ErrorHandler::reportError(request, ErrorHandler::AddressOutOfRange); + } } - // This part is repeated N-times (N = iteration count) - report.appendUint64(startAddress); // Start address - report.appendOctetString(readLength, readData); // Save the read data + + mainService.storeMessage(report); // Save the report message + request.resetRead(); // Reset the reading count + } else { + // todo: Send a failed start of execution report + } +} + + +// Private function declaration section +bool MemoryManagementService::addressValidator( + MemoryManagementService::MemoryID memId, uint64_t address) { + bool validIndicator = false; + + switch (memId) { + case MemoryManagementService::MemoryID::DTCMRAM: + if (address >= DTCMRAM_LOWER_LIM && address <= DTCMRAM_UPPER_LIM) { + validIndicator = true; + } + break; + case MemoryManagementService::MemoryID::ITCMRAM: + if (address >= ITCMRAM_LOWER_LIM && address <= ITCMRAM_UPPER_LIM) { + validIndicator = true; + } + break; + case MemoryManagementService::MemoryID::RAM_D1: + if (address >= RAM_D1_LOWER_LIM && address <= RAM_D1_UPPER_LIM) { + validIndicator = true; + } + break; + case MemoryManagementService::MemoryID::RAM_D2: + if (address >= RAM_D2_LOWER_LIM && address <= RAM_D2_UPPER_LIM) { + validIndicator = true; + } + break; + case MemoryManagementService::MemoryID::RAM_D3: + if (address >= RAM_D3_LOWER_LIM && address <= RAM_D3_UPPER_LIM) { + validIndicator = true; + } + break; + case MemoryManagementService::MemoryID::FLASH: + if (address >= FLASH_LOWER_LIM && address <= FLASH_UPPER_LIM) { + validIndicator = true; + } + break; + + default: + validIndicator = true; // todo: Implemented so addresses from PC can be read. Remove. + break; } - // todo: implement and append the checksum part of the reporting packet - mainService.storeMessage(report); // Save the report message - request.resetRead(); // Reset the reading count + return validIndicator; +} + +inline bool MemoryManagementService::memoryIdValidator( + MemoryManagementService::MemoryID memId) { + return (memId == MemoryManagementService::MemoryID::RAM_D1) || + (memId == MemoryManagementService::MemoryID::RAM_D2) || + (memId == MemoryManagementService::MemoryID::RAM_D3) || + (memId == MemoryManagementService::MemoryID::DTCMRAM) || + (memId == MemoryManagementService::MemoryID::ITCMRAM) || + (memId == MemoryManagementService::MemoryID::FLASH) || + (memId == MemoryManagementService::MemoryID::EXTERNAL); +} + +inline bool MemoryManagementService::dataValidator(const uint8_t *data, uint16_t checksum, + uint16_t length) { + return (checksum == CRCHelper::calculateCRC(data, length)); } diff --git a/src/Services/RequestVerificationService.cpp b/src/Services/RequestVerificationService.cpp index 38de1e70e0b1e646323ca66c652e3807c783f008..0e08b3e71ab47f462a306a8c7c2bde193a68a9dc 100644 --- a/src/Services/RequestVerificationService.cpp +++ b/src/Services/RequestVerificationService.cpp @@ -1,146 +1,103 @@ #include "Services/RequestVerificationService.hpp" #include "Message.hpp" -void RequestVerificationService::successAcceptanceVerification(Message::PacketType packetType, - bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, - uint16_t packetSeqCount) { +void RequestVerificationService::successAcceptanceVerification(const Message &request) { // TM[1,1] successful acceptance verification report - // parameters have max values defined from standard - assert(apid < 2048); - assert(seqFlag < 4); - assert(packetSeqCount < 16384); - Message report = createTM(1); - report.appendEnumerated(3, ECSS_PUS_VERSION); // packet version number - report.appendEnumerated(1, packetType); - report.appendBits(1, static_cast<uint8_t >(secondaryHeaderFlag)); - report.appendEnumerated(11, apid); - report.appendEnumerated(2, seqFlag); - report.appendBits(14, packetSeqCount); + report.appendEnumerated(3, CCSDS_PACKET_VERSION); // packet version number + report.appendEnumerated(1, request.packetType); // packet type + report.appendBits(1, 0); // secondary header flag(not implemented) + report.appendEnumerated(11, request.applicationId); // application process ID + report.appendEnumerated(2, 0); // sequence flags(not implemented) + report.appendBits(14, 0); // packet sequence count(not implemented) storeMessage(report); } void -RequestVerificationService::failAcceptanceVerification(Message::PacketType packetType, - bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, - uint16_t packetSeqCount, - uint16_t errorCode) { +RequestVerificationService::failAcceptanceVerification(const Message &request) { // TM[1,2] failed acceptance verification report - // parameters have max values defined from standard - assert(apid < 2048); - assert(seqFlag < 4); - assert(packetSeqCount < 16384); - Message report = createTM(2); - report.appendEnumerated(3, ECSS_PUS_VERSION); // packet version number - report.appendEnumerated(1, packetType); - report.appendBits(1, static_cast<uint8_t >(secondaryHeaderFlag)); - report.appendEnumerated(11, apid); - report.appendEnumerated(2, seqFlag); - report.appendBits(14, packetSeqCount); - report.appendEnum16(errorCode); + report.appendEnumerated(3, CCSDS_PACKET_VERSION); // packet version number + report.appendEnumerated(1, request.packetType); // packet type + report.appendBits(1, 0); // secondary header flag(not implemented) + report.appendEnumerated(11, request.applicationId); // application process ID + report.appendEnumerated(2, 0); // sequence flags(not implemented) + report.appendBits(14, 0); // packet sequence count(not implemented) + report.appendEnum16(0); // error code(not implemented) storeMessage(report); } -void RequestVerificationService::successExecutionVerification(Message::PacketType packetType, - bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, - uint16_t packetSeqCount) { +void RequestVerificationService::successExecutionVerification(const Message &request) { // TM[1,7] successful completion of execution verification report - // parameters have max values defined from standard - assert(apid < 2048); - assert(seqFlag < 4); - assert(packetSeqCount < 16384); - Message report = createTM(7); - report.appendEnumerated(3, ECSS_PUS_VERSION); // packet version number - report.appendEnumerated(1, packetType); - report.appendBits(1, static_cast<uint8_t >(secondaryHeaderFlag)); - report.appendEnumerated(11, apid); - report.appendEnumerated(2, seqFlag); - report.appendBits(14, packetSeqCount); + report.appendEnumerated(3, CCSDS_PACKET_VERSION); // packet version number + report.appendEnumerated(1, request.packetType); // packet type + report.appendBits(1, 0); // secondary header flag(not implemented) + report.appendEnumerated(11, request.applicationId); // application process ID + report.appendEnumerated(2, 0); // sequence flags(not implemented) + report.appendBits(14, 0); // packet sequence count(not implemented) storeMessage(report); } void -RequestVerificationService::failExecutionVerification(Message::PacketType packetType, - bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, - uint16_t packetSeqCount, - uint16_t errorCode) { +RequestVerificationService::failExecutionVerification(const Message &request) { // TM[1,8] failed completion of execution verification report - // parameters have max values defined from standard - assert(apid < 2048); - assert(seqFlag < 4); - assert(packetSeqCount < 16384); - Message report = createTM(8); - report.appendEnumerated(3, ECSS_PUS_VERSION); // packet version number - report.appendEnumerated(1, packetType); - report.appendBits(1, static_cast<uint8_t >(secondaryHeaderFlag)); - report.appendEnumerated(11, apid); - report.appendEnumerated(2, seqFlag); - report.appendBits(14, packetSeqCount); - report.appendEnum16(errorCode); + report.appendEnumerated(3, CCSDS_PACKET_VERSION); // packet version number + report.appendEnumerated(1, request.packetType); // packet type + report.appendBits(1, 0); // secondary header flag(not implemented) + report.appendEnumerated(11, request.applicationId); // application process ID + report.appendEnumerated(2, 0); // sequence flags(not implemented) + report.appendBits(14, 0); // packet sequence count(not implemented) + report.appendEnum16(0); // error code(not implemented) storeMessage(report); } void -RequestVerificationService::failRoutingVerification(Message::PacketType packetType, - bool secondaryHeaderFlag, - uint16_t apid, uint8_t seqFlag, - uint16_t packetSeqCount, - uint16_t errorCode) { +RequestVerificationService::failRoutingVerification(const Message &request) { // TM[1,10] failed routing verification report - // parameters have max values defined from standard - assert(apid < 2048); - assert(seqFlag < 4); - assert(packetSeqCount < 16384); - Message report = createTM(10); - report.appendEnumerated(3, ECSS_PUS_VERSION); // packet version number - report.appendEnumerated(1, packetType); - report.appendBits(1, static_cast<uint8_t >(secondaryHeaderFlag)); - report.appendEnumerated(11, apid); - report.appendEnumerated(2, seqFlag); - report.appendBits(14, packetSeqCount); - report.appendEnum16(errorCode); + report.appendEnumerated(3, CCSDS_PACKET_VERSION); // packet version number + report.appendEnumerated(1, request.packetType); // packet type + report.appendBits(1, 0); // secondary header flag(not implemented) + report.appendEnumerated(11, request.applicationId); // application process ID + report.appendEnumerated(2, 0); // sequence flags(not implemented) + report.appendBits(14, 0); // packet sequence count(not implemented) + report.appendEnum16(0); // error code(not implemented) storeMessage(report); } -void RequestVerificationService::execute(Message &message) { +void RequestVerificationService::execute(const Message &message) { switch (message.messageType) { case 1: - successAcceptanceVerification(Message::TC, true, 2, 2, 10); + successAcceptanceVerification(message); break; case 2: - failAcceptanceVerification(Message::TC, true, 2, 2, 10, 5); + failAcceptanceVerification(message); break; case 7: - successExecutionVerification(Message::TC, true, 2, 2, 10); + successExecutionVerification(message); break; case 8: - failExecutionVerification(Message::TC, true, 2, 2, 10, 6); + failExecutionVerification(message); break; case 10: - failRoutingVerification(Message::TC, true, 2, 2, 10, 7); + failRoutingVerification(message); break; default: // cout is very bad for embedded systems diff --git a/src/main.cpp b/src/main.cpp index ef59be9cf1b28ff677a88455118739c25fb60fd7..49fcd6e46b9d3040f7e1c2425f202f7e7e1e7d84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,12 +3,15 @@ #include "Services/TestService.hpp" #include "Services/ParameterService.hpp" #include "Services/RequestVerificationService.hpp" +#include "Services/MemoryManagementService.hpp" #include "Services/EventReportService.hpp" #include "Message.hpp" #include "MessageParser.hpp" #include "Services/MemoryManagementService.hpp" +#include "Helpers/CRCHelper.hpp" #include "ErrorHandler.hpp" + int main() { Message packet = Message(0, 0, Message::TC, 1); @@ -67,7 +70,7 @@ int main() { MemoryManagementService memMangService; Message rcvPack = Message(6, 5, Message::TC, 1); - rcvPack.appendEnum8(MemoryManagementService::MemoryID::RAM); // Memory ID + rcvPack.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID rcvPack.appendUint16(3); // Iteration count rcvPack.appendUint64(reinterpret_cast<uint64_t >(string)); // Start address rcvPack.appendUint16(sizeof(string) / sizeof(string[0])); // Data read length @@ -82,23 +85,45 @@ int main() { rcvPack = Message(6, 2, Message::TC, 1); uint8_t data[2] = {'h', 'R'}; - rcvPack.appendEnum8(MemoryManagementService::MemoryID::RAM); // Memory ID + rcvPack.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID rcvPack.appendUint16(2); // Iteration count rcvPack.appendUint64(reinterpret_cast<uint64_t >(pStr)); // Start address rcvPack.appendOctetString(2, data); + rcvPack.appendBits(16, CRCHelper::calculateCRC(data, 2)); // Append the CRC value rcvPack.appendUint64(reinterpret_cast<uint64_t >(pStr + 1)); // Start address rcvPack.appendOctetString(1, data); + rcvPack.appendBits(16, CRCHelper::calculateCRC(data, 1)); // Append the CRC value memMangService.rawDataMemorySubservice.loadRawData(rcvPack); + rcvPack = Message(6, 9, Message::TC, 1); + + rcvPack.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID + rcvPack.appendUint16(2); // Iteration count + rcvPack.appendUint64(reinterpret_cast<uint64_t >(data)); // Start address + rcvPack.appendUint16(2); + rcvPack.appendUint64(reinterpret_cast<uint64_t >(data + 1)); // Start address + rcvPack.appendUint16(1); + memMangService.rawDataMemorySubservice.checkRawData(rcvPack); + // ST[01] test - // parameters take random values and works as expected + RequestVerificationService reqVerifService; - reqVerifService.successAcceptanceVerification(Message::TC, true, 2, 2, 10); - reqVerifService.failAcceptanceVerification(Message::TC, true, 2, 2, 10, 5); - reqVerifService.successExecutionVerification(Message::TC, true, 2, 2, 10); - reqVerifService.failExecutionVerification(Message::TC, true, 2, 2, 10, 6); - reqVerifService.failRoutingVerification(Message::TC, true, 2, 2, 10, 7); + + Message receivedMessage = Message(1, 1, Message::TC, 3); + reqVerifService.successAcceptanceVerification(receivedMessage); + + receivedMessage = Message(1, 2, Message::TC, 3); + reqVerifService.failAcceptanceVerification(receivedMessage); + + receivedMessage = Message(1, 7, Message::TC, 3); + reqVerifService.successExecutionVerification(receivedMessage); + + receivedMessage = Message(1, 8, Message::TC, 3); + reqVerifService.failExecutionVerification(receivedMessage); + + receivedMessage = Message(1, 10, Message::TC, 3); + reqVerifService.failRoutingVerification(receivedMessage); // ST[05] (5,1 to 5,4) test [works] const unsigned char eventReportData[12] = "Hello World"; @@ -114,6 +139,7 @@ int main() { // MessageParser class test std::cout << "\n"; + // ST[17] test Message message = Message(17, 1, Message::TC, 1); MessageParser messageParser; @@ -123,15 +149,15 @@ int main() { messageParser.execute(message); // ST[01] test - message = Message(1, 1, Message::TC, 2); + message = Message(1, 1, Message::TC, 3); messageParser.execute(message); - message = Message(1, 2, Message::TC, 2); + message = Message(1, 2, Message::TC, 3); messageParser.execute(message); - message = Message(1, 7, Message::TC, 2); + message = Message(1, 7, Message::TC, 3); messageParser.execute(message); - message = Message(1, 8, Message::TC, 2); + message = Message(1, 8, Message::TC, 3); messageParser.execute(message); - message = Message(1, 10, Message::TC, 2); + message = Message(1, 10, Message::TC, 3); messageParser.execute(message); // ErrorHandler test diff --git a/test/ErrorHandler.cpp b/test/ErrorHandler.cpp index 23eaa2aef869e2501b7b74ea56157db7255e6503..e6d4003bc89d40ef363d1a24465e739abd2b7740 100644 --- a/test/ErrorHandler.cpp +++ b/test/ErrorHandler.cpp @@ -15,13 +15,13 @@ TEST_CASE("Error: Failed Acceptance", "[errors]") { CHECK(report.packetType == Message::TM); REQUIRE(report.dataSize == 6); - CHECK(report.readBits(3) == ECSS_PUS_VERSION); + CHECK(report.readBits(3) == CCSDS_PACKET_VERSION); CHECK(report.readBits(1) == static_cast<uint16_t>(Message::TC)); - CHECK(report.readBits(1) == true); + CHECK(report.readBits(1) == false); CHECK(report.readBits(11) == 47); - CHECK(report.readBits(2) == ECSS_SEQUENCE_FLAGS); + CHECK(report.readBits(2) == 0); CHECK(report.readBits(14) == failedMessage.packetSequenceCount); - CHECK(report.readEnum16() == 1); + CHECK(report.readEnum16() == 0); } TEST_CASE("Error: Failed Execution Completion", "[errors]") { @@ -37,11 +37,11 @@ TEST_CASE("Error: Failed Execution Completion", "[errors]") { CHECK(report.packetType == Message::TM); REQUIRE(report.dataSize == 6); - CHECK(report.readBits(3) == ECSS_PUS_VERSION); + CHECK(report.readBits(3) == CCSDS_PACKET_VERSION); CHECK(report.readBits(1) == static_cast<uint16_t>(Message::TC)); - CHECK(report.readBits(1) == true); + CHECK(report.readBits(1) == false); CHECK(report.readBits(11) == 56); - CHECK(report.readBits(2) == ECSS_SEQUENCE_FLAGS); + CHECK(report.readBits(2) == 0); CHECK(report.readBits(14) == failedMessage.packetSequenceCount); CHECK(report.readEnum16() == 0); } @@ -59,11 +59,11 @@ TEST_CASE("Error: Failed Routing", "[errors]") { CHECK(report.packetType == Message::TM); REQUIRE(report.dataSize == 6); - CHECK(report.readBits(3) == ECSS_PUS_VERSION); + CHECK(report.readBits(3) == CCSDS_PACKET_VERSION); CHECK(report.readBits(1) == static_cast<uint16_t>(Message::TC)); - CHECK(report.readBits(1) == true); + CHECK(report.readBits(1) == false); CHECK(report.readBits(11) == 71); - CHECK(report.readBits(2) == ECSS_SEQUENCE_FLAGS); + CHECK(report.readBits(2) == 0); CHECK(report.readBits(14) == failedMessage.packetSequenceCount); CHECK(report.readEnum16() == 0); } diff --git a/test/Services/MemoryManagementService.cpp b/test/Services/MemoryManagementService.cpp index d59c8de2c6490d99b9113904a08ce313dc25ef26..06bbe264f0ce68c5585dcc158e5f8e8fcec12cf4 100644 --- a/test/Services/MemoryManagementService.cpp +++ b/test/Services/MemoryManagementService.cpp @@ -2,6 +2,7 @@ #include <Services/MemoryManagementService.hpp> #include <Message.hpp> #include "ServiceTests.hpp" +#include "Helpers/CRCHelper.hpp" TEST_CASE("TM[6,2]", "[service][st06]") { // Required test variables @@ -14,12 +15,14 @@ TEST_CASE("TM[6,2]", "[service][st06]") { MemoryManagementService memMangService; Message receivedPacket = Message(6, 2, Message::TC, 1); - receivedPacket.appendEnum8(MemoryManagementService::MemoryID::RAM); // Memory ID + receivedPacket.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID receivedPacket.appendUint16(2); // Iteration count receivedPacket.appendUint64(reinterpret_cast<uint64_t >(pStr)); // Start address receivedPacket.appendOctetString(2, data); + receivedPacket.appendBits(16, CRCHelper::calculateCRC(data, 2)); // Append CRC receivedPacket.appendUint64(reinterpret_cast<uint64_t >(pStr + 2)); // Start address - receivedPacket.appendOctetString(1, data); + receivedPacket.appendOctetString(1, data); // Append CRC + receivedPacket.appendBits(16, CRCHelper::calculateCRC(data, 1)); memMangService.rawDataMemorySubservice.loadRawData(receivedPacket); CHECK(pStr[0] == 'h'); @@ -33,43 +36,46 @@ TEST_CASE("TM[6,5]", "[service][st06]") { uint8_t testString_3[2] = {5, 8}; uint8_t checkString[ECSS_MAX_STRING_SIZE]; - uint16_t readSize = 0; + uint16_t readSize = 0, checksum = 0; MemoryManagementService memMangService; Message receivedPacket = Message(6, 5, Message::TC, 1); - receivedPacket.appendEnum8(MemoryManagementService::MemoryID::RAM); // Memory ID + receivedPacket.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID receivedPacket.appendUint16(3); // Iteration count (Equal to 3 test strings) receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_1)); // Start address - receivedPacket.appendUint16(sizeof(testString_1)/ sizeof(testString_1[0])); // Data read length + receivedPacket.appendUint16(sizeof(testString_1) / sizeof(testString_1[0])); // Data read length receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_2)); - receivedPacket.appendUint16(sizeof(testString_2)/ sizeof(testString_2[0])); + receivedPacket.appendUint16(sizeof(testString_2) / sizeof(testString_2[0])); receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_3)); - receivedPacket.appendUint16(sizeof(testString_3)/ sizeof(testString_3[0])); + receivedPacket.appendUint16(sizeof(testString_3) / sizeof(testString_3[0])); memMangService.rawDataMemorySubservice.dumpRawData(receivedPacket); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); CHECK(response.serviceType == 6); CHECK(response.messageType == 6); - REQUIRE(response.dataSize == 49); + REQUIRE(response.dataSize == 55); - CHECK(response.readEnum8() == MemoryManagementService::MemoryID::RAM); + CHECK(response.readEnum8() == MemoryManagementService::MemoryID::EXTERNAL); CHECK(response.readUint16() == 3); CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_1)); readSize = response.readOctetString(checkString); - CHECK(readSize == sizeof(testString_1)/ sizeof(testString_1[0])); + checksum = response.readBits(16); + CHECK(readSize == sizeof(testString_1) / sizeof(testString_1[0])); CHECK(checkString[0] == 'F'); CHECK(checkString[1] == 'S'); CHECK(checkString[2] == 't'); CHECK(checkString[3] == 'r'); CHECK(checkString[4] == 'T'); CHECK(checkString[5] == '\0'); + CHECK(checksum == CRCHelper::calculateCRC(checkString, readSize)); CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_2)); readSize = response.readOctetString(checkString); - CHECK(readSize == sizeof(testString_2)/ sizeof(testString_2[0])); + checksum = response.readBits(16); + CHECK(readSize == sizeof(testString_2) / sizeof(testString_2[0])); CHECK(checkString[0] == 'S'); CHECK(checkString[1] == 'e'); CHECK(checkString[2] == 'c'); @@ -78,10 +84,50 @@ TEST_CASE("TM[6,5]", "[service][st06]") { CHECK(checkString[5] == 'r'); CHECK(checkString[6] == 'T'); CHECK(checkString[7] == '\0'); + CHECK(checksum == CRCHelper::calculateCRC(checkString, readSize)); CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_3)); readSize = response.readOctetString(checkString); - CHECK(readSize == sizeof(testString_3)/ sizeof(testString_3[0])); + checksum = response.readBits(16); + CHECK(readSize == sizeof(testString_3) / sizeof(testString_3[0])); CHECK(checkString[0] == 5); CHECK(checkString[1] == 8); + CHECK(checksum == CRCHelper::calculateCRC(checkString, readSize)); +} + +TEST_CASE("TM[6,9]", "[service][st06]") { + uint8_t testString_1[6] = "FStrT"; + uint8_t testString_2[8] = "SecStrT"; + uint16_t readSize = 0, checksum = 0; + + MemoryManagementService memMangService; + Message receivedPacket = Message(6, 9, Message::TC, 1); + receivedPacket.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID + receivedPacket.appendUint16(2); // Iteration count + receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_1)); // Start address + receivedPacket.appendUint16(sizeof(testString_1) / sizeof(testString_1[0])); // Data read length + + receivedPacket.appendUint64(reinterpret_cast<uint64_t >(testString_2)); + receivedPacket.appendUint16(sizeof(testString_2) / sizeof(testString_2[0])); + memMangService.rawDataMemorySubservice.checkRawData(receivedPacket); + REQUIRE(ServiceTests::hasOneMessage()); + + Message response = ServiceTests::get(0); + CHECK(response.serviceType == 6); + CHECK(response.messageType == 10); + REQUIRE(response.dataSize == 27); + + CHECK(response.readEnum8() == MemoryManagementService::MemoryID::EXTERNAL); + CHECK(response.readUint16() == 2); + CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_1)); + readSize = response.readUint16(); + checksum = response.readBits(16); + CHECK(readSize == sizeof(testString_1) / sizeof(testString_1[0])); + CHECK(checksum == CRCHelper::calculateCRC(testString_1, readSize)); + + CHECK(response.readUint64() == reinterpret_cast<uint64_t >(testString_2)); + readSize = response.readUint16(); + checksum = response.readBits(16); + CHECK(readSize == sizeof(testString_2) / sizeof(testString_2[0])); + CHECK(checksum == CRCHelper::calculateCRC(testString_2, readSize)); } diff --git a/test/Services/RequestVerificationService.cpp b/test/Services/RequestVerificationService.cpp index ebb97762346f5c03b07a82052e4e1baeca928d46..65a256d3d37010317e7b61106beeb2083f7e976e 100644 --- a/test/Services/RequestVerificationService.cpp +++ b/test/Services/RequestVerificationService.cpp @@ -5,108 +5,117 @@ TEST_CASE("TM[1,1]", "[service][st01]") { RequestVerificationService reqVerifService; - reqVerifService.successAcceptanceVerification(Message::TC, true, 2, 2, 10); + + Message receivedMessage = Message(1, 1, Message::TC, 3); + reqVerifService.successAcceptanceVerification(receivedMessage); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); // Checks for the data-members of the object response CHECK(response.serviceType == 1); CHECK(response.messageType == 1); - CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1) + CHECK(response.packetType == Message::TM); // packet type CHECK(response.applicationId == 0); REQUIRE(response.dataSize == 4); // dataSize is the number of bytes of data array // Check for the value that is stored in <<data>> array(data-member of object response) - CHECK(response.readEnumerated(3) == 2); // packet version number - CHECK(response.readEnumerated(1) == 1); // packet type - CHECK(response.readBits(1) == true); // secondary header flag - CHECK(response.readEnumerated(11) == 2); // application process ID - CHECK(response.readEnumerated(2) == 2); // sequence flags - CHECK(response.readBits(14) == 10); // packet sequence count + CHECK(response.readEnumerated(3) == CCSDS_PACKET_VERSION); // packet version number + CHECK(response.readEnumerated(1) == Message::TC); // packet type + CHECK(response.readBits(1) == 0); // secondary header flag + CHECK(response.readEnumerated(11) == 3); // application process ID + CHECK(response.readEnumerated(2) == 0); // sequence flags + CHECK(response.readBits(14) == 0); // packet sequence count } TEST_CASE("TM[1,2]", "[service][st01]") { RequestVerificationService reqVerifService; - reqVerifService.failAcceptanceVerification(Message::TC, true, 2, 2, 10, 5); + + Message receivedMessage = Message(1, 2, Message::TC, 3); + reqVerifService.failAcceptanceVerification(receivedMessage); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); // Checks for the data-members of the object response CHECK(response.serviceType == 1); CHECK(response.messageType == 2); - CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1) + CHECK(response.packetType == Message::TM); // packet type CHECK(response.applicationId == 0); REQUIRE(response.dataSize == 6); // dataSize is the number of bytes of data array // Check for the value that is stored in <<data>> array(data-member of object response) - CHECK(response.readEnumerated(3) == 2); // packet version number - CHECK(response.readEnumerated(1) == 1); // packet type - CHECK(response.readBits(1) == true); // secondary header flag - CHECK(response.readEnumerated(11) == 2); // application process ID - CHECK(response.readEnumerated(2) == 2); // sequence flags - CHECK(response.readBits(14) == 10); // packet sequence count - CHECK(response.readEnum16() == 5); // error code + CHECK(response.readEnumerated(3) == CCSDS_PACKET_VERSION); // packet version number + CHECK(response.readEnumerated(1) == Message::TC); // packet type + CHECK(response.readBits(1) == 0); // secondary header flag + CHECK(response.readEnumerated(11) == 3); // application process ID + CHECK(response.readEnumerated(2) == 0); // sequence flags + CHECK(response.readBits(14) == 0); // packet sequence count + CHECK(response.readEnum16() == 0); // error code } TEST_CASE("TM[1,7]", "[service][st01]") { RequestVerificationService reqVerifService; - reqVerifService.successExecutionVerification(Message::TC, true, 2, 2, 10); + + Message receivedMessage = Message(1, 7, Message::TC, 3); + reqVerifService.successExecutionVerification(receivedMessage); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); // Checks for the data-members of the object response CHECK(response.serviceType == 1); CHECK(response.messageType == 7); - CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1) + CHECK(response.packetType == Message::TM); // packet type CHECK(response.applicationId == 0); REQUIRE(response.dataSize == 4); // dataSize is the number of bytes of data array // Check for the value that is stored in <<data>> array(data-member of object response) - CHECK(response.readEnumerated(3) == 2); // packet version number - CHECK(response.readEnumerated(1) == 1); // packet type - CHECK(response.readBits(1) == true); // secondary header flag - CHECK(response.readEnumerated(11) == 2); // application process ID - CHECK(response.readEnumerated(2) == 2); // sequence flags - CHECK(response.readBits(14) == 10); // packet sequence count + CHECK(response.readEnumerated(3) == CCSDS_PACKET_VERSION); // packet version number + CHECK(response.readEnumerated(1) == Message::TC); // packet type + CHECK(response.readBits(1) == 0); // secondary header flag + CHECK(response.readEnumerated(11) == 3); // application process ID + CHECK(response.readEnumerated(2) == 0); // sequence flags + CHECK(response.readBits(14) == 0); // packet sequence count } TEST_CASE("TM[1,8]", "[service][st01]") { RequestVerificationService reqVerifService; - reqVerifService.failExecutionVerification(Message::TC, true, 2, 2, 10, 6); + + Message receivedMessage = Message(1, 8, Message::TC, 3); + reqVerifService.failExecutionVerification(receivedMessage); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); - // Checks for the data-members of the object response CHECK(response.serviceType == 1); CHECK(response.messageType == 8); - CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1) + CHECK(response.packetType == Message::TM); // packet type CHECK(response.applicationId == 0); REQUIRE(response.dataSize == 6); // dataSize is the number of bytes of data array // Check for the value that is stored in <<data>> array(data-member of object response) - CHECK(response.readEnumerated(3) == 2); // packet version number - CHECK(response.readEnumerated(1) == 1); // packet type - CHECK(response.readBits(1) == true); // secondary header flag - CHECK(response.readEnumerated(11) == 2); // application process ID - CHECK(response.readEnumerated(2) == 2); // sequence flags - CHECK(response.readBits(14) == 10); // packet sequence count - CHECK(response.readEnum16() == 6); // error code + CHECK(response.readEnumerated(3) == CCSDS_PACKET_VERSION); // packet version number + CHECK(response.readEnumerated(1) == Message::TC); // packet type + CHECK(response.readBits(1) == 0); // secondary header flag + CHECK(response.readEnumerated(11) == 3); // application process ID + CHECK(response.readEnumerated(2) == 0); // sequence flags + CHECK(response.readBits(14) == 0); // packet sequence count + CHECK(response.readEnum16() == 0); // error code } TEST_CASE("TM[1,10]", "[service][st01]") { RequestVerificationService reqVerifService; - reqVerifService.failRoutingVerification(Message::TC, true, 2, 2, 10, 7); + + Message receivedMessage = Message(1, 10, Message::TC, 3); + reqVerifService.failRoutingVerification(receivedMessage); REQUIRE(ServiceTests::hasOneMessage()); Message response = ServiceTests::get(0); // Checks for the data-members of the object response CHECK(response.serviceType == 1); CHECK(response.messageType == 10); - CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1) + CHECK(response.packetType == Message::TM); // packet type CHECK(response.applicationId == 0); REQUIRE(response.dataSize == 6); // dataSize is the number of bytes of data array // Check for the value that is stored in <<data>> array(data-member of object response) - CHECK(response.readEnumerated(3) == 2); // packet version number - CHECK(response.readEnumerated(1) == 1); // packet type - CHECK(response.readBits(1) == true); // secondary header flag - CHECK(response.readEnumerated(11) == 2); // application process ID - CHECK(response.readEnumerated(2) == 2); // sequence flags - CHECK(response.readBits(14) == 10); // packet sequence count - CHECK(response.readEnum16() == 7); // error code + CHECK(response.readEnumerated(3) == CCSDS_PACKET_VERSION); // packet version number + CHECK(response.readEnumerated(1) == Message::TC); // packet type + CHECK(response.readBits(1) == 0); // secondary header flag + CHECK(response.readEnumerated(11) == 3); // application process ID + CHECK(response.readEnumerated(2) == 0); // sequence flags + CHECK(response.readBits(14) == 0); // packet sequence count + CHECK(response.readEnum16() == 0); // error code }