using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BRServer.Model;
using System.Collections;

namespace BRServer
{
    public class TempTagHandler : TagHandler
    {
        public override void resolve(Tag tag, CasicSession session)
        {
            //TODO LIST:解析数据
            UploadTag tempTag = tag as UploadTag;
            Interval = tempTag.CollectInter;
            CollecTime = tempTag.CollectTime;
            int len = tempTag.Len;
            DataList = new List<Object>();

            String dataValue = tempTag.DataValue;

            float temp = strHexToFloat(dataValue.Substring(0, 8));
            DataList.Add(temp);

            session.Logger.Info("沉降监测仪数据上传，温度TAG：oid：" + tempTag.Oid + " 采集间隔: " +
                Interval + " 采集时间：" + CollecTime + " 上传数值：" + dataValue);
        }

        //网络序列转float
        private float strHexToFloat(String src)
        {
            if (src.Length != 8)
                return 0;

            byte[] lBt ={
                                   byte.Parse(src.Substring(0,2),System.Globalization.NumberStyles.HexNumber),
                                   byte.Parse(src.Substring(2,2),System.Globalization.NumberStyles.HexNumber),
                                   byte.Parse(src.Substring(4,2),System.Globalization.NumberStyles.HexNumber),
                                   byte.Parse(src.Substring(6,2),System.Globalization.NumberStyles.HexNumber)
                                 
                               };
            float ss = BitConverter.ToSingle(lBt, 0);
            return ss;
        }

    }
}
