Пример #1
0
        protected override List<GPSDataEntity> AnalyseData(SessionData sessionData)
        {
            //需应答的消息
            List<byte[]> responseMsg = null;
            //GPS Code
            string fullGpsCode = string.Empty;
            GPSLogDataStruct logData = new GPSLogDataStruct();
            List<GPSDataEntity> dataEntitys = new List<GPSDataEntity>();

            logData.buffer = (byte[])sessionData.ReceivedData.Clone();
            logData.ReceiveTime = DateTime.Now;

            dataEntitys = Parse(sessionData.ReceivedData, out responseMsg, out fullGpsCode, sessionData.SessionID);

            if (responseMsg != null && responseMsg.Count > 0)
            {
                foreach (byte[] Msg in responseMsg)
                {
                    OnPostSendHandlerEvent(fullGpsCode, sessionData.SessionID, Msg);
                    Thread.Sleep(50);
                }
            }

            logData.FullGpsCode = fullGpsCode;
            base.AddInLogQueue(logData);

            return dataEntitys;
        }
Пример #2
0
        protected override List<GPSDataEntity> AnalyseData(SessionData sessionData)
        {
            //需应答的消息
            List<byte[]> responseMsg;
            //GPS Code
            string gpsCode = string.Empty;

            List<GPSDataEntity> lstData = null;
            GPSLogDataStruct logData = new GPSLogDataStruct();
            //edit by huangyz Ticket #2956 : 避免记录日志数据是decode之后的数据,保持日志的GPS数据为原始数据。
            logData.buffer = (byte [])sessionData.ReceivedData.Clone();
            logData.ReceiveTime = DateTime.Now;
            lstData = Parse(sessionData.ReceivedData, out responseMsg, out gpsCode, sessionData.SessionID);

            logData.FullGpsCode = gpsCode;
            base.AddInLogQueue(logData); 

            //若有需要应答下发的数据,发送
            if (responseMsg != null && responseMsg.Count > 0)
            {
                foreach (byte[] Msg in responseMsg)
                {
                    if (base.TransfersType == TransfersType.IsTcp)
                        OnPostSendHandlerEvent(gpsCode, sessionData.SessionID, Msg);
                    else
                    {
                        string[] strremortpoint = sessionData.SessionID.Split(':');
                        IPEndPoint ippoint = new IPEndPoint(IPAddress.Parse(strremortpoint[0]), int.Parse(strremortpoint[1]));
                        OnSendDataEvent((EndPoint)ippoint, Msg);
                    }
                }
            }
            return lstData;
        }
Пример #3
0
        protected override List<GPSDataEntity> AnalyseData(SessionData sessionData)
        {
            //需应答的消息
            List<byte[]> responseMsg;
            string gpsCode = string.Empty;
            List<GPSDataEntity> lstData = null;
            GPSLogDataStruct logData = new GPSLogDataStruct();

            try
            {
                logData.buffer = (byte[])sessionData.ReceivedData.Clone();
                logData.ReceiveTime = DateTime.Now;
                lstData = Parse(sessionData.ReceivedData, out responseMsg, out gpsCode, sessionData.SessionID);

                logData.FullGpsCode = gpsCode;
                base.AddInLogQueue(logData);

                if (responseMsg != null && responseMsg.Count > 0)
                {
                    foreach (byte[] Msg in responseMsg)
                    {
                        OnPostSendHandlerEvent(gpsCode, sessionData.SessionID, Msg);
                        Thread.Sleep(50);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            return lstData;
        }
Пример #4
0
 public void AddInLogQueue(GPSLogDataStruct logData)
 {
     lock (_ReceivedLogQueue)
     {
         _ReceivedLogQueue.Enqueue(logData);
     }
 }
Пример #5
0
        /// <summary>
        /// 将收到原始数据加入队列
        /// </summary>
        /// <param name="logData"></param>
        protected void AddInLogQueue(GPSLogDataStruct logData)
        {
            if (_logCollector != null)
            {
                
                _logCollector.AddInLogQueue(logData);
#if DEBUG
                try
                {
                    if (_CodePrefix == "0022" || _CodePrefix=="0099")
                    {
                        string strInfo = Encoding.ASCII.GetString(logData.buffer);
                        OnDebugDataEvent(this._TransfersType.ToString(), logData.FullGpsCode, strInfo);
                    }
                    else
                    {
                        StringBuilder sbBinaryData = new StringBuilder();
                        for (int i = 0; i < logData.buffer.Length; i++)
                        {
                            sbBinaryData.Append(logData.buffer[i].ToString("X2"));
                            if (i < logData.buffer.Length - 1)
                                sbBinaryData.Append(",");
                        }
                        OnDebugDataEvent(this._TransfersType.ToString(), logData.FullGpsCode, sbBinaryData.ToString());
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);  
                }
                
#endif
            }
        }
Пример #6
0
        /// <summary>
        /// 解析接收到的数据
        /// </summary>
        /// <param name="sessionData"></param>
        protected override List<GPSDataEntity> AnalyseData(SessionData sessionData)
        {
            //需应答的消息
            List<byte[]> responseMsg = null;

            //GPS Code
            string fullGpsCode = string.Empty;
            GPSLogDataStruct logData = new GPSLogDataStruct();
            //edit by huangyz Ticket #2956 : 避免记录日志数据是decode之后的数据,保持日志的GPS数据为原始数据。
            logData.buffer = (byte[])sessionData.ReceivedData.Clone();
            logData.ReceiveTime = DateTime.Now;

            List<GPSDataEntity> dataList = new List<GPSDataEntity>();
            GPSDataEntity dataEntity = null;

            //还原数据
            byte[] buffer = BuBiaoData.FromESC(sessionData.ReceivedData);

            byte[] bPrevPkg = null;
            if (_DicPreviousPkg.ContainsKey(sessionData.SessionID))
            {
                bPrevPkg = _DicPreviousPkg[sessionData.SessionID];
            }

            //added by lixun on 2012/6/12 解决粘包
            byte[] Msgbuffer = null;
            if (bPrevPkg == null)
            {
                Msgbuffer = buffer;
            }
            else
            {
                Msgbuffer = BuBiaoData.SuperPorcPasterPkg(bPrevPkg, buffer);
                if (_DicPreviousPkg.ContainsKey(sessionData.SessionID))
                {
                    _DicPreviousPkg.Remove(sessionData.SessionID);
                }
                Logger.Trace("[部标:出现粘包]合包:" + bPrevPkg.Length + " " + buffer.Length);
            }

            if (Msgbuffer[0] != 0x7e)
            {
                StringBuilder sbMsgbuffer1 = new StringBuilder();
                for (int i = 0; i < Msgbuffer.Length; i++)
                {
                    sbMsgbuffer1.Append(Msgbuffer[i].ToString("X2"));
                    if (i < Msgbuffer.Length - 1)
                        sbMsgbuffer1.Append(",");
                }

                if (bPrevPkg == null)
                {
                    Logger.Trace("[部标:出现脏包]" + sbMsgbuffer1.ToString());
                }
                else
                {
                    Logger.Trace("[部标:合包后出现脏包]" + sbMsgbuffer1.ToString());
                }

                return dataList;
            }
            //end added


            //拆分数据
            //List<byte[]> bufferList = BuBiaoDataSpliter.SplitData(buffer);
            List<byte[]> bufferList = BuBiaoDataSpliter.SplitDataEx(Msgbuffer, ref bPrevPkg);
            if (bPrevPkg != null)
            {
                Logger.Trace("[部标:出现粘包]" + Msgbuffer.Length + " " + bPrevPkg.Length);
                if (_DicPreviousPkg.ContainsKey(sessionData.SessionID))
                    _DicPreviousPkg.Remove(sessionData.SessionID);
                _DicPreviousPkg.Add(sessionData.SessionID, bPrevPkg);
            }

            for (int index = 0; index < bufferList.Count; index++)
            {

                //将解决粘包后的数据分发给809平台
                if (base._distributeSevice != null)
                {
                    base._distributeSevice.AddRawData2Queue(bufferList[index]);
                }

                dataEntity = Parse(bufferList[index], out responseMsg, out fullGpsCode, sessionData.SessionID);
                //取得GPSCode
                if (dataEntity != null)
                {
                    //added by lixun 发送网关业务处理服务的GPSCode不能带前缀
                    if (fullGpsCode.StartsWith("0037"))
                        dataEntity.GPSCode = fullGpsCode.Substring(4);
                    else
                        dataEntity.GPSCode = fullGpsCode;

                    //dataEntity.GPSCode = GetGPSCode(sessionData.SessionID);
                    dataList.Add(dataEntity);
                }

                //若有需要应答下发的数据,发送
                if (responseMsg != null && responseMsg.Count > 0)
                {
                    foreach (byte[] Msg in responseMsg)
                    {
                        OnPostSendHandlerEvent(fullGpsCode, sessionData.SessionID, Msg);
                        //Thread.Sleep(500);
                    }
                }
            }

            logData.FullGpsCode = fullGpsCode;
            base.AddInLogQueue(logData);

            return dataList;
        }
Пример #7
0
        protected override List<GPSDataEntity> AnalyseData(SessionData sessionData)
        {
            //需应答的消息
            List<byte[]> responseMsg = null;
            List<GPSDataEntity> dataList = new List<GPSDataEntity>();
            //GPS Code
            string fullGpsCode = string.Empty;
            GPSLogDataStruct logData = new GPSLogDataStruct();

            logData.buffer = (byte[])sessionData.ReceivedData.Clone();
            logData.ReceiveTime = DateTime.Now;

            List<byte[]> bufferList = LianHuaYingKeDataSpliter.SplitData(sessionData.ReceivedData);//对包根据协议分割,以防止粘包的情况出现,目前没有对02设备的包进行分割
            if (bufferList != null && bufferList.Count > 0)
            {

                foreach (byte[] buffer in bufferList)
                {
                    GPSDataEntity dataEntity = Parse(buffer, out responseMsg, out fullGpsCode, sessionData.SessionID);

                    if (dataEntity != null)
                        dataList.Add(dataEntity);

                    if (responseMsg != null && responseMsg.Count > 0)
                    {
                        foreach (byte[] Msg in responseMsg)
                        {
                            OnPostSendHandlerEvent(fullGpsCode, sessionData.SessionID, Msg);
                            Thread.Sleep(50);
                        }
                    }
                }
            }

            logData.FullGpsCode = fullGpsCode;
            base.AddInLogQueue(logData);
            return dataList;
        }
Пример #8
0
        /// <summary>
        /// 解析接收到的数据
        /// </summary>
        /// <param name="sessionData"></param>
        protected override List<GPSDataEntity> AnalyseData(SessionData sessionData)
        {
            //需应答的消息
            List<byte[]> responseMsg = null;

            //GPS Code
            string fullGpsCode = string.Empty;
            GPSLogDataStruct logData = new GPSLogDataStruct();
            //edit by huangyz Ticket #2956 : 避免记录日志数据是decode之后的数据,保持日志的GPS数据为原始数据。
            logData.buffer = (byte[])sessionData.ReceivedData.Clone();
            logData.ReceiveTime = DateTime.Now;

            List<GPSDataEntity> dataList = new List<GPSDataEntity>();

            GPSDataEntity dataEntity = null;
            //拆分数据
            List<byte[]> bufferList = YaXunDataSpliter.SplitData(sessionData.ReceivedData);

            for (int index = 0; index < bufferList.Count; index++)
            {
                //转义数据
                byte[] buffer = YaXunDataSpliter.BufferFromESC(bufferList[index]);
                dataEntity = Parse(buffer, out responseMsg, out fullGpsCode, sessionData.SessionID);

                //取得GPSCode
                if (dataEntity != null)
                {
                    //added by lixun 发送网关业务处理服务的GPSCode不能带前缀
                    if (fullGpsCode.StartsWith("0019"))
                        dataEntity.GPSCode = fullGpsCode.Substring(4);
                    else
                        dataEntity.GPSCode = fullGpsCode;

                    //dataEntity.GPSCode = GetGPSCode(sessionData.SessionID);
                    dataList.Add(dataEntity);
                }    

#if DEVELOPMENT

                if (dataEntity != null && dataEntity.IsLocatedData)
                {
                    Logger.Info("gpscode=" + dataEntity.GPSCode + "lon=" + dataEntity.Longitude.ToString() + ",lat=" + dataEntity.Latitude.ToString());
                }
#endif

                //若有需要应答下发的数据,发送
                if (responseMsg != null && responseMsg.Count > 0)
                {
                    foreach (byte[] Msg in responseMsg)
                    {
                        OnPostSendHandlerEvent(fullGpsCode, sessionData.SessionID, Msg);
                        Thread.Sleep(500);
                    }
                }
            }

            logData.FullGpsCode = fullGpsCode;
            base.AddInLogQueue(logData);

            return dataList;
        }
Пример #9
0
        /// <summary> 解析数据入口
        /// 解析数据入口
        /// </summary>
        /// <param name="sessionData"></param>
        /// <returns></returns>
        protected override List<GPSDataEntity> AnalyseData(SessionData sessionData)
        {
            //需应答的消息
            List<byte[]> responseMsg;


            //GPS Code
            string gpsCode = string.Empty;

            List<GPSDataEntity> lstData = null;
            GPSLogDataStruct logData = new GPSLogDataStruct();
            //edit by huangyz Ticket #2956 : 避免记录日志数据是decode之后的数据,保持日志的GPS数据为原始数据。
            logData.buffer = (byte [])sessionData.ReceivedData.Clone();
            logData.ReceiveTime = DateTime.Now;
            lstData = Parse(sessionData.ReceivedData, out responseMsg, out gpsCode, sessionData.SessionID);

            logData.FullGpsCode = gpsCode;
            base.AddInLogQueue(logData);

            //若有需要应答下发的数据,发送
            if (responseMsg != null && responseMsg.Count > 0)
            {
                foreach (byte[] Msg in responseMsg)
                {
                    string[] strremortpoint = sessionData.SessionID.Split(':');
                    IPEndPoint ippoint = new IPEndPoint(IPAddress.Parse(strremortpoint[0]), int.Parse(strremortpoint[1]));
                    //updated by lixun 解决向远端发送数据用udpPortByGps绑定的端口发,解决星安回复消息本地端口必须为指定GPS端口
                    //OnSendDataEvent((EndPoint)ippoint, Msg);
                    OnSendDataWithGPSPortEvent((EndPoint)ippoint,Msg);
                    Logger.Info("已下发星按GPS " + "0001" + gpsCode + " 的数据,长度" + Msg.Length + ",IP=" + ippoint.Address.ToString() + ",Port=" + ippoint.Port.ToString());
                    //end update
                    
                    //OnPostSendHandlerEvent(gpsCode, sessionData.SessionID, Msg);
                }
            }
            return lstData;
        }
Пример #10
0
        protected override List<GPSDataEntity> AnalyseData(SessionData sessionData)
        {
            //需应答的消息
            List<byte[]> responseMsg = null;
            List<GPSDataEntity> dataList = new List<GPSDataEntity>();
            //GPS Code
            string fullGpsCode = string.Empty;
            GPSLogDataStruct logData = new GPSLogDataStruct();

            logData.buffer = (byte[])sessionData.ReceivedData.Clone();
            logData.ReceiveTime = DateTime.Now;

            try
            {
                List<byte[]> bufferList = KangKaiSiDataSpliter.SplitData(sessionData.ReceivedData);//对包根据协议分割,以防止粘包的情况出现,目前没有对02设备的包进行分割
                if (bufferList != null && bufferList.Count > 0)
                {

                    foreach (byte[] buffer in bufferList)
                    {
                        GPSDataEntity dataEntity = Parse(buffer, out responseMsg, out fullGpsCode, sessionData.SessionID);

                        //Liuhuaihai Add on 2012/9/7
                        //如果上报的数据是1小时前的数据,抛弃这种数据
                        if (dataEntity != null)
                        {
                            double reportDataTimeInterval = (DateTime.Now - dataEntity.ReportTime).TotalHours;

                            if (reportDataTimeInterval > 1)
                            {
                                Logger.Trace("Receive the " + dataEntity.GPSCode + "'s history data!");
                                dataEntity = null;
                            }
                            else
                            {
                                dataList.Add(dataEntity);
                            }                            
                        }
                        //

                        if (responseMsg != null && responseMsg.Count > 0)
                        {
                            foreach (byte[] Msg in responseMsg)
                            {
                                OnPostSendHandlerEvent(fullGpsCode, sessionData.SessionID, Msg);
                                Thread.Sleep(50);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            logData.FullGpsCode = fullGpsCode;
            base.AddInLogQueue(logData);
            return dataList;
        }
Пример #11
0
        /// <summary>
        /// 解析接收到的数据
        /// </summary>
        /// <param name="sessionData"></param>
        protected override List<GPSDataEntity> AnalyseData(SessionData sessionData)
        {
            List<GPSDataEntity> lstData = null;
            try
            {                
                //需应答的消息
                List<byte[]> responseMsg;

                //GPS Code
                string fullGpsCode = string.Empty;
                GPSLogDataStruct logData = new GPSLogDataStruct();
                //edit by huangyz Ticket #2956 : 避免记录日志数据是decode之后的数据,保持日志的GPS数据为原始数据。
                logData.buffer = (byte[])sessionData.ReceivedData.Clone();
                logData.ReceiveTime = DateTime.Now;
                lstData = Parse(sessionData.ReceivedData, out responseMsg, out fullGpsCode, sessionData.SessionID);

                logData.FullGpsCode = fullGpsCode;
                base.AddInLogQueue(logData);
                //if (lstData != null && lstData.Count > 0)
                    //base.OnParsedDataEvent();

                //若有需要应答下发的数据,发送
                if (responseMsg != null && responseMsg.Count > 0)
                {
                    foreach (byte[] Msg in responseMsg)
                    {
                        OnPostSendHandlerEvent(fullGpsCode, sessionData.SessionID, Msg);
                    }
                }

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