mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-29 11:03:44 +02:00
Add PoC Serial communication implementation
This commit is contained in:
4
components/SerialManager/CMakeLists.txt
Normal file
4
components/SerialManager/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
idf_component_register(SRCS "SerialManager/SerialManager.cpp"
|
||||||
|
INCLUDE_DIRS "SerialManager"
|
||||||
|
REQUIRES esp_driver_uart CommandManager
|
||||||
|
)
|
||||||
49
components/SerialManager/SerialManager/SerialManager.cpp
Normal file
49
components/SerialManager/SerialManager/SerialManager.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include "SerialManager.hpp"
|
||||||
|
|
||||||
|
#define ECHO_TEST_TXD (4)
|
||||||
|
#define ECHO_TEST_RXD (5)
|
||||||
|
#define ECHO_TEST_RTS (UART_PIN_NO_CHANGE)
|
||||||
|
#define ECHO_TEST_CTS (UART_PIN_NO_CHANGE)
|
||||||
|
|
||||||
|
#define ECHO_UART_PORT_NUM (1)
|
||||||
|
#define ECHO_UART_BAUD_RATE (115200)
|
||||||
|
#define ECHO_TASK_STACK_SIZE (3072)
|
||||||
|
|
||||||
|
static const char *TAG = "UART TEST";
|
||||||
|
|
||||||
|
#define BUF_SIZE (1024)
|
||||||
|
uint8_t *data;
|
||||||
|
|
||||||
|
SerialManager::SerialManager(std::shared_ptr<CommandManager> commandManager) : commandManager(commandManager) {}
|
||||||
|
|
||||||
|
void SerialManager::setup()
|
||||||
|
{
|
||||||
|
usb_serial_jtag_driver_config_t usb_serial_jtag_config;
|
||||||
|
usb_serial_jtag_config.rx_buffer_size = BUF_SIZE;
|
||||||
|
usb_serial_jtag_config.tx_buffer_size = BUF_SIZE;
|
||||||
|
usb_serial_jtag_driver_install(&usb_serial_jtag_config);
|
||||||
|
// Configure a temporary buffer for the incoming data
|
||||||
|
data = (uint8_t *)malloc(BUF_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// rewrite this to serial events or something
|
||||||
|
void SerialManager::try_receive()
|
||||||
|
{
|
||||||
|
int len = usb_serial_jtag_read_bytes(data, (BUF_SIZE - 1), 20 / portTICK_PERIOD_MS);
|
||||||
|
if (len)
|
||||||
|
{
|
||||||
|
auto result = this->commandManager->executeFromJson(std::string_view((const char *)data));
|
||||||
|
auto resultMessage = result.getResult();
|
||||||
|
usb_serial_jtag_write_bytes(resultMessage.c_str(), resultMessage.length(), 20 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleSerialManagerTask(void *pvParameters)
|
||||||
|
{
|
||||||
|
auto serialManager = static_cast<SerialManager *>(pvParameters);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
serialManager->try_receive();
|
||||||
|
}
|
||||||
|
}
|
||||||
32
components/SerialManager/SerialManager/SerialManager.hpp
Normal file
32
components/SerialManager/SerialManager/SerialManager.hpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef SERIALMANAGER_HPP
|
||||||
|
#define SERIALMANAGER_HPP
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
#include <CommandManager.hpp>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/queue.h"
|
||||||
|
#include "driver/uart.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "driver/usb_serial_jtag.h"
|
||||||
|
#include "esp_vfs_usb_serial_jtag.h"
|
||||||
|
#include "esp_vfs_dev.h"
|
||||||
|
|
||||||
|
class SerialManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SerialManager(std::shared_ptr<CommandManager> commandManager);
|
||||||
|
void setup();
|
||||||
|
void try_receive();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QueueHandle_t serialQueue;
|
||||||
|
std::shared_ptr<CommandManager> commandManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
void HandleSerialManagerTask(void *pvParameters);
|
||||||
|
#endif
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <WebSocketLogger.hpp>
|
#include <WebSocketLogger.hpp>
|
||||||
#include <StreamServer.hpp>
|
#include <StreamServer.hpp>
|
||||||
#include <CommandManager.hpp>
|
#include <CommandManager.hpp>
|
||||||
|
#include <SerialManager.hpp>
|
||||||
#include <RestAPI.hpp>
|
#include <RestAPI.hpp>
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -58,6 +59,8 @@ UVCStreamManager uvcStream;
|
|||||||
|
|
||||||
LEDManager *ledManager = new LEDManager(BLINK_GPIO, CONFIG_LED_C_PIN_GPIO, ledStateQueue);
|
LEDManager *ledManager = new LEDManager(BLINK_GPIO, CONFIG_LED_C_PIN_GPIO, ledStateQueue);
|
||||||
|
|
||||||
|
SerialManager *serialManager = new SerialManager(commandManager);
|
||||||
|
|
||||||
static void initNVSStorage()
|
static void initNVSStorage()
|
||||||
{
|
{
|
||||||
esp_err_t ret = nvs_flash_init();
|
esp_err_t ret = nvs_flash_init();
|
||||||
@@ -117,8 +120,9 @@ extern "C" void app_main(void)
|
|||||||
|
|
||||||
// rethink state management - DONE
|
// rethink state management - DONE
|
||||||
|
|
||||||
// port serial manager
|
// port serial manager - DONE - needs rewrite
|
||||||
// add support of commands to UVC
|
// instead of the UVCCDC thing - give the board 30s for serial commands and then determine if we should reboot into UVC
|
||||||
|
|
||||||
// add endpoint to check firmware version
|
// add endpoint to check firmware version
|
||||||
// add firmware version somewhere
|
// add firmware version somewhere
|
||||||
// setup CI and building for other boards
|
// setup CI and building for other boards
|
||||||
@@ -148,6 +152,16 @@ extern "C" void app_main(void)
|
|||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
deviceConfig->load();
|
deviceConfig->load();
|
||||||
|
serialManager->setup();
|
||||||
|
|
||||||
|
xTaskCreate(
|
||||||
|
HandleSerialManagerTask,
|
||||||
|
"HandleSerialManagerTask",
|
||||||
|
1024 * 6,
|
||||||
|
serialManager,
|
||||||
|
3,
|
||||||
|
NULL);
|
||||||
|
|
||||||
wifiManager.Begin();
|
wifiManager.Begin();
|
||||||
mdnsManager.start();
|
mdnsManager.start();
|
||||||
restAPI->begin();
|
restAPI->begin();
|
||||||
|
|||||||
Reference in New Issue
Block a user