コード例 #1
0
        public string ReadMsg(string UserDataAll)
        {
            short    SerialNumberTmp;
            DateTime SendTimeTmp;
            string   msg = WaterBaseMessageService.GetSerialNumberAndSendTime(UserDataAll, out SerialNumberTmp, out SendTimeTmp);

            if (msg == "")
            {
                SerialNumber = SerialNumberTmp;
                SendTime     = SendTimeTmp;
            }
            else
            {
                if (ShowLog)
                {
                    logHelper.Error(msg);
                }
                return(msg);
            }

            try
            {
                //StationType = Convert.ToByte(UserDataAll.Substring(30, 2), 16);
                Iden_F1 = new Identifier_F1();
                Iden_F1.RemoteStation = UserDataAll.Substring(20, 10);
                Iden_F1.StationType   = Convert.ToByte(UserDataAll.Substring(30, 2), 16);
            }
            catch (Exception ex)
            {
                if (ShowLog)
                {
                    logHelper.Error(ex.Message + Environment.NewLine + "获取遥测站出错" + " " + RawDataStr);
                }
                return("获取遥测站出错");
            }

            try
            {
                //ObsTime = DateTime.ParseExact("20" + UserDataAll.Substring(36, 10) + "00", "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
                Iden_F0         = new Identifier_F0();
                Iden_F0.ObsTime = DateTime.ParseExact("20" + UserDataAll.Substring(36, 10) + "00", "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
            }
            catch (Exception ex)
            {
                if (ShowLog)
                {
                    logHelper.Error(ex.Message + Environment.NewLine + "获取观测时间出错" + " " + RawDataStr);
                }
                return("获取观测时间出错");
            }

            try
            {
                byte key_04 = Convert.ToByte(UserDataAll.Substring(46, 2), 16);
                if (key_04 != (int)Identifier_Standard._04)
                {
                    return("获取时间步长码出错");
                }
                string LengthStr_04 = UserDataAll.Substring(48, 2);
                int[]  LS_04        = WaterBaseProtocol.GetLengthList(LengthStr_04);
                int    ByteCount_04 = LS_04[0];
                int    Digits_04    = LS_04[1];

                Iden_04 = new Identifier_04();
                Iden_04.SetVal(ByteCount_04, Digits_04, UserDataAll.Substring(50, 6));
            }
            catch (Exception ex)
            {
                if (ShowLog)
                {
                    logHelper.Error(ex.Message + Environment.NewLine + "获取时间步长码出错" + " " + RawDataStr);
                }
                return("获取时间步长码出错");
            }

            string Remain = UserDataAll.Substring(56).ToUpper();

            if (Remain.Length > 4)
            {
                byte Key = Convert.ToByte(Remain.Substring(0, 2), 16);
                Idens = new List <Identifier>();
                if (Key == (byte)Identifier_Standard._FF)
                {
                    if (Remain.Length > 6)
                    {
                        byte KeySub = Convert.ToByte(Remain.Substring(2, 2), 16);
                        Remain = Remain.Substring(6);
                        if (KeySub == (byte)Identifier_Custom._03)
                        {
                            while (Remain.Length >= 24)
                            {
                                Identifier_FF_03 id = new Identifier_FF_03();
                                id.SetVal(0, 0, Remain.Substring(0, 24));
                                Idens.Add(id);
                                Remain = Remain.Substring(24);
                            }
                        }
                        else if (KeySub == (byte)Identifier_Custom._0E)
                        {
                            while (Remain.Length >= 36)
                            {
                                Identifier_FF_0E id = new Identifier_FF_0E();
                                id.SetVal(0, 0, Remain.Substring(0, 36));
                                Idens.Add(id);
                                Remain = Remain.Substring(24);
                            }
                        }
                    }
                }
                else
                {
                    string LengthStr = Remain.Substring(2, 2);
                    int[]  LS        = WaterBaseProtocol.GetLengthList(LengthStr);
                    int    ByteCount = LS[0];
                    int    Digits    = LS[1];
                    if (ByteCount > 0)
                    {
                        Remain = Remain.Substring(4);
                        if (Key == (byte)Identifier_Standard._1A)
                        {
                            while (Remain.Length >= ByteCount * 2)
                            {
                                Identifier_1A id = new Identifier_1A();
                                id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2));
                                Idens.Add(id);
                                Remain = Remain.Substring(ByteCount * 2);
                            }
                        }
                        else if (Key == (byte)Identifier_Standard._1F)
                        {
                            while (Remain.Length >= ByteCount * 2)
                            {
                                Identifier_1F id = new Identifier_1F();
                                id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2));
                                Idens.Add(id);
                                Remain = Remain.Substring(ByteCount * 2);
                            }
                        }
                        else if (Key == (byte)Identifier_Standard._20)
                        {
                            while (Remain.Length >= ByteCount * 2)
                            {
                                Identifier_20 id = new Identifier_20();
                                id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2));
                                Idens.Add(id);
                                Remain = Remain.Substring(ByteCount * 2);
                            }
                        }
                        else if (Key == (byte)Identifier_Standard._26)
                        {
                            while (Remain.Length >= ByteCount * 2)
                            {
                                Identifier_26 id = new Identifier_26();
                                id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2));
                                Idens.Add(id);
                                Remain = Remain.Substring(ByteCount * 2);
                            }
                        }
                        else if (Key == (byte)Identifier_Standard._38)
                        {
                            while (Remain.Length >= ByteCount * 2)
                            {
                                Identifier_38 id = new Identifier_38();
                                id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2));
                                Idens.Add(id);
                                Remain = Remain.Substring(ByteCount * 2);
                            }
                        }
                        else if (Key == (byte)Identifier_Standard._39)
                        {
                            while (Remain.Length >= ByteCount * 2)
                            {
                                Identifier_39 id = new Identifier_39();
                                id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2));
                                Idens.Add(id);
                                Remain = Remain.Substring(ByteCount * 2);
                            }
                        }
                        else if (Key == (byte)Identifier_Standard._F4)
                        {
                            while (Remain.Length >= ByteCount * 2)
                            {
                                Identifier_F4 id = new Identifier_F4();
                                id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2));
                                Idens.Add(id);
                                Remain = Remain.Substring(ByteCount * 2);
                            }
                        }
                        else if (Key == (byte)Identifier_Standard._F5)
                        {
                            while (Remain.Length >= ByteCount * 2)
                            {
                                Identifier_F5 id = new Identifier_F5();
                                id.SetVal(ByteCount, Digits, Remain.Substring(0, ByteCount * 2));
                                Idens.Add(id);
                                Remain = Remain.Substring(ByteCount * 2);
                            }
                        }
                    }
                }
            }
            return("");
        }
コード例 #2
0
        public string ReadMsg()
        {
            if (UserDataBytes == null || UserDataBytes.Length == 0)
            {
                if (ShowLog)
                {
                    logHelper.Error("无信息,无法分析!");
                }
                return("无信息,无法分析!");
            }

            UserData = HexStringUtility.ByteArrayToHexString(UserDataBytes);

            try
            {
                SerialNumber = Convert.ToInt16(UserData.Substring(0, 4), 16);
            }
            catch (Exception ex)
            {
                if (ShowLog)
                {
                    logHelper.Error(ex.Message + Environment.NewLine + "获取流水号出错" + " " + RawDataStr);
                }
                return("获取流水号出错");
            }

            try
            {
                SendTime = DateTime.ParseExact("20" + UserData.Substring(4, 12), "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
            }
            catch (Exception ex)
            {
                if (ShowLog)
                {
                    logHelper.Error(ex.Message + Environment.NewLine + "获取发报时间出错" + " " + RawDataStr);
                }
                return("获取发报时间出错");
            }

            try
            {
                StartTime = DateTime.ParseExact("20" + UserData.Substring(16, 8) + "0000", "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
            }
            catch (Exception ex)
            {
                if (ShowLog)
                {
                    logHelper.Error(ex.Message + Environment.NewLine + "获取起始时间出错" + " " + RawDataStr);
                }
                return("获取起始时间出错");
            }

            try
            {
                EndTime = DateTime.ParseExact("20" + UserData.Substring(24, 8) + "0000", "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
            }
            catch (Exception ex)
            {
                if (ShowLog)
                {
                    logHelper.Error(ex.Message + Environment.NewLine + "获取结束时间出错" + " " + RawDataStr);
                }
                return("获取结束时间出错");
            }

            try
            {
                byte key_04 = Convert.ToByte(UserData.Substring(32, 2), 16);
                if (key_04 != (int)Identifier_Standard._04)
                {
                    return("获取时间步长码出错");
                }
                string LengthStr_04 = UserData.Substring(34, 2);
                int[]  LS_04        = WaterBaseProtocol.GetLengthList(LengthStr_04);
                int    ByteCount_04 = LS_04[0];
                int    Digits_04    = LS_04[1];

                Iden_04 = new Identifier_04();
                Iden_04.SetVal(ByteCount_04, Digits_04, UserData.Substring(36, 6));
            }
            catch (Exception ex)
            {
                if (ShowLog)
                {
                    logHelper.Error(ex.Message + Environment.NewLine + "获取时间步长码出错" + " " + RawDataStr);
                }
                return("获取时间步长码出错");
            }

            try
            {
                byte Key = Convert.ToByte(UserData.Substring(42, 2), 16);
                if (Key == (byte)Identifier_Standard._FF)
                {
                    byte KeySub = Convert.ToByte(UserData.Substring(44, 2), 16);
                    if (KeySub == (byte)Identifier_Custom._03)
                    {
                        Iden = new Identifier_FF_03();
                    }
                    else if (KeySub == (byte)Identifier_Custom._0E)
                    {
                        Iden = new Identifier_FF_0E();
                    }
                }
                else
                {
                    if (Key == (byte)Identifier_Standard._03)
                    {
                        Iden = new Identifier_03();
                    }
                    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._F4)
                    {
                        Iden = new Identifier_F4();
                    }
                    else if (Key == (byte)Identifier_Standard._F5)
                    {
                        Iden = new Identifier_F5();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ShowLog)
                {
                    logHelper.Error(ex.Message + Environment.NewLine + "获取要素标识符出错" + " " + RawDataStr);
                }
                return("获取要素标识符出错");
            }

            return("");
        }