Roboid Control for C++ 0.4
Loading...
Searching...
No Matches
ParticipantUDP.h
1#pragma once
2
3#include "Messages/BinaryMsg.h"
4#include "Messages/DestroyMsg.h"
5#include "Messages/InvestigateMsg.h"
6#include "Messages/ModelUrlMsg.h"
7#include "Messages/NameMsg.h"
8#include "Messages/ParticipantMsg.h"
9#include "Messages/PoseMsg.h"
10#include "Messages/NetworkIdMsg.h"
11#include "Messages/ThingMsg.h"
12#include "Messages/TextMsg.h"
13#include "Participant.h"
14
15#if !defined(NO_STD)
16#include <functional>
17#include <list>
18// #include <unordered_map>
19#endif
20
21#if defined(_WIN32) || defined(_WIN64)
22#include <winsock2.h>
23#elif defined(__unix__) || defined(__APPLE__)
24#include <arpa/inet.h>
25#include <netinet/in.h>
26#include <sys/socket.h>
27#include <unistd.h>
28#endif
29
30namespace RoboidControl {
31
32constexpr int MAX_SENDER_COUNT = 256;
33
47
48#pragma region Init
49
50 public:
56 ParticipantUDP(int port = 7681);
61 ParticipantUDP(const char* ipAddress, int port = 7681, int localPort = 7681);
62
63#pragma endregion Init
64
65#pragma region Properties
66
67public:
70 bool isIsolated = false;
71
74
77 long publishInterval = 3000; // 3 seconds
78
79 protected:
80
81#if !defined(ARDUINO)
82#if defined(__unix__) || defined(__APPLE__)
83 int sock;
84#elif defined(_WIN32) || defined(_WIN64)
85 sockaddr_in remote_addr;
86 sockaddr_in server_addr;
87 sockaddr_in broadcast_addr;
88#endif
89#endif
90 public:
91 void begin();
92 bool connected = false;
93
94#pragma endregion Properties
95
96#pragma region Update
97
98 public:
99 virtual void Update() override;
100
101 protected:
102 unsigned long nextPublishMe = 0;
103
105 virtual void PrepMyThings();
106 virtual void UpdateMyThings();
107 virtual void UpdateOtherThings();
108
109#pragma endregion Update
110
111#pragma region Send
112
113 void SendThingInfo(Participant* remoteParticipant, Thing* thing);
114 void PublishThingInfo(Thing* thing);
115
116 virtual bool Send(IMessage* msg) override;
117 bool Publish(IMessage* msg);
118
119#pragma endregion Send
120
121#pragma region Receive
122
123protected:
124 void ReceiveData(unsigned char bufferSize,
125 char* senderIpAddress,
126 unsigned int senderPort);
127 void ReceiveData(unsigned char bufferSize, Participant* remoteParticipant);
128
129 void SetupUDP(int localPort, const char* remoteIpAddress, int remotePort);
130
131 void ReceiveUDP();
132
133 virtual void Process(Participant* sender, ParticipantMsg* msg);
134 virtual void Process(Participant* sender, NetworkIdMsg* msg);
135 virtual void Process(Participant* sender, InvestigateMsg* msg);
136 virtual void Process(Participant* sender, ThingMsg* msg);
137 virtual void Process(Participant* sender, NameMsg* msg);
138 virtual void Process(Participant* sender, ModelUrlMsg* msg);
139 virtual void Process(Participant* sender, PoseMsg* msg);
140 virtual void Process(Participant* sender, BinaryMsg* msg);
141 virtual void Process(Participant* sender, TextMsg* msg);
142 virtual void Process(Participant* sender, DestroyMsg* msg);
143
144#pragma endregion Receive
145
146};
147
148} // namespace RoboidControl
A message containing binary data for custom communication.
Definition BinaryMsg.h:9
A Message notifiying that a Thing no longer exists.
Definition DestroyMsg.h:9
Root structure for all communcation messages.
Definition IMessage.h:6
Message to request details for a Thing.
Definition InvestigateMsg.h:9
Message for communicating the URL for a model of the thing.
Definition ModelUrlMsg.h:9
Message for communicating the name of a thing.
Definition NameMsg.h:9
A message communicating the network ID for that participant.
Definition NetworkIdMsg.h:8
A participant is a device which manages things. It can communicate with other participant to synchron...
Definition Participant.h:62
unsigned int port
The port number for UDP communication with the participant.
Definition Participant.h:98
const char * ipAddress
The Ip Address of a participant.
Definition Participant.h:94
A participant messages notifies other participants of its presence When received by another participa...
Definition ParticipantMsg.h:10
A participant using UDP communication A local participant is the local device which can communicate w...
Definition ParticipantUDP.h:46
ParticipantUDP(int port=7681)
Create a participant without connecting to a site.
virtual void PrepMyThings()
Prepare the local things for the next update.
virtual void Update() override
Update all things for this participant.
Participant * remoteSite
The remote site when this participant is connected to a site.
Definition ParticipantUDP.h:73
ParticipantUDP(const char *ipAddress, int port=7681, int localPort=7681)
Create a participant which will try to connect to a site.
bool isIsolated
True if the participant is running isolated. Isolated participants do not communicate with other part...
Definition ParticipantUDP.h:70
long publishInterval
Definition ParticipantUDP.h:77
Message to communicate the pose of the thing The pose is in local space relative to the parent....
Definition PoseMsg.h:10
Message for sending generic text.
Definition TextMsg.h:6
A thing is the primitive building block.
Definition Thing.h:20
Message providing generic details about a Thing.
Definition ThingMsg.h:7