Example #1
0
        public bool Handshake()
        {
            if (!SimpleSend(OpCodes.Connect, "00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 03 00 00 00") ||
                !SimpleSend(OpCodes.Connect, "00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 03 00 00 00"))
            {
                return(false);
            }

            using (Packet request = new Packet(OpCodes.SettingsList))
            {
                request.WriteHexString("00 00 00 00 00 00 00 00 C8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 03 00 00 00");
                using (Packet response = Packet.Reader(SendCommand(request.GetBuffer())))
                {
                    if (response.ReadByte() != 1 || response.ReadByte() != 0x20)
                    {
                        return(false);
                    }

                    AvailableMainSettingIds.Clear();
                    AvailableSubSettingIds.Clear();

                    response.Index = 30;
                    ushort unk = response.ReadUInt16();//200?

                    int mainSettingsCount = response.ReadInt32();
                    for (int i = 0; i < mainSettingsCount; i++)
                    {
                        AvailableMainSettingIds.Add(response.ReadUInt16());
                    }

                    int subSettingsCount = response.ReadInt32();
                    for (int i = 0; i < subSettingsCount; i++)
                    {
                        AvailableSubSettingIds.Add(response.ReadUInt16());
                    }
                }
            }


            if (!SimpleSend(OpCodes.Connect, "00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 03 00 00 00"))
            {
                return(false);
            }

            if (!Update(false))
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        public bool Update(bool imageData)
        {
            using (Packet request = new Packet(OpCodes.Settings))
            {
                request.WriteHexString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00");
                byte[] buffer = SendCommand(request.GetBuffer());
                using (Packet response = Packet.Reader(buffer))
                {
                    if (!IsValidResponse(response))
                    {
                        return(false);
                    }

                    response.Index = 30;
                    int numSettings = response.ReadInt32();
                    int unk         = response.ReadInt32();
                    Debug.Assert(unk == 0);//always 0?

                    for (int i = 0; i < numSettings; i++)
                    {
                        ushort settingId             = response.ReadUInt16();
                        int    currentDataStartIndex = response.Index;
                        bool   knownSetting          = false;

                        CameraSetting setting;
                        if (!cameraSettings.TryGetValue((SettingIds)settingId, out setting))
                        {
                            setting = new CameraSetting((SettingIds)settingId);
                            cameraSettings.Add((SettingIds)settingId, setting);
                        }

                        if (AvailableMainSettingIds.Contains(settingId) ||
                            AvailableSubSettingIds.Contains(settingId))
                        {
                            knownSetting = true;

                            ushort dataType = response.ReadUInt16();
                            switch (dataType)
                            {
                            case 1:
                            {
                                response.Skip(3);
                                setting.Value = response.ReadByte();
                                byte subDataType = response.ReadByte();
                                switch (subDataType)
                                {
                                case 1:
                                    response.Skip(3);
                                    break;

                                default:
                                    knownSetting = false;
                                    break;
                                }
                            }
                            break;

                            case 2:
                            {
                                response.Skip(3);
                                setting.Value = response.ReadByte();
                                byte subDataType = response.ReadByte();
                                switch (subDataType)
                                {
                                case 1:
                                    response.Skip(3);
                                    break;

                                case 2:
                                    int num = response.ReadUInt16();
                                    setting.AcceptedValues.Clear();
                                    for (int j = 0; j < num; j++)
                                    {
                                        setting.AcceptedValues.Add(response.ReadByte());
                                    }
                                    break;

                                default:
                                    knownSetting = false;
                                    break;
                                }
                            }
                            break;

                            case 3:
                            {
                                response.Skip(4);
                                setting.Value = response.ReadInt16();
                                byte subDataType = response.ReadByte();
                                switch (subDataType)
                                {
                                case 1:
                                    response.Skip(6);
                                    break;

                                case 2:
                                    int num = response.ReadUInt16();
                                    setting.AcceptedValues.Clear();
                                    for (int j = 0; j < num; j++)
                                    {
                                        setting.AcceptedValues.Add(response.ReadInt16());
                                    }
                                    break;

                                default:
                                    knownSetting = false;
                                    break;
                                }
                            }
                            break;

                            case 4:
                            {
                                response.Skip(4);
                                setting.Value = response.ReadUInt16();
                                byte subDataType = response.ReadByte();
                                switch (subDataType)
                                {
                                case 1:
                                    response.Skip(2);
                                    response.ReadInt16();            // Decrement value?
                                    response.ReadInt16();            // Iecrement value?
                                    break;

                                case 2:
                                    int num = response.ReadUInt16();
                                    setting.AcceptedValues.Clear();
                                    for (int j = 0; j < num; j++)
                                    {
                                        setting.AcceptedValues.Add(response.ReadUInt16());
                                    }
                                    break;

                                default:
                                    knownSetting = false;
                                    break;
                                }
                            }
                            break;

                            case 6:
                            {
                                response.Skip(6);
                                if (setting.HasSubValue)
                                {
                                    setting.Value    = response.ReadUInt16();
                                    setting.SubValue = response.ReadUInt16();
                                }
                                else
                                {
                                    setting.Value = response.ReadInt32();
                                }
                                byte subDataType = response.ReadByte();
                                switch (subDataType)
                                {
                                case 1:
                                    response.Skip(12);
                                    break;

                                case 2:
                                    int num = response.ReadUInt16();
                                    setting.AcceptedValues.Clear();
                                    for (int j = 0; j < num; j++)
                                    {
                                        setting.AcceptedValues.Add(response.ReadInt32());
                                    }
                                    break;

                                default:
                                    knownSetting = false;
                                    break;
                                }
                            }
                            break;

                            default:
                                knownSetting = false;
                                break;
                            }

                            if (setting.Value != setting.PrevValue ||
                                setting.SubValue != setting.PrevSubValue)
                            {
                                setting.OnChanged();
                                if (SettingChanged != null)
                                {
                                    SettingChanged(setting);
                                }
                                setting.PrevValue    = setting.Value;
                                setting.PrevSubValue = setting.SubValue;
                            }
                        }

                        Debug.Assert(knownSetting);
                    }
                }
            }

            if (imageData)
            {
                if (IsLiveViewEnabled)
                {
                    LiveViewImage = GetImage(true);
                }

                CameraSetting photoQueue = GetSetting(SettingIds.PhotoTransferQueue);
                if (photoQueue != null)
                {
                    // NOTE: The camera is capped at 127 (0x75) images in the queue at any given time
                    int  numPhotos = photoQueue.Value & 0xFF;
                    bool photoAvailableForTransfer = ((photoQueue.Value >> 8) & 0xFF) == 0x80;
                    if (photoAvailableForTransfer)
                    {
                        byte[] img = GetImage(false);
                    }
                }
            }

            return(true);
        }