#include "SiteServer.h" #include "Sensors/TemperatureSensor.h" #include #include namespace Passer { namespace Control { SiteServer::SiteServer(int port) { this->name = "Site Server"; this->publishInterval = 0; this->ipAddress = "0.0.0.0"; this->port = port; this->participants.push_back(this); SetupUDP(port, ipAddress, 0); Register((unsigned char)Thing::Type::TemperatureSensor); } // void SiteServer::Update(unsigned long currentTimeMs) { // if (currentTimeMs == 0) { // #if defined(ARDUINO) // currentTimeMs = millis(); // #elif defined(__unix__) || defined(__APPLE__) // #elif defined(__unix__) || defined(__APPLE__) // auto now = std::chrono::steady_clock::now(); // auto ms = std::chrono::duration_cast( // now.time_since_epoch()); // currentTimeMs = static_cast(ms.count()); // #endif // } // this->ReceiveUDP(); // Thing::UpdateAll(currentTimeMs); // } void SiteServer::Process(Participant *sender, ClientMsg *msg) { if (msg->networkId == 0) { std::cout << this->name << " received New Client -> " << sender->ipAddress << " " << (int)sender->networkId << "\n"; NetworkIdMsg *msg = new NetworkIdMsg(sender->networkId); sender->Send(msg); delete msg; } } void SiteServer::Process(Participant *sender, NetworkIdMsg *msg) {} void SiteServer::Process(ThingMsg *msg) { Thing *thing = Thing::Get(msg->networkId, msg->thingId); if (thing == nullptr) { auto thingMsgProcessor = thingMsgProcessors.find(msg->thingType); if (thingMsgProcessor != thingMsgProcessors.end()) // found item thingMsgProcessor->second(msg->networkId, msg->thingId); else new Thing(this, msg->networkId, msg->thingId, (Thing::Type)msg->thingType); } } } // namespace Control } // namespace Passer