Exemplo n.º 1
0
        public void Start()
        {
            try
            {
                SetCameraProporties();

                while (!Finish)
                {
                    if (Request != CameraRequest.Alive)
                    {
                        ProcessRequest(Request);
                        Request = CameraRequest.Alive;
                    }

                    Thread.Sleep(5);
                }
            }
            catch (ThreadAbortException)
            {
                Console.WriteLine("Thread Aborting (Because of exception)");
            }
            finally
            {
                Shutdown();
            }
        }
Exemplo n.º 2
0
 public void InitiateCaptureImage(CameraRequest action, Socket[] connections)
 {
     foreach (Socket connection in connections)
     {
         ThreadPool.QueueUserWorkItem(state => CaptureImage(action, connection));
     }
 }
Exemplo n.º 3
0
        private void ProcessRequest(CameraRequest request)
        {
            //start asking the camera for a new image
            byte[] data = connection.MakeRequest(PropertyRequest(request));

            //extract image data
            string imageName;

            byte[] imageData;
            ByteManipulation.SeperateData(out imageName, data, out imageData);
            if (imageName == "" || imageData.Length <= 0)
            {
                Console.WriteLine("No Image data recieved!!");
                Console.WriteLine("Debug data:");
                Console.WriteLine("\tThread Camera: " + config.Config.Id);
                Console.WriteLine("\tImage set id: " + ImageSetName);
                return;
            }

            using (FileStream fileStream = new FileStream(SavePath + imageName, FileMode.CreateNew))
            {
                for (int i = 0; i < imageData.Length; i++)
                {
                    fileStream.WriteByte(imageData[i]);
                }
            }
        }
Exemplo n.º 4
0
        public byte[] MakeRequest(CameraRequest request)
        {
            byte[] bytes = new byte[Constants.ByteArraySize],
            buffer = new byte[bufferSize];

            if (!socket.Connected)
            {
                throw new Exception("Socket needs to be connnected");
            }
            try
            {
                // Encode the data string into a byte array.
                byte[] msg = Encoding.ASCII.GetBytes((int)request + Constants.EndOfMessage);
                socket.Send(msg);

                //grab the bytes
                bytes = new byte[Constants.ByteArraySize];
                int totalData = 0;
                do
                {
                    int bytesRec = socket.Receive(buffer);
                    Array.Copy(buffer, 0, bytes, totalData, bytesRec);
                    totalData += bytesRec;
                } while (!ByteManipulation.SearchEndOfMessage(bytes, totalData));

                return(Helpers.Networking.TrimExcessByteData(bytes, totalData - 1));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw e;
            }
        }
Exemplo n.º 5
0
        public byte[] MakeRequest(CameraRequest request)
        {
            //check for valid input
            if (!socket.Connected)
            {
                throw new Exception("Socket needs to be connnected");
            }

            //send the request to the camera
            string sendRequest = ((int)request) + Constants.EndOfMessage;

            SendData(socket, sendRequest);
            sentData.WaitOne();

            //wait for the request data
            StateObject state = new StateObject {
                WorkSocket = socket
            };

            try
            {
                socket.BeginReceive(state.Buffer, 0, Constants.ByteArraySize, 0, ReceiveDataComplete, state);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            recieveData.WaitOne();

            return(state.Buffer);
        }
Exemplo n.º 6
0
        private byte[] PropertyRequest(CameraRequest request)
        {
            CommandBuilder builder = new CommandBuilder().Request(request);

            if (request == CameraRequest.Alive || request == CameraRequest.SendTestImage)
            {
                return(builder.Build());
            }

            builder.AddParam("id", ImageSetName);

            return(builder.Build());
        }
Exemplo n.º 7
0
 // POST api/values
 public IHttpActionResult Post([FromBody] CameraRequestDto req)
 {
     try
     {
         CameraRequest data = mapper.Map <CameraRequestDto, CameraRequest>(req);
         data.Date = DateTime.Now;
         context.CameraRequest.Add(data);
         context.SaveChanges();
         return(Ok());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// <see cref="IVideoService.GetCameras(CameraRequest)"/>
        /// </summary>
        public async Task <ListBaseResponse <CameraResponse> > GetCameras(CameraRequest request)
        {
            var result = await _hikHttp.PostAsync <HikVisionResponse <ListBaseResponse <CameraResponse> > >(
                "/api/resource/v1/camera/advance/cameraList", new
            {
                pageNo             = request.PageNo,
                pageSize           = request.PageSize,
                cameraIndexCodes   = request.CameraIndexCodes != null ? string.Join(',', request.CameraIndexCodes) : "",
                cameraName         = request.CameraName,
                encodeDevIndexCode = request.EncodeDevIndexCode,
                regionIndexCode    = request.RegionIndexCode,
                isCascade          = request.IsCascade
            });

            return(result?.Data);
        }
Exemplo n.º 9
0
        public async Task <IActionResult> AddCamera([FromBody] CameraRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            var _camera = new Camera
            {
                IpAddress = req.Url,
                Client    = Mapper.Map <ClientDTO, Client>(req.Client)
            };

            await _service.AddCamera(_camera);

            return(Ok());
        }
Exemplo n.º 10
0
        public void CaptureImageSet(CameraRequest wanted)
        {
            if (!CheckDone())
            {
                return;
            }

            UpdateCameraParams(wanted);

            for (int i = 0; i < cameraThreads.Length; i++)
            {
                if (cameraThreads[i] != null && cameraThreads[i].IsAlive)
                {
                    threadConfiguration[i].ImageSetName = imagesetId.ToString();
                    threadConfiguration[i].Request      = wanted;
                }
            }
        }
Exemplo n.º 11
0
        public CommandReader(byte[] data)
        {
            Parameters = new Dictionary <string, string>();
            string[] listed = Regex.Split(Encoding.ASCII.GetString(StripToBasicMessage(data)), Constants.ParamSeperator);

            CameraRequest pre;

            CameraRequest.TryParse(listed[0], out pre);
            Request = pre;

            for (int i = 1; i < listed.Length; i++)
            {
                int    sepindex = listed[i].IndexOf(Constants.ParamKeyValueSeperator);
                string key      = listed[i].Substring(0, sepindex);
                string value    = listed[i].Substring(sepindex + 1, listed[i].Length - sepindex - 1);

                Parameters.Add(key, value);
            }
        }
Exemplo n.º 12
0
        public static byte[] getSnapshot(Command command)
        {
            byte[]        returnData;
            CameraRequest request = (CameraRequest)Util.Serialization.deserialize(command.data);

            if (Webcam.mostRecent == null)
            {
                return(new byte[] { });
            }
            using (MemoryStream mem = new MemoryStream())
            {
                using (Bitmap target = (Bitmap)Webcam.mostRecent.Clone())
                {
                    EncoderParameters ep = new EncoderParameters();
                    ep.Param[0] = new EncoderParameter(Encoder.Quality, (long)request.compressLevel);
                    target.Save(mem, getEncoderInfo("image/jpeg"), ep);
                    returnData = mem.ToArray();
                }
            }
            return(returnData);
        }
Exemplo n.º 13
0
        private void InternalProcess(CameraRequest request)
        {
            Console.WriteLine("Executing request: " + request);
            byte[] messageData;

            switch (request)
            {
            case CameraRequest.Alive:
                messageData = Encoding.ASCII.GetBytes(Constants.SuccessString + Constants.EndOfMessage);
                break;

            case CameraRequest.SendFullResImage:
                string imageLocation = camera.CaptureImage(imageName);

                messageData = ByteHelpers.FileToBytes(imageLocation);
                SendResponse(client, EndOfMessage(messageData));

                if (File.Exists(imageLocation))
                {
                    File.Delete(imageLocation);
                }
                return;

            case CameraRequest.SendTestImage:
                //For testing, send a static image saved on the device
                messageData = ByteHelpers.FileToBytes(Path.DirectorySeparatorChar + "scanimage" + Path.DirectorySeparatorChar + "test.jpg");
                SendResponse(client, EndOfMessage(messageData));
                return;

            case CameraRequest.SetProporties:
                return;

            default:
                messageData = FailedRequest();
                break;
            }

            SendResponse(client, EndOfMessage(messageData));
        }
Exemplo n.º 14
0
        private void UpdateCameraParams(CameraRequest image)
        {
            if (image == CameraRequest.Alive ||
                image == CameraRequest.SendTestImage ||
                image == CameraRequest.SetProporties)
            {
                return;
            }

            //iterate the image identifier name
            if (image == CameraRequest.SendFullResImage)
            {
                ++imagesetId;

                Directory.CreateDirectory(savePath + Path.DirectorySeparatorChar + "set-" + imagesetId);

                foreach (CameraThread thread in threadConfiguration)
                {
                    thread.SavePath = savePath + Path.DirectorySeparatorChar + "set-" + imagesetId;
                }
            }
        }
Exemplo n.º 15
0
 private void CaptureImage(CameraRequest action, Socket connection)
 {
     Console.WriteLine("Thread Active" + action + ", Socket " + connection.LocalEndPoint);
 }
Exemplo n.º 16
0
 public async Task <ListBaseResponse <CameraResponse> > GetCamerasByCondition(CameraRequest request)
 {
     return(await _videoService.GetCameras(request));
 }
Exemplo n.º 17
0
 public CommandBuilder Request(CameraRequest request)
 {
     command += (int)request;
     return(this);
 }