ESP32-S3 摄像头图传:固件 + Slint 客户端 + 共享协议
两块 ESP32-S3-WROOM-1-N16R8 图传板(DVP 接口接 OV2640/OV3660/OV5640), 向队伍客户端与裁判终端推 UDP 图传。固件是跑在 ESP-IDF 上的 Rust,用官方 esp32-camera 组件采集;客户端是 Rust + Slint 桌面程序。 三个 crate 各自独立构建: . firmware,交叉编译到 Xtensa protocol/ 线路格式与帧重组,两端共用,无 ESP-IDF 依赖,有单元测试 client/ Slint 桌面客户端 视频走 UDP 而非 TCP:实测传感器产出 22 fps,TCP MJPEG 只送出 1.9 fps, 且只占用链路能力的 1%——链路是空的,帧堵在队头阻塞后面等一个实时画面 等不起的重传计时器。改为独立数据报、不重传、缺片丢整帧后达到 20.8 fps。 发现是双向的:板子每 2 秒广播 Hello,客户端广播 Subscribe,板子据此定向 推流。板子身份由 MAC 派生,重启不变,所以客户端可以把绑定存进配置。 裁判端同时收两块板子(每个发送方一个重组器),队伍端绑定其中一块并只显示 自己那一边的血量。装甲板接口已预留(ArmorSource trait + ARMOR_PORT), 当前无数据源,界面显示占位符。 vendor 了 esp32-camera 2.1.7:组件注册表的版本求解器找不到它,且需要打一处 补丁(见 components/esp32-camera/target/esp32s3/ll_cam.c)。 .gitignore 三条 target/ 都锚定在根目录,因为 protocol/ 与 client/ 各自也是 独立 crate;而 components/esp32-camera/target/ 是上游的按芯片分目录,里面是 源码,必须保留。
This commit is contained in:
@@ -0,0 +1,215 @@
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "esp_camera_af.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
#ifndef CONFIG_CAMERA_AF_DEFAULT_TIMEOUT_MS
|
||||
#define CONFIG_CAMERA_AF_DEFAULT_TIMEOUT_MS 2000
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_CAMERA_AF_SUPPORT) && CONFIG_CAMERA_AF_SUPPORT
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
||||
#include "esp32-hal-log.h"
|
||||
#define TAG ""
|
||||
#else
|
||||
#include "esp_log.h"
|
||||
#if CONFIG_LOG_DEFAULT_LEVEL > 0
|
||||
static const char *TAG = "camera_af";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static uint32_t s_default_timeout_ms = CONFIG_CAMERA_AF_DEFAULT_TIMEOUT_MS;
|
||||
|
||||
bool esp_camera_af_is_supported(const sensor_t *sensor)
|
||||
{
|
||||
if (!sensor || !sensor->af_is_supported) {
|
||||
return false;
|
||||
}
|
||||
return sensor->af_is_supported((sensor_t *)sensor) != 0;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_init(sensor_t *sensor, const esp_camera_af_config_t *config)
|
||||
{
|
||||
if (!sensor || !config) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (config->timeout_ms) {
|
||||
s_default_timeout_ms = config->timeout_ms;
|
||||
}
|
||||
|
||||
if (!esp_camera_af_is_supported(sensor)) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (!sensor->af_init) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
int ret = sensor->af_init(sensor, s_default_timeout_ms);
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "AF init failed");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
return esp_camera_af_set_mode(sensor, config->mode);
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_set_mode(sensor_t *sensor, esp_camera_af_mode_t mode)
|
||||
{
|
||||
if (!sensor) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!esp_camera_af_is_supported(sensor)) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (!sensor->af_set_mode) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
int ret = sensor->af_set_mode(sensor, (int)mode);
|
||||
return (ret == 0) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_trigger(sensor_t *sensor)
|
||||
{
|
||||
if (!sensor) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!esp_camera_af_is_supported(sensor)) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (!sensor->af_trigger) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
int ret = sensor->af_trigger(sensor);
|
||||
return (ret == 0) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_get_status(sensor_t *sensor, esp_camera_af_status_t *out_status)
|
||||
{
|
||||
if (!sensor || !out_status) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!esp_camera_af_is_supported(sensor)) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (!sensor->af_get_status) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
memset(out_status, 0, sizeof(*out_status));
|
||||
int ret = sensor->af_get_status(sensor, &out_status->raw, &out_status->focused, &out_status->busy);
|
||||
return (ret == 0) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_wait(sensor_t *sensor, uint32_t timeout_ms, esp_camera_af_status_t *out_status)
|
||||
{
|
||||
if (!sensor || !out_status) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!esp_camera_af_is_supported(sensor)) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (!timeout_ms) {
|
||||
timeout_ms = s_default_timeout_ms;
|
||||
}
|
||||
|
||||
const uint64_t start = esp_timer_get_time();
|
||||
while (true) {
|
||||
esp_err_t ret = esp_camera_af_get_status(sensor, out_status);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!out_status->busy) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
if (timeout_ms && ((esp_timer_get_time() - start) / 1000ULL) > timeout_ms) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(5));
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_set_manual_position(sensor_t *sensor, uint16_t position)
|
||||
{
|
||||
if (!sensor) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!esp_camera_af_is_supported(sensor)) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (!sensor->af_set_manual_position) {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
int ret = sensor->af_set_manual_position(sensor, position);
|
||||
return (ret == 0) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
#else // CONFIG_CAMERA_AF_SUPPORT
|
||||
|
||||
bool esp_camera_af_is_supported(const sensor_t *sensor)
|
||||
{
|
||||
(void)sensor;
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_init(sensor_t *sensor, const esp_camera_af_config_t *config)
|
||||
{
|
||||
(void)sensor;
|
||||
(void)config;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_set_mode(sensor_t *sensor, esp_camera_af_mode_t mode)
|
||||
{
|
||||
(void)sensor;
|
||||
(void)mode;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_trigger(sensor_t *sensor)
|
||||
{
|
||||
(void)sensor;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_get_status(sensor_t *sensor, esp_camera_af_status_t *out_status)
|
||||
{
|
||||
(void)sensor;
|
||||
(void)out_status;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_wait(sensor_t *sensor, uint32_t timeout_ms, esp_camera_af_status_t *out_status)
|
||||
{
|
||||
(void)sensor;
|
||||
(void)timeout_ms;
|
||||
(void)out_status;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t esp_camera_af_set_manual_position(sensor_t *sensor, uint16_t position)
|
||||
{
|
||||
(void)sensor;
|
||||
(void)position;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
#endif // CONFIG_CAMERA_AF_SUPPORT
|
||||
Reference in New Issue
Block a user