techCommunication Reference
Module defined in `lua/common/tech/techCommunication.lua`. TCP socket communication layer for BeamNG's tech/co-simulation interface. Handles client connections, MessagePack-encoded message exchange, a
Module defined in lua/common/tech/techCommunication.lua. TCP socket communication layer for BeamNG's tech/co-simulation interface. Handles client connections, MessagePack-encoded message exchange, and request routing.
Exports
Functions
M.openServer(port, ip)
Open a TCP server on the given port and IP.
- Parameters:
port- number - TCP port to listen onip- string|nil - Bind IP address (default: all interfaces)
- Returns: table - Server object with socket handle
M.checkForClients(servers)
Accept pending client connections on server sockets.
- Parameters:
servers- table - Array of server objects
- Returns: table - Newly connected client sockets
M.receive(skt)
Receive a complete message from a socket (length-prefixed protocol).
- Parameters:
skt- socket - Connected TCP socket
- Returns: string, nil - Received data and error (nil on success)
M.checkMessages(E, clients)
Poll all client sockets for incoming messages, decode via MessagePack, and dispatch to request handlers.
- Parameters:
E- table - Extension/environment with request handlersclients- table - Array of connected client sockets
- Returns: boolean - false if no messages processed
M.callRequestHandler(E, request)
Route a decoded request to the appropriate handler function on E.
- Parameters:
E- table - Extension table with handler functionsrequest- table - Decoded request with type field
- Returns: boolean - false if handler not found
M.sendMessage(skt, message)
Encode and send a MessagePack message with length prefix.
- Parameters:
skt- socket - Target socketmessage- table - Message to encode and send
M.sendLegacyError(skt, error)
Send a legacy-format error message.
- Parameters:
skt- socket - Target socketerror- string - Error message
M.sanitizeTable(tab)
Recursively sanitize a table for MessagePack serialization (remove unsupported types).
- Parameters:
tab- table - Input table
- Returns: table - Sanitized copy
M.newSet()
Create a simple set data structure (from LuaSocket samples).
- Returns: table - Set with insert/remove via metamethods
M.enableDebug()
Enable debug logging for communication.
M.disableDebug()
Disable debug logging.
Variables
M.protocolVersion
- Type: string
- Description: Current protocol version string (
'v1.26')
Internal Notes
- Wire protocol: 4-byte big-endian unsigned length prefix + MessagePack payload
- Uses LuaSocket for TCP networking
- Uses FFI for
packUnsignedInt32Network/unpackUnsignedInt32Network - Request handlers are methods on the extension table
Ematching request type names - Supports recording mode integration via
checkIfRecording
pcdLib Reference
Module defined in `lua/common/tech/pcdLib.lua`. Creates PCD (Point Cloud Data) files - the standard format for lidar, radar, and other point cloud sensor data.
techUtils Reference
Module defined in `lua/common/tech/techUtils.lua`. Utility functions for the tech/co-simulation layer - surface height queries and table-to-vector conversions.