示例#1
0
        /// <summary>
        /// 更新ComSatellite对象
        /// </summary>
        /// <param name="CS">COM服务</param>
        /// <param name="Mobile">卫星标识</param>
        /// <param name="STCD">测站编号</param>
        public static void UpdSatellite(ComServer CS, string satellite, string STCD)
        {
            List <ComSatellite> Cs = CS.Cs;

            lock (Cs)
            {
                var temp  = from c in Cs where c.STCD == STCD select c;
                int count = temp.Count <ComSatellite>();
                if (count == 0)
                {
                    temp  = from c in Cs where c.SATELLITE == satellite select c;
                    count = temp.Count <ComSatellite>();
                    if (count == 0)
                    {
                        AddSatellite(CS, satellite, STCD);
                    }
                    else
                    {
                        temp.First().STCD      = STCD;
                        temp.First().DATATIME  = DateTime.Now;
                        temp.First().SATELLITE = satellite;
                    }
                }
                else
                {
                    //更新
                    temp.First().DATATIME  = DateTime.Now;
                    temp.First().SATELLITE = satellite;
                }
            }
        }
示例#2
0
 /// <summary>
 /// 清空召测命令集中的命令
 /// </summary>
 /// <param name="CS">com服务</param>
 public static void ClearCsdQ(ComServer CS)
 {
     lock (CS.CQ.Qcsd)
     {
         CS.CQ.Qcsd = new ConcurrentQueue <ComSendData>();
     }
 }
示例#3
0
        /// <summary>
        /// 将回复数据放入队列
        /// </summary>
        /// <param name="CS">COM服务</param>
        /// <param name="STCD">测站编号</param>
        /// <param name="bt">数据</param>
        public static void WriteCsdQ(ComServer CS, string STCD, byte[] bt)
        {
            ConcurrentQueue <ComSendData> Qcsd = CS.CQ.Qcsd;

            ComSendData csd = new ComSendData();

            csd.Data = bt;
            csd.STCD = STCD;
            lock (Qcsd)
            {
                Qcsd.Enqueue(csd);
            }
        }
示例#4
0
        public ComThread(ComServer Com)
        {
            com = Com;

            //定时向串口发送查询卫星状态指令,确保卫星正常。
            Thread timer_AccessCom = new Thread(new ThreadStart(AccessCom));

            timer_AccessCom.Start();

            //检查召测列表中是否有命令数据
            Thread timer_SendData = new Thread(new ThreadStart(SendData));

            timer_SendData.Start();
        }
示例#5
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);
                }
            }
        }
示例#6
0
        /// <summary>
        /// 发送召侧命令
        /// </summary>
        /// <param name="CS"></param>
        /// <param name="satellite"></param>
        /// <param name="msg"></param>
        public static void SendCommand(ComServer CS, string satellite, byte[] msg)
        {
            if (CS.sp.IsOpen)
            {
                lock (CS.sp)
                {
                    byte[] vBuffer = ASCIIEncoding.ASCII.GetBytes("$TTCA,1," + satellite + ",1,0" + msg.Length + ",");
                    Array.Resize(ref vBuffer, vBuffer.Length + msg.Length + 1);
                    Array.Copy(msg, 0, vBuffer, vBuffer.Length - 1, msg.Length);
                    vBuffer[vBuffer.Length - 1] = (byte)0x2C;

                    Service.ServiceControl.LogInfoToTxt(Service.ServiceEnum.NFOINDEX.COM, "", vBuffer, "ASC");
                    Service.ServiceControl.LogInfoToTxt(Service.ServiceEnum.NFOINDEX.COM, "", vBuffer);
                }
            }
        }
示例#7
0
        /// <summary>
        /// 收到上报数据给卫星回复
        /// </summary>
        /// <param name="CS"></param>
        public static void Reply(ComServer CS)
        {
            if (CS.sp.IsOpen)
            {
                lock (CS.sp)
                {
                    byte[] vBuffer = ASCIIEncoding.ASCII.GetBytes("$COSS,1,");
                    ComBussiness.XorSAT(ref vBuffer);
                    CS.sp.Write(vBuffer, 0, vBuffer.Length);


                    Service.ServiceControl.LogInfoToTxt(Service.ServiceEnum.NFOINDEX.COM, "", vBuffer, "ASC");
                    Service.ServiceControl.LogInfoToTxt(Service.ServiceEnum.NFOINDEX.COM, "", vBuffer);
                }
            }
        }
示例#8
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);
                }
            }
        }
示例#9
0
        /// <summary>
        /// 添加ComSatellite对象
        /// </summary>
        /// <param name="CS">COM服务</param>
        /// <param name="Mobile">卫星标识</param>
        /// <param name="STCD">测站编号</param>
        private static void AddSatellite(ComServer CS, string satellite, string STCD)
        {
            List <ComSatellite> Cs = CS.Cs;

            lock (Cs)
            {
                var temp  = from c in Cs where c.SATELLITE == satellite select c;
                int count = temp.Count <ComSatellite>();
                if (count == 0)
                {
                    //添加
                    ComSatellite cs = new ComSatellite();
                    cs.DATATIME  = DateTime.Now;
                    cs.SATELLITE = satellite;
                    Cs.Add(cs);
                }
            }
        }
示例#10
0
        /// <summary>
        /// 移除召测命令集中的命令
        /// </summary>
        /// <param name="GS">gsm服务</param>
        /// <param name="STCD">站号</param>
        /// <param name="CommandCode">命令码</param>
        public static void RemoveCsdQ(ComServer CS, string STCD, string CommandCode)
        {
            ConcurrentQueue <ComSendData> Qcsd = CS.CQ.Qcsd;

            lock (Qcsd)
            {
                for (int i = 0; i < CS.CQ.Qcsd.Count; i++)
                {
                    ComSendData csd = null;
                    if (Qcsd.TryDequeue(out csd))
                    {
                        if (csd.STCD != STCD || csd.COMMANDCODE != CommandCode)
                        {
                            Qcsd.Enqueue(csd);
                        }
                    }
                }
            }
        }
示例#11
0
        /// <summary>
        /// 将回复数据放入队列
        /// </summary>
        /// <param name="CS">COM服务</param>
        /// <param name="STCD">测站编号</param>
        /// <param name="bt">数据</param>
        public static void WriteCsdQ(ComServer CS, string STCD, byte[] bt, string CommandCode)
        {
            ConcurrentQueue <ComSendData> Qcsd = CS.CQ.Qcsd;

            var qcsd = from c in Qcsd where c.STCD == STCD && c.COMMANDCODE == CommandCode select c;
            List <ComSendData> QCSD = qcsd.ToList <ComSendData>();

            lock (Qcsd)
                if (QCSD.Count() > 0)
                {
                    QCSD.First().Data = bt;
                }
                else
                {
                    ComSendData csd = new ComSendData();
                    csd.Data        = bt;
                    csd.STCD        = STCD;
                    csd.COMMANDCODE = CommandCode;
                    Qcsd.Enqueue(csd);
                }
        }
示例#12
0
        /// <summary>
        /// 从回复队列中回复数据
        /// </summary>
        /// <param name="CS">COM服务</param>
        public static void SendData(ComServer CS)
        {
            string ServiceId = CS.ServiceID;
            ConcurrentQueue <ComSendData> Qcsd = CS.CQ.Qcsd;
            List <ComSatellite>           Cs   = CS.Cs;
            SerialPort sp = CS.sp;

            lock (Qcsd)
            {
                int k = Qcsd.Count;
                while (Qcsd.Count > 0)
                {
                    ComSendData cs = null;
                    Qcsd.TryDequeue(out cs);
                    if (cs != null)
                    {
                        lock (Cs)
                        {
                            var temp = from c in Cs where cs.STCD == c.STCD select c;
                            if (temp.Count() > 0)
                            {
                                sp.WriteLine(Encoding.ASCII.GetString(cs.Data));

                                ServiceBussiness.WriteQUIM("COM", ServiceId, temp.First().STCD, "回复数据", cs.Data, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text);
                            }
                            else
                            {
                                Qcsd.Enqueue(cs);
                            }
                        }
                        k--;
                        if (k <= 0)
                        {
                            return;
                        }
                    }
                }
            }
        }
示例#13
0
        public ComThread(ComServer Com)
        {
            com = Com;

            timer_SendData = new Timer(new TimerCallback(SendData), null, 100, 100);
        }
示例#14
0
 public void SendCommand(ComService.ComServer CS)
 {
     throw new NotImplementedException();
 }
示例#15
0
 /// <summary>
 /// 解析数据包
 /// </summary>
 /// <param name="CS">COM服务</param>
 public static void ResolvePacket(ComServer CS)
 {
     Reflection_Protoco.PacketArrived(CS);
 }
示例#16
0
 /// <summary>
 /// 发送命令方法,短信仅发一次,业务逻辑
 /// </summary>
 /// <param name="GS">GSM服务</param>
 public static void SendCommand(ComServer CS)
 {
     Reflection_Protoco.SendCommand(CS);
 }
示例#17
0
 public void PacketArrived(ComService.ComServer CS)
 {
     throw new NotImplementedException();
 }
示例#18
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);
        }
示例#19
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);
        }