#pragma once #include "Messages/BinaryMsg.h" #include "Messages/InvestigateMsg.h" #include "Messages/ModelUrlMsg.h" #include "Messages/NameMsg.h" #include "Messages/ParticipantMsg.h" #include "Messages/PoseMsg.h" #include "Messages/SiteMsg.h" #include "Messages/ThingMsg.h" #include "Participant.h" #include #if defined(_WIN32) || defined(_WIN64) #include #elif defined(__unix__) || defined(__APPLE__) #include #include #include #include #elif defined(ARDUINO) #include #endif namespace RoboidControl { /// @brief A participant is device which can communicate with other participants class LocalParticipant : public Participant { public: char buffer[1024]; long publishInterval = 3000; // 3 seconds const char* name = "LocalParticipant"; // int localPort = 0; Participant* site = nullptr; #if defined(ARDUINO) const char* remoteIpAddress = nullptr; unsigned short remotePort = 0; char* broadcastIpAddress = nullptr; WiFiUDP udp; #else #if defined(_WIN32) || defined(_WIN64) SOCKET sock; #elif defined(__unix__) || defined(__APPLE__) int sock; #endif sockaddr_in remote_addr; sockaddr_in server_addr; sockaddr_in broadcast_addr; #endif LocalParticipant(int port = 7681); LocalParticipant(const char* ipAddress, int port = 7681); void begin(); bool connected = false; virtual void Update(unsigned long currentTimeMs = 0); 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); std::list senders; protected: unsigned long nextPublishMe = 0; void SetupUDP(int localPort, const char* remoteIpAddress, int remotePort); Participant* GetParticipant(const char* ipAddress, int port); Participant* AddParticipant(const char* ipAddress, int port); void ReceiveUDP(); virtual void Process(Participant* sender, ParticipantMsg* msg); virtual void Process(Participant* sender, SiteMsg* 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, PoseMsg* msg); virtual void Process(Participant* sender, BinaryMsg* msg); }; } // namespace RoboidControl