private void SendCACA(CCACAStruct param)
        {
            string text = BeidouHelper.GetCACAStr(param);

            Debug.WriteLine("发送CACA:" + text);
            InvokeMessage("通信回执申请  " + text, "发送");
            SendText(text);
        }
            /// <summary>
            /// 通信回执申请,发送回执
            /// $CACA
            /// </summary>
            public static String GetCACAStr(CCACAStruct param)
            {
                StringBuilder rawStr = new StringBuilder();

                rawStr.Append("$");
                rawStr.Append(CCACAStruct.CMD_PREFIX);
                rawStr.Append(",");
                rawStr.Append(param.SenderID);                 // 发信方ID
                rawStr.Append(",");
                rawStr.Append(param.RecvType);                 // 收信方类型
                rawStr.Append(",");
                rawStr.Append(param.RecvAddr);                 // 收信方地址
                rawStr.Append(",");
                rawStr.Append(param.Requirements);             // 保密要求
                rawStr.Append(",");
                rawStr.Append(param.ReceiptMsgSequenceNum);    // 回执的报文顺序号
                rawStr.Append(",");
                rawStr.Append(param.ReceiptContent);           // 回执内容
                rawStr.Append(",");
                rawStr.Append(GenerateCRC(rawStr.ToString())); // 校验和
                rawStr.Append("\r\n");
                return(rawStr.ToString());
            }
        // 处理COUT类型数据
        private void DealCOUT(string msg)
        //  private String DealCOUT(string msg)
        {
            string result = null;

            InvokeMessage("通信输出  " + msg, "接收");
            SendBackTTCAString = msg;
            if (msg.Contains("COUT"))
            {
                if (msg.Contains("COUT"))
                {
                    num = num + 1;
                    FileStream   fs = new FileStream("numbd.txt", FileMode.Create);
                    StreamWriter sw = new StreamWriter(fs);
                    //开始写入
                    sw.Write(num);
                    //清空缓冲区
                    sw.Flush();
                    //关闭流
                    sw.Close();
                    fs.Close();
                }
            }
            // InvokeString(msg);
            var cout = BeidouHelper.GetCOUTInfo(msg);

            if (cout == null)
            {
                return;
            }

            //  return result;
            //  发送COSS指令
            //  必须在1秒内发送给卫星终端,否则会重新发送“通信输出”
            var coss = new CCOSSStruct();

            coss.SuccessStatus = true;          //  终端接收到外设通信申请,并校验成功
            SendCOSS(coss);
            //  发送CACA指令
            //  每隔一分钟发送回执$CACA
            //  65秒左右发一条
            var caca = new CCACAStruct();

            caca.SenderID              = "1";                 //  发信方ID为1,表示本机ID,默认
            caca.RecvType              = cout.SenderType;     //  回执的收信方类型  ==  通信输出中的发信方类型
            caca.RecvAddr              = cout.SenderAddr;     //  回执的收信方地址  ==  通信输出中的发信方地址
            caca.Requirements          = "1";                 //  不保密
            caca.ReceiptMsgSequenceNum = cout.MsgSequenceNum; // 回执的报文顺序号  ==  通信输出中的报文顺序号
            caca.ReceiptContent        = "1";
            SendCACA(caca);

            //  解析通信输出中的内容
            string content = cout.MsgContent;

            //通信输出gm8  $60131G2201161111040003046112271367
            try
            {
                string           rawMsg     = content;
                string           sid        = null;
                string           dealMsg    = ProtocolHelpers.dealBCD(rawMsg);
                WriteToFileClass writeClass = new WriteToFileClass("ReceivedLog");
                Thread           t          = new Thread(new ParameterizedThreadStart(writeClass.WriteInfoToFile));
                t.Start("COUT Message: " + " " + dealMsg + "\r\n");
                string bdid = cout.SenderAddr;
                //InvokeMessage("gm3  " + content, "接收");
                //sid需要根据北斗卫星号获取
                try
                {
                    sid = Manager.XmlStationDataSerializer.Instance.GetStationByBDID(bdid);
                }
                catch (Exception e)
                {
                    sid = "5712";
                    Debug.WriteLine("获取站号失败" + e.Message);
                }
                EMessageType type       = ProtocolMaps.MessageTypeMap.FindKey(dealMsg.Substring(0, 2));
                string       reportType = dealMsg.Substring(0, 2);
                if (reportType == "21" || reportType == "22")   //   定时报,加报
                {
                    //  YAC设备的墒情协议:
                    string stationType = dealMsg.Substring(2, 2);
                    switch (stationType)
                    {
                    //  站类为04时墒情站 05墒情雨量站 06,16墒情水位站 07,17墒情水文站
                    case "04":
                    case "05":
                    case "06":
                    case "07":
                    case "17":
                    {
                        //    var station = FindStationByBeidouID(cout.SenderAddr);
                        //    string currentMsg = rawMsg.Insert(0, "$" + station.StationID + "1G");
                        //    CEntitySoilData soil = new CEntitySoilData();
                        //    CReportStruct soilReport = new CReportStruct();
                        //    if (Soil.Parse(currentMsg, out soil, out soilReport))
                        //    {
                        //        soil.ChannelType = EChannelType.BeiDou;

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

                        //        if (null != soilReport && null != this.UpDataReceived)
                        //        {
                        //            soilReport.ChannelType = EChannelType.BeiDou;
                        //            soilReport.ListenPort = "COM" + this.Port.PortName;
                        //            this.UpDataReceived(null, new UpEventArgs() { RawData = rawMsg, Value = soilReport });
                        //        }
                        //    }

                        //}
                        //1111gm
                        string          newMsg     = dealMsg.Substring(1, dealMsg.Length - 1);
                        CEntitySoilData soil       = new CEntitySoilData();
                        CReportStruct   soilReport = new CReportStruct();
                        if (Soil.Parse(newMsg, out soil, out soilReport))
                        {
                            soilReport.ChannelType = EChannelType.BeiDou;
                            if (null != this.SoilDataReceived)
                            {
                                this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil));
                            }

                            if (null != soilReport && null != this.UpDataReceived)
                            {
                                soilReport.ChannelType = EChannelType.GPRS;
                                soilReport.ListenPort  = "COM" + this.Port.PortName;
                                soilReport.flagId      = bdid;
                                this.UpDataReceived(null, new UpEventArgs()
                                    {
                                        RawData = newMsg, Value = soilReport
                                    });
                            }
                        }
                    }
                    break;

                    //  站类为01,02,03,12,13时,不是墒情站
                    case "01":
                    case "02":
                    case "03":
                    case "12":
                    case "13":
                    {
                        //1111gm
                        //string newMsg = dealMsg.Substring(1, dealMsg.Length - 1);
                        //CReportStruct report = new CReportStruct();
                        //if (Up.Parse(newMsg, out report))
                        //{
                        //    //6013 $60131G2201161111040003046112271367
                        //    report.ChannelType = EChannelType.BeiDou;
                        //    report.ListenPort = "COM" + this.Port.PortName;
                        //    if (this.UpDataReceived != null)
                        //    {
                        //        this.UpDataReceived.Invoke(null, new UpEventArgs() { Value = report, RawData = newMsg });
                        //    }
                        //}
                        CReportStruct report = new CReportStruct();
                        UpParser      Up1    = new UpParser();
                        if (Up1.Parse_beidou(sid, type, rawMsg, out report))
                        {
                            //InvokeMessage("gm6  " + rawMsg, "接收");
                            //$60131G2201161111040003046112271367
                            report.ChannelType = EChannelType.BeiDou;
                            report.ListenPort  = "COM" + this.Port.PortName;
                            report.flagId      = bdid;
                            if (this.UpDataReceived != null)
                            {
                                //InvokeMessage("gm7  " + rawMsg, "接收");
                                this.UpDataReceived.Invoke(null, new UpEventArgs()
                                    {
                                        Value = report, RawData = rawMsg
                                    });
                            }
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
                else if (reportType == "11")    //  人工水位
                {
                }
                else if (reportType == "23")    //  人工流量
                {
                }
                else if (reportType == "25")
                {
                    var    station    = FindStationByBeidouID(cout.SenderAddr);
                    string currentMsg = dealMsg.Insert(0, "$" + station.StationID + "1G");

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

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

                        if (null != soilReport && null != this.UpDataReceived)
                        {
                            soilReport.ChannelType = EChannelType.BeiDou;
                            soilReport.ListenPort  = "COM" + this.Port.PortName;
                            soilReport.flagId      = bdid;
                            this.UpDataReceived(null, new UpEventArgs()
                            {
                                RawData = dealMsg, Value = soilReport
                            });
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine("Beidou 数据解析出错 !" + content + "\r\n" + exp.Message);
            }
            //result = msg;
            //return result;
        }