Exemplo n.º 1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public GPSServer()
        {
            try
            {
                //初始化配置项字典
                ConfigHelper.Init(ConfigScope.GPSService.ToString(), ConfigurationManager.AppSettings["CaseType"], "SelpConnectionStr");
                
                //完成读取配置等初始化工作
                GetConfigPara();

                //开启缓存
                InitCache();


                IGPSDataProcessor storage=null;
                //if (translationType == "tcp")
                //    storage = new TCPGPSDataProcessor(GwBussIPAddress, GwBussUdpPort);
                //else if (translationType == "db")
                storage = new DBGPSDataProcessor();
                //else
                //    storage = new UDPGPSDataProcessor(GwBussIPAddress, GwBussUdpPort);

                Logger.Trace("创建" + translationType + "协议的转发器");

                //创建数据解析器
                CreateDataParser(storage);

                //与应用层关联的解析器
                AnalyseBase AppLayerPaser = null;
                
                if (ProtocolType == "TCP")
                {
                    GpsDataParserTCP.HexDataLogging = GPSHexDataLogging;
                    GpsDataParserTCP.SourceDataPath = PathOfSource;                   
                    TcpServer = new TcpServer(GpsDataParserTCP, localAddress, tcpPort, maxConnections, bufferSize, udpPortByWeb);
                    //收到数据事件(测试)
                    TcpServer.PostConnMsgEvent += new TcpServer.PostConnMsgHandler(OnPostConnMsgEvent);
                    TcpServer.ReceiveDataEvent += new TcpServer.ReceiveDataHandler(OnReceiveDataEvent);
                    //TcpServer.CopyDataEvent += new TcpServer.CopyDataEventHandler(OnCopyDataEvent);
                    //TcpServer.ParsedDataEvent += new TcpServer.ParsedDataHandler(OnParsedDataEvent);
                    GpsDataParserTCP.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                     
                    AppLayerPaser = GpsDataParserTCP;
                }

                else if (ProtocolType == "TCP|UDP")
                {
                    GpsDataParserTCP.HexDataLogging = GPSHexDataLogging;
                    GpsDataParserTCP.SourceDataPath = PathOfSource;
                    TcpServer = new TcpServer(GpsDataParserTCP, localAddress, tcpPort, maxConnections, bufferSize, udpPortByWeb);
                    GpsDataParserTCP.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);

                    GpsDataParserUDP.HexDataLogging = GPSHexDataLogging;
                    GpsDataParserUDP.SourceDataPath = PathOfSource;
                    UdpServer = new UdpServer(GpsDataParserUDP, localAddress, udpPortByGps, maxSendPacket, bufferSize, true, udpPortByWeb);
                    //收到数据事件(测试)
                    UdpServer.PostUdpMsgEvent += new UdpServer.PostUdpMessageHandler(OnPostConnMsgEvent);
                    ////目前博实结协议TCP通道无心跳协议,已通知厂家增加,暂时用UDP通道下发指令
                    //if (GpsDataParserUDP.CodePrefix == "0013")
                    //    AppLayerPaser = GpsDataParserUDP;
                    //else
                        AppLayerPaser = GpsDataParserTCP;

                    //向远端发送数据, updated by lixun on 2010/11/11
                    GpsDataParserUDP.SendDataEvent += new AnalyseBase.SendDataHandler(GpsDataParser_SendDataEvent);
                    GpsDataParserUDP.SendDataWithGPSPortEvent += new AnalyseBase.SendDataWithGPSPortHandler(GpsDataParser_SendDataEvent);
                    GpsDataParserUDP.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                }
                else if (ProtocolType == "UDP")
                {
                    GpsDataParserUDP.HexDataLogging = GPSHexDataLogging; 
                    GpsDataParserUDP.SourceDataPath = PathOfSource;
                    UdpServer = new UdpServer(GpsDataParserUDP, localAddress, udpPortByGps, maxSendPacket, bufferSize, false, udpPortByWeb);

                    //收到数据事件(测试)
                    UdpServer.PostUdpMsgEvent += new UdpServer.PostUdpMessageHandler(OnPostConnMsgEvent);                    
                    AppLayerPaser = GpsDataParserUDP;

                    //向远端发送数据updated by lixun on 2010/11/11
                    //GpsDataParserUDP.SendDataEvent += new AnalyseBase.SendDataHandler(GpsDataParser_SendDataEvent);
                    GpsDataParserUDP.SendDataWithGPSPortEvent += new AnalyseBase.SendDataWithGPSPortHandler(GpsDataParser_SendDataEvent);
                    GpsDataParserUDP.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                }
                if (AppLayerPaser != null)
                {
                    ProcessAppCmd = new SwitchAppLayerCmd(AppLayerPaser, bufferSize, localAddress, udpPortByWeb);
                }
            }
            catch (Exception ex)
            {
                //写日志
                Logger.Error(ex, null);

                //throw ex;
            }
        }
Exemplo n.º 2
0
        private IGPSDataProcessor CreateDataProcessor(byte transferType)
        {
            IGPSDataProcessor storage = null;

            if (transferType == 0)
                storage = new TCPGPSDataProcessor(GwBussIPAddress, GwBussUdpPort);
            else if (transferType == 1)
                storage = new UDPGPSDataProcessor(GwBussIPAddress, GwBussUdpPort);
            else
            {
                //为部标认证使用
                DBGPSDataProcessor dbStorage=new DBGPSDataProcessor();
                //dbStorage.alarmServerIP = GwBussIPAddress.ToString();
                //dbStorage.alarmServerPort = GwBussUdpPort;
               
                storage = dbStorage;
            }
            

            return storage;
        }