コード例 #1
0
        private bool ParseData(string msg, string gprs)
        {
            //           InvokeMessage("协议。。。 ", "进入函数7");
            try
            {
                string rawData = msg;

                if (msg.Contains("$"))
                {
                    string data = string.Empty;
                    if (!ProtocolHelpers.DeleteSpecialChar(msg, out data))
                    {
                        return(false);
                    }
                    msg = data;

                    string sid  = msg.Substring(0, 4);
                    string type = msg.Substring(4, 2);

                    #region 1G
                    if (type == "1G")
                    {
                        string reportType = msg.Substring(6, 2);
                        if (reportType == "21" || reportType == "22")   //   定时报,加报
                        {
                            //  YAC设备的墒情协议:
                            string stationType = msg.Substring(8, 2);
                            switch (stationType)
                            {
                            //  站类为04时墒情站 05墒情雨量站 06,16墒情水位站 07,17墒情水文站
                            case "04":
                            case "05":
                            case "06":
                            case "07":
                            case "17":
                            {
                                //CEntitySoilData soilStruct = new CEntitySoilData();
                                //if (Soil.Parse(msg, out soilStruct))
                                //{
                                //    soilStruct.ChannelType = EChannelType.GPRS;
                                //    //soilStruct.ListenPort = this.GetListenPort().ToString();

                                //    //string temp = soilStruct.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                //    //InvokeMessage(String.Format("{0,-10}   ", temp) + rawData, "接收");

                                //    //  抛出YAC设备墒情事件
                                //    if (null != this.SoilDataReceived)
                                //        this.SoilDataReceived.Invoke(null, new YACSoilEventArg()
                                //        {
                                //            RawData = rawData,
                                //            Value = soilStruct
                                //        });
                                //}

                                CEntitySoilData soil       = new CEntitySoilData();
                                CReportStruct   soilReport = new CReportStruct();
                                if (Soil.Parse(rawData, out soil, out soilReport))
                                {
                                    soil.ChannelType = EChannelType.GPRS;

                                    if (null != this.SoilDataReceived)
                                    {
                                        this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil));
                                    }
                                    //1111gm
                                    string temp = soilReport.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                    InvokeMessage("  gprs号码:  " + gprs + String.Format("  {0,-10}   ", temp) + rawData, "接收");

                                    if (null != soilReport && null != this.UpDataReceived)
                                    {
                                        soilReport.ChannelType = EChannelType.GPRS;
                                        soilReport.ListenPort  = this.GetListenPort().ToString();
                                        soilReport.flagId      = gprs;
                                        this.UpDataReceived(null, new UpEventArgs()
                                            {
                                                RawData = rawData, Value = soilReport
                                            });
                                    }
                                }
                                else
                                {
                                    //string temp = soilReport.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                    InvokeMessage("  gprs号码:  " + gprs + "  " + rawData, "接收");
                                }
                            }
                            break;

                            //  站类为01,02,03,12,13时,不是墒情站
                            case "01":
                            case "02":
                            case "03":
                            case "12":
                            case "13":
                            {
                                CReportStruct report = new CReportStruct();
                                if (Up.Parse(msg, out report))
                                {
                                    report.ChannelType = EChannelType.GPRS;
                                    report.ListenPort  = this.GetListenPort().ToString();
                                    report.flagId      = gprs;

                                    string temp = report.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                    InvokeMessage("  gprs号码:  " + gprs + String.Format("  {0,-10}   ", temp) + rawData, "接收");

                                    if (this.UpDataReceived != null)
                                    {
                                        this.UpDataReceived.Invoke(null, new UpEventArgs()
                                            {
                                                Value = report, RawData = rawData
                                            });
                                    }
                                    //   InvokeMessage("12333", "接收");
                                }
                                else
                                {
                                    //string temp = report.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                    InvokeMessage("  gprs号码:  " + gprs + "  可疑数据 " + rawData, "接收");
                                }
                            }
                            break;

                            case "11":
                            {
                                CReportStruct report = new CReportStruct();
                                //CReportArtificalWater report = new CReportArtificalWater();
                                if (Up.Parse_1(msg, out report))
                                {
                                    report.ChannelType = EChannelType.GPRS;
                                    report.ListenPort  = this.GetListenPort().ToString();
                                    report.ReportType  = EMessageType.Batch;
                                    string temptype = "人工水位";
                                    InvokeMessage(String.Format("{0,-10}   ", temptype) + rawData, "接收");
                                    //if (this.UpDataReceived != null)
                                    this.UpDataReceived.Invoke(null, new UpEventArgs()
                                        {
                                            Value = report, RawData = rawData
                                        });
                                }
                            }
                            break;

                            default:
                                break;
                            }
                        }
                        else if (reportType == "23")    //  人工流量
                        {
                            CReportStruct report = new CReportStruct();
                            if (Up.Parse_2(msg, out report))
                            {
                                report.ChannelType = EChannelType.GPRS;
                                report.ListenPort  = this.GetListenPort().ToString();
                                report.ReportType  = EMessageType.Batch;
                                string temptype = "人工流量";
                                InvokeMessage(String.Format("{0,-10}   ", temptype) + rawData, "接收");
                                this.UpDataReceived.Invoke(null, new UpEventArgs()
                                {
                                    Value = report, RawData = rawData
                                });
                            }
                        }
                        else if (reportType == "32")    //  人工报送水位
                        {
                            CReportStruct report = new CReportStruct();
                            report.ChannelType = EChannelType.GPRS;
                            report.ListenPort  = this.GetListenPort().ToString();
                            string temptype = "人工报送水位";
                            InvokeMessage(String.Format("{0,-10}   ", temptype) + rawData, "接收");
                            WriteToFileClass writeClass = new WriteToFileClass("RGwater");
                            //Thread t = new Thread(new ParameterizedThreadStart(writeClass.WriteInfoToFile));
                            //t.Start("GPRS: " + "长度:" + data.Length + " " + rawData + "\r\n");
                            string a1 = rawData.Substring(9, 1);
                            string a2 = rawData.Substring(10, 1);
                            if (a1 == "P" || a1 == "H" || a1 == "K" || a1 == "Z" || a1 == "D" || a1 == "T" || a1 == "M" || a1 == "G" || a1 == "Y" || a1 == "F" || a1 == "R")
                            {
                                if (a2 == "A")
                                {
                                    if (rawData.Contains("ST"))
                                    {
                                        WriteToFileClass writeClass1 = new WriteToFileClass("sharewater");
                                        Thread           t1          = new Thread(new ParameterizedThreadStart(writeClass1.WriteInfoToFile));
                                        t1.Start("GPRS: " + "长度:" + data.Length + " " + rawData + "\r\n");
                                    }
                                }
                            }
                        }
                        else if (reportType == "53")    // 人工报送时段雨量 日雨量 旬雨量 水库水位 蓄水量 入库流量 出库流量
                        {
                            CReportStruct report = new CReportStruct();
                            report.ChannelType = EChannelType.GPRS;
                            report.ListenPort  = this.GetListenPort().ToString();
                            string temptype = "人工报送雨量";
                            InvokeMessage(String.Format("{0,-10}   ", temptype) + rawData, "接收");
                            WriteToFileClass writeClass = new WriteToFileClass("RGRain");
                            Thread           t          = new Thread(new ParameterizedThreadStart(writeClass.WriteInfoToFile));
                            t.Start("GPRS: " + "长度:" + data.Length + " " + rawData + "\r\n");
                        }
                        else if (reportType == "25")
                        {
                            //CEntitySoilData readSoilStruct = new CEntitySoilData();
                            //if (Soil.Parse(msg, out readSoilStruct))
                            //{
                            //    readSoilStruct.ChannelType = EChannelType.GPRS;
                            //    //readSoilStruct.ListenPort = this.GetListenPort().ToString();

                            //    //string temp = readSoilStruct.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                            //    //InvokeMessage(String.Format("{0,-10}   ", temp) + rawData, "接收");
                            //    //  抛出读墒情事件
                            //    if (null != this.SoilDataReceived)
                            //        this.SoilDataReceived.Invoke(null, new YACSoilEventArg()
                            //        {
                            //            RawData = rawData,
                            //            Value = readSoilStruct
                            //        });
                            //}

                            CEntitySoilData soil       = new CEntitySoilData();
                            CReportStruct   soilReport = new CReportStruct();
                            if (Soil.Parse(rawData, out soil, out soilReport))
                            {
                                soil.ChannelType = EChannelType.GPRS;

                                if (null != this.SoilDataReceived)
                                {
                                    this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil));
                                }

                                if (null != soilReport && null != this.UpDataReceived)
                                {
                                    soilReport.ChannelType = EChannelType.GPRS;
                                    soilReport.ListenPort  = this.GetListenPort().ToString();
                                    soilReport.flagId      = gprs;
                                    this.UpDataReceived(null, new UpEventArgs()
                                    {
                                        RawData = rawData, Value = soilReport
                                    });
                                }
                            }
                        }
                        else //  下行指令
                        {
                            CDownConf downconf = new CDownConf();
                            if (Down.Parse(msg, out downconf))
                            {
                                InvokeMessage(String.Format("{0,-10}   ", "下行指令读取参数") + rawData, "接收");
                                if (this.DownDataReceived != null)
                                {
                                    this.DownDataReceived.Invoke(null, new DownEventArgs()
                                    {
                                        Value = downconf, RawData = rawData
                                    });
                                }
                            }
                        }
                    }
                    #endregion

                    #region 1K
                    if (type == "1K")
                    {
                        var station = FindStationBySID(sid);
                        if (station == null)
                        {
                            throw new Exception("批量传输,站点匹配错误");
                        }
                        //EStationBatchType batchType = station.BatchTranType;

                        //if (batchType == EStationBatchType.EFlash)
                        //{
                        //    CBatchStruct batch = new CBatchStruct();
                        //    if (FlashBatch.Parse(msg, out batch))
                        //    {
                        //        InvokeMessage(String.Format("{0,-10}   ", "Flash批量传输") + rawData, "接收");

                        //        if (this.BatchDataReceived != null)
                        //            this.BatchDataReceived.Invoke(null, new BatchEventArgs() { Value = batch, RawData = rawData });
                        //    }
                        //}
                        //else if (batchType == EStationBatchType.EUPan)
                        //{
                        //    CBatchStruct batch = new CBatchStruct();
                        //    if (UBatch.Parse(msg, out batch))
                        //    {
                        //        InvokeMessage(String.Format("{0,-10}   ", "U盘批量传输") + rawData, "接收");

                        //        if (this.BatchDataReceived != null)
                        //            this.BatchDataReceived.Invoke(null, new BatchEventArgs() { Value = batch, RawData = rawData });
                        //    }
                        //}

                        CBatchStruct batch = new CBatchStruct();
                        if (FlashBatch.Parse(msg, out batch))
                        {
                            InvokeMessage(String.Format("{0,-10}   ", "批量传输") + rawData, "接收");

                            if (this.BatchDataReceived != null)
                            {
                                this.BatchDataReceived.Invoke(null, new BatchEventArgs()
                                {
                                    Value = batch, RawData = rawData
                                });
                            }
                        }
                    }
                    #endregion

                    #region 1S
                    if (type == "1S")
                    {
                        CDownConf downconf = new CDownConf();
                        if (Down.Parse(msg, out downconf))
                        {
                            InvokeMessage(String.Format("{0,-10}   ", "下行指令设置参数") + rawData, "接收");

                            if (this.DownDataReceived != null)
                            {
                                this.DownDataReceived.Invoke(null, new DownEventArgs()
                                {
                                    Value = downconf, RawData = rawData
                                });
                            }
                        }
                    }
                    #endregion
                }
                else if (msg.Contains("#"))
                {
                    CEntitySoilData soil       = new CEntitySoilData();
                    CReportStruct   soilReport = new CReportStruct();
                    if (Soil.Parse(rawData, out soil, out soilReport))
                    {
                        soil.ChannelType = EChannelType.GPRS;

                        if (null != this.SoilDataReceived)
                        {
                            this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil));
                        }

                        if (null != soilReport && null != this.UpDataReceived)
                        {
                            soilReport.ChannelType = EChannelType.GPRS;
                            soilReport.ListenPort  = this.GetListenPort().ToString();
                            soilReport.flagId      = gprs;
                            this.UpDataReceived(null, new UpEventArgs()
                            {
                                RawData = rawData, Value = soilReport
                            });
                        }
                    }
                }
                else
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception exp)
            {
                //System.Diagnostics.Debug.WriteLine("GPRS 数据解析出错 !" + msg + "\r\n" + exp.Message);
            }
            return(false);
        }
コード例 #2
0
        private void Parser_3(object str)
        {
            try
            {
                string data = str as string;
                /* 删除 '\r\n' 字符串 */
                while (data.StartsWith("\r\n"))
                {
                    data = data.Substring(2);
                }

                /*
                 * 解析数据,获取CGSMStruct
                 */
                var gsm = new CGSMStruct();
                if (!GsmHelper.Parse_3(data, out gsm))
                {
                    return;
                }
                /*  如果解析成功,触发GSM数据接收完成事件  */
                //string rawdata = "";
                //string rawdata1 = gsm.Message;
                //if (!rawdata1.Contains('$'))
                //{
                //    rawdata = "$" + rawdata1;
                //}

                if (data.EndsWith("+"))
                {
                    data = data.Substring(0, data.Length - 1);
                }
                InvokeMessage(data, "接收");

                string msg = string.Empty;
                if (!ProtocolHelpers.DeleteSpecialChar(gsm.Message, out msg))
                {
                    return;
                }
                msg = gsm.Message;
                string rawdata = msg;
                if (msg.Contains('$'))
                {
                    msg = msg.Substring(1);
                }
                //if (msg.Contains('9'))
                //{
                //    msg = msg.Substring(1);
                //}


                if (!msg.ToUpper().Contains("TRU"))
                {
                    string sid  = msg.Substring(0, 4);
                    string type = msg.Substring(4, 2);

                    /*
                     *  上行指令信息,
                     *  或者读取参数返回的信息
                     */
                    #region 1G
                    if (type == "1G")
                    {
                        string reportType = msg.Substring(6, 2);
                        /*  定时报,加报 */
                        if (reportType == "21" || reportType == "22")
                        {
                            //  YAC设备的墒情协议:
                            string stationType = msg.Substring(8, 2);
                            switch (stationType)
                            {
                            //  站类为04时墒情站 05墒情雨量站 06,16墒情水位站 07,17墒情水文站
                            case "04":
                            case "05":
                            case "06":
                            case "07":
                                //case "17":
                                //    {
                                //        CEntitySoilData soil = new CEntitySoilData();
                                //        CReportStruct soilReport = new CReportStruct();
                                //        Soil = new Protocol.Data.Lib.SoilParser();
                                //        if (Soil.Parse(rawdata, out soil, out soilReport))
                                //        {
                                //            soil.ChannelType = EChannelType.GSM;

                                //            if (null != this.SoilDataReceived)
                                //                this.SoilDataReceived(null, new CEventSingleArgs<CEntitySoilData>(soil));
                                //            //1111gm
                                //            string temp = soilReport.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                //            //InvokeMessage(String.Format("{0,-10}   ", temp) + rawdata, "接收");

                                //            if (null != soilReport && null != this.UpDataReceived)
                                //           // if (null != soilReport)
                                //             {
                                //                soilReport.ChannelType = EChannelType.GSM;
                                //                soilReport.ListenPort = "COM" + this.ListenPort.PortName;
                                //                this.UpDataReceived(null, new UpEventArgs() { RawData = rawdata, Value = soilReport });
                                //            }
                                //        }
                                //        else
                                //        {
                                //            //string temp = soilReport.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                //            InvokeMessage(" " + rawdata, "接收");
                                //        }
                                //    }
                                break;

                            //  站类为01,02,03,12,13时,不是墒情站
                            case "01":
                            case "02":
                            case "03":
                            case "12":
                            case "13":
                            {
                                CReportStruct report = new CReportStruct();
                                if (Up.Parse(msg, out report))         /* 解析成功 */
                                {
                                    report.ChannelType = EChannelType.GSM;
                                    report.ListenPort  = "COM" + this.ListenPort.PortName;
                                    report.flagId      = gsm.PhoneNumber;
                                    if (this.UpDataReceived != null)
                                    {
                                        this.UpDataReceived.Invoke(null, new UpEventArgs()
                                            {
                                                Value = report, RawData = data
                                            });
                                    }
                                }
                            }
                            break;

                            default:
                                break;
                            }
                        }
                        else if (reportType == "11")    //  人工水位
                        {
                        }
                        else if (reportType == "23")    //  人工流量
                        {
                        }
                        else if (reportType == "25")
                        {
                        }
                        else /* 下行指令 */
                        {
                            CDownConf downconf = new CDownConf();
                            if (Down.Parse(msg, out downconf)) /* 解析成功 */
                            {
                                if (this.DownDataReceived != null)
                                {
                                    this.DownDataReceived.Invoke(null, new DownEventArgs()
                                    {
                                        Value = downconf, RawData = data
                                    });
                                }
                            }
                        }
                    }

                    #endregion

                    #region 1K
                    if (type == "1K") /* 批量传输 */
                    {
                        var station = FindStationBySID(sid);
                        if (station == null)
                        {
                            throw new Exception("批量传输,站点传输类型匹配错误");
                        }
                        //  EStationBatchType batchType = station.BatchTranType;

                        //if (batchType == EStationBatchType.EFlash)          /* Flash传输 */
                        //{
                        CBatchStruct batch = new CBatchStruct();
                        if (FlashBatch.Parse(gsm.Message, out batch)) /* 解析成功 */
                        {
                            if (this.BatchDataReceived != null)
                            {
                                this.BatchDataReceived.Invoke(null, new BatchEventArgs()
                                {
                                    Value = batch, RawData = data
                                });
                            }
                        }
                        //}
                        //else if (batchType == EStationBatchType.EUPan)  /* U盘传输 */
                        //{
                        //    CBatchStruct batch = new CBatchStruct();
                        //    if (UBatch.Parse(gsm.Message, out batch))   /* 解析成功 */
                        //    {
                        //        if (this.BatchDataReceived != null)
                        //            this.BatchDataReceived.Invoke(null, new BatchEventArgs() { Value = batch, RawData = data });
                        //    }
                        //}
                        else
                        {
                            throw new Exception("批量传输,站点传输类型匹配错误");
                        }
                    }
                    #endregion

                    #region 1S
                    if (type == "1S") /* 远地下行指令,设置参数 */
                    {
                        CDownConf downconf = new CDownConf();
                        if (Down.Parse(gsm.Message, out downconf))/* 解析成功 */
                        {
                            if (this.DownDataReceived != null)
                            {
                                this.DownDataReceived.Invoke(null, new DownEventArgs()
                                {
                                    Value = downconf, RawData = data
                                });
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    if (this.ErrorReceived != null)
                    {
                        this.ErrorReceived.Invoke(null, new ReceiveErrorEventArgs()
                        {
                            Msg = data
                        });
                    }
                }
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp.Message);
            }
        }
コード例 #3
0
        private bool ParseData(string msg)
        {
            //           InvokeMessage("协议。。。 ", "进入函数7");
            try
            {
                string rawData = msg;

                if (msg.Contains("$"))
                {
                    string data = string.Empty;
                    if (!ProtocolHelpers.DeleteSpecialChar(msg, out data))
                    {
                        return(false);
                    }
                    msg = data;

                    string sid  = msg.Substring(0, 4);
                    string type = msg.Substring(4, 2);

                    #region 1G
                    if (type == "1G")
                    {
                        //   InvokeMessage("1: " + DateTime.Now, "函数");
                        string reportType = msg.Substring(6, 2);
                        if (reportType == "21" || reportType == "22")   //   定时报,加报
                        {
                            //  YAC设备的墒情协议:
                            string stationType = msg.Substring(8, 2);
                            switch (stationType)
                            {
                            //  站类为04时墒情站 05墒情雨量站 06,16墒情水位站 07,17墒情水文站
                            case "04":
                            case "05":
                            case "06":
                            case "07":
                            case "17":
                            {
                                //CEntitySoilData soilStruct = new CEntitySoilData();
                                //if (Soil.Parse(msg, out soilStruct))
                                //{
                                //    soilStruct.ChannelType = EChannelType.GPRS;
                                //    //soilStruct.ListenPort = this.GetListenPort().ToString();

                                //    //string temp = soilStruct.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                //    //InvokeMessage(String.Format("{0,-10}   ", temp) + rawData, "接收");

                                //    //  抛出YAC设备墒情事件
                                //    if (null != this.SoilDataReceived)
                                //        this.SoilDataReceived.Invoke(null, new YACSoilEventArg()
                                //        {
                                //            RawData = rawData,
                                //            Value = soilStruct
                                //        });
                                //}

                                CEntitySoilData soil       = new CEntitySoilData();
                                CReportStruct   soilReport = new CReportStruct();
                                if (Soil.Parse(rawData, out soil, out soilReport))
                                {
                                    soil.ChannelType = EChannelType.GPRS;

                                    if (null != this.SoilDataReceived)
                                    {
                                        this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil));
                                    }
                                    //1111gm
                                    string temp = soilReport.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                    InvokeMessage(String.Format("{0,-10}   ", temp) + rawData, "接收");

                                    if (null != soilReport && null != this.UpDataReceived)
                                    {
                                        soilReport.ChannelType = EChannelType.GPRS;
                                        soilReport.ListenPort  = this.GetListenPort().ToString();
                                        this.UpDataReceived(null, new UpEventArgs()
                                            {
                                                RawData = rawData, Value = soilReport
                                            });
                                    }
                                }
                                else
                                {
                                    //string temp = soilReport.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                    InvokeMessage(" " + rawData, "接收");
                                }
                            }
                            break;

                            //  站类为01,02,03,12,13时,不是墒情站
                            case "01":
                            case "02":
                            case "03":
                            case "12":
                            case "13":
                            {
                                CReportStruct report = new CReportStruct();
                                if (Up.Parse(msg, out report))
                                {
                                    report.ChannelType = EChannelType.GPRS;
                                    report.ListenPort  = this.GetListenPort().ToString();

                                    string temp = report.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                    InvokeMessage(String.Format("{0,-10}   ", temp) + rawData, "接收");
                                    //by LH 10.05
                                    //读取数据
                                    //ModemDataStruct dat = new ModemDataStruct();
                                    //while (this.GetNextData(out dat))
                                    //{
                                    //uint dtuID = 0;

                                    //var gprs = FindGprsByUserid(userID);
                                    //if (gprs.FindByID(userID, out dtuID))
                                    //{
                                    //    //query = gprs.Down.BuildQuery(stationID, cmds, EChannelType.GPRS);
                                    //    gprs.SendHex(dtuID, bts);
                                    //}

                                    //InvokeMessage("TRU,modemId: " + dat.m_modemId, "发送");
                                    //    InvokeMessage("bts: " + bts, "发送");
                                    //    //InvokeMessage("bts.length: " + (ushort)bts.Length, "发送");
                                    //    // 发送回执

                                    //InvokeMessage("3: " + DateTime.Now, "函数");
                                    // }
                                    //DTUdll.Instance.SendHex(m, bts, (ushort)bts.Length);

                                    //byte[] bts = new byte[] { 84, 82, 85, 13, 10 };
                                    //uint m = 1610637336;
                                    //InvokeMessage("2: " + DateTime.Now, "函数");
                                    //DTUdll.Instance.SendHex(m, bts, (ushort)bts.Length);
                                    //   report.Datas[0].Voltge = Decimal.Parse("111111") * (Decimal)0.01;
                                    //  InvokeMessage(report.Datas[0].Voltge.ToString(), "接收");
                                    if (this.UpDataReceived != null)
                                    {
                                        this.UpDataReceived.Invoke(null, new UpEventArgs()
                                            {
                                                Value = report, RawData = rawData
                                            });
                                    }
                                    //   InvokeMessage("12333", "接收");
                                }
                                else
                                {
                                    //string temp = report.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                                    InvokeMessage(" " + rawData, "接收");
                                }
                            }
                            break;

                            case "11":
                            {
                                CReportStruct report = new CReportStruct();
                                //CReportArtificalWater report = new CReportArtificalWater();
                                if (Up.Parse_1(msg, out report))
                                {
                                    report.ChannelType = EChannelType.GPRS;
                                    report.ListenPort  = this.GetListenPort().ToString();
                                    report.ReportType  = EMessageType.Batch;
                                    string temptype = "人工水位";
                                    InvokeMessage(String.Format("{0,-10}   ", temptype) + rawData, "接收");
                                    //if (this.UpDataReceived != null)
                                    this.UpDataReceived.Invoke(null, new UpEventArgs()
                                        {
                                            Value = report, RawData = rawData
                                        });
                                }
                            }
                            break;

                            default:
                                break;
                            }
                        }
                        else if (reportType == "23")    //  人工流量
                        {
                            CReportStruct report = new CReportStruct();
                            if (Up.Parse_2(msg, out report))
                            {
                                report.ChannelType = EChannelType.GPRS;
                                report.ListenPort  = this.GetListenPort().ToString();
                                report.ReportType  = EMessageType.Batch;
                                string temptype = "人工流量";
                                InvokeMessage(String.Format("{0,-10}   ", temptype) + rawData, "接收");
                                this.UpDataReceived.Invoke(null, new UpEventArgs()
                                {
                                    Value = report, RawData = rawData
                                });
                            }
                        }
                        else if (reportType == "32")    //  人工报送水位
                        {
                            CReportStruct report = new CReportStruct();
                            report.ChannelType = EChannelType.GPRS;
                            report.ListenPort  = this.GetListenPort().ToString();
                            string temptype = "人工报送水位";
                            InvokeMessage(String.Format("{0,-10}   ", temptype) + rawData, "接收");
                            WriteToFileClass writeClass = new WriteToFileClass("RGwater");
                            Thread           t          = new Thread(new ParameterizedThreadStart(writeClass.WriteInfoToFile));
                            t.Start("GPRS: " + "长度:" + data.Length + " " + rawData + "\r\n");
                            string a1 = rawData.Substring(9, 1);
                            string a2 = rawData.Substring(10, 1);
                            if (a1 == "P" || a1 == "H" || a1 == "K" || a1 == "Z" || a1 == "D" || a1 == "T" || a1 == "M" || a1 == "G" || a1 == "Y" || a1 == "F" || a1 == "R")
                            {
                                if (a2 == "A")
                                {
                                    if (rawData.Contains("ST"))
                                    {
                                        WriteToFileClass writeClass1 = new WriteToFileClass("sharewater");
                                        Thread           t1          = new Thread(new ParameterizedThreadStart(writeClass1.WriteInfoToFile));
                                        t1.Start("GPRS: " + "长度:" + data.Length + " " + rawData + "\r\n");
                                    }
                                }
                            }
                        }
                        else if (reportType == "53")    // 人工报送时段雨量 日雨量 旬雨量 水库水位 蓄水量 入库流量 出库流量
                        {
                            CReportStruct report = new CReportStruct();
                            report.ChannelType = EChannelType.GPRS;
                            report.ListenPort  = this.GetListenPort().ToString();
                            string temptype = "人工报送雨量";
                            InvokeMessage(String.Format("{0,-10}   ", temptype) + rawData, "接收");
                            WriteToFileClass writeClass = new WriteToFileClass("RGRain");
                            Thread           t          = new Thread(new ParameterizedThreadStart(writeClass.WriteInfoToFile));
                            t.Start("GPRS: " + "长度:" + data.Length + " " + rawData + "\r\n");
                        }
                        else if (reportType == "25")
                        {
                            //CEntitySoilData readSoilStruct = new CEntitySoilData();
                            //if (Soil.Parse(msg, out readSoilStruct))
                            //{
                            //    readSoilStruct.ChannelType = EChannelType.GPRS;
                            //    //readSoilStruct.ListenPort = this.GetListenPort().ToString();

                            //    //string temp = readSoilStruct.ReportType == EMessageType.EAdditional ? "加报" : "定时报";
                            //    //InvokeMessage(String.Format("{0,-10}   ", temp) + rawData, "接收");
                            //    //  抛出读墒情事件
                            //    if (null != this.SoilDataReceived)
                            //        this.SoilDataReceived.Invoke(null, new YACSoilEventArg()
                            //        {
                            //            RawData = rawData,
                            //            Value = readSoilStruct
                            //        });
                            //}

                            CEntitySoilData soil       = new CEntitySoilData();
                            CReportStruct   soilReport = new CReportStruct();
                            if (Soil.Parse(rawData, out soil, out soilReport))
                            {
                                soil.ChannelType = EChannelType.GPRS;

                                if (null != this.SoilDataReceived)
                                {
                                    this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil));
                                }

                                if (null != soilReport && null != this.UpDataReceived)
                                {
                                    soilReport.ChannelType = EChannelType.GPRS;
                                    soilReport.ListenPort  = this.GetListenPort().ToString();
                                    this.UpDataReceived(null, new UpEventArgs()
                                    {
                                        RawData = rawData, Value = soilReport
                                    });
                                }
                            }
                        }
                        else //  下行指令
                        {
                            CDownConf downconf = new CDownConf();
                            if (Down.Parse(msg, out downconf))
                            {
                                InvokeMessage(String.Format("{0,-10}   ", "下行指令读取参数") + rawData, "接收");
                                if (this.DownDataReceived != null)
                                {
                                    this.DownDataReceived.Invoke(null, new DownEventArgs()
                                    {
                                        Value = downconf, RawData = rawData
                                    });
                                }
                            }
                        }
                    }
                    #endregion

                    #region 1K
                    if (type == "1K")
                    {
                        var station = FindStationBySID(sid);
                        if (station == null)
                        {
                            throw new Exception("批量传输,站点匹配错误");
                        }
                        //EStationBatchType batchType = station.BatchTranType;

                        //if (batchType == EStationBatchType.EFlash)
                        //{
                        //    CBatchStruct batch = new CBatchStruct();
                        //    if (FlashBatch.Parse(msg, out batch))
                        //    {
                        //        InvokeMessage(String.Format("{0,-10}   ", "Flash批量传输") + rawData, "接收");

                        //        if (this.BatchDataReceived != null)
                        //            this.BatchDataReceived.Invoke(null, new BatchEventArgs() { Value = batch, RawData = rawData });
                        //    }
                        //}
                        //else if (batchType == EStationBatchType.EUPan)
                        //{
                        //    CBatchStruct batch = new CBatchStruct();
                        //    if (UBatch.Parse(msg, out batch))
                        //    {
                        //        InvokeMessage(String.Format("{0,-10}   ", "U盘批量传输") + rawData, "接收");

                        //        if (this.BatchDataReceived != null)
                        //            this.BatchDataReceived.Invoke(null, new BatchEventArgs() { Value = batch, RawData = rawData });
                        //    }
                        //}

                        CBatchStruct batch = new CBatchStruct();
                        if (FlashBatch.Parse(msg, out batch))
                        {
                            InvokeMessage(String.Format("{0,-10}   ", "批量传输") + rawData, "接收");

                            if (this.BatchDataReceived != null)
                            {
                                this.BatchDataReceived.Invoke(null, new BatchEventArgs()
                                {
                                    Value = batch, RawData = rawData
                                });
                            }
                        }
                    }
                    #endregion

                    #region 1S
                    if (type == "1S")
                    {
                        CDownConf downconf = new CDownConf();
                        if (Down.Parse(msg, out downconf))
                        {
                            InvokeMessage(String.Format("{0,-10}   ", "下行指令设置参数") + rawData, "接收");

                            if (this.DownDataReceived != null)
                            {
                                this.DownDataReceived.Invoke(null, new DownEventArgs()
                                {
                                    Value = downconf, RawData = rawData
                                });
                            }
                        }
                    }
                    #endregion
                }
                else if (msg.Contains("#"))
                {
                    CEntitySoilData soil       = new CEntitySoilData();
                    CReportStruct   soilReport = new CReportStruct();
                    if (Soil.Parse(rawData, out soil, out soilReport))
                    {
                        soil.ChannelType = EChannelType.GPRS;

                        if (null != this.SoilDataReceived)
                        {
                            this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil));
                        }

                        if (null != soilReport && null != this.UpDataReceived)
                        {
                            soilReport.ChannelType = EChannelType.GPRS;
                            soilReport.ListenPort  = this.GetListenPort().ToString();
                            this.UpDataReceived(null, new UpEventArgs()
                            {
                                RawData = rawData, Value = soilReport
                            });
                        }
                    }
                }
                else
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine("GPRS 数据解析出错 !" + msg + "\r\n" + exp.Message);
            }
            return(false);
        }