diff --git a/inc/Message.hpp b/inc/Message.hpp index 93821cbe1bed298eb0080f70a295954824a360c3..b59938dda18b932830057e602fab0178eba81ea1 100644 --- a/inc/Message.hpp +++ b/inc/Message.hpp @@ -159,8 +159,7 @@ public: * * @param string The string to insert */ - template <const size_t SIZE> - void appendString(const String<SIZE>& string); + void appendString(const etl::istring& string); /** * Appends a number of bytes to the message @@ -175,8 +174,7 @@ public: * * @param string The string to insert */ - template <const size_t SIZE> - void appendFixedString(const String<SIZE>& string); + void appendFixedString(const etl::istring& string); /** * Reads the next \p numBits bits from the the message in a big-endian format @@ -358,14 +356,7 @@ public: * * PTC = 7, PFC = 0 */ - template <const size_t SIZE> - void appendOctetString(const String<SIZE>& string) { - // Make sure that the string is large enough to count - ASSERT_INTERNAL(string.size() <= (std::numeric_limits<uint16_t>::max)(), ErrorHandler::StringTooLarge); - - appendUint16(string.size()); - appendString(string); - } + void appendOctetString(const etl::istring& string); /** * Adds a nested TC or TM Message within the current Message @@ -573,25 +564,4 @@ public: } }; -template <const size_t SIZE> -inline void Message::appendString(const String<SIZE>& string) { - ASSERT_INTERNAL(dataSize + string.size() < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); - // TODO: Do we need to keep this check? How does etl::string handle it? - ASSERT_INTERNAL(string.size() < string.capacity(), ErrorHandler::StringTooLarge); - - memcpy(data + dataSize, string.data(), string.size()); - - dataSize += string.size(); -} - -template <const size_t SIZE> -inline void Message::appendFixedString(const String<SIZE>& string) { - ASSERT_INTERNAL((dataSize + SIZE) < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); - - memcpy(data + dataSize, string.data(), string.size()); // Append the bytes with content - (void) memset(data + dataSize + string.size(), 0, SIZE - string.size()); // The rest of the bytes is set to 0 - - dataSize += SIZE; -} - #endif // ECSS_SERVICES_PACKET_H diff --git a/src/Message.cpp b/src/Message.cpp index e96eacaab14cc30c143abb607ad09bb423358abe..b1dc6999d5322991b20048ae30d9ab918a386980 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -166,3 +166,32 @@ void Message::resetRead() { void Message::appendMessage(const Message& message, uint16_t size) { appendString(MessageParser::composeECSS(message, size)); } + +void Message::appendString(const etl::istring& string) { + ASSERT_INTERNAL(dataSize + string.size() < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); + // TODO: Do we need to keep this check? How does etl::string handle it? + ASSERT_INTERNAL(string.size() < string.capacity(), ErrorHandler::StringTooLarge); + + memcpy(data + dataSize, string.data(), string.size()); + + dataSize += string.size(); +} + +void Message::appendFixedString(const etl::istring& string) { + ASSERT_INTERNAL((dataSize + string.max_size()) < ECSS_MAX_MESSAGE_SIZE, ErrorHandler::MessageTooLarge); + + // Append the bytes with content + memcpy(data + dataSize, string.data(), string.size()); + // The rest of the bytes is set to 0 + (void) memset(data + dataSize + string.size(), 0, string.max_size() - string.size()); + + dataSize += string.max_size(); +} + +void Message::appendOctetString(const etl::istring& string) { + // Make sure that the string is large enough to count + ASSERT_INTERNAL(string.size() <= (std::numeric_limits<uint16_t>::max)(), ErrorHandler::StringTooLarge); + + appendUint16(string.size()); + appendString(string); +} diff --git a/src/Platform/x86/main.cpp b/src/Platform/x86/main.cpp index 54a997bae9e74898afd18a1bab439a9549c82698..391780a790d452b7d5e0fd46a3aec0c280882818 100644 --- a/src/Platform/x86/main.cpp +++ b/src/Platform/x86/main.cpp @@ -25,7 +25,7 @@ int main() { Message packet = Message(0, 0, Message::TC, 1); - packet.appendString<5>("hello"); + packet.appendString(String<5>("hello")); packet.appendBits(15, 0x28a8); packet.appendBits(1, 1); packet.appendFloat(5.7); diff --git a/test/Message.cpp b/test/Message.cpp index 2c92a13ed98fd4954d78634502a2a24a1fe7559c..a13c29e2b7b59298188b77042069ac60b83af8f8 100644 --- a/test/Message.cpp +++ b/test/Message.cpp @@ -156,7 +156,7 @@ TEST_CASE("Requirement 7.3.6 (Real)", "[message][ecss]") { TEST_CASE("Requirement 7.3.8 (Octet-string)", "[message][ecss]") { Message message(0, 0, Message::TC, 0); - message.appendString<4>("test"); + message.appendString(String<4>("test")); REQUIRE(message.dataSize == 4);