Skip to content

Commit

Permalink
Merge branch 'feature/dueros_handler' into 'master'
Browse files Browse the repository at this point in the history
DuerOS: Overwrite dueros response handler and update the userAgent in profile

See merge request adf/esp-adf-internal!1350
  • Loading branch information
jason-mao committed Dec 19, 2024
2 parents c855d6a + ef98618 commit cbf80d8
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 16 deletions.
Binary file modified components/clouds/dueros/lightduer/esp32/libduer-device-v5x.a
Binary file not shown.
Binary file modified components/clouds/dueros/lightduer/esp32p4/libduer-device-v5x.a
Binary file not shown.
Binary file modified components/clouds/dueros/lightduer/esp32s3/libduer-device-v5x.a
Binary file not shown.
20 changes: 20 additions & 0 deletions components/clouds/dueros/lightduer/include/lightduer_dcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ void duer_dcs_listen_handler(void);
*/
void duer_dcs_stop_listen_handler(void);

/**
* DESC:
* Developer needs to implement this interface to set voice id.
*
* PARAM[in] voice_id: the id of voice
*
* @RETURN: none.
*/
void duer_dcs_set_voice_handler(int voice_id);

/**
* DESC:
* Developer needs to implement this interface to get voice id.
*
* PARAM: none
*
* @RETURN: voice id.
*/
int duer_dcs_get_voice_id(void);

/**
* DESC:
* Initialize dcs voice output interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ extern const char *DCS_RENDER_AUDIO_LIST;
extern const char *DCS_RENDER_ALBUM_LIST;
extern const char *DCS_SET_ACTIVE_DIALOG;
extern const char *DCS_REQUIRE_PUSH_ACK;
extern const char *DCS_SET_VOICE_NAME;

// internal directive.
extern const char *DCS_DIALOGUE_FINISHED_NAME;
Expand All @@ -191,6 +192,7 @@ extern const char *DCS_SPEECH_STATE_NAME;
extern const char *DCS_LINK_CLICKED_NAME;
extern const char *DCS_RECOMMEND_NAME;
extern const char *DCS_PUSH_ACK_NAME;
extern const char *DCS_VOICE_CHANGED_NAME;

// internal exception type
extern const char *DCS_UNEXPECTED_INFORMATION_RECEIVED_TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef struct {
} duer_ap_t;

typedef struct {
int (*ble_send_data)(uint8_t *data, size_t data_len, uint16_t handle);
int (*ble_send_data)(uint8_t *data, uint32_t data_len, uint16_t handle);

duer_ap_t* (*scan_wifi)(int *list_num);

Expand Down
23 changes: 22 additions & 1 deletion components/dueros_service/duer_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>

#include "duer_profile.h"
#include "audio_error.h"
Expand All @@ -30,7 +31,7 @@
#include "esp_log.h"
#include "nvs.h"

#define DUER_USER_AGENT_VER ("app/3.0.0.1 DcsSdk/3.0")
#define DUER_USER_AGENT_VER ("app/3.0.0.1 DcsSdk/3.3 didp/1 version/1")

static char *TAG = "DUER_PROFILE";

Expand Down Expand Up @@ -150,3 +151,23 @@ int32_t duer_profile_certified()
duer_profile_release(profile);
return ret;
}

int32_t duer_profile_get_uuid(char *buf, size_t blen)
{
const char *profile = duer_profile_load();
AUDIO_NULL_CHECK(TAG, profile, return 1);

baidu_json *root = baidu_json_Parse(profile);
AUDIO_NULL_CHECK(TAG, root, return 2);

int32_t ret = 3;
baidu_json *uuid = baidu_json_GetObjectItem(root, "uuid");
if (uuid) {
ret = 0;
snprintf(buf, blen, "%s", uuid->valuestring);
ESP_LOGI(TAG, "got uuid form profile: %s", buf);
}
baidu_json_Delete(root);
duer_profile_release(profile);
return ret;
}
8 changes: 7 additions & 1 deletion components/dueros_service/duer_wifi_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@

#include "duer_wifi_cfg.h"
#include "duer_wifi_cfg_if.h"
#include "duer_profile.h"
#include "lightduer_dipb_data_handler.h"
#include "lightduer_types.h"

#define DUER_DEV_ID_LEN (32)

static duer_wifi_cfg_t *duer_wifi_cfg;
static char duer_device_id[DUER_DEV_ID_LEN];
static const char *TAG = "DUER_WIFI_CFG";

static void duer_on_ble_recv_data(void *data, size_t len, uint16_t handle)
Expand Down Expand Up @@ -107,7 +111,7 @@ static const char *get_profile_value(int key)
case PROFILE_KEY_CLIENT_ID:
return duer_wifi_cfg->client_id;
case PROFILE_KEY_DEVICE_ID:
return duer_wifi_cfg->device_id;
return duer_device_id;
case PROFILE_KEY_DEVICE_ECC_PUB_KEY:
return duer_wifi_cfg->pub_key;
default:
Expand Down Expand Up @@ -143,6 +147,7 @@ int duer_wifi_cfg_init(duer_wifi_cfg_t *cfg)
AUDIO_NULL_CHECK(TAG, duer_wifi_cfg, return ESP_ERR_NO_MEM);
memcpy(duer_wifi_cfg, cfg, sizeof(duer_wifi_cfg_t));

ESP_ERROR_CHECK(duer_profile_get_uuid(duer_device_id, DUER_DEV_ID_LEN - 1));
ESP_ERROR_CHECK(duer_wifi_cfg_ble_host_init(&host_cb));
ESP_ERROR_CHECK(duer_dipb_data_handler_init(&dipb_cbs));

Expand All @@ -159,5 +164,6 @@ int duer_wifi_cfg_deinit(void)
ESP_ERROR_CHECK(duer_dipb_data_handler_deinit());
audio_free(duer_wifi_cfg);
duer_wifi_cfg = NULL;
memset(duer_device_id, 0x00, DUER_DEV_ID_LEN);
return 0;
}
11 changes: 11 additions & 0 deletions components/dueros_service/include/duer_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ esp_err_t duer_profile_update(const char *bduss, const char *client_id);
*/
int32_t duer_profile_certified();

/**
* @brief Get the 'uuid' of the profile
*
* @return
* - (0), OK
* - (1), Profile load failed
* - (2), Profile parse failed
* - (3), Profile has no 'uuid'
*/
int32_t duer_profile_get_uuid(char *buf, size_t blen);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 0 additions & 1 deletion components/dueros_service/include/duer_wifi_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ typedef void (*duer_wifi_cfg_user_cb_t)(duer_wifi_cfg_event_t event, void *data)
typedef struct {
duer_wifi_cfg_user_cb_t user_cb; /*!< User callback */
const char *client_id; /*!< Duer client id */
const char *device_id; /*!< Duer device id */
const char *pub_key; /*!< Duer public key */
} duer_wifi_cfg_t;

Expand Down
7 changes: 3 additions & 4 deletions examples/dueros/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
set(COMPONENT_SRCS "duer_audio_wrapper.c" "dueros_app.c" "app_main.c")
set(COMPONENT_ADD_INCLUDEDIRS .)

register_component()
idf_component_register(SRCS "duer_audio_wrapper.c" "dueros_app.c" "dueros_handler.c" "app_main.c"
INCLUDE_DIRS "."
WHOLE_ARCHIVE)

spiffs_create_partition_image(spiffs_data ../spiffs FLASH_IN_PROJECT)
7 changes: 0 additions & 7 deletions examples/dueros/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ config DUER_CLIENT_ID
help
The duer client id.

config DUER_DEVICE_ID
string "Duer device ID"
depends on DUER_WIFI_CONFIG
default "device id"
help
The duer device id.

config DUER_ECC_PUB_KEY
string "Duer ECC public key"
depends on DUER_WIFI_CONFIG
Expand Down
1 change: 0 additions & 1 deletion examples/dueros/main/dueros_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ static esp_err_t wifi_cfg_start()
duer_wifi_cfg_t duer_wifi = {
.user_cb = duer_wifi_cfg_user_cb,
.client_id = CONFIG_DUER_CLIENT_ID,
.device_id = CONFIG_DUER_DEVICE_ID,
.pub_key = CONFIG_DUER_ECC_PUB_KEY,
};
return dueros_start_wifi_cfg(duer_serv_handle, &duer_wifi);
Expand Down
96 changes: 96 additions & 0 deletions examples/dueros/main/dueros_handler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/task.h"

#include "esp_audio_device_info.h"
#include "lightduer_connagent.h"
#include "lightduer_dcs.h"
#include "lightduer_dipb_data_handler.h"
#include "lightduer_dlp.h"
#include "lightduer_ota_notifier.h"
#include "lightduer_voice.h"

#include "esp_log.h"

const static char *TAG = "duer_handler";
static int32_t cur_voice_id = 0;

duer_status_t duer_dcs_input_text_handler(const char *text, const char *type)
{
ESP_LOGW(TAG, "duer_dcs_input_text_handler: %s: %s", type, text);
return DUER_OK;
}

duer_status_t duer_dcs_render_card_handler(baidu_json *payload)
{
baidu_json *type = NULL;
baidu_json *content = NULL;
duer_status_t ret = DUER_OK;

do {
if (!payload) {
ret = DUER_ERR_FAILED;
break;
}

type = baidu_json_GetObjectItem(payload, "type");
if (!type) {
ret = DUER_ERR_FAILED;
break;
}

if (strcmp("TextCard", type->valuestring) == 0) {
content = baidu_json_GetObjectItem(payload, "content");
if (!content) {
ret = DUER_ERR_FAILED;
break;
}
ESP_LOGW(TAG, "Render card content: %s", content->valuestring);
}
} while (0);

return ret;
}

duer_status_t duer_dcs_render_stream_card_handler(const duer_dcs_render_stream_card_t *stream_card_payload)
{
duer_status_t ret = DUER_OK;

do {
if (!stream_card_payload) {
ret = DUER_ERR_FAILED;
break;
}
if (stream_card_payload->answer) {
ESP_LOGW(TAG, "Render stream card answer: %s\n", stream_card_payload->answer);
}
ESP_LOGW(TAG, "Render stream card index: %d\n", stream_card_payload->index);
if (stream_card_payload->part) {
ESP_LOGW(TAG, "Render stream card part: %s\n", stream_card_payload->part);
}
if (stream_card_payload->tts) {
ESP_LOGW(TAG, "Render stream card tts: %s\n", stream_card_payload->tts);
}
ESP_LOGW(TAG, "Render stream card end: %d\n", stream_card_payload->is_end);
} while (0);

return ret;
}

void duer_dcs_set_voice_handler(int voice_id)
{
ESP_LOGI(TAG, "set voice id to [%d]", voice_id);
cur_voice_id = voice_id;
// TODO: Save the configuration and load when init
}

int duer_dcs_get_voice_id(void)
{
return cur_voice_id;
}

0 comments on commit cbf80d8

Please sign in to comment.