/*****************************************************************************
Copyright: 2013-2018, MXKJ Tech. Co., Ltd.
File name:
Description: 安装参数
Author: 周涛
Version: 0.0.01
Date: 2023-12-28
History:
*****************************************************************************/

#include "includes.h"

// 定义一个全局变量，保存参数
static SAVE_INSTALL_T g_stSaveInstallParam = {0};

// 模块初始化
void wmm_install_init()
{
    SYS_MEMSET(&g_stSaveInstallParam, 0, sizeof(SAVE_INSTALL_T));
    wmm_install_set_param_with_default_data();
}

// 基于默认数据配置设备参数
void wmm_install_set_param_with_default_data()
{
    char *pbyBlockDesc = "input block desc pls";
    char *pbyPosition = "input install position pls";

    SYS_MEMSET(&g_stSaveInstallParam, 0, sizeof(SAVE_INSTALL_T));
    g_stSaveInstallParam.byBuildId = 1;
    g_stSaveInstallParam.wLayerId = 1;
    g_stSaveInstallParam.byLayerBlockId = 1;
    SYS_MEMCPY(g_stSaveInstallParam.abyLayerBlockDesc, pbyBlockDesc, SYS_STRLEN(pbyBlockDesc));
    g_stSaveInstallParam.byLocationType = 3; // 融合定位
    g_stSaveInstallParam.dwCoordX = 100;
    g_stSaveInstallParam.dwCoordY = 100;
    g_stSaveInstallParam.dwCoordZ = 300;
    SYS_MEMCPY(g_stSaveInstallParam.abyPositon, pbyPosition, SYS_STRLEN(pbyPosition));
}

// 基于flash中的数据配置设备参数
void wmm_install_set_param_with_flash_data(uint8 *pbyData)
{
    SYS_MEMCPY((void *)&g_stSaveInstallParam, (void *)pbyData, sizeof(SAVE_INSTALL_T));
}

// 向外暴露参数，方便其他模块使用参数
SAVE_INSTALL_T *wmm_install_query_param()
{
    return (SAVE_INSTALL_T *)(&g_stSaveInstallParam);
}

// 查询参数
// wCommand:  查询命令，pstLtv：当前监控对象
uint8 wmm_install_query(uint16 wCommand, uint8 *pabyLtv)
{
    LTV_T *pstLtv = (LTV_T *)pabyLtv;
    uint16 wLen = pstLtv->wLen - 4; // 净荷长度

    switch (wCommand)
    {
    case ORDER_INSTALL_BUILD_ID:
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveInstallParam.byBuildId, wLen);
        break;
    case ORDER_INSTALL_LAYER_ID:
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveInstallParam.wLayerId, wLen);
        break;
    case ORDER_INSTALL_LAYER_BLOCK_ID:
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveInstallParam.byLayerBlockId, wLen);
        break;
    case ORDER_INSTALL_LAYER_BLOCK_DESC:
        wLen = SYS_STRLEN(g_stSaveInstallParam.abyLayerBlockDesc);
        SYS_MEMCPY(pstLtv->abyData, g_stSaveInstallParam.abyLayerBlockDesc, wLen);
        break;
    case ORDER_INSTALL_LOCATION_TYPE:
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveInstallParam.byLocationType, wLen);
        break;
    case ORDER_INSTALL_LAYER_POSITION:
        wLen = SYS_STRLEN(g_stSaveInstallParam.abyPositon);
        SYS_MEMCPY(pstLtv->abyData, g_stSaveInstallParam.abyPositon, wLen);
        break;
    case ORDER_INSTALL_LAYER_COORD_X:
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveInstallParam.dwCoordX, wLen);
        break;
    case ORDER_INSTALL_LAYER_COORD_Y:
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveInstallParam.dwCoordY, wLen);
        break;
    case ORDER_INSTALL_LAYER_COORD_Z:
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveInstallParam.dwCoordZ, wLen);
        break;
    default:
        break;
    }

    return 0;
}

// 配置参数
// wCommand:  查询命令，pstLtv：当前监控对象
uint8 wmm_install_config(uint16 wCommand, uint8 *pabyLtv)
{
    LTV_T *pstLtv = (LTV_T *)pabyLtv;
    uint16 wLen = pstLtv->wLen - 4; // 净荷长度

    switch (wCommand)
    {
    case ORDER_INSTALL_BUILD_ID:
        SYS_MEMCPY(&g_stSaveInstallParam.byBuildId, pstLtv->abyData, wLen);
        break;
    case ORDER_INSTALL_LAYER_ID:
        SYS_MEMCPY(&g_stSaveInstallParam.wLayerId, pstLtv->abyData, wLen);
        break;
    case ORDER_INSTALL_LAYER_BLOCK_ID:
        SYS_MEMCPY(&g_stSaveInstallParam.byLayerBlockId, pstLtv->abyData, wLen);
        break;
    case ORDER_INSTALL_LAYER_BLOCK_DESC:
        SYS_MEMCPY(g_stSaveInstallParam.abyLayerBlockDesc, pstLtv->abyData, wLen);
        break;
    case ORDER_INSTALL_LOCATION_TYPE:
        SYS_MEMCPY(&g_stSaveInstallParam.byLocationType, pstLtv->abyData, wLen);
        break;
    case ORDER_INSTALL_LAYER_POSITION:
        SYS_MEMCPY(g_stSaveInstallParam.abyPositon, pstLtv->abyData, wLen);
        break;
    case ORDER_INSTALL_LAYER_COORD_X:
        SYS_MEMCPY(&g_stSaveInstallParam.dwCoordX, pstLtv->abyData, wLen);
        break;
    case ORDER_INSTALL_LAYER_COORD_Y:
        SYS_MEMCPY(&g_stSaveInstallParam.dwCoordY, pstLtv->abyData, wLen);
        break;
    case ORDER_INSTALL_LAYER_COORD_Z:
        SYS_MEMCPY(&g_stSaveInstallParam.dwCoordZ, pstLtv->abyData, wLen);
        break;
    default:
        break;
    }
}