diff --git a/CMakeLists.txt b/CMakeLists.txt index da5aa37c441fcc3a5001daade0debc5abfb94e41..1a0a37c20fb7c77cbbe9bb2b4a1214f1615618cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.9) project(ecss_services) # Set C++ version to c++17 @@ -8,4 +8,4 @@ set(CMAKE_CXX_STANDARD 17) include_directories ("${PROJECT_SOURCE_DIR}/inc") # Specify the .cpp files for the executables -add_executable(ecss_services main.cpp src/Message.cpp) \ No newline at end of file +add_executable(ecss_services src/main.cpp src/Message.cpp) diff --git a/inc/ECSS_Definitions.h b/inc/ECSS_Definitions.hpp similarity index 100% rename from inc/ECSS_Definitions.h rename to inc/ECSS_Definitions.hpp diff --git a/inc/Message.h b/inc/Message.hpp similarity index 87% rename from inc/Message.h rename to inc/Message.hpp index 3b2ba62a977ab1613f88c952bd83ed31365f603b..afd32582a1f96855351fc7995170a13dc3e2ffb2 100644 --- a/inc/Message.h +++ b/inc/Message.hpp @@ -1,9 +1,9 @@ #ifndef ECSS_SERVICES_PACKET_H #define ECSS_SERVICES_PACKET_H +#include "ECSS_Definitions.hpp" #include <cstdint> #include <cassert> -#include "ECSS_Definitions.h" /** * A telemetry (TM) or telecommand (TC) message (request/report), as specified in ECSS-E-ST-70-41C @@ -26,14 +26,16 @@ public: uint16_t applicationId; // 7.4.3.1b - uint16_t messageTypeCounter; + uint16_t messageTypeCounter = 0; // TODO: Find out if we need more than 16 bits for this - uint16_t dataSize; + uint16_t dataSize = 0; - // We allocate this data statically, in order to make sure there is predictability in the handling and - // storage of messages - uint8_t data[ECSS_MAX_MESSAGE_SIZE]; // Pointer to the contents of the message (excluding the PUS header) + // Pointer to the contents of the message (excluding the PUS header) + // We allocate this data statically, in order to make sure there is predictability in the + // handling and storage of messages + // TODO: Is it a good idea to not initialise this to 0? + uint8_t data[ECSS_MAX_MESSAGE_SIZE] = { '\0' }; //private: uint8_t currentBit = 0; @@ -70,6 +72,9 @@ public: */ void appendString(uint8_t size, const char * value); public: + Message(uint8_t serviceType, uint8_t messageType, PacketType packetType, + uint16_t applicationId); + /** * Adds a single-byte boolean value to the end of the message * @@ -78,7 +83,8 @@ public: void appendBoolean(bool value); /** - * Adds an enumerated parameter consisting of an arbitrary number of bits to the end of the message + * Adds an enumerated parameter consisting of an arbitrary number of bits to the end of the + * message * * PTC = 1, PFC = \p bits */ diff --git a/src/Message.cpp b/src/Message.cpp index e20ac13598404e3ec2e2a2732f1707a16597c63f..61ef26afb70971833089ecad58324a7011bcd68a 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -1,8 +1,6 @@ -#include <Message.h> +#include "Message.hpp" #include <cstring> -#include "Message.h" - void Message::appendBits(uint8_t numBits, uint16_t data) { assert(dataSize < ECSS_MAX_MESSAGE_SIZE); assert(numBits < 16); @@ -11,7 +9,6 @@ void Message::appendBits(uint8_t numBits, uint16_t data) { if (currentBit + numBits >= 8) { // Will have to shift the bits and insert the next ones later auto bitsToAddNow = static_cast<uint8_t>(8 - currentBit); - auto maskedFirstBits = static_cast<uint8_t>(data >> (numBits - bitsToAddNow)); this->data[dataSize] |= static_cast<uint8_t>(data >> (numBits - bitsToAddNow)); @@ -116,7 +113,11 @@ void Message::appendInteger(int32_t value) { } void Message::appendReal(float value) { - static_assert(sizeof(uint32_t) == sizeof(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/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b799fe9cfcf28d4f042aea8fa50adb89b8d7f278 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,17 @@ +#include <iostream> +#include <cstring> +#include "Message.hpp" + +int main() { + Message packet = Message(0, 0, Message::TC, 1); + + packet.appendString(5, "hello"); + packet.appendBits(15, 0x28a8); + packet.appendBits(1, 1); + packet.appendReal(5.7); + + std::cout << "Hello, World!" << std::endl; + std::cout << std::hex << packet.data << std::endl; // packet data must be 'helloQQ' +// std::cout << *(reinterpret_cast<float*>(packet.data + 7)) << std::endl; + return 0; +}