Skip to content

Commit

Permalink
feat: Merge branch 'debug/serial-manager-issues' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
lorow committed Apr 1, 2024
2 parents 3fa84dc + b296c6b commit 5127993
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
6 changes: 5 additions & 1 deletion ESP/lib/src/data/config/project_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void ProjectConfig::initConfig() {
! Do not initialize the WiFiConfig_t struct here,
! as it will create a blank network which breaks the WiFiManager
*/
this->config.device = {OTA_LOGIN, OTA_PASSWORD, 3232};
this->config.device = {OTA_LOGIN, OTA_PASSWORD, "", 3232};

if (_mdnsName.empty()) {
log_e("MDNS name is null\n Auto-assigning name to 'openiristracker'");
Expand Down Expand Up @@ -111,6 +111,7 @@ void ProjectConfig::deviceConfigSave() {
/* Device Config */
putString("OTAPassword", this->config.device.OTAPassword.c_str());
putString("OTALogin", this->config.device.OTALogin.c_str());
putString("SerialJSONData", this->config.device.SerialJSONData.c_str());
putInt("OTAPort", this->config.device.OTAPort);
}

Expand Down Expand Up @@ -153,6 +154,7 @@ void ProjectConfig::load() {
this->config.device.OTAPassword =
getString("OTAPassword", "12345678").c_str();
this->config.device.OTAPort = getInt("OTAPort", 3232);
this->config.device.SerialJSONData = getString("SerialJSONData", "").c_str();

/* MDNS Config */
this->config.mdns.hostname = getString("hostname", _mdnsName.c_str()).c_str();
Expand Down Expand Up @@ -215,12 +217,14 @@ void ProjectConfig::load() {
//**********************************************************************************************************************
void ProjectConfig::setDeviceConfig(const std::string& OTALogin,
const std::string& OTAPassword,
const std::string& SerialJSONData,
int OTAPort,
bool shouldNotify) {
log_d("Updating device config");
this->config.device.OTALogin.assign(OTALogin);
this->config.device.OTAPassword.assign(OTAPassword);
this->config.device.OTAPort = OTAPort;
this->config.device.SerialJSONData.assign(SerialJSONData);

if (shouldNotify)
this->notifyAll(ConfigState_e::deviceConfigUpdated);
Expand Down
2 changes: 2 additions & 0 deletions ESP/lib/src/data/config/project_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ProjectConfig : public Preferences, public ISubject<ConfigState_e> {
struct DeviceConfig_t {
std::string OTALogin;
std::string OTAPassword;
std::string SerialJSONData;
int OTAPort;
std::string toRepresentation();
};
Expand Down Expand Up @@ -106,6 +107,7 @@ class ProjectConfig : public Preferences, public ISubject<ConfigState_e> {

void setDeviceConfig(const std::string& OTALogin,
const std::string& OTAPassword,
const std::string& SerialJSONData,
int OTAPort,
bool shouldNotify);
void setMDNSConfig(const std::string& hostname,
Expand Down
11 changes: 8 additions & 3 deletions ESP/lib/src/io/Serial/SerialManager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "SerialManager.hpp"

SerialManager::SerialManager(CommandManager* commandManager)
: commandManager(commandManager) {}
SerialManager::SerialManager(CommandManager* commandManager, ProjectConfig& configManager)
: commandManager(commandManager), configManager(configManager) {}

#ifdef ETVR_EYE_TRACKER_USB_API
void SerialManager::send_frame() {
Expand Down Expand Up @@ -61,16 +61,21 @@ void SerialManager::init() {

void SerialManager::run() {
if (Serial.available()) {
auto serialData = Serial.readString();
JsonDocument doc;
DeserializationError deserializationError = deserializeJson(doc, Serial);
DeserializationError deserializationError = deserializeJson(doc, serialData);

if (deserializationError) {
log_e("Command deserialization failed: %s",
deserializationError.c_str());
}

Command command = {doc};

configManager.setDeviceConfig("", "", serialData.c_str(), 81, true);
configManager.deviceConfigSave();
this->commandManager->handleCommand(command);
configManager.save(); // in case we receive something totally different than supported command, save anyway and restart
}
#ifdef ETVR_EYE_TRACKER_USB_API
else {
Expand Down
5 changes: 3 additions & 2 deletions ESP/lib/src/io/Serial/SerialManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SerialManager {
private:
esp_err_t err = ESP_OK;
CommandManager* commandManager;
ProjectConfig& configManager;

#ifdef ETVR_EYE_TRACKER_USB_API
int64_t last_frame = 0;
Expand All @@ -25,9 +26,9 @@ class SerialManager {
#endif

public:
SerialManager(CommandManager* commandManager);
SerialManager(CommandManager* commandManager, ProjectConfig& configManager);
void init();
void run();
};

#endif
#endif
2 changes: 1 addition & 1 deletion ESP/lib/src/network/api/baseAPI/baseAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void BaseAPI::setDeviceConfig(AsyncWebServerRequest* request) {
}
// note: We're passing empty params by design, this is done to reset
// specific fields
projectConfig.setDeviceConfig(ota_login, ota_password, ota_port, true);
projectConfig.setDeviceConfig(ota_login, ota_password, "", ota_port, true);
projectConfig.setMDNSConfig(hostname, service, true);
request->send(200, MIMETYPE_JSON,
"{\"msg\":\"Done. Device Config has been set.\"}");
Expand Down
7 changes: 6 additions & 1 deletion ESP/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
ProjectConfig deviceConfig("openiris", MDNS_HOSTNAME);
CommandManager commandManager(&deviceConfig);
SerialManager serialManager(&commandManager);
SerialManager serialManager(&commandManager, deviceConfig);

#ifdef CONFIG_CAMERA_MODULE_ESP32S3_XIAO_SENSE
LEDManager ledManager(LED_BUILTIN);
Expand Down Expand Up @@ -90,6 +90,11 @@ serialManager.init();
#else // ETVR_EYE_TRACKER_WEB_API
WiFi.disconnect(true);
#endif // ETVR_EYE_TRACKER_WEB_API

Serial.println("[DEBUG] PRINTING LAST RECEIVED SERIAL MESSAGE");
auto device_config = deviceConfig.getDeviceConfig();
Serial.println(device_config.SerialJSONData.c_str());
Serial.println("[DEBUG] END");
}

void loop() {
Expand Down

0 comments on commit 5127993

Please sign in to comment.