Skip to content
Snippets Groups Projects
Commit b9db3b32 authored by kongr45gpen's avatar kongr45gpen
Browse files

Fix bugs, typos and issues

parent 24fb3034
No related branches found
No related tags found
No related merge requests found
......@@ -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));
}
......
#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) {}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment