// OAM设置参数
#include "includes.h"

// 定义全局变量保存设置参数
static SAVE_BTS_T g_stSaveBtsParam;

// 模块初始化
void wmm_bts_init()
{
    SYS_MEMSET(&g_stSaveBtsParam, 0, sizeof(SAVE_BTS_T));
    wmm_bts_set_param_with_default_data();
}

// 初始化默认参数
void wmm_bts_set_param_with_default_data()
{
    uint32 dwBtsId = 10000; // 默认基站ID
    SYS_MEMSET(&g_stSaveBtsParam, 0, sizeof(SAVE_BTS_T));

    SYS_MEMCPY((void *)g_stSaveBtsParam.abyBtsId, (void *)&dwBtsId, sizeof(uint32));
    g_stSaveBtsParam.byCarrierID = 2;    // 2号载波
    g_stSaveBtsParam.byTimeslot = 1;     // 1号时隙
    g_stSaveBtsParam.byLocationType = 2; // 融合定位
    g_stSaveBtsParam.byTwoBtsNum = 0;
    SYS_MEMSET(g_stSaveBtsParam.abyTwoBtsList, 0, 48);
}

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

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

// 参数基站参数
// pbyData:当前监控对象
void wmm_bts_query(uint8 *pbyData)
{
    LTV_T *pstLtv = (LTV_T *)pbyData;
    uint8 byLen = pstLtv->wLen - 4; // 净荷长度
    uint16 wCommand = pstLtv->wTag;

    switch (wCommand)
    {
    case ORDER_BTS_ID: // 基站ID
        SYS_MEMCPY(pstLtv->abyData, g_stSaveBtsParam.abyBtsId, byLen);
        break;
    case ORDER_BTS_CARRIER_ID: // 载波ID
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveBtsParam.byCarrierID, byLen);
        break;
    case ORDER_BTS_TIMESLOT: // 发送时隙
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveBtsParam.byTimeslot, byLen);
        break;
    case ORDER_BTS_LOCATION_TYPE: // 定位类型
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveBtsParam.byLocationType, byLen);
        break;
    case ORDER_BTS_TWO_BTS_NUM: // 两基站定位数量
        SYS_MEMCPY(pstLtv->abyData, &g_stSaveBtsParam.byTwoBtsNum, byLen);
        break;
    case ORDER_BTS_TWO_BTS_LIST: // 两基站定位基站列表
        SYS_MEMCPY(pstLtv->abyData, g_stSaveBtsParam.abyTwoBtsList, byLen);
        break;
    default:
        break;
    }

    return;
}

// 配置基站参数
// pbyData:当前监控对象
void wmm_bts_config(uint8 *pbyData)
{
    LTV_T *pstLtv = (LTV_T *)pbyData;
    uint8 byLen = pstLtv->wLen - 4; // 净荷长度
    uint16 wCommand = pstLtv->wTag;

    switch (wCommand)
    {
    case ORDER_BTS_ID: // 基站ID
        SYS_MEMCPY(g_stSaveBtsParam.abyBtsId, pstLtv->abyData, byLen);
        break;
    case ORDER_BTS_CARRIER_ID: // 载波ID，1-9号载波
        SYS_MEMCPY(&g_stSaveBtsParam.byCarrierID, pstLtv->abyData, byLen);
        break;
    case ORDER_BTS_TIMESLOT: // 发送时隙
        SYS_MEMCPY(&g_stSaveBtsParam.byTimeslot, pstLtv->abyData, byLen);
        break;
    case ORDER_BTS_LOCATION_TYPE: // 定位类型
        SYS_MEMCPY(&g_stSaveBtsParam.byLocationType, pstLtv->abyData, byLen);
        break;
    case ORDER_BTS_TWO_BTS_NUM: // 两基站定位数量
        SYS_MEMCPY(&g_stSaveBtsParam.byTwoBtsNum, pstLtv->abyData, byLen);
        break;
    case ORDER_BTS_TWO_BTS_LIST: // 两基站定位基站列表
        SYS_MEMCPY(g_stSaveBtsParam.abyTwoBtsList, pstLtv->abyData, byLen);
        break;
    default:
        break;
    }
}

// 查询基站编号
uint32 wmm_bts_query_bts_id()
{
    uint32 dwBtsId = 0;
    SYS_MEMCPY(&dwBtsId, g_stSaveBtsParam.abyBtsId, 4);
    if (dwBtsId == 0x00 || dwBtsId == 0xFFFFFFFF)
    {
        dwBtsId = 10000; // 默认基站编号
    }

    return dwBtsId;
}

// 查询基站载波编号
uint8 wmm_bts_query_carrier_id()
{
    uint8 byCarrierID = g_stSaveBtsParam.byCarrierID;
    if (byCarrierID < 1 || byCarrierID > 9)
    {
        byCarrierID = 0x09;
    }

    return (byCarrierID - 1);
}

// 查询基站时隙编号
uint8 wmm_bts_query_timeslot_id()
{
    uint8 bySlot = g_stSaveBtsParam.byTimeslot;
    if (bySlot < 1 || bySlot > 4)
    {
        bySlot = 0x01;
    }

    return (bySlot - 1);
}