diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index bbac218..85614e0 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -202,6 +202,8 @@ + + diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index bbac218..85614e0 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -202,6 +202,8 @@ + + diff --git a/Correlator/SensorHubTag/CellTag.cs b/Correlator/SensorHubTag/CellTag.cs index 87b838b..1eb26d6 100644 --- a/Correlator/SensorHubTag/CellTag.cs +++ b/Correlator/SensorHubTag/CellTag.cs @@ -1,15 +1,17 @@ -namespace Correlator.SensorHubTag +using System; +using System.Diagnostics; + +namespace Correlator.SensorHubTag { public class CellTag : Tag { public string Cell { get; set; } - public const string CellTagOid = "60000020"; - public CellTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btCell = dataValue[0]; - Cell = btCell + ""; + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + Cell = Convert.ToInt32(hex, 16).ToString(); + Debug.WriteLine($"CellTag => [Oid:{oid}, Cell:{Cell}]"); } } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index bbac218..85614e0 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -202,6 +202,8 @@ + + diff --git a/Correlator/SensorHubTag/CellTag.cs b/Correlator/SensorHubTag/CellTag.cs index 87b838b..1eb26d6 100644 --- a/Correlator/SensorHubTag/CellTag.cs +++ b/Correlator/SensorHubTag/CellTag.cs @@ -1,15 +1,17 @@ -namespace Correlator.SensorHubTag +using System; +using System.Diagnostics; + +namespace Correlator.SensorHubTag { public class CellTag : Tag { public string Cell { get; set; } - public const string CellTagOid = "60000020"; - public CellTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btCell = dataValue[0]; - Cell = btCell + ""; + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + Cell = Convert.ToInt32(hex, 16).ToString(); + Debug.WriteLine($"CellTag => [Oid:{oid}, Cell:{Cell}]"); } } } \ No newline at end of file diff --git a/Correlator/SensorHubTag/SensorExceptionTag.cs b/Correlator/SensorHubTag/SensorExceptionTag.cs index cc2bdb5..ba0c09b 100644 --- a/Correlator/SensorHubTag/SensorExceptionTag.cs +++ b/Correlator/SensorHubTag/SensorExceptionTag.cs @@ -2,8 +2,6 @@ { public class SensorExceptionTag : Tag { - public const string SensorExceptionTagOid = "60000009"; - public string State { get; set; } public SensorExceptionTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index bbac218..85614e0 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -202,6 +202,8 @@ + + diff --git a/Correlator/SensorHubTag/CellTag.cs b/Correlator/SensorHubTag/CellTag.cs index 87b838b..1eb26d6 100644 --- a/Correlator/SensorHubTag/CellTag.cs +++ b/Correlator/SensorHubTag/CellTag.cs @@ -1,15 +1,17 @@ -namespace Correlator.SensorHubTag +using System; +using System.Diagnostics; + +namespace Correlator.SensorHubTag { public class CellTag : Tag { public string Cell { get; set; } - public const string CellTagOid = "60000020"; - public CellTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btCell = dataValue[0]; - Cell = btCell + ""; + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + Cell = Convert.ToInt32(hex, 16).ToString(); + Debug.WriteLine($"CellTag => [Oid:{oid}, Cell:{Cell}]"); } } } \ No newline at end of file diff --git a/Correlator/SensorHubTag/SensorExceptionTag.cs b/Correlator/SensorHubTag/SensorExceptionTag.cs index cc2bdb5..ba0c09b 100644 --- a/Correlator/SensorHubTag/SensorExceptionTag.cs +++ b/Correlator/SensorHubTag/SensorExceptionTag.cs @@ -2,8 +2,6 @@ { public class SensorExceptionTag : Tag { - public const string SensorExceptionTagOid = "60000009"; - public string State { get; set; } public SensorExceptionTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) diff --git a/Correlator/SensorHubTag/TagFactory.cs b/Correlator/SensorHubTag/TagFactory.cs index 03d9e20..b61f55b 100644 --- a/Correlator/SensorHubTag/TagFactory.cs +++ b/Correlator/SensorHubTag/TagFactory.cs @@ -7,19 +7,26 @@ Tag tag; if (UploadTag.IsUploadTag(oid)) { + //关键数据存在此Tag中 tag = new UploadTag(oid, len, value); } - else if (oid == CellTag.CellTagOid) - { - tag = new CellTag(oid, len, value); - } - else if (oid == SensorExceptionTag.SensorExceptionTagOid) - { - tag = new SensorExceptionTag(oid, len, value); - } else { - tag = new NormalTag(oid, len, value); + switch (oid) + { + case TagOid.CellTagOid: + tag = new CellTag(oid, len, value); + break; + case TagOid.TimeTagOid: + tag = new TimeTag(oid, len, value); + break; + case TagOid.ExceptionTagOid: + tag = new SensorExceptionTag(oid, len, value); + break; + default: + tag = new NormalTag(oid, len, value); + break; + } } return tag; diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index bbac218..85614e0 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -202,6 +202,8 @@ + + diff --git a/Correlator/SensorHubTag/CellTag.cs b/Correlator/SensorHubTag/CellTag.cs index 87b838b..1eb26d6 100644 --- a/Correlator/SensorHubTag/CellTag.cs +++ b/Correlator/SensorHubTag/CellTag.cs @@ -1,15 +1,17 @@ -namespace Correlator.SensorHubTag +using System; +using System.Diagnostics; + +namespace Correlator.SensorHubTag { public class CellTag : Tag { public string Cell { get; set; } - public const string CellTagOid = "60000020"; - public CellTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btCell = dataValue[0]; - Cell = btCell + ""; + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + Cell = Convert.ToInt32(hex, 16).ToString(); + Debug.WriteLine($"CellTag => [Oid:{oid}, Cell:{Cell}]"); } } } \ No newline at end of file diff --git a/Correlator/SensorHubTag/SensorExceptionTag.cs b/Correlator/SensorHubTag/SensorExceptionTag.cs index cc2bdb5..ba0c09b 100644 --- a/Correlator/SensorHubTag/SensorExceptionTag.cs +++ b/Correlator/SensorHubTag/SensorExceptionTag.cs @@ -2,8 +2,6 @@ { public class SensorExceptionTag : Tag { - public const string SensorExceptionTagOid = "60000009"; - public string State { get; set; } public SensorExceptionTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) diff --git a/Correlator/SensorHubTag/TagFactory.cs b/Correlator/SensorHubTag/TagFactory.cs index 03d9e20..b61f55b 100644 --- a/Correlator/SensorHubTag/TagFactory.cs +++ b/Correlator/SensorHubTag/TagFactory.cs @@ -7,19 +7,26 @@ Tag tag; if (UploadTag.IsUploadTag(oid)) { + //关键数据存在此Tag中 tag = new UploadTag(oid, len, value); } - else if (oid == CellTag.CellTagOid) - { - tag = new CellTag(oid, len, value); - } - else if (oid == SensorExceptionTag.SensorExceptionTagOid) - { - tag = new SensorExceptionTag(oid, len, value); - } else { - tag = new NormalTag(oid, len, value); + switch (oid) + { + case TagOid.CellTagOid: + tag = new CellTag(oid, len, value); + break; + case TagOid.TimeTagOid: + tag = new TimeTag(oid, len, value); + break; + case TagOid.ExceptionTagOid: + tag = new SensorExceptionTag(oid, len, value); + break; + default: + tag = new NormalTag(oid, len, value); + break; + } } return tag; diff --git a/Correlator/SensorHubTag/TagOid.cs b/Correlator/SensorHubTag/TagOid.cs new file mode 100644 index 0000000..9ac368f --- /dev/null +++ b/Correlator/SensorHubTag/TagOid.cs @@ -0,0 +1,9 @@ +namespace Correlator.SensorHubTag +{ + public class TagOid + { + public const string CellTagOid = "60000020"; + public const string TimeTagOid = "10000051"; + public const string ExceptionTagOid = "60000009"; + } +} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index bbac218..85614e0 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -202,6 +202,8 @@ + + diff --git a/Correlator/SensorHubTag/CellTag.cs b/Correlator/SensorHubTag/CellTag.cs index 87b838b..1eb26d6 100644 --- a/Correlator/SensorHubTag/CellTag.cs +++ b/Correlator/SensorHubTag/CellTag.cs @@ -1,15 +1,17 @@ -namespace Correlator.SensorHubTag +using System; +using System.Diagnostics; + +namespace Correlator.SensorHubTag { public class CellTag : Tag { public string Cell { get; set; } - public const string CellTagOid = "60000020"; - public CellTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btCell = dataValue[0]; - Cell = btCell + ""; + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + Cell = Convert.ToInt32(hex, 16).ToString(); + Debug.WriteLine($"CellTag => [Oid:{oid}, Cell:{Cell}]"); } } } \ No newline at end of file diff --git a/Correlator/SensorHubTag/SensorExceptionTag.cs b/Correlator/SensorHubTag/SensorExceptionTag.cs index cc2bdb5..ba0c09b 100644 --- a/Correlator/SensorHubTag/SensorExceptionTag.cs +++ b/Correlator/SensorHubTag/SensorExceptionTag.cs @@ -2,8 +2,6 @@ { public class SensorExceptionTag : Tag { - public const string SensorExceptionTagOid = "60000009"; - public string State { get; set; } public SensorExceptionTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) diff --git a/Correlator/SensorHubTag/TagFactory.cs b/Correlator/SensorHubTag/TagFactory.cs index 03d9e20..b61f55b 100644 --- a/Correlator/SensorHubTag/TagFactory.cs +++ b/Correlator/SensorHubTag/TagFactory.cs @@ -7,19 +7,26 @@ Tag tag; if (UploadTag.IsUploadTag(oid)) { + //关键数据存在此Tag中 tag = new UploadTag(oid, len, value); } - else if (oid == CellTag.CellTagOid) - { - tag = new CellTag(oid, len, value); - } - else if (oid == SensorExceptionTag.SensorExceptionTagOid) - { - tag = new SensorExceptionTag(oid, len, value); - } else { - tag = new NormalTag(oid, len, value); + switch (oid) + { + case TagOid.CellTagOid: + tag = new CellTag(oid, len, value); + break; + case TagOid.TimeTagOid: + tag = new TimeTag(oid, len, value); + break; + case TagOid.ExceptionTagOid: + tag = new SensorExceptionTag(oid, len, value); + break; + default: + tag = new NormalTag(oid, len, value); + break; + } } return tag; diff --git a/Correlator/SensorHubTag/TagOid.cs b/Correlator/SensorHubTag/TagOid.cs new file mode 100644 index 0000000..9ac368f --- /dev/null +++ b/Correlator/SensorHubTag/TagOid.cs @@ -0,0 +1,9 @@ +namespace Correlator.SensorHubTag +{ + public class TagOid + { + public const string CellTagOid = "60000020"; + public const string TimeTagOid = "10000051"; + public const string ExceptionTagOid = "60000009"; + } +} \ No newline at end of file diff --git a/Correlator/SensorHubTag/TimeTag.cs b/Correlator/SensorHubTag/TimeTag.cs new file mode 100644 index 0000000..b83a915 --- /dev/null +++ b/Correlator/SensorHubTag/TimeTag.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using Correlator.Util; + +namespace Correlator.SensorHubTag +{ + public class TimeTag : Tag + { + public string Time { get; set; } + + public TimeTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) + { + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + var temp = new List(); + for (var i = 0; i < hex.Length; i += 2) + { + temp.Add(hex.Substring(i, 2)); + } + + var timeBuilder = new StringBuilder(); + var year = $"{Convert.ToInt32(temp[0], 16) + 2000}"; + var month = Convert.ToInt32(temp[1], 16).AppendLeftZero(); + var day = Convert.ToInt32(temp[2], 16).AppendLeftZero(); + var hour = Convert.ToInt32(temp[3], 16).AppendLeftZero(); + var minute = Convert.ToInt32(temp[4], 16).AppendLeftZero(); + var seconds = Convert.ToInt32(temp[5], 16).AppendLeftZero(); + timeBuilder.Append(year).Append(month).Append(day).Append(hour).Append(minute).Append(seconds); + Time = timeBuilder.ToString(); + Debug.WriteLine($"TimeTag => [Oid:{oid}, Time:{Time}]"); + } + } +} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index bbac218..85614e0 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -202,6 +202,8 @@ + + diff --git a/Correlator/SensorHubTag/CellTag.cs b/Correlator/SensorHubTag/CellTag.cs index 87b838b..1eb26d6 100644 --- a/Correlator/SensorHubTag/CellTag.cs +++ b/Correlator/SensorHubTag/CellTag.cs @@ -1,15 +1,17 @@ -namespace Correlator.SensorHubTag +using System; +using System.Diagnostics; + +namespace Correlator.SensorHubTag { public class CellTag : Tag { public string Cell { get; set; } - public const string CellTagOid = "60000020"; - public CellTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btCell = dataValue[0]; - Cell = btCell + ""; + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + Cell = Convert.ToInt32(hex, 16).ToString(); + Debug.WriteLine($"CellTag => [Oid:{oid}, Cell:{Cell}]"); } } } \ No newline at end of file diff --git a/Correlator/SensorHubTag/SensorExceptionTag.cs b/Correlator/SensorHubTag/SensorExceptionTag.cs index cc2bdb5..ba0c09b 100644 --- a/Correlator/SensorHubTag/SensorExceptionTag.cs +++ b/Correlator/SensorHubTag/SensorExceptionTag.cs @@ -2,8 +2,6 @@ { public class SensorExceptionTag : Tag { - public const string SensorExceptionTagOid = "60000009"; - public string State { get; set; } public SensorExceptionTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) diff --git a/Correlator/SensorHubTag/TagFactory.cs b/Correlator/SensorHubTag/TagFactory.cs index 03d9e20..b61f55b 100644 --- a/Correlator/SensorHubTag/TagFactory.cs +++ b/Correlator/SensorHubTag/TagFactory.cs @@ -7,19 +7,26 @@ Tag tag; if (UploadTag.IsUploadTag(oid)) { + //关键数据存在此Tag中 tag = new UploadTag(oid, len, value); } - else if (oid == CellTag.CellTagOid) - { - tag = new CellTag(oid, len, value); - } - else if (oid == SensorExceptionTag.SensorExceptionTagOid) - { - tag = new SensorExceptionTag(oid, len, value); - } else { - tag = new NormalTag(oid, len, value); + switch (oid) + { + case TagOid.CellTagOid: + tag = new CellTag(oid, len, value); + break; + case TagOid.TimeTagOid: + tag = new TimeTag(oid, len, value); + break; + case TagOid.ExceptionTagOid: + tag = new SensorExceptionTag(oid, len, value); + break; + default: + tag = new NormalTag(oid, len, value); + break; + } } return tag; diff --git a/Correlator/SensorHubTag/TagOid.cs b/Correlator/SensorHubTag/TagOid.cs new file mode 100644 index 0000000..9ac368f --- /dev/null +++ b/Correlator/SensorHubTag/TagOid.cs @@ -0,0 +1,9 @@ +namespace Correlator.SensorHubTag +{ + public class TagOid + { + public const string CellTagOid = "60000020"; + public const string TimeTagOid = "10000051"; + public const string ExceptionTagOid = "60000009"; + } +} \ No newline at end of file diff --git a/Correlator/SensorHubTag/TimeTag.cs b/Correlator/SensorHubTag/TimeTag.cs new file mode 100644 index 0000000..b83a915 --- /dev/null +++ b/Correlator/SensorHubTag/TimeTag.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using Correlator.Util; + +namespace Correlator.SensorHubTag +{ + public class TimeTag : Tag + { + public string Time { get; set; } + + public TimeTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) + { + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + var temp = new List(); + for (var i = 0; i < hex.Length; i += 2) + { + temp.Add(hex.Substring(i, 2)); + } + + var timeBuilder = new StringBuilder(); + var year = $"{Convert.ToInt32(temp[0], 16) + 2000}"; + var month = Convert.ToInt32(temp[1], 16).AppendLeftZero(); + var day = Convert.ToInt32(temp[2], 16).AppendLeftZero(); + var hour = Convert.ToInt32(temp[3], 16).AppendLeftZero(); + var minute = Convert.ToInt32(temp[4], 16).AppendLeftZero(); + var seconds = Convert.ToInt32(temp[5], 16).AppendLeftZero(); + timeBuilder.Append(year).Append(month).Append(day).Append(hour).Append(minute).Append(seconds); + Time = timeBuilder.ToString(); + Debug.WriteLine($"TimeTag => [Oid:{oid}, Time:{Time}]"); + } + } +} \ No newline at end of file diff --git a/Correlator/SensorHubTag/UploadTag.cs b/Correlator/SensorHubTag/UploadTag.cs index 47749e4..d0523b0 100644 --- a/Correlator/SensorHubTag/UploadTag.cs +++ b/Correlator/SensorHubTag/UploadTag.cs @@ -1,4 +1,7 @@ -using System.Globalization; +using System; +using System.Diagnostics; +using System.Globalization; +using Correlator.Util; namespace Correlator.SensorHubTag { @@ -25,7 +28,7 @@ public UploadTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btPduType = int.Parse(this.Oid, NumberStyles.HexNumber); + var btPduType = int.Parse(Oid, NumberStyles.HexNumber); BizType = (btPduType >> 24) & 0x0F; //转换采集间隔 @@ -35,6 +38,9 @@ var minute = collectMin % 60; var hour = collectMin / 60; CollectTime = hour + ":" + minute + ":00"; + + var s = BitConverter.ToString(dataValue).Replace("-", ""); + Debug.WriteLine($"UploadTag => [Oid:{oid}, BizType:{BizType.ToChineseType()}]"); } } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index bbac218..85614e0 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -202,6 +202,8 @@ + + diff --git a/Correlator/SensorHubTag/CellTag.cs b/Correlator/SensorHubTag/CellTag.cs index 87b838b..1eb26d6 100644 --- a/Correlator/SensorHubTag/CellTag.cs +++ b/Correlator/SensorHubTag/CellTag.cs @@ -1,15 +1,17 @@ -namespace Correlator.SensorHubTag +using System; +using System.Diagnostics; + +namespace Correlator.SensorHubTag { public class CellTag : Tag { public string Cell { get; set; } - public const string CellTagOid = "60000020"; - public CellTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btCell = dataValue[0]; - Cell = btCell + ""; + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + Cell = Convert.ToInt32(hex, 16).ToString(); + Debug.WriteLine($"CellTag => [Oid:{oid}, Cell:{Cell}]"); } } } \ No newline at end of file diff --git a/Correlator/SensorHubTag/SensorExceptionTag.cs b/Correlator/SensorHubTag/SensorExceptionTag.cs index cc2bdb5..ba0c09b 100644 --- a/Correlator/SensorHubTag/SensorExceptionTag.cs +++ b/Correlator/SensorHubTag/SensorExceptionTag.cs @@ -2,8 +2,6 @@ { public class SensorExceptionTag : Tag { - public const string SensorExceptionTagOid = "60000009"; - public string State { get; set; } public SensorExceptionTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) diff --git a/Correlator/SensorHubTag/TagFactory.cs b/Correlator/SensorHubTag/TagFactory.cs index 03d9e20..b61f55b 100644 --- a/Correlator/SensorHubTag/TagFactory.cs +++ b/Correlator/SensorHubTag/TagFactory.cs @@ -7,19 +7,26 @@ Tag tag; if (UploadTag.IsUploadTag(oid)) { + //关键数据存在此Tag中 tag = new UploadTag(oid, len, value); } - else if (oid == CellTag.CellTagOid) - { - tag = new CellTag(oid, len, value); - } - else if (oid == SensorExceptionTag.SensorExceptionTagOid) - { - tag = new SensorExceptionTag(oid, len, value); - } else { - tag = new NormalTag(oid, len, value); + switch (oid) + { + case TagOid.CellTagOid: + tag = new CellTag(oid, len, value); + break; + case TagOid.TimeTagOid: + tag = new TimeTag(oid, len, value); + break; + case TagOid.ExceptionTagOid: + tag = new SensorExceptionTag(oid, len, value); + break; + default: + tag = new NormalTag(oid, len, value); + break; + } } return tag; diff --git a/Correlator/SensorHubTag/TagOid.cs b/Correlator/SensorHubTag/TagOid.cs new file mode 100644 index 0000000..9ac368f --- /dev/null +++ b/Correlator/SensorHubTag/TagOid.cs @@ -0,0 +1,9 @@ +namespace Correlator.SensorHubTag +{ + public class TagOid + { + public const string CellTagOid = "60000020"; + public const string TimeTagOid = "10000051"; + public const string ExceptionTagOid = "60000009"; + } +} \ No newline at end of file diff --git a/Correlator/SensorHubTag/TimeTag.cs b/Correlator/SensorHubTag/TimeTag.cs new file mode 100644 index 0000000..b83a915 --- /dev/null +++ b/Correlator/SensorHubTag/TimeTag.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using Correlator.Util; + +namespace Correlator.SensorHubTag +{ + public class TimeTag : Tag + { + public string Time { get; set; } + + public TimeTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) + { + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + var temp = new List(); + for (var i = 0; i < hex.Length; i += 2) + { + temp.Add(hex.Substring(i, 2)); + } + + var timeBuilder = new StringBuilder(); + var year = $"{Convert.ToInt32(temp[0], 16) + 2000}"; + var month = Convert.ToInt32(temp[1], 16).AppendLeftZero(); + var day = Convert.ToInt32(temp[2], 16).AppendLeftZero(); + var hour = Convert.ToInt32(temp[3], 16).AppendLeftZero(); + var minute = Convert.ToInt32(temp[4], 16).AppendLeftZero(); + var seconds = Convert.ToInt32(temp[5], 16).AppendLeftZero(); + timeBuilder.Append(year).Append(month).Append(day).Append(hour).Append(minute).Append(seconds); + Time = timeBuilder.ToString(); + Debug.WriteLine($"TimeTag => [Oid:{oid}, Time:{Time}]"); + } + } +} \ No newline at end of file diff --git a/Correlator/SensorHubTag/UploadTag.cs b/Correlator/SensorHubTag/UploadTag.cs index 47749e4..d0523b0 100644 --- a/Correlator/SensorHubTag/UploadTag.cs +++ b/Correlator/SensorHubTag/UploadTag.cs @@ -1,4 +1,7 @@ -using System.Globalization; +using System; +using System.Diagnostics; +using System.Globalization; +using Correlator.Util; namespace Correlator.SensorHubTag { @@ -25,7 +28,7 @@ public UploadTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btPduType = int.Parse(this.Oid, NumberStyles.HexNumber); + var btPduType = int.Parse(Oid, NumberStyles.HexNumber); BizType = (btPduType >> 24) & 0x0F; //转换采集间隔 @@ -35,6 +38,9 @@ var minute = collectMin % 60; var hour = collectMin / 60; CollectTime = hour + ":" + minute + ":00"; + + var s = BitConverter.ToString(dataValue).Replace("-", ""); + Debug.WriteLine($"UploadTag => [Oid:{oid}, BizType:{BizType.ToChineseType()}]"); } } } \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 3fbaebb..39028d5 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -63,6 +63,12 @@ return ((decimal)d).ToString("G").PadRight(16, '0'); } + public static string AppendLeftZero(this int i) + { + //数据固定长度2 + return i.ToString("G").PadLeft(2, '0'); + } + public static string To16HexString(this string src) { if (src.Length == 4) @@ -266,5 +272,23 @@ return tempBytes.ToArray(); } + + public static string ToChineseType(this int i) + { + //1,2,3,4分别代表流量、压力、液位、噪声 + switch (i) + { + case 1: + return "流量数据"; + case 2: + return "压力数据"; + case 3: + return "液位数据"; + case 4: + return "噪声数据"; + default: + return "未知类型数据"; + } + } } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index bbac218..85614e0 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -202,6 +202,8 @@ + + diff --git a/Correlator/SensorHubTag/CellTag.cs b/Correlator/SensorHubTag/CellTag.cs index 87b838b..1eb26d6 100644 --- a/Correlator/SensorHubTag/CellTag.cs +++ b/Correlator/SensorHubTag/CellTag.cs @@ -1,15 +1,17 @@ -namespace Correlator.SensorHubTag +using System; +using System.Diagnostics; + +namespace Correlator.SensorHubTag { public class CellTag : Tag { public string Cell { get; set; } - public const string CellTagOid = "60000020"; - public CellTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btCell = dataValue[0]; - Cell = btCell + ""; + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + Cell = Convert.ToInt32(hex, 16).ToString(); + Debug.WriteLine($"CellTag => [Oid:{oid}, Cell:{Cell}]"); } } } \ No newline at end of file diff --git a/Correlator/SensorHubTag/SensorExceptionTag.cs b/Correlator/SensorHubTag/SensorExceptionTag.cs index cc2bdb5..ba0c09b 100644 --- a/Correlator/SensorHubTag/SensorExceptionTag.cs +++ b/Correlator/SensorHubTag/SensorExceptionTag.cs @@ -2,8 +2,6 @@ { public class SensorExceptionTag : Tag { - public const string SensorExceptionTagOid = "60000009"; - public string State { get; set; } public SensorExceptionTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) diff --git a/Correlator/SensorHubTag/TagFactory.cs b/Correlator/SensorHubTag/TagFactory.cs index 03d9e20..b61f55b 100644 --- a/Correlator/SensorHubTag/TagFactory.cs +++ b/Correlator/SensorHubTag/TagFactory.cs @@ -7,19 +7,26 @@ Tag tag; if (UploadTag.IsUploadTag(oid)) { + //关键数据存在此Tag中 tag = new UploadTag(oid, len, value); } - else if (oid == CellTag.CellTagOid) - { - tag = new CellTag(oid, len, value); - } - else if (oid == SensorExceptionTag.SensorExceptionTagOid) - { - tag = new SensorExceptionTag(oid, len, value); - } else { - tag = new NormalTag(oid, len, value); + switch (oid) + { + case TagOid.CellTagOid: + tag = new CellTag(oid, len, value); + break; + case TagOid.TimeTagOid: + tag = new TimeTag(oid, len, value); + break; + case TagOid.ExceptionTagOid: + tag = new SensorExceptionTag(oid, len, value); + break; + default: + tag = new NormalTag(oid, len, value); + break; + } } return tag; diff --git a/Correlator/SensorHubTag/TagOid.cs b/Correlator/SensorHubTag/TagOid.cs new file mode 100644 index 0000000..9ac368f --- /dev/null +++ b/Correlator/SensorHubTag/TagOid.cs @@ -0,0 +1,9 @@ +namespace Correlator.SensorHubTag +{ + public class TagOid + { + public const string CellTagOid = "60000020"; + public const string TimeTagOid = "10000051"; + public const string ExceptionTagOid = "60000009"; + } +} \ No newline at end of file diff --git a/Correlator/SensorHubTag/TimeTag.cs b/Correlator/SensorHubTag/TimeTag.cs new file mode 100644 index 0000000..b83a915 --- /dev/null +++ b/Correlator/SensorHubTag/TimeTag.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using Correlator.Util; + +namespace Correlator.SensorHubTag +{ + public class TimeTag : Tag + { + public string Time { get; set; } + + public TimeTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) + { + var hex = BitConverter.ToString(dataValue).Replace("-", ""); + var temp = new List(); + for (var i = 0; i < hex.Length; i += 2) + { + temp.Add(hex.Substring(i, 2)); + } + + var timeBuilder = new StringBuilder(); + var year = $"{Convert.ToInt32(temp[0], 16) + 2000}"; + var month = Convert.ToInt32(temp[1], 16).AppendLeftZero(); + var day = Convert.ToInt32(temp[2], 16).AppendLeftZero(); + var hour = Convert.ToInt32(temp[3], 16).AppendLeftZero(); + var minute = Convert.ToInt32(temp[4], 16).AppendLeftZero(); + var seconds = Convert.ToInt32(temp[5], 16).AppendLeftZero(); + timeBuilder.Append(year).Append(month).Append(day).Append(hour).Append(minute).Append(seconds); + Time = timeBuilder.ToString(); + Debug.WriteLine($"TimeTag => [Oid:{oid}, Time:{Time}]"); + } + } +} \ No newline at end of file diff --git a/Correlator/SensorHubTag/UploadTag.cs b/Correlator/SensorHubTag/UploadTag.cs index 47749e4..d0523b0 100644 --- a/Correlator/SensorHubTag/UploadTag.cs +++ b/Correlator/SensorHubTag/UploadTag.cs @@ -1,4 +1,7 @@ -using System.Globalization; +using System; +using System.Diagnostics; +using System.Globalization; +using Correlator.Util; namespace Correlator.SensorHubTag { @@ -25,7 +28,7 @@ public UploadTag(string oid, int len, byte[] dataValue) : base(oid, len, dataValue) { - var btPduType = int.Parse(this.Oid, NumberStyles.HexNumber); + var btPduType = int.Parse(Oid, NumberStyles.HexNumber); BizType = (btPduType >> 24) & 0x0F; //转换采集间隔 @@ -35,6 +38,9 @@ var minute = collectMin % 60; var hour = collectMin / 60; CollectTime = hour + ":" + minute + ":00"; + + var s = BitConverter.ToString(dataValue).Replace("-", ""); + Debug.WriteLine($"UploadTag => [Oid:{oid}, BizType:{BizType.ToChineseType()}]"); } } } \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 3fbaebb..39028d5 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -63,6 +63,12 @@ return ((decimal)d).ToString("G").PadRight(16, '0'); } + public static string AppendLeftZero(this int i) + { + //数据固定长度2 + return i.ToString("G").PadLeft(2, '0'); + } + public static string To16HexString(this string src) { if (src.Length == 4) @@ -266,5 +272,23 @@ return tempBytes.ToArray(); } + + public static string ToChineseType(this int i) + { + //1,2,3,4分别代表流量、压力、液位、噪声 + switch (i) + { + case 1: + return "流量数据"; + case 2: + return "压力数据"; + case 3: + return "液位数据"; + case 4: + return "噪声数据"; + default: + return "未知类型数据"; + } + } } } \ No newline at end of file diff --git a/Correlator/ViewModel/HomePageProViewModel.cs b/Correlator/ViewModel/HomePageProViewModel.cs index 77c5762..dbfa00c 100644 --- a/Correlator/ViewModel/HomePageProViewModel.cs +++ b/Correlator/ViewModel/HomePageProViewModel.cs @@ -707,7 +707,6 @@ Owner = _homePageWindow }; speedDialog.ShowDialog(); - // new CheckResponseDialog { Owner = _homePageWindow }.Show(); }); ImportDataCommand = new RelayCommand(delegate