libdoip  0.1.0
DoIP (Diagnostics over Internet Protocol) ISO 13400 C++17 Library
doip::DoIPServer Class Reference

DoIP Server class to handle incoming DoIP connections and UDP messages. More...

#include <DoIPServer.h>

Public Member Functions

 DoIPServer (const ServerConfig &config=DefaultServerConfig)
 Construct a DoIP server with the given configuration. More...
 
 ~DoIPServer ()
 Destructor. More...
 
 DoIPServer (const DoIPServer &)=delete
 
DoIPServeroperator= (const DoIPServer &)=delete
 
 DoIPServer (DoIPServer &&)=delete
 
DoIPServeroperator= (DoIPServer &&)=delete
 
bool setupTcpSocket ()
 Initialize and bind the TCP socket for DoIP. More...
 
template<typename Model = DefaultDoIPServerModel>
std::unique_ptr< DoIPConnectionwaitForTcpConnection ()
 Block until a TCP client connects and create a DoIP connection. More...
 
bool setupUdpSocket ()
 Initialize and bind the UDP socket for announcements and UDP messages. More...
 
bool isRunning () const
 Check if the server is currently running. More...
 
void setAnnounceNum (int Num)
 Set the number of vehicle announcements to send. More...
 
void setAnnounceInterval (unsigned int Interval)
 Set the interval between announcements in milliseconds. More...
 
void setLoopbackMode (bool useLoopback)
 Enable/disable loopback mode for announcements (no broadcast). More...
 
void closeTcpSocket ()
 Close the TCP socket if open. More...
 
void closeUdpSocket ()
 Close the UDP socket if open. More...
 
void setLogicalGatewayAddress (DoIPAddress logicalAddress)
 Set the logical DoIP gateway address. More...
 
bool setDefaultEid ()
 Sets the EID to a default value based on the MAC address. More...
 
void setVin (const std::string &VINString)
 Set VIN from a 17-character string. More...
 
void setVin (const DoIpVin &vin)
 Set VIN from a DoIpVin instance. More...
 
const DoIpVingetVin () const
 Get current VIN. More...
 
void setEid (uint64_t nputEID)
 Set EID value. More...
 
const DoIpEidgetEid () const
 Get current EID. More...
 
void setGid (uint64_t inputGID)
 Set GID value. More...
 
const DoIpGidgetGid () const
 Get current GID. More...
 
DoIPFurtherAction getFurtherActionRequired () const
 Get current further action requirement status. More...
 
void setFurtherActionRequired (DoIPFurtherAction furtherActionRequired)
 Set further action requirement status. More...
 
std::string getClientIp () const
 Get last accepted client IP (string form). More...
 
int getClientPort () const
 Get last accepted client TCP port. More...
 

Detailed Description

DoIP Server class to handle incoming DoIP connections and UDP messages.

This class manages the low-level TCP/UDP socket handling.

Definition at line 70 of file DoIPServer.h.

Constructor & Destructor Documentation

◆ DoIPServer() [1/3]

DoIPServer::DoIPServer ( const ServerConfig config = DefaultServerConfig)
explicit

Construct a DoIP server with the given configuration.

Parameters
configServer configuration (EID/GID/VIN, announce params, etc.).

Definition at line 24 of file DoIPServer.cpp.

References doip::ServerConfig::daemonize, doip::ServerConfig::loopback, and setLoopbackMode().

◆ ~DoIPServer()

DoIPServer::~DoIPServer ( )

Destructor.

Ensures sockets/threads are closed/stopped.

Definition at line 18 of file DoIPServer.cpp.

◆ DoIPServer() [2/3]

doip::DoIPServer::DoIPServer ( const DoIPServer )
delete

◆ DoIPServer() [3/3]

doip::DoIPServer::DoIPServer ( DoIPServer &&  )
delete

Member Function Documentation

◆ closeTcpSocket()

void DoIPServer::closeTcpSocket ( )

Close the TCP socket if open.

Definition at line 164 of file DoIPServer.cpp.

◆ closeUdpSocket()

void DoIPServer::closeUdpSocket ( )

Close the UDP socket if open.

Definition at line 220 of file DoIPServer.cpp.

◆ getClientIp()

std::string doip::DoIPServer::getClientIp ( ) const
inline

Get last accepted client IP (string form).

Returns
IP address string.

Definition at line 209 of file DoIPServer.h.

◆ getClientPort()

int doip::DoIPServer::getClientPort ( ) const
inline

Get last accepted client TCP port.

Returns
Client port number.

Definition at line 214 of file DoIPServer.h.

◆ getEid()

const DoIpEid& doip::DoIPServer::getEid ( ) const
inline

Get current EID.

Returns
Reference to configured EID.

Definition at line 181 of file DoIPServer.h.

References doip::ServerConfig::eid.

◆ getFurtherActionRequired()

DoIPFurtherAction doip::DoIPServer::getFurtherActionRequired ( ) const
inline

Get current further action requirement status.

Returns
Current DoIPFurtherAction value.

Definition at line 198 of file DoIPServer.h.

◆ getGid()

const DoIpGid& doip::DoIPServer::getGid ( ) const
inline

Get current GID.

Returns
Reference to configured GID.

Definition at line 192 of file DoIPServer.h.

References doip::ServerConfig::gid.

◆ getVin()

const DoIpVin& doip::DoIPServer::getVin ( ) const
inline

Get current VIN.

Returns
Reference to configured VIN.

Definition at line 170 of file DoIPServer.h.

References doip::ServerConfig::vin.

◆ isRunning()

bool doip::DoIPServer::isRunning ( ) const
inline

Check if the server is currently running.

Definition at line 115 of file DoIPServer.h.

◆ operator=() [1/2]

DoIPServer& doip::DoIPServer::operator= ( const DoIPServer )
delete

◆ operator=() [2/2]

DoIPServer& doip::DoIPServer::operator= ( DoIPServer &&  )
delete

◆ setAnnounceInterval()

void DoIPServer::setAnnounceInterval ( unsigned int  Interval)

Set the interval between announcements in milliseconds.

Parameters
IntervalInterval in ms.

Definition at line 271 of file DoIPServer.cpp.

References doip::ServerConfig::announceInterval.

◆ setAnnounceNum()

void DoIPServer::setAnnounceNum ( int  Num)

Set the number of vehicle announcements to send.

Parameters
NumCount of announcements.

Definition at line 267 of file DoIPServer.cpp.

References doip::ServerConfig::announceCount.

◆ setDefaultEid()

bool DoIPServer::setDefaultEid ( )

Sets the EID to a default value based on the MAC address.

Returns
true if the EID was successfully set to the default value.
false if the default EID could not be set.

Definition at line 230 of file DoIPServer.cpp.

References doip::ServerConfig::eid, doip::getFirstMacAddress(), doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH, LOG_DOIP_ERROR, and doip::GenericFixedId< 6, false >::Zero.

◆ setEid()

void DoIPServer::setEid ( uint64_t  nputEID)

Set EID value.

Parameters
nputEIDEID as 64-bit value (lower 48 bits used).

Definition at line 255 of file DoIPServer.cpp.

References doip::ServerConfig::eid.

◆ setFurtherActionRequired()

void DoIPServer::setFurtherActionRequired ( DoIPFurtherAction  furtherActionRequired)

Set further action requirement status.

Parameters
furtherActionRequiredValue to set.

Definition at line 263 of file DoIPServer.cpp.

◆ setGid()

void DoIPServer::setGid ( uint64_t  inputGID)

Set GID value.

Parameters
inputGIDGID as 64-bit value (lower 48 bits used).

Definition at line 259 of file DoIPServer.cpp.

References doip::ServerConfig::gid.

◆ setLogicalGatewayAddress()

void DoIPServer::setLogicalGatewayAddress ( DoIPAddress  logicalAddress)

Set the logical DoIP gateway address.

Parameters
logicalAddressLogical address value.

Definition at line 251 of file DoIPServer.cpp.

References doip::ServerConfig::logicalAddress.

◆ setLoopbackMode()

void DoIPServer::setLoopbackMode ( bool  useLoopback)

Enable/disable loopback mode for announcements (no broadcast).

Parameters
useLoopbackTrue to use loopback, false for broadcast.

Definition at line 275 of file DoIPServer.cpp.

References LOG_DOIP_INFO, and doip::ServerConfig::loopback.

Referenced by DoIPServer().

◆ setupTcpSocket()

bool DoIPServer::setupTcpSocket ( )

Initialize and bind the TCP socket for DoIP.

Returns
true on success, false otherwise.

Definition at line 132 of file DoIPServer.cpp.

References doip::DOIP_SERVER_TCP_PORT, LOG_DOIP_DEBUG, LOG_TCP_ERROR, LOG_TCP_INFO, and LOG_TCP_WARN.

◆ setupUdpSocket()

bool DoIPServer::setupUdpSocket ( )

Initialize and bind the UDP socket for announcements and UDP messages.

Returns
true on success, false otherwise.

Definition at line 168 of file DoIPServer.cpp.

References LOG_UDP_DEBUG, LOG_UDP_INFO, and doip::ServerConfig::loopback.

◆ setVin() [1/2]

void DoIPServer::setVin ( const DoIpVin vin)

Set VIN from a DoIpVin instance.

Parameters
vinVIN value.

Definition at line 247 of file DoIPServer.cpp.

References doip::ServerConfig::vin.

◆ setVin() [2/2]

void DoIPServer::setVin ( const std::string &  VINString)

Set VIN from a 17-character string.

Parameters
VINStringVIN string (17 bytes expected).

Definition at line 242 of file DoIPServer.cpp.

References doip::ServerConfig::vin.

◆ waitForTcpConnection()

template<typename Model >
std::unique_ptr< DoIPConnection > doip::DoIPServer::waitForTcpConnection

Block until a TCP client connects and create a DoIP connection.

Template Parameters
ModelServer model type used by the connection (default DefaultDoIPServerModel).
Returns
Unique pointer to established DoIPConnection, or nullptr on failure.

Definition at line 255 of file DoIPServer.h.


The documentation for this class was generated from the following files: