From 24fb3034b32182cbd8a51af64b51553f024e2f0b Mon Sep 17 00:00:00 2001 From: kongr45gpen <electrovesta@gmail.com> Date: Tue, 13 Nov 2018 03:47:49 +0200 Subject: [PATCH] Explicitly state the size of the message in `append()` functions to prevent ambiguity Fixes #1 --- inc/Message.hpp | 20 ++++++++++---------- src/Services/TestService.cpp | 2 +- src/main.cpp | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/inc/Message.hpp b/inc/Message.hpp index 5747a211..8b3ff35d 100644 --- a/inc/Message.hpp +++ b/inc/Message.hpp @@ -98,7 +98,7 @@ public: * * PTC = 1, PFC = 8 */ - void appendEnumerated(uint8_t value) { + void appendEnum8(uint8_t value) { return appendByte(value); }; @@ -107,7 +107,7 @@ public: * * PTC = 1, PFC = 16 */ - void appendEnumerated(uint16_t value) { + void appendEnum16(uint16_t value) { return appendHalfword(value); } @@ -116,7 +116,7 @@ public: * * PTC = 1, PFC = 32 */ - void appendEnumerated(uint32_t value) { + void appendEnum32(uint32_t value) { return appendWord(value); } @@ -125,7 +125,7 @@ public: * * PTC = 2, PFC = 4 */ - void appendInteger(uint8_t value) { + void appendUint8(uint8_t value) { return appendByte(value); } @@ -134,7 +134,7 @@ public: * * PTC = 2, PFC = 8 */ - void appendInteger(uint16_t value) { + void appendUint16(uint16_t value) { return appendHalfword(value); } @@ -143,7 +143,7 @@ public: * * PTC = 2, PFC = 14 */ - void appendInteger(uint32_t value) { + void appendUint32(uint32_t value) { return appendWord(value); } @@ -152,7 +152,7 @@ public: * * PTC = 3, PFC = 4 */ - void appendInteger(int8_t value) { + void appendSint8(int8_t value) { return appendByte(reinterpret_cast<uint8_t&>(value)); } @@ -161,7 +161,7 @@ public: * * PTC = 3, PFC = 8 */ - void appendInteger(int16_t value) { + void appendSint16(int16_t value) { return appendHalfword(reinterpret_cast<uint16_t&>(value)); } @@ -170,7 +170,7 @@ public: * * PTC = 3, PFC = 14 */ - void appendInteger(int32_t value) { + void appendSint32(int32_t value) { return appendWord(reinterpret_cast<uint32_t&>(value)); } @@ -179,7 +179,7 @@ public: * * PTC = 5, PFC = 1 */ - void appendReal(float value) { + void appendFloat(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/Services/TestService.cpp b/src/Services/TestService.cpp index 674b19db..aaf3f4f6 100644 --- a/src/Services/TestService.cpp +++ b/src/Services/TestService.cpp @@ -12,7 +12,7 @@ void TestService::onBoardConnection(const Message &request) { Message report = createTM(4); // TODO: This is not the correct way to do this! Fetching functions will be added later - report.appendInteger(request.data[1]); + report.appendUint8(request.data[1]); storeMessage(report); } diff --git a/src/main.cpp b/src/main.cpp index 31ecd04f..5d941648 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,7 @@ int main() { packet.appendString(5, "hello"); packet.appendBits(15, 0x28a8); packet.appendBits(1, 1); - packet.appendReal(5.7); + packet.appendFloat(5.7); std::cout << "Hello, World!" << std::endl; std::cout << std::hex << packet.data << std::endl; // packet data must be 'helloQQ' @@ -19,7 +19,7 @@ int main() { Message receivedPacket = Message(17, 1, Message::TC, 1); testService.areYouAlive(receivedPacket); receivedPacket = Message(17, 3, Message::TC, 1); - receivedPacket.appendInteger(static_cast<uint16_t>(7)); + receivedPacket.appendUint16(7); testService.onBoardConnection(receivedPacket); return 0; -- GitLab