diff --git a/inc/Message.hpp b/inc/Message.hpp index 93bc12d0affa8bee962ef0bd2d25b709abba81f6..5747a2111c5ed740c55a50edb325becc626d9670 100644 --- a/inc/Message.hpp +++ b/inc/Message.hpp @@ -81,7 +81,9 @@ public: * * PTC = 1, PFC = 0 */ - void appendBoolean(bool value); + void appendBoolean(bool value) { + return appendByte(static_cast<uint8_t>(value)); + } /** * Adds an enumerated parameter consisting of an arbitrary number of bits to the end of the @@ -96,70 +98,92 @@ public: * * PTC = 1, PFC = 8 */ - void appendEnumerated(uint8_t value); + void appendEnumerated(uint8_t value) { + return appendByte(value); + }; /** * Adds an enumerated parameter consisting of 2 bytes to the end of the message * * PTC = 1, PFC = 16 */ - void appendEnumerated(uint16_t value); + void appendEnumerated(uint16_t value) { + return appendHalfword(value); + } /** * Adds an enumerated parameter consisting of 4 bytes to the end of the message * * PTC = 1, PFC = 32 */ - void appendEnumerated(uint32_t value); + void appendEnumerated(uint32_t value) { + return appendWord(value); + } /** * Adds a 1 byte unsigned integer to the end of the message * * PTC = 2, PFC = 4 */ - void appendInteger(uint8_t value); + void appendInteger(uint8_t value) { + return appendByte(value); + } /** * Adds a 2 byte unsigned integer to the end of the message * * PTC = 2, PFC = 8 */ - void appendInteger(uint16_t value); + void appendInteger(uint16_t value) { + return appendHalfword(value); + } /** * Adds a 4 byte unsigned integer to the end of the message * * PTC = 2, PFC = 14 */ - void appendInteger(uint32_t value); + void appendInteger(uint32_t value) { + return appendWord(value); + } /** * Adds a 1 byte signed integer to the end of the message * * PTC = 3, PFC = 4 */ - void appendInteger(int8_t value); + void appendInteger(int8_t value) { + return appendByte(reinterpret_cast<uint8_t&>(value)); + } /** * Adds a 2 byte signed integer to the end of the message * * PTC = 3, PFC = 8 */ - void appendInteger(int16_t value); + void appendInteger(int16_t value) { + return appendHalfword(reinterpret_cast<uint16_t&>(value)); + } /** * Adds a 4 byte signed integer to the end of the message * * PTC = 3, PFC = 14 */ - void appendInteger(int32_t value); + void appendInteger(int32_t value) { + return appendWord(reinterpret_cast<uint32_t&>(value)); + } /** * Adds a 4-byte single-precision floating point number to the end of the message * * PTC = 5, PFC = 1 */ - void appendReal(float value); + void appendReal(float value) { + static_assert(sizeof(uint32_t) == sizeof(value), "Floating point numbers must be 32 bits long"); + + return appendWord(reinterpret_cast<uint32_t&>(value)); + } }; diff --git a/src/Message.cpp b/src/Message.cpp index 61ef26afb70971833089ecad58324a7011bcd68a..eb9335d04fe240b82fd57768985b874935ee28a1 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -65,59 +65,13 @@ void Message::appendString(uint8_t size, const char *value) { dataSize += size; } -void Message::appendBoolean(bool value) { - return appendByte(static_cast<uint8_t>(value)); -} - -inline void Message::appendEnumerated(uint8_t bits, uint32_t value) { +void Message::appendEnumerated(uint8_t bits, uint32_t value) { // TODO: Implement 32-bit enums, if needed assert((value & 0xffff0000) != 0); return appendBits(bits, value); } -inline void Message::appendEnumerated(uint8_t value) { - return appendByte(value); -} - -inline void Message::appendEnumerated(uint16_t value) { - return appendHalfword(value); -} - -inline void Message::appendEnumerated(uint32_t value) { - return appendWord(value); -} - -inline void Message::appendInteger(uint8_t value) { - return appendByte(value); -} - -inline void Message::appendInteger(uint16_t value) { - return appendHalfword(value); -} - -inline void Message::appendInteger(uint32_t value) { - return appendWord(value); -} - -inline void Message::appendInteger(int8_t value) { - return appendByte(static_cast<uint8_t>(value)); -} - -void Message::appendInteger(int16_t value) { - return appendHalfword(static_cast<uint8_t>(value)); -} - -void Message::appendInteger(int32_t value) { - return appendWord(static_cast<uint8_t>(value)); -} - -void Message::appendReal(float value) { - static_assert(sizeof(uint32_t) == sizeof(value), "Floating point numbers must be 32 bits long"); - - return appendWord(reinterpret_cast<uint32_t&>(value)); -} - Message::Message(uint8_t serviceType, uint8_t messageType, Message::PacketType packetType, uint16_t applicationId) : serviceType(serviceType), messageType(messageType), packetType(packetType), applicationId(applicationId) {} diff --git a/src/Services/TestService.cpp b/src/Services/TestService.cpp index 6335e3adf3b24b2cafab1c0e3232976155c5109f..674b19db93c3e699e3e7699f85a31f98547a8e58 100644 --- a/src/Services/TestService.cpp +++ b/src/Services/TestService.cpp @@ -1,6 +1,3 @@ - -#include <Services/TestService.hpp> - #include "Services/TestService.hpp" void TestService::areYouAlive(const Message &request) {