Example #1
0
        public async Task <MainDevice> SendGETAsync(string address, CancellationToken token)
        {
            var request = new HttpRequestMessage();

            request.RequestUri = new Uri("http://" + address + ":8080");
            request.Method     = HttpMethod.Get;
            request.Headers.Add("Accept", "application/json");
            var client = new HttpClient();

            try
            {
                Console.WriteLine(address + "GET");
                HttpResponseMessage response = await client.SendAsync(request, token);

                if (response.IsSuccessStatusCode)
                {
                    HttpContent content = response.Content;
                    var         result  = await content.ReadAsStringAsync();

                    if (result.Contains("DeviceName"))
                    {
                        MainDevice mainDevice = JsonConvert.DeserializeObject <MainDevice>(result);
                        mainDevice.IpAddress = address;
                        return(mainDevice);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(null);
        }
Example #2
0
        public async Task <MainDevice> GetInfoAsync(string deviceName, string address)
        {
            AuthRequest auth     = new AuthRequest(deviceName, "Viewer");
            var         jsonData = JsonConvert.SerializeObject(auth);
            string      uri      = "http://" + address + ":8080/register";
            var         client   = new HttpClient();

            try
            {
                HttpResponseMessage response = await client.PostAsync(uri, new StringContent(jsonData, Encoding.UTF8, "application/json"));

                response.EnsureSuccessStatusCode();

                HttpContent content = response.Content;
                var         result  = await content.ReadAsStringAsync();

                MainDevice mainDevice = JsonConvert.DeserializeObject <MainDevice>(result);
                mainDevice.IpAddress = address;
                return(mainDevice);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(null);
        }
        public override void Execute(JobP[] jobs)
        {
            Init(jobs);
            JobP tmp;

            for (int i = 0; i < currentJobs.Length; i++)     /*boucle sur le temps*/
            {
                for (int j = i; j < currentJobs.Length; j++) /* parcours du tableau */
                {
                    if (currentJobs[j].Deadline < currentJobs[i].Deadline)
                    {
                        tmp            = currentJobs[i];
                        currentJobs[i] = currentJobs[j];
                        currentJobs[j] = tmp;
                    }
                } /* On a ordonnancé selon le principe glouton par profits*/

                if (currentJobs[i].Deadline > MainDevice.TimeReady)
                {
                    Profit += currentJobs[i].Profit;
                    onTime.Add(currentJobs[i]);
                }
                else
                {
                    late.Add(currentJobs[i]);
                }
                MainDevice.AddJob(currentJobs[i]);
            }
        }
Example #4
0
 // Use this for initialization
 void Start()
 {
     mainDevice    = GameObject.FindGameObjectWithTag("MainDevice").GetComponent <MainDevice>();
     recordAudio   = gameObject.AddComponent <AudioSource>();
     playAudio     = gameObject.AddComponent <AudioSource>();
     encodeBufList = null;
     lastSamplePos = 0;
 }
 public void Release()
 {
     CaptureSession.StopRunning();
     Recorder.Dispose();
     Queue.Dispose();
     CaptureSession.RemoveOutput(Output);
     CaptureSession.RemoveInput(Input);
     Output.Dispose();
     Input.Dispose();
     MainDevice.Dispose();
     this.RemoveGestureRecognizer(Pinch);
 }
Example #6
0
        private void SetPinchGesture()
        {
            nfloat lastscale = 1.0f;

            Pinch = new UIPinchGestureRecognizer((e) =>
            {
                if (e.State == UIGestureRecognizerState.Changed)
                {
                    NSError device_error;
                    MainDevice.LockForConfiguration(out device_error);
                    if (device_error != null)
                    {
                        Console.WriteLine($"Error: {device_error.LocalizedDescription}");
                        MainDevice.UnlockForConfiguration();
                        return;
                    }
                    var scale = e.Scale + (1 - lastscale);
                    var zoom  = MainDevice.VideoZoomFactor * scale;
                    if (zoom > MaxZoom)
                    {
                        zoom = MaxZoom;
                    }
                    if (zoom < MinZoom)
                    {
                        zoom = MinZoom;
                    }
                    MainDevice.VideoZoomFactor = zoom;
                    MainDevice.UnlockForConfiguration();
                    lastscale = e.Scale;
                }
                else if (e.State == UIGestureRecognizerState.Ended)
                {
                    lastscale = 1.0f;
                }
            });
            this.AddGestureRecognizer(Pinch);
        }
        private async Task FetchAndUpdateAsync(string uid)
        {
            var user = await db.Users
                       .Include(u => u.Stations)
                       .ThenInclude(s => s.Devices)
                       .SingleAsync(u => u.Uid == uid);

            var accessToken = await EnsureValidAccessToken(user);

            var weatherData = await GetStationData(accessToken);

            user.FeelLike     = (FeelLikeAlgo)weatherData.Body.User.AdminData.FeelLikeAlgo;
            user.PressureUnit = (PressureUnit)weatherData.Body.User.AdminData.PressureUnit;
            user.Unit         = (Unit)weatherData.Body.User.AdminData.Unit;
            user.WindUnit     = (WindUnit)weatherData.Body.User.AdminData.WindUnit;

            foreach (var deviceDto in weatherData.Body.Devices)
            {
                var station = user.Stations.SingleOrDefault(s => s.Devices.Select(d => d.Id).Contains(deviceDto.Id));
                if (station == null)
                {
                    station = new Station {
                        Devices = new List <Core.Models.Device>()
                    };
                    user.Stations.Add(station);
                }

                station.Name        = deviceDto.StationName;
                station.Altitude    = deviceDto.Place.Altitude;
                station.City        = deviceDto.Place.City;
                station.CountryCode = deviceDto.Place.Country;
                station.Latitude    = deviceDto.Place.Location[0];
                station.Longitude   = deviceDto.Place.Location[1];
                station.Timezone    = deviceDto.Place.Timezone;

                var mainModule = station.Devices.OfType <MainDevice>().SingleOrDefault(d => d.Id == deviceDto.Id);
                if (mainModule == null)
                {
                    mainModule = new MainDevice
                    {
                        Id            = deviceDto.Id,
                        DashboardData = new List <DashboardData>()
                    };
                    station.Devices.Add(mainModule);
                }

                mainModule.Name       = deviceDto.ModuleName;
                mainModule.Firmware   = deviceDto.FirmwareVersion;
                mainModule.WifiStatus = deviceDto.WifiStatus;
                mainModule.DashboardData.Add(Convert2MainDashboardData(deviceDto.DashboardData));

                foreach (var moduleDto in deviceDto.Modules)
                {
                    var module = station.Devices.OfType <ModuleDevice>().SingleOrDefault(d => d.Id == moduleDto.Id);
                    if (module == null)
                    {
                        module = new ModuleDevice
                        {
                            Id            = moduleDto.Id,
                            Type          = ConvertToModuleType(moduleDto.Type),
                            DashboardData = new List <DashboardData>()
                        };
                        station.Devices.Add(module);
                    }

                    module.Name           = moduleDto.ModuleName;
                    module.Firmware       = moduleDto.FirmwareVersion;
                    module.RfStatus       = moduleDto.RFStatus;
                    module.BatteryVp      = moduleDto.BatteryPower;
                    module.BatteryPercent = moduleDto.BatteryPercentage;
                    module.DashboardData.Add(Convert2ModuleDashboardData(moduleDto));
                }
            }

            await db.SaveChangesAsync();
        }
        private void Initialize()
        {
            //Pinchジェスチャ登録
            SetPinchGesture();

            //デバイス設定
            var videoDevices   = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video);
            var cameraPosition = (cameraOptions == CameraOptions.Front) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back;

            MainDevice = videoDevices.FirstOrDefault(d => d.Position == cameraPosition);

            NSError device_error;

            MainDevice.LockForConfiguration(out device_error);
            if (device_error != null)
            {
                Console.WriteLine($"Error: {device_error.LocalizedDescription}");
                MainDevice.UnlockForConfiguration();
                return;
            }
            //フレームレート設定
            MainDevice.ActiveVideoMinFrameDuration = new CMTime(1, 24);
            MainDevice.UnlockForConfiguration();

            if (MainDevice == null)
            {
                return;
            }

            //max zoom
            MaxZoom = (float)Math.Min(MainDevice.ActiveFormat.VideoMaxZoomFactor, 6);

            //入力設定
            NSError error;

            Input = new AVCaptureDeviceInput(MainDevice, out error);
            CaptureSession.AddInput(Input);

            //出力設定
            Output = new AVCaptureVideoDataOutput();

            //フレーム処理用
            Queue = new DispatchQueue("myQueue");
            Output.AlwaysDiscardsLateVideoFrames = true;
            Recorder = new OutputRecorder()
            {
                Camera = Camera
            };
            Output.SetSampleBufferDelegate(Recorder, Queue);
            var vSettings = new AVVideoSettingsUncompressed();

            vSettings.PixelFormatType = CVPixelFormatType.CV32BGRA;
            Output.WeakVideoSettings  = vSettings.Dictionary;

            CaptureSession.AddOutput(Output);

            if (IsPreviewing)
            {
                CaptureSession.StartRunning();
            }
        }
Example #9
0
 public override int GetHashCode()
 {
     return(MainDevice != null ? MainDevice.GetHashCode() : 0);
 }