예제 #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;
            }
        }
예제 #2
0
        private void CreateDataParser()
        {
            IGPSDataProcessor storage = null;
            AnalyseBase analyseBaser = null;
            TcpServer tcpServer = null;
            UdpServer udpServer = null;

            try
            {
                switcher = new Switcher4WebApp(bufferSize, localAddress, udpPortByWeb);

                string[] aryServers = sServersConfig.Split('|');
                foreach (string serverinfo in aryServers)
                {
                    if (serverinfo.Length > 0)
                    {
                        string[] aryConfig = serverinfo.Split(';');
                        string gpsType = aryConfig[0];
                        byte transferType = byte.Parse(aryConfig[2]);

                        string[] aryPort = aryConfig[1].Split(',');
                        int port1 = Int32.Parse(aryPort[0]);
                        int port2 = 0;
                        if (aryPort.Length > 1)
                        {
                            port2 = Int32.Parse(aryPort[1]); 
                        }

                        storage = CreateDataProcessor(transferType);
                        storage.CodePrefix = gpsType;

                        switch (gpsType)
                        {
                            case "0001":

                                analyseBaser = new XinAnDataParser(gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                udpServer = new UdpServer(analyseBaser, localAddress, port1, maxSendPacket, bufferSize, false, udpPortByWeb);
                                XinAnUdpServer = udpServer;

                                analyseBaser.SendDataWithGPSPortEvent += new AnalyseBase.SendDataWithGPSPortHandler(Send2XinAnDevice);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);
                                break;
                            case "0007":
                                analyseBaser = new KaiYanDataParser(TransfersType.IsTcp, gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);


                                analyseBaser = new KaiYanDataParser(TransfersType.IsUdp, gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                udpServer = new UdpServer(analyseBaser, localAddress, port2, maxSendPacket, bufferSize, false, udpPortByWeb);
                                KaiYanUdpServer = udpServer;
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(Send2KaiYanDevice);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType + "_1", analyseBaser);

                                break;
                            case "0009":
                                analyseBaser = new YouWeiDataParser(gpsType, false, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);


                                break;
                            case "0013":
                                analyseBaser = new BoShiJieDataParser(TransfersType.IsTcp, gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);


                                analyseBaser = new BoShiJieDataParser(TransfersType.IsUdp, gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                udpServer = new UdpServer(analyseBaser, localAddress, port2, maxSendPacket, bufferSize, false, udpPortByWeb);
                                BoShiJieUdpServer = udpServer;
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.SendDataWithGPSPortEvent += new AnalyseBase.SendDataWithGPSPortHandler(Send2BoShiJieDevice);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType + "_1", analyseBaser);

                                break;
                            case "0014":
                                analyseBaser = new DiBiaoDataParser(TransfersType.IsTcp, gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);
                                break;
                            case "0016":
                                analyseBaser = new LongHanDataParser(TransfersType.IsTcp, gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);


                                analyseBaser = new LongHanDataParser(TransfersType.IsUdp, gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                udpServer = new UdpServer(analyseBaser, localAddress, port2, maxSendPacket, bufferSize, false, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.SendDataWithGPSPortEvent += new AnalyseBase.SendDataWithGPSPortHandler(switcher.SendDataHandler);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType + "_1", analyseBaser);

                                break;
                            //0020部标
                            case "0020":
                                analyseBaser = new BuBiaoDataParser(gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                //分发给部标对接服务
                                analyseBaser.Distributor = lstDistributor;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);
                                break;
                            case "0022":
                                analyseBaser = new YongHuaDataParser(gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);
                                break;
                            //康凯斯
                            case "0023":
                                analyseBaser = new KangKaiSiDataParser(gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);
                                break;
                            //联华盈科
                            case "0033":
                                analyseBaser = new LianHuaYingKeDataParser(gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);
                                break;
                            //深圳中讯
                            case "0035":
                                analyseBaser = new ZhongXunDataParser(gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);
                                break;
                            //键车宝
                            case "0036":
                                analyseBaser = new JianCheBaoDataParser(gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);
                                break;
                            //华宝部标 A5
                            case "0037":
                                analyseBaser = new GPSHBBuBiaoDataParser(gpsType, storage);
                                analyseBaser.HexDataLogging = GPSHexDataLogging;
                                analyseBaser.SourceDataPath = PathOfSource;
                                tcpServer = new TcpServer(analyseBaser, localAddress, port1, maxConnections, bufferSize, udpPortByWeb);
                                analyseBaser.DebugDataEvent += new AnalyseBase.DebugDataEventHandler(OnDebugDataEvent);
                                analyseBaser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(switcher.PostAckMsgHandler);
                                analyseBaser.SendDataEvent += new AnalyseBase.SendDataHandler(switcher.SendDataHandler);
                                analyseBaser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(switcher.SetWebTable);
                                analyseBaser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(switcher.SendAnswerToWeb);
                                CheckTaskThread.GetInstance().AddParserInstance(gpsType, analyseBaser);
                                break;
                        }

                    }
                }
                
            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
            }

        }