public bool GetNextData(out ModemDataStruct dat)
 {
     try
     {
         //WriteToFileClass writeClass = new WriteToFileClass();
         //Thread t = new Thread(new ParameterizedThreadStart(writeClass.WriteInfoToFile));
         //t.Start("Test" +  "\r\n");
         dat = new ModemDataStruct();
         return(DSGetNextData(ref dat, 0));
     }
     catch (Exception e)
     {
         WriteToFileClass writeClass = new WriteToFileClass("Buginfo");
         Thread           t          = new Thread(new ParameterizedThreadStart(writeClass.WriteInfoToFile));
         t.Start("f**k" + "\r\n");
         dat = new ModemDataStruct();
         return(false);
     }
 }
Exemple #2
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);
        }
        // 处理内存缓存中的数据
        private void DealData()
        {
            //InvokeMessage("协议。。。 ", "进入函数6");
            while (true)
            {
                m_semaphoreData.WaitOne(); //阻塞当前线程,知道被其它线程唤醒
                // 获取对data内存缓存的访问权
                m_mutexListDatas.WaitOne();
                List <ModemDataStruct> dataListTmp = m_listDatas;
                m_listDatas = new List <ModemDataStruct>(); //开辟一快新的缓存区
                m_mutexListDatas.ReleaseMutex();
                // 开始处理数据
                for (int i = 0; i < dataListTmp.Count; ++i)
                {
                    try
                    {
                        ModemDataStruct dat  = dataListTmp[i];
                        string          data = System.Text.Encoding.Default.GetString(dat.m_data_buf);
                        //1119
                        WriteToFileClass writeClass = new WriteToFileClass("ReceivedLog");
                        Thread           t          = new Thread(new ParameterizedThreadStart(writeClass.WriteInfoToFile));
                        t.Start("GPRS: " + "长度:" + data.Length + " " + data + "\r\n");
                        //t.Start("GPRS: " + "长度:" + data.Trim().Length + " " + data + "\r\n" );

                        if (data.Contains("TRU"))
                        {
                            Debug.WriteLine("接收数据TRU完成,停止计时器");
                            //m_timer.Stop();
                            InvokeMessage("TRU " + ((uint)dat.m_modemId).ToString("X").PadLeft(8, '0'), "接收");
                            if (this.ErrorReceived != null)
                            {
                                this.ErrorReceived.Invoke(null, new ReceiveErrorEventArgs()
                                {
                                    //   Msg = "TRU " + dat.m_modemId
                                    Msg = "TRU " + ((uint)dat.m_modemId).ToString("X").PadLeft(8, '0')
                                });
                            }
                        }
                        if (data.Contains("ATE0"))
                        {
                            Debug.WriteLine("接收数据ATE0完成,停止计时器");
                            //m_timer.Stop();
                            // InvokeMessage("ATE0", "接收");
                            if (this.ErrorReceived != null)
                            {
                                this.ErrorReceived.Invoke(null, new ReceiveErrorEventArgs()
                                {
                                    Msg = "ATE0"
                                });
                            }
                        }
                        if (data.Contains("$"))
                        {
                            if (data.Contains("$TS"))
                            {
                                Debug.WriteLine("接收数据正确完成,停止计时器");
                                int indexStart = data.IndexOf("$");

                                data = data.Substring(indexStart + 3);
                                int length = data.IndexOf(CSpecialChars.ENTER_CHAR);
                                data = data.Substring(0, length);
                                data = "$" + data;
                                data = data.Trim();
                                data = data + "TS";
                                if (this.ParseData(data))
                                {
                                    if (this.ModemDataReceived != null)
                                    {
                                        this.ModemDataReceived.Invoke(this, new ModemDataEventArgs()
                                        {
                                            Msg   = data,
                                            Value = dat
                                        });
                                    }
                                }
                            }
                            else
                            {
                                Debug.WriteLine("接收数据正确完成,停止计时器");
                                //m_timer.Stop();
                                int indexStart = data.IndexOf("$");
                                data = data.Substring(indexStart);
                                int length = data.IndexOf(CSpecialChars.ENTER_CHAR);
                                data = data.Substring(0, length);
                                data = data.Trim();
                                //this.ParseData(data);
                                if (this.ParseData(data))
                                {
                                    if (this.ModemDataReceived != null)
                                    {
                                        this.ModemDataReceived.Invoke(this, new ModemDataEventArgs()
                                        {
                                            Msg   = data,
                                            Value = dat
                                        });
                                    }
                                }
                            }
                        }
                        if (data.Contains("#"))
                        {
                            Debug.WriteLine("接收数据正确完成,停止计时器");
                            //m_timer.Stop();
                            int indexStart = data.IndexOf("#");
                            data = data.Substring(indexStart);
                            int length = data.IndexOf(CSpecialChars.ENTER_CHAR);
                            data = data.Substring(0, length);
                            data = data.Trim();
                            //this.ParseData(data);
                            if (this.ParseData(data))
                            {
                                if (this.ModemDataReceived != null)
                                {
                                    this.ModemDataReceived.Invoke(this, new ModemDataEventArgs()
                                    {
                                        Msg   = data,
                                        Value = dat
                                    });
                                }
                            }
                        }
                        m_timer.Stop();
                    }
                    catch (Exception exp) { Debug.WriteLine(exp.Message); }
                } //end of for
            }     //end of while
        }
        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);
        }