(1)添加开关机语音(2)发多个协议wife的信号强度AT+RSSI

This commit is contained in:
dianke3yu 2025-06-13 15:49:41 +08:00
parent 4b2b74f75a
commit be158a4975
12 changed files with 2162 additions and 161 deletions

View File

@ -5802,6 +5802,20 @@ static bk_err_t aud_tras_drv_play_prompt_tone(aud_intf_voc_prompt_tone_t prompt_
#endif #endif
break; break;
case AUD_INTF_VOC_AGENT_POWER_ON://zhanyu
#if CONFIG_PROMPT_TONE_SOURCE_ARRAY
prompt_tone_info.url = (char *)agent_power_on_prompt_tone_array;
prompt_tone_info.total_len = sizeof(agent_power_on_prompt_tone_array);
#endif
break;
case AUD_INTF_VOC_AGENT_POWER_OFF://zhanyu
#if CONFIG_PROMPT_TONE_SOURCE_ARRAY
prompt_tone_info.url = (char *)agent_power_off_prompt_tone_array;
prompt_tone_info.total_len = sizeof(agent_power_off_prompt_tone_array);
#endif
break;
default: default:
LOGE("%s, %d, prompt_tone: %d not support fail\n", __func__, __LINE__, prompt_tone); LOGE("%s, %d, prompt_tone: %d not support fail\n", __func__, __LINE__, prompt_tone);
play_flag = false; play_flag = false;

View File

@ -15,7 +15,7 @@
#pragma once #pragma once
#include <common/bk_include.h> #include <common/bk_include.h>
#include <driver/audio_ring_buff.h> #include <driver/audio_ring_buff.h>
#include <driver/aud_dac_types.h> #include <driver/aud_dac_types.h>
#include <driver/aud_dac.h> #include <driver/aud_dac.h>
#include <driver/aud_adc_types.h> #include <driver/aud_adc_types.h>
@ -240,6 +240,8 @@ typedef enum {
AUD_INTF_VOC_OTA_UPDATE_FAIL, AUD_INTF_VOC_OTA_UPDATE_FAIL,
AUD_INTF_VOC_OTA_UPDATE_SUCCESS, AUD_INTF_VOC_OTA_UPDATE_SUCCESS,
AUD_INTF_VOC_AGENT_START_FAIL, AUD_INTF_VOC_AGENT_START_FAIL,
AUD_INTF_VOC_AGENT_POWER_ON,//zhanyu
AUD_INTF_VOC_AGENT_POWER_OFF,//zhanyu
} aud_intf_voc_prompt_tone_t; } aud_intf_voc_prompt_tone_t;
#endif #endif
@ -259,17 +261,17 @@ typedef enum {
typedef struct { typedef struct {
uint32_t adc_samp_rate; uint32_t adc_samp_rate;
uint32_t enc_bitrate; uint32_t enc_bitrate;
uint8_t enc_frame_len_in_ms; uint8_t enc_frame_len_in_ms;
uint8_t enc_data_depth_in_byte; uint8_t enc_data_depth_in_byte;
uint8_t enc_vbr_en; uint8_t enc_vbr_en;
uint8_t reserved; uint8_t reserved;
uint32_t dac_samp_rate; uint32_t dac_samp_rate;
uint32_t dec_bitrate; uint32_t dec_bitrate;
uint8_t dec_frame_len_in_ms; uint8_t dec_frame_len_in_ms;
uint8_t dec_data_depth_in_byte; uint8_t dec_data_depth_in_byte;
uint8_t dec_vbr_en; uint8_t dec_vbr_en;
uint8_t reserved1; uint8_t reserved1;
} aud_codec_setup_input_t; } aud_codec_setup_input_t;

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,31 @@
// Copyright 2023-2024 Beken // Copyright 2023-2024 Beken
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "stdio.h" #include "stdio.h"
#include <os/os.h> #include <os/os.h>
#include <os/mem.h> #include <os/mem.h>
#include <os/str.h> #include <os/str.h>
#include <modules/pm.h> #include <modules/pm.h>
#include "prompt_tone_play.h" #include "prompt_tone_play.h"
#include "aud_tras_drv.h" #include "aud_tras_drv.h"
#define PROMPT_TONE_PLAY_TAG "rt_play" #define PROMPT_TONE_PLAY_TAG "rt_play"
#define LOGI(...) BK_LOGI(PROMPT_TONE_PLAY_TAG, ##__VA_ARGS__) #define LOGI(...) BK_LOGI(PROMPT_TONE_PLAY_TAG, ##__VA_ARGS__)
#define LOGW(...) BK_LOGW(PROMPT_TONE_PLAY_TAG, ##__VA_ARGS__) #define LOGW(...) BK_LOGW(PROMPT_TONE_PLAY_TAG, ##__VA_ARGS__)
#define LOGE(...) BK_LOGE(PROMPT_TONE_PLAY_TAG, ##__VA_ARGS__) #define LOGE(...) BK_LOGE(PROMPT_TONE_PLAY_TAG, ##__VA_ARGS__)
#define LOGD(...) BK_LOGD(PROMPT_TONE_PLAY_TAG, ##__VA_ARGS__) #define LOGD(...) BK_LOGD(PROMPT_TONE_PLAY_TAG, ##__VA_ARGS__)
#if CONFIG_PROMPT_TONE_CODEC_MP3 #if CONFIG_PROMPT_TONE_CODEC_MP3
#define CHUNK_SIZE (4068) #define CHUNK_SIZE (4068)
@ -49,13 +49,13 @@ static int source_out_data_handle_cb(char *buffer, uint32_t len, void *params)
break; break;
} }
LOGD("%s, %d, ret: %d\n", __func__, __LINE__, ret); LOGD("%s, %d, ret: %d\n", __func__, __LINE__, ret);
w_len += ret; w_len += ret;
} }
return w_len; return w_len;
} }
int source_notify_cb(void *play_ctx, void *params) int source_notify_cb(void *play_ctx, void *params)
{ {
audio_source_event_t event = (audio_source_event_t)params; audio_source_event_t event = (audio_source_event_t)params;
@ -79,7 +79,7 @@ int source_notify_cb(void *play_ctx, void *params)
return BK_OK; return BK_OK;
} }
static int codec_out_data_handle_cb(audio_frame_info_t *frame_info, char *buffer, uint32_t len, void *params) static int codec_out_data_handle_cb(audio_frame_info_t *frame_info, char *buffer, uint32_t len, void *params)
{ {
LOGD("channel_number: %d, sample_rate: %d, sample_bits: %d\n", frame_info->channel_number, frame_info->sample_rate, frame_info->sample_bits); LOGD("channel_number: %d, sample_rate: %d, sample_bits: %d\n", frame_info->channel_number, frame_info->sample_rate, frame_info->sample_bits);
@ -87,10 +87,10 @@ static int codec_out_data_handle_cb(audio_frame_info_t *frame_info, char *buffer
uint32_t temp_w_len = 0; uint32_t temp_w_len = 0;
uint32_t w_len = 0; uint32_t w_len = 0;
int ret = 0; int ret = 0;
#if CONFIG_AUD_INTF_SUPPORT_OPUS_PROMPT_TONE_RESAMPLE #if CONFIG_AUD_INTF_SUPPORT_OPUS_PROMPT_TONE_RESAMPLE
uint32_t rsp_out_len,rsp_in_len; uint32_t rsp_out_len,rsp_in_len;
uint8_t *rsp_out_addr = aud_tras_drv_get_rsp_output_buff(); uint8_t *rsp_out_addr = aud_tras_drv_get_rsp_output_buff();
#endif #endif
while (w_len < len) while (w_len < len)
{ {
@ -112,41 +112,41 @@ static int codec_out_data_handle_cb(audio_frame_info_t *frame_info, char *buffer
{ {
temp_w_len = len - w_len; temp_w_len = len - w_len;
} }
#if CONFIG_AUD_INTF_SUPPORT_OPUS_PROMPT_TONE_RESAMPLE #if CONFIG_AUD_INTF_SUPPORT_OPUS_PROMPT_TONE_RESAMPLE
if(PROMPT_TONE_SRC_SAMP_RATE != aud_tras_drv_get_dac_samp_rate()) if(PROMPT_TONE_SRC_SAMP_RATE != aud_tras_drv_get_dac_samp_rate())
{ {
rsp_in_len = (temp_w_len/2); rsp_in_len = (temp_w_len/2);
rsp_out_len = MAX_SAMP_CNT_20MS/2; rsp_out_len = MAX_SAMP_CNT_20MS/2;
ret = bk_aud_rsp_process((int16_t *)(buffer + w_len), &rsp_in_len, (int16_t *)rsp_out_addr, &rsp_out_len); ret = bk_aud_rsp_process((int16_t *)(buffer + w_len), &rsp_in_len, (int16_t *)rsp_out_addr, &rsp_out_len);
if (BK_OK != ret) if (BK_OK != ret)
{ {
LOGE("%s:%d bk_aud_rsp_process fail\n", __func__, __LINE__); LOGE("%s:%d bk_aud_rsp_process fail\n", __func__, __LINE__);
break; break;
} }
ret = aud_tras_drv_write_prompt_tone_data((char *)rsp_out_addr, rsp_out_len*2, 40); ret = aud_tras_drv_write_prompt_tone_data((char *)rsp_out_addr, rsp_out_len*2, 40);
LOGD("rsp len:%d, w_len:%d,in len:%d,%d,out len:%d,in addr:0x%x,out_addr:0x%x,ret:%d\n",len,w_len,temp_w_len,rsp_in_len,rsp_out_len,(buffer + w_len),rsp_out_addr,ret); LOGD("rsp len:%d, w_len:%d,in len:%d,%d,out len:%d,in addr:0x%x,out_addr:0x%x,ret:%d\n",len,w_len,temp_w_len,rsp_in_len,rsp_out_len,(buffer + w_len),rsp_out_addr,ret);
if(ret > temp_w_len) if(ret > temp_w_len)
{ {
ret = temp_w_len;//write size may larger than input length after resample ret = temp_w_len;//write size may larger than input length after resample
} }
} }
else else
{ {
ret = aud_tras_drv_write_prompt_tone_data(buffer + w_len, temp_w_len, 40); ret = aud_tras_drv_write_prompt_tone_data(buffer + w_len, temp_w_len, 40);
} }
#else #else
ret = aud_tras_drv_write_prompt_tone_data(buffer + w_len, temp_w_len, 40); ret = aud_tras_drv_write_prompt_tone_data(buffer + w_len, temp_w_len, 40);
#endif #endif
if (ret <= 0) if (ret <= 0)
{ {
LOGE("%s, %d, aud_tras_drv_write_prompt_tone_data fail, ret: %d\n", __func__, __LINE__, ret); LOGE("%s, %d, aud_tras_drv_write_prompt_tone_data fail, ret: %d\n", __func__, __LINE__, ret);
break; break;
} }
w_len += ret; w_len += ret;
/* start prompt tone play after write frame data to prompt tone ringbuffer pool to avoid read prompt tone fail */ /* start prompt tone play after write frame data to prompt tone ringbuffer pool to avoid read prompt tone fail */
if (SPK_SOURCE_TYPE_PROMPT_TONE != aud_tras_drv_get_spk_source_type()) if (SPK_SOURCE_TYPE_PROMPT_TONE != aud_tras_drv_get_spk_source_type())
@ -231,43 +231,43 @@ prompt_tone_play_handle_t prompt_tone_play_create( prompt_tone_play_cfg_t *conf
os_memcpy(&handle->config, config, sizeof(prompt_tone_play_cfg_t)); os_memcpy(&handle->config, config, sizeof(prompt_tone_play_cfg_t));
#if CONFIG_AUD_INTF_SUPPORT_OPUS_PROMPT_TONE_RESAMPLE #if CONFIG_AUD_INTF_SUPPORT_OPUS_PROMPT_TONE_RESAMPLE
int ret; int ret;
handle->config.rsp_cfg.dest_rate = aud_tras_drv_get_dac_samp_rate(); handle->config.rsp_cfg.dest_rate = aud_tras_drv_get_dac_samp_rate();
if(PROMPT_TONE_SRC_SAMP_RATE != handle->config.rsp_cfg.dest_rate) if(PROMPT_TONE_SRC_SAMP_RATE != handle->config.rsp_cfg.dest_rate)
{ {
handle->config.rsp_cfg.complexity = 6; handle->config.rsp_cfg.complexity = 6;
handle->config.rsp_cfg.src_ch = 1;//only enable SPK left channel handle->config.rsp_cfg.src_ch = 1;//only enable SPK left channel
handle->config.rsp_cfg.dest_ch = 1;//only enable SPK left channel handle->config.rsp_cfg.dest_ch = 1;//only enable SPK left channel
handle->config.rsp_cfg.src_bits = 16; handle->config.rsp_cfg.src_bits = 16;
handle->config.rsp_cfg.dest_bits = 16; handle->config.rsp_cfg.dest_bits = 16;
handle->config.rsp_cfg.src_rate = PROMPT_TONE_SRC_SAMP_RATE; handle->config.rsp_cfg.src_rate = PROMPT_TONE_SRC_SAMP_RATE;
handle->config.rsp_cfg.down_ch_idx = 0; handle->config.rsp_cfg.down_ch_idx = 0;
ret = bk_aud_rsp_init(handle->config.rsp_cfg); ret = bk_aud_rsp_init(handle->config.rsp_cfg);
if (ret != BK_OK) if (ret != BK_OK)
{ {
LOGE("%s, %d, audio resampler init fail\n", __func__, __LINE__); LOGE("%s, %d, audio resampler init fail\n", __func__, __LINE__);
goto fail; goto fail;
} }
handle->config.rsp_out_buff = (uint8_t *)psram_malloc(MAX_SAMP_CNT_20MS); handle->config.rsp_out_buff = (uint8_t *)psram_malloc(MAX_SAMP_CNT_20MS);
if (!handle->config.rsp_out_buff) if (!handle->config.rsp_out_buff)
{ {
LOGE("%s, %d, malloc rsp output buffer fail\n", __func__, __LINE__); LOGE("%s, %d, malloc rsp output buffer fail\n", __func__, __LINE__);
goto fail; goto fail;
} }
LOGI("%s:%d rsp_init done!src sr:%d,dest sr:%d,cplx:%d,out buf:0x%x\n", LOGI("%s:%d rsp_init done!src sr:%d,dest sr:%d,cplx:%d,out buf:0x%x\n",
__func__, __LINE__, __func__, __LINE__,
handle->config.rsp_cfg.src_rate, handle->config.rsp_cfg.src_rate,
handle->config.rsp_cfg.dest_rate, handle->config.rsp_cfg.dest_rate,
handle->config.rsp_cfg.complexity, handle->config.rsp_cfg.complexity,
handle->config.rsp_out_buff); handle->config.rsp_out_buff);
} }
#endif #endif
return handle; return handle;
fail: fail:
@ -301,7 +301,7 @@ fail:
return NULL; return NULL;
} }
bk_err_t prompt_tone_play_destroy(prompt_tone_play_handle_t handle) bk_err_t prompt_tone_play_destroy(prompt_tone_play_handle_t handle)
{ {
LOGI("%s\n", __func__); LOGI("%s\n", __func__);
if (!handle) if (!handle)
@ -321,21 +321,21 @@ bk_err_t prompt_tone_play_destroy(prompt_tone_play_handle_t handle)
audio_source_destroy(handle->source); audio_source_destroy(handle->source);
handle->source = NULL; handle->source = NULL;
} }
#if CONFIG_AUD_INTF_SUPPORT_OPUS_PROMPT_TONE_RESAMPLE #if CONFIG_AUD_INTF_SUPPORT_OPUS_PROMPT_TONE_RESAMPLE
if(PROMPT_TONE_SRC_SAMP_RATE != handle->config.rsp_cfg.dest_rate) if(PROMPT_TONE_SRC_SAMP_RATE != handle->config.rsp_cfg.dest_rate)
{ {
bk_aud_rsp_deinit(); bk_aud_rsp_deinit();
psram_free(handle->config.rsp_out_buff); psram_free(handle->config.rsp_out_buff);
} }
#endif #endif
psram_free(handle); psram_free(handle);
return BK_OK; return BK_OK;
} }
bk_err_t prompt_tone_play_open(prompt_tone_play_handle_t handle) bk_err_t prompt_tone_play_open(prompt_tone_play_handle_t handle)
{ {
bk_err_t ret = BK_OK; bk_err_t ret = BK_OK;
@ -387,7 +387,7 @@ fail:
return BK_FAIL; return BK_FAIL;
} }
bk_err_t prompt_tone_play_close(prompt_tone_play_handle_t handle, bool wait_play_finish) bk_err_t prompt_tone_play_close(prompt_tone_play_handle_t handle, bool wait_play_finish)
{ {
if (!handle) if (!handle)
{ {
@ -434,7 +434,7 @@ bk_err_t prompt_tone_play_close(prompt_tone_play_handle_t handle, bool wait_play
return BK_OK; return BK_OK;
} }
bk_err_t prompt_tone_play_set_url(prompt_tone_play_handle_t handle, url_info_t *url_info) bk_err_t prompt_tone_play_set_url(prompt_tone_play_handle_t handle, url_info_t *url_info)
{ {
if (!handle || !url_info || !url_info->url) if (!handle || !url_info || !url_info->url)
{ {
@ -458,9 +458,9 @@ bk_err_t prompt_tone_play_set_url(prompt_tone_play_handle_t handle, url_info_t *
{ {
return BK_FAIL; return BK_FAIL;
} }
} }
bk_err_t prompt_tone_play_start(prompt_tone_play_handle_t handle) bk_err_t prompt_tone_play_start(prompt_tone_play_handle_t handle)
{ {
bk_err_t ret = BK_OK; bk_err_t ret = BK_OK;
@ -512,9 +512,9 @@ fail:
audio_codec_ctrl(handle->codec, AUDIO_CODEC_CTRL_STOP, NULL); audio_codec_ctrl(handle->codec, AUDIO_CODEC_CTRL_STOP, NULL);
return BK_FAIL; return BK_FAIL;
} }
bk_err_t prompt_tone_play_stop(prompt_tone_play_handle_t handle) bk_err_t prompt_tone_play_stop(prompt_tone_play_handle_t handle)
{ {
bk_err_t ret = BK_OK; bk_err_t ret = BK_OK;
bk_err_t err = BK_OK; bk_err_t err = BK_OK;
@ -572,5 +572,5 @@ bk_err_t prompt_tone_play_stop(prompt_tone_play_handle_t handle)
handle->status = PROMPT_TONE_PLAY_STA_IDLE; handle->status = PROMPT_TONE_PLAY_STA_IDLE;
return err; return err;
} }

View File

@ -137,6 +137,7 @@ static uint8_t ota_event_callback(evt_ota event_param)
case EVT_OTA_SUCCESS: case EVT_OTA_SUCCESS:
app_event_send_msg(APP_EVT_OTA_SUCCESS, 0); app_event_send_msg(APP_EVT_OTA_SUCCESS, 0);
break; break;
default: default:
break; break;
} }
@ -151,11 +152,12 @@ static uint8_t battery_event_callback(evt_battery event_param)
app_event_send_msg(APP_EVT_CHARGING, 0); app_event_send_msg(APP_EVT_CHARGING, 0);
break; break;
case EVT_BATTERY_LOW_VOLTAGE: case EVT_BATTERY_LOW_VOLTAGE:
app_event_send_msg(APP_EVT_LOW_VOLTAGE, 0); // app_event_send_msg(APP_EVT_LOW_VOLTAGE, 0);
break; break;
case EVT_SHUTDOWN_LOW_BATTERY: case EVT_SHUTDOWN_LOW_BATTERY:
app_event_send_msg(APP_EVT_SHUTDOWN_LOW_BATTERY, 0); //app_event_send_msg(APP_EVT_SHUTDOWN_LOW_BATTERY, 0);
break; break;
default: default:
break; break;
} }
@ -175,6 +177,14 @@ static uint8_t battery_main_event_callback(evt_main_battery event_param)//zhanyu
case EVT_SHUTDOWN_MAIN_LOW_BATTERY: case EVT_SHUTDOWN_MAIN_LOW_BATTERY:
app_event_send_msg(APP_EVT_SHUTDOWN_LOW_BATTERY, 0); app_event_send_msg(APP_EVT_SHUTDOWN_LOW_BATTERY, 0);
break; break;
case EVT_POWER_ON:
app_event_send_msg(APP_EVT_POWER_ON, 0);
break;
case EVT_POWER_OFF:
app_event_send_msg(APP_EVT_POWER_OFF, 0);
break;
default: default:
break; break;
} }
@ -373,6 +383,20 @@ static void app_event_thread(beken_thread_arg_t data)
bool skip_countdown_update = false; bool skip_countdown_update = false;
switch (msg.event) switch (msg.event)
{ {
case APP_EVT_POWER_ON://zhanyu
LOGE("APP_EVT_POWER_ON\n");
#if CONFIG_AUD_INTF_SUPPORT_PROMPT_TONE
bk_aud_intf_voc_play_prompt_tone(AUD_INTF_VOC_AGENT_POWER_ON);
#endif
break;
case APP_EVT_POWER_OFF://zhanyu
LOGE("APP_EVT_POWER_ON\n");
#if CONFIG_AUD_INTF_SUPPORT_PROMPT_TONE
bk_aud_intf_voc_play_prompt_tone(AUD_INTF_VOC_AGENT_POWER_OFF);
#endif
break;
case APP_EVT_ASR_WAKEUP: // hi armino case APP_EVT_ASR_WAKEUP: // hi armino
is_standby = 0; is_standby = 0;
indicates_state &= ~((1 << INDICATES_STANDBY) | (1 << INDICATES_AGENT_CONNECT)); indicates_state &= ~((1 << INDICATES_STANDBY) | (1 << INDICATES_AGENT_CONNECT));
@ -542,8 +566,8 @@ static void app_event_thread(beken_thread_arg_t data)
case APP_EVT_SHUTDOWN_LOW_BATTERY: case APP_EVT_SHUTDOWN_LOW_BATTERY:
LOGI("APP_EVT_SHUTDOWN_LOW_BATTERY\n"); LOGI("APP_EVT_SHUTDOWN_LOW_BATTERY\n");
skip_countdown_update = true; //skip_countdown_update = true;
bk_config_sync_flash(); // bk_config_sync_flash();
break; break;
case APP_EVT_CLOSE_BLUETOOTH: case APP_EVT_CLOSE_BLUETOOTH:

View File

@ -20,8 +20,8 @@ typedef enum
APP_EVT_OTA_START, APP_EVT_OTA_START,
APP_EVT_OTA_SUCCESS, APP_EVT_OTA_SUCCESS,
APP_EVT_OTA_FAIL, APP_EVT_OTA_FAIL,
APP_EVT_POWER_ON, APP_EVT_POWER_ON,
APP_EVT_POWER_OFF,
} app_evt_type_t; } app_evt_type_t;

View File

@ -353,15 +353,19 @@ static void handle_system_event(key_event_t event)
// bk_reboot(); // bk_reboot();
// break; // break;
case TURN_OFF_LOGHT: case TURN_OFF_LOGHT:
bk_printf("ispoweron = %d\n", ispoweron); bk_printf("ispoweron11 = %d\n", ispoweron);
// clearallled(); // clearallled();
if (ispoweron == 1) if (ispoweron == 1)
{ {
bk_printf(TAG, "POWER OFFaaa~~~ \r\n");
bk_printf("POWER OFFaaa~~~ \r\n");
poweroff_voice();
ws2812_led_clear_all(); ws2812_led_clear_all();
ispoweron = 0; ispoweron = 0;
rtos_delay_milliseconds(300);
bk_gpio_enable_output(51); bk_gpio_enable_output(51);
bk_gpio_set_output_low(51); bk_gpio_set_output_low(51);
} }
else if (ispoweron == 0) else if (ispoweron == 0)
{ {
@ -373,7 +377,7 @@ static void handle_system_event(key_event_t event)
ispoweron = 1; ispoweron = 1;
ws2812_led_wifi_disconnect(); ws2812_led_wifi_disconnect();
poweron_voice();
// bk_gpio_enable_output(0); // bk_gpio_enable_output(0);
//bk_gpio_set_output_high(0); //bk_gpio_set_output_high(0);
#endif #endif
@ -464,7 +468,7 @@ static void handle_system_event(key_event_t event)
return 0; return 0;
} }
static void bk_enter_deepsleep() void bk_enter_deepsleep()
{ {
#if CONFIG_GSENSOR_ENABLE #if CONFIG_GSENSOR_ENABLE
extern int gsensor_enter_sleep_config(); extern int gsensor_enter_sleep_config();
@ -551,6 +555,9 @@ static void handle_system_event(key_event_t event)
bk_gpio_enable_output(GPIO_0); bk_gpio_enable_output(GPIO_0);
bk_gpio_set_output_low(GPIO_0); bk_gpio_set_output_low(GPIO_0);
if (bk_misc_get_reset_reason() != RESET_SOURCE_FORCE_DEEPSLEEP) if (bk_misc_get_reset_reason() != RESET_SOURCE_FORCE_DEEPSLEEP)
{ {
#if (CONFIG_SYS_CPU0) #if (CONFIG_SYS_CPU0)
@ -568,6 +575,8 @@ static void handle_system_event(key_event_t event)
#endif #endif
#if (CONFIG_SYS_CPU0) #if (CONFIG_SYS_CPU0)
/*to judgement key is long press or short press; long press exit deepsleep*/ /*to judgement key is long press or short press; long press exit deepsleep*/
//zhanyu //zhanyu
@ -651,6 +660,11 @@ static void handle_system_event(key_event_t event)
} }
#if (CONFIG_SYS_CPU0) #if (CONFIG_SYS_CPU0)
// bk_printf("ispoweron = %d bk_enter_deepsleep();\n",ispoweron);
// if(ispoweron == 0){
// bk_printf("bk_enter_deepsleep()aaa\n");
// bk_enter_deepsleep();
// }
volume = 10; volume = 10;
bk_aud_intf_set_spk_gain(0x29); // 0x30 bk_aud_intf_set_spk_gain(0x29); // 0x30
@ -661,6 +675,7 @@ static void handle_system_event(key_event_t event)
thing_init(); thing_init();
init_bat_timer(); init_bat_timer();
// spi_led_init(); // spi_led_init();
bk_printf("bk_misc_get_reset_reason = 0x%02X \n",bk_misc_get_reset_reason());
bk_printf("VER:1.0.3 2025.05.27\r\n"); bk_printf("VER:1.0.3 2025.05.27\r\n");
#endif #endif
#endif #endif

View File

@ -170,7 +170,7 @@ static bk_err_t prvStartBatteryAdcOneTime()
if (s_battery_main_event_callback && insert_value == 0) if (s_battery_main_event_callback && insert_value == 0)
{ {
bk_printf("ADC bat_value < 3500\r\n"); bk_printf("ADC bat_value < 3500\r\n");
//s_battery_main_event_callback(EVT_BATTERY_MAIN_LOW_VOLTAGE); s_battery_main_event_callback(EVT_BATTERY_MAIN_LOW_VOLTAGE);
} }
} }
@ -218,3 +218,30 @@ void init_bat_timer()
bk_printf("rtos_start_bat_timer fail\r\n"); bk_printf("rtos_start_bat_timer fail\r\n");
} }
} }
void poweron_voice()
{
if (s_battery_main_event_callback)
{
bk_printf("s_battery_main_event_callback(EVT_POWER_ON);\r\n");
s_battery_main_event_callback(EVT_POWER_ON);
}
}
void poweroff_voice()
{
if (s_battery_main_event_callback)
{
bk_printf("s_battery_main_event_callback(EVT_POWER_ON);\r\n");
s_battery_main_event_callback(EVT_POWER_OFF);
}
}

View File

@ -2,8 +2,12 @@ typedef enum{
EVT_BATTERY_MAIN_CHARGING = 0, EVT_BATTERY_MAIN_CHARGING = 0,
EVT_BATTERY_MAIN_LOW_VOLTAGE, EVT_BATTERY_MAIN_LOW_VOLTAGE,
EVT_SHUTDOWN_MAIN_LOW_BATTERY, EVT_SHUTDOWN_MAIN_LOW_BATTERY,
EVT_POWER_ON,
EVT_POWER_OFF,
}evt_main_battery; }evt_main_battery;
typedef uint8_t (*battery_main_event_callback_t)(evt_main_battery event_param); typedef uint8_t (*battery_main_event_callback_t)(evt_main_battery event_param);
int battery_main_event_callback_register(battery_main_event_callback_t callback); int battery_main_event_callback_register(battery_main_event_callback_t callback);
void init_bat_timer(); void init_bat_timer();
void poweron_voice();
void poweroff_voice();

View File

@ -129,6 +129,47 @@ void ble_set_wifi_scan_result(wifi_scan_result_t *result){
os_printf("STR:%s\r\n", str_ssid); os_printf("STR:%s\r\n", str_ssid);
//<2F>ش<EFBFBD>WIFI <20>б<EFBFBD> //<2F>ش<EFBFBD>WIFI <20>б<EFBFBD>
wifi_boarding_notify((uint8_t *)str_ssid, strlen(str_ssid)); wifi_boarding_notify((uint8_t *)str_ssid, strlen(str_ssid));
// 封装 AT+RSSI 指令
char str_ssid2[1024] = {0};
strcat(str_ssid2, "AT+RSSI=");
ap_index = 0;
int valid_ssid_count = 0; // 用于记录有效的 SSID 数量
for (int i = 0; i < count; i++)
{
if (strlen(scan_result->aps[i].ssid) > 0)
{
ssid_count_in_scan_result(scan_result->aps[i].ssid);
// if (in_list > 0)
// {
// os_printf("%s already in list for str_ssid2\r\n", scan_result->aps[i].ssid);
// continue;
// }
// 拼接 SSID 和信号强度
char temp[32] = {0};
int ret = sprintf(temp, "%s:%d", scan_result->aps[i].ssid, scan_result->aps[i].rssi);
if (ret < 0) {
// os_printf("Error: sprintf failed for %s\r\n", scan_result->aps[i].ssid);
continue;
}
strcat(str_ssid2, temp);
valid_ssid_count++;
// os_printf("After adding SSID:RSSI %s, str_ssid2: %s\r\n", temp, str_ssid2);
if (i != count - 1)
{
strcat(str_ssid2, ",");
// os_printf("After adding comma, str_ssid2: %s\r\n", str_ssid2);
}
}
}
if (valid_ssid_count == 0) {
// os_printf("No valid SSIDs added to str_ssid2\r\n");
}
os_printf("STR2:%s\r\n", str_ssid2);
// 回复 AT+SSID2 指令结果
wifi_boarding_notify((uint8_t *)str_ssid2, strlen(str_ssid2));
} }
#endif #endif

View File

@ -690,6 +690,8 @@ static int bk_genie_reselect_pan(void)
extern void beken_auto_run(void); extern void beken_auto_run(void);
extern void ws2812_led_wifi_connected(void); extern void ws2812_led_wifi_connected(void);
extern void bk_enter_deepsleep();
extern int ispoweron;
beken_timer_t led_wifi_connected_timer; beken_timer_t led_wifi_connected_timer;
static void led_wifi_connected(void *param) static void led_wifi_connected(void *param)
@ -697,6 +699,13 @@ static void led_wifi_connected(void *param)
bk_printf("led_wifi_connected\n"); bk_printf("led_wifi_connected\n");
// bk_printf("ispoweron = %d bk_enter_deepsleep();\n",ispoweron);
// if(ispoweron == 0){
// bk_printf("bk_enter_deepsleep()aaa\n");
// bk_enter_deepsleep();
// }
ws2812_led_wifi_connected(); ws2812_led_wifi_connected();
rtos_stop_timer(&led_wifi_connected_timer); rtos_stop_timer(&led_wifi_connected_timer);

View File

@ -110,7 +110,7 @@ extern uint32_t volume;
extern uint32_t g_volume_gain[SPK_VOLUME_LEVEL]; extern uint32_t g_volume_gain[SPK_VOLUME_LEVEL];
extern app_aud_para_t app_aud_cust_para; extern app_aud_para_t app_aud_cust_para;
bk_err_t beken_rtc_stop(void);//zhanyu bk_err_t beken_rtc_stop(void); // zhanyu
#if CONFIG_WIFI_ENABLE #if CONFIG_WIFI_ENABLE
extern void rwnxl_set_video_transfer_flag(uint32_t video_transfer_flag); extern void rwnxl_set_video_transfer_flag(uint32_t video_transfer_flag);
@ -523,7 +523,7 @@ void rtc_websocket_msg_handle(char *json_text, unsigned int size)
LOGE("Error: Failed to parse JSON text:%s\n", json_text); LOGE("Error: Failed to parse JSON text:%s\n", json_text);
return; return;
} }
//bk_printf("rtc_websocket_msg_handle json_text : %s \n",json_text); // bk_printf("rtc_websocket_msg_handle json_text : %s \n",json_text);
cJSON *type = cJSON_GetObjectItem(root, "type"); cJSON *type = cJSON_GetObjectItem(root, "type");
if (type == NULL) if (type == NULL)
{ {
@ -541,7 +541,8 @@ void rtc_websocket_msg_handle(char *json_text, unsigned int size)
int ret = 200; int ret = 200;
if (ret == 200) if (ret == 200)
{ {
if(g_connected_flag){//zhanyu if (g_connected_flag)
{ // zhanyu
return; return;
} }
g_connected_flag = true; g_connected_flag = true;
@ -550,21 +551,20 @@ void rtc_websocket_msg_handle(char *json_text, unsigned int size)
smart_config_running = false; smart_config_running = false;
__get_beken_rtc()->disconnecting_state = 0; __get_beken_rtc()->disconnecting_state = 0;
//发送设备IOT能力描述到服务器 // 发送设备IOT能力描述到服务器
//rtc_websocket_send_text(client, "", BEKEN_RTC_SEND_IOT_DESC); // rtc_websocket_send_text(client, "", BEKEN_RTC_SEND_IOT_DESC);
} }
else else
{ {
LOGE("join WebSocket server fail\r\n"); LOGE("join WebSocket server fail\r\n");
} }
} }
//解析服务器下发的IOT 指令 // 解析服务器下发的IOT 指令
else if (strcmp(type->valuestring, "iot") == 0) else if (strcmp(type->valuestring, "iot") == 0)
{ {
thing_iot_invoke(json_text); thing_iot_invoke(json_text);
} }
// else if ((strcmp(type->valuestring, "reply_text") == 0) || (strcmp(type->valuestring, "request_text") == 0)) { // else if ((strcmp(type->valuestring, "reply_text") == 0) || (strcmp(type->valuestring, "request_text") == 0)) {
// text_info_t info = {0}; // text_info_t info = {0};
// info.text_type = (strcmp(type->valuestring, "request_text") == 0) ? 0:1; // info.text_type = (strcmp(type->valuestring, "request_text") == 0) ? 0:1;
@ -673,13 +673,13 @@ int first_abort = 0;
void sent_abort_msg() void sent_abort_msg()
{ {
bk_printf("MEDIA_APP_EVT_ASR_WAKEUP_IND_sent_abort_msg first_abort = %d\n",first_abort); bk_printf("MEDIA_APP_EVT_ASR_WAKEUP_IND_sent_abort_msg first_abort = %d\n", first_abort);
if (first_abort == 0) if (first_abort == 0)
{ {
first_abort = 1; first_abort = 1;
return; return;
} }
// bk_printf("MEDIA_APP_EVT_ASR_WAKEUP_IND_sent_abort_msg first_abort = %d\n",first_abort); // bk_printf("MEDIA_APP_EVT_ASR_WAKEUP_IND_sent_abort_msg first_abort = %d\n",first_abort);
if (client) if (client)
{ {
bk_printf("rtc_websocket_send_text_BEKEN_RTC_SEND_ABORT_BEKEN_RTC_SEND_STOP_LISTEN_BEKEN_RTC_SEND_START_LISTEN\r\n"); bk_printf("rtc_websocket_send_text_BEKEN_RTC_SEND_ABORT_BEKEN_RTC_SEND_STOP_LISTEN_BEKEN_RTC_SEND_START_LISTEN\r\n");
@ -693,7 +693,6 @@ void sent_abort_msg()
} }
} }
// 检查二进制数据接收状态的接口函数 // 检查二进制数据接收状态的接口函数
uint8_t get_binary_data_status(void) uint8_t get_binary_data_status(void)
{ {
@ -753,11 +752,11 @@ static bk_err_t init_check_timer(void)
timer_initialized = true; timer_initialized = true;
return 0; return 0;
} }
//extern bk_err_t audio_tras_deinit(void);zhanyu // extern bk_err_t audio_tras_deinit(void);zhanyu
void rtc_websocket_event_handler(void *event_handler_arg, char *event_base, int32_t event_id, void *event_data) void rtc_websocket_event_handler(void *event_handler_arg, char *event_base, int32_t event_id, void *event_data)
{ {
bk_websocket_event_data_t *data = (bk_websocket_event_data_t *)event_data; bk_websocket_event_data_t *data = (bk_websocket_event_data_t *)event_data;
//transport client = (transport)event_handler_arg;//zhanyu // transport client = (transport)event_handler_arg;//zhanyu
client = (transport)event_handler_arg; client = (transport)event_handler_arg;
switch (event_id) switch (event_id)
{ {
@ -767,33 +766,32 @@ void rtc_websocket_event_handler(void *event_handler_arg, char *event_base, int3
rtos_delay_milliseconds(100); rtos_delay_milliseconds(100);
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_START); rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_START);
rtos_delay_milliseconds(100); rtos_delay_milliseconds(100);
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_IOT_DESC); rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_IOT_DESC);
// rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_START_LISTEN); // rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_START_LISTEN);
// rtos_delay_milliseconds(200); // rtos_delay_milliseconds(200);
// rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_LISTEN); // rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_LISTEN);
break; break;
case WEBSOCKET_EVENT_DISCONNECTED: case WEBSOCKET_EVENT_DISCONNECTED:
bk_printf("WEBSOCKET_EVENT_DISCONNECTED~~~~\n"); bk_printf("WEBSOCKET_EVENT_DISCONNECTED~~~~\n");
LOGE("Disconnected from WebSocket server\r\n"); LOGE("Disconnected from WebSocket server\r\n");
g_connected_flag = false; g_connected_flag = false;
__get_beken_rtc()->disconnecting_state++; __get_beken_rtc()->disconnecting_state++;
if (__get_beken_rtc()->disconnecting_state == 1){ if (__get_beken_rtc()->disconnecting_state == 1)
{
app_event_send_msg(APP_EVT_RTC_CONNECTION_LOST, 0); app_event_send_msg(APP_EVT_RTC_CONNECTION_LOST, 0);
} }
// beken_rtc_stop();//zhanyu
// beken_rtc_stop();//zhanyu // audio_tras_deinit();
//audio_tras_deinit();
break; break;
case WEBSOCKET_EVENT_CLOSED: case WEBSOCKET_EVENT_CLOSED:
bk_printf("WEBSOCKET_EVENT_CLOSED~~~~\n"); bk_printf("WEBSOCKET_EVENT_CLOSED~~~~\n");
beken_rtc_stop();//zhanyu beken_rtc_stop(); // zhanyu
//audio_tras_deinit(); // audio_tras_deinit();
break; break;
case WEBSOCKET_EVENT_DATA: case WEBSOCKET_EVENT_DATA:
LOGD("data from WebSocket server, len:%d op:%d\r\n", data->data_len, data->op_code); LOGD("data from WebSocket server, len:%d op:%d\r\n", data->data_len, data->op_code);
if (data->op_code == WS_TRANSPORT_OPCODES_BINARY) if (data->op_code == WS_TRANSPORT_OPCODES_BINARY)
@ -835,7 +833,7 @@ void beken_rtc_main(void)
bk_printf("headers = %s\r\n", headers); bk_printf("headers = %s\r\n", headers);
websocket_cfg.headers = headers; websocket_cfg.headers = headers;
websocket_cfg.uri = "wss://xiaozhi.xa-poka.com/websocket/xiaozhi/v1/"; websocket_cfg.uri = "wss://xiaozhi.xa-poka.com/websocket/xiaozhi/v1/";
//websocket_cfg.uri = "ws://43.139.216.160:8000/xiaozhi/v1/"; // websocket_cfg.uri = "ws://43.139.216.160:8000/xiaozhi/v1/";
websocket_cfg.ws_event_handler = rtc_websocket_event_handler; websocket_cfg.ws_event_handler = rtc_websocket_event_handler;
rtc_session *rtc_session = rtc_websocket_create(&websocket_cfg, rtc_user_audio_rx_data_handle, &audio_info); rtc_session *rtc_session = rtc_websocket_create(&websocket_cfg, rtc_user_audio_rx_data_handle, &audio_info);
if (rtc_session == NULL) if (rtc_session == NULL)
@ -923,8 +921,6 @@ bk_err_t beken_rtc_stop(void)
return BK_OK; return BK_OK;
} }
static bk_err_t beken_rtc_start(void) static bk_err_t beken_rtc_start(void)
{ {
bk_printf("beken_rtc_start2222~~~\n"); bk_printf("beken_rtc_start2222~~~\n");
@ -1042,4 +1038,3 @@ void cli_beken_rtc_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc,
cmd_fail: cmd_fail:
cli_beken_rtc_help(); cli_beken_rtc_help();
} }