using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FLY.FeedbackRenZiJia.Common { public class FlyData_BoltHeatRecord { /// /// 稳定历史 /// public BoltHeatRecord[] StableList; /// /// 不稳定列表 /// public BoltHeatRecord[] UnstableList; public byte[] ToBytes() { List buf = new List(); buf.AddRange(BitConverter.GetBytes(StableList.Count()));//4 for (int i = 0; i < StableList.Count(); i++) buf.AddRange(StableList[i].ToBytes());//16 buf.AddRange(BitConverter.GetBytes(UnstableList.Count()));//4 for (int i = 0; i < UnstableList.Count(); i++) buf.AddRange(UnstableList[i].ToBytes());//16 return buf.ToArray(); } public bool TryParse(byte[] value) { int cnt; return TryParse(value, 0, out cnt); } public bool TryParse(byte[] value, int index, out int cnt) { int idx = index; cnt = 4; if (value.Length < (index + cnt)) return false; int len = BitConverter.ToInt32(value, idx); idx += 4; if (len > 0) { cnt += len * 20; if (value.Length < (index + cnt)) return false; StableList = new BoltHeatRecord[len]; for (int i = 0; i < len; i++) { BoltHeatRecord r = new BoltHeatRecord(); r.TryParse(value, idx); StableList[i] = r; idx += 20; } } cnt += 4; if (value.Length < (index + cnt)) return false; len = BitConverter.ToInt32(value, idx); idx += 4; if (len > 0) { cnt += len * 20; if (value.Length < (index + cnt)) return false; UnstableList = new BoltHeatRecord[len]; for (int i = 0; i < len; i++) { BoltHeatRecord r = new BoltHeatRecord(); r.TryParse(value, idx); UnstableList[i] = r; idx += 20; } } return true; } } /// /// [厚度%差,厚度%差中值,加热%滤波 差,加热%滤波 差中值]] /// public class BoltHeatRecord { public int ThickDiff { get; set; } public int ThickMid { get; set; } public int HeatDiff { get; set; } public int HeatMid { get; set; } /// /// 次数 /// public int Cnt { get; set; } public BoltHeatRecord() { Cnt = 1; } public int Thick0 { get { return ThickMid + ThickDiff / 2; } } public int Thick1 { get { return ThickMid - ThickDiff / 2; } } public int Heat0 { get { return HeatMid + HeatDiff / 2; } } public int Heat1 { get { return HeatMid - HeatDiff / 2; } } public bool IsSameThick(int thick, int range) { if (Math.Abs(thick - Thick0) <= range) return true; if (Math.Abs(thick - Thick1) <= range) return true; return false; } public byte[] ToBytes() { List buf = new List(); buf.AddRange(BitConverter.GetBytes(Cnt));//4 buf.AddRange(BitConverter.GetBytes(ThickDiff));//4 buf.AddRange(BitConverter.GetBytes(ThickMid));//4 buf.AddRange(BitConverter.GetBytes(HeatDiff));//4 buf.AddRange(BitConverter.GetBytes(HeatMid));//4 return buf.ToArray(); } /// /// 20 byte /// /// /// public bool TryParse(byte[] value) { return TryParse(value, 0); } /// /// 20 byte /// /// /// /// /// public bool TryParse(byte[] value, int index) { int cnt = 4 * 5; if (value.Length < (index + cnt)) return false; int idx = index; Cnt = BitConverter.ToInt32(value, idx); idx += 4; ThickDiff = BitConverter.ToInt32(value, idx); idx += 4; ThickMid = BitConverter.ToInt32(value, idx); idx += 4; HeatDiff = BitConverter.ToInt32(value, idx); idx += 4; HeatMid = BitConverter.ToInt32(value, idx); idx += 4; return true; } } }