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

Move implementations of Message functions to its header, so they can be inlined

parent 1f147c93
No related branches found
No related tags found
No related merge requests found
...@@ -81,7 +81,9 @@ public: ...@@ -81,7 +81,9 @@ public:
* *
* PTC = 1, PFC = 0 * 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 * Adds an enumerated parameter consisting of an arbitrary number of bits to the end of the
...@@ -96,70 +98,92 @@ public: ...@@ -96,70 +98,92 @@ public:
* *
* PTC = 1, PFC = 8 * 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 * Adds an enumerated parameter consisting of 2 bytes to the end of the message
* *
* PTC = 1, PFC = 16 * 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 * Adds an enumerated parameter consisting of 4 bytes to the end of the message
* *
* PTC = 1, PFC = 32 * 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 * Adds a 1 byte unsigned integer to the end of the message
* *
* PTC = 2, PFC = 4 * 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 * Adds a 2 byte unsigned integer to the end of the message
* *
* PTC = 2, PFC = 8 * 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 * Adds a 4 byte unsigned integer to the end of the message
* *
* PTC = 2, PFC = 14 * 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 * Adds a 1 byte signed integer to the end of the message
* *
* PTC = 3, PFC = 4 * 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 * Adds a 2 byte signed integer to the end of the message
* *
* PTC = 3, PFC = 8 * 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 * Adds a 4 byte signed integer to the end of the message
* *
* PTC = 3, PFC = 14 * 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 * Adds a 4-byte single-precision floating point number to the end of the message
* *
* PTC = 5, PFC = 1 * 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));
}
}; };
......
...@@ -65,59 +65,13 @@ void Message::appendString(uint8_t size, const char *value) { ...@@ -65,59 +65,13 @@ void Message::appendString(uint8_t size, const char *value) {
dataSize += size; dataSize += size;
} }
void Message::appendBoolean(bool value) { void Message::appendEnumerated(uint8_t bits, uint32_t value) {
return appendByte(static_cast<uint8_t>(value));
}
inline void Message::appendEnumerated(uint8_t bits, uint32_t value) {
// TODO: Implement 32-bit enums, if needed // TODO: Implement 32-bit enums, if needed
assert((value & 0xffff0000) != 0); assert((value & 0xffff0000) != 0);
return appendBits(bits, value); 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, Message::Message(uint8_t serviceType, uint8_t messageType, Message::PacketType packetType,
uint16_t applicationId) : serviceType(serviceType), messageType(messageType), uint16_t applicationId) : serviceType(serviceType), messageType(messageType),
packetType(packetType), applicationId(applicationId) {} packetType(packetType), applicationId(applicationId) {}
#include <Services/TestService.hpp>
#include "Services/TestService.hpp" #include "Services/TestService.hpp"
void TestService::areYouAlive(const Message &request) { void TestService::areYouAlive(const Message &request) {
......
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