#ifndef DEBUGSERVICE_H #define DEBUGSERVICE_H #include "BasicTCPSocket.h" #include "BasicUDPSocket.h" #include "DebugServiceBase.h" #include "EmbeddedServiceMethodBinderI.h" #include "MessageI.h" #include "ReferenceT.h" #include "SingleThreadService.h" namespace MARTe { /** * @brief TCP/UDP implementation of DebugServiceI (via DebugServiceBase). * * Provides signal tracing (UDP), forced-value injection, break conditions, * and a text command channel (TCP) with a log-forwarding sidecar (TcpLogger). * All signal management and command dispatch logic lives in DebugServiceBase. */ class DebugService : public DebugServiceBase, public MessageI, public EmbeddedServiceMethodBinderI { public: friend class DebugServiceTest; CLASS_REGISTER_DECLARATION() DebugService(); virtual ~DebugService(); virtual bool Initialise(StructuredDataI &data); virtual ErrorManagement::ErrorType Execute(ExecutionInfo &info); virtual ErrorManagement::ErrorType HandleMessage(ReferenceT &data); protected: // Transport-specific overrides of DebugServiceBase hooks virtual void GetServiceInfo(StreamString &out); virtual void RebuildTransportConfig(); private: void InjectTcpLoggerIfNeeded(); ErrorManagement::ErrorType Server (ExecutionInfo &info); ErrorManagement::ErrorType Streamer(ExecutionInfo &info); // TCP/UDP-specific configuration uint16 controlPort; uint16 streamPort; uint16 logPort; StreamString streamIP; bool isServer; bool suppressTimeoutLogs; BasicTCPSocket tcpServer; BasicUDPSocket udpSocket; class ServiceBinder : public EmbeddedServiceMethodBinderI { public: enum ServiceType { ServerType, StreamerType }; ServiceBinder(DebugService *parent, ServiceType type) : parent(parent), type(type) {} virtual ErrorManagement::ErrorType Execute(ExecutionInfo &info) { if (type == StreamerType) return parent->Streamer(info); return parent->Server(info); } private: DebugService *parent; ServiceType type; }; ServiceBinder binderServer; ServiceBinder binderStreamer; SingleThreadService threadService; SingleThreadService streamerService; ThreadIdentifier serverThreadId; ThreadIdentifier streamerThreadId; // activeClient — exclusively owned by Server thread FastPollingMutexSem clientMutex; BasicTCPSocket *activeClient; // Streamer assembly buffer // STREAMER_MTU: target packet size for batching small signals (network-friendly). // STREAMER_BUFFER_SIZE: maximum UDP datagram payload; large single-signal samples // can exceed STREAMER_MTU and are sent as their own datagram up to this limit. static const uint32 STREAMER_MTU = 1400u; static const uint32 STREAMER_BUFFER_SIZE = 65535u; uint8 streamerPacketBuffer[STREAMER_BUFFER_SIZE]; // assembled outgoing packet uint8 streamerSampleBuffer[STREAMER_BUFFER_SIZE]; // staging for one popped sample uint32 streamerPacketOffset; uint32 streamerSequenceNumber; // Rate-limiting and idle-timeout constants / state static const uint32 CMD_RATE_LIMIT = 100u; static const uint32 CLIENT_IDLE_TIMEOUT_MS = 30000u; static const uint32 INPUT_BUFFER_MAX = 8192u; uint32 cmdCountInWindow; uint64 cmdWindowStartMs; uint64 lastDataTimeMs; // Carry-over buffer for multi-segment TCP commands StreamString inputBuffer; }; } // namespace MARTe #endif // DEBUGSERVICE_H