Beispiel #1
0
        /// <summary>
        /// 将收到数据放入数据队列
        /// </summary>
        /// <param name="CS">COM服务</param>
        /// <param name="senddatetime">发送时间</param>
        /// <param name="bt">数据</param>
        public static void WriteCrdQ(ComServer CS, byte[] bt)
        {
            ConcurrentQueue <ComReceivedData> Qcrd = CS.CQ.Qcrd;
            ComReceivedData crd = new ComReceivedData();

            crd.Data = bt;
            if (bt.Length > 0)
            {
                lock (Qcrd)
                {
                    Qcrd.Enqueue(crd);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 将收到数据放入数据队列
        /// </summary>
        /// <param name="CS">COM服务</param>
        /// <param name="senddatetime">发送时间</param>
        /// <param name="bt">数据</param>
        public static void WriteCrdQ(ComServer CS, string Satellite, byte[] bt)
        {
            ConcurrentQueue <ComReceivedData> Qcrd = CS.CQ.Qcrd;
            ComReceivedData crd = new ComReceivedData();

            crd.SATELLITE = Satellite;
            crd.Data      = bt;
            /////////////////////////测试输出
            Console.Write(EnCoder.ByteArrayToHexStr(bt));
            if (bt.Length > 0)
            {
                lock (Qcrd)
                {
                    Qcrd.Enqueue(crd);
                }
            }
        }
Beispiel #3
0
        public static List <ComReceivedData> SubpackageFor4(ComServer CS, byte[] data)
        {
            List <ComReceivedData> Lcrd = new List <ComReceivedData>();
            string str = EnCoder.ByteArrayToHexStr(data);

            if (str.Length >= 10)
            {
                string temp = str.Substring(0, 10);
                if (temp == "2454585858")  //$TXXX   通讯信息
                {
                    //报文内容长度
                    long l = Convert.ToInt64(str.Substring(32, 4), 16);
                    //用户地址
                    string RevSatellite = Convert.ToInt64(str.Substring(14, 6), 16).ToString();
                    //发信方地址
                    string SendSatellite = Convert.ToInt64(str.Substring(22, 6), 16).ToString();
                    //时间
                    string Time = Convert.ToInt64(str.Substring(28, 2), 16).ToString() + "时" + Convert.ToInt64(str.Substring(30, 2), 16).ToString() + "分";

                    ComReceivedData crd = new ComReceivedData();
                    crd.SATELLITE = SendSatellite;

                    //从原始数据报里copy报文
                    byte[] vBuffer1 = new byte[l / 8];

                    Array.Copy(data, 18, vBuffer1, 0, l / 8);
                    crd.Data = vBuffer1;
                    Lcrd.Add(crd);


                    //IsCOUT = true;
                    //反馈给界面信息
                    ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "接收卫星", "接收数据,用户地址:" + RevSatellite + ",发信方地址:" + SendSatellite + ",时间" + Time + ",数据报长度:" + l, new byte[] { }, ServiceEnum.EnCoderType.HEX, ServiceEnum.DataType.Text);
                }
                else if (temp == "245A4A5858") //$ZJXX  自检信息
                {
                    string Explain = "";
                    //用户地址
                    string RevSatellite = Convert.ToInt64(str.Substring(14, 6), 16).ToString();
                    //IC卡状态
                    string ICState = str.Substring(20, 2);
                    if (ICState == "00")//正常
                    {
                        Explain += "IC卡状态:正常\n";
                    }
                    else //异常
                    {
                        Explain += "IC卡状态:异常\n";
                    }
                    CS.CStateFor4.ICState = ICState;

                    //硬件状态
                    string HardwareState = str.Substring(22, 2);
                    if (HardwareState == "00")//正常
                    {
                        Explain += "                                                   硬件状态:正常\n";
                    }
                    else //异常
                    {
                        Explain += "                                                   硬件状态:异常\n";
                    }
                    CS.CStateFor4.HardwareState = HardwareState;

                    //电量百分比
                    string Electricity = str.Substring(24, 2);
                    Electricity = Convert.ToInt64(Electricity, 16).ToString();
                    Explain    += "                                                   电量:" + Electricity + "%\n";
                    CS.CStateFor4.Electricity = Electricity;

                    //入站状态
                    string Inbound = str.Substring(26, 2);
                    if (Inbound == "00")//正常
                    {
                    }
                    else //异常
                    {
                    }

                    string Power = str.Substring(28, 12);
                    CS.CStateFor4.Power = Power;
                    string[] bs = new string[] { "<-158dBW", "-156~-157dBW", "-154~-155dBW", "-152~-153dBW", ">-152dBW" };
                    for (int i = 0; i < 6; i++)
                    {
                        string s = Power.Substring(2 * i, 2);
                        if (s == "00")
                        {
                            Explain += "                                                   波束" + (i + 1) + "#功率:" + bs[0] + "\n";
                        }
                        else if (s == "01")
                        {
                            Explain += "                                                   波束" + (i + 1) + "#功率:" + bs[1] + "\n";
                        }
                        else if (s == "02")
                        {
                            Explain += "                                                   波束" + (i + 1) + "#功率:" + bs[2] + "\n";
                        }
                        else if (s == "03")
                        {
                            Explain += "                                                   波束" + (i + 1) + "#功率:" + bs[3] + "\n";
                        }
                        else if (s == "04")
                        {
                            Explain += "                                                   波束" + (i + 1) + "#功率:" + bs[4] + "\n";
                        }
                    }

                    CS.CStateFor4.DATATIME = DateTime.Now;

                    //将以上解析信息反馈到界面时注销下行
                    //Explain = " 服务器与卫星接收设备通讯正常";

                    //反馈给界面信息
                    ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, RevSatellite, "接收到状态信息\n" + Explain, new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text);
                }
                else if (temp == "24544A5858") //$SJXX 时间信息
                {
                    //用户地址
                    string RevSatellite = Convert.ToInt64(str.Substring(14, 6), 16).ToString();
                    //日期时间
                    string Date = Convert.ToInt64(str.Substring(20, 4), 16).ToString() + "年" + Convert.ToInt64(str.Substring(24, 2), 16).ToString() + "月" + Convert.ToInt64(str.Substring(26, 2), 16).ToString() + "日";
                    string Time = Convert.ToInt64(str.Substring(28, 2), 16).ToString() + "时" + Convert.ToInt64(str.Substring(30, 2), 16).ToString() + "分" + Convert.ToInt64(str.Substring(32, 2), 16).ToString() + "秒";

                    //反馈给界面信息
                    string Explain = "用户地址" + RevSatellite + ",接收时间信息" + "[" + Date + " " + Time + "]";
                    //ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "接收卫星", "接收数据" + item, new byte[] { }, ServiceEnum.EnCoderType.HEX, ServiceEnum.DataType.Text);

                    ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "", Explain, new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text);
                }
            }



            return(Lcrd);
        }
Beispiel #4
0
        /// <summary>
        /// 从COM口读取数据分包,并处理状态时间等数据报
        /// </summary>
        /// <param name="CS"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static List <ComReceivedData> Subpackage(ComServer CS, byte[] data)
        {
            List <ComReceivedData> Lcrd = new List <ComReceivedData>();
            string str = System.Text.Encoding.ASCII.GetString(data);

            string[] Temp_Strs = str.Split(new string[] { CS.sp.NewLine }, StringSplitOptions.None);

            bool IsCOUT = false;

            foreach (var item in Temp_Strs)
            {
                if (item.Length > 0)
                {
                    string[] temp = item.Split(new string[] { "," }, StringSplitOptions.None);
                    if (temp[0] == "$COUT" && temp.Length >= 10)
                    {
                        int dataLen = 0;
                        if (int.TryParse(temp[7], out dataLen) && dataLen == temp[8].Length)
                        {
                            ComReceivedData crd = new ComReceivedData();
                            crd.SATELLITE = temp[4];
                            //从原始数据报里copy报文
                            byte[] vBuffer = new byte[dataLen];
                            Array.Copy(data, data.Length - dataLen - 4, vBuffer, 0, dataLen);
                            crd.Data = vBuffer;

                            Lcrd.Add(crd);
                        }
                        IsCOUT = true;
                        //反馈给界面信息
                        ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "接收卫星", "接收数据" + temp[0] + "," + temp[1] + "," + temp[2] + "," + temp[3] + "," + temp[4] + "," + temp[5] + "," + temp[6] + "," + temp[7], new byte[] { }, ServiceEnum.EnCoderType.HEX, ServiceEnum.DataType.Text);
                    }
                    //校验状态
                    else if (temp[0] == "$CASS" && temp.Length >= 3)
                    {
                        int    check   = 0;
                        string Explain = "[失败]";
                        if (int.TryParse(temp[1], out check))
                        {
                            if (check == 1)
                            {
                                Explain = "[成功]";
                            }
                        }

                        //反馈给界面信息
                        ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "接收卫星", "接收数据" + item, new byte[] {}, ServiceEnum.EnCoderType.HEX, ServiceEnum.DataType.Text);

                        ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "", "接收校验状态" + Explain, new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text);
                    }
                    //授时信息
                    else if (temp[0] == "$TINF" && temp.Length >= 3)
                    {
                        //反馈给界面信息
                        string Explain = "接收授时信息" + "[" + temp[1] + "]";
                        ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "接收卫星", "接收数据" + item, new byte[] { }, ServiceEnum.EnCoderType.HEX, ServiceEnum.DataType.Text);

                        ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "", Explain, new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text);
                    }
                    //卫星状态
                    else if (temp[0] == "$TSTA" && temp.Length >= 15)
                    {
                        string Satellite = temp[8];
                        string Explain   =
                            "                                                   通道1信号功率:" + temp[1] + "\n" +
                            "                                                   通道2信号功率:" + temp[2] + "\n" +
                            "                                                   通道1卫星波束:" + temp[3] + "\n" +
                            "                                                   通道2卫星波束:" + temp[4] + "\n" +
                            "                                                   响应波束:" + temp[5] + "\n" +
                            "                                                   信号抑制:" + (temp[6] == "0" ? "有" : "无") + "\n" +
                            "                                                   供电状态:" + (temp[7] == "0" ? "异常" : "正常");
                        int Power1      = 0;
                        int Power2      = 0;
                        int Beam1       = 0;
                        int Beam2       = 0;
                        int Response    = 0;
                        int Inhibition  = 0;
                        int PowerSupply = 0;
                        if (int.TryParse(temp[1], out Power1))
                        {
                            CS.CState.Power1 = Power1;
                        }
                        if (int.TryParse(temp[2], out Power2))
                        {
                            CS.CState.Power2 = Power2;
                        }
                        if (int.TryParse(temp[3], out Beam1))
                        {
                            CS.CState.Beam1 = Beam1;
                        }
                        if (int.TryParse(temp[4], out Beam2))
                        {
                            CS.CState.Beam2 = Beam2;
                        }
                        if (int.TryParse(temp[5], out Response))
                        {
                            CS.CState.Response = Response;
                        }
                        if (int.TryParse(temp[6], out Inhibition))
                        {
                            CS.CState.Inhibition = Inhibition;
                        }
                        if (int.TryParse(temp[7], out PowerSupply))
                        {
                            CS.CState.PowerSupply = PowerSupply;
                        }
                        CS.CState.DATATIME = DateTime.Now;
                        ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, Satellite, "接收卫星" + item, new byte[] { }, ServiceEnum.EnCoderType.HEX, ServiceEnum.DataType.Text);

                        ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, Satellite, "接收到状态信息\n" + Explain, new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text);
                    }
                    else
                    {
                        ServiceBussiness.WriteQUIM(ServiceEnum.NFOINDEX.COM.ToString(), CS.ServiceID, "", "接收异常数据" + item, new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text);
                    }
                }
            }
            if (IsCOUT) //如果接收的数据报含有$COUT指令,回复$COSS
            {
                ComBussiness.Reply(CS);
            }
            return(Lcrd);
        }