Roboid Control for C++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
RoboidControl::ParticipantUDP Class Reference

Detailed Description

A participant using UDP communication A local participant is the local device which can communicate with other participants It manages all local things and communcation with other participants. Each application has a local participant which is usually explicit in the code. An participant can be isolated. In that case it is standalong and does not communicate with other participants.

It is possible to work with an hidden participant by creating things without specifying a participant in the constructor. In that case an hidden isolated participant is created which can be obtained using RoboidControl::IsolatedParticipant::Isolated().

See also
RoboidControl::Thing::Thing()

#include <ParticipantUDP.h>

Inheritance diagram for RoboidControl::ParticipantUDP:
RoboidControl::Participant RoboidControl::SiteServer

Public Member Functions

 ParticipantUDP (int port=7681)
 Create a participant without connecting to a site.
 
 ParticipantUDP (const char *ipAddress, int port=7681, int localPort=7681)
 Create a participant which will try to connect to a site.
 
void begin ()
 
virtual void Update (unsigned long currentTimeMs=0) override
 Update all things for this participant.
 
ThingGet (unsigned char thingId)
 Find a thing managed by this participant.
 
void Add (Thing *thing, bool checkId=true)
 Add a new thing for this participant.
 
void Remove (Thing *thing)
 Remove a thing for this participant.
 

Static Public Member Functions

static ParticipantUDPIsolated ()
 Isolated participant is used when the application is run without networking.
 

Public Attributes

bool isIsolated = false
 True if the participant is running isolated. Isolated participants do not communicate with other participants.
 
ParticipantremoteSite = nullptr
 The remote site when this participant is connected to a site.
 
long publishInterval = 3000
 
const char * name = "ParticipantUDP"
 The name of the participant.
 
bool connected = false
 
const char * ipAddress = "0.0.0.0"
 The Ip Address of a participant.
 
unsigned int port = 0
 The port number for UDP communication with the participant.
 
unsigned char networkId = 0
 The network Id to identify the participant.
 
unsigned char thingCount = 0
 
Thingthings [MAX_THING_COUNT]
 
std::list< Thing * > things
 The things managed by this participant.
 

Static Public Attributes

static ParticipantRegistry registry
 

Protected Member Functions

virtual void UpdateMyThings (unsigned long currentTimeMs)
 
virtual void UpdateOtherThings (unsigned long currentTimeMs)
 
void SendThingInfo (Participant *remoteParticipant, Thing *thing)
 
void PublishThingInfo (Thing *thing)
 
bool Send (Participant *remoteParticipant, IMessage *msg)
 
bool Publish (IMessage *msg)
 
void ReceiveData (unsigned char bufferSize, char *senderIpAddress, unsigned int senderPort)
 
void ReceiveData (unsigned char bufferSize, Participant *remoteParticipant)
 
void SetupUDP (int localPort, const char *remoteIpAddress, int remotePort)
 
void ReceiveUDP ()
 
virtual void Process (Participant *sender, ParticipantMsg *msg)
 
virtual void Process (Participant *sender, NetworkIdMsg *msg)
 
virtual void Process (Participant *sender, InvestigateMsg *msg)
 
virtual void Process (Participant *sender, ThingMsg *msg)
 
virtual void Process (Participant *sender, NameMsg *msg)
 
virtual void Process (Participant *sender, ModelUrlMsg *msg)
 
virtual void Process (Participant *sender, PoseMsg *msg)
 
virtual void Process (Participant *sender, BinaryMsg *msg)
 

Protected Attributes

char buffer [1024]
 
int sock
 
sockaddr_in remote_addr
 
sockaddr_in server_addr
 
sockaddr_in broadcast_addr
 
unsigned long nextPublishMe = 0
 

Constructor & Destructor Documentation

◆ ParticipantUDP() [1/2]

RoboidControl::ParticipantUDP::ParticipantUDP ( int  port = 7681)

Create a participant without connecting to a site.

Parameters
portThe port on which the participant communicates These participant typically broadcast Participant messages to let site servers on the local network know their presence. Alternatively they can broadcast information which can be used directly by other participants.

◆ ParticipantUDP() [2/2]

RoboidControl::ParticipantUDP::ParticipantUDP ( const char *  ipAddress,
int  port = 7681,
int  localPort = 7681 
)

Create a participant which will try to connect to a site.

Parameters
ipAddressThe IP address of the site
portThe port used by the site
localPortThe port used by the local participant

Member Function Documentation

◆ Isolated()

ParticipantUDP * RoboidControl::ParticipantUDP::Isolated ( )
static

Isolated participant is used when the application is run without networking.

Returns
A participant without networking support

◆ Update()

void RoboidControl::ParticipantUDP::Update ( unsigned long  currentTimeMs = 0)
overridevirtual

Update all things for this participant.

Parameters
currentTimeMsThe current time in milliseconds (optional)

Reimplemented from RoboidControl::Participant.

◆ Get()

Thing * RoboidControl::Participant::Get ( unsigned char  thingId)
inherited

Find a thing managed by this participant.

Parameters
thingIdThe ID of the thing
Returns
The thing if found, nullptr when no thing has been found

◆ Add()

void RoboidControl::Participant::Add ( Thing thing,
bool  checkId = true 
)
inherited

Add a new thing for this participant.

Parameters
thingThe thing to add
checkIdIf true, the thing.id is regenerated if it is zero

◆ Remove()

void RoboidControl::Participant::Remove ( Thing thing)
inherited

Remove a thing for this participant.

Parameters
thingThe thing to remove

Member Data Documentation

◆ isIsolated

bool RoboidControl::ParticipantUDP::isIsolated = false

True if the participant is running isolated. Isolated participants do not communicate with other participants.

True if the participant is running isolated. Isolated participants do not communicate with other participants

◆ publishInterval

long RoboidControl::ParticipantUDP::publishInterval = 3000

The interval in milliseconds for publishing (broadcasting) data on the local network