diff --git a/ArduinoUtils.cpp b/ArduinoUtils.cpp index 0229c8c..0de1370 100644 --- a/ArduinoUtils.cpp +++ b/ArduinoUtils.cpp @@ -109,49 +109,4 @@ bool StartWifi(const char *wifiSsid, const char *wifiPassword, return (!hotSpotEnabled); } - - -void CheckFirmware(String url, String FIRMWARE_NAME, int FIRMWARE_VERSION) { - Serial.println("Checking for firmware updates."); - - WiFiClient client; - HTTPClient httpClient; - String versionURL = url + FIRMWARE_NAME + ".version"; - httpClient.begin(client, versionURL); - int httpCode = httpClient.GET(); - if (httpCode == 200) { - String newFWVersion = httpClient.getString(); - - Serial.print("Current firmware version: "); - Serial.println(FIRMWARE_VERSION); - Serial.print("Available firmware version: "); - Serial.println(newFWVersion); - - int newVersion = newFWVersion.toInt(); - - if (newVersion > FIRMWARE_VERSION) { - Serial.println("Preparing to update firmware."); - - String firmwareURL = url + FIRMWARE_NAME + ".bin"; - t_httpUpdate_return ret = ESPhttpUpdate.update(client, firmwareURL); - switch (ret) { - case HTTP_UPDATE_FAILED: - Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s", - ESPhttpUpdate.getLastError(), - ESPhttpUpdate.getLastErrorString().c_str()); - break; - case HTTP_UPDATE_NO_UPDATES: - Serial.println("HTTP_UPDATE_NO_UPDATES"); - break; - case HTTP_UPDATE_OK: - break; - } - } else { - Serial.println("No Firmware update necessary."); - } - } else { - Serial.print("Http Error: "); - Serial.println(httpCode); - } -} -#endif \ No newline at end of file +#endif \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3129eac..4e5d151 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ else() . LinearAlgebra ) - file(GLOB srcs *.cpp Sensors/*.cpp) + file(GLOB srcs *.cpp Sensors/*.cpp Messages/*.cpp) add_library(ControlCore STATIC ${srcs}) enable_testing() diff --git a/Messages/CusstomMsg.cpp b/Messages/CustomMsg.cpp similarity index 97% rename from Messages/CusstomMsg.cpp rename to Messages/CustomMsg.cpp index 76f3b92..40e91f1 100644 --- a/Messages/CusstomMsg.cpp +++ b/Messages/CustomMsg.cpp @@ -1,4 +1,4 @@ -#include "Custommsg.h" +#include "CustomMsg.h" namespace Passer { namespace Control { diff --git a/Participant.cpp b/Participant.cpp index 21edb60..188ce38 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -199,6 +199,11 @@ void Participant::ReceiveData(unsigned char bufferSize, Process(msg); delete msg; } break; + case NameMsg::id: { + NameMsg *msg = new NameMsg(this->buffer); + Process(msg); + delete msg; + } break; case PoseMsg::id: { PoseMsg *msg = new PoseMsg(this->buffer); Process(msg); @@ -237,6 +242,15 @@ void Participant::Process(InvestigateMsg *msg) {} void Participant::Process(ThingMsg *msg) {} +void Participant::Process(NameMsg *msg) { + Thing *thing = Thing::Get(msg->networkId, msg->thingId); + if (thing != nullptr) { + thing->name = new char[strlen(msg->name)]; + strcpy(thing->name, msg->name); + std::cout << "thing name = " << thing->name << "\n"; + } +} + void Participant::Process(PoseMsg *msg) {} void Participant::Process(CustomMsg *msg) { diff --git a/Participant.h b/Participant.h index f89a25e..8f2686b 100644 --- a/Participant.h +++ b/Participant.h @@ -95,6 +95,7 @@ protected: virtual void Process(Participant *sender, NetworkIdMsg *msg); virtual void Process(InvestigateMsg *msg); virtual void Process(ThingMsg *msg); + virtual void Process(NameMsg *msg); virtual void Process(PoseMsg *msg); virtual void Process(CustomMsg *msg); }; diff --git a/SiteServer.cpp b/SiteServer.cpp index e00cf60..87ea5d6 100644 --- a/SiteServer.cpp +++ b/SiteServer.cpp @@ -38,18 +38,6 @@ void SiteServer::Process(Participant *sender, ClientMsg *msg) { void SiteServer::Process(Participant *sender, NetworkIdMsg *msg) {} -using ThingConstructor = std::function( - unsigned char networkId, unsigned char thingId)>; -std::unordered_map thingMsgProcessors; - -template -void SiteServer::Register(unsigned char thingType) { - thingMsgProcessors[thingType] = [](unsigned char networkId, - unsigned char thingId) { - return std::make_unique(networkId, thingId); - }; -} - void SiteServer::Process(ThingMsg *msg) { Thing *thing = Thing::Get(msg->networkId, msg->thingId); diff --git a/SiteServer.h b/SiteServer.h index 95a6c29..507c8b9 100644 --- a/SiteServer.h +++ b/SiteServer.h @@ -2,6 +2,10 @@ #include "Participant.h" +#include +#include +#include + namespace Passer { namespace Control { @@ -12,7 +16,12 @@ public: virtual void Update(unsigned long currentTimeMs) override; - template void Register(unsigned char thingType); + template void Register(unsigned char thingType) { + thingMsgProcessors[thingType] = [](unsigned char networkId, + unsigned char thingId) { + return std::make_unique(networkId, thingId); + }; + }; protected: unsigned long nextPublishMe = 0; @@ -20,6 +29,10 @@ protected: virtual void Process(Participant *sender, ClientMsg *msg) override; virtual void Process(Participant *sender, NetworkIdMsg *msg) override; virtual void Process(ThingMsg *msg) override; + +using ThingConstructor = std::function( + unsigned char networkId, unsigned char thingId)>; + std::unordered_map thingMsgProcessors; }; } // namespace Control diff --git a/Thing.h b/Thing.h index 41431c2..b4b29de 100644 --- a/Thing.h +++ b/Thing.h @@ -73,7 +73,7 @@ protected: public: /// @brief The type of Thing unsigned char type = 0; - const char *name = nullptr; + char *name = nullptr; const char *modelUrl = nullptr; float modelScale = 1; // protected Sensor sensor;