mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-19 14:33:45 +02:00
Add support for keeping serial manager alive when in WiFi mode but connected to serial, fix resolving heartbeats
This commit is contained in:
@@ -20,8 +20,15 @@ void SerialManager::setup()
|
|||||||
usb_serial_jtag_driver_install(&usb_serial_jtag_config);
|
usb_serial_jtag_driver_install(&usb_serial_jtag_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SerialManager::isConnected()
|
||||||
|
{
|
||||||
|
// in preparation for handling uart as well
|
||||||
|
return usb_serial_jtag_is_connected();
|
||||||
|
}
|
||||||
|
|
||||||
void SerialManager::try_receive()
|
void SerialManager::try_receive()
|
||||||
{
|
{
|
||||||
|
/// @todo: make it so we still read in chunks, but until we get a newline or we timeout - 1s?
|
||||||
int current_position = 0;
|
int current_position = 0;
|
||||||
int len = usb_serial_jtag_read_bytes(this->temp_data, 256, 1000 / 20);
|
int len = usb_serial_jtag_read_bytes(this->temp_data, 256, 1000 / 20);
|
||||||
|
|
||||||
@@ -79,11 +86,11 @@ void SerialManager::notify_startup_command_received()
|
|||||||
setStartupCommandReceived(true);
|
setStartupCommandReceived(true);
|
||||||
|
|
||||||
// Cancel the startup timer if it's still running
|
// Cancel the startup timer if it's still running
|
||||||
if (timerHandle != nullptr)
|
if (timerHandle != nullptr && *timerHandle != nullptr)
|
||||||
{
|
{
|
||||||
esp_timer_stop(*timerHandle);
|
esp_timer_stop(*timerHandle);
|
||||||
esp_timer_delete(*timerHandle);
|
esp_timer_delete(*timerHandle);
|
||||||
timerHandle = nullptr;
|
*timerHandle = nullptr;
|
||||||
ESP_LOGI("[MAIN]", "Startup timer cancelled, staying in heartbeat mode");
|
ESP_LOGI("[MAIN]", "Startup timer cancelled, staying in heartbeat mode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,7 +119,7 @@ bool SerialManager::should_send_heartbeat()
|
|||||||
// Always send heartbeat during startup delay or if no WiFi configured
|
// Always send heartbeat during startup delay or if no WiFi configured
|
||||||
|
|
||||||
// If startup timer is still running, always send heartbeat
|
// If startup timer is still running, always send heartbeat
|
||||||
if (timerHandle != nullptr)
|
if (timerHandle != nullptr && *timerHandle != nullptr)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class SerialManager
|
|||||||
public:
|
public:
|
||||||
explicit SerialManager(std::shared_ptr<CommandManager> commandManager, esp_timer_handle_t *timerHandle, std::shared_ptr<ProjectConfig> deviceConfig);
|
explicit SerialManager(std::shared_ptr<CommandManager> commandManager, esp_timer_handle_t *timerHandle, std::shared_ptr<ProjectConfig> deviceConfig);
|
||||||
void setup();
|
void setup();
|
||||||
|
bool isConnected();
|
||||||
void try_receive();
|
void try_receive();
|
||||||
void send_heartbeat();
|
void send_heartbeat();
|
||||||
bool should_send_heartbeat();
|
bool should_send_heartbeat();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
TaskHandle_t serialManagerHandle;
|
TaskHandle_t serialManagerHandle;
|
||||||
|
|
||||||
esp_timer_handle_t timerHandle;
|
esp_timer_handle_t timerHandle = nullptr;
|
||||||
QueueHandle_t eventQueue = xQueueCreate(10, sizeof(SystemEvent));
|
QueueHandle_t eventQueue = xQueueCreate(10, sizeof(SystemEvent));
|
||||||
QueueHandle_t ledStateQueue = xQueueCreate(10, sizeof(uint32_t));
|
QueueHandle_t ledStateQueue = xQueueCreate(10, sizeof(uint32_t));
|
||||||
QueueHandle_t cdcMessageQueue = xQueueCreate(3, sizeof(cdc_command_packet_t));
|
QueueHandle_t cdcMessageQueue = xQueueCreate(3, sizeof(cdc_command_packet_t));
|
||||||
@@ -201,8 +201,15 @@ void startWiFiMode(bool shouldCloseSerialManager)
|
|||||||
ESP_LOGI("[MAIN]", "Starting WiFi streaming mode.");
|
ESP_LOGI("[MAIN]", "Starting WiFi streaming mode.");
|
||||||
if (shouldCloseSerialManager)
|
if (shouldCloseSerialManager)
|
||||||
{
|
{
|
||||||
ESP_LOGI("[MAIN]", "Closing serial manager task.");
|
if (!serialManager->isConnected())
|
||||||
vTaskDelete(serialManagerHandle);
|
{
|
||||||
|
ESP_LOGI("[MAIN]", "We're not connected to serial. Closing serial manager task.");
|
||||||
|
vTaskDelete(serialManagerHandle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGI("[MAIN]", "We're still connected to serial. Serial manager task will remain running.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wifiManager->Begin();
|
wifiManager->Begin();
|
||||||
|
|||||||
Reference in New Issue
Block a user