示例#1
0
        /// <summary>
        /// 组合设置短信中心号码(粗略写,暂时测试用)
        /// </summary>
        /// <returns></returns>
        public byte[] GetMsgCenterNumber(string Telephone)
        {
            byte[] YxData;
            YaXunSubmitData YaXunSubmitDataObj;
            //设置短信中心号码
            YaXunSubmitDataObj = new YaXunSubmitData();
            YaXunSubmitDataObj.areaNum = 0x7f38;
            YaXunSubmitDataObj.businessType = BusinessType.UserManage;
            YaXunSubmitDataObj.dataType = DataType.SetShortMsgCenterNum;
            YaXunSubmitDataObj.destPhone = Telephone;
            YaXunSubmitDataObj.sourcePhone = Telephone;
            //数据:+8613800592500
            YxData = new byte[28]{0x2b,0x38 ,0x36 ,0x31 ,0x33 ,0x38 ,0x30 ,0x30 ,0x35 ,0x39 ,0x32 
                                    ,0x35 ,0x30 ,0x30 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x31 ,0x31 ,0x31 ,0x31 ,0x31 ,0x31};

            YaXunSubmitDataObj.data = YxData;
            byte[] destBuffer = new byte[YaXunSubmitDataObj.GetLength()];
            YaXunSubmitDataObj.WriteBuffer(destBuffer);
            //GPRS信息帧数据
            GPRSFrame gprsFrame = new GPRSFrame();
            gprsFrame.Data = destBuffer;
            gprsFrame.CmdType = GPRSCmdType.GPRSTransferData;
            destBuffer = new byte[gprsFrame.GetLength()];
            gprsFrame.WriteBuffer(destBuffer);

            return YaXunDataSpliter.BufferToESC(destBuffer);
        }
示例#2
0
        /// <summary>
        /// 组合链路探测报文
        /// </summary>
        /// <returns></returns>
        public byte[] GetGPRSSeekLink()
        {
            //下发个链路探测命令(设置下次探测时间为5分钟)
            byte[] dataBuffer = new byte[1] { 0x05 };
            //GPRS信息帧数据
            GPRSFrame gprsFrame = new GPRSFrame();
            gprsFrame.Data = dataBuffer;
            gprsFrame.CmdType = GPRSCmdType.GPRSSeekLink;
            byte[] destBuffer = new byte[gprsFrame.GetLength()];
            gprsFrame.WriteBuffer(destBuffer);

            return YaXunDataSpliter.BufferToESC(destBuffer);
        }
示例#3
0
        /// <summary>
        /// 设置下监控请求(粗略写,暂时测试用)
        /// </summary>
        /// <param name="Telephone"></param>
        /// <returns></returns>
        public byte[] GetMonitorReq(string Telephone)
        {
            //设置下监控请求
            YaXunSubmitData YaXunSubmitDataObj = new YaXunSubmitData();
            YaXunSubmitDataObj.areaNum = 0x7f38;
            YaXunSubmitDataObj.businessType = BusinessType.CircuitMonitor;
            YaXunSubmitDataObj.dataType = DataType.MonitorReq;
            YaXunSubmitDataObj.destPhone = Telephone;
            YaXunSubmitDataObj.sourcePhone = Telephone;
            //数据
            byte[] YxData = new byte[9];
            YxData[0] = 0x42;//定时更新 
            YxData[1] = 0x7f;//永久监控
            YxData[2] = 0x7f;//
            YxData[3] = 0x7f;//10秒一次
            YxData[4] = 0x0a;//
            YxData[5] = 0x7f;//监控距离
            YxData[6] = 0x7f;//
            YxData[7] = 0x7f;//上传GPS条数
            YxData[8] = 0x0a;//

            YaXunSubmitDataObj.data = YxData;
            byte[] destBuffer = new byte[YaXunSubmitDataObj.GetLength()];
            YaXunSubmitDataObj.WriteBuffer(destBuffer);
            //GPRS信息帧数据
            GPRSFrame gprsFrame = new GPRSFrame();
            gprsFrame.Data = destBuffer;
            gprsFrame.CmdType = GPRSCmdType.GPRSTransferData;
            destBuffer = new byte[gprsFrame.GetLength()];
            gprsFrame.WriteBuffer(destBuffer);

            return YaXunDataSpliter.BufferToESC(destBuffer);
        }
示例#4
0
        /// <summary>
        /// 组合设置移动台初始化(粗略写,暂时测试用)
        /// </summary>
        /// <returns></returns>
        public byte[] GetAllocateInitPara(string Telephone)
        {
            byte[] YxData;
            YaXunSubmitData YaXunSubmitDataObj;
            //
            YaXunSubmitDataObj = new YaXunSubmitData();
            YaXunSubmitDataObj.areaNum = 0x7f38;
            YaXunSubmitDataObj.businessType = BusinessType.UserManage;
            YaXunSubmitDataObj.dataType = DataType.SetMobileInitPara;
            YaXunSubmitDataObj.destPhone = Telephone;
            YaXunSubmitDataObj.sourcePhone = Telephone;
            //
            YxData = new byte[11]{0x31,0x31 ,0x31 ,0x31 ,0x31 ,0x31 ,//用户识别码(暂时随便给)
                                  0x02 ,//参数个数
                                  0x01 ,0x01 ,//TCP方式在线
                                  0x02 ,0x01 };//???};

            YaXunSubmitDataObj.data = YxData;
            byte[] destBuffer = new byte[YaXunSubmitDataObj.GetLength()];
            YaXunSubmitDataObj.WriteBuffer(destBuffer);
            //GPRS信息帧数据
            GPRSFrame gprsFrame = new GPRSFrame();
            gprsFrame.Data = destBuffer;
            gprsFrame.CmdType = GPRSCmdType.GPRSTransferData;
            destBuffer = new byte[gprsFrame.GetLength()];
            gprsFrame.WriteBuffer(destBuffer);

            return YaXunDataSpliter.BufferToESC(destBuffer);
        }
示例#5
0
        /// <summary> 
        /// 分析GPS数据包
        /// </summary>
        /// <param name="buffer">收到的原始数据</param>
        /// <param name="responseList">应答数据</param>
        /// <param name="fullGpsCode">解析后加前缀的GPSCode</param>
        /// <param name="sessionID">会话ID:IP地址+端口号</param>
        /// <returns></returns>
        public GPSDataEntity Parse(byte[] buffer, out List<byte[]> responseList, out string fullGpsCode, string sessionID)
        {
            //传进去赋值,必须在外面创建对象
            GPSDataEntity dataEntity = new GPSDataEntity();

            responseList = new List<byte[]>();
            
            fullGpsCode = GetGPSCode(sessionID);

            //string data = Encoding.ASCII.GetString(buffer);

            //GPRS信息帧数据
            GPRSFrame gprsFrame = new GPRSFrame();
            gprsFrame.ReadBuffer(buffer);

            if (!gprsFrame.IsValidData)
            {
                return null;
            }

            //发送数据缓冲区
            byte[] dataBuffer = null;
            //gprs数据帧
            byte[]destBuffer = null;

            //转义之后的数据帧
            byte[] sendBuffer = null;

            switch (gprsFrame.CmdType)
            {
                //移动台登录请求
                case GPRSCmdType.MobileLoginReq:

                    //读取数据
                    MobileLoginReq mobileLoginReq = new MobileLoginReq();
                    mobileLoginReq.ReadBuffer(gprsFrame.Data);

                    fullGpsCode = CodePrefix + mobileLoginReq.Telephone;

                    //将gpsCode加入列表
                    AddCodeSessionTb(fullGpsCode, sessionID);
                    
                    //将连接加入关系表
                    if (!string.IsNullOrEmpty(fullGpsCode))
                    {
                        OnAddConnectionEvent(fullGpsCode, sessionID);
                    }
                    //如果为有效数据则发送应答消息
                    if (mobileLoginReq.IsValidData)
                    {
                        //发送应答消息
                        MobileLoginAck mobileLoginAck = new MobileLoginAck();
                        mobileLoginAck.Data = 0x01;
                        dataBuffer = new byte[mobileLoginAck.GetLength()];                        
                        mobileLoginAck.WriteBuffer(dataBuffer);

                        gprsFrame.Data = dataBuffer;
                        gprsFrame.CmdType = GPRSCmdType.MobileLoginAck;
                        destBuffer = new byte[gprsFrame.GetLength()];                         
                        gprsFrame.WriteBuffer(destBuffer);

                        sendBuffer = YaXunDataSpliter.BufferToESC(destBuffer);

                        responseList.Add(sendBuffer);

                        //移动台初始化


                        //设置短信中心号码
                        responseList.Add(SetShortMsgCenterNum(mobileLoginReq.Telephone));

                        //加入链路探测关系
                        AddLinkSesskTb(fullGpsCode, DateTime.Now);

                        //再发送个链路探测
                        responseList.Add(GPRSSeekLink(0x14));

                        //设置监控请求 
                        responseList.Add(MonitorReq(mobileLoginReq.Telephone));

                        ////设置移动台初始化参数
                        //responseList.Add(SetMobileInitPara(mobileLoginReq.Telephone,10));

                        ////激活gprs连接
                        //responseList.Add(ActiveGPRSLink(mobileLoginReq.Telephone, 0x01));
                    }
                    break;

                //移动台上传数据
                case GPRSCmdType.MobileTransferData:

                    //读取数据
                    YaXunDeliverData DeliverData = new YaXunDeliverData();
                    
                    DeliverData.ReadBuffer(gprsFrame.Data);

                    //处理接收到的数据
                    DealWithDeliver(DeliverData,ref dataEntity);

                    //在每次收到数据时判断是否需要下发链路探测数据
                    if (NeedLinkSeek(fullGpsCode))
                    {
                        //10分钟发一次链接探测,但是发送的时间值为20分钟
                        responseList.Add(GPRSSeekLink(0x14));

                        //added by lixun 更新链接探测时间
                        AddLinkSesskTb(fullGpsCode, DateTime.Now);
                    }

                    break;

                //GPRS前置机探录TCP链路应答
                case GPRSCmdType.GPRSSeekLinkAck:

                    //需要应答
                    //TCPSeekLinkAck tcpSeekLinkAck = new TCPSeekLinkAck();
                    
                    //dataBuffer = new byte[tcpSeekLinkAck.GetLength()];
                    //tcpSeekLinkAck.Result = 0x01;
                    //tcpSeekLinkAck.WriteBuffer(dataBuffer);
                    //gprsFrame.Data = dataBuffer;
                    //destBuffer = new byte[gprsFrame.GetLength()];
                    //gprsFrame.WriteBuffer(destBuffer);
                    //responseList.Add(destBuffer);
                    
                    if (buffer[0] == 0x01)
                    { 
                       //成功收到链路探测数据
  
                    }


                    break;

            }
            return dataEntity;
        }
示例#6
0
        /// <summary>
        /// 构造下发数据体
        /// </summary>
        /// <param name="dataBuffer">用户数据</param>
        /// <param name="terminalNum">终端号</param>
        /// <param name="businessType">业务类型</param>
        /// <param name="dataType">数据类型</param>
        /// <returns></returns>
        public byte[] BuildSubmitData(byte[] dataBuffer, string terminalNum, BusinessType businessType, DataType dataType)
        {
            //下发监控请求
            YaXunSubmitData submit = new YaXunSubmitData();
            submit.areaNum = 0x7f38;
            //用户管理
            submit.businessType = businessType;
            submit.dataType = dataType;
            submit.destPhone = terminalNum;
            submit.sourcePhone = terminalNum;
            submit.data = dataBuffer;
            byte[] destBuffer = new byte[submit.GetLength()];
            submit.WriteBuffer(destBuffer);

            //GPRS信息帧数据
            GPRSFrame gprsFrame = new GPRSFrame();
            gprsFrame.Data = destBuffer;
            gprsFrame.CmdType = GPRSCmdType.GPRSTransferData;
            destBuffer = new byte[gprsFrame.GetLength()];
            gprsFrame.WriteBuffer(destBuffer);

            //转义之后发出
            return YaXunDataSpliter.BufferToESC(destBuffer);
        }