Пример #1
0
 public TakePhotoDelayCmd(GPSPhotographTask task)
 {
     this.task = task;
 }
 //检测是否存在开门设置并且门状态为开,如果有则加入拍照任务列表.
 public void CheckGPSPhotograph(GPSDataEntity entity)
 {
     EOpenDoorPhotoPara para = CacheUtility.GetPhotoIntervalByVehicleCodeFromHT(entity.GPSCode);
     //Logger.Fatal("para != null" + (para != null));
     //Logger.Fatal("IsOpened(entity)" + IsOpened(entity));
     if (para != null && IsOpened(entity))
     {
         GPSPhotographTask task = new GPSPhotographTask()
         {
             Finished = false,
             IsOpenDoor = true,
             GPSCode = entity.GPSCode,
             PhotoInterval = para.ShootTimeSpan * 60,
             ReportTime = DateTime.Now,//由于是和服务器时间相对比,所以直接使用服务器时间 entity.ReportTime,
             LastPhotographTime = DateTime.Now,//检测到开门,则默认此时为GPS硬件设备自动触发的第一次拍照的时间。
             VehicleCode = entity.VehicleCode,
             CurrentCameraIndex = 0
         };
         string[] CameraIDArr = para.CameraIds.Split(',');
         int CameraIDArrLen = CameraIDArr.Length;
         task.CameraIds = new ushort[CameraIDArrLen];
         for (int i = 0; i < CameraIDArrLen; i++)
         {
             task.CameraIds[i] = Convert.ToUInt16(CameraIDArr[i]);
         }
         lock (mPhotoTask)
         {
             if (!mPhotoTask.ContainsKey(entity.GPSCode))
             {
                 mPhotoTask.Add(entity.GPSCode, task);
                 Util.Common.LogFatal(string.Format("GPS[{0}]添加一个拍照任务,摄像头:{1}", entity.GPSCode, para.CameraIds));
             }
         }
     }
 }
 //发送拍照指令。
 private void SendPhotographCmd(GPSPhotographTask task)
 {
     Command.ICommand cmd = new Command.TakePhotoDelayCmd(task);
     cmd.Send();
 }
        //关门或取消了设置.0关,1开
        private bool IsClosedOrUnSetted(GPSPhotographTask task)
        {
            GPSDataEntity entity = Util.Common.GetLastCurrentInfo(task.GPSCode);
            //Util.Common.LogFatal(string.Format("IsClosedOrUnSetted task.IsOpenDoor={0},entity.DoorStatus={1} 是否己关门{2} [{3}]", task.IsOpenDoor, entity.DoorStatus, (task.IsOpenDoor && entity.DoorStatus == 0), task.GPSCode));
            //如果拍照任务的为开门,而现在门状态为关,则车辆己关门
            if (task.IsOpenDoor && entity.DoorStatus == 0)
            {
                return true;//closed=true
            }
            //int interval = CacheUtility.GetPhotoIntervalByVehicleCodeFromHT(entity.GPSCode);
            //LogFatal(string.Format("IsClosedOrUnSetted interval={0} 取消了设置{1}", interval,(interval == 0)));
            //return interval == 0;//取消了设置.
            return false;

        }
 //检查拍照任务是否超出连续拍照的时间内
 private bool IsOutSettingInterval(GPSPhotographTask task)
 {
     TimeSpan ts = DateTime.Now.Subtract(task.ReportTime).Duration();
     bool timeUp = ts.TotalSeconds > task.PhotoInterval;
     Util.Common.LogFatal(string.Format("[{0}]任务实际总用时:{1};任务计划总用时:{2}",task.GPSCode, ts.TotalSeconds, task.PhotoInterval));
     bool IfTurnsFinished = (task.CurrentCameraIndex == task.CameraIds.Length - 1);
     //Util.Common.LogFatal(string.Format("timeUp:{0};IfTurnsFinished:{1}", timeUp, IfTurnsFinished));
     bool result = timeUp && IfTurnsFinished;
     if (result)
     {
         Util.Common.LogFatal(string.Format("gps[{0}]超出连续拍照时间[{1}],且最后一轮拍摄已完成", task.GPSCode, task.PhotoInterval));
     }
     return result;
 }
 // 拍照完成且在每次拍照时间间隔内或拍照超时
 private bool IsFinishedOrTimeOut(GPSPhotographTask task)
 {
     bool finishedOrTimeUp = false;
     TimeSpan ts = DateTime.Now.Subtract(task.LastPhotographTime).Duration();
     Util.Common.LogFatal(string.Format("[{0}]上次拍照时间:{1}",task.GPSCode, task.LastPhotographTime));
     if (task.Finished)
     {
         finishedOrTimeUp = ts.TotalSeconds > mPerPhotographInterval;//如果每次拍照时间少于30秒,也需要等到30秒才拍一次
         Util.Common.LogFatal(string.Format("[{0}]超过单次照片需要等的时间:{1}",task.GPSCode,finishedOrTimeUp));
     }
     else
     {
         finishedOrTimeUp = ts.TotalMinutes > mPhotographTimeout;
         Util.Common.LogFatal(string.Format("[{0}]超过单次照片最大时间:{1}", task.GPSCode, finishedOrTimeUp));
     }
     if (finishedOrTimeUp)
     {
         Util.Common.LogFatal(string.Format("GPSCode:{0}, CameraID:{1},拍照{2} 每次拍照间隔{3}秒,每次拍照超时间隔{4}秒,距上次拍照时间间隔{5}秒 [{6}]",task.GPSCode,task.CameraIds[task.CurrentCameraIndex], task.Finished ? "完成" : "未完成",
             mPerPhotographInterval, mPhotographTimeout * 60, ts.TotalSeconds, task.GPSCode));
     }
     return finishedOrTimeUp;
 }