示例#1
0
        internal async Task ProcessMessage(byte[] buf)
        {
            try
            {
                if (OffFrameProcessor == null)
                {
                    return;
                }

                var slice = new Slice(buf);

                var imageStart = OffFrameProcessor.CalcImageStart(slice);

                if (LiveViewUpdated != null && imageStart > 60 && imageStart < buf.Length - 100 &&
                    buf[imageStart] == 0xff && buf[imageStart + 1] == 0xd8 && buf[buf.Length - 2] == 0xff &&
                    buf[buf.Length - 1] == 0xd9)
                {
                    IntPoint?size = null;
                    foreach (var ev in LiveViewUpdated.GetInvocationList().Cast <LiveViewUpdatedDelegate>())
                    {
                        size = await ev(new ArraySegment <byte>(buf, imageStart, buf.Length - imageStart));
                    }

                    if (size != null)
                    {
                        OffFrameProcessor.Process(new Slice(slice, 0, imageStart), size.Value);
                    }

                    if (firstconnect)
                    {
                        firstconnect = false;
                        LogTrace($"Camera connected and got first frame {Device.ModelName}");
                    }
                }
            }
            catch (Exception ex)
            {
                if (firstconnect)
                {
                    firstconnect = false;
                    LogError($"Camera failed first frame {Device.ModelName}", ex);
                }
            }
        }
示例#2
0
        public async Task <bool> Connect(int liveviewport, string lang)
        {
            language = lang;
            var token        = connectCancellation.Token;
            var connectStage = 0;

            try
            {
                LogTrace("Connecting camera " + Device.ModelName);
                do
                {
                    try
                    {
                        if (Profile.RequestConnection)
                        {
                            await RequestAccess(token);
                        }

                        connectStage = 1;

                        if (Profile.SetDeviceName)
                        {
                            await TryGet("?mode=setsetting&type=device_name&value=SM-G9350");
                        }

                        connectStage = 2;

                        LumixState.Reset();

                        LumixState.MenuSet = await GetMenuSet();

                        if (LumixState.MenuSet == null)
                        {
                            LogError($"Camera connection failed on Stage {connectStage} for camera {Device.ModelName}", "CameraConnect");
                            LumixState.IsLimited = true;
                        }

                        if (!LumixState.IsLimited)
                        {
                            LumixState.CurMenu = await GetCurMenu();
                        }

                        connectStage = 3;
                        await SwitchToRec();

                        connectStage        = 4;
                        LumixState.LensInfo = await GetLensInfo();

                        connectStage     = 5;
                        LumixState.State = await GetState();

                        connectStage = 6;
                        await http.Get <BaseRequestResult>($"?mode=startstream&value={liveviewport}", token);

                        token.ThrowIfCancellationRequested();
                        break;
                    }
                    catch (ConnectionLostException)
                    {
                        Debug.WriteLine("Connection lost", "Connection");
                    }
                    catch (TimeoutException)
                    {
                        Debug.WriteLine("Timeout", "Connection");
                    }
                    catch (OperationCanceledException)
                    {
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        LogError($"Camera connection failed on Stage {connectStage} for camera {Device.ModelName}", ex);
                    }

                    await Task.Delay(1000, token);
                }while (true);

                if (OffFrameProcessor == null)
                {
                    connectStage                   = 7;
                    OffFrameProcessor              = new OffFrameProcessor(Device.ModelName, Parser, LumixState);
                    OffFrameProcessor.LensChanged += OffFrameProcessor_LensChanged;
                }

                stateTimer.Change(2000, 2000);
                return(true);
            }
            catch (OperationCanceledException)
            {
                connectCancellation.Dispose();
                return(false);
            }
            catch (Exception e)
            {
                LogError($"Camera connection failed on Stage {connectStage} for camera {Device.ModelName}", e);
                return(false);
            }
            finally
            {
                isConnecting = false;
            }
        }