Skip to content

CoreSimNet.h#

ROS/acres_core_sim/include/acres_core_sim/CoreSimNet.h Generated

The game's local transports, served: a TCP port on 127.0.0.1 with one client at a time (a second client waits in the listen backlog until the first disconnects), as the game's sensor stream (AcresSensorStream.h), RL / DBW bridge (AcresRlBridge.h) and simulator-control channel (AcresSimControl.h) are. acres_sim's clients (stream.hpp) connect to it unchanged.

Each port has an I/O thread (accept, then read until the client closes) and a sender thread, so a slow client never blocks the simulation: output is queued, and above MaxQueuedBytes droppable frames (LiDAR clouds) are dropped and counted, as the game's stream drops them. Input lines are stamped with CLOCK_MONOTONIC at arrival (the command timing of AcresCommandTiming.h needs it); Drain() reads what the socket holds right now on the caller's thread, so a line a client wrote before a request on another port is handled before that request (loopback delivers into the receive buffer before send() returns).

Also the stream's frame encoder (32-byte header "TSS1": type, flags, sequence, payload bytes, stamp, publish time).

MonotonicS#

CLOCK_MONOTONIC in seconds (the clock of the stream's publish stamps and of the arrival stamps).

double MonotonicS();

EncodeFrame#

Encodes one stream frame: header ("TSS1", type, flags 0, sequence, payload bytes, stamp, CLOCK_MONOTONIC now) and payload.

Argument Description
Type Frame type.
Sequence Per-stream sequence number (all types).
StampS Simulation time of the data, s. Head, HeadBytes: Leading payload bytes (the LiDAR sub-header), may be null. Body, BodyBytes: Payload body.

Returns: The frame's bytes.

std::string EncodeFrame(uint16_t Type, uint32_t Sequence, double StampS, const void* Head, size_t HeadBytes, const void* Body, size_t BodyBytes);

FLine#

struct FLine

A received line and its arrival time.

FServedPort#

class FServedPort

One served port. See the file comment.

FServedPort::size_t#

Queued output above which droppable frames are dropped, bytes (the game's FAcresSensorStream::MaxQueuedBytes).

static constexpr size_t MaxQueuedBytes = size_t(96) << 20;

FServedPort::Open#

Binds 127.0.0.1:Port and listens.

Argument Description
Port TCP port (1-65535).
Name For the log ("control", "stream polaris", ...).
Error Why it failed.

Returns: False when the port cannot be bound (in use).

bool Open(int Port, const std::string& Name, std::string* Error);

FServedPort::Start#

Starts the threads.

Argument Description
bReadLines Collect newline-delimited input lines (JSON ports); else input is read and discarded.
OnConnect Called on the I/O thread when a client connects; what it returns is queued first (the stream's hello frame, the control channel's episode event), before anything the simulation queues later.
Wake Notified whenever a line arrives (the simulation loop waits on it).
void Start(bool bReadLines, std::function<std::string()> OnConnect, std::condition_variable_any* Wake);

FServedPort::Stop#

Stops the threads and closes the sockets.

void Stop();

FServedPort::Send#

Queues bytes for the connected client (dropped when none is connected).

Argument Description
Bytes The data (moved).
bDroppable May be dropped when the client lags (above MaxQueuedBytes).

Returns: False when nothing is connected or the frame was dropped.

bool Send(std::string Bytes, bool bDroppable = false);

FServedPort::Drain#

Reads whatever the socket holds now (non-blocking) into the line queue.

void Drain();

FServedPort::TakeLines#

Takes the lines received so far.

std::vector<FLine> TakeLines();

FServedPort::Connected#

A client is connected; connections so far; the port.

bool Connected() const ;

FServedPort::Flush#

Waits until everything queued before the call has been written to the socket (or the client is gone).

void Flush();

FServedPort::Dropped#

Frames dropped so far.

uint64_t Dropped() const ;

FServedPort::QueuedBytes#

Output bytes queued and not yet written.

size_t QueuedBytes() ;

EStreamFrame#

enum EStreamFrame : uint16_t

Stream frame types (AcresSensorStream.h EFrame).

Value Description
FrameHello
FrameClock
FrameIns
FrameLidar
FrameCamera
FrameBarrier