avs-device-sdk/docs/AVS SDK Porting Document(1....

6.7 KiB
Raw Blame History

AVS SDK DEV

base on AVS SDK 1.2.6.0

1. 说明

基于 AVS SDK 的修改说明

2. 开发内容

2.1. 通信模块

引入通信模块 transport

2.1.1. 源码相关改动

  • SampleApp/CMakeLists.txt
add_subdirectory("Authorization")
+add_subdirectory("transport")
  • SampleApp/src 以及 include/SampleApp 下面几个文件 详情参见git diff

2.1.2. transport 模块

具体参见源码SampleApp/transport

2.2. 添加与config_app交互以及对应的业务逻辑执行代码

具体代码参见UserInputManager.cpp部分代码如下

#define CMD_KEY "cmd"
#define CMD_VAL_BUTTON "button"
#define CMD_VAL_NET "net"
#define CMD_VAL_FACTORYRESET "factoryreset"
#define CMD_VAL_SET_LIGHTING "set_lighting"
#define CMD_VAL_SET_SPEAKER_VOL "set_speaker_volume"
#define CMD_VAL_SET_ALERT_VOL "set_alert_volume"
#define CMD_VAL_SET_UX_LEN "set_ux_led"
#define CMD_DATA_KEY "data"
#define CMD_DATA_VALUE_KEY "value"

void UserInputManager::OnCfgMessage(std::shared_ptr<alexaClientSDK::buffer::Buffer> buffer) {
}

2.3. 添加音量设置接口

接口形式如下,详细内容参见源码

// InteractionManager.h/cpp
void InteractionManager::setVolume(avsCommon::sdkInterfaces::ChannelVolumeInterface::Type type, int8_t volume) {
}

2.4. 添加认证接口给LWA

参见源码 AuthInputManager.h

2.5. 添加UI执行模块

引入灯效与音效处理 ui

2.5.1. 源码相关改动

  • SampleApp/CMakeLists.txt
add_subdirectory("transport")
+add_subdirectory("ui")

2.5.2. 代码

参见 SampleApp/ui 部分代码

2.6. 导入音效文件

参见 Resources/Audio/include/Audio/Data 目录下面文件

2.7. DSN 处理

DSN使用MAC地址参见文件: srcs/AVSCommon/Utils/src/DeviceInfo.cpp 部分代码如下:

const std::string DEFAULT_DSN = "avs_def_dsn";
const std::string DEFAULT_IF = "wlan0";

static std::string GetAvaliableMac() {
}

2.8. 导入灯效驱动文件

2.8.1. 导入driver到内核

详情参见文件 <<"led drivers && hal.pdf">>

2.8.2. 导入hal文件以及解决编译问题

详情参见文件 <<"led drivers && hal.pdf">> 以及 ledhal模块

2.9. 唤醒词切换

2.9.1. 相关源码文件修改

  • srcs/extension/avs-cpp-sdk/KWD/AmazonLite/src/PryonLiteKeywordDetector.cpp
  • srcs/extension/avs-cpp-sdk/KWD/AmazonLite/include/AmazonLite/PryonLiteKeywordDetector.h
  • srcs/extension/avs-cpp-sdk/KWD/KWDProvider/src/PryonLiteRegistration.cpp
  • srcs/SampleApp/include/SampleApp/InteractionManager.h
  • srcs/SampleApp/include/SampleApp/SampleApplication.h
  • srcs/SampleApp/src/InteractionManager.cpp
  • srcs/SampleApp/src/SampleApplication.cpp
  • srcs/shared/KWD/acsdkKWDProvider/src/KeywordDetectorProvider.cpp
  • srcs/shared/KWD/acsdkKWDProvider/include/acsdkKWDProvider/KWDProvider/KeywordDetectorProvider.h

2.9.2. 新增

添加 管理类 KDWModelSel部分代码如下:


class KDWModelSel {
public:
    KDWModelSel() {
#ifdef KWD
        model_map_["ja-JP"] = "X.ja-JP.alexa.bin";
        model_map_["en-US"] = "X.en-CA+en-US.alexa.bin";
#endif
    }

    std::unique_ptr<alexaClientSDK::acsdkKWDImplementations::AbstractKeywordDetector> UpdateModel(
        const std::string& local) {
#ifdef KWD
        ACSDK_INFO(alexaClientSDK::avsCommon::utils::logger::LogEntry("KDWModelSel", "UpdateModel").d("local", local));
        return alexaClientSDK::kwd::KeywordDetectorProvider::updateKWDModel(suffix_ + model_map_[local]);
#endif
        return nullptr;
    }

private:
    const std::string suffix_ = "/data/avs/wakeword-models/x1f8/";

    std::unordered_map<std::string, std::string> model_map_;
};

2.10. 添加 onNotificationReceived 接口

添加Notification接口以及相关的业务功能

void onNotificationReceived() override;

2.11. 添加数据库模块

参见源码: db_wrapper.h/cpp

2.12. 程序启动音量处理

部分代码

std::string vol_str;
    bool ret = db_wrapper_->Load(::avs::db::USER_DB_KEY_SPEAKER_VOL, vol_str);
    if (ret) {
        m_interactionManager->setVolume(ChannelVolumeInterface::Type::AVS_SPEAKER_VOLUME, std::atoi(vol_str.c_str()));
    } else {
        // database has val,use config file
        int vol_int;
        alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getRoot()[SPEAKER_MANAGER_CAPABILITY_AGENT]
            .getInt("defaultSpeakerVolume", &vol_int, 80);
        m_interactionManager->setVolume(ChannelVolumeInterface::Type::AVS_SPEAKER_VOLUME, vol_int);
    }

    ret = db_wrapper_->Load(::avs::db::USER_DB_KEY_ALERT_VOL, vol_str);
    if (ret) {
        m_interactionManager->setVolume(ChannelVolumeInterface::Type::AVS_ALERTS_VOLUME, std::atoi(vol_str.c_str()));
    } else {
        // database has val,use config file
        int vol_int;
        alexaClientSDK::avsCommon::utils::configuration::ConfigurationNode::getRoot()[SPEAKER_MANAGER_CAPABILITY_AGENT]
            .getInt("defaultAlertsVolume", &vol_int, 80);
        m_interactionManager->setVolume(ChannelVolumeInterface::Type::AVS_ALERTS_VOLUME, vol_int);
    }

2.13. DND状态存入数据库与开机加载

auto dnd = m_client->getSettingsManager()->getValue<settings::DO_NOT_DISTURB>();
    ACSDK_INFO(LX("DNS").d("enable", dnd.second));
    ::avs::ui::UiExector::Instance()->SetDND(dnd.second);

2.14. 添加解绑功能

支持app解绑、按键解绑、云端解绑关于云端解绑修改的源文件有

  • srcs/ApplicationUtilities/DefaultClient/src/DefaultClient.cpp
  • srcs/ApplicationUtilities/DefaultClient/include/DefaultClient/DefaultClient.h
  • srcs/AVSCommon/SDKInterfaces/include/AVSCommon/SDKInterfaces/UserInactivityMonitorObserverInterface.h
  • srcs/capabilities/MultiRoomMusic/acsdkMultiRoomMusic/include/acsdkMultiRoomMusic/MRMCapabilityAgent.h
  • srcs/CapabilityAgents/System/src/UserInactivityMonitor.cpp
  • srcs/CapabilityAgents/System/include/System/UserInactivityMonitor.h

2.15. 添加编译和git信息

execute_process(
  COMMAND  git log -1 --format=%h
  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 
  OUTPUT_VARIABLE GIT_VERSION
)
string (REGEX REPLACE "[\n\t\r]" "" GIT_VERSION ${GIT_VERSION})
add_definitions( -DGIT_VERSION=\"${GIT_VERSION}\")

string(TIMESTAMP COMPILE_TIME "%Y%m%d %H%M%S")
add_definitions( -DCOMPILE_TIME=\"${COMPILE_TIME}\")

#if defined(GIT_VERSION) && defined(COMPILE_TIME)
    ACSDK_CRITICAL(LX("SampleApplication").d("version", GIT_VERSION).d("build", COMPILE_TIME));
#endif