189
+
190
+            for (int e = 0, en = intf.getEndpointCount(); e < en; ++e) {
191
+                UsbEndpoint endpoint = intf.getEndpoint(e);
192
+                if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
193
+                    if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) {
194
+                        in = endpoint;
195
+                    } else if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
196
+                        out = endpoint;
197
+                    }
198
+                }
199
+            }
200
+
201
+            if (in == null || out == null) {
202
+                continue;
203
+            }
204
+
205
+            if (AppConfig.LOG) {
206
+                Log.i(TAG, "Found compatible USB interface");
207
+                Log.i(TAG, "Interface class " + intf.getInterfaceClass());
208
+                Log.i(TAG, "Interface subclass " + intf.getInterfaceSubclass());
209
+                Log.i(TAG, "Interface protocol " + intf.getInterfaceProtocol());
210
+                Log.i(TAG, "Bulk out max size " + out.getMaxPacketSize());
211
+                Log.i(TAG, "Bulk in max size " + in.getMaxPacketSize());
212
+                listener.onLogMessage("发现兼容的USB接口设备 "+ device.getDeviceName() +" "+  device.getVendorId());
213
+            }
214
+
215
+            if (device.getVendorId() == PtpConstants.CanonVendorId) {
216
+                PtpUsbConnection connection = new PtpUsbConnection(usbManager.openDevice(device), in, out,
217
+                        device.getVendorId(), device.getProductId());
218
+                camera = new EosCamera(connection, listener, new WorkerNotifier(context));
219
+            } else if (device.getVendorId() == PtpConstants.NikonVendorId) {
220
+                PtpUsbConnection connection = new PtpUsbConnection(usbManager.openDevice(device), in, out,
221
+                        device.getVendorId(), device.getProductId());
222
+                camera = new NikonCamera(connection, listener, new WorkerNotifier(context));
223
+            }
224
+
225
+            return true;
226
+        }
227
+
228
+        if (listener != null) {
229
+            listener.onError("No compatible camera found");
230
+        }
231
+
232
+        return false;
233
+    }
234
+}

+ 34 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/WorkerNotifier.java

@@ -0,0 +1,34 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp;
17
+
18
+import android.content.Context;
19
+
20
+public class WorkerNotifier implements Camera.WorkerListener {
21
+
22
+
23
+    public WorkerNotifier(Context context) {
24
+    }
25
+
26
+    @Override
27
+    public void onWorkerStarted() {
28
+    }
29
+
30
+    @Override
31
+    public void onWorkerEnded() {
32
+    }
33
+
34
+}

+ 61 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/CloseSessionCommand.java

@@ -0,0 +1,61 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.AppConfig;
21
+import com.remoteyourcam.usb.ptp.PtpCamera;
22
+import com.remoteyourcam.usb.ptp.PtpConstants;
23
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
25
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
26
+
27
+import android.util.Log;
28
+
29
+public class CloseSessionCommand extends Command {
30
+
31
+    private final String TAG = CloseSessionCommand.class.getSimpleName();
32
+
33
+    public CloseSessionCommand(PtpCamera camera) {
34
+        super(camera);
35
+    }
36
+
37
+    @Override
38
+    public void exec(IO io) {
39
+        io.handleCommand(this);
40
+        // Can this even happen?
41
+        if (responseCode == Response.DeviceBusy) {
42
+            camera.onDeviceBusy(this, true);
43
+            return;
44
+        }
45
+        // close even when error happened
46
+        camera.onSessionClosed();
47
+        if (responseCode != Response.Ok) {
48
+            // TODO error report
49
+            if (AppConfig.LOG) {
50
+                Log.w(TAG,
51
+                        String.format("Error response when closing session, response %s",
52
+                                PtpConstants.responseToString(responseCode)));
53
+            }
54
+        }
55
+    }
56
+
57
+    @Override
58
+    public void encodeCommand(ByteBuffer b) {
59
+        encodeCommand(b, Operation.CloseSession);
60
+    }
61
+}

+ 188 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/Command.java

@@ -0,0 +1,188 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import android.util.Log;
19
+
20
+import com.remoteyourcam.usb.AppConfig;
21
+import com.remoteyourcam.usb.ptp.PacketUtil;
22
+import com.remoteyourcam.usb.ptp.PtpAction;
23
+import com.remoteyourcam.usb.ptp.PtpCamera;
24
+import com.remoteyourcam.usb.ptp.PtpConstants;
25
+import com.remoteyourcam.usb.ptp.PtpConstants.Type;
26
+
27
+import java.nio.ByteBuffer;
28
+
29
+/**
30
+ * Base class for all PTP commands.
31
+ */
32
+public abstract class Command implements PtpAction {
33
+
34
+    private static final String TAG = "Command";
35
+
36
+    protected final PtpCamera camera;
37
+
38
+    /**
39
+     * Deriving classes have to set this field to true if they want to send data
40
+     * from host to camera.
41
+     */
42
+    protected boolean hasDataToSend;
43
+
44
+    /**
45
+     * Received response code, should be handled in
46
+     * {@link #exec(com.remoteyourcam.usb.ptp.PtpCamera.IO)}.
47
+     */
48
+    protected int responseCode;
49
+
50
+    private boolean hasResponseReceived;
51
+
52
+    public Command(PtpCamera camera) {
53
+        this.camera = camera;
54
+    }
55
+
56
+    @Override
57
+    public abstract void exec(PtpCamera.IO io);
58
+
59
+    public abstract void encodeCommand(ByteBuffer b);
60
+
61
+    /**
62
+     * Derived classes should implement this method if they want to send data
63
+     * from host to camera. The field {@code hasDataToSend} has to be set to
64
+     * true for the sending to be done. The data to send must not be greater
65
+     * than the USB max packet size, any size below 256 should be save.
66
+     */
67
+    public void encodeData(ByteBuffer b) {
68
+    }
69
+
70
+    /**
71
+     * Derived classes should implement this method if they want to decode data
72
+     * received in an data packet that has been sent by the camera. The
73
+     * {@code ByteBuffer} already points to the first byte behind the
74
+     * transaction id, i.e. the payload.
75
+     */
76
+    protected void decodeData(ByteBuffer b, int length) {
77
+        if (AppConfig.LOG) {
78
+            Log.w(TAG, "Received data packet but handler not implemented");
79
+        }
80
+    }
81
+
82
+    /**
83
+     * Override if any special response data has to be decoded. The
84
+     * {@code ByteBuffer} already points to the first byte behind the
85
+     * transaction id, i.e. the payload.
86
+     */
87
+    protected void decodeResponse(ByteBuffer b, int length) {
88
+    }
89
+
90
+    public boolean hasDataToSend() {
91
+        return hasDataToSend;
92
+    }
93
+
94
+    public boolean hasResponseReceived() {
95
+        return hasResponseReceived;
96
+    }
97
+
98
+    public int getResponseCode() {
99
+        return responseCode;
100
+    }
101
+
102
+    public void receivedRead(ByteBuffer b) {
103
+        int length = b.getInt();
104
+        int type = b.getShort() & 0xFFFF;
105
+        int code = b.getShort() & 0xFFFF;
106
+        int tx = b.getInt();
107
+
108
+        if (AppConfig.LOG) {
109
+            Log.i(TAG,
110
+                    String.format("Received %s packet for %s, length %d, code %s, tx %d",
111
+                            PtpConstants.typeToString(type), getClass().getSimpleName(), length,
112
+                            PtpConstants.codeToString(type, code), tx));
113
+        }
114
+        if (AppConfig.LOG_PACKETS) {
115
+            PacketUtil.logHexdump(TAG, b.array(), length < 512 ? length : 512);
116
+        }
117
+
118
+        if (type == Type.Data) {
119
+            decodeData(b, length);
120
+        } else if (type == Type.Response) {
121
+            hasResponseReceived = true;
122
+            responseCode = code;
123
+            decodeResponse(b, length);
124
+        } else {
125
+            // error
126
+            hasResponseReceived = true;
127
+        }
128
+    }
129
+
130
+    /**
131
+     * Reset fields so this command may be requeued.
132
+     */
133
+    @Override
134
+    public void reset() {
135
+        responseCode = 0;
136
+        hasResponseReceived = false;
137
+    }
138
+
139
+    protected void encodeCommand(ByteBuffer b, int code) {
140
+        b.putInt(12);
141
+        b.putShort((short) Type.Command);
142
+        b.putShort((short) code);
143
+        b.putInt(camera.nextTransactionId());
144
+        if (AppConfig.LOG_PACKETS) {
145
+            Log.i(TAG, "command packet for " + getClass().getSimpleName());
146
+            PacketUtil.logHexdump(TAG, b.array(), 12);
147
+        }
148
+    }
149
+
150
+    protected void encodeCommand(ByteBuffer b, int code, int p0) {
151
+        b.putInt(16);
152
+        b.putShort((short) Type.Command);
153
+        b.putShort((short) code);
154
+        b.putInt(camera.nextTransactionId());
155
+        b.putInt(p0);
156
+        if (AppConfig.LOG_PACKETS) {
157
+            Log.i(TAG, "command packet for " + getClass().getSimpleName());
158
+            PacketUtil.logHexdump(TAG, b.array(), 16);
159
+        }
160
+    }
161
+
162
+    protected void encodeCommand(ByteBuffer b, int code, int p0, int p1) {
163
+        b.putInt(20);
164
+        b.putShort((short) Type.Command);
165
+        b.putShort((short) code);
166
+        b.putInt(camera.nextTransactionId());
167
+        b.putInt(p0);
168
+        b.putInt(p1);
169
+        if (AppConfig.LOG_PACKETS) {
170
+            Log.i(TAG, "command packet for " + getClass().getSimpleName());
171
+            PacketUtil.logHexdump(TAG, b.array(), 20);
172
+        }
173
+    }
174
+
175
+    protected void encodeCommand(ByteBuffer b, int code, int p0, int p1, int p2) {
176
+        b.putInt(24);
177
+        b.putShort((short) Type.Command);
178
+        b.putShort((short) code);
179
+        b.putInt(camera.nextTransactionId());
180
+        b.putInt(p0);
181
+        b.putInt(p1);
182
+        b.putInt(p2);
183
+        if (AppConfig.LOG_PACKETS) {
184
+            Log.i(TAG, "command packet for " + getClass().getSimpleName());
185
+            PacketUtil.logHexdump(TAG, b.array(), 24);
186
+        }
187
+    }
188
+}

+ 62 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetDeviceInfoCommand.java

@@ -0,0 +1,62 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PtpCamera;
21
+import com.remoteyourcam.usb.ptp.PtpConstants;
22
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
25
+import com.remoteyourcam.usb.ptp.model.DeviceInfo;
26
+
27
+public class GetDeviceInfoCommand extends Command {
28
+
29
+    private DeviceInfo info;
30
+
31
+    public GetDeviceInfoCommand(PtpCamera camera) {
32
+        super(camera);
33
+    }
34
+
35
+    @Override
36
+    public void exec(IO io) {
37
+        io.handleCommand(this);
38
+        if (responseCode != Response.Ok) {
39
+            camera.onPtpError(String.format("Couldn't read device information, error code \"%s\"",
40
+                    PtpConstants.responseToString(responseCode)));
41
+        } else if (info == null) {
42
+            camera.onPtpError("Couldn't retrieve device information");
43
+        }
44
+    }
45
+
46
+    @Override
47
+    public void reset() {
48
+        super.reset();
49
+        info = null;
50
+    }
51
+
52
+    @Override
53
+    public void encodeCommand(ByteBuffer b) {
54
+        encodeCommand(b, Operation.GetDeviceInfo);
55
+    }
56
+
57
+    @Override
58
+    protected void decodeData(ByteBuffer b, int length) {
59
+        info = new DeviceInfo(b, length);
60
+        camera.setDeviceInfo(info);
61
+    }
62
+}

+ 57 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetDevicePropDescCommand.java

@@ -0,0 +1,57 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PtpCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants;
23
+import com.remoteyourcam.usb.ptp.model.DevicePropDesc;
24
+
25
+public class GetDevicePropDescCommand extends Command {
26
+
27
+    private final int property;
28
+    private DevicePropDesc devicePropDesc;
29
+
30
+    public GetDevicePropDescCommand(PtpCamera camera, int property) {
31
+        super(camera);
32
+        this.property = property;
33
+    }
34
+
35
+    @Override
36
+    public void exec(IO io) {
37
+        io.handleCommand(this);
38
+        if (responseCode == PtpConstants.Response.DeviceBusy) {
39
+            camera.onDeviceBusy(this, true);
40
+        }
41
+        if (devicePropDesc != null) {
42
+            // this order is important
43
+            camera.onPropertyDescChanged(property, devicePropDesc);
44
+            camera.onPropertyChanged(property, devicePropDesc.currentValue);
45
+        }
46
+    }
47
+
48
+    @Override
49
+    public void encodeCommand(ByteBuffer b) {
50
+        encodeCommand(b, PtpConstants.Operation.GetDevicePropDesc, property);
51
+    }
52
+
53
+    @Override
54
+    protected void decodeData(ByteBuffer b, int length) {
55
+        devicePropDesc = new DevicePropDesc(b, length);
56
+    }
57
+}

+ 68 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetDevicePropValueCommand.java

@@ -0,0 +1,68 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PtpCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Datatype;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
25
+
26
+public class GetDevicePropValueCommand extends Command {
27
+
28
+    private final int property;
29
+    private final int datatype;
30
+    private int value;
31
+
32
+    public GetDevicePropValueCommand(PtpCamera camera, int property, int datatype) {
33
+        super(camera);
34
+        this.property = property;
35
+        this.datatype = datatype;
36
+    }
37
+
38
+    @Override
39
+    public void exec(IO io) {
40
+        io.handleCommand(this);
41
+        if (responseCode == Response.DeviceBusy) {
42
+            camera.onDeviceBusy(this, true);
43
+        }
44
+        if (responseCode == Response.Ok) {
45
+            camera.onPropertyChanged(property, value);
46
+        }
47
+    }
48
+
49
+    @Override
50
+    public void encodeCommand(ByteBuffer b) {
51
+        encodeCommand(b, PtpConstants.Operation.GetDevicePropValue, property);
52
+    }
53
+
54
+    @Override
55
+    protected void decodeData(ByteBuffer b, int length) {
56
+        if (datatype == Datatype.int8) {
57
+            value = b.get();
58
+        } else if (datatype == Datatype.uint8) {
59
+            value = b.get() & 0xFF;
60
+        } else if (datatype == Datatype.uint16) {
61
+            value = b.getShort() & 0xFFFF;
62
+        } else if (datatype == Datatype.int16) {
63
+            value = b.getShort();
64
+        } else if (datatype == Datatype.int32 || datatype == Datatype.uint32) {
65
+            value = b.getInt();
66
+        }
67
+    }
68
+}

+ 90 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetObjectCommand.java

@@ -0,0 +1,90 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import android.graphics.Bitmap;
21
+import android.graphics.BitmapFactory;
22
+import android.util.Log;
23
+
24
+import com.remoteyourcam.usb.ptp.PtpCamera;
25
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
26
+import com.remoteyourcam.usb.ptp.PtpConstants;
27
+
28
+/**
29
+ * Read file data from camera with specified {@code objectHandle}.
30
+ */
31
+public class GetObjectCommand extends Command {
32
+
33
+    private static final String TAG = GetObjectCommand.class.getSimpleName();
34
+
35
+    private final int objectHandle;
36
+
37
+    private final BitmapFactory.Options options;
38
+    private Bitmap inBitmap;
39
+
40
+    private boolean outOfMemoryError;
41
+
42
+    public GetObjectCommand(PtpCamera camera, int objectHandle, int sampleSize) {
43
+        super(camera);
44
+        this.objectHandle = objectHandle;
45
+        options = new BitmapFactory.Options();
46
+        if (sampleSize >= 1 && sampleSize <= 4) {
47
+            options.inSampleSize = sampleSize;
48
+        } else {
49
+            options.inSampleSize = 2;
50
+        }
51
+    }
52
+
53
+    public Bitmap getBitmap() {
54
+        return inBitmap;
55
+    }
56
+
57
+    public boolean isOutOfMemoryError() {
58
+        return outOfMemoryError;
59
+    }
60
+
61
+    @Override
62
+    public void exec(IO io) {
63
+        throw new UnsupportedOperationException();
64
+    }
65
+
66
+    @Override
67
+    public void reset() {
68
+        super.reset();
69
+        inBitmap = null;
70
+        outOfMemoryError = false;
71
+    }
72
+
73
+    @Override
74
+    public void encodeCommand(ByteBuffer b) {
75
+        encodeCommand(b, PtpConstants.Operation.GetObject, objectHandle);
76
+    }
77
+
78
+    @Override
79
+    protected void decodeData(ByteBuffer b, int length) {
80
+        try {
81
+            // 12 == offset of data header
82
+            inBitmap = BitmapFactory.decodeByteArray(b.array(), 12, length - 12, options);
83
+        } catch (RuntimeException e) {
84
+            Log.i(TAG, "exception on decoding picture : " + e.toString());
85
+        } catch (OutOfMemoryError e) {
86
+            System.gc();
87
+            outOfMemoryError = true;
88
+        }
89
+    }
90
+}

+ 79 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetObjectHandlesCommand.java

@@ -0,0 +1,79 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.Camera.StorageInfoListener;
21
+import com.remoteyourcam.usb.ptp.PacketUtil;
22
+import com.remoteyourcam.usb.ptp.PtpCamera;
23
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
24
+import com.remoteyourcam.usb.ptp.PtpConstants;
25
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
26
+
27
+public class GetObjectHandlesCommand extends Command {
28
+
29
+    private final int storageId;
30
+    private final int objectFormat;
31
+    private final int associationHandle;
32
+    private int[] objectHandles;
33
+    private final StorageInfoListener listener;
34
+
35
+    public int[] getObjectHandles() {
36
+        if (objectHandles == null) {
37
+            return new int[0];
38
+        }
39
+        return objectHandles;
40
+    }
41
+
42
+    public GetObjectHandlesCommand(PtpCamera camera, StorageInfoListener listener, int storageId) {
43
+        this(camera, listener, storageId, 0, 0);
44
+    }
45
+
46
+    public GetObjectHandlesCommand(PtpCamera camera, StorageInfoListener listener, int storageId, int objectFormat) {
47
+        this(camera, listener, storageId, objectFormat, 0);
48
+    }
49
+
50
+    public GetObjectHandlesCommand(PtpCamera camera, StorageInfoListener listener, int storageId, int objectFormat,
51
+            int associationHandle) {
52
+        super(camera);
53
+        this.listener = listener;
54
+        this.storageId = storageId;
55
+        this.objectFormat = objectFormat;
56
+        this.associationHandle = associationHandle;
57
+    }
58
+
59
+    @Override
60
+    public void exec(IO io) {
61
+        io.handleCommand(this);
62
+        if (getResponseCode() != Response.Ok) {
63
+            // error
64
+            listener.onImageHandlesRetrieved(new int[0]);
65
+            return;
66
+        }
67
+        listener.onImageHandlesRetrieved(objectHandles);
68
+    }
69
+
70
+    @Override
71
+    public void encodeCommand(ByteBuffer b) {
72
+        super.encodeCommand(b, PtpConstants.Operation.GetObjectHandles, storageId, objectFormat, associationHandle);
73
+    }
74
+
75
+    @Override
76
+    protected void decodeData(ByteBuffer b, int length) {
77
+        objectHandles = PacketUtil.readU32Array(b);
78
+    }
79
+}

+ 73 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetObjectInfoCommand.java

@@ -0,0 +1,73 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.AppConfig;
21
+import com.remoteyourcam.usb.ptp.PtpCamera;
22
+import com.remoteyourcam.usb.ptp.PtpConstants;
23
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
25
+import com.remoteyourcam.usb.ptp.model.ObjectInfo;
26
+
27
+import android.util.Log;
28
+
29
+public class GetObjectInfoCommand extends Command {
30
+
31
+    private final String TAG = GetObjectInfoCommand.class.getSimpleName();
32
+
33
+    private final int outObjectHandle;
34
+    private ObjectInfo inObjectInfo;
35
+
36
+    public GetObjectInfoCommand(PtpCamera camera, int objectHandle) {
37
+        super(camera);
38
+        this.outObjectHandle = objectHandle;
39
+    }
40
+
41
+    public ObjectInfo getObjectInfo() {
42
+        return inObjectInfo;
43
+    }
44
+
45
+    @Override
46
+    public void exec(IO io) {
47
+        io.handleCommand(this);
48
+        if (responseCode == Response.DeviceBusy) {
49
+            camera.onDeviceBusy(this, true);
50
+        }
51
+        if (inObjectInfo != null) {
52
+            if (AppConfig.LOG) {
53
+                Log.i(TAG, inObjectInfo.toString());
54
+            }
55
+        }
56
+    }
57
+
58
+    @Override
59
+    public void reset() {
60
+        super.reset();
61
+        inObjectInfo = null;
62
+    }
63
+
64
+    @Override
65
+    public void encodeCommand(ByteBuffer b) {
66
+        encodeCommand(b, PtpConstants.Operation.GetObjectInfo, outObjectHandle);
67
+    }
68
+
69
+    @Override
70
+    protected void decodeData(ByteBuffer b, int length) {
71
+        inObjectInfo = new ObjectInfo(b, length);
72
+    }
73
+}

+ 54 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetStorageIdsCommand.java

@@ -0,0 +1,54 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PacketUtil;
21
+import com.remoteyourcam.usb.ptp.PtpCamera;
22
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
23
+import com.remoteyourcam.usb.ptp.PtpConstants;
24
+
25
+public class GetStorageIdsCommand extends Command {
26
+
27
+    private int[] storageIds;
28
+
29
+    public int[] getStorageIds() {
30
+        if (storageIds == null) {
31
+            return new int[0];
32
+        }
33
+        return storageIds;
34
+    }
35
+
36
+    public GetStorageIdsCommand(PtpCamera camera) {
37
+        super(camera);
38
+    }
39
+
40
+    @Override
41
+    public void exec(IO io) {
42
+        io.handleCommand(this);
43
+    }
44
+
45
+    @Override
46
+    public void encodeCommand(ByteBuffer b) {
47
+        super.encodeCommand(b, PtpConstants.Operation.GetStorageIDs);
48
+    }
49
+
50
+    @Override
51
+    protected void decodeData(ByteBuffer b, int length) {
52
+        storageIds = PacketUtil.readU32Array(b);
53
+    }
54
+}

+ 53 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetStorageInfoCommand.java

@@ -0,0 +1,53 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PtpCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants;
23
+import com.remoteyourcam.usb.ptp.model.StorageInfo;
24
+
25
+public class GetStorageInfoCommand extends Command {
26
+
27
+    private StorageInfo storageInfo;
28
+    private final int storageId;
29
+
30
+    public StorageInfo getStorageInfo() {
31
+        return storageInfo;
32
+    }
33
+
34
+    public GetStorageInfoCommand(PtpCamera camera, int storageId) {
35
+        super(camera);
36
+        this.storageId = storageId;
37
+    }
38
+
39
+    @Override
40
+    public void exec(IO io) {
41
+        io.handleCommand(this);
42
+    }
43
+
44
+    @Override
45
+    public void encodeCommand(ByteBuffer b) {
46
+        super.encodeCommand(b, PtpConstants.Operation.GetStorageInfo, storageId);
47
+    }
48
+
49
+    @Override
50
+    protected void decodeData(ByteBuffer b, int length) {
51
+        storageInfo = new StorageInfo(b, length);
52
+    }
53
+}

+ 72 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetStorageInfosAction.java

@@ -0,0 +1,72 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import com.remoteyourcam.usb.ptp.Camera;
19
+import com.remoteyourcam.usb.ptp.Camera.StorageInfoListener;
20
+import com.remoteyourcam.usb.ptp.PtpAction;
21
+import com.remoteyourcam.usb.ptp.PtpCamera;
22
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
24
+
25
+public class GetStorageInfosAction implements PtpAction {
26
+
27
+    private final PtpCamera camera;
28
+    private final StorageInfoListener listener;
29
+
30
+    public GetStorageInfosAction(PtpCamera camera, Camera.StorageInfoListener listener) {
31
+        this.camera = camera;
32
+        this.listener = listener;
33
+    }
34
+
35
+    @Override
36
+    public void exec(IO io) {
37
+        GetStorageIdsCommand getStorageIds = new GetStorageIdsCommand(camera);
38
+        io.handleCommand(getStorageIds);
39
+
40
+        if (getStorageIds.getResponseCode() != Response.Ok) {
41
+            listener.onAllStoragesFound();
42
+            return;
43
+        }
44
+
45
+        int ids[] = getStorageIds.getStorageIds();
46
+        for (int i = 0; i < ids.length; ++i) {
47
+            int storageId = ids[i];
48
+            if(storageId == 131073){
49
+                GetStorageInfoCommand c = new GetStorageInfoCommand(camera, storageId);
50
+                io.handleCommand(c);
51
+
52
+                if (c.getResponseCode() != Response.Ok) {
53
+                    listener.onAllStoragesFound();
54
+                    return;
55
+                }
56
+
57
+                String label = c.getStorageInfo().volumeLabel.isEmpty() ? c.getStorageInfo().storageDescription : c
58
+                        .getStorageInfo().volumeLabel;
59
+                if (label == null || label.isEmpty()) {
60
+                    label = "Storage " + i;
61
+                }
62
+                listener.onStorageFound(storageId, label);
63
+            }
64
+        }
65
+
66
+        listener.onAllStoragesFound();
67
+    }
68
+
69
+    @Override
70
+    public void reset() {
71
+    }
72
+}

+ 71 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/GetThumb.java

@@ -0,0 +1,71 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import android.graphics.Bitmap;
21
+import android.graphics.BitmapFactory;
22
+import android.util.Log;
23
+
24
+import com.remoteyourcam.usb.ptp.PtpCamera;
25
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
26
+import com.remoteyourcam.usb.ptp.PtpConstants;
27
+
28
+public class GetThumb extends Command {
29
+
30
+    private static final String TAG = GetThumb.class.getSimpleName();
31
+
32
+    private final int objectHandle;
33
+    private Bitmap inBitmap;
34
+
35
+    public GetThumb(PtpCamera camera, int objectHandle) {
36
+        super(camera);
37
+        this.objectHandle = objectHandle;
38
+    }
39
+
40
+    public Bitmap getBitmap() {
41
+        return inBitmap;
42
+    }
43
+
44
+    @Override
45
+    public void exec(IO io) {
46
+        throw new UnsupportedOperationException();
47
+    }
48
+
49
+    @Override
50
+    public void reset() {
51
+        super.reset();
52
+        inBitmap = null;
53
+    }
54
+
55
+    @Override
56
+    public void encodeCommand(ByteBuffer b) {
57
+        encodeCommand(b, PtpConstants.Operation.GetThumb, objectHandle);
58
+    }
59
+
60
+    @Override
61
+    protected void decodeData(ByteBuffer b, int length) {
62
+        try {
63
+            // 12 == offset of data header
64
+            inBitmap = BitmapFactory.decodeByteArray(b.array(), 12, length - 12);
65
+        } catch (RuntimeException e) {
66
+            Log.i(TAG, "exception on decoding picture : " + e.toString());
67
+        } catch (OutOfMemoryError e) {
68
+            System.gc();
69
+        }
70
+    }
71
+}

+ 44 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/InitiateCaptureCommand.java

@@ -0,0 +1,44 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PtpCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
24
+
25
+public class InitiateCaptureCommand extends Command {
26
+
27
+    public InitiateCaptureCommand(PtpCamera camera) {
28
+        super(camera);
29
+    }
30
+
31
+    @Override
32
+    public void exec(IO io) {
33
+        io.handleCommand(this);
34
+        if (responseCode == Response.DeviceBusy) {
35
+            camera.onDeviceBusy(this, true); // TODO when nikon live view is enabled this stalls
36
+            return;
37
+        }
38
+    }
39
+
40
+    @Override
41
+    public void encodeCommand(ByteBuffer b) {
42
+        encodeCommand(b, Operation.InitiateCapture, 0, 0);
43
+    }
44
+}

+ 44 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/InitiateOpenCaptureCommand.java

@@ -0,0 +1,44 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import com.remoteyourcam.usb.ptp.PtpCamera;
19
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
20
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
21
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
22
+
23
+import java.nio.ByteBuffer;
24
+
25
+public class InitiateOpenCaptureCommand extends Command {
26
+
27
+    public InitiateOpenCaptureCommand(PtpCamera camera) {
28
+        super(camera);
29
+    }
30
+
31
+    @Override
32
+    public void exec(IO io) {
33
+        io.handleCommand(this);
34
+        if (responseCode == Response.DeviceBusy) {
35
+            camera.onDeviceBusy(this, true); // TODO when nikon live view is enabled this stalls
36
+            return;
37
+        }
38
+    }
39
+
40
+    @Override
41
+    public void encodeCommand(ByteBuffer b) {
42
+        encodeCommand(b, Operation.InitiateOpenCapture, 0, 0);
43
+    }
44
+}

+ 48 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/OpenSessionCommand.java

@@ -0,0 +1,48 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PtpCamera;
21
+import com.remoteyourcam.usb.ptp.PtpConstants;
22
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
25
+
26
+public class OpenSessionCommand extends Command {
27
+
28
+    public OpenSessionCommand(PtpCamera camera) {
29
+        super(camera);
30
+    }
31
+
32
+    @Override
33
+    public void exec(IO io) {
34
+        io.handleCommand(this);
35
+        if (responseCode == Response.Ok) {
36
+            camera.onSessionOpened();
37
+        } else {
38
+            camera.onPtpError(String.format("Couldn't open session, error code \"%s\"",
39
+                    PtpConstants.responseToString(responseCode)));
40
+        }
41
+    }
42
+
43
+    @Override
44
+    public void encodeCommand(ByteBuffer b) {
45
+        camera.resetTransactionId();
46
+        encodeCommand(b, Operation.OpenSession, 1);
47
+    }
48
+}

+ 51 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/RetrieveAddedObjectInfoAction.java

@@ -0,0 +1,51 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import com.remoteyourcam.usb.ptp.PtpAction;
19
+import com.remoteyourcam.usb.ptp.PtpCamera;
20
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
21
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
22
+
23
+public class RetrieveAddedObjectInfoAction implements PtpAction {
24
+
25
+    private final PtpCamera camera;
26
+    private final int objectHandle;
27
+
28
+    public RetrieveAddedObjectInfoAction(PtpCamera camera, int objectHandle) {
29
+        this.camera = camera;
30
+        this.objectHandle = objectHandle;
31
+    }
32
+
33
+    @Override
34
+    public void exec(IO io) {
35
+        GetObjectInfoCommand getInfo = new GetObjectInfoCommand(camera, objectHandle);
36
+        io.handleCommand(getInfo);
37
+
38
+        if (getInfo.getResponseCode() != Response.Ok) {
39
+            return;
40
+        }
41
+        if (getInfo.getObjectInfo() == null) {
42
+            return;
43
+        }
44
+
45
+        camera.onEventObjectAdded(objectHandle);
46
+    }
47
+
48
+    @Override
49
+    public void reset() {
50
+    }
51
+}

+ 54 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/RetrieveImageAction.java

@@ -0,0 +1,54 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import com.remoteyourcam.usb.ptp.Camera.RetrieveImageListener;
19
+import com.remoteyourcam.usb.ptp.PtpAction;
20
+import com.remoteyourcam.usb.ptp.PtpCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
23
+
24
+public class RetrieveImageAction implements PtpAction {
25
+
26
+    private final PtpCamera camera;
27
+    private final int objectHandle;
28
+    private final RetrieveImageListener listener;
29
+    private final int sampleSize;
30
+
31
+    public RetrieveImageAction(PtpCamera camera, RetrieveImageListener listener, int objectHandle, int sampleSize) {
32
+        this.camera = camera;
33
+        this.listener = listener;
34
+        this.objectHandle = objectHandle;
35
+        this.sampleSize = sampleSize;
36
+    }
37
+
38
+    @Override
39
+    public void exec(IO io) {
40
+        GetObjectCommand getObject = new GetObjectCommand(camera, objectHandle, sampleSize);
41
+        io.handleCommand(getObject);
42
+
43
+        if (getObject.getResponseCode() != Response.Ok || getObject.getBitmap() == null) {
44
+            listener.onImageRetrieved(0, null);
45
+            return;
46
+        }
47
+
48
+        listener.onImageRetrieved(objectHandle, getObject.getBitmap());
49
+    }
50
+
51
+    @Override
52
+    public void reset() {
53
+    }
54
+}

+ 70 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/RetrieveImageInfoAction.java

@@ -0,0 +1,70 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import android.graphics.Bitmap;
19
+
20
+import com.remoteyourcam.usb.ptp.Camera.RetrieveImageInfoListener;
21
+import com.remoteyourcam.usb.ptp.PtpAction;
22
+import com.remoteyourcam.usb.ptp.PtpCamera;
23
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
24
+import com.remoteyourcam.usb.ptp.PtpConstants;
25
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
26
+import com.remoteyourcam.usb.ptp.model.ObjectInfo;
27
+
28
+public class RetrieveImageInfoAction implements PtpAction {
29
+
30
+    private final PtpCamera camera;
31
+    private final int objectHandle;
32
+    private final RetrieveImageInfoListener listener;
33
+
34
+    public RetrieveImageInfoAction(PtpCamera camera, RetrieveImageInfoListener listener, int objectHandle) {
35
+        this.camera = camera;
36
+        this.listener = listener;
37
+        this.objectHandle = objectHandle;
38
+    }
39
+
40
+    @Override
41
+    public void exec(IO io) {
42
+        GetObjectInfoCommand getInfo = new GetObjectInfoCommand(camera, objectHandle);
43
+        io.handleCommand(getInfo);
44
+
45
+        if (getInfo.getResponseCode() != Response.Ok) {
46
+            return;
47
+        }
48
+
49
+        ObjectInfo objectInfo = getInfo.getObjectInfo();
50
+        if (objectInfo == null) {
51
+            return;
52
+        }
53
+
54
+        Bitmap thumbnail = null;
55
+        if (objectInfo.thumbFormat == PtpConstants.ObjectFormat.JFIF
56
+                || objectInfo.thumbFormat == PtpConstants.ObjectFormat.EXIF_JPEG) {
57
+            GetThumb getThumb = new GetThumb(camera, objectHandle);
58
+            io.handleCommand(getThumb);
59
+            if (getThumb.getResponseCode() == Response.Ok) {
60
+                thumbnail = getThumb.getBitmap();
61
+            }
62
+        }
63
+
64
+        listener.onImageInfoRetrieved(objectHandle, getInfo.getObjectInfo(), thumbnail);
65
+    }
66
+
67
+    @Override
68
+    public void reset() {
69
+    }
70
+}

+ 86 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/RetrievePictureAction.java

@@ -0,0 +1,86 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import android.graphics.Bitmap;
19
+
20
+import com.remoteyourcam.usb.ptp.PtpAction;
21
+import com.remoteyourcam.usb.ptp.PtpCamera;
22
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
23
+import com.remoteyourcam.usb.ptp.PtpConstants;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
25
+import com.remoteyourcam.usb.ptp.model.ObjectInfo;
26
+
27
+public class RetrievePictureAction implements PtpAction {
28
+
29
+    private final PtpCamera camera;
30
+    private final int objectHandle;
31
+    private final int sampleSize;
32
+
33
+    public RetrievePictureAction(PtpCamera camera, int objectHandle, int sampleSize) {
34
+        this.camera = camera;
35
+        this.objectHandle = objectHandle;
36
+        this.sampleSize = sampleSize;
37
+    }
38
+
39
+    @Override
40
+    public void exec(IO io) {
41
+        GetObjectInfoCommand getInfo = new GetObjectInfoCommand(camera, objectHandle);
42
+        io.handleCommand(getInfo);
43
+
44
+        if (getInfo.getResponseCode() != Response.Ok) {
45
+            return;
46
+        }
47
+
48
+        ObjectInfo objectInfo = getInfo.getObjectInfo();
49
+        if (objectInfo == null) {
50
+            return;
51
+        }
52
+
53
+        Bitmap thumbnail = null;
54
+        if (objectInfo.thumbFormat == PtpConstants.ObjectFormat.JFIF
55
+                || objectInfo.thumbFormat == PtpConstants.ObjectFormat.EXIF_JPEG) {
56
+            GetThumb getThumb = new GetThumb(camera, objectHandle);
57
+            io.handleCommand(getThumb);
58
+            if (getThumb.getResponseCode() == Response.Ok) {
59
+                thumbnail = getThumb.getBitmap();
60
+            }
61
+        }
62
+
63
+        GetObjectCommand getObject = new GetObjectCommand(camera, objectHandle, sampleSize);
64
+        io.handleCommand(getObject);
65
+
66
+        if (getObject.getResponseCode() != Response.Ok) {
67
+            return;
68
+        }
69
+        if (getObject.getBitmap() == null) {
70
+            if (getObject.isOutOfMemoryError()) {
71
+                camera.onPictureReceived(objectHandle, getInfo.getObjectInfo().filename, thumbnail, null);
72
+            }
73
+            return;
74
+        }
75
+
76
+        if (thumbnail == null) {
77
+            // TODO resize real picture?
78
+        }
79
+
80
+        camera.onPictureReceived(objectHandle, getInfo.getObjectInfo().filename, thumbnail, getObject.getBitmap());
81
+    }
82
+
83
+    @Override
84
+    public void reset() {
85
+    }
86
+}

+ 76 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/SetDevicePropValueCommand.java

@@ -0,0 +1,76 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PtpCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Datatype;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
25
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
26
+import com.remoteyourcam.usb.ptp.PtpConstants.Type;
27
+
28
+public class SetDevicePropValueCommand extends Command {
29
+
30
+    private final int property;
31
+    private final int value;
32
+    private final int datatype;
33
+
34
+    public SetDevicePropValueCommand(PtpCamera camera, int property, int value, int datatype) {
35
+        super(camera);
36
+        this.property = property;
37
+        this.value = value;
38
+        this.datatype = datatype;
39
+        hasDataToSend = true;
40
+    }
41
+
42
+    @Override
43
+    public void exec(IO io) {
44
+        io.handleCommand(this);
45
+        if (responseCode == Response.DeviceBusy) {
46
+            camera.onDeviceBusy(this, true);
47
+            return;
48
+        } else if (responseCode == Response.Ok) {
49
+            camera.onPropertyChanged(property, value);
50
+        }
51
+    }
52
+
53
+    @Override
54
+    public void encodeCommand(ByteBuffer b) {
55
+        encodeCommand(b, Operation.SetDevicePropValue, property);
56
+    }
57
+
58
+    @Override
59
+    public void encodeData(ByteBuffer b) {
60
+        // header
61
+        b.putInt(12 + PtpConstants.getDatatypeSize(datatype));
62
+        b.putShort((short) Type.Data);
63
+        b.putShort((short) Operation.SetDevicePropValue);
64
+        b.putInt(camera.currentTransactionId());
65
+        // specific block
66
+        if (datatype == Datatype.int8 || datatype == Datatype.uint8) {
67
+            b.put((byte) value);
68
+        } else if (datatype == Datatype.int16 || datatype == Datatype.uint16) {
69
+            b.putShort((short) value);
70
+        } else if (datatype == Datatype.int32 || datatype == Datatype.uint32) {
71
+            b.putInt(value);
72
+        } else {
73
+            throw new UnsupportedOperationException();
74
+        }
75
+    }
76
+}

+ 70 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/SimpleCommand.java

@@ -0,0 +1,70 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PtpCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
23
+
24
+public class SimpleCommand extends Command {
25
+
26
+    private final int operation;
27
+    private int numParams;
28
+    private int p0;
29
+    private int p1;
30
+
31
+    public SimpleCommand(PtpCamera camera, int operation) {
32
+        super(camera);
33
+        this.operation = operation;
34
+    }
35
+
36
+    public SimpleCommand(PtpCamera camera, int operation, int p0) {
37
+        super(camera);
38
+        this.operation = operation;
39
+        this.p0 = p0;
40
+        this.numParams = 1;
41
+    }
42
+
43
+    public SimpleCommand(PtpCamera camera, int operation, int p0, int p1) {
44
+        super(camera);
45
+        this.operation = operation;
46
+        this.p0 = p0;
47
+        this.p1 = p1;
48
+        this.numParams = 2;
49
+    }
50
+
51
+    @Override
52
+    public void exec(IO io) {
53
+        io.handleCommand(this);
54
+        if (responseCode == Response.DeviceBusy) {
55
+            camera.onDeviceBusy(this, true);
56
+            return;
57
+        }
58
+    }
59
+
60
+    @Override
61
+    public void encodeCommand(ByteBuffer b) {
62
+        if (numParams == 2) {
63
+            encodeCommand(b, operation, p0, p1);
64
+        } else if (numParams == 1) {
65
+            encodeCommand(b, operation, p0);
66
+        } else {
67
+            encodeCommand(b, operation);
68
+        }
69
+    }
70
+}

+ 29 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/eos/EosCommand.java

@@ -0,0 +1,29 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.eos;
17
+
18
+import com.remoteyourcam.usb.ptp.EosCamera;
19
+import com.remoteyourcam.usb.ptp.commands.Command;
20
+
21
+public abstract class EosCommand extends Command {
22
+
23
+    protected EosCamera camera;
24
+
25
+    public EosCommand(EosCamera camera) {
26
+        super(camera);
27
+        this.camera = camera;
28
+    }
29
+}

+ 184 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/eos/EosEventCheckCommand.java

@@ -0,0 +1,184 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.eos;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import android.util.Log;
21
+
22
+import com.remoteyourcam.usb.AppConfig;
23
+import com.remoteyourcam.usb.ptp.EosCamera;
24
+import com.remoteyourcam.usb.ptp.PacketUtil;
25
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
26
+import com.remoteyourcam.usb.ptp.PtpConstants;
27
+import com.remoteyourcam.usb.ptp.PtpConstants.Event;
28
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
29
+import com.remoteyourcam.usb.ptp.PtpConstants.Property;
30
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
31
+
32
+public class EosEventCheckCommand extends EosCommand {
33
+
34
+    private static final String TAG = EosEventCheckCommand.class.getSimpleName();
35
+
36
+    public EosEventCheckCommand(EosCamera camera) {
37
+        super(camera);
38
+    }
39
+
40
+    @Override
41
+    public void exec(IO io) {
42
+        io.handleCommand(this);
43
+        if (responseCode == Response.DeviceBusy) {
44
+            camera.onDeviceBusy(this, false);
45
+        }
46
+    }
47
+
48
+    @Override
49
+    public void encodeCommand(ByteBuffer b) {
50
+        encodeCommand(b, Operation.EosEventCheck);
51
+    }
52
+
53
+    @Override
54
+    protected void decodeData(ByteBuffer b, int length) {
55
+        while (b.position() < length) {
56
+            int eventLength = b.getInt();
57
+            int event = b.getInt();
58
+            if (AppConfig.LOG) {
59
+                Log.i(TAG, "event length " + eventLength);
60
+                Log.i(TAG, "event type " + PtpConstants.eventToString(event));
61
+            }
62
+            switch (event) {
63
+            case Event.EosObjectAdded: {
64
+                int objectHandle = b.getInt();
65
+                int storageId = b.getInt();
66
+                int objectFormat = b.getShort();
67
+                skip(b, eventLength - 18);
68
+                camera.onEventDirItemCreated(objectHandle, storageId, objectFormat, "TODO");
69
+                break;
70
+            }
71
+            case Event.EosDevicePropChanged: {
72
+                int property = b.getInt();
73
+                if (AppConfig.LOG) {
74
+                    Log.i(TAG, "property " + PtpConstants.propertyToString(property));
75
+                }
76
+                switch (property) {
77
+                case Property.EosApertureValue:
78
+                case Property.EosShutterSpeed:
79
+                case Property.EosIsoSpeed:
80
+                case Property.EosWhitebalance:
81
+                case Property.EosEvfOutputDevice:
82
+                case Property.EosShootingMode:
83
+                case Property.EosAvailableShots:
84
+                case Property.EosColorTemperature:
85
+                case Property.EosAfMode:
86
+                case Property.EosMeteringMode:
87
+                case Property.EosExposureCompensation:
88
+                case Property.EosPictureStyle:
89
+                case Property.EosEvfMode: {
90
+                    int value = b.getInt();
91
+                    if (AppConfig.LOG) {
92
+                        Log.i(TAG, "value " + value);
93
+                    }
94
+                    camera.onPropertyChanged(property, value);
95
+                    break;
96
+                }
97
+                default:
98
+                    if (AppConfig.LOG && eventLength <= 200) {
99
+                        PacketUtil.logHexdump(TAG, b.array(), b.position(), eventLength - 12);
100
+                    }
101
+                    skip(b, eventLength - 12);
102
+                    break;
103
+                }
104
+                break;
105
+            }
106
+            case Event.EosDevicePropDescChanged: {
107
+                int property = b.getInt();
108
+                if (AppConfig.LOG) {
109
+                    Log.i(TAG, "property " + PtpConstants.propertyToString(property));
110
+                }
111
+                switch (property) {
112
+                case Property.EosApertureValue:
113
+                case Property.EosShutterSpeed:
114
+                case Property.EosIsoSpeed:
115
+                case Property.EosMeteringMode:
116
+                case Property.EosPictureStyle:
117
+                case Property.EosExposureCompensation:
118
+                case Property.EosColorTemperature:
119
+                case Property.EosWhitebalance: {
120
+                    /* int dataType = */b.getInt();
121
+                    int num = b.getInt();
122
+                    if (AppConfig.LOG) {
123
+                        Log.i(TAG, "property desc with num " + num);
124
+                    }
125
+                    if (eventLength != 20 + 4 * num) {
126
+                        if (AppConfig.LOG) {
127
+                            Log.i(TAG, String.format("Event Desc length invalid should be %d but is %d", 20 + 4 * num,
128
+                                    eventLength));
129
+                            PacketUtil.logHexdump(TAG, b.array(), b.position() - 20, eventLength);
130
+                        }
131
+                    }
132
+                    int[] values = new int[num];
133
+                    for (int i = 0; i < num; ++i) {
134
+                        values[i] = b.getInt();
135
+                    }
136
+                    if (eventLength != 20 + 4 * num) {
137
+                        for (int i = 20 + 4 * num; i < eventLength; ++i) {
138
+                            b.get();
139
+                        }
140
+                    }
141
+                    camera.onPropertyDescChanged(property, values);
142
+                    break;
143
+                }
144
+                default:
145
+                    if (AppConfig.LOG && eventLength <= 50) {
146
+                        PacketUtil.logHexdump(TAG, b.array(), b.position(), eventLength - 12);
147
+                    }
148
+                    skip(b, eventLength - 12);
149
+                }
150
+                break;
151
+            }
152
+            case Event.EosBulbExposureTime: {
153
+                int seconds = b.getInt();
154
+                camera.onBulbExposureTime(seconds);
155
+                break;
156
+            }
157
+            case Event.EosCameraStatus: {
158
+                // 0 - capture stopped
159
+                // 1 - capture started
160
+                int status = b.getInt();
161
+                camera.onEventCameraCapture(status != 0);
162
+                break;
163
+            }
164
+            case Event.EosWillSoonShutdown: {
165
+                /* int seconds = */b.getInt();
166
+                //TODO
167
+                break;
168
+            }
169
+            default:
170
+                //                if (BuildConfig.LOG) {
171
+                //                    PacketUtil.logHexdump(b.array(), b.position(), eventLength - 8);
172
+                //                }
173
+                skip(b, eventLength - 8);
174
+                break;
175
+            }
176
+        }
177
+    }
178
+
179
+    private void skip(ByteBuffer b, int length) {
180
+        for (int i = 0; i < length; ++i) {
181
+            b.get();
182
+        }
183
+    }
184
+}

+ 153 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/eos/EosGetLiveViewPictureCommand.java

@@ -0,0 +1,153 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.eos;
17
+
18
+import java.nio.ByteBuffer;
19
+import java.nio.ByteOrder;
20
+
21
+import android.graphics.BitmapFactory;
22
+import android.graphics.BitmapFactory.Options;
23
+import android.util.Log;
24
+
25
+import com.remoteyourcam.usb.AppConfig;
26
+import com.remoteyourcam.usb.ptp.EosCamera;
27
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
28
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
29
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
30
+import com.remoteyourcam.usb.ptp.model.LiveViewData;
31
+
32
+public class EosGetLiveViewPictureCommand extends EosCommand {
33
+
34
+    private static final String TAG = EosGetLiveViewPictureCommand.class.getSimpleName();
35
+    private static byte[] tmpStorage = new byte[0x4000];
36
+    private final Options options;
37
+    private LiveViewData data;
38
+
39
+    public EosGetLiveViewPictureCommand(EosCamera camera, LiveViewData data) {
40
+        super(camera);
41
+        if (data == null) {
42
+            this.data = new LiveViewData();
43
+            this.data.histogram = ByteBuffer.allocate(1024 * 4);
44
+            this.data.histogram.order(ByteOrder.LITTLE_ENDIAN);
45
+        } else {
46
+            this.data = data;
47
+        }
48
+        options = new BitmapFactory.Options();
49
+        options.inBitmap = this.data.bitmap;
50
+        options.inSampleSize = 1;
51
+        options.inTempStorage = tmpStorage;
52
+        this.data.bitmap = null;
53
+    }
54
+
55
+    @Override
56
+    public void exec(IO io) {
57
+        io.handleCommand(this);
58
+        if (responseCode == Response.DeviceBusy) {
59
+            camera.onDeviceBusy(this, true);
60
+            return;
61
+        }
62
+        if (this.data.bitmap != null && responseCode == Response.Ok) {
63
+            camera.onLiveViewReceived(data);
64
+        } else {
65
+            camera.onLiveViewReceived(null);
66
+        }
67
+    }
68
+
69
+    @Override
70
+    public void encodeCommand(ByteBuffer b) {
71
+        encodeCommand(b, Operation.EosGetLiveViewPicture, 0x100000);
72
+    }
73
+
74
+    @Override
75
+    protected void decodeData(ByteBuffer b, int length) {
76
+
77
+        data.hasHistogram = false;
78
+        data.hasAfFrame = false;
79
+
80
+        if (length < 1000) {
81
+            if (AppConfig.LOG) {
82
+                Log.w(TAG, String.format("liveview data size too small %d", length));
83
+            }
84
+            return;
85
+        }
86
+
87
+        try {
88
+
89
+            while (b.hasRemaining()) {
90
+                int subLength = b.getInt();
91
+                int type = b.getInt();
92
+
93
+                if (subLength < 8) {
94
+                    throw new RuntimeException("Invalid sub size " + subLength);
95
+                }
96
+
97
+                int unknownInt = 0;
98
+
99
+                switch (type) {
100
+                case 0x01:
101
+                    data.bitmap = BitmapFactory.decodeByteArray(b.array(), b.position(), subLength - 8, options);
102
+                    b.position(b.position() + subLength - 8);
103
+                    break;
104
+                case 0x04:
105
+                    data.zoomFactor = b.getInt();
106
+                    break;
107
+                case 0x05:
108
+                    // zoomfocusx, zoomfocusy
109
+                    data.zoomRectRight = b.getInt();
110
+                    data.zoomRectBottom = b.getInt();
111
+                    if (AppConfig.LOG) {
112
+                        Log.i(TAG, "header 5 " + data.zoomRectRight + " " + data.zoomRectBottom);
113
+                    }
114
+                    break;
115
+                case 0x06:
116
+                    // imagex, imagey (if zoomed should be non zero)
117
+                    data.zoomRectLeft = b.getInt();
118
+                    data.zoomRectTop = b.getInt();
119
+                    if (AppConfig.LOG) {
120
+                        Log.i(TAG, "header 6 " + data.zoomRectLeft + " " + data.zoomRectTop);
121
+                    }
122
+                    break;
123
+                case 0x07:
124
+                    unknownInt = b.getInt();
125
+                    if (AppConfig.LOG) {
126
+                        Log.i(TAG, "header 7 " + unknownInt + " " + subLength);
127
+                    }
128
+                    break;
129
+                case 0x03:
130
+                    data.hasHistogram = true;
131
+                    b.get(data.histogram.array(), 0, 1024 * 4);
132
+                    break;
133
+                case 0x08: // faces if faces focus
134
+                case 0x0e: // TODO original width, original height
135
+                default:
136
+                    b.position(b.position() + subLength - 8);
137
+                    if (AppConfig.LOG) {
138
+                        Log.i(TAG, "unknown header " + type + " size " + subLength);
139
+                    }
140
+                    break;
141
+                }
142
+
143
+                if (length - b.position() < 8) {
144
+                    break;
145
+                }
146
+            }
147
+
148
+        } catch (RuntimeException e) {
149
+            Log.e(TAG, "" + e.toString());
150
+            Log.e(TAG, "" + e.getLocalizedMessage());
151
+        }
152
+    }
153
+}

+ 65 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/eos/EosOpenSessionAction.java

@@ -0,0 +1,65 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.eos;
17
+
18
+import com.remoteyourcam.usb.ptp.EosCamera;
19
+import com.remoteyourcam.usb.ptp.PtpAction;
20
+import com.remoteyourcam.usb.ptp.PtpConstants;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.commands.OpenSessionCommand;
23
+
24
+public class EosOpenSessionAction implements PtpAction {
25
+
26
+    private final EosCamera camera;
27
+
28
+    public EosOpenSessionAction(EosCamera camera) {
29
+        this.camera = camera;
30
+    }
31
+
32
+    @Override
33
+    public void exec(IO io) {
34
+        OpenSessionCommand openSession = new OpenSessionCommand(camera);
35
+        io.handleCommand(openSession);
36
+        if (openSession.getResponseCode() == PtpConstants.Response.Ok) {
37
+            EosSetPcModeCommand setPcMode = new EosSetPcModeCommand(camera);
38
+            io.handleCommand(setPcMode);
39
+            if (setPcMode.getResponseCode() == PtpConstants.Response.Ok) {
40
+                EosSetExtendedEventInfoCommand c = new EosSetExtendedEventInfoCommand(camera);
41
+                io.handleCommand(c);
42
+                if (c.getResponseCode() == PtpConstants.Response.Ok) {
43
+                    camera.onSessionOpened();
44
+                    return;
45
+                } else {
46
+                    camera.onPtpError(String.format(
47
+                            "Couldn't open session! Setting extended event info failed with error code \"%s\"",
48
+                            PtpConstants.responseToString(c.getResponseCode())));
49
+                }
50
+            } else {
51
+                camera.onPtpError(String.format(
52
+                        "Couldn't open session! Setting PcMode property failed with error code \"%s\"",
53
+                        PtpConstants.responseToString(setPcMode.getResponseCode())));
54
+            }
55
+        } else {
56
+            camera.onPtpError(String.format(
57
+                    "Couldn't open session! Open session command failed with error code \"%s\"",
58
+                    PtpConstants.responseToString(openSession.getResponseCode())));
59
+        }
60
+    }
61
+
62
+    @Override
63
+    public void reset() {
64
+    }
65
+}

+ 46 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/eos/EosSetExtendedEventInfoCommand.java

@@ -0,0 +1,46 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.eos;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.EosCamera;
21
+import com.remoteyourcam.usb.ptp.PtpConstants;
22
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
25
+
26
+public class EosSetExtendedEventInfoCommand extends EosCommand {
27
+
28
+    public EosSetExtendedEventInfoCommand(EosCamera camera) {
29
+        super(camera);
30
+    }
31
+
32
+    @Override
33
+    public void exec(IO io) {
34
+        io.handleCommand(this);
35
+        if (responseCode != Response.Ok) {
36
+            camera.onPtpError(String.format(
37
+                    "Couldn't initialize session! Setting extended event info failed, error code %s",
38
+                    PtpConstants.responseToString(responseCode)));
39
+        }
40
+    }
41
+
42
+    @Override
43
+    public void encodeCommand(ByteBuffer b) {
44
+        encodeCommand(b, Operation.EosSetEventMode, 1);
45
+    }
46
+}

+ 84 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/eos/EosSetLiveViewAction.java

@@ -0,0 +1,84 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.eos;
17
+
18
+import com.remoteyourcam.usb.ptp.EosCamera;
19
+import com.remoteyourcam.usb.ptp.EosConstants;
20
+import com.remoteyourcam.usb.ptp.PtpAction;
21
+import com.remoteyourcam.usb.ptp.EosConstants.EvfMode;
22
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Property;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
25
+
26
+public class EosSetLiveViewAction implements PtpAction {
27
+
28
+    private final EosCamera camera;
29
+    private final boolean enabled;
30
+
31
+    public EosSetLiveViewAction(EosCamera camera, boolean enabled) {
32
+        this.camera = camera;
33
+        this.enabled = enabled;
34
+    }
35
+
36
+    @Override
37
+    public void exec(IO io) {
38
+        int evfMode = camera.getPtpProperty(Property.EosEvfMode);
39
+
40
+        if (enabled && evfMode != EvfMode.ENABLE || !enabled && evfMode != EvfMode.DISABLE) {
41
+            EosSetPropertyCommand setEvfMode = new EosSetPropertyCommand(camera, Property.EosEvfMode,
42
+                    enabled ? EvfMode.ENABLE : EvfMode.DISABLE);
43
+            io.handleCommand(setEvfMode);
44
+
45
+            if (setEvfMode.getResponseCode() == Response.DeviceBusy) {
46
+                camera.onDeviceBusy(this, true);
47
+                return;
48
+            } else if (setEvfMode.getResponseCode() != Response.Ok) {
49
+                camera.onPtpWarning("Couldn't open live view");
50
+                return;
51
+            }
52
+        }
53
+
54
+        int outputDevice = camera.getPtpProperty(Property.EosEvfOutputDevice);
55
+
56
+        if (enabled) {
57
+            outputDevice |= EosConstants.EvfOutputDevice.PC;
58
+        } else {
59
+            outputDevice &= ~EosConstants.EvfOutputDevice.PC;
60
+        }
61
+
62
+        EosSetPropertyCommand setOutputDevice = new EosSetPropertyCommand(camera, Property.EosEvfOutputDevice,
63
+                outputDevice);
64
+        io.handleCommand(setOutputDevice);
65
+
66
+        if (setOutputDevice.getResponseCode() == Response.DeviceBusy) {
67
+            camera.onDeviceBusy(this, true);
68
+        } else if (setOutputDevice.getResponseCode() == Response.Ok) {
69
+            if (!enabled) {
70
+                camera.onLiveViewStopped();
71
+            } else {
72
+                camera.onLiveViewStarted();
73
+            }
74
+            return;
75
+        } else {
76
+            camera.onPtpWarning("Couldn't open live view");
77
+        }
78
+
79
+    }
80
+
81
+    @Override
82
+    public void reset() {
83
+    }
84
+}

+ 45 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/eos/EosSetPcModeCommand.java

@@ -0,0 +1,45 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.eos;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.EosCamera;
21
+import com.remoteyourcam.usb.ptp.PtpConstants;
22
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
25
+
26
+public class EosSetPcModeCommand extends EosCommand {
27
+
28
+    public EosSetPcModeCommand(EosCamera camera) {
29
+        super(camera);
30
+    }
31
+
32
+    @Override
33
+    public void exec(IO io) {
34
+        io.handleCommand(this);
35
+        if (responseCode != Response.Ok) {
36
+            camera.onPtpError(String.format("Couldn't initialize session! setting PC Mode failed, error code %s",
37
+                    PtpConstants.responseToString(responseCode)));
38
+        }
39
+    }
40
+
41
+    @Override
42
+    public void encodeCommand(ByteBuffer b) {
43
+        encodeCommand(b, Operation.EosSetPCConnectMode, 1);
44
+    }
45
+}

+ 64 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/eos/EosSetPropertyCommand.java

@@ -0,0 +1,64 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.eos;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.EosCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Type;
25
+
26
+public class EosSetPropertyCommand extends EosCommand {
27
+
28
+    private final int property;
29
+    private final int value;
30
+
31
+    public EosSetPropertyCommand(EosCamera camera, int property, int value) {
32
+        super(camera);
33
+        hasDataToSend = true;
34
+        this.property = property;
35
+        this.value = value;
36
+    }
37
+
38
+    @Override
39
+    public void exec(IO io) {
40
+        io.handleCommand(this);
41
+        if (responseCode == Response.DeviceBusy) {
42
+            camera.onDeviceBusy(this, true);
43
+            return;
44
+        }
45
+    }
46
+
47
+    @Override
48
+    public void encodeCommand(ByteBuffer b) {
49
+        encodeCommand(b, Operation.EosSetDevicePropValue);
50
+    }
51
+
52
+    @Override
53
+    public void encodeData(ByteBuffer b) {
54
+        // header
55
+        b.putInt(24);
56
+        b.putShort((short) Type.Data);
57
+        b.putShort((short) Operation.EosSetDevicePropValue);
58
+        b.putInt(camera.currentTransactionId());
59
+        // specific block
60
+        b.putInt(0x0C);
61
+        b.putInt(property);
62
+        b.putInt(value);
63
+    }
64
+}

+ 43 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/eos/EosTakePictureCommand.java

@@ -0,0 +1,43 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.eos;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.EosCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
24
+
25
+public class EosTakePictureCommand extends EosCommand {
26
+
27
+    public EosTakePictureCommand(EosCamera camera) {
28
+        super(camera);
29
+    }
30
+
31
+    @Override
32
+    public void exec(IO io) {
33
+        io.handleCommand(this);
34
+        if (responseCode == Response.DeviceBusy) {
35
+            camera.onDeviceBusy(this, true);
36
+        }
37
+    }
38
+
39
+    @Override
40
+    public void encodeCommand(ByteBuffer b) {
41
+        encodeCommand(b, Operation.EosTakePicture);
42
+    }
43
+}

+ 47 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonAfDriveCommand.java

@@ -0,0 +1,47 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.NikonCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
24
+
25
+public class NikonAfDriveCommand extends NikonCommand {
26
+
27
+    public NikonAfDriveCommand(NikonCamera camera) {
28
+        super(camera);
29
+    }
30
+
31
+    @Override
32
+    public void exec(IO io) {
33
+        //        if (camera.isInActivationTypePhase()) {
34
+        //            return;
35
+        //        }
36
+        io.handleCommand(this);
37
+        if (getResponseCode() == Response.Ok) {
38
+            camera.onFocusStarted();
39
+            camera.enqueue(new NikonAfDriveDeviceReadyCommand(camera), 200);
40
+        }
41
+    }
42
+
43
+    @Override
44
+    public void encodeCommand(ByteBuffer b) {
45
+        encodeCommand(b, Operation.NikonAfDrive);
46
+    }
47
+}

+ 46 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonAfDriveDeviceReadyCommand.java

@@ -0,0 +1,46 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.NikonCamera;
21
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
24
+
25
+public class NikonAfDriveDeviceReadyCommand extends NikonCommand {
26
+
27
+    public NikonAfDriveDeviceReadyCommand(NikonCamera camera) {
28
+        super(camera);
29
+    }
30
+
31
+    @Override
32
+    public void exec(IO io) {
33
+        io.handleCommand(this);
34
+        if (getResponseCode() == Response.DeviceBusy) {
35
+            reset();
36
+            camera.enqueue(this, 200);
37
+        } else {
38
+            camera.onFocusEnded(getResponseCode() == Response.Ok);
39
+        }
40
+    }
41
+
42
+    @Override
43
+    public void encodeCommand(ByteBuffer b) {
44
+        encodeCommand(b, Operation.NikonDeviceReady);
45
+    }
46
+}

+ 54 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonCloseSessionAction.java

@@ -0,0 +1,54 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import com.remoteyourcam.usb.ptp.NikonCamera;
19
+import com.remoteyourcam.usb.ptp.PtpAction;
20
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
21
+import com.remoteyourcam.usb.ptp.PtpConstants.Datatype;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Property;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
24
+import com.remoteyourcam.usb.ptp.commands.CloseSessionCommand;
25
+import com.remoteyourcam.usb.ptp.commands.SetDevicePropValueCommand;
26
+
27
+public class NikonCloseSessionAction implements PtpAction {
28
+
29
+    private final NikonCamera camera;
30
+
31
+    public NikonCloseSessionAction(NikonCamera camera) {
32
+        this.camera = camera;
33
+    }
34
+
35
+    @Override
36
+    public void exec(IO io) {
37
+        SetDevicePropValueCommand setRecordingMedia = new SetDevicePropValueCommand(camera,
38
+                Property.NikonRecordingMedia, 0,
39
+                Datatype.uint8);
40
+        io.handleCommand(setRecordingMedia);
41
+
42
+        if (setRecordingMedia.getResponseCode() == Response.DeviceBusy) {
43
+            camera.onDeviceBusy(this, true);
44
+            return;
45
+        }
46
+
47
+        io.handleCommand(new CloseSessionCommand(camera));
48
+        camera.onSessionClosed();
49
+    }
50
+
51
+    @Override
52
+    public void reset() {
53
+    }
54
+}

+ 29 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonCommand.java

@@ -0,0 +1,29 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import com.remoteyourcam.usb.ptp.NikonCamera;
19
+import com.remoteyourcam.usb.ptp.commands.Command;
20
+
21
+public abstract class NikonCommand extends Command {
22
+
23
+    protected NikonCamera camera;
24
+
25
+    public NikonCommand(NikonCamera camera) {
26
+        super(camera);
27
+        this.camera = camera;
28
+    }
29
+}

+ 81 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonEventCheckCommand.java

@@ -0,0 +1,81 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import android.util.Log;
21
+
22
+import com.remoteyourcam.usb.AppConfig;
23
+import com.remoteyourcam.usb.ptp.NikonCamera;
24
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
25
+import com.remoteyourcam.usb.ptp.PtpConstants;
26
+import com.remoteyourcam.usb.ptp.PtpConstants.Event;
27
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
28
+
29
+public class NikonEventCheckCommand extends NikonCommand {
30
+
31
+    private static final String TAG = NikonEventCheckCommand.class.getSimpleName();
32
+
33
+    public NikonEventCheckCommand(NikonCamera camera) {
34
+        super(camera);
35
+    }
36
+
37
+    @Override
38
+    public void exec(IO io) {
39
+        io.handleCommand(this);
40
+    }
41
+
42
+    @Override
43
+    public void encodeCommand(ByteBuffer b) {
44
+        encodeCommand(b, Operation.NikonGetEvent);
45
+    }
46
+
47
+    @Override
48
+    protected void decodeData(ByteBuffer b, int length) {
49
+        int count = b.getShort();
50
+
51
+        while (count > 0) {
52
+            --count;
53
+
54
+            int eventCode = b.getShort();
55
+            int eventParam = b.getInt();
56
+
57
+            if (AppConfig.LOG) {
58
+                Log.i(TAG,
59
+                        String.format("event %s value %s(%04x)", PtpConstants.eventToString(eventCode),
60
+                                PtpConstants.propertyToString(eventParam), eventParam));
61
+            }
62
+
63
+            switch (eventCode) {
64
+            case Event.ObjectAdded:
65
+                camera.onEventObjectAdded(eventParam);
66
+                break;
67
+            case Event.DevicePropChanged:
68
+                camera.onEventDevicePropChanged(eventParam);
69
+                break;
70
+            case Event.CaptureComplete:
71
+                camera.onEventCaptureComplete();
72
+                break;
73
+            case Event.NikonObjectAddedInSdram:
74
+                //libgphoto2 相关处理
75
+                if (eventParam == 0) { eventParam = 0xffff001; }
76
+                camera.onEventObjectAdded(eventParam);
77
+                break;
78
+            }
79
+        }
80
+    }
81
+}

+ 70 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonGetLiveViewImageAction.java

@@ -0,0 +1,70 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import com.remoteyourcam.usb.ptp.NikonCamera;
19
+import com.remoteyourcam.usb.ptp.PtpAction;
20
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
21
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
23
+import com.remoteyourcam.usb.ptp.commands.SimpleCommand;
24
+import com.remoteyourcam.usb.ptp.model.LiveViewData;
25
+
26
+public class NikonGetLiveViewImageAction implements PtpAction {
27
+
28
+    private final NikonCamera camera;
29
+    private final LiveViewData reuse;
30
+
31
+    public NikonGetLiveViewImageAction(NikonCamera camera, LiveViewData reuse) {
32
+        this.camera = camera;
33
+        this.reuse = reuse;
34
+    }
35
+
36
+    @Override
37
+    public void exec(IO io) {
38
+        SimpleCommand simpleCmd = new SimpleCommand(camera, Operation.NikonStartLiveView);
39
+        io.handleCommand(simpleCmd);
40
+
41
+        if (simpleCmd.getResponseCode() != Response.Ok) {
42
+            return;
43
+        }
44
+
45
+        SimpleCommand deviceReady = new SimpleCommand(camera, Operation.NikonDeviceReady);
46
+        for (int i = 0; i < 10; ++i) {
47
+            try {
48
+                Thread.sleep(300);
49
+            } catch (InterruptedException e) {
50
+                // nop
51
+            }
52
+
53
+            deviceReady.reset();
54
+            io.handleCommand(deviceReady);
55
+            if (deviceReady.getResponseCode() == Response.DeviceBusy) {
56
+                // still waiting
57
+            } else if (deviceReady.getResponseCode() == Response.Ok) {
58
+                camera.onLiveViewRestarted();
59
+                io.handleCommand(new NikonGetLiveViewImageCommand(camera, reuse));
60
+                return;
61
+            } else {
62
+                return;
63
+            }
64
+        }
65
+    }
66
+
67
+    @Override
68
+    public void reset() {
69
+    }
70
+}

+ 158 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonGetLiveViewImageCommand.java

@@ -0,0 +1,158 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import android.graphics.BitmapFactory;
19
+import android.graphics.BitmapFactory.Options;
20
+import android.util.Log;
21
+
22
+import com.remoteyourcam.usb.AppConfig;
23
+import com.remoteyourcam.usb.ptp.NikonCamera;
24
+import com.remoteyourcam.usb.ptp.PacketUtil;
25
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
26
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
27
+import com.remoteyourcam.usb.ptp.PtpConstants.Product;
28
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
29
+import com.remoteyourcam.usb.ptp.model.LiveViewData;
30
+
31
+import java.nio.ByteBuffer;
32
+import java.nio.ByteOrder;
33
+
34
+public class NikonGetLiveViewImageCommand extends NikonCommand {
35
+
36
+    private static boolean haveAddedDumpToAcra = false;
37
+
38
+    private static final String TAG = NikonGetLiveViewImageCommand.class.getSimpleName();
39
+    private static byte[] tmpStorage = new byte[0x4000];
40
+    private final Options options;
41
+    private LiveViewData data;
42
+
43
+    public NikonGetLiveViewImageCommand(NikonCamera camera, LiveViewData data) {
44
+        super(camera);
45
+        this.data = data;
46
+        if (data == null) {
47
+            this.data = new LiveViewData();
48
+            //this.data.histogram = ByteBuffer.allocate(1024 * 4);
49
+            //this.data.histogram.order(ByteOrder.LITTLE_ENDIAN);
50
+        } else {
51
+            this.data = data;
52
+        }
53
+        options = new BitmapFactory.Options();
54
+        options.inBitmap = this.data.bitmap;
55
+        options.inSampleSize = 1;
56
+        options.inTempStorage = tmpStorage;
57
+        this.data.bitmap = null;
58
+    }
59
+
60
+    @Override
61
+    public void exec(IO io) {
62
+        if (!camera.isLiveViewOpen()) {
63
+            return;
64
+        }
65
+        io.handleCommand(this);
66
+        if (responseCode == Response.DeviceBusy) {
67
+            camera.onDeviceBusy(this, true);
68
+            return;
69
+        }
70
+        data.hasHistogram = false;
71
+        if (this.data.bitmap != null && responseCode == Response.Ok) {
72
+            camera.onLiveViewReceived(data);
73
+        } else {
74
+            camera.onLiveViewReceived(null);
75
+        }
76
+    }
77
+
78
+    @Override
79
+    public void encodeCommand(ByteBuffer b) {
80
+        encodeCommand(b, Operation.NikonGetLiveViewImage);
81
+    }
82
+
83
+    @Override
84
+    protected void decodeData(ByteBuffer b, int length) {
85
+        if (length <= 128) {
86
+            return;
87
+        }
88
+
89
+        data.hasAfFrame = false;
90
+
91
+        int productId = camera.getProductId();
92
+        int start = b.position();
93
+        int pictureOffset;
94
+
95
+        switch (productId) {
96
+        case Product.NikonD5000:
97
+        case Product.NikonD3S:
98
+        case Product.NikonD90:
99
+            pictureOffset = 128;
100
+            break;
101
+        case Product.NikonD3X:
102
+        case Product.NikonD300S:
103
+        case Product.NikonD3:
104
+        case Product.NikonD300:
105
+        case Product.NikonD700:
106
+            pictureOffset = 64;
107
+            break;
108
+        case Product.NikonD7000:
109
+        case Product.NikonD5100:
110
+            pictureOffset = 384;
111
+            break;
112
+        default:
113
+            return;
114
+        }
115
+
116
+        b.order(ByteOrder.BIG_ENDIAN);
117
+
118
+        // read af frame
119
+        {
120
+            data.hasAfFrame = true;
121
+
122
+            int jpegImageWidth = b.getShort() & 0xFFFF;
123
+            int jpegImageHeight = b.getShort() & 0xFFFF;
124
+            int wholeWidth = b.getShort() & 0xFFFF;
125
+            int wholeHeight = b.getShort() & 0xFFFF;
126
+
127
+            float multX = jpegImageWidth / (float) wholeWidth;
128
+            float multY = jpegImageHeight / (float) wholeHeight;
129
+
130
+            b.position(start + 16);
131
+            data.nikonWholeWidth = wholeWidth;
132
+            data.nikonWholeHeight = wholeHeight;
133
+            data.nikonAfFrameWidth = (int) ((b.getShort() & 0xFFFF) * multX);
134
+            data.nikonAfFrameHeight = (int) ((b.getShort() & 0xFFFF) * multY);
135
+            data.nikonAfFrameCenterX = (int) ((b.getShort() & 0xFFFF) * multX);
136
+            data.nikonAfFrameCenterY = (int) ((b.getShort() & 0xFFFF) * multY);
137
+        }
138
+
139
+        b.order(ByteOrder.LITTLE_ENDIAN);
140
+
141
+        b.position(start + pictureOffset);
142
+
143
+        if (b.remaining() <= 128) {
144
+            data.bitmap = null;
145
+            return;
146
+        }
147
+
148
+        try {
149
+            data.bitmap = BitmapFactory.decodeByteArray(b.array(), b.position(), length - b.position(), options);
150
+        } catch (RuntimeException e) {
151
+            Log.e(TAG, "decoding failed " + e.toString());
152
+            Log.e(TAG, e.getLocalizedMessage());
153
+            if (AppConfig.LOG) {
154
+                PacketUtil.logHexdump(TAG, b.array(), start, 512);
155
+            }
156
+        }
157
+    }
158
+}

+ 51 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonGetVendorPropCodesCommand.java

@@ -0,0 +1,51 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.NikonCamera;
21
+import com.remoteyourcam.usb.ptp.PacketUtil;
22
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
24
+
25
+public class NikonGetVendorPropCodesCommand extends NikonCommand {
26
+
27
+    private int[] propertyCodes = new int[0];
28
+
29
+    public NikonGetVendorPropCodesCommand(NikonCamera camera) {
30
+        super(camera);
31
+    }
32
+
33
+    public int[] getPropertyCodes() {
34
+        return propertyCodes;
35
+    }
36
+
37
+    @Override
38
+    public void exec(IO io) {
39
+        throw new UnsupportedOperationException();
40
+    }
41
+
42
+    @Override
43
+    public void encodeCommand(ByteBuffer b) {
44
+        encodeCommand(b, Operation.NikonGetVendorPropCodes);
45
+    }
46
+
47
+    @Override
48
+    protected void decodeData(ByteBuffer b, int length) {
49
+        propertyCodes = PacketUtil.readU16Array(b);
50
+    }
51
+}

+ 69 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonOpenSessionAction.java

@@ -0,0 +1,69 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import com.remoteyourcam.usb.ptp.NikonCamera;
19
+import com.remoteyourcam.usb.ptp.PtpAction;
20
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
21
+import com.remoteyourcam.usb.ptp.PtpConstants;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Datatype;
23
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
24
+import com.remoteyourcam.usb.ptp.PtpConstants.Property;
25
+import com.remoteyourcam.usb.ptp.commands.OpenSessionCommand;
26
+import com.remoteyourcam.usb.ptp.commands.SetDevicePropValueCommand;
27
+
28
+public class NikonOpenSessionAction implements PtpAction {
29
+
30
+    private final NikonCamera camera;
31
+
32
+    public NikonOpenSessionAction(NikonCamera camera) {
33
+        this.camera = camera;
34
+    }
35
+
36
+    @Override
37
+    public void exec(IO io) {
38
+        OpenSessionCommand openSession = new OpenSessionCommand(camera);
39
+        io.handleCommand(openSession);
40
+        if (openSession.getResponseCode() == PtpConstants.Response.Ok) {
41
+            if (camera.hasSupportForOperation(Operation.NikonGetVendorPropCodes)) {
42
+                NikonGetVendorPropCodesCommand getPropCodes = new NikonGetVendorPropCodesCommand(camera);
43
+                io.handleCommand(getPropCodes);
44
+                SetDevicePropValueCommand c = new SetDevicePropValueCommand(camera, Property.NikonRecordingMedia, 1,
45
+                        Datatype.uint8);
46
+                io.handleCommand(c);
47
+                if (getPropCodes.getResponseCode() == PtpConstants.Response.Ok
48
+                        && c.getResponseCode() == PtpConstants.Response.Ok) {
49
+                    camera.setVendorPropCodes(getPropCodes.getPropertyCodes());
50
+                    camera.onSessionOpened();
51
+                } else {
52
+                    camera.onPtpError(String.format(
53
+                            "Couldn't read device property codes! Open session command failed with error code \"%s\"",
54
+                            PtpConstants.responseToString(getPropCodes.getResponseCode())));
55
+                }
56
+            } else {
57
+                camera.onSessionOpened();
58
+            }
59
+        } else {
60
+            camera.onPtpError(String.format(
61
+                    "Couldn't open session! Open session command failed with error code \"%s\"",
62
+                    PtpConstants.responseToString(openSession.getResponseCode())));
63
+        }
64
+    }
65
+
66
+    @Override
67
+    public void reset() {
68
+    }
69
+}

+ 66 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonStartLiveViewAction.java

@@ -0,0 +1,66 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import com.remoteyourcam.usb.ptp.NikonCamera;
19
+import com.remoteyourcam.usb.ptp.PtpAction;
20
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
21
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
23
+import com.remoteyourcam.usb.ptp.commands.SimpleCommand;
24
+
25
+public class NikonStartLiveViewAction implements PtpAction {
26
+
27
+    private final NikonCamera camera;
28
+
29
+    public NikonStartLiveViewAction(NikonCamera camera) {
30
+        this.camera = camera;
31
+    }
32
+
33
+    @Override
34
+    public void exec(IO io) {
35
+        SimpleCommand simpleCmd = new SimpleCommand(camera, Operation.NikonStartLiveView);
36
+        io.handleCommand(simpleCmd);
37
+
38
+        if (simpleCmd.getResponseCode() != Response.Ok) {
39
+            return;
40
+        }
41
+
42
+        SimpleCommand deviceReady = new SimpleCommand(camera, Operation.NikonDeviceReady);
43
+        for (int i = 0; i < 10; ++i) {
44
+            try {
45
+                Thread.sleep(300);
46
+            } catch (InterruptedException e) {
47
+                // nop
48
+            }
49
+
50
+            deviceReady.reset();
51
+            io.handleCommand(deviceReady);
52
+            if (deviceReady.getResponseCode() == Response.DeviceBusy) {
53
+                // still waiting
54
+            } else if (deviceReady.getResponseCode() == Response.Ok) {
55
+                camera.onLiveViewStarted();
56
+                return;
57
+            } else {
58
+                return;
59
+            }
60
+        }
61
+    }
62
+
63
+    @Override
64
+    public void reset() {
65
+    }
66
+}

+ 54 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/commands/nikon/NikonStopLiveViewAction.java

@@ -0,0 +1,54 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.commands.nikon;
17
+
18
+import com.remoteyourcam.usb.ptp.NikonCamera;
19
+import com.remoteyourcam.usb.ptp.PtpAction;
20
+import com.remoteyourcam.usb.ptp.PtpCamera.IO;
21
+import com.remoteyourcam.usb.ptp.PtpConstants.Operation;
22
+import com.remoteyourcam.usb.ptp.PtpConstants.Response;
23
+import com.remoteyourcam.usb.ptp.commands.SimpleCommand;
24
+
25
+public class NikonStopLiveViewAction implements PtpAction {
26
+
27
+    private final NikonCamera camera;
28
+    private final boolean notifyUser;
29
+
30
+    public NikonStopLiveViewAction(NikonCamera camera, boolean notifyUser) {
31
+        this.camera = camera;
32
+        this.notifyUser = notifyUser;
33
+    }
34
+
35
+    @Override
36
+    public void exec(IO io) {
37
+        SimpleCommand simpleCmd = new SimpleCommand(camera, Operation.NikonEndLiveView);
38
+        io.handleCommand(simpleCmd);
39
+
40
+        if (simpleCmd.getResponseCode() == Response.DeviceBusy) {
41
+            camera.onDeviceBusy(this, true);
42
+        } else {
43
+            if (notifyUser) {
44
+                camera.onLiveViewStopped();
45
+            } else {
46
+                camera.onLiveViewStoppedInternal();
47
+            }
48
+        }
49
+    }
50
+
51
+    @Override
52
+    public void reset() {
53
+    }
54
+}

+ 113 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/model/DeviceInfo.java

@@ -0,0 +1,113 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.model;
17
+
18
+import java.nio.ByteBuffer;
19
+import java.util.Arrays;
20
+
21
+import com.remoteyourcam.usb.ptp.PacketUtil;
22
+import com.remoteyourcam.usb.ptp.PtpConstants;
23
+
24
+/**
25
+ * Device info data set as defined by PTP standard.
26
+ */
27
+public class DeviceInfo {
28
+
29
+    public short standardVersion;
30
+    public int vendorExtensionId;
31
+    public short vendorExtensionVersion;
32
+    public String vendorExtensionDesc;
33
+    public short functionalMode;
34
+    public int[] operationsSupported;
35
+    public int[] eventsSupported;
36
+    public int[] devicePropertiesSupported;
37
+    public int[] captureFormats;
38
+    public int[] imageFormats;
39
+    public String manufacture;
40
+    public String model;
41
+    public String deviceVersion;
42
+    public String serialNumber;
43
+
44
+    public DeviceInfo(ByteBuffer b, int length) {
45
+        decode(b, length);
46
+    }
47
+
48
+    public DeviceInfo() {
49
+    }
50
+
51
+    public void decode(ByteBuffer b, int length) {
52
+        standardVersion = b.getShort();
53
+        vendorExtensionId = b.getInt();
54
+        vendorExtensionVersion = b.getShort();
55
+        vendorExtensionDesc = PacketUtil.readString(b);
56
+        functionalMode = b.getShort();
57
+        operationsSupported = PacketUtil.readU16Array(b);
58
+        eventsSupported = PacketUtil.readU16Array(b);
59
+        devicePropertiesSupported = PacketUtil.readU16Array(b);
60
+        captureFormats = PacketUtil.readU16Array(b);
61
+        imageFormats = PacketUtil.readU16Array(b);
62
+        manufacture = PacketUtil.readString(b);
63
+        model = PacketUtil.readString(b);
64
+        deviceVersion = PacketUtil.readString(b);
65
+        serialNumber = PacketUtil.readString(b);
66
+    }
67
+
68
+    public void encode(ByteBuffer b) {
69
+        b.putShort(standardVersion);
70
+        b.putInt(vendorExtensionId);
71
+        b.putInt(vendorExtensionVersion);
72
+        PacketUtil.writeString(b, "");
73
+        b.putShort(functionalMode);
74
+        PacketUtil.writeU16Array(b, new int[0]);
75
+        PacketUtil.writeU16Array(b, new int[0]);
76
+        PacketUtil.writeU16Array(b, new int[0]);
77
+        PacketUtil.writeU16Array(b, new int[0]);
78
+        PacketUtil.writeU16Array(b, new int[0]);
79
+        PacketUtil.writeString(b, "");
80
+        PacketUtil.writeString(b, "");
81
+        PacketUtil.writeString(b, "");
82
+    }
83
+
84
+    @Override
85
+    public String toString() {
86
+        // Changes here have to reflect changes in PtpConstants.main()
87
+        StringBuilder b = new StringBuilder();
88
+        b.append("DeviceInfo\n");
89
+        b.append("StandardVersion: ").append(standardVersion).append('\n');
90
+        b.append("VendorExtensionId: ").append(vendorExtensionId).append('\n');
91
+        b.append("VendorExtensionVersion: ").append(vendorExtensionVersion).append('\n');
92
+        b.append("VendorExtensionDesc: ").append(vendorExtensionDesc).append('\n');
93
+        b.append("FunctionalMode: ").append(functionalMode).append('\n');
94
+        appendU16Array(b, "OperationsSupported", PtpConstants.Operation.class, operationsSupported);
95
+        appendU16Array(b, "EventsSupported", PtpConstants.Event.class, eventsSupported);
96
+        appendU16Array(b, "DevicePropertiesSupported", PtpConstants.Property.class, devicePropertiesSupported);
97
+        appendU16Array(b, "CaptureFormats", PtpConstants.ObjectFormat.class, captureFormats);
98
+        appendU16Array(b, "ImageFormats", PtpConstants.ObjectFormat.class, imageFormats);
99
+        b.append("Manufacture: ").append(manufacture).append('\n');
100
+        b.append("Model: ").append(model).append('\n');
101
+        b.append("DeviceVersion: ").append(deviceVersion).append('\n');
102
+        b.append("SerialNumber: ").append(serialNumber).append('\n');
103
+        return b.toString();
104
+    }
105
+
106
+    private static void appendU16Array(StringBuilder b, String name, Class<?> cl, int[] a) {
107
+        Arrays.sort(a);
108
+        b.append(name).append(":\n");
109
+        for (int i = 0; i < a.length; ++i) {
110
+            b.append("    ").append(PtpConstants.constantToString(cl, a[i])).append('\n');
111
+        }
112
+    }
113
+}

+ 102 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/model/DevicePropDesc.java

@@ -0,0 +1,102 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.model;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PacketUtil;
21
+import com.remoteyourcam.usb.ptp.PtpConstants.Datatype;
22
+
23
+public class DevicePropDesc {
24
+
25
+    public int code;
26
+    public int datatype;
27
+    public boolean readOnly;
28
+    public int factoryDefault;
29
+    public int currentValue;
30
+    public int[] description;
31
+
32
+    public DevicePropDesc() {
33
+    }
34
+
35
+    public DevicePropDesc(ByteBuffer b, int length) {
36
+        decode(b, length);
37
+    }
38
+
39
+    public void decode(ByteBuffer b, int length) {
40
+        code = b.getShort() & 0xFFFF;
41
+        datatype = b.getShort() & 0xFFFF;
42
+        readOnly = b.get() == 0;
43
+
44
+        if (datatype == Datatype.int8 || datatype == Datatype.uint8) {
45
+            factoryDefault = b.get() & 0xFF;
46
+            currentValue = b.get() & 0xFF;
47
+            int form = b.get();
48
+            if (form == 2) {
49
+                description = PacketUtil.readU8Enumeration(b);
50
+            } else if (form == 1) {
51
+                int mini = b.get();
52
+                int maxi = b.get();
53
+                int step = b.get();
54
+                description = new int[(maxi - mini) / step + 1];
55
+                for (int i = 0; i < description.length; ++i) {
56
+                    description[i] = mini + step * i;
57
+                }
58
+            }
59
+        } else if (datatype == Datatype.uint16) {
60
+            factoryDefault = b.getShort() & 0xFFFF;
61
+            currentValue = b.getShort() & 0xFFFF;
62
+            int form = b.get();
63
+            if (form == 2) {
64
+                description = PacketUtil.readU16Enumeration(b);
65
+            } else if (form == 1) {
66
+                int mini = b.getShort() & 0xFFFF;
67
+                int maxi = b.getShort() & 0xFFFF;
68
+                int step = b.getShort() & 0xFFFF;
69
+                description = new int[(maxi - mini) / step + 1];
70
+                for (int i = 0; i < description.length; ++i) {
71
+                    description[i] = mini + step * i;
72
+                }
73
+            }
74
+        } else if (datatype == Datatype.int16) {
75
+            factoryDefault = b.getShort();
76
+            currentValue = b.getShort();
77
+            int form = b.get();
78
+            if (form == 2) {
79
+                description = PacketUtil.readS16Enumeration(b);
80
+            } else if (form == 1) {
81
+                int mini = b.getShort();
82
+                int maxi = b.getShort();
83
+                int step = b.getShort();
84
+                description = new int[(maxi - mini) / step + 1];
85
+                for (int i = 0; i < description.length; ++i) {
86
+                    description[i] = mini + step * i;
87
+                }
88
+            }
89
+        } else if (datatype == Datatype.int32 || datatype == Datatype.uint32) {
90
+            factoryDefault = b.getInt();
91
+            currentValue = b.getInt();
92
+            int form = b.get();
93
+            if (form == 2) {
94
+                description = PacketUtil.readU32Enumeration(b);
95
+            }
96
+        }
97
+
98
+        if (description == null) {
99
+            description = new int[0];
100
+        }
101
+    }
102
+}

+ 44 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/model/LiveViewData.java

@@ -0,0 +1,44 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.model;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import android.graphics.Bitmap;
21
+
22
+public class LiveViewData {
23
+
24
+    public Bitmap bitmap;
25
+
26
+    public int zoomFactor;
27
+    public int zoomRectLeft;
28
+    public int zoomRectTop;
29
+    public int zoomRectRight;
30
+    public int zoomRectBottom;
31
+
32
+    public boolean hasHistogram;
33
+    public ByteBuffer histogram;
34
+
35
+    // dimensions are in bitmap size
36
+    public boolean hasAfFrame;
37
+    public int nikonAfFrameCenterX;
38
+    public int nikonAfFrameCenterY;
39
+    public int nikonAfFrameWidth;
40
+    public int nikonAfFrameHeight;
41
+
42
+    public int nikonWholeWidth;
43
+    public int nikonWholeHeight;
44
+}

+ 101 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/model/ObjectInfo.java

@@ -0,0 +1,101 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.model;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PacketUtil;
21
+import com.remoteyourcam.usb.ptp.PtpConstants;
22
+
23
+/**
24
+ * Object info data set as defined by the PTP standard.
25
+ */
26
+public class ObjectInfo {
27
+
28
+    public int storageId;
29
+    public int objectFormat;
30
+    public int protectionStatus;
31
+    public int objectCompressedSize;
32
+    public int thumbFormat;
33
+    public int thumbCompressedSize;
34
+    public int thumbPixWidth;
35
+    public int thumbPixHeight;
36
+    public int imagePixWidth;
37
+    public int imagePixHeight;
38
+    public int imageBitDepth;
39
+    public int parentObject;
40
+    public int associationType;
41
+    public int associationDesc;
42
+    public int sequenceNumber;
43
+    public String filename;
44
+    public String captureDate;
45
+    public String modificationDate;
46
+    public int keywords;
47
+
48
+    public ObjectInfo() {
49
+    }
50
+
51
+    public ObjectInfo(ByteBuffer b, int length) {
52
+        decode(b, length);
53
+    }
54
+
55
+    public void decode(ByteBuffer b, int length) {
56
+        storageId = b.getInt();
57
+        objectFormat = b.getShort();
58
+        protectionStatus = b.getShort();
59
+        objectCompressedSize = b.getInt();
60
+        thumbFormat = b.getShort();
61
+        thumbCompressedSize = b.getInt();
62
+        thumbPixWidth = b.getInt();
63
+        thumbPixHeight = b.getInt();
64
+        imagePixWidth = b.getInt();
65
+        imagePixHeight = b.getInt();
66
+        imageBitDepth = b.getInt();
67
+        parentObject = b.getInt();
68
+        associationType = b.getShort();
69
+        associationDesc = b.getInt();
70
+        sequenceNumber = b.getInt();
71
+        filename = PacketUtil.readString(b);
72
+        captureDate = PacketUtil.readString(b);
73
+        modificationDate = PacketUtil.readString(b);
74
+        keywords = b.get(); // string, not used on camera?
75
+    }
76
+
77
+    @Override
78
+    public String toString() {
79
+        StringBuilder b = new StringBuilder();
80
+        b.append("ObjectInfo\n");
81
+        b.append("StorageId: ").append(String.format("0x%08x\n", storageId));
82
+        b.append("ObjectFormat: ").append(PtpConstants.objectFormatToString(objectFormat)).append('\n');
83
+        b.append("ProtectionStatus: ").append(protectionStatus).append('\n');
84
+        b.append("ObjectCompressedSize: ").append(objectCompressedSize).append('\n');
85
+        b.append("ThumbFormat: ").append(PtpConstants.objectFormatToString(thumbFormat)).append('\n');
86
+        b.append("ThumbCompressedSize: ").append(thumbCompressedSize).append('\n');
87
+        b.append("ThumbPixWdith: ").append(thumbPixWidth).append('\n');
88
+        b.append("ThumbPixHeight: ").append(thumbPixHeight).append('\n');
89
+        b.append("ImagePixWidth: ").append(imagePixWidth).append('\n');
90
+        b.append("ImagePixHeight: ").append(imagePixHeight).append('\n');
91
+        b.append("ImageBitDepth: ").append(imageBitDepth).append('\n');
92
+        b.append("ParentObject: ").append(String.format("0x%08x", parentObject)).append('\n');
93
+        b.append("AssociationType: ").append(associationType).append('\n');
94
+        b.append("AssociatonDesc: ").append(associationDesc).append('\n');
95
+        b.append("Filename: ").append(filename).append('\n');
96
+        b.append("CaptureDate: ").append(captureDate).append('\n');
97
+        b.append("ModificationDate: ").append(modificationDate).append('\n');
98
+        b.append("Keywords: ").append(keywords).append('\n');
99
+        return b.toString();
100
+    }
101
+}

+ 47 - 0
ryc/src/main/java/com/remoteyourcam/usb/ptp/model/StorageInfo.java

@@ -0,0 +1,47 @@
1
+/**
2
+ * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+package com.remoteyourcam.usb.ptp.model;
17
+
18
+import java.nio.ByteBuffer;
19
+
20
+import com.remoteyourcam.usb.ptp.PacketUtil;
21
+
22
+public class StorageInfo {
23
+
24
+    public int storageType;
25
+    public int filesystemType;
26
+    public int accessCapability;
27
+    public long maxCapacity;
28
+    public long freeSpaceInBytes;
29
+    public int freeSpaceInImages;
30
+    public String storageDescription;
31
+    public String volumeLabel;
32
+
33
+    public StorageInfo(ByteBuffer b, int length) {
34
+        decode(b, length);
35
+    }
36
+
37
+    private void decode(ByteBuffer b, int length) {
38
+        storageType = b.getShort() & 0xffff;
39
+        filesystemType = b.getShort() & 0xffff;
40
+        accessCapability = b.getShort() & 0xff;
41
+        maxCapacity = b.getLong();
42
+        freeSpaceInBytes = b.getLong();
43
+        freeSpaceInImages = b.getInt();
44
+        storageDescription = PacketUtil.readString(b);
45
+        volumeLabel = PacketUtil.readString(b);
46
+    }
47
+}

+ 3 - 0
ryc/src/main/res/values/strings.xml

@@ -0,0 +1,3 @@
1
+<resources>
2
+    <string name="app_name">ryc</string>
3
+</resources>

+ 1 - 1
settings.gradle

@@ -1 +1 @@
1
-include ':app', ':common', ':views'
1
+include ':app', ':common', ':views', ':ryc'

Zaloguj się - Gogs: Go Git Service

Zaloguj się

Zapomniałeś hasła?
kodo - Gogs: Go Git Service

No Description

0003_auto_20180402_1904.py 868B

    # -*- coding: utf-8 -*- # Generated by Django 1.11.11 on 2018-04-02 11:04 from __future__ import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ('integral', '0002_auto_20180308_1440'), ] operations = [ migrations.AddField( model_name='saleclerkintegralincomeexpensesinfo', name='model_id', field=models.CharField(blank=True, db_index=True, help_text='\u578b\u53f7\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='model_id'), ), migrations.AddField( model_name='saleclerkintegralincomeexpensesinfo', name='model_name', field=models.CharField(blank=True, help_text='\u578b\u53f7\u540d\u79f0', max_length=255, null=True, verbose_name='model_name'), ), ]