#pragma once //#include "Messages/" #include "Messages/ParticipantMsg.h" #include "Messages/BinaryMsg.h" #include "Messages/InvestigateMsg.h" #include "Messages/ModelUrlMsg.h" #include "Messages/NameMsg.h" #include "Messages/NetworkIdMsg.h" #include "Messages/PoseMsg.h" #include "Messages/ThingMsg.h" #include "RemoteParticipant.h" #include #if defined(_WIN32) || defined(_WIN64) #include #elif defined(__unix__) || defined(__APPLE__) #include #include #include #include #elif defined(ARDUINO) #include #endif namespace Passer { namespace RoboidControl { /// @brief A participant is device which can communicate with other participants class Participant : public RemoteParticipant { public: unsigned char buffer[1024]; long publishInterval = 3000; // 3 seconds // unsigned char networkId = 0; const char *name = "Participant"; // const char *ipAddress = "0.0.0.0"; // int port = 0; int localPort = 0; #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 Participant(); Participant(int port); Participant(const char *ipAddress, int port); void begin(); bool connected = false; virtual void Update(unsigned long currentTimeMs = 0); // std::list things; // Thing *Get(unsigned char networkId, unsigned char thingId); // int Add(Thing *thing); // void Remove(Thing *thing); // void UpdateAll(unsigned long currentTimeMs); void SendThingInfo(RemoteParticipant* remoteParticipant, Thing *thing); void PublishThingInfo(Thing *thing); bool Send(RemoteParticipant* remoteParticipant, IMessage *msg); bool Publish(IMessage *msg); void ReceiveData(unsigned char bufferSize, RemoteParticipant *remoteParticipant); protected: std::list senders; 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(RemoteParticipant *sender, ParticipantMsg *msg); virtual void Process(RemoteParticipant *sender, NetworkIdMsg *msg); virtual void Process(RemoteParticipant* sender, InvestigateMsg *msg); virtual void Process(RemoteParticipant* sender, ThingMsg *msg); virtual void Process(RemoteParticipant* sender, NameMsg *msg); virtual void Process(RemoteParticipant* sender, PoseMsg *msg); virtual void Process(RemoteParticipant* sender, BinaryMsg *msg); }; } // namespace Control } // namespace Passer using namespace Passer::RoboidControl;