#ifndef SMART_SOUND_H
#define SMART_SOUND_H

#ifdef __cplusplus
extern "C" {
#endif

#define CMD_BT_AVK_OPEN CMD_BT_BREDR_ENABLE
#define CMD_BT_AVK_CLOSE CMD_BT_BREDR_DISABLE

//*****************************************************************
//* Global Configure
//*****************************************************************
#define USED_SHM_TO_DBUS            (0)             // used shm for dbus transfer data
#ifndef MAX_PATH
#define MAX_PATH                    (256)
#endif

//*************************************************************

typedef enum {
    MODULE_CONTROLLER = 0,
    MODULE_ALARM,
    MODULE_CALL,
    MODULE_VOICEENGINE,
    MODULE_PLAYER,
    MODULE_CONFIGURE,
    MODULE_OTA,
    MODULE_WIFI,
    MODULE_BT,
    MODULE_KPLAYER,
    MODULE_KPLAYER_TEST,
    MODULE_SPLAYER,
    MODULE_SPLAYER_TEST,
    MODULE_LIGHT_MCU,
    MODULE_BLUEKC,
    MODULE_BLUEKC_TEST,
    MODULE_MANUFACTURE,
    MODULE_BT_DEMO,
    MODULE_SKINS,
    MODULE_LOG_CTRL,
    MODULE_WIRELESSTEST,
    MODULE_WIRELESSTEST_DEMO,
    MODULE_MANUFACTURE_CONTROLLER,
    MODULE_WIFI_DEMO,
    MODULE_MAX,
} MODULE_NAME;

typedef enum {
    CMD_MISC_PING = 0x0000,
    CMD_MISC_OTA,
    CMD_MISC_WEATHER,
    CMD_MISC_NOWTIME,
    CMD_MISC_UPGRADE,
    CMD_SYSTEM_STANDBY,
    CMD_MISC_QUERY_OTA_STATUS,
    CMD_MISC_QUERY_DL_STATUS,
    CMD_MISC_CHANGE2TEST,
    CMD_MISC_CHANGE2ONLINE,

    CMD_SEARCH_PLAYER_REQ,
    CMD_SEARCH_PLAYER_RESP,

    CMD_PROCESS_START,

    CMD_CALL_DIAL = 0x0300,
    CMD_CALL_ACCEPI,
    CMD_CALL_HANGUP,
    CMD_CALL_MESSAGE,

    CMD_PLAY_MODECHANGE = 0x0600,
    CMD_PLAY_PLAY,
    CMD_PLAY_PAUSE,
    CMD_PLAY_STOP,
    CMD_PLAY_SEEKTO,
    CMD_PLAY_SHOWMODE,
    CMD_PLAY_NEXT,
    CMD_PLAY_PRE,
    CMD_PLAY_SEEKTO_PLAY,
    CMD_PLAY_SHOWLIST,
    CMD_PLAY_UPDATELIST,
    CMD_PLAY_PREPARE_NEXT,
    CMD_PLAY_ADDTOLIST,
    CMD_PLAY_DELETEFROMLIST,
    CMD_PLAY_RESETLIST,
    CMD_PLAY_VOL_SET,
    CMD_PLAY_VOL_RESTORE,
    CMD_PLAY_MAX,

    CMD_PLAY_AUDIO_STOP = 0x0700,
    CMD_PLAY_AUDIO_PLAY,
    CMD_PLAY_AUDIO_MAX,

    CMD_SE_PLAY = 0x0780,
    CMD_SE_PLAYER_STATE_NTF,

    CMD_MUSIC_PCM_PLAY = 0X0790,
    CMD_MUSIC_PCM_PAUSE = 0X0791,
    CMD_MUSIC_PCM_STOP = 0X0792,
    CMD_MUSIC_PCM_MAX,

    CMD_PLAYER_MAX = 0X07FF,

    CMD_PLAY_RET_STATUS = 0x0800,

    CMD_CFG_ADD_REQ = 0x0900,
    CMD_CFG_ADD_RSP,
    CMD_CFG_CHANGE_REQ,
    CMD_CFG_CHANGE_RSP,
    CMD_CFG_GET_REQ,
    CMD_CFG_GET_RSP,
    CMD_CFG_UPG_NOTIFY,

    CMD_MSC_MSG_CONTROLLER_RECOG_SUCCESS = 0x0a00,
    CMD_MSC_MSG_CONTROLLER_RECOG_ERROR,
    CMD_MSC_MSG_CONTROLLER_WAKEUP,
    CMD_MSC_MSG_CONTROLLER_SESSION_BEGIN,
    CMD_MSC_MSG_CONTROLLER_RECOGING,
    CMD_CC_MSC_BEGIN_SESSION,
    CMD_CC_MSC_END_SESSION,
    CMD_CONTROLLER_REQMSG_INITARGS,
    CMD_CONTROLLER_RSPMSG_INITARGS,
    CMD_CONTROLLER_REQMSG_PLAYERSTATUS,
    CMD_CONTROLLER_RSPMSG_PLAYERSTATUS,
    CMD_MSC_REQMSG_MIC_CONTROL,
    CMD_MSC_RSPMSG_MIC_CONTROL,
    CMD_NDUILITE_FESPA_SET_ARG,
    CMD_NDUILITE_SDK_REINIT,
    CMD_YUNXIN_RECVMSG,
    CMD_YUNXIN_SENDMSG,
    CMD_YUNXIN_SENDMSG_BYPASS,
    CMD_YUNXIN_SENDMSGCB,
    CMD_CONTROLLER_MSG_YUNXIN,
    CMD_YUNXIN_STATUS,
    CMD_YUNXIN_SYSMSG,

    CMD_WIFI_CONF = 0x0b00,
    CMD_WIFI_CONF_RESP,
    CMD_WIFI_AUTO_CONN,
    CMD_WIFI_AUTO_CONN_RESP,
    CMD_WIFI_AUTO_CONN_OUT,
    CMD_WIFI_STATE_REQ,
    CMD_WIFI_STATE_RESP,
    CMD_WIFI_STATE_NTF,
    CMD_WIFI_CHANGE_VALID_AP,
    CMD_WIFI_CHANGE_VALID_AP_OUT,
    CMD_WIFI_CHANGE_VALID_AP_RESP,

    CMD_WIFI_BL_CMD_START,
    CMD_WIFI_BL_CONF,
    CMD_WIFI_BL_CONF_ABORT,
    CMD_WIFI_BL_DEV_INFO_NTF,
    CMD_WIFI_BL_CLOUD_CHALLENGE_SIGNATURE,
    CMD_WIFI_BL_DEV_SIGNATURE,
    CMD_WIFI_BL_CLOUD_SHAREDKEY,
    CMD_WIFI_BL_DEV_TOKEN,
    CMD_WIFI_BL_DEV_TOKEN_BOUND,
    CMD_WIFI_BL_CONF_FAILED,
    CMD_WIFI_BL_CMD_END,

    CMD_BT_NAME_GET_REQ,
    CMD_BT_NAME_GET_RESP,
    CMD_BT_EVT_NTF,
    CMD_BT_CREATED,

    CMD_BT_RESET,
    CMD_BT_BREDR_ENABLE,  // 0xb10
    CMD_BT_BREDR_DISABLE, // 0xb11

    CMD_BT_AVK_SOUND_OPEN,
    CMD_BT_AVK_SOUND_CLOSE,

    CMD_BT_AVK_CON_EVT,
    CMD_BT_AVK_DISC_EVT,

    CMD_BT_AVK_CON_DEV,
    CMD_BT_AVK_DISC_DEV,
    CMD_BT_AVK_PLAY,
    CMD_BT_AVK_PAUSE,
    CMD_BT_AVK_STOP,
    CMD_BT_AVK_PRE,
    CMD_BT_AVK_NEXT,
    CMD_BT_AVK_VOL_UP,
    CMD_BT_AVK_VOL_DOWN,

    CMD_BT_AVK_SOUND_START_EVT, // 0xb1f
    CMD_BT_AVK_SOUND_STOP_EVT,  // 0xb20

    CMD_BT_LE_ENABLE, // 0xb21
    CMD_BT_LE_DISABLE,
    CMD_BT_LE_NEVSPS_DISC,

    CMD_BT_AVK_CRTED,
    CMD_BT_AVK_DELETED,

    CMD_BT_AVK_RC_PLAY,
    CMD_BT_AVK_RC_PAUSE,

    CMD_WIFI_UNBIND_ACCOUNT,
    CMD_BT_VOL_CHANGE,

    CMD_BT_BREDR_REBOOT_CLOSE,
    CMD_BT_AVK_DEV_CON_CONFLICT,
    CMD_WIFI_ON,
    CMD_WIFI_OFF,
    CMD_WIFI_ON_RESP,
    CMD_WIFI_OFF_RESP,

    CMD_KPLAYER_START = 0x1b00,
    CMD_KPLAYER_STOP,
    CMD_KPLAYER_NOTIF_DUR,
    CMD_KPLAYER_HOST_ACTION,
    CMD_KPLAYER_CTR_NTF_BASE = 0x1c00,
    CMD_KPLAYER_CTR_CREATED,
    CMD_KPLAYER_CTR_DELED,
    CMD_KPLAYER_CTR_PLAY,
    CMD_KPLAYER_CTR_STOP,
    CMD_KPLAYER_CTR_PAUSE,
    CMD_KPLAYER_CTR_SEEK,
    CMD_KPLAYER_CTR_SET_URL,
    CMD_KPLAYER_CTR_SET_VOLUME,
    CMD_KPLAYER_CTR_SET_MUTE,
    CMD_KPLAYER_CTR_SET_NXT_URL,
    CMD_KPLAYER_CTR_SET_NEXT,
    CMD_KPLAYER_CTR_SET_PREV,

    CMD_SPLAYER_SFIFO_TEST = 0x1d00,
    CMD_SPLAYER_START,
    CMD_SPLAYER_STOP,
    CMD_SPLAYER_HOST_ACTION,

    CMD_SPLAYER_CTR_NTF_BASE = 0x1e00,
    CMD_SPLAYER_MSG_TYPE_CREATE,
    CMD_SPLAYER_MSG_TYPE_DEL,
    CMD_SPALYER_MSG_TYPE_START,
    CMD_SPLAYER_MSG_TYPE_STOP,
    CMD_SPLAYER_MSG_TYPE_SET_VOLUME,
    CMD_SPLAYER_MSG_TYPE_STREAMING,
    CMD_SPLAYER_MSG_TYPE_DESTRY,
    CMD_SPLAYER_MSG_TYPE_DURATION,
    CMD_SPLAYER_MSG_TYPE_STREAM_NTF,
    CMD_SPLAYER_MSG_TYPE_STREAM_PLAYPAUSE,

    CMD_BLUEKC_POOL_TEST = 0x1f00,
    CMD_BLUEKC_LOG_DEBUG,
    CMD_BLUEKC_LOG_RESTORE,

    // 厂测
    CMD_TEST_GET_VER_REQ = 0X2000,
    CMD_TEST_GET_VER_RESP,
    CMD_TEST_GET_MCU_VER_REQ,
    CMD_TEST_GET_MCU_VER_RESP,
    CMD_TEST_KNOB_REQ,
    CMD_TEST_KNOB_RESP,
    CMD_TEST_BUTTON_REQ,
    CMD_TEST_BUTTON_RESP,
    CMD_TEST_GET_VOLUME_REQ,
    CMD_TEST_GET_VOLUME_RESP,
    CMD_TEST_SET_VOLUME_REQ,
    CMD_TEST_SET_VOLUME_RESP,
    CMD_TEST_BT_ADDR_REQ,
    CMD_TEST_BT_ADDR_RESP,
    CMD_TEST_BT_PARRING_REQ,
    CMD_TEST_BT_PARRING_RESP,
    CMD_TEST_GET_CPLD_REQ,

    // RF cmd--->

    CMD_TEST_RF_BASE = 0x2100,
    CMD_TEST_RF_BT_ENTER,
    CMD_TEST_RF_BT_ENTER_RESP,
    CMD_TEST_RF_EXIT_TO_NORNAL,
    CMD_TEST_RF_EXIT_TO_NORNAL_RESP,

    CMD_TEST_RF_BT_TX = 0x2200,
    CMD_TEST_RF_BT_TX_RESP,
    CMD_TEST_RF_BT_TX_2402_1DH1,
    CMD_TEST_RF_BT_TX_2402_1DH1_RESP,
    CMD_TEST_RF_BT_TX_2440_1DH1,
    CMD_TEST_RF_BT_TX_2440_1DH1_RESP,
    CMD_TEST_RF_BT_TX_2480_1DH1,
    CMD_TEST_RF_BT_TX_2480_1DH1_RESP,
    CMD_TEST_RF_BT_TX_2402_2DH3,
    CMD_TEST_RF_BT_TX_2402_2DH3_RESP,
    CMD_TEST_RF_BT_TX_2440_2DH3,
    CMD_TEST_RF_BT_TX_2440_2DH3_RESP,
    CMD_TEST_RF_BT_TX_2480_2DH3,
    CMD_TEST_RF_BT_TX_2480_2DH3_RESP,
    CMD_TEST_RF_BT_TX_2402_3DH5,
    CMD_TEST_RF_BT_TX_2402_3DH5_RESP,
    CMD_TEST_RF_BT_TX_2440_3DH5,

    CMD_TEST_RF_BT_TX_2440_3DH5_RESP,
    CMD_TEST_RF_BT_TX_2480_3DH5,
    CMD_TEST_RF_BT_TX_2480_3DH5_RESP,

    // varible extend--->
    CMD_TEST_RF_BT_TX_VARIABLE = 0x22f0,
    CMD_TEST_RF_BT_TX_VARIABLE_RESP,
    //<----varible extend

    CMD_TEST_RF_BT_RX = 0x2300,
    CMD_TEST_RF_BT_RX_RESP,
    CMD_TEST_RF_BT_RX_2402_1DH1,
    CMD_TEST_RF_BT_RX_2402_1DH1_RESP,
    CMD_TEST_RF_BT_RX_2440_1DH1,
    CMD_TEST_RF_BT_RX_2440_1DH1_RESP,
    CMD_TEST_RF_BT_RX_2480_1DH1,
    CMD_TEST_RF_BT_RX_2480_1DH1_RESP,
    CMD_TEST_RF_BT_RX_2402_2DH3,
    CMD_TEST_RF_BT_RX_2402_2DH3_RESP,
    CMD_TEST_RF_BT_RX_2440_2DH3,
    CMD_TEST_RF_BT_RX_2440_2DH3_RESP,
    CMD_TEST_RF_BT_RX_2480_2DH3,
    CMD_TEST_RF_BT_RX_2480_2DH3_RESP,
    CMD_TEST_RF_BT_RX_2402_3DH5,
    CMD_TEST_RF_BT_RX_2402_3DH5_RESP,
    CMD_TEST_RF_BT_RX_2440_3DH5,

    CMD_TEST_RF_BT_RX_2440_3DH5_RESP,
    CMD_TEST_RF_BT_RX_2480_3DH5,
    CMD_TEST_RF_BT_RX_2480_3DH5_RESP,

    // varible extend--->
    CMD_TEST_RF_BT_RX_VARIABLE = 0x23f0,
    CMD_TEST_RF_BT_RX_VARIABLE_RESP,
    //<----varible extend

    CMD_TEST_RF_BT_EXIT = 0x2400,
    CMD_TEST_RF_BT_EXIT_RESP,

    CMD_TEST_RF_WIFI_ENTER = 0x2500,
    CMD_TEST_RF_WIFI_ENTER_RESP,

    CMD_TEST_RF_WIFI_TX = 0x2600,
    CMD_TEST_RF_WIFI_TX_RESP,

    CMD_TEST_RF_WIFI_TX_CHANNEL1,
    CMD_TEST_RF_WIFI_TX_CHANNEL1_RESP,
    CMD_TEST_RF_WIFI_TX_CHANNEL7,
    CMD_TEST_RF_WIFI_TX_CHANNEL7_RESP,
    CMD_TEST_RF_WIFI_TX_CHANNEL13,
    CMD_TEST_RF_WIFI_TX_CHANNEL13_RESP,

    // varible extend--->
    CMD_TEST_RF_WIFI_TX_VARIABLE = 0x26f0,
    CMD_TEST_RF_WIFI_TX_VARIABLE_RESP,
    //<----varible extend

    CMD_TEST_RF_WIFI_RX = 0x2700,
    CMD_TEST_RF_WIFI_RX_RESP,

    CMD_TEST_RF_WIFI_RX_CHANNEL1,
    CMD_TEST_RF_WIFI_RX_CHANNEL1_RESP,
    CMD_TEST_RF_WIFI_RX_CHANNEL1_RET,
    CMD_TEST_RF_WIFI_RX_CHANNEL1_RET_RESP,
    CMD_TEST_RF_WIFI_RX_CHANNEL7,
    CMD_TEST_RF_WIFI_RX_CHANNEL7_RESP,
    CMD_TEST_RF_WIFI_RX_CHANNEL7_RET,
    CMD_TEST_RF_WIFI_RX_CHANNEL7_RET_RESP,
    CMD_TEST_RF_WIFI_RX_CHANNEL13,
    CMD_TEST_RF_WIFI_RX_CHANNEL13_RESP,
    CMD_TEST_RF_WIFI_RX_CHANNEL13_RET,
    CMD_TEST_RF_WIFI_RX_CHANNEL13_RET_RESP,

    // varible extend--->
    CMD_TEST_RF_WIFI_RX_VARIABLE = 0x27f0,
    CMD_TEST_RF_WIFI_RX_VARIABLE_RESP,
    //<----varible extend

    CMD_TEST_RF_WIFI_EXIT = 0x2800,
    CMD_TEST_RF_WIFI_EXIT_RESP,

    CMD_TEST_MCU_LED_GUIDE = 0X2900,
    CMD_TEST_MCU_LED_GUIDE_RSP,
    CMD_TEST_MCU_LED_MATRIX,
    CMD_TEST_MCU_LED_MATRIX_RSP,
    //<-----RF cmd

    CMD_TEST_RELEASE_SYSTEM,

    CMD_ALARM_SYNC_REQ = 0xF000,
    CMD_ALARM_SYNC_RSP,
    CMD_ALARM_ADD,
    CMD_ALARM_REMOVE,
    CMD_ALARM_REMOVEALL,

    CMD_REMAIND_SYNC_REQ,
    CMD_REMAIND_SYNC_RSP,
    CMD_REMAIND_ADD,
    CMD_REMAIND_REMOVE,
    CMD_REMAIND_REMOVEALL,

    CMD_ASSISTANT_STATUS,
    CMD_ASSISTANT_RUNNING,
    CMD_ASSISTANT_NOTIFY,

    CMD_SESSION_ALARM_SYNC,

    CMD_WORKDAY_DB_REQ = 0xF100,
    CMD_WORKDAY_DB_RSP,

    CMD_OTA_NOTIFY = 0xF200,
    CMD_OTA_STATUS,
    CMD_OTA_RUNNOW,

    CMD_LOG_CONFIG = 0xF300,

    CMD_DEMO_PERFORM_TEST = 0xff00,

} DBUS_CMD;

typedef enum {
    ERR_INPUT_PARAMS = 1,
    ERR_NO_ITEMS,
    ERR_GET_BUS,
    ERR_DBUS_CONNECTION,
    ERR_REQUEST_BUS_NAME,
    ERR_SET_WATCH_FUNCTION,
    ERR_SET_TIMEOUT_FUNCTION,
    ERR_BUS_MATCH,
    ERR_BUS_SET_MSG_CB,
    ERR_DBUS_CREATE_MSG,
    ERR_BUS_SEND_MSG,
    ERR_DBUS_MSG_TO_LARGE,
    ERR_BUS_RCV_MSG,
    ERR_ADD_TASK,
    ERR_UNSUP_EVP_TYPE,

    ERR_CREATE_MQ,
    ERR_MQ_SENDMSG,
    ERR_CREATE_SHM,
    ERR_MAP_SHM,
    ERR_MALLOC_MEMORY,

    ERR_EVP_INIT_KEY,
    ERR_EVP_UPDATE,
    ERR_EVP_FINALE,
    ERR_EVP_KEY_SIZE,

    ERR_OPEN_FILE,
    ERR_READ_FILE,
    ERR_WRITE_FILE,
    ERR_COPY_FILE,
    ERR_FILE_NOT_EXISTS,
    ERR_GET_FILE_SIZE,
    ERR_UNINIT_ITEM,
    ERR_FILE_EMPTY,

    ERR_SEND_MAIL,
    ERR_NETWORK_SEND,
    ERR_NETWORK_NOT_CONNECTED,

    ERR_CREATE_SOCKET,
    ERR_BIND_SOCKET,

    ERR_UNSUPPORT,
} DBUS_WITH_LIBUV_ERROR;

/**
 * 错误码
 */
typedef enum {
    ERR_NO_INIT_IPL3 = 2000,  ///< (0xF101) 未初始化OTA参数
    ERR_BAD_IPL3,             ///< OTA参数异常
    ERR_BAD_FILE_SIZE,        ///< 文件大小不正确
    ERR_MD5_FILE,             ///< 计算文件MD5校验和异常
    ERR_MD5_CHECK_SUM,        ///< MD5校验和不正确
    ERR_OTA_WRITE_BOOT,       ///< 写入BOOT分区异常
    ERR_OTA_WRITE_ROOTFS,     ///< 写入ROOTFS分区异常
    ERR_OTA_WRITE_IPL3,       ///< 写入IPL3分区异常
    ERR_OTA_WRITE_PARAMS,     ///< 写入OTA参数异常
    ERR_OTA_DOWNLOAD_FILE,    ///< 下载文件失败
    ERR_VERIFY_PARTITION_MD5, ///< 校验分区MD5异常
    ERR_OTA_PRE_STATR,   ///< 先前已经启动了一个未完成的OTA任务
    ERR_OTA_YET_CUR_VER, ///< 当前版本已经更新
    ERR_OTA_NOT_READY,   ///< OTA未准备好,暂时不能进行OTA升级
} OTA_ERROR;

typedef enum {
    ERR_CREATE_CFG_FILE = 1000,
    ERR_CREATE_SQLITE3_DB,
    ERR_OPEN_SQLITE3_DB,
    ERR_SQLITE3_CREATE_TABLE,
    ERR_SYNC_DATABASE,
    ERR_SQL_QUERY,
    ERR_SQL_DELETE,
    ERR_UNKNOWN_TYPE,
    ERR_PERMISSION_DENIED,
    ERR_CFG_NOITEM,
    ERR_CFG_ITEM_EXIST,
    ERR_CFG_WAIT_RSP,
    ERR_CFG_BUSY,
    ERR_STR_CONVERT,
    ERR_SQL_REG_MODULE,
} CONFIG_MODE_ERRCODE;

typedef enum {
    REPEAT_MODE_NONE                = 1,
    REPEAT_MODE_EVERY_DAY           = 2,
    REPEAT_MODE_WORKDAY             = 3,
    REPEAT_MODE_WEEKEND             = 4,
    REPEAT_MODE_WEEKDAY             = 5,
    REPEAT_MODE_EVERY_MONTH_DAY     = 6,
    REPEAT_MODE_EVERY_YEAR_DAY      = 7,
    REPEAT_MODE_EVERY_TIME          = 8,
    REPEAT_MODE_MONTH_LAST_DAY      = 9,
    REPEAT_MODE_HOLIDAY             = 10,
} REPEAT_MODE;

#define     MAX_CFG_KEY_NAME                    (256)
#define     MAX_CFG_KEY_VALUE                   (1024)
#define     DATA_TIME_STR_LEN                   (20)

#define GET_FILE_SIZE(path, size)                                              \
    do {                                                                       \
        struct stat st;                                                        \
        memset(&st, 0, sizeof(struct stat));                                   \
        if (stat(path, &st) != 0) {                                            \
            size = -1;                                                         \
        } else {                                                               \
            size = st.st_size;                                                 \
        }                                                                      \
    } while (0)
#ifdef __cplusplus
}
#endif
#endif