//同步参数查询响应
// 秒寻科技
// zt 2024-10-03

package oam

import (
	"fmt"
	"ipsomc/module/bparam/bparammodel"
)

type OamRtc struct {
}

const (
	ORDER_SYNC_TIMER_CURRENT_TIME = 0x0700
	ORDER_SYNC_TIMER_SWITCH       = 0x0701
	ORDER_SYNC_TIMER_NUM          = 0x0702
	ORDER_SYNC_TIMER1_START       = 0x0703
	ORDER_SYNC_TIMER1_STOP        = 0x0704
	ORDER_SYNC_TIMER2_START       = 0x0705
	ORDER_SYNC_TIMER2_STOP        = 0x0706
)

// RTC参数查询响应
// dataModel:基站基本参数模型
// wCommand:监控命令
// datalist:数据队列
// wLen:队列长度
func (obj *OamRtc) OamRtcQueryResp(dataModel *bparammodel.BtsBaseParam, wCommand uint16, dataList []byte, wLen uint16) error {
	strTmp := ""

	switch wCommand {
	case ORDER_SYNC_TIMER_CURRENT_TIME:
		strTmp = obj.OamRtcParseDateTime(dataList)
		dataModel.RtcDateTime = strTmp
	case ORDER_SYNC_TIMER_SWITCH:
		dataModel.SyncTimerSwitch = uint8(dataList[0])
	case ORDER_SYNC_TIMER_NUM:
		dataModel.SyncTimerNum = uint8(dataList[0])
	case ORDER_SYNC_TIMER1_START:
		strTmp = obj.OamRtcParseTime(dataList)
		dataModel.SyncTimer1Start = strTmp
	case ORDER_SYNC_TIMER1_STOP:
		strTmp = obj.OamRtcParseTime(dataList)
		dataModel.SyncTimer1Stop = strTmp
	case ORDER_SYNC_TIMER2_START:
		strTmp = obj.OamRtcParseTime(dataList)
		dataModel.SyncTimer2Start = strTmp
	case ORDER_SYNC_TIMER2_STOP:
		strTmp = obj.OamRtcParseTime(dataList)
		dataModel.SyncTimer2Stop = strTmp
	default:
		break
	}

	return nil
}

// 将日期和时间转成字符串
func (obj *OamRtc) OamRtcParseDateTime(dateTimeList []byte) string {

	year := int(dateTimeList[5])
	year += 2000
	month := dateTimeList[4]
	day := dateTimeList[3]
	hour := dateTimeList[2]
	minute := dateTimeList[1]
	second := dateTimeList[0]
	rtcDateTime := fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second)

	return rtcDateTime
}

// 时间转成字符串
func (obj *OamRtc) OamRtcParseTime(timeList []byte) string {
	hour := timeList[1]
	minute := timeList[0]

	rtcTime := fmt.Sprintf("%02d:%02d", hour, minute)

	return rtcTime
}
