using System;
using System.Collections.Generic;
namespace BRServer
{
    public class BRCJTagHandler:TagHandler
    {
        public override void resolve(Tag tag,CasicSession session)
        {
            //TODO LIST:解析数据，保存数据
            UploadTag BRTag = tag as UploadTag;
            Interval = BRTag.CollectInter;
            CollecTime = BRTag.CollectTime;
            int len = BRTag.Len;
            String dataValue = BRTag.DataValue;

            DataList = new List<Object>();

            float sedimentation = strHexToSingle(dataValue.Substring(0, 8));
            DataList.Add(sedimentation);

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

        //网络序列转float
        private float strHexToSingle(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)                          
                               };
            return BitConverter.ToSingle(lBt, 0);
        }
    }
}
