Roboid Control for C++
Loading...
Searching...
No Matches
d:/C/controlcore_cpp/Participant.h
1#pragma once
2
3//#include "Messages/"
4#include "Messages/ParticipantMsg.h"
5#include "Messages/BinaryMsg.h"
6#include "Messages/InvestigateMsg.h"
7#include "Messages/ModelUrlMsg.h"
8#include "Messages/NameMsg.h"
9#include "Messages/NetworkIdMsg.h"
10#include "Messages/PoseMsg.h"
11#include "Messages/ThingMsg.h"
12#include "RemoteParticipant.h"
13
14#include <list>
15
16#if defined(_WIN32) || defined(_WIN64)
17#include <winsock2.h>
18#elif defined(__unix__) || defined(__APPLE__)
19#include <arpa/inet.h>
20#include <netinet/in.h>
21#include <sys/socket.h>
22#include <unistd.h>
23#elif defined(ARDUINO)
24#include <WiFiUdp.h>
25#endif
26
27namespace Passer {
28namespace RoboidControl {
29
32public:
33 char buffer[1024];
34 long publishInterval = 3000; // 3 seconds
35 // unsigned char networkId = 0;
36
37 const char *name = "Participant";
38
39 // const char *ipAddress = "0.0.0.0";
40 // int port = 0;
41 int localPort = 0;
42
43#if defined(ARDUINO)
44 const char *remoteIpAddress = nullptr;
45 unsigned short remotePort = 0;
46 char *broadcastIpAddress = nullptr;
47
48 WiFiUDP udp;
49#else
50
51#if defined(_WIN32) || defined(_WIN64)
52 SOCKET sock;
53#elif defined(__unix__) || defined(__APPLE__)
54 int sock;
55#endif
56 sockaddr_in remote_addr;
57 sockaddr_in server_addr;
58 sockaddr_in broadcast_addr;
59
60#endif
61
63 Participant(int port);
64 Participant(const char *ipAddress, int port);
65
66 void begin();
67 bool connected = false;
68
69 virtual void Update(unsigned long currentTimeMs = 0);
70
71 // std::list<Thing *> things;
72 // Thing *Get(unsigned char networkId, unsigned char thingId);
73 // int Add(Thing *thing);
74 // void Remove(Thing *thing);
75 // void UpdateAll(unsigned long currentTimeMs);
76
77 void SendThingInfo(RemoteParticipant* remoteParticipant, Thing *thing);
78 void PublishThingInfo(Thing *thing);
79
80 bool Send(RemoteParticipant* remoteParticipant, IMessage *msg);
81 bool Publish(IMessage *msg);
82
83 void ReceiveData(unsigned char bufferSize, RemoteParticipant *remoteParticipant);
84
85protected:
86 std::list<Participant *> senders;
87
88 unsigned long nextPublishMe = 0;
89
90 void SetupUDP(int localPort, const char *remoteIpAddress, int remotePort);
91
92 Participant *GetParticipant(const char *ipAddress, int port);
93 Participant *AddParticipant(const char *ipAddress, int port);
94
95 void ReceiveUDP();
96
97 virtual void Process(RemoteParticipant *sender, ParticipantMsg *msg);
98 virtual void Process(RemoteParticipant *sender, NetworkIdMsg *msg);
99 virtual void Process(RemoteParticipant* sender, InvestigateMsg *msg);
100 virtual void Process(RemoteParticipant* sender, ThingMsg *msg);
101 virtual void Process(RemoteParticipant* sender, NameMsg *msg);
102 virtual void Process(RemoteParticipant* sender, PoseMsg *msg);
103 virtual void Process(RemoteParticipant* sender, BinaryMsg *msg);
104};
105
106} // namespace Control
107} // namespace Passer
108using namespace Passer::RoboidControl;
Root structure for all communcation messages.
Definition Messages.h:12
Message to request details for a Thing.
Definition InvestigateMsg.h:7
Message for communicating the name of a thing.
Definition NameMsg.h:7
A message communicating the network ID for that participant.
Definition NetworkIdMsg.h:7
A participant is device which can communicate with other participants.
Definition Participant.h:31
A participant messages notifies other participants of its presence When received by another participa...
Definition ParticipantMsg.h:11
Message to communicate the pose of the thing The pose is in local space relative to the parent....
Definition PoseMsg.h:9
A reference to a participant, possibly on a remote location.
Definition RemoteParticipant.h:8
int port
The UDP port on which the participant can be reached.
Definition RemoteParticipant.h:13
const char * ipAddress
The internet address of the participant.
Definition RemoteParticipant.h:11
A thing is the primitive building block.
Definition Thing.h:17
Message providing generic information about a Thing.
Definition ThingMsg.h:7