Ejemplo n.º 1
0
 /// <summary>
 /// 清空召测命令集中的命令
 /// </summary>
 /// <param name="GS">gsm服务</param>
 public static void ClearGsdQ(GsmServer GS)
 {
     lock (GS.GQ.Qgsd)
     {
         GS.GQ.Qgsd = new ConcurrentQueue <GsmSendData>();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新GsmMobile对象
        /// </summary>
        /// <param name="GS">GSM服务</param>
        /// <param name="Mobile">测站手机号</param>
        /// <param name="STCD">测站编号</param>
        public static void UpdMobile(GsmServer GS, string Mobile, string STCD)
        {
            List <GsmMobile> Gs = GS.Gs;

            lock (Gs)
            {
                var temp = from g in Gs where g.STCD == STCD select g;
                List <GsmMobile> TEMP = temp.ToList <GsmMobile>();
                int count             = TEMP.Count <GsmMobile>();
                if (count == 0)
                {
                    temp  = from g in Gs where g.MOBILE == Mobile select g;
                    TEMP  = temp.ToList <GsmMobile>();
                    count = TEMP.Count <GsmMobile>();
                    if (count == 0)//Add
                    {
                        AddMobile(GS, Mobile, STCD);
                    }
                    else//Upd
                    {
                        TEMP.First().STCD     = STCD;
                        TEMP.First().DATATIME = DateTime.Now;
                        TEMP.First().MOBILE   = Mobile;
                    }
                }
                else
                {
                    //更新
                    TEMP.First().DATATIME = DateTime.Now;
                    TEMP.First().MOBILE   = Mobile;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 将回复数据放入队列
        /// </summary>
        /// <param name="GS">GSM服务</param>
        /// <param name="STCD">测站编号</param>
        /// <param name="bt">数据</param>
        public static void WriteGsdQ(GsmServer GS, string STCD, byte[] bt)
        {
            ConcurrentQueue <GsmSendData> Qgsd = GS.GQ.Qgsd;

            GsmSendData gsd = new GsmSendData();

            gsd.Data = bt;
            gsd.STCD = STCD;
            lock (Qgsd)
            {
                Qgsd.Enqueue(gsd);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 从回复队列中回复数据(未使用)
        /// </summary>
        /// <param name="GS">GSM服务</param>
        public static void SendData(GsmServer GS)
        {
            string ServiceId = GS.ServiceID;
            ConcurrentQueue <GsmSendData> Qgsd = GS.GQ.Qgsd;
            List <GsmMobile> Gs = GS.Gs;

            GSMMODEM.GsmModem gm = GS.gm;

            lock (Qgsd)
            {
                int k = Qgsd.Count;
                while (Qgsd.Count > 0)
                {
                    GsmSendData gs = null;
                    Qgsd.TryDequeue(out gs);
                    if (gs != null)
                    {
                        lock (Gs)
                        {
                            var temp = from g in Gs where gs.STCD == g.STCD select g;
                            List <GsmMobile> TEMP = temp.ToList <GsmMobile>();
                            if (TEMP.Count() > 0)
                            {
                                try
                                {
                                    gm.SendMsg(TEMP.First().MOBILE, gs.Data);
                                }
                                catch (Exception ex)
                                {
                                    ServiceControl.log.Error(DateTime.Now + ex.ToString());
                                }
                                //ServiceBussiness.WriteQUIM("GSM", ServiceId, temp.First().STCD, "回复数据", gs.Data, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text);
                            }
                            else
                            {
                                Qgsd.Enqueue(gs);
                            }
                        }
                        k--;
                        if (k <= 0)
                        {
                            return;
                        }
                    }

                    System.Threading.Thread.Sleep(800);
                }
            }
        }
Ejemplo n.º 5
0
        public GsmThread(GsmServer Gsm)
        {
            gsm = Gsm;


            Thread timer_ReadGSMCard = new Thread(new ThreadStart(ReadGSMCard));

            timer_ReadGSMCard.Start();

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

            timer_SendData.Start();

            //职守线程每5分钟检查1次与串口交互时间,如5分钟内无交互,重启串口。
            timer_CheckSerialPort = new Timer(new TimerCallback(CheckSerialPort), null, 5 * 60 * 1000, 5 * 60 * 1000);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 将收到数据放入数据队列
        /// </summary>
        /// <param name="GS">GSM服务</param>
        /// <param name="senddatetime">发送时间</param>
        /// <param name="bt">数据</param>
        public static void WriteGrdQ(GsmServer GS, string mobile, DateTime senddatetime, byte[] bt)
        {
            ConcurrentQueue <GsmReceivedData> Qgrd = GS.GQ.Qgrd;

            GsmReceivedData grd = new GsmReceivedData();

            grd.MOBILE       = mobile;
            grd.SENDDATETIME = senddatetime;
            grd.Data         = bt;
            if (bt.Length > 0)
            {
                lock (Qgrd)
                {
                    Qgrd.Enqueue(grd);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 添加GsmMobile对象
        /// </summary>
        /// <param name="GS">GSM服务</param>
        /// <param name="Mobile">测站手机号</param>
        /// <param name="STCD">测站编号</param>
        private static void AddMobile(GsmServer GS, string Mobile, string STCD)
        {
            List <GsmMobile> Gs = GS.Gs;

            lock (Gs)
            {
                var temp  = from g in Gs where g.MOBILE == Mobile select g;
                int count = temp.Count <GsmMobile>();
                if (count == 0)
                {
                    //添加
                    GsmMobile gs = new GsmMobile();
                    gs.DATATIME = DateTime.Now;
                    gs.MOBILE   = Mobile;
                    Gs.Add(gs);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 移除召测命令集中的命令
        /// </summary>
        /// <param name="GS">gsm服务</param>
        /// <param name="STCD">站号</param>
        /// <param name="CommandCode">命令码</param>
        public static void RemoveGsdQ(GsmServer GS, string STCD, string CommandCode)
        {
            ConcurrentQueue <GsmSendData> Qgsd = GS.GQ.Qgsd;

            lock (Qgsd)
            {
                for (int i = 0; i < GS.GQ.Qgsd.Count; i++)
                {
                    GsmSendData gsd = null;
                    if (Qgsd.TryDequeue(out gsd))
                    {
                        if (gsd.STCD != STCD || gsd.COMMANDCODE != CommandCode)
                        {
                            Qgsd.Enqueue(gsd);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 从回复队列中回复数据
        /// </summary>
        /// <param name="GS">GSM服务</param>
        public static void SendData(GsmServer GS)
        {
            //string ServiceId=GS.ServiceID;
            //ConcurrentQueue<GsmSendData> Qgsd=GS.GQ.Qgsd;
            //List<GsmMobile> Gs=GS.Gs;
            //GSMMODEM.GsmModem gm = GS.gm;

            //lock (Qgsd)
            //{
            //    int k = Qgsd.Count;
            //    while (Qgsd.Count > 0)
            //    {
            //        GsmSendData gs = null;
            //        Qgsd.TryDequeue(out gs);
            //        if (gs != null)
            //        {
            //            lock (Gs)
            //            {
            //                var temp = from g in Gs where gs.STCD == g.STCD select g;
            //                if (temp.Count() > 0)
            //                {
            //                    gm.SendMsg(temp.First().MOBILE,Encoding.Default.GetString(gs.Data));

            //                    ServiceBussiness.WriteQUIM("GSM", ServiceId, temp.First().STCD, "回复数据", gs.Data, ServiceBussiness.EnCoderType.HEX,ServiceBussiness.DataType.Text);
            //                }
            //                else
            //                {
            //                    Qgsd.Enqueue(gs);
            //                }

            //            }
            //            k--;
            //            if (k <= 0)
            //            {
            //                return;
            //            }
            //        }

            //    }
            //}
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 将回复数据放入队列
        /// </summary>
        /// <param name="GS">GSM服务</param>
        /// <param name="STCD">测站编号</param>
        /// <param name="bt">数据</param>
        /// <param name="CommandCode">命令码</param>
        public static void WriteGsdQ(GsmServer GS, string STCD, byte[] bt, string CommandCode)
        {
            ConcurrentQueue <GsmSendData> Qgsd = GS.GQ.Qgsd;

            var qgsd = from g in Qgsd where g.STCD == STCD && g.COMMANDCODE == CommandCode select g;
            List <GsmSendData> QGSD = qgsd.ToList <GsmSendData>();

            lock (Qgsd)
                if (QGSD.Count() > 0)
                {
                    QGSD.First().Data = bt;
                }
                else
                {
                    GsmSendData gsd = new GsmSendData();
                    gsd.Data        = bt;
                    gsd.STCD        = STCD;
                    gsd.COMMANDCODE = CommandCode;
                    Qgsd.Enqueue(gsd);
                }
        }
Ejemplo n.º 11
0
        //与串口交互后,如有异常重启串口
        void Restart(GsmServer gsm)
        {
            string result = gsm.gm.SendAT("AT+CGMI");

            if (result == null || !result.Contains("OK"))
            {
                try
                {
                    gsm.Stop();
                    Thread.Sleep(3 * 1000);
                    gsm.Start();
                    Console.WriteLine(DateTime.Now + "定时与串口交互异常," + "Restart!");
                }
                catch (Exception ex)
                { Console.WriteLine(DateTime.Now + ex.ToString()); }
            }
            else
            {
                Console.WriteLine(DateTime.Now + " " + "living!");
            }

            dtime = DateTime.Now;
        }
Ejemplo n.º 12
0
 public void SendCommand(GsmService.GsmServer GS)
 {
     //throw new NotImplementedException();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 接收数据时收到未设置测站信息,自动将测站信息入库并在列表中添加
        /// </summary>
        /// <param name="STCD">站号</param>
        /// <param name="NFOINDEX">信道类型</param>
        /// <param name="Server">服务</param>
        public void InsertNewSTCD(string STCD, Service.ServiceEnum.NFOINDEX NFOINDEX, object Server)
        {
            if (STCD.Length == 0)
            {
                return;
            }
            var rtu = from r in Service.ServiceBussiness.RtuList where r.STCD == STCD select r;

            if (rtu.Count() == 0)
            {
                Service.Model.YY_RTU_Basic model = new Service.Model.YY_RTU_Basic();
                model.STCD     = STCD;
                model.PassWord = "******";
                model.NiceName = STCD;
                bool b = PublicBD.db.AddRTU(model);     //添加
                if (b)
                {
                    Service.ServiceBussiness.RtuList.Add(new Service.Model.YY_RTU_Basic()
                    {
                        STCD = STCD, NiceName = STCD, PassWord = "******"
                    });
                }
            }
            if (NFOINDEX == Service.ServiceEnum.NFOINDEX.UDP)
            {
                UdpService.UdpServer        US = Server as UdpService.UdpServer;
                List <UdpService.UdpSocket> Us = US.Us;
                var udps = from u in Us where u.STCD == STCD select u;
                if (udps.Count() == 0)
                {
                    UdpSocket us = new UdpSocket()
                    {
                        STCD = STCD
                    };
                    Us.Add(us);
                }
            }
            else if (NFOINDEX == Service.ServiceEnum.NFOINDEX.TCP)
            {
                TcpService.TcpServer        TS = Server as TcpService.TcpServer;
                List <TcpService.TcpSocket> Ts = TS.Ts;
                var tcps = from t in Ts where t.STCD == STCD select t;
                if (tcps.Count() == 0)
                {
                    TcpSocket ts = new TcpSocket()
                    {
                        STCD = STCD
                    };
                    Ts.Add(ts);
                }
            }
            else if (NFOINDEX == Service.ServiceEnum.NFOINDEX.GSM)
            {
                if (STCD != null || STCD != "")
                {
                    GsmService.GsmServer        GS = Server as GsmService.GsmServer;
                    List <GsmService.GsmMobile> Gs = GS.Gs;
                    var gsms = from g in Gs where g.STCD == STCD select g;
                    if (gsms.Count() == 0)
                    {
                        GsmMobile gs = new GsmMobile()
                        {
                            STCD = STCD
                        };
                        Gs.Add(gs);
                    }
                }
            }
            //else if (NFOINDEX == Service.ServiceEnum.NFOINDEX.COM)
            //{
            //    ComService.ComServer CS = Server as ComService.ComServer;
            //    List<ComService.ComSatellite> Cs = CS.Cs;
            //    var coms = from g in Cs where g.STCD == STCD select g;
            //    if (coms.Count() == 0)
            //    {

            //    }
            //}
        }
Ejemplo n.º 14
0
 public void PacketArrived(GsmService.GsmServer GS)
 {
     //throw new NotImplementedException();
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 解析数据包
 /// </summary>
 /// <param name="GS">GSM服务</param>
 public static void ResolvePacket(GsmServer GS)
 {
     Reflection_Protoco.PacketArrived(GS);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 发送命令方法,短信仅发一次,业务逻辑
 /// </summary>
 /// <param name="GS">GSM服务</param>
 public static void SendCommand(GsmServer GS)
 {
     Reflection_Protoco.SendCommand(GS);
 }
Ejemplo n.º 17
0
        public GsmThread(GsmServer Gsm)
        {
            gsm = Gsm;

            timer_SendData = new Timer(new TimerCallback(SendData), null, 100, 100);
        }