-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor commands and serial manager to support updated commands payload * set setMinSecurity to WIFI_AUTH_WEP to fix boards not connecting to some networks, cleanup some logs and comments * feat: Move logging in serial streaming so that we at least attempt to get new frame * remove unused etvr_eye_tracker_usb * PoC query manager for better flasher logging * simplify query implementation * remove old include * fix: serial output for esp32cams and other boards not supporting higher frequency baud rate * fix: serial output for esp32cams and other boards not supporting higher frequency baud rate * Switch higher frequency to be opt-in * feat: Add support for ov5640 cameras * feat: fix usb streaming on wroom boards, add support for babble custom board * feat: PoC add support for project babble board * Add support for bable wireless, adjust flash_mode and memory type to get PSRAM working * Add DARDUINO_USB_MODE=1 and DARDUINO_USB_CDC_ON_BOOT=1 to Babble and wroom boards to fix USB streaming discovered and fixed entirely by Rames the Generic * cleanup PoC
- Loading branch information
Showing
16 changed files
with
295 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,81 @@ | ||
#include "CommandManager.hpp" | ||
|
||
CommandManager::CommandManager(ProjectConfig *deviceConfig) : deviceConfig(deviceConfig) {} | ||
CommandManager::CommandManager(ProjectConfig* deviceConfig) | ||
: deviceConfig(deviceConfig) {} | ||
|
||
const CommandType CommandManager::getCommandType(JsonVariant& command) { | ||
if (!command.containsKey("command")) | ||
return CommandType::None; | ||
|
||
const CommandType CommandManager::getCommandType(Command &command){ | ||
if (!command.data.containsKey("command")) | ||
return CommandType::None; | ||
if (auto search = commandMap.find(command["command"]); | ||
search != commandMap.end()) | ||
return search->second; | ||
|
||
if (auto search = commandMap.find(command.data["command"]); search != commandMap.end()) | ||
return search->second; | ||
|
||
return CommandType::None; | ||
return CommandType::None; | ||
} | ||
|
||
bool CommandManager::hasDataField(JsonVariant& command) { | ||
return command.containsKey("data"); | ||
} | ||
|
||
bool CommandManager::hasHasDataField(Command &command) { | ||
return command.data.containsKey("data"); | ||
void CommandManager::handleCommands(CommandsPayload commandsPayload) { | ||
if (!commandsPayload.data.containsKey("commands")) { | ||
log_e("Json data sent not supported, lacks commands field"); | ||
return; | ||
} | ||
|
||
for (JsonVariant commandData : | ||
commandsPayload.data["commands"].as<JsonArray>()) { | ||
this->handleCommand(commandData); | ||
} | ||
|
||
this->deviceConfig->save(); | ||
} | ||
|
||
void CommandManager::handleCommand(Command command) { | ||
auto command_type = this->getCommandType(command); | ||
|
||
switch(command_type) | ||
{ | ||
case CommandType::SET_WIFI: { | ||
if (!this->hasHasDataField(command)) | ||
// malformed command, lacked data field | ||
break; | ||
|
||
|
||
if(!command.data["data"].containsKey("ssid") || !command.data["data"].containsKey("password")) | ||
break; | ||
|
||
std::string customNetworkName = "main"; | ||
if (command.data["data"].containsKey("network_name")) | ||
customNetworkName = command.data["data"]["network_name"].as<std::string>(); | ||
|
||
this->deviceConfig->setWifiConfig( | ||
customNetworkName, | ||
command.data["data"]["ssid"], | ||
command.data["data"]["password"], | ||
0, // channel, should this be zero? | ||
0, // power, should this be zero? | ||
false, | ||
false | ||
); | ||
|
||
// we purposefully save here | ||
this->deviceConfig->save(); | ||
break; | ||
} | ||
case CommandType::SET_MDNS: { | ||
if (!this->hasHasDataField(command)) | ||
break; | ||
|
||
if(!command.data["data"].containsKey("hostname") || !strlen(command.data["data"]["hostname"])) | ||
break; | ||
|
||
this->deviceConfig->setMDNSConfig( | ||
command.data["data"]["hostname"], | ||
"openiristracker", | ||
false | ||
); | ||
|
||
break; | ||
} | ||
case CommandType::PING: { | ||
Serial.println("PONG \n\r"); | ||
break; | ||
} | ||
default: | ||
break; | ||
void CommandManager::handleCommand(JsonVariant command) { | ||
auto command_type = this->getCommandType(command); | ||
|
||
switch (command_type) { | ||
case CommandType::SET_WIFI: { | ||
if (!this->hasDataField(command)) | ||
// malformed command, lacked data field | ||
break; | ||
|
||
if (!command["data"].containsKey("ssid") || | ||
!command["data"].containsKey("password")) | ||
break; | ||
|
||
std::string customNetworkName = "main"; | ||
if (command["data"].containsKey("network_name")) | ||
customNetworkName = command["data"]["network_name"].as<std::string>(); | ||
|
||
this->deviceConfig->setWifiConfig(customNetworkName, | ||
command["data"]["ssid"], | ||
command["data"]["password"], | ||
0, // channel, should this be zero? | ||
0, // power, should this be zero? | ||
false, false); | ||
|
||
break; | ||
} | ||
case CommandType::SET_MDNS: { | ||
if (!this->hasDataField(command)) | ||
break; | ||
|
||
if (!command["data"].containsKey("hostname") || | ||
!strlen(command["data"]["hostname"])) | ||
break; | ||
|
||
this->deviceConfig->setMDNSConfig(command["data"]["hostname"], | ||
"openiristracker", false); | ||
|
||
break; | ||
} | ||
case CommandType::PING: { | ||
Serial.println("PONG \n\r"); | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} |
Oops, something went wrong.