Exemple #1
0
        /// <summary>
        /// 给GPS发送拍照指令
        /// </summary>
        /// <param name="takePicture"></param>
        /// <param name="sendData"></param>
        public virtual void SendShootCMD(TakePicTask task, byte[] sendData)
        {
            //Liuhuaihai update on 2012-6-12
            //参考途鸽的多网关修改
            //string remortpoint = null;
            //Socket socket = null;

            //try
            //{
            //    //取得已建立的套接字
            //    if (TransfersType == TransfersType.IsTcp)
            //    {
            //        socket = TCPConnList.Instance().GetTCPConnection(task.GPSCode);
            //        if (socket == null)
            //        {
            //            Logger.Trace("[下发拍照指令]失败(socket == null) ;GPSCode:" + task.GPSCode);
            //            return;
            //        }
            //        if (socket.Connected == false)
            //        {
            //            //从集合移除
            //            TCPConnList.Instance().RemoveTCPConnection(task.GPSCode);
            //            Logger.Trace("[下发拍照指令]失败(Connected == false) ;GPSCode:" + task.GPSCode);
            //            return;
            //        }
            //    }
            //    else
            //    {
            //        remortpoint = UDPConnList.Instance().GetUDPConnection(task.GPSCode);
            //        if (string.IsNullOrEmpty(remortpoint))
            //        {
            //            Logger.Trace("[下发拍照指令]失败(remortpoint == null) ;GPSCode:" + task.GPSCode);
            //            return;
            //        }
            //    }

            //    if (sendData == null || sendData.Length <= 0) return;

            //    try
            //    {
            //        if (TransfersType == TransfersType.IsTcp)
            //        {

            //            int send = socket.Send(sendData);
            //            if (send > 0)
            //            {
            //                Logger.Trace(string.Format("[下发拍照指令成功]设备:{0},GPSCode:{1}", socket.RemoteEndPoint.ToString(), task.GPSCode));
            //                //发送回复表示执行成功
            //                //SendAnswerToWeb(takePicture.SerialNumber, false, takePicture.GPSCode, ControlCmdType.SimpleInstruction, true, new SimpleCmdType[] { takePicture.Data.ShootType });
            //                OnSendAnswerToWebEvent(task.SerialNumber, false, task.GPSCode, ControlCmdType.SimpleInstruction, true, new SimpleCmdType[] { task.TaskType });
            //            }
            //            else
            //            {
            //                //发送回复表示执行失败
            //                //SendAnswerToWeb(takePicture.SerialNumber, false, takePicture.GPSCode, ControlCmdType.SimpleInstruction, false, new SimpleCmdType[] { takePicture.Data.ShootType });
            //                OnSendAnswerToWebEvent(task.SerialNumber, false, task.GPSCode, ControlCmdType.SimpleInstruction, false, new SimpleCmdType[] { task.TaskType });
            //                Logger.Trace(string.Format("[下发拍照指令失败]设备:{0},GPSCode:{1}", socket.RemoteEndPoint.ToString(), task.GPSCode));
            //            }
            //        }
            //        else
            //        {
            //            string[] endpoint = remortpoint.Split(':');
            //            IPEndPoint e = new IPEndPoint(IPAddress.Parse(endpoint[0]), int.Parse(endpoint[1]));
            //            //if(GpsDataParser.CodePrefix=="0001") 

            //            OnSendDataEvent((EndPoint)e, sendData);
            //        }
            //    }
            //    catch (SocketException ex)
            //    {
            //        //从列表移除此连接
            //        TCPConnList.Instance().RemoveTCPConnection(task.GPSCode);
            //        Logger.Trace("[下发拍照指令]错误" + task.GPSCode + ";拍照类型:" + task.TaskType.ToString() + ex.ToString(), null);
            //    }

            //}
            //catch (Exception ex)
            //{
            //    Logger.Error(ex, null);
            //}
            //finally
            //{
            //    sendData = null;
            //}
            //
        }
Exemple #2
0
 /// <summary>
 /// 开始指定任务
 /// </summary>
 /// <param name="task"></param>
 /// <param name="instructionLen"></param>
 /// <param name="instruction"></param>
 public virtual void StartTask(TakePicTask task, ref uint instructionLen, ref byte[] instruction)
 {
     switch (task.TaskType)
     {
         //实时抓拍
         case SimpleCmdType.RealTimeShoot:
             TakePicture(task.GPSCode, task.CameraList[task.CurrentCameraIndex], ref instructionLen, ref instruction);
             //重新设定当前照片的最后完成时间:当前时间+超时时间
             task.CurrentPicDeadline = DateTime.Now.AddSeconds(TAKEPICTURETIMEOUT);
             Logger.Trace(string.Format("[开始拍照]实时抓拍Camera ID为:{0};GPSCode:{1};任务序列号:{2}", task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, task.SerialNumber));
             break;
         //定时拍照(是网关自己给自己下发的)
         case SimpleCmdType.TimingShoot:
             TakePicture(task.GPSCode, task.CameraList[task.CurrentCameraIndex], ref instructionLen, ref instruction);
             //重新设定当前照片的最后完成时间:当前时间+超时时间
             task.CurrentPicDeadline = DateTime.Now.AddSeconds(TAKEPICTURETIMEOUT);
             Logger.Trace(string.Format("[开始拍照]定时拍照Camera ID为:{0};GPSCode:{1};任务序列号:{2}", task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, task.SerialNumber));
             break;
         //正常连拍
         case SimpleCmdType.NormalSeriateShoot:
             TakePicture(task.GPSCode, task.CameraList[task.CurrentCameraIndex], ref instructionLen, ref instruction);
             task.CurrentPicDeadline = DateTime.Now.AddSeconds(TAKEPICTURETIMEOUT);
             Logger.Trace(string.Format("[开始拍照]正常连拍Camera ID为:{0};GPSCode:{1};已拍轮数:0;任务序列号:{2}", task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, task.SerialNumber));
             break;
         //开门连续拍照
         case SimpleCmdType.TakePictureForDoorShot:
             TakePicture(task.GPSCode, task.CameraList[task.CurrentCameraIndex], ref instructionLen, ref instruction);
             //重新设定当前照片的最后完成时间:当前时间+超时时间
             task.CurrentPicDeadline = DateTime.Now.AddSeconds(TAKEPICTURETIMEOUT);
             Logger.Trace(string.Format("[开始拍照]开门延时拍照Camera ID为:{0};GPSCode:{1};任务序列号:{2}", task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, task.SerialNumber));
             break;
         default:
             Logger.Trace(string.Format("[开始拍照]未知类型:{0};GPSCode:{1}", task.TaskType.ToString(), task.GPSCode));
             break;
     }
 }
Exemple #3
0
 /// <summary>
 /// 开始该任务的下一个照片,如果任务已完成,则退队,开始下一个任务
 /// </summary>
 /// <param name="task"></param>
 /// <param name="instructionLen"></param>
 /// <param name="instruction"></param>
 public virtual void StartNextPic(TakePicTask task, ref uint instructionLen, ref byte[] instruction)
 {
     string strLogType;
     if (task.Status == TakePicTaskStatus.LastPicFinished)
     {
         strLogType = "照片完成";
     }
     else
     {
         strLogType = "拍照超时";
     }
     switch (task.TaskType)
     {
         //实时抓拍
         case SimpleCmdType.RealTimeShoot:
         //定时拍照(是网关自己给自己下发的)
         case SimpleCmdType.TimingShoot:
             string taskType = "";
             if (task.TaskType == SimpleCmdType.RealTimeShoot)
             {
                 taskType = "实时抓拍";
             }
             else
             {
                 taskType = "定时拍照";
             }
             Logger.Trace(string.Format("[{0}]{1}Camera ID为:{2};GPSCode:{3};任务序列号:{4}", strLogType, taskType, task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, task.SerialNumber));
             if (task.CurrentCameraIndex < task.CameraList.Count - 1)
             {
                 task.CurrentCameraIndex++;
                 TakePicture(task.GPSCode, task.CameraList[task.CurrentCameraIndex], ref instructionLen, ref instruction);
                 //重新设定当前照片的最后完成时间:当前时间+超时时间
                 task.CurrentPicDeadline = DateTime.Now.AddSeconds(TAKEPICTURETIMEOUT);
                 //新的拍照已开始,改状态为Runing
                 task.Status = TakePicTaskStatus.Runing;
                 Logger.Trace(string.Format("[拍下一张照]{0}Camera ID为:{1};GPSCode:{2};任务序列号:{3}", taskType, task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, task.SerialNumber));
             }
             else
             {
                 if (task.TaskType == SimpleCmdType.TimingShoot)
                 {
                     try
                     {
                         CheckTaskThread.GetInstance().TimingShootList[task.GPSCode].IsFinish = true;
                         //如果是定时拍照,拍照完成时,要设定下次进行定时拍照的时间
                         CheckTaskThread.GetInstance().TimingShootList[task.GPSCode].NextShootTime = DateTime.Now.AddMinutes(CheckTaskThread.GetInstance().TimingShootList[task.GPSCode].TimeSpan);
                     }
                     catch (Exception ex)
                     {
                         if (ex.Message.Contains("给定关键字不在字典中"))
                         {
                             //说明检查线程将该goscode的定时拍照任务删除了,不用做处理
                         }
                         else
                         {
                             Logger.Error(ex, null);
                         }
                     }
                 }
                 //该实时拍照任务完成,推出队列
                 PicTaskPool[task.GPSCode].Dequeue();
                 Logger.Trace(string.Format("[任务退队]{0};GPSCode:{1};队列中任务数:{2};任务序列号:{3}", taskType, task.GPSCode, PicTaskPool[task.GPSCode].Count, task.SerialNumber));
                 //取出队首的任务
                 DoShoot(task.GPSCode, false);
             }
             break;
         //正常连拍
         case SimpleCmdType.NormalSeriateShoot:
             Logger.Trace(string.Format("[{0}]正常连拍Camera ID为:{1};GPSCode:{2};任务序列号:{3}", strLogType, task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, task.SerialNumber));
             NormalSeriateShootTask SeriateShootTask = (NormalSeriateShootTask)task;
             if (SeriateShootTask.CurrentCameraIndex < SeriateShootTask.CameraList.Count - 1)
             {
                 SeriateShootTask.CurrentCameraIndex++;
                 TakePicture(SeriateShootTask.GPSCode, SeriateShootTask.CameraList[task.CurrentCameraIndex], ref instructionLen, ref instruction);
                 SeriateShootTask.CurrentPicDeadline = DateTime.Now.AddSeconds(TAKEPICTURETIMEOUT);
                 //新的拍照已开始,改状态为Runing
                 task.Status = TakePicTaskStatus.Runing;
                 Logger.Trace(string.Format("[拍下一张照]正常连拍Camera ID为:{0};GPSCode:{1};已拍轮数:{2};任务序列号:{3}", task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, SeriateShootTask.HaveTurnsCount, SeriateShootTask.SerialNumber));
             }
             else//拍完了一轮
             {
                 //轮数加1
                 SeriateShootTask.HaveTurnsCount++;
                 if (SeriateShootTask.HaveTurnsCount < SeriateShootTask.TurnsCount)
                 {
                     SeriateShootTask.CurrentCameraIndex = 0;
                     TakePicture(SeriateShootTask.GPSCode, SeriateShootTask.CameraList[task.CurrentCameraIndex], ref instructionLen, ref instruction);
                     SeriateShootTask.CurrentPicDeadline = DateTime.Now.AddSeconds(TAKEPICTURETIMEOUT);
                     //新的拍照已开始,改状态为Runing
                     task.Status = TakePicTaskStatus.Runing;
                     Logger.Trace(string.Format("[拍下一张照]正常连拍Camera ID为:{0};GPSCode:{1};已拍轮数:{2};任务序列号:{3}", task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, SeriateShootTask.HaveTurnsCount, SeriateShootTask.SerialNumber));
                 }
                 else
                 {
                     //该正常连拍任务完成,推出队列
                     PicTaskPool[task.GPSCode].Dequeue();
                     Logger.Trace(string.Format("[任务退队]正常连拍;GPSCode:{0};队列中任务数:{1};任务序列号:{2}", task.GPSCode, PicTaskPool[task.GPSCode].Count, task.SerialNumber));
                     DoShoot(task.GPSCode, false);
                 }
             }
             break;
         //开门连续拍照
         case SimpleCmdType.TakePictureForDoorShot:
             Logger.Trace(string.Format("[{0}]开门延时拍照Camera ID为:{1};GPSCode:{2};任务序列号:{3}", strLogType, task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, task.SerialNumber));
             if (task.CurrentCameraIndex < task.CameraList.Count - 1)
             {
                 task.CurrentCameraIndex++;
                 TakePicture(task.GPSCode, task.CameraList[task.CurrentCameraIndex], ref instructionLen, ref instruction);
                 //重新设定当前照片的最后完成时间:当前时间+超时时间
                 task.CurrentPicDeadline = DateTime.Now.AddSeconds(TAKEPICTURETIMEOUT);
                 //新的拍照已开始,改状态为Runing
                 task.Status = TakePicTaskStatus.Runing;
                 Logger.Trace(string.Format("[拍下一张照]开门延时拍照Camera ID为:{0};GPSCode:{1};任务序列号:{2}", task.CameraList[task.CurrentCameraIndex].ToString(), task.GPSCode, task.SerialNumber));
             }
             else
             {
                 //该开门连续拍照任务完成,推出队列
                 PicTaskPool[task.GPSCode].Dequeue();
                 Logger.Trace(string.Format("[任务退队]开门连续拍照;GPSCode:{0};队列中任务数:{1};任务序列号:{2}", task.GPSCode, PicTaskPool[task.GPSCode].Count, task.SerialNumber));
                 DoShoot(task.GPSCode, false);
             }
             break;
         default:
             Logger.Trace(string.Format("[拍下一张照]未知类型:{0};GPSCode:{1};任务序列号:{2}", task.TaskType.ToString(), task.GPSCode, task.SerialNumber));
             break;
     }
 }
Exemple #4
0
 /// <summary>
 /// 解析拍照控制命令(多摄像头)
 /// </summary>
 /// <param name="takePicture">拍照实体</param>
 /// <param name="instructionLen">解析后的命令长度</param>
 /// <param name="instruction">命令</param>
 public virtual void ParseShootInstructionControl(TakePictureControlMultiCamera takePicture)
 {
     if (!PicTaskPool.ContainsKey(takePicture.GPSCode))
     {
         PicTaskPool.Add(takePicture.GPSCode, new Queue<TakePicTask>());
     }
     Queue<TakePicTask> taskQueue = PicTaskPool[takePicture.GPSCode];
     string[] CameraIds = takePicture.CameraIds.Split(',');
     List<ushort> CameraIdList = new List<ushort>();
     for (int i = 0, i_Count = CameraIds.Length; i < i_Count; i++)
     {
         CameraIdList.Add(Convert.ToUInt16(CameraIds[i]));
     }
     switch (takePicture.Data.ShootType)
     {
         //实时抓拍:对应数据库表的该字段值为22,即enumInstructionType.enumInstructionType_GPSRealTimeTakePicture==22
         case SimpleCmdType.RealTimeShoot:
             TakePicTask objRealTimeShoot = new TakePicTask();
             objRealTimeShoot.GPSCode = takePicture.GPSCode;
             objRealTimeShoot.TaskType = SimpleCmdType.RealTimeShoot;
             objRealTimeShoot.CurrentCameraIndex = 0;
             objRealTimeShoot.CameraList = CameraIdList;
             objRealTimeShoot.Status = TakePicTaskStatus.NotStart;
             objRealTimeShoot.SerialNumber = takePicture.SerialNumber;
             taskQueue.Enqueue(objRealTimeShoot);
             Logger.Trace(string.Format("[添加拍照任务]实时抓拍,Camera ID为:{0};GPSCode:{1};队列中任务数:{2};任务序列号:{3};", takePicture.CameraIds, takePicture.GPSCode, taskQueue.Count, takePicture.SerialNumber));
             break;
         //正常连拍:对应数据库表的该字段值为20,即enumInstructionType.enumInstructionType_GPSTakePictureNormalShootTime==20
         case SimpleCmdType.NormalSeriateShoot:
             NormalSeriateShootTask objNormalSeriateShoot = new NormalSeriateShootTask();
             objNormalSeriateShoot.GPSCode = takePicture.GPSCode;
             objNormalSeriateShoot.TaskType = SimpleCmdType.NormalSeriateShoot;
             objNormalSeriateShoot.CurrentCameraIndex = 0;
             objNormalSeriateShoot.HaveTurnsCount = 0;
             objNormalSeriateShoot.TurnsCount = takePicture.Data.TurnsCount;
             objNormalSeriateShoot.CameraList = CameraIdList;
             objNormalSeriateShoot.Status = TakePicTaskStatus.NotStart;
             objNormalSeriateShoot.SerialNumber = takePicture.SerialNumber;
             taskQueue.Enqueue(objNormalSeriateShoot);
             Logger.Trace(string.Format("[添加拍照任务]正常连拍,Camera ID为:{0};GPSCode:{1};队列中任务数:{2};任务序列号:{3};总轮数:{4}",takePicture.CameraIds,takePicture.GPSCode,taskQueue.Count,takePicture.SerialNumber,takePicture.Data.TurnsCount));
             break;
         //开门连续拍照
         case SimpleCmdType.TakePictureForDoorShot:
             TakePicTask objDoorShot = new TakePicTask();
             objDoorShot.GPSCode = takePicture.GPSCode;
             objDoorShot.TaskType = SimpleCmdType.TakePictureForDoorShot;
             objDoorShot.CurrentCameraIndex = 0;
             objDoorShot.CameraList = CameraIdList;
             objDoorShot.Status = TakePicTaskStatus.NotStart;
             objDoorShot.SerialNumber = takePicture.SerialNumber;
             taskQueue.Enqueue(objDoorShot);
             Logger.Trace(string.Format("[添加拍照任务]开门连续拍照,Camera ID为:{0};GPSCode:{1};队列中任务数:{2};任务序列号:{3};", takePicture.CameraIds, takePicture.GPSCode, taskQueue.Count, takePicture.SerialNumber));
             break;
         default:
             Logger.Trace(string.Format("[添加拍照任务]未知类型,Camera ID为:{0};GPSCode:{1};队列中任务数:{2};任务序列号:{3};", takePicture.CameraIds, takePicture.GPSCode, taskQueue.Count, takePicture.SerialNumber));
             break;
     }
     //添加完任务,先执行一次该gpscode的任务列表
     DoShoot(takePicture.GPSCode, false);
 }
 public override void SendShootCMD(TakePicTask task, byte[] sendData)
 {
     //_ProcessAppLayerCmd.SendShootCMD(task, sendData, this.TransfersType);
 }
        public override void SendShootCMD(TakePicTask task, byte[] sendData)
        {
            string remortpoint = null;
            Socket socket = null;

            try
            {
                //取得已建立的套接字
                if (TransfersType == TransfersType.IsTcp)
                {
                    socket = TCPConnList.Instance().GetTCPConnection(task.GPSCode);
                    if (socket == null)
                    {
                        Logger.Trace("[下发拍照指令]失败(socket == null) ;GPSCode:" + task.GPSCode);
                        return;
                    }
                    if (socket.Connected == false)
                    {
                        //从集合移除
                        //TCPConnList.Instance().RemoveTCPConnection(task.GPSCode);
                        Logger.Trace("[下发拍照指令]失败(Connected == false) ;GPSCode:" + task.GPSCode);
                        return;
                    }
                }
                else
                {
                    remortpoint = UDPConnList.Instance().GetUDPConnection(task.GPSCode);
                    if (string.IsNullOrEmpty(remortpoint))
                    {
                        Logger.Trace("[下发拍照指令]失败(remortpoint == null) ;GPSCode:" + task.GPSCode);
                        return;
                    }
                }

                if (sendData == null || sendData.Length <= 0) return;

                try
                {
                    if (TransfersType == TransfersType.IsTcp)
                    {
                        //要发指令,不要发心跳
                        BoShiJieTCPKeepAlive.Instance.AddTCPKeepAlive(task.GPSCode);
                        int send = socket.Send(sendData);
                        if (send > 0)
                        {
                            Logger.Trace(string.Format("[下发拍照指令成功]设备:{0},GPSCode:{1}", socket.RemoteEndPoint.ToString(), task.GPSCode));
                            //发送回复表示执行成功
                            //SendAnswerToWeb(takePicture.SerialNumber, false, takePicture.GPSCode, ControlCmdType.SimpleInstruction, true, new SimpleCmdType[] { takePicture.Data.ShootType });
                            OnSendAnswerToWebEvent(task.SerialNumber, false, task.GPSCode, ControlCmdType.SimpleInstruction, true, new SimpleCmdType[] { task.TaskType });
                        }
                        else
                        {
                            //发送回复表示执行失败
                            //SendAnswerToWeb(takePicture.SerialNumber, false, takePicture.GPSCode, ControlCmdType.SimpleInstruction, false, new SimpleCmdType[] { takePicture.Data.ShootType });
                            OnSendAnswerToWebEvent(task.SerialNumber, false, task.GPSCode, ControlCmdType.SimpleInstruction, false, new SimpleCmdType[] { task.TaskType });
                            Logger.Trace(string.Format("[下发拍照指令失败]设备:{0},GPSCode:{1}", socket.RemoteEndPoint.ToString(), task.GPSCode));
                        }
                    }
                    else
                    {
                        string[] endpoint = remortpoint.Split(':');
                        IPEndPoint e = new IPEndPoint(IPAddress.Parse(endpoint[0]), int.Parse(endpoint[1]));
                        //if(GpsDataParser.CodePrefix=="0001") 

                        OnSendDataEvent((EndPoint)e, sendData);
                    }
                }
                catch (SocketException ex)
                {
                    //从列表移除此连接
                    //TCPConnList.Instance().RemoveTCPConnection(task.GPSCode);
                    Logger.Trace("[下发拍照指令]错误" + task.GPSCode + ";拍照类型:" + task.TaskType.ToString() + ex.ToString(), null);
                }

            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
            }
            finally
            {
                sendData = null;
            }
        }
 /// <summary>
 /// 新增照片接收实体
 /// </summary>
 /// <param name="picture"></param>
 /// <param name="task"></param>
 /// <param name="fragement"></param>
 private void AddPicReciver(BoShiJiePicture picture, TakePicTask task, GPSPictureFragment fragement)
 {
     if (task.TaskType == SimpleCmdType.NormalSeriateShoot)
     {
     }
     else
     {
         picture = new BoShiJiePicture(task.GPSCode, (byte)fragement.FragementCount, (byte)fragement.CameraID, (byte)fragement.Status);
     }
 }
Exemple #8
0
 /// <summary>
 /// 获得一个定时拍照任务
 /// </summary>
 /// <param name="para"></param>
 /// <returns></returns>
 private TakePicTask getATimingTask(ETimingPhotoPara para)
 {
     TakePicTask objRealTimeShoot = new TakePicTask();
     objRealTimeShoot.GPSCode = para.GPSCode;
     objRealTimeShoot.TaskType = SimpleCmdType.TimingShoot;
     objRealTimeShoot.CurrentCameraIndex = 0;
     objRealTimeShoot.CameraList = para.TimingShootCameraId;
     objRealTimeShoot.Status = TakePicTaskStatus.NotStart;
     objRealTimeShoot.SerialNumber = "Timing";
     return objRealTimeShoot;
 }