Esempio n. 1
0
        static void th11s_Server_NewRequestReceived(TH11SProtocolSession session, SuperSocket.SocketBase.Protocol.BinaryRequestInfo requestInfo)
        {
            //string remoteEndPoint = session.RemoteEndPoint.Address + ":" + session.RemoteEndPoint.Port.ToString();
            string terminalType = DeviceCode.TH11S;
            string DeviceSN     = "";

            //处理设备的登陆信息
            handleDeviceInfo(terminalType, requestInfo.Key.Substring(0, 2), session.RemoteEndPoint.Address.ToString(), session.RemoteEndPoint.Port.ToString(), out DeviceSN);

            //获取原始监控数据
            InspectOriginalData oData = new TH11SDataResolver().CreateOriginalData(DeviceSN, requestInfo);

            //解析监控数据
            List <InspectItemData> itemDatas = new TH11SDataResolver().ResolveItemData(oData);

            ///保存监测数据
            saveData(oData, itemDatas);

            ///打印采集信息
            printData(session.SessionID, session.RemoteEndPoint.Address.ToString(), session.RemoteEndPoint.Port.ToString(), oData, itemDatas);

            ////更新当前连接信息到静态变量中,用于定时清理垃圾session
            //CommonSession cs = ThJob.getTh11s(session.SessionID);
            //if (cs != null)
            //{
            //    cs.session = session;
            //    ThJob.updateTh11s(session.SessionID, cs);
            //}
        }
Esempio n. 2
0
        static void th11s_Server_SessionClosed(TH11SProtocolSession session, CloseReason value)
        {
            //识别码_IP生成KEY用于保存session
            string key = session.SessionID;

            ThJob.removeTh11s(key);
            //连接关闭
            printColsed(session.SessionID);
        }
Esempio n. 3
0
        static void th11s_Server_NewSessionConnected(TH11SProtocolSession session)
        {
            //识别码_IP生成KEY用于保存session
            string        key = session.SessionID;
            CommonSession cs  = new CommonSession();

            cs.session = session;
            ThJob.addTh11s(key, cs);
            ///连接打开
            printConnectioned(session.SessionID, session.RemoteEndPoint.Address.ToString(), session.RemoteEndPoint.Port.ToString());
        }
Esempio n. 4
0
        public void Execute(IJobExecutionContext context)
        {
            List <string> delList = new List <string>();

            //定时清理指定时间之前的SESSION连接
            foreach (KeyValuePair <string, CommonSession> th in th10w)
            {
                if (th.Value != null)
                {
                    //定时下发查询指令
                    TH10WProtocolSession session = ((TH10WProtocolSession)(th.Value).session);
                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeTh10w(key);
                }
            }

            delList = new List <string>();

            //th11s定时下发查询指令
            foreach (KeyValuePair <string, CommonSession> th in th11s)
            {
                if (th.Value != null)
                {
                    //定时下发查询指令
                    TH11SProtocolSession session = ((TH11SProtocolSession)(th.Value).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    session.Send("010300000002C40B");
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeTh11s(key);
                }
            }

            delList = new List <string>();

            //ane定时下发查询指令
            foreach (KeyValuePair <string, CommonSession> th in anemoclinoGrap)
            {
                if (th.Value != null)
                {
                    //定时下发查询指令
                    ANEMOCLINOGRAPProtocolSession session = ((ANEMOCLINOGRAPProtocolSession)(th.Value).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    session.Send("0101C1E0");
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeAnemoclinoGrap(key);
                }
            }

            delList = new List <string>();

            //ACTW-CAR小型清洁刷式温盐传感器
            foreach (KeyValuePair <string, CommonSession> th in tw)
            {
                if (th.Value != null)
                {
                    CommonSession cs = th.Value;
                    //定时下发查询指令
                    ACTWCARProtocolSession session = ((ACTWCARProtocolSession)(cs).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    if (!ThJob.twIsWorking(th.Key))
                    {
                        session.Send("1111776970652C302C0D");
                        //设置设备工作状态
                        ThJob.setTwIsWorking(th.Key, true);
                    }
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeTw(key);
                }
            }

            delList = new List <string>();

            //ACLW-CAR传感器通讯协议与电气参数
            foreach (KeyValuePair <string, CommonSession> th in lw)
            {
                if (th.Value != null)
                {
                    CommonSession cs = th.Value;
                    //定时下发查询指令
                    ACLWCARProtocolSession session = ((ACLWCARProtocolSession)(cs).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    if (!ThJob.lwIsWorking(th.Key))
                    {
                        session.Send("1111776970652C302C0D");
                        ThJob.setLwIsWorking(th.Key, true);
                    }
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeLw(key);
                }
            }

            delList = new List <string>();

            //百叶箱光照传感器
            foreach (KeyValuePair <string, CommonSession> th in lls)
            {
                if (th.Value != null)
                {
                    CommonSession cs = th.Value;
                    //定时下发查询指令
                    LouverlightSensorProtocolSession session = ((LouverlightSensorProtocolSession)(cs).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    session.Send("010300000006C5C8");
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeLouverlightSensor(key);
                }
            }
        }