Pendant_Rtc_Toy/main/protocols/volc_rtc_protocol.h
Rdzleo 93f0e19d1d 初始化项目:精灵吊坠 RTC 语音助手 + VEML7700 石头同频匹配
ESP32-S3 吊坠设备固件,集成火山引擎 RTC 语音助手、蓝牙配网、
VEML7700 环境光传感器驱动及石头同频匹配交友功能。

VEML7700 驱动:
- 基于 ESP-IDF i2c_master API 实现,复用项目 I2cDevice 基类
- 支持 ALS + White 双通道、自动量程、Vishay 非线性校正
- 3 次采样取中位数过滤偶发异常

石头同频匹配算法(双维度):
- 维度1:光谱比值 ALS/White(石头固有光学特征,不随光照强度变化)
- 维度2:亮度等级(5级对数划分,排除极端环境差异)
- 比值阈值 15%,实测同石头姿势变化波动 1.6%~9.6%,安全余量充足

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 11:43:57 +08:00

70 lines
2.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _VOLC_RTC_PROTOCOL_H_
#define _VOLC_RTC_PROTOCOL_H_
#include "protocol.h"
#include "volc_rtc.h"
#include "base/volc_device_manager.h"
#include <freertos/FreeRTOS.h>
#include <freertos/event_groups.h>
#include <mutex>
#include <vector>
class VolcRtcProtocol : public Protocol {
public:
VolcRtcProtocol();
~VolcRtcProtocol();
void Start() override;
void SendAudio(const std::vector<uint8_t>& data) override;// 🔊 发送音频数据到RTC
void SendPcm(const std::vector<uint8_t>& data) override;// 🔊 发送PCM音频数据到RTC
void SendG711A(const std::vector<uint8_t>& data) override;// 🔊 发送G711A音频数据到RTC
bool OpenAudioChannel() override;// 🔊 打开音频通道
void CloseAudioChannel() override;// 🔊 关闭音频通道
bool IsAudioChannelOpened() const override;// 🔊 检查音频通道是否已打开
void SendAbortSpeaking(AbortReason reason) override;// 🔊 发送中止通话请求
void SendStartListening(ListeningMode mode) override;// 🔊 发送开始监听请求
void SendTextMessage(const std::string& text) override;// 🔊 发送文本消息到RTC
void SendFunctionResult(const std::string& tool_call_id, const std::string& content) override;// 🔊 发送函数调用结果到RTC
/**
* @brief 设置Agent配置参数如音色、提示词等
* @param params JSON格式的配置参数字符串
*/
void SetAgentConfig(const std::string& params);
private:
EventGroupHandle_t event_group_handle_;
volc_rtc_t rtc_handle_ = nullptr;
std::mutex rtc_mutex_;
std::string extra_params_; // 存储额外的Agent配置参数
bool is_connected_ = false;
bool is_audio_channel_opened_ = false;
bool iot_ready_ = false;
volc_iot_info_t iot_info_ = {};
size_t opus_bytes_accum_ = 0;
size_t pcm_bytes_accum_ = 0;
size_t g711a_bytes_accum_ = 0;
size_t down_pcm_bytes_accum_ = 0;
size_t down_opus_bytes_accum_ = 0;
int opus_frames_accum_ = 0;
int pcm_frames_accum_ = 0;
int g711a_frames_accum_ = 0;
uint64_t uplink_last_log_us_ = 0;
std::vector<uint8_t> pcm_pending_;
std::vector<uint8_t> g711a_pending_;
bool first_downlink_logged_ = false;
static void MessageCallback(void* context, volc_msg_t* message);
static void DataCallback(void* context, const void* data, size_t len, volc_data_info_t* info);
void ParseServerMessage(const char* message);
void ProcessAudioData(const void* data, int size);
void SendText(const std::string& text) override;
void LogUplinkStatsMaybe();// 打印上传统计信息
void SendCtrl(const std::string& json);// 🔊 发送控制指令到RTC
void SendFunc(const std::string& json);// 🔊 发送函数调用指令到RTC
};
#endif