Compare commits

..

No commits in common. "d54fd916e7f0787ce9c158037f424883f95c27e8" and "e46beee76d0c3268589a04316510de33f4776e09" have entirely different histories.

54 changed files with 130 additions and 1767 deletions

View File

@ -113,9 +113,6 @@ char *https_url = NULL;
int bk_https_ota_download(const char *url);
void bk_https_start_download(beken_thread_arg_t arg) {
int ret;
//退出WEBSOCKET
//退出语音识别
ret = bk_https_ota_download(https_url);
if(ret != BK_OK) {
os_printf("%s download fail, ret:%d\r\n", __func__, ret);

View File

@ -1 +1 @@
/home/harmony/work/bk7258_iR58/bk_aidk/bk_avdk/bk_idk/tools/env_tools/beken_packager/partition_bk7256_ota_a_new.json
/home/harmony/armino/LFV2/bk_aidk/bk_avdk/bk_idk/tools/env_tools/beken_packager/partition_bk7256_ota_a_new.json

View File

@ -12,28 +12,28 @@
"name": "app",
"flash_name": "beken_onchip_crc",
"offset": "0x00011000",
"len": "2856K"
"len": "2584K"
},
{
"magic": "0x45503130",
"name": "app1",
"flash_name": "beken_onchip_crc",
"offset": "0x002db000",
"len": "1496K"
"offset": "0x00297000",
"len": "408K"
},
{
"magic": "0x45503130",
"name": "app2",
"flash_name": "beken_onchip_crc",
"offset": "0x00451000",
"len": "476K"
"offset": "0x002fd000",
"len": "136K"
},
{
"magic": "0x45503130",
"name": "download",
"flash_name": "beken_onchip",
"offset": "0x004c8000",
"len": "3196K"
"offset": "0x0031f000",
"len": "1792K"
}
]
}

View File

@ -26,8 +26,6 @@ list(APPEND srcs
iot/iot_sleep_helper.c
iot/thing.c
iot/iot_ota.c
mcp/mcp_server.c
application.c
)
if (CONFIG_NETWORK_AUTO_RECONNECT)
list(APPEND srcs

View File

@ -42,7 +42,7 @@
#include "app_main.h"
#include "spi_led.h"
#include "bat_main.h"
#include "application.h"
extern void user_app_main(void);
extern void rtos_set_user_app_entry(beken_thread_function_t entry);
@ -673,7 +673,6 @@ static void handle_system_event(key_event_t event)
//poka
ws2812_init();
thing_init();
app_start();
init_bat_timer();
// spi_led_init();
bk_printf("VER:%s\r\n","1.0.6");

View File

@ -1,268 +0,0 @@
#include <common/sys_config.h>
#include <components/log.h>
#include <modules/wifi.h>
#include <components/netif.h>
#include <components/event.h>
#include <string.h>
#include "bk_private/bk_init.h"
#include <components/system.h>
#include <os/os.h>
#include "components/webclient.h"
#include "cJSON.h"
#include "components/bk_uid.h"
#include "bk_genie_comm.h"
#include "thing.h"
#include "iot_lamp.h"
#include "iot_speaker.h"
#include "iot_sleep_helper.h"
#include "bat_main.h"
#include "application.h"
#include "mcp/mcp_server.h"
#include "beken_rtc.h"
#include "iot_lamp.h"
#include "iot_speaker.h"
#include "iot_sleep_helper.h"
#include "bat_main.h"
#include "spi_led.h"
#include "app_event.h"
#define TAG "APP"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
#define LOGW(...) BK_LOGW(TAG, ##__VA_ARGS__)
#define LOGE(...) BK_LOGE(TAG, ##__VA_ARGS__)
#define LOGD(...) BK_LOGD(TAG, ##__VA_ARGS__)
static ReturnValue sleep_helper_set_mode_callback(const PropertyList* properties) {
Property* mode_prop = property_list_get_by_name(properties, "mode");
if (!mode_prop || property_get_type(mode_prop) != PROPERTY_TYPE_INTEGER) {
return return_value_create_string("{\"error\":\"Invalid level parameter\"}");
}
int mode = property_get_integer_value(mode_prop);
sleep_helper_set_mode(mode);
LOGE("sleep_helper_setmode ->%d\n",mode);
return return_value_create_string("{\"success\":true}");
}
static ReturnValue sleep_helper_set_level_callback(const PropertyList* properties) {
Property* level_prop = property_list_get_by_name(properties, "mode");
if (!level_prop || property_get_type(level_prop) != PROPERTY_TYPE_INTEGER) {
return return_value_create_string("{\"error\":\"Invalid level parameter\"}");
}
int level = property_get_integer_value(level_prop);
sleep_helper_set_level(level);
LOGE("sleep_helper_set_level ->%d\n",level);
return return_value_create_string("{\"success\":true}");
}
static ReturnValue sleep_helper_open_callback(const PropertyList* properties) {
LOGE("sleep_helper_open_callback\n");
int result = sleep_helper_open();
if(result == -1){
return return_value_create_string("{\"success\":false,\"error\":\"耳夹未接入\"}");
}else{
return return_value_create_string("{\"success\":true}");
}
//return return_value_create_string("{\"success\":true}");
}
static ReturnValue sleep_helper_close_callback(const PropertyList* properties) {
LOGE("sleep_helper_close_callback\n");
sleep_helper_close();
return return_value_create_string("{\"success\":true}");
}
// 设备状态工具回调
static ReturnValue get_device_status_callback(const PropertyList* properties) {
cJSON* status = cJSON_CreateObject();
//软件版本
cJSON* application = cJSON_CreateObject();
cJSON_AddStringToObject(application, "version", APPLICATION_VERSION);
cJSON_AddItemToObject(status, "application", application);
//扬声器状态
cJSON* audio_speaker = cJSON_CreateObject();
cJSON_AddNumberToObject(audio_speaker, "volume", speaker_volume_get_current());
cJSON_AddItemToObject(status, "audio_speaker", audio_speaker);
//灯光状态 不需要获取 肉眼所见
cJSON* light = cJSON_CreateObject();
cJSON_AddNumberToObject(light, "brightness", lamp_get_bright());
//cJSON_AddStringToObject(screen, "theme", "light");
cJSON_AddItemToObject(status, "light", light);
//电池状态
cJSON* battery = cJSON_CreateObject();
cJSON_AddNumberToObject(battery, "level", battery_get_percent());
cJSON_AddItemToObject(status, "battery", battery);
char *jsonString = cJSON_PrintUnformatted(status);
ReturnValue ret = return_value_create_string(jsonString);
cJSON_Delete(status);
return ret;
}
// 设置音量工具回调
static ReturnValue set_volume_callback(const PropertyList* properties) {
Property* volume_prop = property_list_get_by_name(properties, "volume");
if (!volume_prop || property_get_type(volume_prop) != PROPERTY_TYPE_INTEGER) {
return return_value_create_string("{\"error\":\"Invalid volume parameter\"}");
}
int volume = property_get_integer_value(volume_prop);
LOGE("board_set_volume ->%d\n",volume);
//board_set_volume(volume);
//uint32_t speaker_volume_get_current();
speaker_set_volume(volume);
return return_value_create_string("{\"success\":true}");
}
// 设置亮度工具回调
static ReturnValue set_brightness_callback(const PropertyList* properties) {
Property* brightness_prop = property_list_get_by_name(properties, "brightness");
if (!brightness_prop || property_get_type(brightness_prop) != PROPERTY_TYPE_INTEGER) {
return return_value_create_string("{\"error\":\"Invalid brightness parameter\"}");
}
int brightness = property_get_integer_value(brightness_prop);
if(brightness == 0){
ws2812_led_clear_all();
}else{
//ws2812_set_all_led(0xFFFFFF,brightness);
ws2812_set_all_led_brightness(brightness);
}
LOGE("board_set_brightness ->%d\n",brightness);
return return_value_create_string("{\"success\":true}");
}
// 设置主题工具回调
static ReturnValue set_theme_callback(const PropertyList* properties) {
Property* theme_prop = property_list_get_by_name(properties, "theme");
if (!theme_prop || property_get_type(theme_prop) != PROPERTY_TYPE_STRING) {
return return_value_create_string("{\"error\":\"Invalid theme parameter\"}");
}
const char* theme = property_get_string_value(theme_prop);
LOGE("board_set_theme ->%s\n",theme);
return return_value_create_string("{\"success\":true}");
}
// 拍照工具回调
static ReturnValue take_photo_callback(const PropertyList* properties) {
ReturnValue ret = return_value_create_string("photo_data");
return ret;
}
// OTA升级检测工具回调
static ReturnValue ota_update_device_callback(const PropertyList* properties) {
// ReturnValue ret = return_value_create_string("photo_data");
// 电量低于25 不允许执行OTA
int battery = battery_get_percent();
if (battery < 25)
{
LOGE("power low bat:%d ,don't ota !!\n", battery);
app_event_send_msg(APP_EVT_LOW_VOLTAGE, 0);
return return_value_create_string("{\"success\":false,\"error\":\"电量低,不允许升级设备\"}");
}
iot_lamp_check_ota();
return return_value_create_string("{\"success\":true}");
}
// 设备助眠仪状态回调
static ReturnValue sleep_helper_get_device_status_callback(const PropertyList* properties) {
cJSON* status = cJSON_CreateObject();
//助眠仪的状态
cJSON* sleep_helper = cJSON_CreateObject();
cJSON_AddNumberToObject(sleep_helper, "model", sleep_helper_get_mode());
cJSON_AddNumberToObject(sleep_helper, "level", sleep_helper_get_level());
cJSON_AddItemToObject(status, "sleep_helper", sleep_helper);
char *jsonString = cJSON_PrintUnformatted(status);
ReturnValue ret = return_value_create_string(jsonString);
cJSON_Delete(status);
return ret;
}
void app_mcp_init(){
McpServer* mcp_server = mcp_server_get_instance();
// 助眠仪模式
{
PropertyList* props = property_list_create();
Property* prop_mode = property_create_integer("mode", false, 0, true, 0, 3);
property_list_add_property(props, prop_mode);
mcp_server_add_tool_with_params(mcp_server, "self.sleep_helper.set_mode", "设置助眠仪的模式", props, sleep_helper_set_mode_callback);
}
// 助眠仪等级
{
PropertyList* props = property_list_create();
Property* prop_level = property_create_integer("level", false, 1, true, 1, 9);
property_list_add_property(props, prop_level);
mcp_server_add_tool_with_params(mcp_server, "self.sleep_helper.set_level", "设置助眠仪的等级", props, sleep_helper_set_level_callback);
}
//打开助眠仪
{
PropertyList* props = property_list_create();
mcp_server_add_tool_with_params(mcp_server, "self.sleep_helper.open", "打开助眠仪", props, sleep_helper_open_callback);
}
//关闭助眠仪
{
PropertyList* props = property_list_create();
mcp_server_add_tool_with_params(mcp_server, "self.sleep_helper.close", "关闭助眠仪", props, sleep_helper_close_callback);
}
// 获取助眠仪状态
{
PropertyList* props = property_list_create();
mcp_server_add_tool_with_params(mcp_server, "self.sleep_helper.get_status",
"获取助眠仪状态 (mode=0 表示已经关闭, mode=1 表示模式1, mode=2 表示模式2,mode=3 表示模式3,level (0-9)分别代表9个不同等级", props, sleep_helper_get_device_status_callback);
}
// 添加获取设备状态工具
{
PropertyList* props = property_list_create();
mcp_server_add_tool_with_params(mcp_server, "self.get_device_status", "获取软件版本,设备音量,灯光亮度,设备电池状态", props, get_device_status_callback);
}
// 添加设置音量工具
{
PropertyList* props = property_list_create();
Property* volume_prop = property_create_integer("volume", false, 0, true, 0, 100);
property_list_add_property(props, volume_prop);
//Property* vol_prop = property_create_integer("vol", false, 0, true, 0, 100);
//property_list_add_property(props, vol_prop);
mcp_server_add_tool_with_params(
mcp_server,
"self.audio_speaker.set_volume",
"Set the volume of the audio speaker. If the current volume is unknown, you must call `self.get_device_status` tool first and then call this tool.",
props, set_volume_callback);
}
// 添加设置亮度工具
{
PropertyList* props = property_list_create();
Property* brightness_prop = property_create_integer("brightness", false, 0, true, 0, 100);
property_list_add_property(props, brightness_prop);
mcp_server_add_tool_with_params(mcp_server, "self.screen.set_brightness", "Set screen brightness", props, set_brightness_callback);
}
// 添加拍照工具
//{
// PropertyList* props = property_list_create();
// mcp_server_add_tool_with_params(mcp_server, "take_photo", "Take a photo", props, take_photo_callback);
//}
// OTA
{
PropertyList* props = property_list_create();
mcp_server_add_tool_with_params(mcp_server, "self.ota.update_device", "更新拍拍灯乐小牛软件,执行该指令需要和用户二次确认才允许下发这个指令", props, ota_update_device_callback);
}
}
void app_start(){
app_mcp_init();
}

View File

@ -80,7 +80,7 @@ enum ListeningMode {
* BLE设置灯光常亮时异常问题
*/
#define APPLICATION_VERSION "1.1.6"
#define APPLICATION_VERSION "1.1.5"
#define APPLICATION_DEFULT_OTA_URL "https://xiaozhi.xa-poka.com/xiaozhi/ota/"
#define APPLICATION_CONFIG_KEY_AI_URL "ai_url"
/**
@ -95,17 +95,10 @@ enum ListeningMode {
* 10 - 10
*/
#define APPLICATION_DEFULT_SLEEP_TIMEOUT 10
/**
* 使MCP协议
*/
#define APPLICATION_IOT_PROTOCOL_MCP 1
#define APPLICATION_DEVICE_BOARD_NAME "Poka"
void app_set_ota_url(char * ota_url);
char* app_get_ota_url();
void app_start();
#ifdef __cplusplus
}
#endif

View File

@ -52,7 +52,7 @@
#define BAT_DETEC_ADC_STEADY_CTRL 7
#define BAT_DETEC_ADC_SAMPLE_RATE 0
#define BATTERY_MAX_VOLTAGE 4100
#define BATTERY_MAX_VOLTAGE 4200
#define BATTERY_MIN_VOLTAGE 3400
static int batt_percent = 0;

View File

@ -1,16 +1,3 @@
/*************************************************************
*
* Copyright (C) POKA
* All rights reserved.
*
*************************************************************/
#ifndef __BATTERY_H__
#define __BATTERY_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef enum{
EVT_BATTERY_MAIN_CHARGING = 0,
EVT_BATTERY_MAIN_LOW_VOLTAGE,
@ -27,10 +14,4 @@ void poweroff_voice();
/**
*
*/
int battery_get_percent();
#ifdef __cplusplus
}
#endif
#endif /* __BATTERY_H__ */
int battery_get_percent();

View File

@ -14,7 +14,6 @@
#endif
#include "bk_genie_comm.h"
#include "thing.h"
#include "application.h"
#define TAG "beken_rtc"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
@ -811,39 +810,68 @@ int rtc_websocket_send_text(transport web_socket, void *str, enum MsgType msgtyp
case BEKEN_RTC_SEND_ABORT:{
cJSON *abortMessage = cJSON_CreateObject();
if (abortMessage == NULL) {
}
cJSON_AddStringToObject(abortMessage, "type", "abort") ;
cJSON_AddStringToObject(abortMessage, "reason", "user_interrupted") ;
char *jsonString = cJSON_PrintUnformatted(abortMessage);
char *jsonString = cJSON_Print(abortMessage);
websocket_client_send_text(web_socket, jsonString, strlen(jsonString), 10*1000);
cJSON_Delete(abortMessage);
break;
}
case BEKEN_RTC_SEND_LISTEN:{
cJSON *listenMessage = cJSON_CreateObject();
cJSON_AddStringToObject(listenMessage, "session_id", "");
cJSON_AddStringToObject(listenMessage, "type", "listen");
cJSON_AddStringToObject(listenMessage, "state", "detect");
cJSON_AddStringToObject(listenMessage, "mode", "auto");
cJSON_AddStringToObject(listenMessage, "text", "");
char *jsonString = cJSON_PrintUnformatted(listenMessage);
BK_LOGE("WebSocket", "Sending: %s\r\n", jsonString);
websocket_client_send_text(web_socket, jsonString, strlen(jsonString), 10*1000);
cJSON_Delete(listenMessage);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> JSON <20><><EFBFBD><EFBFBD>
cJSON *listenMessage = cJSON_CreateObject();
if (listenMessage == NULL) {
}
cJSON_AddStringToObject(listenMessage, "session_id", "");
cJSON_AddStringToObject(listenMessage, "type", "listen");
cJSON_AddStringToObject(listenMessage, "state", "detect");
cJSON_AddStringToObject(listenMessage, "mode", "auto");
cJSON_AddStringToObject(listenMessage, "text", "С<EFBFBD><EFBFBD>ͬѧ");
// <20><> cJSON <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
char *jsonString = cJSON_Print(listenMessage);
BK_LOGE("WebSocket", "Sending: %s\r\n", jsonString);
websocket_client_send_text(web_socket, jsonString, strlen(jsonString), 10*1000);
// ɾ<><C9BE> cJSON <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
cJSON_Delete(listenMessage);
break;
}
case BEKEN_RTC_SEND_START_LISTEN:{
cJSON *startlistent = cJSON_CreateObject();
extern char *getGlobalSessionId(void);
cJSON_AddStringToObject(startlistent, "session_id", getGlobalSessionId());
// char *session_id = getGlobalSessionId();
// bk_printf("Global session_id_BEKEN_RTC_SEND_START_LISTEN: %s\n", session_id);
// <20><><EFBFBD><EFBFBD>session_id<69>ֶ<EFBFBD>
cJSON_AddStringToObject(startlistent, "session_id", "");
// <20><><EFBFBD><EFBFBD>type<70>ֶ<EFBFBD>
cJSON_AddStringToObject(startlistent, "type", "listen");
// <20><><EFBFBD><EFBFBD>state<74>ֶ<EFBFBD>
cJSON_AddStringToObject(startlistent, "state", "start");
// <20><><EFBFBD><EFBFBD>mode<64>ֶ<EFBFBD>
cJSON_AddStringToObject(startlistent, "mode", "auto") ;
char *jsonString = cJSON_PrintUnformatted(startlistent);
// <20><><EFBFBD><EFBFBD>JSON<4F>ַ<EFBFBD><D6B7><EFBFBD>
char *jsonString = cJSON_Print(startlistent);
websocket_client_send_text(web_socket, jsonString, strlen(jsonString), 10*1000);
cJSON_Delete(startlistent);
break;
@ -851,15 +879,29 @@ int rtc_websocket_send_text(transport web_socket, void *str, enum MsgType msgtyp
case BEKEN_RTC_SEND_STOP_LISTEN:{
cJSON *stoplistent = cJSON_CreateObject();
extern char *getGlobalSessionId(void);
cJSON_AddStringToObject(stoplistent, "session_id", getGlobalSessionId());
cJSON_AddStringToObject(stoplistent, "type", "listen");
cJSON_AddStringToObject(stoplistent, "state", "stop");
cJSON_AddStringToObject(stoplistent, "mode", "auto");
char *jsonString = cJSON_PrintUnformatted(stoplistent);
websocket_client_send_text(web_socket, jsonString, strlen(jsonString), 10 * 1000);
cJSON_Delete(stoplistent);
cJSON *stoplistent = cJSON_CreateObject();
// char *session_id = getGlobalSessionId();
// bk_printf("Global session_id_BEKEN_RTC_SEND_STOP_LISTEN: %s\n", session_id);
// <20><><EFBFBD><EFBFBD>session_id<69>ֶ<EFBFBD>
cJSON_AddStringToObject(stoplistent, "session_id", "");
// <20><><EFBFBD><EFBFBD>type<70>ֶ<EFBFBD>
cJSON_AddStringToObject(stoplistent, "type", "listen");
// <20><><EFBFBD><EFBFBD>state<74>ֶ<EFBFBD>
cJSON_AddStringToObject(stoplistent, "state", "stop");
// <20><><EFBFBD><EFBFBD>mode<64>ֶ<EFBFBD>
cJSON_AddStringToObject(stoplistent, "mode", "auto") ;
// <20><><EFBFBD><EFBFBD>JSON<4F>ַ<EFBFBD><D6B7><EFBFBD>
char *jsonString = cJSON_Print(stoplistent);
websocket_client_send_text(web_socket, jsonString, strlen(jsonString), 10*1000);
cJSON_Delete(stoplistent);
break;
}
@ -892,7 +934,7 @@ int rtc_websocket_send_text(transport web_socket, void *str, enum MsgType msgtyp
cJSON_AddItemToObject(startMessage, "audio_params", audio_params);
// <20><> cJSON <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
char *jsonString = cJSON_PrintUnformatted(startMessage);
char *jsonString = cJSON_Print(startMessage);
BK_LOGI("WebSocket", "Sending: %s\r\n", jsonString);
websocket_client_send_text(web_socket, jsonString, strlen(jsonString), 10*1000);
// ɾ<><C9BE> cJSON <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
@ -900,32 +942,53 @@ int rtc_websocket_send_text(transport web_socket, void *str, enum MsgType msgtyp
break;}
case BEKEN_RTC_SEND_HELLO:{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> JSON <20><><EFBFBD><EFBFBD>
cJSON *helloMessage = cJSON_CreateObject();
if (helloMessage == NULL) {
//return NULL;
}
// <20><><EFBFBD><EFBFBD> "type" <20>ֶ<EFBFBD>
cJSON_AddStringToObject(helloMessage, "type", "hello");
// <20><><EFBFBD><EFBFBD> "version" <20>ֶ<EFBFBD>
cJSON_AddNumberToObject(helloMessage, "version", 3);
// <20><><EFBFBD><EFBFBD> "transport" <20>ֶ<EFBFBD>
cJSON_AddStringToObject(helloMessage, "transport", "websocket");
#if APPLICATION_IOT_PROTOCOL_MCP
cJSON* features = cJSON_CreateObject();
cJSON_AddBoolToObject(features, "mcp", true);
cJSON_AddItemToObject(helloMessage, "features", features);
#endif
// <20><><EFBFBD><EFBFBD> "audio_params" JSON <20><><EFBFBD><EFBFBD>
cJSON *audio_params = cJSON_CreateObject();
if (audio_params == NULL) {
cJSON_Delete(helloMessage);
//return NULL;
}
// <20><> "audio_params" <20><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
cJSON_AddStringToObject(audio_params, "format", "opus");
cJSON_AddNumberToObject(audio_params, "sample_rate", 16000);
cJSON_AddNumberToObject(audio_params, "channels", 1);
cJSON_AddNumberToObject(audio_params, "frame_duration", 60);
// <20><> "audio_params" <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD> JSON <20><><EFBFBD><EFBFBD>
cJSON_AddItemToObject(helloMessage, "audio_params", audio_params);
char *jsonString = cJSON_PrintUnformatted(helloMessage);
BK_LOGE("WebSocket", "Sending: %s\r\n", jsonString);
// <20><> cJSON <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
char *jsonString = cJSON_Print(helloMessage);
BK_LOGI("WebSocket", "Sending: %s\r\n", jsonString);
websocket_client_send_text(web_socket, jsonString, strlen(jsonString), 10*1000);
cJSON_Delete(helloMessage);
// ɾ<><C9BE> cJSON <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
cJSON_Delete(helloMessage);
/*
n = snprintf(buf, BEKEN_RTC_TXT_SIZE,
"{\"type\":\"hello\",\"config\":{\"version\": 2,\"audio\":{\"to_server\":{\"format\":\"%s\", \"sample_rate\":%d, \"channels\":1, \"frame_duration\":%d}, \"from_server\":{\"format\":\"%s\", \"sample_rate\":%d, \"channels\":1, \"frame_duration\":%d}}}}",
((audio_info_t *)str)->encoding_type, ((audio_info_t *)str)->adc_samp_rate, ((audio_info_t *)str)->enc_samp_interval,
((audio_info_t *)str)->encoding_type, ((audio_info_t *)str)->dac_samp_rate, ((audio_info_t *)str)->dec_samp_interval);
BK_LOGE("WebSocket", "Sending: %s\r\n", buf);
websocket_client_send_text(web_socket, buf, n, 10*1000);*/
break;}
case BEKEN_RTC_SEND_IOT_DESC:{
extern char *getGlobalSessionId(void);

View File

@ -323,7 +323,7 @@ void iot_lamp_parser_invoke(char* cmd,char * paramters_json){
//ws2812_set_all_led(0xFFFFFF,brightness);
ws2812_set_all_led_brightness(brightness);
}
//thing_report_iot_state_number(IOT_LAMP_DEVICE_NAME,IOT_LAMP_DEVICE_PARAM_BRIGHTNESS,brightness);
thing_report_iot_state_number(IOT_LAMP_DEVICE_NAME,IOT_LAMP_DEVICE_PARAM_BRIGHTNESS,brightness);
cJSON_Delete(params);
}
else if (strcmp(cmd, IOT_LAMP_DEVICE_OTA) == 0){

View File

@ -272,7 +272,7 @@ void sleep_helper_set_mode(sleep_mode mode){
sleep_msg_t msg;
msg.mode = mode;
rtos_push_to_queue(&sleep_helper_msg_que, &msg, BEKEN_NO_WAIT);
//thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,mode);
thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,mode);
}
}
@ -339,11 +339,11 @@ void sleep_helper_set_level(sleep_model_level level){
LOGE("sleep_helper period_cycle s %d duty_cycle %d\n",config.period_cycle,config.duty_cycle);
bk_pwm_set_init_signal_low(pwm_chan);
bk_pwm_set_period_duty(pwm_chan,&config);
//thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_LEVEL,level);
thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_LEVEL,level);
}
}
int sleep_helper_open(){
void sleep_helper_open(){
if(current_mode != SLEEP_MODE_OFF){
sleep_helper_close();
}
@ -360,7 +360,7 @@ int sleep_helper_open(){
socket_insert = insert_value;
if(socket_insert == 1){
LOGE("sleep_helper open fail!! cable not insert %d \n",insert_value);
return -1;
return ;
}
pwm_init_config_t config = {0};
@ -375,8 +375,7 @@ int sleep_helper_open(){
//默认模式1
sleep_helper_set_mode(SLEEP_MODE_1);
sleep_helper_start_timer();
//thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,SLEEP_MODE_1);
return 0;
thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,SLEEP_MODE_1);
}
void sleep_helper_close(){
@ -390,7 +389,7 @@ void sleep_helper_close(){
bk_gpio_set_output_low(GPIO_44);
bk_gpio_set_output_low(GPIO_45);
//thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,0);
thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,0);
}
cJSON* iot_sleep_helper_get_device_desc()

View File

@ -65,7 +65,7 @@ typedef struct
void sleep_helper_init();
int sleep_helper_open();
void sleep_helper_open();
void sleep_helper_close();
void sleep_helper_set_mode(sleep_mode mode);
void sleep_helper_set_timeout(int timeout);

View File

@ -209,7 +209,7 @@ void speaker_set_volume(int volume)
int level = volume / 10;
LOGE("speaker_setVolume--> volume :%d level:%d\n", volume, level);
speaker_volume_set_abs(level, 0);
//thing_report_iot_state_number(IOT_SPEAKER_DEVICE_NAME, IOT_SPEAKER_DEVICE_PARAM_VOL, volume);
thing_report_iot_state_number(IOT_SPEAKER_DEVICE_NAME, IOT_SPEAKER_DEVICE_PARAM_VOL, volume);
}
}
void iot_speaker_parser_invoke(char* cmd,char * paramters_json){

File diff suppressed because it is too large Load Diff

View File

@ -1,137 +0,0 @@
#ifndef MCP_SERVER_C_H
#define MCP_SERVER_C_H
#include <stdbool.h>
#include <stdint.h>
#include "cJSON.h"
#ifdef __cplusplus
extern "C" {
#endif
// 属性类型枚举
typedef enum {
PROPERTY_TYPE_BOOLEAN,
PROPERTY_TYPE_INTEGER,
PROPERTY_TYPE_STRING
} PropertyType;
// 返回值类型枚举
typedef enum {
RETURN_TYPE_BOOLEAN,
RETURN_TYPE_INTEGER,
RETURN_TYPE_STRING
} ReturnType;
// 返回值联合体
typedef struct {
ReturnType type;
union {
bool boolean_value;
int integer_value;
char* string_value;
} value;
} ReturnValue;
// 属性结构体
typedef struct {
char* name;
char* description;
PropertyType type;
bool has_default_value;
union {
bool boolean_value;
int integer_value;
char* string_value;
} value;
bool has_range;
int min_value;
int max_value;
} Property;
// 属性列表结构体
typedef struct {
Property* properties;
int count;
int capacity;
} PropertyList;
// MCP工具回调函数类型
typedef ReturnValue (*McpToolCallback)(const PropertyList* properties);
// MCP工具结构体
typedef struct {
char* name;
char* description;
PropertyList properties;
McpToolCallback callback;
} McpTool;
// MCP服务器结构体
typedef struct {
McpTool** tools;
int tool_count;
int tool_capacity;
} McpServer;
// 全局单例
extern McpServer* g_mcp_server;
// 属性函数
Property* property_create_boolean(const char* name, bool has_default, bool default_value);
Property* property_create_integer(const char* name, bool has_default, int default_value, bool has_range, int min_value, int max_value);
Property* property_create_string(const char* name, bool has_default, const char* default_value);
void property_destroy(Property* property);
const char* property_get_name(const Property* property);
PropertyType property_get_type(const Property* property);
bool property_has_default_value(const Property* property);
bool property_has_range(const Property* property);
int property_get_min_value(const Property* property);
int property_get_max_value(const Property* property);
bool property_get_boolean_value(const Property* property);
int property_get_integer_value(const Property* property);
const char* property_get_string_value(const Property* property);
void property_set_boolean_value(Property* property, bool value);
void property_set_integer_value(Property* property, int value);
void property_set_string_value(Property* property, const char* value);
char* property_to_json(const Property* property);
// 属性列表函数
PropertyList* property_list_create(void);
PropertyList* property_list_create_with_capacity(int capacity);
void property_list_destroy(PropertyList* list);
void property_list_add_property(PropertyList* list, Property* property);
Property* property_list_get_by_name(const PropertyList* list, const char* name);
char** property_list_get_required(const PropertyList* list, int* count);
char* property_list_to_json(const PropertyList* list);
// 返回值函数
ReturnValue return_value_create_boolean(bool value);
ReturnValue return_value_create_integer(int value);
ReturnValue return_value_create_string(const char* value);
void return_value_destroy(ReturnValue* value);
// MCP工具函数
McpTool* mcp_tool_create(const char* name, const char* description, PropertyList* properties, McpToolCallback callback);
void mcp_tool_destroy(McpTool* tool);
const char* mcp_tool_get_name(const McpTool* tool);
const char* mcp_tool_get_description(const McpTool* tool);
const PropertyList* mcp_tool_get_properties(const McpTool* tool);
char* mcp_tool_to_json(const McpTool* tool);
char* mcp_tool_call(const McpTool* tool, const PropertyList* properties);
// MCP服务器函数
McpServer* mcp_server_create(void);
void mcp_server_destroy(McpServer* server);
McpServer* mcp_server_get_instance(void);
void mcp_server_add_common_tools(McpServer* server);
void mcp_server_add_tool(McpServer* server, McpTool* tool);
void mcp_server_add_tool_with_params(McpServer* server, const char* name, const char* description, PropertyList* properties, McpToolCallback callback);
void mcp_server_parse_message(McpServer* server, const char* message);
void mcp_server_parse_message_json(McpServer* server, const cJSON* json);
#ifdef __cplusplus
}
#endif
#endif // MCP_SERVER_C_H

View File

@ -35,8 +35,6 @@
#include "thing.h"
#include "iot_ota.h"
#include "iot_lamp.h"
#include "application.h"
#include "mcp/mcp_server.h"
#define TAG "WS_MAIN"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
@ -527,7 +525,7 @@ void rtc_websocket_msg_handle(char *json_text, unsigned int size)
LOGE("Error: Failed to parse JSON text:%s\n", json_text);
return;
}
//bk_printf("TEXT: %s \n",cJSON_PrintUnformatted(root));
// bk_printf("rtc_websocket_msg_handle json_text : %s \n",json_text);
cJSON *type = cJSON_GetObjectItem(root, "type");
if (type == NULL)
{
@ -568,42 +566,6 @@ void rtc_websocket_msg_handle(char *json_text, unsigned int size)
{
thing_iot_invoke(json_text);
}
else if (strcmp(type->valuestring, "llm") == 0)
{
cJSON *emotion = cJSON_GetObjectItem(root, "emotion");
if(emotion != NULL){
LOGE("emotion--> %s\n",emotion->valuestring);
}
}
else if (strcmp(type->valuestring, "stt") == 0)
{
cJSON *text = cJSON_GetObjectItem(root, "text");
if(text != NULL){
LOGE(">> %s\n",text->valuestring);
}
}
else if (strcmp(type->valuestring, "tts") == 0)
{
cJSON *state = cJSON_GetObjectItem(root, "state");
cJSON *text = cJSON_GetObjectItem(root, "text");
if(state != NULL && text != NULL){
LOGE("<< (%s) %s\n",state->valuestring,text->valuestring);
}
}
#if APPLICATION_IOT_PROTOCOL_MCP
else if (strcmp(type->valuestring, "mcp") == 0) {
cJSON * payload = cJSON_GetObjectItem(root, "payload");
if (cJSON_IsObject(payload)) {
//LOGE("MCP: %s\n", cJSON_PrintUnformatted(payload));
McpServer* mcp_server = mcp_server_get_instance();
mcp_server_parse_message_json(mcp_server, payload);
//McpServer::GetInstance().ParseMessage(payload);
}
}
#endif
// else if ((strcmp(type->valuestring, "reply_text") == 0) || (strcmp(type->valuestring, "request_text") == 0)) {
// text_info_t info = {0};
@ -728,7 +690,7 @@ void sent_abort_msg()
//bk_printf("rtc_websocket_send_text_BEKEN_RTC_SEND_ABORT_BEKEN_RTC_SEND_STOP_LISTEN_BEKEN_RTC_SEND_START_LISTEN\r\n");
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_ABORT);
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);
// rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_STOP_LISTEN);
@ -807,14 +769,12 @@ void rtc_websocket_event_handler(void *event_handler_arg, char *event_base, int3
LOGE("Connected to WebSocket server\r\n");
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_HELLO);
rtos_delay_milliseconds(100);
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_START_LISTEN);
//2025.07.07
//rtos_delay_milliseconds(100);
//rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_IOT_DESC);
//rtos_delay_milliseconds(20);
//thing_report_device_state();
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_START);
rtos_delay_milliseconds(100);
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_IOT_DESC);
rtos_delay_milliseconds(20);
thing_report_device_state();
// rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_START_LISTEN);
// rtos_delay_milliseconds(200);
@ -827,7 +787,7 @@ void rtc_websocket_event_handler(void *event_handler_arg, char *event_base, int3
__get_beken_rtc()->disconnecting_state++;
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
@ -1059,7 +1019,6 @@ void beken_auto_run(void)
}
*/
//bk_https_ota_download("https://xiaozhi.xa-poka.com/xiaozhi/otaMag/download/59cc091e-eaf3-417d-a524-d5e3d95883f4");
beken_rtc_start();
}
}