Esempio n. 1
0
        public void Send()
        {
            try
            {
                TakePictureControlMultiCamera takePicture = new TakePictureControlMultiCamera();
                //如果是上一张是第一张照片
                if (task.IsFirstPhoto)
                {
                    task.IsFirstPhoto = false;
                    task.CurrentCameraIndex = 0;
                }
                else
                {
                    if (task.CurrentCameraIndex < task.CameraIds.Length-1)
                    {
                        task.CurrentCameraIndex++;
                    }
                    else
                    {
                        task.CurrentCameraIndex = 0;
                    }
                }
                takePicture.CameraIds = task.CameraIds[task.CurrentCameraIndex].ToString();
                takePicture.SerialNumber = Guid.NewGuid().ToString();
                takePicture.GPSCode = task.GPSCode;
                takePicture.Data.ShootType = SimpleCmdType.TakePictureForDoorShot;
                takePicture.Data.CameraIdsLen = (byte)Encoding.Default.GetBytes(takePicture.CameraIds).Length;
                takePicture.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(takePicture.SerialNumber).Length;
                takePicture.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(takePicture.GPSCode).Length;

                Util.Common.LogFatal(string.Format("发送开门拍照指令,GPSCode:{0};CameraID:{1}",takePicture.GPSCode, takePicture.CameraIds));

                byte[] dataBuffer = new byte[takePicture.GetLength()];
                takePicture.WriteBuffer(0, dataBuffer);
                CmdData cmdData = new CmdData();
                cmdData.Data.Cmd = ControlCmdType.SendTakePictureMultiCamera;
                cmdData.DataBuffer = dataBuffer;
                cmdData.Data.DataLen = (ushort)dataBuffer.Length;
                byte[] destBuffer = new byte[cmdData.GetLenth()];
                cmdData.WriteBuffer(0, destBuffer);

                System.Net.IPEndPoint remoteGateway = Util.Common.GetGPSGatewayRouter(task.GPSCode);
                if (null == remoteGateway)
                {
                    Logger.Info(string.Format("获取不到{0}的IP端口.", task.GPSCode));
                    return;
                }
                gwClient.Connect(remoteGateway);
                gwClient.Send(destBuffer, destBuffer.Length);
                Util.Common.LogFatal(string.Format("SendPhotographCmd gpscode:{0},vehicleCode:{1},CameraID:{2}", task.GPSCode, task.VehicleCode, task.CameraIds[task.CurrentCameraIndex]));
            }
            catch (System.Exception ex)
            {
                PES.Beehive.Logging.Logger.Fatal(ex);
                PES.Beehive.Logging.Logger.Error(ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 监听喊话
        /// </summary>
        private byte[] ListenCall(int iNdex)
        {

            CmdData cmdData = new CmdData();
            cmdData.Data.Cmd = ControlCmdType.ListenCall;

            ListenCallControl data = new ListenCallControl();
            if(iNdex==6) 
                data.Data.ListenCallType = 1;
            else
                data.Data.ListenCallType = 2;
            data.Phone = txtParam1.Text;
            data.Data.PhoneLen = (byte)Encoding.Default.GetBytes(data.Phone).Length;
            data.GPSCode = txtGpsCode.Text.Trim();
            data.SerialNumber = Guid.NewGuid().ToString();
            data.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(data.SerialNumber).Length;
            data.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(data.GPSCode).Length;

            byte[] buffer = new byte[data.GetLength()];
            data.WriteBuffer(0, buffer);
            cmdData.DataBuffer = buffer;
            cmdData.Data.DataLen = (ushort)data.GetLength();

            byte[] sendBuffer = new byte[cmdData.GetLenth()];
            cmdData.WriteBuffer(0, sendBuffer);

            return sendBuffer;
        }
Esempio n. 3
0
        private byte[] UpdateMileage()
        {

            CmdData cmdData = new CmdData();
            cmdData.Data.Cmd = ControlCmdType.updatemileage;
            UpdateMileage data = new UpdateMileage();
            data.Data.GpsType = GPSType.BoShiJie;
            data.Data.Mileage = int.Parse(txtParam1.Text);
            data.GPSCode = txtGpsCode.Text.Trim();
            data.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(data.GPSCode).Length;
            data.SerialNumber = Guid.NewGuid().ToString();
            data.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(data.SerialNumber).Length;

            byte[] buffer = new byte[data.GetLength()];
            data.WriteBuffer(0, buffer);
            cmdData.DataBuffer = buffer;
            cmdData.Data.DataLen = (ushort)buffer.Length;

            byte[] sendBuffer = new byte[cmdData.GetLenth()];
            cmdData.WriteBuffer(0, sendBuffer);

            return sendBuffer;

            
        }
Esempio n. 4
0
        private byte[] SettingGPSUploadInterval(int index)
        {

            CmdData cmdData = new CmdData();
            cmdData.Data.Cmd = ControlCmdType.SendGPSPosUploadInterval; 
            GPSPosUploadInterval data = new GPSPosUploadInterval();
            if (index == 3)
            {
                data.Data.IntervalType = GPSIntervalType.ACCOn;  
            }
            else if (index == 4)
            {
                data.Data.IntervalType = GPSIntervalType.ACCOff; 
            }
            data.GPSCode = txtGpsCode.Text.Trim();
            data.Data.GpsType = GPSType.BoShiJie; 
            data.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(data.GPSCode).Length;
            data.SerialNumber = Guid.NewGuid().ToString();
            data.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(data.SerialNumber).Length;

            byte[] buffer = new byte[data.GetLength()];
            data.WriteBuffer(0, buffer);

            cmdData.DataBuffer = buffer;
            cmdData.Data.DataLen = (ushort)data.GetLength();

            byte[] sendBuffer = new byte[cmdData.GetLenth()];
            cmdData.WriteBuffer(0, sendBuffer);

            return sendBuffer;

        }
Esempio n. 5
0
        private byte[] ControlOilBreak(int index)
        {

            CmdData cmdData = new CmdData();
            ControlOilCircuit data = new ControlOilCircuit();
            data.BreakOilCircuitTime = DateTime.Now;

            if (index == 1)
            {
                cmdData.Data.Cmd = ControlCmdType.BreakOilCircuitByForce;
                data.Data.operateMode = ControlOilMode.Force;
                data.Data.operateType = ContorlOilType.CutOil;
            }
            else if (index == 2)
            {
                cmdData.Data.Cmd = ControlCmdType.SupplyOilCircuit;
                data.Data.operateMode = ControlOilMode.Smart;
                data.Data.operateType = ContorlOilType.RestoreOil;
            }
            data.GPSCode = txtGpsCode.Text.Trim();
            if (data.GPSCode.StartsWith("0019"))
                data.Data.GpsType = GPSType.YaXun;
            else if (data.GPSCode.StartsWith("0013"))
                data.Data.GpsType = GPSType.BoShiJie;
            else if (data.GPSCode.StartsWith("0023"))
                data.Data.GpsType = GPSType.KangKaiSi;
            else if (data.GPSCode.StartsWith("0033"))
                data.Data.GpsType = GPSType.LianHuaYingKe;
            data.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(data.GPSCode).Length;
            data.SerialNumber = Guid.NewGuid().ToString();
            data.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(data.SerialNumber).Length;

            byte[] buffer = new byte[data.GetLength()];
            data.WriteBuffer(0, buffer);

            ControlOilCircuit dest = new ControlOilCircuit();
            dest.ReadBuffer(0, buffer);

            cmdData.DataBuffer = buffer;
            cmdData.Data.DataLen = (ushort)data.GetLength();

            byte[] sendBuffer = new byte[cmdData.GetLenth()];
            cmdData.WriteBuffer(0, sendBuffer);

            return sendBuffer;

        }
Esempio n. 6
0
        /// <summary>
        /// 多摄像头拍照
        /// </summary>
        /// <param name="eventIndex"></param>
        /// <returns></returns>
        private byte[] TakePicture(int eventIndex)
        {
            TakePictureControlMultiCamera takePicture = new TakePictureControlMultiCamera();
            takePicture.CameraIds = this.txtParam2.Text.Trim();
            takePicture.Data.GpsType = GPSType.BoShiJie;
            takePicture.SerialNumber = Guid.NewGuid().ToString();
            takePicture.GPSCode = txtGpsCode.Text.Trim();
            takePicture.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(takePicture.GPSCode).Length;
            takePicture.Data.CameraIdsLen = (byte)Encoding.Default.GetBytes(takePicture.CameraIds).Length;
            takePicture.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(takePicture.SerialNumber).Length;
            takePicture.Data.IsGpsAckMsg = true;

            switch (eventIndex)
            {
                //实时抓拍
                case 5:
                    takePicture.Data.ShootType = SimpleCmdType.RealTimeShoot;

                    break;

                //正常连拍
                case 6:
                    takePicture.Data.ShootType = SimpleCmdType.NormalSeriateShoot;
                    takePicture.Data.TurnsCount = Convert.ToUInt16(this.txtParam1.Text.Trim());
                    break;
            }

            byte[] dataBuffer = new byte[takePicture.GetLength()];
            takePicture.WriteBuffer(0, dataBuffer);


            CmdData cmdData = new CmdData();
            cmdData.Data.Cmd = ControlCmdType.SendTakePictureMultiCamera;
            cmdData.DataBuffer = dataBuffer;
            cmdData.Data.DataLen = (ushort)dataBuffer.Length;

            byte[] destBuffer = new byte[cmdData.GetLenth()];
            cmdData.WriteBuffer(0, destBuffer);

            return destBuffer;


        }
Esempio n. 7
0
        private byte[] SetFriendNumber()
        {
            KKSSimpleControl control = new KKSSimpleControl();
            control.GPSCode = txtGpsCode.Text.Trim();
            control.SendContent = txtParam1.Text.Trim();
            control.Data.GpsType = GPSType.KangKaiSi;
            control.SerialNumber = Guid.NewGuid().ToString();
            control.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(control.GPSCode).Length;
            control.Data.ContentLen = (byte)Encoding.Default.GetBytes(control.SendContent).Length;
            control.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(control.SerialNumber).Length;
            control.Data.IsGpsAckMsg = true;
            control.Data.SimpleControlType = KKSSimpleControlType.SetFriendNumber;

            byte[] dataBuffer = new byte[control.GetLength()];
            control.WriteBuffer(0, dataBuffer);


            CmdData cmdData = new CmdData();
            cmdData.Data.Cmd = ControlCmdType.SetFriendNumber;
            cmdData.DataBuffer = dataBuffer;
            cmdData.Data.DataLen = (ushort)dataBuffer.Length;

            byte[] destBuffer = new byte[cmdData.GetLenth()];
            cmdData.WriteBuffer(0, destBuffer);

            return destBuffer;
        }
Esempio n. 8
0
        private byte[] TakePicture_bak(int eventIndex)
        {
            TakePictureControl takePicture = new TakePictureControl();
            takePicture.Data.CameraId = 1;
            takePicture.Data.GpsType = GPSType.YouWei;
            takePicture.Data.PictureCount = 1;
            takePicture.SerialNumber = Guid.NewGuid().ToString();
            takePicture.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(takePicture.SerialNumber).Length;
            takePicture.GPSCode = txtGpsCode.Text.Trim();
            takePicture.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(takePicture.GPSCode).Length;

            switch (eventIndex)
            {
                //实时抓拍
                case 5:

                    takePicture.Data.ShootType = SimpleCmdType.RealTimeShoot;
                    takePicture.Data.PictureCount = 1;
                    takePicture.Data.PictureType = TakePictureType.TakePictureForRealTime;

                    break;

                //正常连拍
                case 15:

                    takePicture.Data.ShootType = SimpleCmdType.NormalSeriateShoot;
                    takePicture.Data.PictureCount = 3;
                    takePicture.Data.TimeSpanValue = 60;

                    break;
            }

            byte[] dataBuffer = new byte[takePicture.GetLength()];
            takePicture.WriteBuffer(0, dataBuffer);


            CmdData cmdData = new CmdData();
            cmdData.Data.Cmd = ControlCmdType.SendTakePicture;
            cmdData.DataBuffer = dataBuffer;
            cmdData.Data.DataLen = (ushort)dataBuffer.Length;

            byte[] destBuffer = new byte[cmdData.GetLenth()];
            cmdData.WriteBuffer(0, destBuffer);

            return destBuffer;


        }
Esempio n. 9
0
        public bool SetFriendNumber(string gpsCode, string SMSStr, int type)
        {
            SettingEMOpenGPSInfo(gpsCode, type);
            KKSSimpleControl control = new KKSSimpleControl();
            control.GPSCode = gpsCode;
            control.SendContent = SMSStr;
            control.Data.GpsType = GPSType.KangKaiSi;
            control.SerialNumber = Guid.NewGuid().ToString();
            control.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(control.GPSCode).Length;
            control.Data.ContentLen = (byte)Encoding.Default.GetBytes(control.SendContent).Length;
            control.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(control.SerialNumber).Length;
            control.Data.IsGpsAckMsg = true;
            control.Data.SimpleControlType = KKSSimpleControlType.SetFriendNumber;

            byte[] dataBuffer = new byte[control.GetLength()];
            control.WriteBuffer(0, dataBuffer);


            CmdData cmdData = new CmdData();
            cmdData.Data.Cmd = ControlCmdType.SetFriendNumber;
            cmdData.DataBuffer = dataBuffer;
            cmdData.Data.DataLen = (ushort)dataBuffer.Length;

            byte[] destBuffer = new byte[cmdData.GetLenth()];
            cmdData.WriteBuffer(0, destBuffer);

            IPEndPoint endPoint = GetEndPoint(gpsCode);
            return SendData(destBuffer, endPoint);
            
        }
Esempio n. 10
0
        /// <summary>
        /// 发送供油供电
        /// </summary>
        public bool SupplyOilCircuit(GPSGatewayServer.CommadData.ControlOilCircuit control)
        {
            try
            {
                Logger.Info("CommandService.ControlOil:进入发送供油供电");
                control.Data.operateMode = ControlOilMode.Smart;
                control.Data.operateType = ContorlOilType.RestoreOil;
                control.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(control.GPSCode).Length;
                control.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(control.SerialNumber).Length;

                CmdData cmdData = new CmdData();
                cmdData.Data.Cmd = ControlCmdType.SupplyOilCircuit;

                byte[] buffer = new byte[control.GetLength()];
                control.WriteBuffer(0, buffer);

                cmdData.DataBuffer = buffer;
                cmdData.Data.DataLen = (ushort)buffer.Length;

                byte[] sendBuffer = new byte[cmdData.GetLenth()];
                cmdData.WriteBuffer(0, sendBuffer);

                IPEndPoint endPoint = GetEndPoint(control.GPSCode);
                return SendData(sendBuffer, endPoint);
            }
            catch (Exception ex)
            {
                Logger.Error("CommandService.ControlOil:" + ex);
                return false;
            }
        }
Esempio n. 11
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 = null;
            responseList = new List<byte[]>();
            string strPicFile = "";
            //GPRS信息帧数据
            GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrame = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame();
            gprsFrame.ReadBuffer(buffer);
            if (!gprsFrame.IsValidData)
            {
                fullGpsCode = "";
                return null;
            }
            fullGpsCode = gprsFrame.GPSCode;
            //将连接加入关系表
            if (!string.IsNullOrEmpty(fullGpsCode))
            {
                OnAddConnectionEvent(fullGpsCode, sessionID);
            }

            if (gprsFrame.IsMutiPackage)
            {

                byte[] bSerialNum = gprsFrame.SerialNum;
                gprsFrame.InitData();

                if (gprsFrame.MsgID == BuBiaoMsgIdType.MediaDataReport)
                {
                    //上传一帧,保存一帧
                    if (gprsFrame.PackageIndex == 1)
                    {
                        //第一帧已包括图片信息定位信息
                        MediaDataReport aMediaDataReport = new MediaDataReport();
                        aMediaDataReport.dataBuffer = gprsFrame.Data;
                        aMediaDataReport.ReadBuffer(gprsFrame.DataLength);

                        dataEntity = new GPSDataEntity();
                        GetGPSDataEntity(fullGpsCode, aMediaDataReport.PhotoLocation, ref dataEntity);

                        WritePicFile(fullGpsCode, aMediaDataReport.ChannelID.ToString(), aMediaDataReport.Data, aMediaDataReport.MediaFomat, aMediaDataReport.EventCode, FileMode.OpenOrCreate, ref dataEntity, ref strPicFile);

                        if (dicCurPicCameraId.ContainsKey(fullGpsCode))
                        {
                            dicCurPicCameraId.Remove(fullGpsCode);
                        }
                        dicCurPicCameraId.Add(fullGpsCode, strPicFile);
                    }
                    else
                    {
                        if (dicCurPicCameraId.ContainsKey(fullGpsCode))
                        {
                            strPicFile = dicCurPicCameraId[fullGpsCode];
                            WritePicFile(strPicFile, gprsFrame.Data, FileMode.Append);
                            dataEntity = null;
                        }
                    }
                }


                Logger.Trace("[部标:分包消息]" + fullGpsCode + "  " + string.Format("消息类型:{0}总包数:{1}, 包序号{2}", gprsFrame.MsgID.ToString(), gprsFrame.PackageCount, gprsFrame.PackageIndex));
                if (_LongMsgProcessor.AddFrame(ref gprsFrame) == false)
                {
                    //最后一包不发送通用应答
                    TMLOrPFCommonRsp PCMPackage = GetTMLOrPFCommonRsp(bSerialNum, BuBiaoMsgIdType.MediaDataReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameMPackage = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCMPackage.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCMPackage.dataBuffer);
                    responseList.Add(gprsFrameMPackage.WriteBuffer());

                    return dataEntity;
                }

            }


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

            switch (gprsFrame.MsgID)
            {
                case BuBiaoMsgIdType.BSJBlindZoneUpload:
                    //博实结盲区补传,跟厂家确认需要给应答,否则会导致终端重发
                    TMLOrPFCommonRsp PCBSJRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.BSJBlindZoneUpload, 0);
                    AddSerialNum(fullGpsCode); ;
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameBSJ = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCBSJRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCBSJRsp.dataBuffer);

                    responseList.Add(gprsFrameBSJ.WriteBuffer());

                    break;

                //终端通用应答
                case BuBiaoMsgIdType.TMLCommonRsp:
                    TMLOrPFCommonRsp TCRsp = new TMLOrPFCommonRsp();
                    TCRsp.dataBuffer = gprsFrame.Data;
                    TCRsp.ReadBuffer();

                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveBubiaoCommonRsp(TCRsp,fullGpsCode);
                    //base.OnDebugDataEvent(base.TransfersType.ToString(), fullGpsCode, "[通用应答] 消息类型:" + TCRsp.RspID.ToString() + " 消息流水号:" + TCRsp.SerialNum.ToString() + " 结果:" + TCRsp.Result.ToString());                    
                    Logger.Trace("[部标:通用应答]" + fullGpsCode + "  " + string.Format("消息类型:{0},消息流水号:{1}, 结果{2}", TCRsp.RspID.ToString(), TCRsp.SerialNum.ToString(), TCRsp.Result.ToString()));
                    break;
                //提问应答消息
                case BuBiaoMsgIdType.TMLAnwerQuestion:
                    TMLAnswerQuestion aTMLAnswerQuestion = new TMLAnswerQuestion();
                    aTMLAnswerQuestion.ReadBuffer(gprsFrame.Data);
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().UpdateBubiaoQuestion(aTMLAnswerQuestion, fullGpsCode);

                    TMLOrPFCommonRsp PCAnswerRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLAnwerQuestion, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameAnswer = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCAnswerRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCAnswerRsp.dataBuffer);
                    responseList.Add(gprsFrameAnswer.WriteBuffer());

                    Logger.Trace("[部标:提问应答]" + fullGpsCode + "  " + gprsFrame.Data[0]);
                    break;
                //事件上报
                case BuBiaoMsgIdType.TMLEventReport:
                    //base.OnDebugDataEvent(base.TransfersType.ToString(), fullGpsCode, "[事件报告]:" + gprsFrame.Data[0]);
                    int iEventId = (int)gprsFrame.Data[0];
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveEventReport(iEventId, fullGpsCode);

                    TMLOrPFCommonRsp PCEventRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLEventReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameEvent = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCEventRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCEventRsp.dataBuffer);
                    responseList.Add(gprsFrameEvent.WriteBuffer());

                    Logger.Trace("[部标:事件报告]" + fullGpsCode + "  " + gprsFrame.Data[0]);
                    break;
                //车辆控制应答
                case BuBiaoMsgIdType.TMLVehicleControlRsp:
                    byte[] RspSerialNum = new byte[2];
                    Array.Copy(gprsFrame.Data, 0, RspSerialNum, 0, 2);
                    UInt16 iSerialNum = BitConverter.ToUInt16(BuBiaoData.LocalByteToNetByteOrder(RspSerialNum), 0);

                    byte[] locData = new byte[gprsFrame.Data.Length - 2];
                    Array.Copy(gprsFrame.Data, 2, locData, 0, locData.Length);
                    LocationReport VC_LR = new LocationReport();
                    VC_LR.ReadBuffer(locData, locData.Length);

                    dataEntity = new GPSDataEntity();
                    GetGPSDataEntity(fullGpsCode, VC_LR, ref dataEntity);
                    TMLOrPFCommonRsp TCVehicle = new TMLOrPFCommonRsp();
                    TCVehicle.RspID = BuBiaoMsgIdType.TMLVehicleControl;
                    TCVehicle.SerialNum = iSerialNum;
                    TCVehicle.Result = 0;
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveBubiaoCommonRsp(TCVehicle, fullGpsCode);

                    TMLOrPFCommonRsp PCControlRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLVehicleControlRsp, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameControl = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCControlRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCControlRsp.dataBuffer);
                    responseList.Add(gprsFrameControl.WriteBuffer());

                    //base.OnDebugDataEvent(base.TransfersType.ToString(), fullGpsCode, "[车辆控制应答]:" + iSerialNum.ToString());
                    Logger.Trace("[部标:车辆控制应答]" + fullGpsCode + "  " + iSerialNum.ToString());
                    break;
                //信息点播或取消
                case BuBiaoMsgIdType.TMLInfoPlayOrCancel:
                    TMLMediaPlayOrCancel TCPc = new TMLMediaPlayOrCancel();
                    TCPc.dataBuffer = gprsFrame.Data;
                    TCPc.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().UpdateInfoPlay(TCPc, fullGpsCode);                                        

                    TMLOrPFCommonRsp PCInfoPlayRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLInfoPlayOrCancel, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameInfoPlay = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCInfoPlayRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCInfoPlayRsp.dataBuffer);
                    responseList.Add(gprsFrameInfoPlay.WriteBuffer());

                    //Add2InfoService(TCPc, fullGpsCode);
                    Logger.Trace("[部标:信息点播或取消]" + fullGpsCode + "  " + string.Format("消息类型:{0},flag:{1}", TCPc.InfoType.ToString(), TCPc.InfoFlag.ToString()));
                    break;
                //心跳
                case BuBiaoMsgIdType.TMLKeepAlive:
                    TMLOrPFCommonRsp PCHeartRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLKeepAlive, 0);
                    AddSerialNum(fullGpsCode); ;
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameHeart = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCHeartRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCHeartRsp.dataBuffer);
                    responseList.Add(gprsFrameHeart.WriteBuffer());
                    break;
                //终端注册
                case BuBiaoMsgIdType.TMLRegisterReq:
                    //解析终端注册消息
                    //if (!dicDeviceHasRegiste.ContainsKey(fullGpsCode))
                    //{
                    //    dicDeviceHasRegiste.Add(fullGpsCode, 0);
                    //}

                    //byte hasRegiste = dicDeviceHasRegiste[fullGpsCode];

                    TMLRegisterFrameReq RstReq = new TMLRegisterFrameReq();
                    RstReq.ReadBuffer(gprsFrame.Data, gprsFrame.DataLength);

                    Logger.Trace("终端注册(Device):" + RstReq.LicenceNum + " " + RstReq.DeviceId);

                    TMLRegisterFrameRsp RstRsp = new TMLRegisterFrameRsp();
                    RstRsp.SerialNumByte = gprsFrame.SerialNum;
                    //0--成功 1--车辆已注册 2--数据库无此车辆 3--终端已注册 4--数据库无此终端 
                    RstRsp.Result = 0;
                    RstRsp.Akey = gprsFrame.GPSCode;

                    //if (CheckDeviceIsVaild(fullGpsCode, RstReq.LicenceNum, RstReq.DeviceId))
                    //{
                    //    if (hasRegiste == 1)
                    //    {
                    //        //已经注册                        
                    //        RstRsp.Result = 3;
                    //    }
                    //    else
                    //    {
                    //        RstRsp.Result = 0;
                    //        RstRsp.Akey = gprsFrame.GPSCode;
                    //        dicDeviceHasRegiste[fullGpsCode] = 1;

                    //        lock (dicNeedSaveDeviceRegiste)
                    //        {
                    //            if (dicNeedSaveDeviceRegiste.ContainsKey(fullGpsCode))
                    //                dicNeedSaveDeviceRegiste.Remove(fullGpsCode);
                    //            dicNeedSaveDeviceRegiste.Add(fullGpsCode, RstReq);
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    //        RstRsp.Result = 4;
                    //}

                    RstRsp.WriteBuffer();
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameSendRstRsp = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.TMLRegisterRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(RstRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, RstRsp.dataBuffer);
                    responseList.Add(gprsFrameSendRstRsp.WriteBuffer());

                    Logger.Trace("[部标:终端注册]" + fullGpsCode + " " + RstRsp.Result);
                    break;
                //终端注销
                case BuBiaoMsgIdType.TMLCancelReq:
                    TMLOrPFCommonRsp PCCancelRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLCancelReq, 0);
                    AddSerialNum(fullGpsCode); ;
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameCancel = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCCancelRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCCancelRsp.dataBuffer);
                    responseList.Add(gprsFrameCancel.WriteBuffer());

                    if (dicDeviceHasRegiste.ContainsKey(fullGpsCode))
                    {
                        dicDeviceHasRegiste.Remove(fullGpsCode);
                    }
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().RemoveDeviceRegInfo(fullGpsCode);
                    Logger.Trace("[部标:终端注销]" + fullGpsCode);
                    break;
                //数据透传
                case BuBiaoMsgIdType.DataTransparentUp:
                    TransparentTranData aTransparentTranData = new TransparentTranData();
                    aTransparentTranData.dataBuffer = gprsFrame.Data;
                    aTransparentTranData.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveTransparentTranInfo(aTransparentTranData,fullGpsCode);

                    TMLOrPFCommonRsp PCTTRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.DataTransparentUp, 0);
                    AddSerialNum(fullGpsCode); ;
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameTT = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCTTRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCTTRsp.dataBuffer);
                    responseList.Add(gprsFrameTT.WriteBuffer());
                    Logger.Trace("[部标:数据透传]" + aTransparentTranData.DataType);

                    break;
                //鉴权
                case BuBiaoMsgIdType.TMLAuthenticationReq:

                    TMLAuthenticationReq aTMLAuthenticationReq = new TMLAuthenticationReq();
                    aTMLAuthenticationReq.ReadBuffer(gprsFrame.Data);
                    //取得鉴权码,去判断是否已经合法车辆
                    byte bResult = 0;

                    //改为从内存鉴权
                    //正式环境暂不认证
                    //if (dicPlatformAllVehilceInfo.ContainsKey(aTMLAuthenticationReq.Akey))
                    //    bResult = 0;
                    //else
                    //    bResult = 1;
                    TMLOrPFCommonRsp PCRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLAuthenticationReq, bResult);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameSend = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCRsp.dataBuffer);
                    responseList.Add(gprsFrameSend.WriteBuffer());

                    //设置参数默认值,统一通过终端参数设置

                    SetTMLPara setPara = new SetTMLPara();
                    List<TMLParaItem> paraList = new List<TMLParaItem>();
                    TMLParaItem item;
                    int BufferLen = 0;
                    //终端心跳发送间隔,单位为秒(s)
                    //item = new TMLParaItem(ParaIDType.TMLKeepAlive, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(0x0000003c)));
                    //BufferLen += item.GetItemLen();
                    //paraList.Add(item);

                    //位置汇报策略
                    item = new TMLParaItem(ParaIDType.LocationReportStrategy, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(0)));
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    //位置汇报方案
                    item = new TMLParaItem(ParaIDType.LocationReportProgram, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(0)));
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    //缺省时间汇报间隔
                    item = new TMLParaItem(ParaIDType.DefaultReportInterval, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(15)));
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    item = new TMLParaItem(ParaIDType.SleepReportInterval, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(60)));
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    item = new TMLParaItem(ParaIDType.DriverNoLoginReportInterval, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(60))); ;
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    setPara.AddTMLParaItem(paraList, BufferLen);
                    AddSerialNum(fullGpsCode);
                    gprsFrameSend = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.SetTMLPara, false, EncryptType.NoEncrypt, Convert.ToUInt16(setPara.dataBuffer.Length)
                        , gprsFrame.TMLPhoneNumByte, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, setPara.dataBuffer);

                    byte[] sendbuffer = gprsFrameSend.WriteBuffer();
                    responseList.Add(sendbuffer);

                    Logger.Trace("[部标:终端签权]" + fullGpsCode + "  " + bResult);
                    break;
                //查询终端参数应答
                case BuBiaoMsgIdType.QueryTMLParaRsp:

                    CmdData cmdData = new CmdData();
                    cmdData.Data.Cmd = ControlCmdType.QueryTerminalParamRsp;
                    cmdData.DataBuffer = gprsFrame.Data;
                    cmdData.Data.DataLen = (ushort)gprsFrame.Data.Length;

                    byte[] RspBuffer = new byte[cmdData.GetLenth()];
                    cmdData.WriteBuffer(0, RspBuffer);


                    //生成公共应答
                    //QueryTMLPara tmlparam = new QueryTMLPara();
                    //tmlparam.ReadBuffer(gprsFrame.Data);
                    //TMLOrPFCommonRsp TCQuery = new TMLOrPFCommonRsp();
                    //TCQuery.RspID = BuBiaoMsgIdType.QueryTMLParaReq;
                    //TCQuery.SerialNum = tmlparam.RspSerialNumber;
                    //TCQuery.Result = 0;
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveBubiaoCommonRsp(TCQuery, fullGpsCode);

                    TMLOrPFCommonRsp PCQuery = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.QueryTMLParaRsp, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameQuery = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCQuery.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCQuery.dataBuffer);
                    responseList.Add(gprsFrameQuery.WriteBuffer());

                    base.OnPostAckMsgHandlerEvent(fullGpsCode, RspBuffer);
                    //base.OnDebugDataEvent(base.TransfersType.ToString(), fullGpsCode, "查询终端参数应答" + gprsFrame.DataLength);
                    Logger.Trace("[部标:查询终端参数应答]" + gprsFrame.DataLength);

                    break;
                case BuBiaoMsgIdType.LocationReport:

                    LocationReport LR = new LocationReport();
                    LR.ReadBuffer(gprsFrame.Data, gprsFrame.DataLength);

                    dataEntity = new GPSDataEntity();
                    GetGPSDataEntity(fullGpsCode, LR, ref dataEntity);
                    DealWithAlarm(LR, gprsFrame, ref responseList);

                    //TO DO

                    break;
                //驾驶员上报
                case BuBiaoMsgIdType.DriverInfoReport:
                    DriverInfoReport aDriverInfoReport = new DriverInfoReport();
                    aDriverInfoReport.dataBuffer = gprsFrame.Data;
                    aDriverInfoReport.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveDriverReport(aDriverInfoReport, fullGpsCode);

                    TMLOrPFCommonRsp PCVehicleRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.DriverInfoReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameVehilce = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCVehicleRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCVehicleRsp.dataBuffer);
                    responseList.Add(gprsFrameVehilce.WriteBuffer());
                    Logger.Trace("[部标:驾驶员身份上报]" + fullGpsCode + "  " + aDriverInfoReport.DriverName);

                    break;
                //电子运单上报
                case BuBiaoMsgIdType.ConsignOrderReport:
                    ConsignOrderReport aConsignOrderReport = new ConsignOrderReport();
                    aConsignOrderReport.dataBuffer = gprsFrame.Data;
                    aConsignOrderReport.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveETransForm(aConsignOrderReport, fullGpsCode);

                    TMLOrPFCommonRsp PCOrderRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.ConsignOrderReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameOrder = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCOrderRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCOrderRsp.dataBuffer);
                    responseList.Add(gprsFrameOrder.WriteBuffer());

                    Logger.Trace("[部标:电子运单上报]" + fullGpsCode);
                    break;
                //多媒体事件信息上传
                case BuBiaoMsgIdType.MediaEventInfoReport:
                    MediaEventInfoReport aMediaEventInfoReport = new MediaEventInfoReport();
                    aMediaEventInfoReport.ReadBuffer(gprsFrame.Data);

                    TMLOrPFCommonRsp PCMediaReportRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.MediaEventInfoReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameMediaReport = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCMediaReportRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCMediaReportRsp.dataBuffer);
                    responseList.Add(gprsFrameMediaReport.WriteBuffer());

                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveMediaEventInfo(aMediaEventInfoReport, fullGpsCode);
                    Logger.Trace("[部标:多媒体事件信息上传]" + fullGpsCode);
                    break;
                //多媒体数据检索应答
                case BuBiaoMsgIdType.MediaDataSearchRsp:

                    CmdData cmdData1 = new CmdData();
                    cmdData1.Data.Cmd = ControlCmdType.MediaDataSearchRsp;
                    cmdData1.DataBuffer = gprsFrame.Data;
                    cmdData1.Data.DataLen = (ushort)gprsFrame.Data.Length;

                    byte[] RspBuffer1 = new byte[cmdData1.GetLenth()];
                    cmdData1.WriteBuffer(0, RspBuffer1);
                    base.OnPostAckMsgHandlerEvent(fullGpsCode, RspBuffer1);


                    TMLOrPFCommonRsp PCMediaSearchRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.MediaDataSearchRsp, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameMediaSearch = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCMediaSearchRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCMediaSearchRsp.dataBuffer);
                    responseList.Add(gprsFrameMediaSearch.WriteBuffer());

                    MediaDataSearchRsp aMediaDataSearchRsp = new MediaDataSearchRsp();
                    aMediaDataSearchRsp.ReadBuffer(gprsFrame.Data);
                    TMLOrPFCommonRsp TCDataSearch = new TMLOrPFCommonRsp();
                    TCDataSearch.RspID = BuBiaoMsgIdType.MediaDataSearch;
                    TCDataSearch.SerialNum = aMediaDataSearchRsp.SerialNumber;
                    TCDataSearch.Result = 0;
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveBubiaoCommonRsp(TCDataSearch, fullGpsCode);

                    Logger.Trace("[部标:多媒体数据检索应答] " + fullGpsCode);

                    break;
                //多媒体数据上传
                case BuBiaoMsgIdType.MediaDataReport:
                    MediaDataReport aMediaDataReport = new MediaDataReport();
                    aMediaDataReport.dataBuffer = gprsFrame.Data;
                    aMediaDataReport.ReadBuffer(gprsFrame.DataLength);

                    //将图片数据写成图片文件存入指定位置
                    if (dicCurPicCameraId.ContainsKey(fullGpsCode))
                    {
                        strPicFile = dicCurPicCameraId[fullGpsCode];
                        WritePicFile(strPicFile, aMediaDataReport.Data, FileMode.OpenOrCreate);
                    }

                    //应答0x8800
                    AddSerialNum(fullGpsCode);
                    byte[] bMediaDataRsp = GetMediaDataReportRsp(aMediaDataReport, null);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameSend3 = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.MediaDataReportRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(bMediaDataRsp.Length), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, bMediaDataRsp);
                    responseList.Add(gprsFrameSend3.WriteBuffer());

                    //平台下发拍照指令
                    if (aMediaDataReport.EventCode == 0)
                    {
                        if (CheckTaskThread.GetInstance().PicTaskPool.ContainsKey(fullGpsCode))
                        {
                            if (CheckTaskThread.GetInstance().PicTaskPool[fullGpsCode].Count > 0)
                            {
                                TakePicTask task = CheckTaskThread.GetInstance().PicTaskPool[fullGpsCode].Peek();
                                if (task != null)
                                {
                                    task.Status = TakePicTaskStatus.LastPicFinished;
                                    CheckTaskThread.GetInstance().DoShoot(fullGpsCode, false);
                                    Logger.Trace("[拍照]完成,更改任务状态 ChannelID" + aMediaDataReport.ChannelID + "--" + task.CameraList[task.CurrentCameraIndex]);
                                }
                            }
                        }
                    }

                    Logger.Trace("[部标:多媒体上传完成]" + fullGpsCode);
                    break;
                //行驶记录上传
                case BuBiaoMsgIdType.TravelRecordReport:
                    TravelRecordReport aTravelRecReport = new TravelRecordReport();
                    aTravelRecReport.DataBuffer = gprsFrame.Data;
                    aTravelRecReport.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().UpdateTravelRecordReport(aTravelRecReport, fullGpsCode);


                    TMLOrPFCommonRsp PCTravelRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TravelRecordReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameTravel = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCTravelRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCTravelRsp.dataBuffer);
                    responseList.Add(gprsFrameTravel.WriteBuffer());
                    Logger.Trace("[部标:行驶记录数据上报]" + fullGpsCode);
                    break;
                case BuBiaoMsgIdType.QueryPositionRsp:
                    QueryPositionRsp aQueryPositionRsp = new QueryPositionRsp();
                    aQueryPositionRsp.dataBuffer = gprsFrame.Data;
                    aQueryPositionRsp.ReadBuffer(gprsFrame.DataLength);
                    //FetchData.GetInstance().UpdateTMLResponse(fullGpsCode, aQueryPositionRsp.SerialNum, DateTime.Now, 0);

                    dataEntity = new GPSDataEntity();
                    GetGPSDataEntity(fullGpsCode, aQueryPositionRsp.LR, ref dataEntity);

                    TMLOrPFCommonRsp PCPositionRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.QueryPositionRsp, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFramePosition = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCPositionRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCPositionRsp.dataBuffer);
                    responseList.Add(gprsFramePosition.WriteBuffer());


                    Logger.Trace("[部标:点名]" + fullGpsCode);
                    //DealWithAlarm(aQueryPositionRsp.LR, gprsFrame, ref responseList);
                    break;

            }
            return dataEntity;
        }
Esempio n. 12
0
        /// <summary>
        /// 发送网关活动信息
        /// </summary>
        /// <param name="activeInfo">网关活动信息</param>
        /// <param name="remotePoint">客户端信息</param>
        private void SendGatewayActiveInfo(GatewayActiveInfo activeInfo,EndPoint remotePoint)
        {
            try
            {
                CmdData cmd = new CmdData();
                switch (activeInfo.Data.Cmd)
                {
                    //连接数
                    case ActionMark.SelectConnectCount:
                        if (activeInfo.Data.tranType == TransfersType.IsTcp)
                            activeInfo.Data.ActiveCount = TCPConnList.Instance().GetTCPCount();
                        else if (activeInfo.Data.tranType == TransfersType.IsUdp)
                            activeInfo.Data.ActiveCount = UDPConnList.Instance().GetUDPCount();

                        byte[] buffer = new byte[activeInfo.GetLength()];
                        activeInfo.WriteBuffer(0, buffer);

                        cmd.Data.Cmd = ControlCmdType.GetGatewayActiveInfo;
                        cmd.DataBuffer = buffer;
                        cmd.Data.DataLen = (ushort)buffer.Length;

                        byte[] sendBufferConn = new byte[cmd.GetLenth()];
                        cmd.WriteBuffer(0, sendBufferConn);
                        OnSendDataEvent(remotePoint, sendBufferConn);
                        break;

                    //连接状态
                    //case ActionMark.SelectGpsState:
                    //    //是否在线
                    //    if (activeInfo.Data.tranType == TransfersType.IsTcp)
                    //        activeInfo.Data.IsOnline = TCPConnList.Instance().IsOnline(activeInfo.GPSCode) ? '1' : '0';
                    //    else if (activeInfo.Data.tranType == TransfersType.IsUdp)
                    //        activeInfo.Data.IsOnline = UDPConnList.Instance().IsOnline(activeInfo.GPSCode) ? '1' : '0';

                    //    //是否存在于本网关
                    //    string ipport = CacheUtility.GetRemoteGateWayIPPort(activeInfo.GPSCode);
                    //    if (!string.IsNullOrEmpty(ipport))
                    //    {
                    //        string[] serverAdress = ipport.Split(':');
                    //        if (GpsDataParser.IpEndPoint.Address.ToString() == serverAdress[0] && GpsDataParser.IpEndPoint.Port.ToString() == serverAdress[1])
                    //            activeInfo.Data.IsContained = '1';
                    //        else
                    //            activeInfo.Data.IsContained = '0';
                    //    }
                    //    else
                    //    {
                    //        activeInfo.Data.IsContained = '0';
                    //    }

                    //    byte[] buffer2 = new byte[activeInfo.GetLength()];
                    //    activeInfo.WriteBuffer(0, buffer2);

                    //    cmd.Data.Cmd = ControlCmdType.GetGatewayActiveInfo;
                    //    cmd.DataBuffer = buffer2;
                    //    cmd.Data.DataLen = (ushort)buffer2.Length;

                    //    byte[] sendBufferGpsState = new byte[cmd.GetLenth()];
                    //    cmd.WriteBuffer(0, sendBufferGpsState);
                    //    OnSendDataEvent(remotePoint, sendBufferGpsState);
                    //    break;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
            }
        }
Esempio n. 13
0
        /// <summary> 发送应答信息给应用
        /// 发送应答信息给应用
        /// </summary>
        /// <param name="serialNumber">流水号</param>
        /// <param name="isGpsAckMsg">是否是GPS应答消息</param>
        /// <param name="gpscode"></param>
        /// <param name="cmdType">下发的命令类型</param>
        /// <param name="result">GPS终端对命令的执行结果:成功或失败</param>
        //private void SendAnswerToWeb(string serialNumber, bool isGpsAckMsg, string gpscode, ControlCmdType cmdType, bool result, params SimpleCmdType[] simplecmd)
        //{
        //    //获取WEB列表
        //    EndPoint adress = (EndPoint)WebTable[gpscode];

        //    if (adress != null)
        //    {
        //        byte[] answerBytes = SetAnswerByte(serialNumber, isGpsAckMsg, gpscode, cmdType, result, simplecmd);

        //        CmdServer.SendTo((IPEndPoint)adress, answerBytes);
        //    }
        //}

        /// <summary> 构造应答数据
        /// 构造应答数据
        /// </summary>
        /// <param name="serialNumber">流水号</param>
        /// <param name="isGpsAckMsg">是否是GPS应答信息</param>
        /// <param name="gpsCode">GPSG带前缀编码</param>
        /// <param name="cmd">下发的命令类型</param>
        /// <param name="result">GPS终端对命令的执行结果:成功或失败</param>
        /// <param name="simpleCmd">简单控制命令类型</param>
        /// <returns></returns>
        private byte[] SetAnswerByte(string serialNumber,bool isGpsAckMsg, string gpsCode, ControlCmdType cmd, bool result, params SimpleCmdType[] simpleCmd)
        {
            try
            {
                byte[] sendBuffer = null;

                byte[] dataBuffer = null;

                CmdData cmddata = new CmdData();
                cmddata.Data.Cmd = cmd;

                byte gpsCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length;

                byte serialLen = (byte)Encoding.Default.GetBytes(serialNumber).Length;

                switch (cmd)
                {
                    case ControlCmdType.DeviceCircuitresAndOil://控制油路应答

                        ControlOilCircuit structOil = new ControlOilCircuit();

                        structOil.Data.IsGpsAckMsg = isGpsAckMsg;
                        structOil.GPSCode = gpsCode;
                        structOil.Data.Result = result;
                        structOil.Data.GPSCodeLen = gpsCodeLen;
                        structOil.SerialNumber = serialNumber;
                        structOil.Data.SerialNumberLen = serialLen;
                        byte[] bytsOil = new byte[structOil.GetLength()];
                        structOil.WriteBuffer(0, bytsOil);
                        cmddata.DataBuffer = bytsOil;
                        cmddata.Data.DataLen = (ushort)bytsOil.Length;
                        sendBuffer = new byte[cmddata.GetLenth()];
                        cmddata.WriteBuffer(0, sendBuffer);

                        break;

                    //解除报警应答
                    case ControlCmdType.DischargeAlarm:

                        DischangeAlarmControl structAlarm = new DischangeAlarmControl();

                        structAlarm.GPSCode = gpsCode;
                        structAlarm.Data.Result = result;
                        structAlarm.Data.GPSCodeLen = gpsCodeLen;
                        structAlarm.SerialNumber = serialNumber;
                        structAlarm.Data.SerialNumberLen = serialLen;

                        byte[] bytsAlarm = new byte[structAlarm.GetLength()];
                        structAlarm.WriteBuffer(0, bytsAlarm);
                        cmddata.DataBuffer = bytsAlarm;
                        cmddata.Data.DataLen = (ushort)bytsAlarm.Length;
                        sendBuffer = new byte[cmddata.GetLenth()];
                        cmddata.WriteBuffer(0, sendBuffer);

                        break;

                    //调度控制(下发文本)
                    case ControlCmdType.DispatchControl:

                        DispatchControl structDispatch = new DispatchControl();
                        structDispatch.Data.IsGpsAckMsg = isGpsAckMsg;
                        structDispatch.GPSCode = gpsCode;
                        structDispatch.Data.Result = result;
                        structDispatch.Data.GPSCodeLen = gpsCodeLen;
                        structDispatch.SerialNumber = serialNumber;
                        byte[] bytsDispatch = new byte[structDispatch.GetLength()];
                        structDispatch.WriteBuffer(0, bytsDispatch);
                        cmddata.DataBuffer = bytsDispatch;
                        cmddata.Data.DataLen = (ushort)bytsDispatch.Length;
                        sendBuffer = new byte[cmddata.GetLenth()];
                        cmddata.WriteBuffer(0, sendBuffer);

                        break;

                    //监听喊话
                    case ControlCmdType.ListenCall:

                        ListenCallControl structListenCall = new ListenCallControl();
                        structListenCall.Data.IsGpsAckMsg = isGpsAckMsg;
                        structListenCall.GPSCode = gpsCode;
                        structListenCall.Data.GPSCodeLen = gpsCodeLen;
                        structListenCall.Data.Result = result;
                        structListenCall.Data.SerialNumberLen = serialLen;
                        structListenCall.SerialNumber = serialNumber;
                        byte[] bytsListenCall = new byte[structListenCall.GetLength()];
                        structListenCall.WriteBuffer(0, bytsListenCall);
                        cmddata.DataBuffer = bytsListenCall;
                        cmddata.Data.DataLen = (ushort)bytsListenCall.Length;
                        sendBuffer = new byte[cmddata.GetLenth()];
                        cmddata.WriteBuffer(0, sendBuffer);

                        break;

                    case ControlCmdType.BJSZLedControl://透传数据应答(BJSZ  LED)

                        BJSZLEDContentControl structBJSZLED = new BJSZLEDContentControl();
                        structBJSZLED.Data.IsGpsAckMsg = isGpsAckMsg;
                        structBJSZLED.GPSCode = gpsCode;
                        structBJSZLED.Data.Result = result;
                        structBJSZLED.Data.SerialNumberLen = serialLen;
                        structBJSZLED.SerialNumber = serialNumber;
                        structBJSZLED.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length;
                        byte[] bytsBJSZLED = new byte[structBJSZLED.GetLength()];
                        structBJSZLED.WriteBuffer(0, bytsBJSZLED);
                        cmddata.DataBuffer = bytsBJSZLED;
                        cmddata.Data.DataLen = (ushort)bytsBJSZLED.Length;
                        sendBuffer = new byte[cmddata.GetLenth()];
                        cmddata.WriteBuffer(0, sendBuffer);
                        break;

                    case ControlCmdType.LongHanAnswered://龙汗数据应答                    
                        break;

                    case ControlCmdType.SimpleInstruction://简单控制命令

                        SimpleInstructionControl structSimple = new SimpleInstructionControl();
                        structSimple.Data.InstructionType = simpleCmd[0];
                        structSimple.Data.IsGpsAckMsg = isGpsAckMsg;
                        structSimple.GPSCode = gpsCode;
                        structSimple.Data.Result = result;
                        structSimple.Data.SerialNumberLen = serialLen;
                        structSimple.SerialNumber = serialNumber;
                        structSimple.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length;
                        byte[] bytsSimple = new byte[structSimple.GetLength()];
                        structSimple.WriteBuffer(0, bytsSimple);
                        cmddata.DataBuffer = bytsSimple;
                        cmddata.Data.DataLen = (ushort)bytsSimple.Length;
                        sendBuffer = new byte[cmddata.GetLenth()];
                        cmddata.WriteBuffer(0, sendBuffer);
                        break;

                    case ControlCmdType.SendTakePicture://拍照应答

                        TakePictureControl structPicture = new TakePictureControl();
                        structPicture.Data.IsGpsAckMsg = isGpsAckMsg;
                        structPicture.GPSCode = gpsCode;
                        structPicture.Data.Result = result;
                        structPicture.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length;
                        structPicture.SerialNumber = serialNumber;
                        structPicture.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(serialNumber).Length;
                        byte[] bytsPicture = new byte[structPicture.GetLength()];
                        structPicture.WriteBuffer(0, bytsPicture);
                        cmddata.DataBuffer = bytsPicture;
                        cmddata.Data.DataLen = (ushort)bytsPicture.Length;
                        sendBuffer = new byte[cmddata.GetLenth()];
                        cmddata.WriteBuffer(0, sendBuffer);
                        break;

                    //对下发广告的回复
                    case ControlCmdType.SendAdvertisement:

                        LEDControl ledControl = new LEDControl();
                        ledControl.GPSCode = gpsCode;
                        ledControl.SerialNumber = serialNumber;
                        ledControl.Data.SerialNumberLen = serialLen;
                        ledControl.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length;
                        ledControl.Data.IsGpsAckMsg = false;
                        ledControl.Data.Result = result;
                        dataBuffer = new byte[ledControl.GetLength()];
                        ledControl.WriteBuffer(0, dataBuffer);
                        cmddata.DataBuffer = dataBuffer;
                        cmddata.Data.DataLen = (ushort)dataBuffer.Length;
                        cmddata.Data.Cmd = ControlCmdType.SendAdvertisement;
                        sendBuffer = new byte[cmddata.GetLenth()];
                        cmddata.WriteBuffer(0, sendBuffer);

                        break;

                    //超速报警
                    case ControlCmdType.OverSpeedAlarm:

                        OverSpeedAlarmControl overSpeedCrl = new OverSpeedAlarmControl();
                        overSpeedCrl.GPSCode = gpsCode;
                        overSpeedCrl.Data.GPSCodeLen = gpsCodeLen;
                        overSpeedCrl.SerialNumber = serialNumber;
                        overSpeedCrl.Data.SerialNumberLen = serialLen;
                        overSpeedCrl.Data.IsGpsAckMsg = isGpsAckMsg;
                        overSpeedCrl.Data.Result = result;
                        dataBuffer = new byte[overSpeedCrl.GetLength()];
                        overSpeedCrl.WriteBuffer(0, dataBuffer);
                        cmddata.DataBuffer = dataBuffer;
                        cmddata.Data.DataLen = (ushort)dataBuffer.Length;
                        cmddata.Data.Cmd = ControlCmdType.OverSpeedAlarm;
                        sendBuffer = new byte[cmddata.GetLenth()];
                        cmddata.WriteBuffer(0, sendBuffer);

                        break;
                }
                return sendBuffer;
            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
                return new byte[0];
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 应用层拍照确认方法
        /// </summary>
        /// <param name="pictureData">拍照数据</param>
        /// <param name="isGpsAckMsg">是否是GPS终端的确认消息</param>
        /// <param name="bResult">执行结果:成功或失败</param>
        public void TakePictureAckMsg(ref YouWeiGPSData pictureData, bool isGpsAckMsg, bool bResult)
        {
            TakePictureControl takePicture = new TakePictureControl();
            takePicture.FilePath = pictureData.BaseData.PhotoPath;
            takePicture.GPSCode = pictureData.FullGpsCode;
            takePicture.Data.FilePathLen = Encoding.Default.GetBytes(takePicture.FilePath).Length;
            takePicture.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(takePicture.GPSCode).Length;
            takePicture.Data.PictureType = (TakePictureType)pictureData.BaseData.RealTimePhotoType;
            takePicture.Data.Result = bResult;
            takePicture.Data.IsGpsAckMsg = isGpsAckMsg;

            byte[] dataBuffer = new byte[takePicture.GetLength()];
            takePicture.WriteBuffer(0, dataBuffer);

            CmdData data = new CmdData();
            data.Data.Cmd = ControlCmdType.SendTakePicture;
            data.DataBuffer = dataBuffer;
            data.Data.DataLen = (ushort)dataBuffer.Length;

            byte[] sendBuffer = new byte[data.GetLenth()];
            data.WriteBuffer(0, sendBuffer);

            OnPostAckMsgHandlerEvent(takePicture.GPSCode, sendBuffer);
        }