diff --git a/inc/Services/OnBoardMonitoringService.hpp b/inc/Services/OnBoardMonitoringService.hpp index 6af64f36094d4ddd577ba813b1a92da81d464c59..d67bf35176f980da78bcde8ca4c1c59f0f734f08 100644 --- a/inc/Services/OnBoardMonitoringService.hpp +++ b/inc/Services/OnBoardMonitoringService.hpp @@ -98,4 +98,4 @@ public: void execute(Message& message); }; -#endif // ECSS_SERVICES_ONBOARDMONITORINGSERVICE_HPP +#endif // ECSS_SERVICES_ONBOARDMONITORINGSERVICE_HPP \ No newline at end of file diff --git a/src/Platform/x86/Service.cpp b/src/Platform/x86/Service.cpp index 60786fc650c32da32cb98860886291537e378fce..f316a764a1a679cf1126e8f3f0e1994592b8c8bc 100644 --- a/src/Platform/x86/Service.cpp +++ b/src/Platform/x86/Service.cpp @@ -1,7 +1,47 @@ -#include <iostream> -#include <iomanip> -#include <Logger.hpp> #include "Service.hpp" +#include <Logger.hpp> +#include <MessageParser.hpp> +#include <arpa/inet.h> +#include <iomanip> +#include <iostream> +#include <netinet/in.h> +#include <string> +#include <sys/socket.h> +#include <unistd.h> + +class PacketSender { +private: + const char* hostname = "127.0.0.1"; + const uint16_t port = 10015; + sockaddr_in destination; + int socket; + +public: + PacketSender() { + socket = ::socket(AF_INET, SOCK_DGRAM, 0); + destination.sin_family = AF_INET; + destination.sin_port = htons(port); + destination.sin_addr.s_addr = inet_addr(hostname); + }; + + ~PacketSender() { + ::close(socket); + }; + + void sendPacketToYamcs(Message& message) { + // Add ECSS and CCSDS header + String<CCSDSMaxMessageSize> createdPacket = MessageParser::compose(message); + auto bytesSent = ::sendto(socket, createdPacket.c_str(), createdPacket.length(), 0, reinterpret_cast<sockaddr*>(&destination), sizeof(destination)); + LOG_DEBUG << bytesSent << " bytes sent"; + } +}; + +PacketSender packetSender; + +/** + * If set to true, the created messages will be sent to port 10025 on localhost for testing purposes. + */ +inline const bool SendToYamcs = true; void Service::storeMessage(Message& message) { // appends the remaining bits to complete a byte @@ -14,12 +54,17 @@ void Service::storeMessage(Message& message) { ss << "New " << ((message.packetType == Message::TM) ? "TM" : "TC") << "[" << std::hex << static_cast<int>(message.serviceType) << "," // Ignore-MISRA - << static_cast<int>(message.messageType) // Ignore-MISRA + << static_cast<int>(message.messageType) // Ignore-MISRA << "] message! "; for (unsigned int i = 0; i < message.dataSize; i++) { ss << static_cast<int>(message.data[i]) << " "; // Ignore-MISRA } + + // Send data to YAMCS port + if constexpr (SendToYamcs) { + packetSender.sendPacketToYamcs(message); + } LOG_DEBUG << ss.str(); }