Merge commit '830b418e48f419876c9a81db5b87cd6e82d6cc72'
This commit is contained in:
commit
bf5d949992
@ -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
|
||||
#endif
|
@ -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()
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "Custommsg.h"
|
||||
#include "CustomMsg.h"
|
||||
|
||||
namespace Passer {
|
||||
namespace Control {
|
@ -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) {
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -38,18 +38,6 @@ void SiteServer::Process(Participant *sender, ClientMsg *msg) {
|
||||
|
||||
void SiteServer::Process(Participant *sender, NetworkIdMsg *msg) {}
|
||||
|
||||
using ThingConstructor = std::function<std::unique_ptr<Thing>(
|
||||
unsigned char networkId, unsigned char thingId)>;
|
||||
std::unordered_map<unsigned char, ThingConstructor> thingMsgProcessors;
|
||||
|
||||
template <typename ThingClass>
|
||||
void SiteServer::Register(unsigned char thingType) {
|
||||
thingMsgProcessors[thingType] = [](unsigned char networkId,
|
||||
unsigned char thingId) {
|
||||
return std::make_unique<ThingClass>(networkId, thingId);
|
||||
};
|
||||
}
|
||||
|
||||
void SiteServer::Process(ThingMsg *msg) {
|
||||
|
||||
Thing *thing = Thing::Get(msg->networkId, msg->thingId);
|
||||
|
15
SiteServer.h
15
SiteServer.h
@ -2,6 +2,10 @@
|
||||
|
||||
#include "Participant.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace Passer {
|
||||
namespace Control {
|
||||
|
||||
@ -12,7 +16,12 @@ public:
|
||||
|
||||
virtual void Update(unsigned long currentTimeMs) override;
|
||||
|
||||
template <typename ThingClass> void Register(unsigned char thingType);
|
||||
template <typename ThingClass> void Register(unsigned char thingType) {
|
||||
thingMsgProcessors[thingType] = [](unsigned char networkId,
|
||||
unsigned char thingId) {
|
||||
return std::make_unique<ThingClass>(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<std::unique_ptr<Thing>(
|
||||
unsigned char networkId, unsigned char thingId)>;
|
||||
std::unordered_map<unsigned char, ThingConstructor> thingMsgProcessors;
|
||||
};
|
||||
|
||||
} // namespace Control
|
||||
|
Loading…
x
Reference in New Issue
Block a user