/// <summary> /// 覆写解析方法 /// </summary> /// <param name="header"></param> public override void analyze(string header) { this._Header = header; //StringBuilder sbUnitID = new StringBuilder(); //for (int i = 4; i < 19; i++) //{ // sbUnitID.Append(ASCII.Chr((int)SystemCode.HexNumberToDenary(this._Header.Substring(i * 2, 2), false, 8, 'u'))); //} string sbUnitID = ""; bool isNormal = false; string tmpchar; //将后面是00的抛弃 for (int i = 18; i >= 4; i--) { tmpchar = this._Header.Substring(i * 2, 2); if (!isNormal && !tmpchar.Equals("00")) { isNormal = true; } if (isNormal) { sbUnitID = ASCII.Chr((int)SystemCode.HexNumberToDenary(tmpchar, false, 8, 'u')) + sbUnitID; } } _CollectorCode = sbUnitID.ToString(); _CollectorCode = _CollectorCode.Replace("\0", "0");//临时处理非法测试数据 _Version = SystemCode.HexNumberToDenary(this._Header.Substring(19 * 2, 2 * 2), true, 16, 'u').ToString(); if (debug_collector.Equals(_CollectorCode)) { Console.WriteLine(""); } string ssss = this._Header.Substring(21 * 2, 6 * 2); int year = 2000 + (int)SystemCode.HexNumberToDenary(ssss.Substring(0, 2), true, 16, 'u') % 99; int moth = (int)SystemCode.HexNumberToDenary(ssss.Substring(2, 2), true, 16, 'u'); if (moth > 12) { moth = 12; } int day = (int)SystemCode.HexNumberToDenary(ssss.Substring(4, 2), true, 16, 'u'); if (day > 31) { day = 28; } int hh = (int)SystemCode.HexNumberToDenary(ssss.Substring(6, 2), true, 16, 'u'); if (hh > 23) { hh = 23; } int mm = (int)SystemCode.HexNumberToDenary(ssss.Substring(8, 2), true, 16, 'u'); if (mm > 60) { mm = 59; } int ss = (int)SystemCode.HexNumberToDenary(ssss.Substring(10, 2), true, 16, 'u'); if (ss > 60) { ss = 59; } this.TimeNow = new DateTime(year, moth, day, hh, mm, ss); string dayestr = SystemCode.ReversionAll(this._Header.Substring(31 * 2, 4 * 2)); _dayEnergy = (float)SystemCode.HexNumberToDenary(dayestr, false, 32, 'u'); //add in 8/6 for 原来是4字节无符号整形,改为无符号带一位小数整形 _dayEnergy = _dayEnergy * 0.1F; LogUtil.info("collector energy " + _dayEnergy); string totalstr = SystemCode.ReversionAll(this._Header.Substring(35 * 2, 4 * 2)); _totalEnergy = SystemCode.HexNumberToDenary(totalstr, false, 32, 'U'); string powerstr = SystemCode.ReversionAll(this._Header.Substring(27 * 2, 4 * 2)); _power = (int)SystemCode.HexNumberToDenary(powerstr, false, 32, 'u'); _power = float.Parse(Math.Round(_power / 1000, 3).ToString());//换算成kw _DevicesNum = (int)SystemCode.HexNumberToDenary(this._Header.Substring(39 * 2, 1 * 2), false, 8, 'u'); BugNum = (int)SystemCode.HexNumberToDenary(this._Header.Substring(40 * 2, 1 * 2), false, 8, 'u'); }
/// <summary> /// 覆写解析方法 /// </summary> /// <param name="header"></param> public override void analyze(string header) { this._Header = header; this.hasData = true; CollectorCode = getSn(header); _Version = SystemCode.HexNumberToDenary(this._Header.Substring(19 * 2, 2 * 2), true, 16, 'u').ToString(); if (debug_collector.Equals(_CollectorCode)) { Console.WriteLine(""); } string ssss = this._Header.Substring(21 * 2, 6 * 2); int year = 2000 + (int)SystemCode.HexNumberToDenary(ssss.Substring(0, 2), true, 16, 'u') % 99; int moth = (int)SystemCode.HexNumberToDenary(ssss.Substring(2, 2), true, 16, 'u'); if (moth > 12) { moth = 12; } int day = (int)SystemCode.HexNumberToDenary(ssss.Substring(4, 2), true, 16, 'u'); if (day > 31) { day = 28; } int hh = (int)SystemCode.HexNumberToDenary(ssss.Substring(6, 2), true, 16, 'u'); if (hh > 23) { hh = 23; } int mm = (int)SystemCode.HexNumberToDenary(ssss.Substring(8, 2), true, 16, 'u'); if (mm > 60) { mm = 59; } int ss = (int)SystemCode.HexNumberToDenary(ssss.Substring(10, 2), true, 16, 'u'); if (ss > 60) { ss = 59; } //临时代码 //if (day == 2) day = 4; //else if (day == 3) day = 5; this.TimeNow = new DateTime(year, moth, day, hh, mm, ss); LogUtil.info("collector TimeNow " + TimeNow.ToString()); string dayestr = SystemCode.ReversionAll(this._Header.Substring(31 * 2, 4 * 2)); _dayEnergy = (float)SystemCode.HexNumberToDenary(dayestr, false, 32, 'u'); //add in 8/6 for 原来是4字节无符号整形,改为无符号带一位小数整形 _dayEnergy = _dayEnergy * 0.1F; LogUtil.info("collector energy " + _dayEnergy); string totalstr = SystemCode.ReversionAll(this._Header.Substring(35 * 2, 4 * 2)); _totalEnergy = SystemCode.HexNumberToDenary(totalstr, false, 32, 'U'); string powerstr = SystemCode.ReversionAll(this._Header.Substring(27 * 2, 4 * 2)); _power = (int)SystemCode.HexNumberToDenary(powerstr, false, 32, 'u'); _power = float.Parse(Math.Round(_power.Value / 1000, 3).ToString());//换算成kw _DevicesNum = (int)SystemCode.HexNumberToDenary(this._Header.Substring(39 * 2, 1 * 2), false, 8, 'u'); BugNum = (int)SystemCode.HexNumberToDenary(this._Header.Substring(40 * 2, 1 * 2), false, 8, 'u'); base.hasData = true; this.issub = false; }