From b9db3b3251a1085a3ee5372cf23bfa607a1c2026 Mon Sep 17 00:00:00 2001 From: kongr45gpen <electrovesta@gmail.com> Date: Thu, 15 Nov 2018 01:48:28 +0200 Subject: [PATCH] Fix bugs, typos and issues --- inc/Message.hpp | 38 +++++++++++++++++++++++--------------- src/Message.cpp | 20 +++++++++++--------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/inc/Message.hpp b/inc/Message.hpp index 8b3ff35d..d32e6ba9 100644 --- a/inc/Message.hpp +++ b/inc/Message.hpp @@ -89,14 +89,18 @@ public: * Adds an enumerated parameter consisting of an arbitrary number of bits to the end of the * message * - * PTC = 1, PFC = \p bits + * PTC = 2, PFC = \p bits */ - void appendEnumerated(uint8_t bits, uint32_t value); + void appendEnumerated(uint8_t bits, uint32_t value) { + // TODO: Implement 32-bit enums, if needed + + return appendBits(bits, value); + } /** * Adds an enumerated parameter consisting of 1 byte to the end of the message * - * PTC = 1, PFC = 8 + * PTC = 2, PFC = 8 */ void appendEnum8(uint8_t value) { return appendByte(value); @@ -105,7 +109,7 @@ public: /** * Adds an enumerated parameter consisting of 2 bytes to the end of the message * - * PTC = 1, PFC = 16 + * PTC = 2, PFC = 16 */ void appendEnum16(uint16_t value) { return appendHalfword(value); @@ -114,7 +118,7 @@ public: /** * Adds an enumerated parameter consisting of 4 bytes to the end of the message * - * PTC = 1, PFC = 32 + * PTC = 2, PFC = 32 */ void appendEnum32(uint32_t value) { return appendWord(value); @@ -123,7 +127,7 @@ public: /** * Adds a 1 byte unsigned integer to the end of the message * - * PTC = 2, PFC = 4 + * PTC = 3, PFC = 4 */ void appendUint8(uint8_t value) { return appendByte(value); @@ -132,7 +136,7 @@ public: /** * Adds a 2 byte unsigned integer to the end of the message * - * PTC = 2, PFC = 8 + * PTC = 3, PFC = 8 */ void appendUint16(uint16_t value) { return appendHalfword(value); @@ -141,7 +145,7 @@ public: /** * Adds a 4 byte unsigned integer to the end of the message * - * PTC = 2, PFC = 14 + * PTC = 3, PFC = 14 */ void appendUint32(uint32_t value) { return appendWord(value); @@ -150,28 +154,28 @@ public: /** * Adds a 1 byte signed integer to the end of the message * - * PTC = 3, PFC = 4 + * PTC = 4, PFC = 4 */ void appendSint8(int8_t value) { - return appendByte(reinterpret_cast<uint8_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 + * PTC = 4, PFC = 8 */ void appendSint16(int16_t value) { - return appendHalfword(reinterpret_cast<uint16_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 + * PTC = 4, PFC = 14 */ void appendSint32(int32_t value) { - return appendWord(reinterpret_cast<uint32_t&>(value)); + return appendWord(reinterpret_cast<uint32_t &>(value)); } /** @@ -180,7 +184,11 @@ public: * PTC = 5, PFC = 1 */ void appendFloat(float value) { - static_assert(sizeof(uint32_t) == sizeof(value), "Floating point numbers must be 32 bits long"); + static_assert(sizeof(uint32_t) == sizeof(value), + "Floating point numbers must be 32 bits long"); + + return appendWord(reinterpret_cast<uint32_t &>(value)); + } return appendWord(reinterpret_cast<uint32_t&>(value)); } diff --git a/src/Message.cpp b/src/Message.cpp index 62c15f86..47ac5575 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -1,11 +1,19 @@ #include "Message.hpp" #include <cstring> +#include <Message.hpp> + + +Message::Message(uint8_t serviceType, uint8_t messageType, Message::PacketType packetType, + uint16_t applicationId) : serviceType(serviceType), messageType(messageType), + packetType(packetType), applicationId(applicationId) {} void Message::appendBits(uint8_t numBits, uint16_t data) { - assert(dataSize < ECSS_MAX_MESSAGE_SIZE); - assert(numBits < 16); + // TODO: Add assertion that data does not contain 1s outside of numBits bits + assert(numBits <= 16); while (numBits > 0) { // For every sequence of 8 bits... + assert(dataSize < ECSS_MAX_MESSAGE_SIZE); + if (currentBit + numBits >= 8) { // Will have to shift the bits and insert the next ones later auto bitsToAddNow = static_cast<uint8_t>(8 - currentBit); @@ -65,13 +73,7 @@ void Message::appendString(uint8_t size, const char *value) { dataSize += size; } -void Message::appendEnumerated(uint8_t bits, uint32_t value) { - // TODO: Implement 32-bit enums, if needed - assert((value & 0xffff0000) != 0); - return appendBits(bits, value); + return value; } -Message::Message(uint8_t serviceType, uint8_t messageType, Message::PacketType packetType, - uint16_t applicationId) : serviceType(serviceType), messageType(messageType), - packetType(packetType), applicationId(applicationId) {} -- GitLab