// OAM模块-基站参数
// 秒寻科技
// zt 2024-10-2

package bparamoam

import (
	"bytes"
	"encoding/binary"
	"ipsomc/module/bparam/bparammodel"
	"ipsomc/module/oam"
	"ipsomc/module/ps/psdl"
	"ipsomc/module/ps/psmodel"
	"ipsomc/util"
	"strconv"
)

type BparamOam struct {
	psDlApi psdl.PsDl
}

// 组织查询LTV-A数据结构
func (obj *BparamOam) OamOrganizeQueryLtvA(wLen uint16, wCmd uint16, dataList *bytes.Buffer) {
	dataLen := wLen - 4
	binary.Write(dataList, binary.LittleEndian, wLen)                  //长度
	binary.Write(dataList, binary.LittleEndian, wCmd)                  //命令
	binary.Write(dataList, binary.LittleEndian, make([]byte, dataLen)) //数据
}

// 组织设置LTV-A数据结构
func (obj *BparamOam) OamOrganizeSetLtvA(wLen uint16, wCmd uint16, value []byte, dataList *bytes.Buffer) {
	dataLen := wLen - 4
	tmpSlice := make([]byte, dataLen) //定义该命令所需的数据切片
	copy(tmpSlice, value)

	binary.Write(dataList, binary.LittleEndian, wLen)     //长度
	binary.Write(dataList, binary.LittleEndian, wCmd)     //命令
	binary.Write(dataList, binary.LittleEndian, tmpSlice) //数据
}

// 查询基站设备参数
// dataModel:基站参数
func (obj *BparamOam) OamQueryDeviceParam(dataModel *bparammodel.BtsBaseParam) error {
	////组织查询参数数据
	var dataList bytes.Buffer
	zeroBuffer := make([]byte, 20)

	//设备类型
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_DEVICE_TYPE), &dataList)

	//设备序列号
	binary.Write(&dataList, binary.LittleEndian, uint16(24))                         //长度
	binary.Write(&dataList, binary.LittleEndian, uint16(oam.ORDER_DEVICE_SERIAL_NO)) //命令
	binary.Write(&dataList, binary.LittleEndian, zeroBuffer)                         //数据

	//设备型号
	binary.Write(&dataList, binary.LittleEndian, uint16(24))                     //长度
	binary.Write(&dataList, binary.LittleEndian, uint16(oam.ORDER_DEVICE_MODEL)) //命令
	binary.Write(&dataList, binary.LittleEndian, zeroBuffer)                     //数据

	//软件版本
	binary.Write(&dataList, binary.LittleEndian, uint16(24))                           //长度
	binary.Write(&dataList, binary.LittleEndian, uint16(oam.ORDER_DEVICE_MCU_VERSION)) //命令
	binary.Write(&dataList, binary.LittleEndian, zeroBuffer)                           //数据

	//蓝牙名称
	binary.Write(&dataList, binary.LittleEndian, uint16(32))                            //长度
	binary.Write(&dataList, binary.LittleEndian, uint16(oam.ORDER_DEVICE_BLE_BTS_NAME)) //命令
	binary.Write(&dataList, binary.LittleEndian, make([]byte, 28))                      //数据

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_QUERY, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 查询基站网管参数
// dataModel:基站参数
func (obj *BparamOam) OamQueryNetworkParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer

	////组织查询参数
	obj.OamOrganizeQueryLtvA(24, uint16(oam.ORDER_NETWORK_WIFI_NAME), &dataList)   //wifi名称
	obj.OamOrganizeQueryLtvA(24, uint16(oam.ORDER_NETWORK_WIFI_PWD), &dataList)    //wifi密码
	obj.OamOrganizeQueryLtvA(36, uint16(oam.ORDER_NETWORK_SERVICE_IP), &dataList)  //管理中心IP
	obj.OamOrganizeQueryLtvA(6, uint16(oam.ORDER_NETWORK_SERVICE_PORT), &dataList) //管理中心端口
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_NETWORK_SWITCH), &dataList)       //管理中心使能

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_QUERY, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 设置基站网管参数
// dataModel:基站参数
func (obj *BparamOam) OamSetNetworkParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer
	tmpBytes := make([]byte, 32)

	////组织查询参数
	tmpBytes = []byte(dataModel.WifiName)
	obj.OamOrganizeSetLtvA(24, uint16(oam.ORDER_NETWORK_WIFI_NAME), tmpBytes, &dataList) //wifi名称

	tmpBytes = []byte(dataModel.WifiPwd)
	obj.OamOrganizeSetLtvA(24, uint16(oam.ORDER_NETWORK_WIFI_PWD), tmpBytes, &dataList) //wifi密码

	tmpBytes = []byte(dataModel.ServiceIP)
	obj.OamOrganizeSetLtvA(36, uint16(oam.ORDER_NETWORK_SERVICE_IP), tmpBytes, &dataList) //管理中心IP

	binary.LittleEndian.PutUint16(tmpBytes, uint16(dataModel.ServicePort))
	obj.OamOrganizeSetLtvA(6, uint16(oam.ORDER_NETWORK_SERVICE_PORT), tmpBytes, &dataList) //管理中心端口

	tmpBytes = []byte{dataModel.NetworkSwitch}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_NETWORK_SWITCH), tmpBytes, &dataList) //管理中心使能

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_CONFIGURE, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 查询基站同步参数
// dataModel:基站参数
func (obj *BparamOam) OamQuerySyncParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer

	////组织查询参数
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_SYNC_CENTER_FREQ), &dataList) //中心频率
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_SYNC_TX_POWER), &dataList)    //发射功率
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_SYNC_RSSI), &dataList)        //接收电平

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_QUERY, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 设置基站同步参数
// dataModel:基站参数
func (obj *BparamOam) OamSetSyncParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer
	tmpBytes := make([]byte, 1)

	////组织参数
	tmpBytes = []byte{byte(dataModel.CenterFreq)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_SYNC_CENTER_FREQ), tmpBytes, &dataList)

	tmpBytes = []byte{byte(dataModel.TxPower)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_SYNC_TX_POWER), tmpBytes, &dataList) //发射功率

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_CONFIGURE, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 查询基站增益参数
// dataModel:基站参数
func (obj *BparamOam) OamQueryGainParam(dataModel *bparammodel.BtsDeviceParam) error {
	var dataList bytes.Buffer

	////组织查询参数
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_CONFIG_DAC_SWITCH), &dataList) //中心频率
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_CONFIG_DAC_GAIN), &dataList)   //发射功率
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_CONFIG_PA_SWITCH), &dataList)  //中心频率
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_CONFIG_PA_GAIN), &dataList)    //发射功率

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_QUERY, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 设置基站增益参数
// dataModel:基站参数
func (obj *BparamOam) OamSetGainParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer
	tmpBytes := make([]byte, 32)

	////组织参数
	tmpBytes = []byte{byte(dataModel.DaSwitch)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_CONFIG_DAC_SWITCH), tmpBytes, &dataList)

	tmpBytes = []byte{byte(dataModel.DaGain)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_CONFIG_DAC_GAIN), tmpBytes, &dataList)

	tmpBytes = []byte{byte(dataModel.PaSwitch)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_CONFIG_PA_SWITCH), tmpBytes, &dataList)

	tmpBytes = []byte{byte(dataModel.PaGain)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_CONFIG_PA_GAIN), tmpBytes, &dataList)

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_CONFIGURE, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 查询安装参数
// dataModel:基站参数
func (obj *BparamOam) OamQueryInstallParam(dataModel *bparammodel.BtsDeviceParam) error {
	var dataList bytes.Buffer

	////组织查询参数
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_INSTALL_BUILD_ID), &dataList)          //
	obj.OamOrganizeQueryLtvA(6, uint16(oam.ORDER_INSTALL_LAYER_ID), &dataList)          //
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_INSTALL_LAYER_BLOCK_ID), &dataList)    //
	obj.OamOrganizeQueryLtvA(36, uint16(oam.ORDER_INSTALL_LAYER_BLOCK_DESC), &dataList) //

	obj.OamOrganizeQueryLtvA(36, uint16(oam.ORDER_INSTALL_LAYER_POSITION), &dataList) //
	obj.OamOrganizeQueryLtvA(8, uint16(oam.ORDER_INSTALL_LAYER_COORD_X), &dataList)   //
	obj.OamOrganizeQueryLtvA(8, uint16(oam.ORDER_INSTALL_LAYER_COORD_Y), &dataList)   //
	obj.OamOrganizeQueryLtvA(8, uint16(oam.ORDER_INSTALL_LAYER_COORD_Z), &dataList)   //

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_QUERY, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 设置安装参数
// dataModel:基站参数
func (obj *BparamOam) OamSetInstallParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer
	tmpBytes := make([]byte, 32)

	////组织参数
	tmpBytes = []byte{byte(dataModel.BuildID)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_INSTALL_BUILD_ID), tmpBytes, &dataList)

	layerBytes := make([]byte, 2)
	binary.LittleEndian.PutUint16(layerBytes, uint16(dataModel.LayerID))
	obj.OamOrganizeSetLtvA(6, uint16(oam.ORDER_INSTALL_LAYER_ID), layerBytes, &dataList)

	tmpBytes = []byte{byte(dataModel.BlockID)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_INSTALL_LAYER_BLOCK_ID), tmpBytes, &dataList)

	tmpBytes = []byte(dataModel.BlockDesc) //UTF-8编码
	blockDesc, _ := util.CharTransUtf8ToGb(tmpBytes)
	obj.OamOrganizeSetLtvA(36, uint16(oam.ORDER_INSTALL_LAYER_BLOCK_DESC), blockDesc, &dataList)

	tmpBytes = []byte(dataModel.Position)
	position, _ := util.CharTransUtf8ToGb(tmpBytes)
	obj.OamOrganizeSetLtvA(36, uint16(oam.ORDER_INSTALL_LAYER_POSITION), position, &dataList)

	binary.LittleEndian.PutUint32(tmpBytes, uint32(dataModel.CoordX))
	obj.OamOrganizeSetLtvA(8, uint16(oam.ORDER_INSTALL_LAYER_COORD_X), tmpBytes, &dataList)

	binary.LittleEndian.PutUint32(tmpBytes, uint32(dataModel.CoordY))
	obj.OamOrganizeSetLtvA(8, uint16(oam.ORDER_INSTALL_LAYER_COORD_Y), tmpBytes, &dataList)

	binary.LittleEndian.PutUint32(tmpBytes, uint32(dataModel.CoordZ))
	obj.OamOrganizeSetLtvA(8, uint16(oam.ORDER_INSTALL_LAYER_COORD_Z), tmpBytes, &dataList)

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_CONFIGURE, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 查询基站参数
// dataModel:基站参数
func (obj *BparamOam) OamQueryBtsParam(dataModel *bparammodel.BtsDeviceParam) error {
	var dataList bytes.Buffer

	////组织查询参数
	obj.OamOrganizeQueryLtvA(8, uint16(oam.ORDER_BTS_ID), &dataList)         //基站ID
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_BTS_CARRIER_ID), &dataList) //载波ID
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_BTS_TIMESLOT), &dataList)   //时隙ID

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_QUERY, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 设置基站参数
// dataModel:基站参数
func (obj *BparamOam) OamSetBtsParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer
	tmpBytes := make([]byte, 32)

	////组织参数
	binary.LittleEndian.PutUint32(tmpBytes, uint32(dataModel.BtsID))
	obj.OamOrganizeSetLtvA(8, uint16(oam.ORDER_BTS_ID), tmpBytes, &dataList)

	tmpBytes = []byte{byte(dataModel.CarrierID)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_BTS_CARRIER_ID), tmpBytes, &dataList)

	tmpBytes = []byte{byte(dataModel.Timeslot)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_BTS_TIMESLOT), tmpBytes, &dataList)

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_CONFIGURE, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 查询定位类型参数
// dataModel:基站参数
func (obj *BparamOam) OamQueryLocationTypeParam(dataModel *bparammodel.BtsDeviceParam) error {
	var dataList bytes.Buffer

	////组织查询参数
	//定位类型
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_BTS_LOCATION_TYPE), &dataList)

	//一维定位基站数量
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_BTS_TWO_BTS_NUM), &dataList)

	//一维定位基站列表
	obj.OamOrganizeQueryLtvA(52, uint16(oam.ORDER_BTS_TWO_BTS_LIST), &dataList)

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_QUERY, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 设置定位类型参数
// dataModel:基站参数
func (obj *BparamOam) OamSetLocationTypeParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer
	tmpBytes := make([]byte, 48)

	////组织参数
	//定位类型
	tmpBytes = []byte{byte(dataModel.LocationType)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_BTS_LOCATION_TYPE), tmpBytes, &dataList)

	//一维基站数量
	tmpBytes = []byte{byte(dataModel.TwoBtsNum)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_BTS_TWO_BTS_NUM), tmpBytes, &dataList)

	//一维基站列表
	tmpBytes = []byte(dataModel.TwoBtsList)
	obj.OamOrganizeSetLtvA(52, uint16(oam.ORDER_BTS_TWO_BTS_LIST), tmpBytes, &dataList)

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_CONFIGURE, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 查询RTC参数
// dataModel:基站参数
func (obj *BparamOam) OamQueryRtcParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer

	////rtc当前时间
	obj.OamOrganizeQueryLtvA(10, uint16(oam.ORDER_SYNC_TIMER_CURRENT_TIME), &dataList)

	//同步定时开关
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_SYNC_TIMER_SWITCH), &dataList)

	//同步定时数量
	obj.OamOrganizeQueryLtvA(5, uint16(oam.ORDER_SYNC_TIMER_NUM), &dataList)

	//同步定时1开始时间
	obj.OamOrganizeQueryLtvA(6, uint16(oam.ORDER_SYNC_TIMER1_START), &dataList)

	//同步定时1结束时间
	obj.OamOrganizeQueryLtvA(6, uint16(oam.ORDER_SYNC_TIMER1_STOP), &dataList)

	//同步定时2开始时间
	obj.OamOrganizeQueryLtvA(6, uint16(oam.ORDER_SYNC_TIMER2_START), &dataList)

	//同步定时2结束时间
	obj.OamOrganizeQueryLtvA(6, uint16(oam.ORDER_SYNC_TIMER2_STOP), &dataList)

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_QUERY, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 设置RTC参数
// dataModel:基站参数
func (obj *BparamOam) OamSetRtcParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer
	tmpBytes := make([]byte, 32)
	var rtcTime uint16 = 0

	////组织参数
	//RTC初始时间
	dataTmp := obj.OrganizeDateTime(dataModel.RtcDateTime)
	obj.OamOrganizeSetLtvA(10, uint16(oam.ORDER_SYNC_TIMER_CURRENT_TIME), dataTmp, &dataList)

	//同步定时开关
	tmpBytes = []byte{byte(dataModel.SyncTimerSwitch)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_SYNC_TIMER_SWITCH), tmpBytes, &dataList)

	//同步定时数量
	tmpBytes = []byte{byte(dataModel.SyncTimerNum)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_SYNC_TIMER_NUM), tmpBytes, &dataList)

	//同步定时1开始时间
	rtcTime = obj.OrganizeTime((dataModel.SyncTimer1Start))
	start1Bytes := make([]byte, 2)
	binary.LittleEndian.PutUint16(start1Bytes, rtcTime)
	obj.OamOrganizeSetLtvA(6, uint16(oam.ORDER_SYNC_TIMER1_START), start1Bytes, &dataList)

	//同步定时1结束时间
	rtcTime = obj.OrganizeTime((dataModel.SyncTimer1Stop))
	stop1Bytes := make([]byte, 2)
	binary.LittleEndian.PutUint16(stop1Bytes, rtcTime)
	obj.OamOrganizeSetLtvA(6, uint16(oam.ORDER_SYNC_TIMER1_STOP), stop1Bytes, &dataList)

	//同步定时2开始时间
	rtcTime = obj.OrganizeTime((dataModel.SyncTimer2Start))
	start2Bytes := make([]byte, 2)
	binary.LittleEndian.PutUint16(start2Bytes, rtcTime)
	obj.OamOrganizeSetLtvA(6, uint16(oam.ORDER_SYNC_TIMER2_START), start2Bytes, &dataList)

	//同步定时2结束时间
	rtcTime = obj.OrganizeTime((dataModel.SyncTimer2Stop))
	stop2Bytes := make([]byte, 2)
	binary.LittleEndian.PutUint16(stop2Bytes, rtcTime)
	obj.OamOrganizeSetLtvA(6, uint16(oam.ORDER_SYNC_TIMER2_STOP), stop2Bytes, &dataList)

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_CONFIGURE, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

func (obj *BparamOam) OrganizeDateTime(rtcDateTime string) []uint8 {
	dateTimeList := make([]uint8, 6)
	strTmp := ""

	//年
	strTmp = rtcDateTime[0:4]
	year, _ := strconv.Atoi(strTmp)
	year -= 2000
	dateTimeList[5] = uint8(year)

	//月
	strTmp = rtcDateTime[5:7]
	month, _ := strconv.Atoi(strTmp)
	dateTimeList[4] = uint8(month)

	//日
	strTmp = rtcDateTime[8:10]
	day, _ := strconv.Atoi(strTmp)
	dateTimeList[3] = uint8(day)

	//小时
	strTmp = rtcDateTime[11:13]
	hour, _ := strconv.Atoi(strTmp)
	dateTimeList[2] = uint8(hour)

	//分钟
	strTmp = rtcDateTime[14:16]
	minute, _ := strconv.Atoi(strTmp)
	dateTimeList[1] = uint8(minute)

	//秒
	strTmp = rtcDateTime[17:19]
	second, _ := strconv.Atoi(strTmp)
	dateTimeList[0] = uint8(second)

	return dateTimeList
}

// 组织时间
func (obj *BparamOam) OrganizeTime(rtcTime string) uint16 {
	strTmp := ""
	hourMinute := 0

	//小时
	strTmp = rtcTime[0:2]
	hour, _ := strconv.Atoi(strTmp)
	hour <<= 8

	//分钟
	strTmp = rtcTime[3:5]
	minute, _ := strconv.Atoi(strTmp)

	hourMinute = (hour | minute)

	return uint16(hourMinute)
}

// 保存参数
// dataModel:基站参数
func (obj *BparamOam) OamSaveParam(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer

	////组织参数
	tmpBytes := []byte{dataModel.SaveParam}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_CONFIG_SAVE), tmpBytes, &dataList)

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_CONFIGURE, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}

// 设备复位
// dataModel:基站参数
func (obj *BparamOam) OamResetBts(dataModel *bparammodel.BtsBaseParam) error {
	var dataList bytes.Buffer

	////组织参数
	tmpBytes := []byte{byte(dataModel.ResetBts)}
	obj.OamOrganizeSetLtvA(5, uint16(oam.ORDER_CONFIG_RESET), tmpBytes, &dataList)

	//发送数据给基站
	if err := obj.psDlApi.PsDlSendOamDataToBts(int(dataModel.ProjectID), dataModel.BtsID, psmodel.MCP_A, psmodel.MCP_A_CONFIGURE, dataList.Bytes()); err != nil {
		return err
	}

	return nil
}
