public static List <Identifier> analyse2(string Remain, out string msg) { List <Identifier> List_Identifier = new List <Identifier>(); try { while (Remain.Length >= 4) { byte Key = Convert.ToByte(Remain.Substring(0, 2), 16); if (Key == (byte)Identifier_Standard._FF) { byte IdentifierSub = Convert.ToByte(Remain.Substring(2, 2), 16); if (IdentifierSub == (byte)Identifier_Custom._03) { Identifier_FF_03 iden = new Identifier_FF_03(); List_Identifier.Add(iden); Remain = Remain.Substring(6); } else if (IdentifierSub == (byte)Identifier_Custom._0E) { Identifier_FF_0E iden = new Identifier_FF_0E(); List_Identifier.Add(iden); Remain = Remain.Substring(6); } else { msg = "非法自定义标识符" + IdentifierSub + "" + " " + Remain; return(null); } } else if (Key == (byte)Identifier_Standard._F0) { Identifier_F0 iden = new Identifier_F0(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._F1) { Identifier_F1 iden = new Identifier_F1(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._F2) { Identifier_F2 iden = new Identifier_F2(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._F3) { Identifier_F3 iden = new Identifier_F3(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._F4) { Identifier_F4 iden = new Identifier_F4(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._F5) { Identifier_F5 iden = new Identifier_F5(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._F6) { Identifier_F6 iden = new Identifier_F6(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._F7) { Identifier_F7 iden = new Identifier_F7(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._F8) { Identifier_F8 iden = new Identifier_F8(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._F9) { Identifier_F9 iden = new Identifier_F9(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._FA) { Identifier_FA iden = new Identifier_FA(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._FB) { Identifier_FB iden = new Identifier_FB(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._FC) { Identifier_FC iden = new Identifier_FC(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else if (Key == (byte)Identifier_Standard._FD) { Identifier_FD iden = new Identifier_FD(); List_Identifier.Add(iden); Remain = Remain.Substring(4); } else { Identifier iden; if (Key == (byte)Identifier_Standard._03) { iden = new Identifier_03(); } else if (Key == (byte)Identifier_Standard._04) { iden = new Identifier_04(); } else if (Key == (byte)Identifier_Standard._0E) { iden = new Identifier_0E(); } else if (Key == (byte)Identifier_Standard._1A) { iden = new Identifier_1A(); } else if (Key == (byte)Identifier_Standard._1F) { iden = new Identifier_1F(); } else if (Key == (byte)Identifier_Standard._20) { iden = new Identifier_20(); } else if (Key == (byte)Identifier_Standard._26) { iden = new Identifier_26(); } else if (Key == (byte)Identifier_Standard._38) { iden = new Identifier_38(); } else if (Key == (byte)Identifier_Standard._39) { iden = new Identifier_39(); } else if (Key == (byte)Identifier_Standard._45) { iden = new Identifier_45(); } else if (Key == (byte)Identifier_Standard._70) { iden = new Identifier_70(); } else if (Key == (byte)Identifier_Standard._71) { iden = new Identifier_71(); } else if (Key == (byte)Identifier_Standard._72) { iden = new Identifier_72(); } else if (Key == (byte)Identifier_Standard._73) { iden = new Identifier_73(); } else if (Key == (byte)Identifier_Standard._74) { iden = new Identifier_74(); } else if (Key == (byte)Identifier_Standard._75) { iden = new Identifier_75(); } else { iden = new Identifier_00(Key); } List_Identifier.Add(iden); } } msg = ""; return(List_Identifier); } catch (Exception ex) { msg = ex.Message; return(null); } }
public static List <Identifier> analyse(string Remain, byte AFN, out string msg) { List <Identifier> List_Identifier = new List <Identifier>(); try { while (Remain.Length >= 4) { byte Key = Convert.ToByte(Remain.Substring(0, 2), 16); string LengthStr = Remain.Substring(2, 2); byte Length = Convert.ToByte(LengthStr, 16); if (Key == (byte)Identifier_Standard._FF) { byte IdentifierSub = Convert.ToByte(Remain.Substring(2, 2), 16); if (IdentifierSub == (byte)Identifier_Custom._03) { if (Remain.Length < 30) { msg = "长度不足,无法获取日水温" + " " + Remain; return(null); } Identifier_FF_03 iden = new Identifier_FF_03(); iden.SetVal(0, 0, Remain.Substring(6, 24)); List_Identifier.Add(iden); Remain = Remain.Substring(30); } else if (IdentifierSub == (byte)Identifier_Custom._0E) { if (Remain.Length < 42) { msg = "长度不足,无法获取日埋深" + " " + Remain; return(null); } Identifier_FF_0E iden = new Identifier_FF_0E(); iden.SetVal(0, 0, Remain.Substring(6, 36)); List_Identifier.Add(iden); Remain = Remain.Substring(42); } else { msg = "非法自定义标识符" + IdentifierSub + "" + " " + Remain; return(null); } } else if (Key == (byte)Identifier_Standard._F0) { int ByteCount = 5; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } Identifier_F0 iden = new Identifier_F0(); iden.SetVal(0, 0, Remain.Substring(4, 10)); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F1) { int ByteCount = 5; if (Enum.IsDefined(typeof(Identifier_F1.HaveKey), (int)AFN)) { ByteCount = 6; } if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } Identifier_F1 iden = new Identifier_F1(); iden.SetVal(0, 0, Remain.Substring(4, ByteCount * 2)); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F2) { Identifier_F2 iden = new Identifier_F2(); iden.SetVal(0, 0, Remain.Substring(4)); List_Identifier.Add(iden); msg = ""; return(List_Identifier); } else if (Key == (byte)Identifier_Standard._F3) { Identifier_F3 iden = new Identifier_F3(); iden.SetVal(0, 0, Remain.Substring(4)); List_Identifier.Add(iden); msg = ""; return(List_Identifier); } else if (Key == (byte)Identifier_Standard._F4) { int ByteCount = 12; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F4 iden = new Identifier_F4(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F5) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F5 iden = new Identifier_F5(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F6) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F6 iden = new Identifier_F6(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F7) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F7 iden = new Identifier_F7(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F8) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F8 iden = new Identifier_F8(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._F9) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_F9 iden = new Identifier_F9(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._FA) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_FA iden = new Identifier_FA(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._FB) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_FB iden = new Identifier_FB(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._FC) { int ByteCount = 24; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier_FC iden = new Identifier_FC(); iden.SetVal(0, 0, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } else if (Key == (byte)Identifier_Standard._FD) { Identifier_FD iden = new Identifier_FD(); iden.SetVal(0, 0, Remain.Substring(4)); List_Identifier.Add(iden); msg = ""; return(List_Identifier); } else { int[] LS = WaterBaseProtocol.GetLengthList(LengthStr); int ByteCount = LS[0]; int Digits = LS[1]; if (Remain.Length < 2 + 2 + ByteCount * 2) { msg = "长度不足,无法获取标识符" + Key + "数据" + " " + Remain; return(null); } string ValStr = Remain.Substring(4, ByteCount * 2); Identifier iden; if (Key == (byte)Identifier_Standard._03) { iden = new Identifier_03(); } else if (Key == (byte)Identifier_Standard._04) { iden = new Identifier_04(); } else if (Key == (byte)Identifier_Standard._0E) { iden = new Identifier_0E(); } else if (Key == (byte)Identifier_Standard._1A) { iden = new Identifier_1A(); } else if (Key == (byte)Identifier_Standard._1F) { iden = new Identifier_1F(); } else if (Key == (byte)Identifier_Standard._20) { iden = new Identifier_20(); } else if (Key == (byte)Identifier_Standard._26) { iden = new Identifier_26(); } else if (Key == (byte)Identifier_Standard._38) { iden = new Identifier_38(); } else if (Key == (byte)Identifier_Standard._39) { iden = new Identifier_39(); } else if (Key == (byte)Identifier_Standard._45) { iden = new Identifier_45(); } else if (Key == (byte)Identifier_Standard._70) { iden = new Identifier_70(); } else if (Key == (byte)Identifier_Standard._71) { iden = new Identifier_71(); } else if (Key == (byte)Identifier_Standard._72) { iden = new Identifier_72(); } else if (Key == (byte)Identifier_Standard._73) { iden = new Identifier_73(); } else if (Key == (byte)Identifier_Standard._74) { iden = new Identifier_74(); } else if (Key == (byte)Identifier_Standard._75) { iden = new Identifier_75(); } else { iden = new Identifier_00(Key); } iden.SetVal(ByteCount, Digits, ValStr); List_Identifier.Add(iden); Remain = Remain.Substring(2 + 2 + ByteCount * 2); } } msg = ""; return(List_Identifier); } catch (Exception ex) { msg = ex.Message; return(null); } }