2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 |
21 | /**
22 | * A Buffer handles marshaling/unmarshaling rules applicable to PTP
23 | * over USB. That's a fairly standard sort of little-endian
24 | * marshaling, Unicode enabled.
25 | * In this API, eight and sixteen bit values are passed in the least
26 | * significant bits of integers, and are sign extended if needed.
27 | * Unsigned thirty-two and sixty-four bit values are not currently
28 | * provided; they have the same bit patterns as signed values, but
29 | * applications must print them differently.
30 | * One hundred twenty-eight bit integers are not currently supported.
31 | * These buffers are not to be used concurrently.
32 | *
33 | * Strings representing times (YYYYMMDDThhmmss[.s]{,Z,{+,-}hhmm})
34 | * are not currently transformed to Java-oriented representations.
35 | *
36 | * @version $Id: Buffer.java,v 1.5 2001/04/12 23:13:00 dbrownell Exp $
37 | * @author David Brownell
38 | */
39 | public class Buffer
40 | {
41 | // package private
42 | public byte data [];
43 | public int length;
44 | public int offset;
45 |
46 | // package private
47 | Buffer (byte buf [])
48 | {
49 | this (buf, buf.length);
50 | }
51 |
52 | // package private
53 | Buffer (byte buf [], int len)
54 | {
55 | if (buf != null && (len < 0 || len > buf.length))
56 | throw new IllegalArgumentException ();
57 | if (buf == null && len != 0)
58 | throw new IllegalArgumentException ();
59 | data = buf;
60 | length = len;
61 | offset = 0;
62 | }
63 |
64 | public byte[] getData() {
65 | return data;
66 | }
67 |
68 | public int getLength() {
69 | return length;
70 | }
71 |
72 | /** Unmarshals a signed 8 bit integer from a fixed buffer offset. */
73 | protected final int getS8 (int index)
74 | {
75 | return data [index];
76 | }
77 |
78 | /** Unmarshals an unsigned 8 bit integer from a fixed buffer offset. */
79 | protected final int getU8 (int index)
80 | {
81 | return 0xff & data [index];
82 | }
83 |
84 | /** Marshals an 8 bit integer (signed or unsigned) */
85 | protected final void put8 (int value)
86 | {
87 | data [offset++] = (byte) value;
88 | }
89 |
90 | /** Unmarshals the next signed 8 bit integer */
91 | protected final int nextS8 ()
92 | {
93 | return data [offset++];
94 | }
95 |
96 | /** Unmarshals the next unsigned 8 bit integer */
97 | protected final int nextU8 ()
98 | {
99 | return 0xff & data [offset++];
100 | }
101 |
102 | /** Unmarshals an array of signed 8 bit integers */
103 | protected final int [] nextS8Array ()
104 | {
105 | int len = /* unsigned */ nextS32 ();
106 | int retval [] = new int [len];
107 | for (int i = 0; i < len; i++)
108 | retval [i] = nextS8 ();
109 | return retval;
110 | }
111 |
112 |
113 | /** Unmarshals an array of 8 bit integers */
114 | protected final int [] nextU8Array ()
115 | {
116 | int len = /* unsigned */ nextS32 ();
117 | int retval [] = new int [len];
118 | for (int i = 0; i < len; i++)
119 | retval [i] = nextU8 ();
120 | return retval;
121 | }
122 |
123 |
124 | /** Unmarshals a signed 16 bit integer from a fixed buffer offset. */
125 | protected final int getS16 (int index)
126 | {
127 | int retval;
128 |
129 | retval = 0xff & data [index++];
130 | retval |= data [index] << 8;
131 | return retval;
132 | }
133 |
134 | /** Unmarshals an unsigned 16 bit integer from a fixed buffer offset. */
135 | protected final int getU16 (int index)
136 | {
137 | int retval;
138 |
139 | retval = 0xff & data [index++];
140 | retval |= 0xff00 & (data [index] << 8);
141 | return retval;
142 | }
143 |
144 | /** Marshals a 16 bit integer (signed or unsigned) */
145 | protected final void put16 (int value)
146 | {
147 | data [offset++] = (byte) value;
148 | data [offset++] = (byte) (value >> 8);
149 | }
150 |
151 | /** Unmarshals the next signed 16 bit integer */
152 | protected final int nextS16 ()
153 | {
154 | int retval = getS16 (offset);
155 | offset += 2;
156 | return retval;
157 | }
158 |
159 | /** Unmarshals the next unsinged 16 bit integer */
160 | protected final int nextU16 ()
161 | {
162 | int retval = getU16 (offset);
163 | offset += 2;
164 | return retval;
165 | }
166 |
167 | /** Unmarshals an array of signed 16 bit integers */
168 | protected final int [] nextS16Array ()
169 | {
170 | int len = /* unsigned */ nextS32 ();
171 | int retval [] = new int [len];
172 | for (int i = 0; i < len; i++)
173 | retval [i] = nextS16 ();
174 | return retval;
175 | }
176 |
177 | /** Unmarshals an array of unsigned 16 bit integers */
178 | protected final int [] nextU16Array ()
179 | {
180 | int len = /* unsigned */ nextS32 ();
181 | int retval [] = new int [len];
182 | for (int i = 0; i < len; i++)
183 | retval [i] = nextU16 ();
184 | return retval;
185 | }
186 |
187 |
188 | /** Unmarshals a signed 32 bit integer from a fixed buffer offset. */
189 | protected final int getS32 (int index)
190 | {
191 | int retval;
192 |
193 | retval = (0xff & data [index++]) ;
194 | retval |= (0xff & data [index++]) << 8;
195 | retval |= (0xff & data [index++]) << 16;
196 | retval |= data [index ] << 24;
197 |
198 | return retval;
199 | }
200 |
201 | /** Marshals a 32 bit integer (signed or unsigned) */
202 | public final void put32 (int value)
203 | {
204 | data [offset++] = (byte) value;
205 | data [offset++] = (byte) (value >> 8);
206 | data [offset++] = (byte) (value >> 16);
207 | data [offset++] = (byte) (value >> 24);
208 | }
209 |
210 | /** Unmarshals the next signed 32 bit integer */
211 | protected final int nextS32 ()
212 | {
213 | int retval = getS32 (offset);
214 | offset += 4;
215 | return retval;
216 | }
217 |
218 | /** Unmarshals an array of signed 32 bit integers. */
219 | protected final int [] nextS32Array ()
220 | {
221 | int len = /* unsigned */ nextS32 ();
222 | int retval [] = new int [len];
223 | for (int i = 0; i < len; i++) {
224 | retval [i] = nextS32 ();
225 | }
226 | return retval;
227 | }
228 |
229 |
230 |
231 | /** Unmarshals a signed 64 bit integer from a fixed buffer offset */
232 | protected final long getS64 (int index)
233 | {
234 | long retval = 0xffffffff & getS32 (index);
235 |
236 | retval |= (getS32 (index + 4) << 32);
237 | return retval;
238 | }
239 |
240 | /** Marshals a 64 bit integer (signed or unsigned) */
241 | protected final void put64 (long value)
242 | {
243 | put32 ((int) value);
244 | put32 ((int) (value >> 32));
245 | }
246 |
247 | /** Unmarshals the next signed 64 bit integer */
248 | protected final long nextS64 ()
249 | {
250 | long retval = getS64 (offset);
251 | offset += 8;
252 | return retval;
253 | }
254 |
255 | /** Unmarshals an array of signed 64 bit integers */
256 | protected final long [] nextS64Array ()
257 | {
258 | int len = /* unsigned */ nextS32 ();
259 | long retval [] = new long [len];
260 | for (int i = 0; i < len; i++)
261 | retval [i] = nextS64 ();
262 | return retval;
263 | }
264 |
265 | // Java doesn't yet support 128 bit integers,
266 | // needed to support primitives like these:
267 |
268 | // getU128
269 | // putU128
270 | // nextU128
271 | // nextU128Array
272 |
273 | // getS128
274 | // putS128
275 | // nextS128
276 | // nextS128Array
277 |
278 |
279 | /** Unmarshals a string (or null) from a fixed buffer offset. */
280 | protected final String getString (int index)
281 | {
282 | int savedOffset = offset;
283 | String retval;
284 |
285 | offset = index;
286 | retval = nextString ();
287 | offset = savedOffset;
288 | return retval;
289 | }
290 |
291 | /** Marshals a string, of length at most 254 characters, or null. */
292 | public void putString (String s)
293 | {
294 | if (s == null) {
295 | put8 (0);
296 | return;
297 | }
298 |
299 | int len = s.length ();
300 |
301 | if (len > 254)
302 | throw new IllegalArgumentException ();
303 | put8 (len + 1);
304 | for (int i = 0; i < len; i++)
305 | put16 ((int) s.charAt (i));
306 | put16 (0);
307 | }
308 |
309 | /** Unmarshals the next string (or null). */
310 | protected String nextString ()
311 | {
312 | int len = nextU8 ();
313 | StringBuffer str;
314 |
315 | if (len == 0)
316 | return null;
317 |
318 | str = new StringBuffer (len);
319 | for (int i = 0; i < len; i++)
320 | str.append ((char) nextU16 ());
321 | // drop terminal null
322 | str.setLength (len - 1);
323 | return str.toString ();
324 | }
325 |
326 | public void dump() {
327 | System.out.println(data);
328 | for (int i=0; i < data.length; ++i) {
329 | if ((i%8) == 0) {
330 | System.out.println();
331 | }
332 | System.out.print(String.format("%1$02X ", data[i]));
333 | }
334 | }
335 | }
336 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/Command.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 | package com.ptplib.usbcamera;
18 |
19 | /**
20 | * Command messages start PTP transactions, and are sent from
21 | * initiator to responder. They include an operation code,
22 | * either conform to chapter 10 of the PTP specification or
23 | * are vendor-specific commands.
24 | *
25 | * Create these objects in helper routines which package
26 | * intelligence about a given Operation. That is, it'll know
27 | * the command code, how many command and response parameters
28 | * may be used, particularly significant response code, and
29 | * whether the transaction has a data phase (and its direction).
30 | *
31 | * @version $Id: Command.java,v 1.3 2001/04/12 23:13:00 dbrownell Exp $
32 | * @author David Brownell
33 | */
34 | public class Command extends ParamVector {
35 |
36 | private Command(int nparams, int code, Session s) {
37 | super(new byte[HDR_LEN + (4 * nparams)], s.getFactory());
38 | putHeader(data.length, 1 /*OperationCode*/, code, s.getNextXID());
39 | }
40 |
41 | /**
42 | * This creates a zero-parameter command.
43 | * @param code as defined in section 10, table 18
44 | * @param s session this command is associated with
45 | */
46 | public Command(int code, Session s) {
47 | this(0, code, s);
48 | }
49 |
50 | /**
51 | * This creates a one-parameter command.
52 | * @param code as defined in section 10, table 18
53 | * @param s session this command is associated with
54 | * @param param1 first operation parameter
55 | */
56 | public Command(int code, Session s, int param1) {
57 | this(1, code, s);
58 | put32(param1);
59 | }
60 |
61 | /**
62 | * This creates a two-parameter command.
63 | * @param code as defined in section 10, table 18
64 | * @param s session this command is associated with
65 | * @param param1 first operation parameter
66 | * @param param2 second operation parameter
67 | */
68 | public Command(int code, Session s, int param1, int param2) {
69 | this(2, code, s);
70 | put32(param1);
71 | put32(param2);
72 | }
73 |
74 | /**
75 | * This creates a three-parameter command.
76 | * @param code as defined in section 10, table 18
77 | * @param s session this command is associated with
78 | * @param param1 first operation parameter
79 | * @param param2 second operation parameter
80 | * @param param3 third operation parameter
81 | */
82 | Command(int code, Session s, int param1, int param2, int param3) {
83 | this(3, code, s);
84 | put32(param1);
85 | put32(param2);
86 | put32(param3);
87 | }
88 | // allegedly some commands could have up to five params
89 | public static final int GetDeviceInfo = 0x1001;
90 | public static final int OpenSession = 0x1002;
91 | public static final int CloseSession = 0x1003;
92 | public static final int GetStorageIDs = 0x1004;
93 | public static final int GetStorageInfo = 0x1005;
94 | public static final int GetNumObjects = 0x1006;
95 | public static final int GetObjectHandles = 0x1007;
96 | public static final int GetObjectInfo = 0x1008;
97 | public static final int GetObject = 0x1009;
98 | public static final int GetThumb = 0x100a;
99 | public static final int DeleteObject = 0x100b;
100 | public static final int SendObjectInfo = 0x100c;
101 | public static final int SendObject = 0x100d;
102 | public static final int InitiateCapture = 0x100e;
103 | public static final int FormatStore = 0x100f;
104 | public static final int ResetDevice = 0x1010;
105 | public static final int SelfTest = 0x1011;
106 | public static final int SetObjectProtection = 0x1012;
107 | public static final int PowerDown = 0x1013;
108 | public static final int GetDevicePropDesc = 0x1014;
109 | public static final int GetDevicePropValue = 0x1015;
110 | public static final int SetDevicePropValue = 0x1016;
111 | public static final int ResetDevicePropValue = 0x1017;
112 | public static final int TerminateOpenCapture = 0x1018;
113 | public static final int MoveObject = 0x1019;
114 | public static final int CopyObject = 0x101a;
115 | public static final int GetPartialObject = 0x101b;
116 | public static final int InitiateOpenCapture = 0x101c;
117 | public static final int EosGetStorageIds = 0x9101;
118 | public static final int EosGetStorageInfo = 0x9102;
119 | public static final int EosGetObjectInfo = 0x9103;
120 | public static final int EosGetObject = 0x9104;
121 | public static final int EosDeleteObject = 0x9105;
122 | public static final int EosFormatStore = 0x9106;
123 | public static final int EosGetPartialObject = 0x9107;
124 | public static final int EosGetDeviceInfoEx = 0x9108;
125 | public static final int EosGetObjectInfoEx = 0x9109;
126 | public static final int EosGetThumbEx = 0x910a;
127 | public static final int EosSendPartialObject = 0x910b;
128 | public static final int EosSetObjectProperties = 0x910c;
129 | public static final int EosGetObjectTime = 0x910d;
130 | public static final int EosSetObjectTime = 0x910e;
131 | public static final int EosRemoteRelease = 0x910f;
132 | public static final int EosSetDevicePropValueEx = 0x9110;
133 | public static final int EosSendObjectEx = 0x9111;
134 | public static final int EosCreageObject = 0x9112;
135 | public static final int EosGetRemoteMode = 0x9113;
136 | public static final int EosSetRemoteMode = 0x9114;
137 | public static final int EOS_OC_SetPCConnectMode = 0x9114;
138 | public static final int EosSetEventMode = 0x9115;
139 | public static final int EosGetEvent = 0x9116;
140 | public static final int EosTransferComplete = 0x9117;
141 | public static final int EosCancelTransfer = 0x9118;
142 | public static final int EosResetTransfer = 0x9119;
143 | public static final int EosPCHDDCapacity = 0x911a;
144 | public static final int EosSetUILock = 0x911b;
145 | public static final int EosResetUILock = 0x911c;
146 | public static final int EosKeepDeviceOn = 0x911d;
147 | public static final int EosSetNullPacketmode = 0x911e;
148 | public static final int EosUpdateFirmware = 0x911f;
149 | public static final int EosUpdateTransferCompleteDt = 0x9120;
150 | public static final int EosCancelTransferDt = 0x9121;
151 | public static final int EosSetFWTProfile = 0x9122;
152 | public static final int EosGetFWTProfile = 0x9123;
153 | public static final int EosSetProfileToWTF = 0x9124;
154 | public static final int EosBulbStart = 0x9125;
155 | public static final int EosBulbEnd = 0x9126;
156 | public static final int EosRequestDevicePropValue = 0x9127;
157 | public static final int EosRemoeReleaseOn = 0x9128;
158 | public static final int EosRemoeReleaseOff = 0x9129;
159 | public static final int EosRegistBackgroundImage = 0x912a;
160 | public static final int EosChangePhotoStadIOMode = 0x912b;
161 | public static final int EosGetPartialObjectEx = 0x912c;
162 | public static final int EosResetMirrorLockupState = 0x9130;
163 | public static final int EosPopupBuiltinFlash = 0x9131;
164 | public static final int EosEndGetPartialObjectEx = 0x9132;
165 | public static final int EosMovieSelectSWOn = 0x9133;
166 | public static final int EosMovieSelectSWOff = 0x9134;
167 | public static final int EosInitiateViewFinder = 0x9151;
168 | public static final int EosTerminateViewFinder = 0x9152;
169 | public static final int EosGetViewFinderData = 0x9153;
170 | public static final int EOS_OC_GetLiveViewPicture = 0x9153;
171 | public static final int EosDoAF = 0x9154;
172 | public static final int EosDriveLens = 0x9155;
173 | public static final int EosDepthOfFieldPreview = 0x9156;
174 | public static final int EosClickWB = 0x9157;
175 | public static final int EosZoom = 0x9158;
176 | public static final int EosZoomPosition = 0x9159;
177 | public static final int EosSetLiveAFFrame = 0x915a;
178 | public static final int EosAFCancel = 0x9160;
179 | public static final int EosFapiMessageTx = 0x91fe;
180 | public static final int EosFapiMessageRx = 0x91ff;
181 | public static final int MtpGetObjectPropsSupported = 0x9801;
182 | public static final int MtpGetObjectPropDesc = 0x9802;
183 | public static final int MtpGetObjectPropValue = 0x9803;
184 | public static final int MtpSetObjectPropValue = 0x9804;
185 | public static final int MtpGetObjPropList = 0x9805;
186 |
187 |
188 | /**PTP Device Properties*/
189 | public static final int EOS_DPC_CameraDescription = 0xD402;
190 |
191 | /**Non-PTP Device properties*/
192 | public static final int EOS_DPC_Aperture = 0xD101;
193 | public static final int EOS_DPC_ShutterSpeed = 0xD102;
194 | public static final int EOS_DPC_Iso = 0xD103;
195 | public static final int EOS_DPC_ExposureCompensation = 0xD104;
196 | public static final int EOS_DPC_ShootingMode = 0xD105;
197 | public static final int EOS_DPC_DriveMode = 0xD106;
198 | public static final int EOS_DPC_ExpMeterringMode = 0xD107;
199 | public static final int EOS_DPC_AFMode = 0xD108;
200 | public static final int EOS_DPC_WhiteBalance = 0xD109;
201 | public static final int EOS_DPC_PictureStyle = 0xD110;
202 | public static final int EOS_DPC_TransferOption = 0xD111;
203 | public static final int EOS_DPC_UnixTime = 0xD113;
204 | public static final int EOS_DPC_ImageQuality = 0xD120;
205 | public static final int EOS_DPC_LiveView = 0xD1B0;
206 | public static final int EOS_DPC_AvailableShots = 0xD11B;
207 | public static final int EOS_DPC_CaptureDestination = 0xD11C;
208 | public static final int EOS_DPC_BracketMode = 0xD11D;
209 | public static final int PTP_OC_CANON_EOS_SetNullPacketMode =0x911E;
210 |
211 | // Nikon Extension Operation Codes
212 | public static final int NK_OC_GetProfileAllData = 0x9006;
213 | public static final int NK_OC_SendProfileData = 0x9007;
214 | public static final int NK_OC_DeleteProfile = 0x9008;
215 | public static final int NK_OC_SetProfileData = 0x9009;
216 | public static final int NK_OC_AdvancedTransfer = 0x9010;
217 | public static final int NK_OC_GetFileInfoInBlock = 0x9011;
218 | public static final int NK_OC_Capture = 0x90C0;
219 | public static final int NK_OC_SetControlMode = 0x90C2;
220 | public static final int NK_OC_CurveDownload = 0x90C5;
221 | public static final int NK_OC_CurveUpload = 0x90C6;
222 | public static final int NK_OC_CheckEvent = 0x90C7;
223 | public static final int NK_OC_DeviceReady = 0x90C8;
224 | public static final int NK_OC_CaptureInSDRAM = 0x90CB;
225 | public static final int NK_OC_GetDevicePTPIPInfo = 0x90E0;
226 |
227 | public static final int PTP_OC_NIKON_GetPreviewImg = 0x9200;
228 | public static final int PTP_OC_NIKON_StartLiveView = 0x9201;
229 | public static final int PTP_OC_NIKON_EndLiveView = 0x9202;
230 | public static final int PTP_OC_NIKON_GetLiveViewImg = 0x9203;
231 | public static final int PTP_OC_NIKON_MfDrive = 0x9204;
232 | public static final int PTP_OC_NIKON_ChangeAfArea = 0x9205;
233 | public static final int PTP_OC_NIKON_AfDriveCancel = 0x9206;
234 |
235 |
236 |
237 |
238 | public String getCodeName(int code) {
239 | return factory.getOpcodeString(code);
240 | }
241 |
242 | static String _getOpcodeString(int code) {
243 | switch (code) {
244 | case GetDeviceInfo: return "GetDeviceInfo";
245 | case OpenSession: return "OpenSession";
246 | case CloseSession: return "CloseSession";
247 | case GetStorageIDs: return "GetStorageIDs";
248 | case GetStorageInfo: return "GetStorageInfo";
249 | case GetNumObjects: return "GetNumObjects";
250 | case GetObjectHandles: return "GetObjectHandles";
251 | case GetObjectInfo: return "GetObjectInfo";
252 | case GetObject: return "GetObject";
253 | case GetThumb: return "GetThumb";
254 | case DeleteObject: return "DeleteObject";
255 | case SendObjectInfo: return "SendObjectInfo";
256 | case SendObject: return "SendObject";
257 | case InitiateCapture: return "InitiateCapture";
258 | case FormatStore: return "FormatStore";
259 | case ResetDevice: return "ResetDevice";
260 | case SelfTest: return "SelfTest";
261 | case SetObjectProtection: return "SetObjectProtection";
262 | case PowerDown: return "PowerDown";
263 | case GetDevicePropDesc: return "GetDevicePropDesc";
264 | case GetDevicePropValue: return "GetDevicePropValue";
265 | case SetDevicePropValue: return "SetDevicePropValue";
266 | case ResetDevicePropValue: return "ResetDevicePropValue";
267 | case TerminateOpenCapture: return "TerminateOpenCapture";
268 | case MoveObject: return "MoveObject";
269 | case CopyObject: return "CopyObject";
270 | case GetPartialObject: return "GetPartialObject";
271 | case InitiateOpenCapture: return "InitiateOpenCapture";
272 | case EosSetDevicePropValueEx: return "EosSetDevicePropValueEx";
273 | case EosCancelTransfer: return "EosCancelTransfer";
274 | case EosCreageObject: return "EosCreageObject";
275 | case EosDeleteObject: return "EosDeleteObject";
276 | case EosFapiMessageRx: return "EosFapiMessageRx";
277 | case EosFapiMessageTx: return "EosFapiMessageTx";
278 | case EosFormatStore: return "EosFormatStore";
279 | case EosGetDeviceInfoEx: return "EosGetDeviceInfoEx";
280 | case EosGetEvent: return "EosGetEvent";
281 | case EosGetObject: return "EosGetObject";
282 | case EosGetObjectInfo: return "EosGetObjectInfo";
283 | case EosGetObjectInfoEx: return "EosGetObjectInfoEx";
284 | case EosGetObjectTime: return "EosGetObjectTime";
285 | case EosGetPartialObject: return "EosGetPartialObject";
286 | case EosGetRemoteMode: return "EosGetRemoteMode";
287 | case EosGetStorageIds: return "EosGetStorageIds";
288 | case EosGetStorageInfo: return "EosGetStorageInfo";
289 | case EosGetThumbEx: return "EosGetThumbEx";
290 | case EosKeepDeviceOn: return "EosKeepDeviceOn";
291 | case EosPCHDDCapacity: return "EosPCHDDCapacity";
292 | case EosRemoteRelease: return "EosRemoteRelease";
293 | case EosResetUILock: return "EosResetUILock";
294 | case EosResetTransfer: return "EosResetTransfer";
295 | case EosSendObjectEx: return "EosSendObjectEx";
296 | case EosSendPartialObject: return "EosSendPartialObject";
297 | case EosSetNullPacketmode: return "EosSetNullPacketmode";
298 | case EosSetObjectProperties: return "EosSetObjectProperties";
299 | case EosSetObjectTime: return "EosSetObjectTime";
300 | case EosSetRemoteMode: return "EosSetRemoteMode";
301 | case EosSetUILock: return "EosSetUILock";
302 | case EosTransferComplete: return "EosGetTransferComplete";
303 | case EosUpdateFirmware: return "EosUpdateFirmware";
304 | case EosRequestDevicePropValue: return "EosRequestDevicePropValue";
305 | case EosUpdateTransferCompleteDt: return "EosUpdateTransferCompleteDt";
306 | case EosCancelTransferDt: return "EosCancelTransferDt";
307 | case EosInitiateViewFinder: return "EosInitiateViewFinder";
308 | case EosTerminateViewFinder: return "EosTerminateViewFinder";
309 | case EosGetViewFinderData: return "EosgetViewFinderData";
310 | case EosDriveLens: return "EosDriveLens";
311 | case EosDepthOfFieldPreview: return "EosDepthOfFieldPreview";
312 | case EosClickWB: return "EosClickWB";
313 | case EosSetLiveAFFrame: return "EosSetLiveAFFrame";
314 | case EosZoom: return "EosZoom";
315 | case EosZoomPosition: return "EosZoomPostion";
316 | case EosGetFWTProfile: return "EosGetFWTProfile";
317 | case EosSetFWTProfile: return "EosSetFWTProfile";
318 | case EosSetProfileToWTF: return "EosSetProfileToWTF";
319 | case EosBulbStart: return "EosBulbStart";
320 | case EosBulbEnd: return "EosBulbEnd";
321 | case EosRemoeReleaseOn: return "EosRemoeReleaseOn";
322 | case EosRemoeReleaseOff: return "EosRemoeReleaseOff";
323 | case EosDoAF: return "EosDoAF";
324 | case EosAFCancel: return "EosAFCancel";
325 | case EosRegistBackgroundImage: return "EosRegistBackgroundImage";
326 | case EosChangePhotoStadIOMode: return "EosChangePhotoStadIOMode";
327 | case EosGetPartialObjectEx: return "EosGetPartialObjectEx";
328 | case EosResetMirrorLockupState: return "EosResetMirrorLockupState";
329 | case EosPopupBuiltinFlash: return "EosPopupBuiltinFlash";
330 | case EosEndGetPartialObjectEx: return "EosEndGetPartialObjectEx";
331 | case EosMovieSelectSWOn: return "EosMovieSelectSWOn";
332 | case EosMovieSelectSWOff: return "EosMovieSelectSWOff";
333 | case EosSetEventMode: return "EosSetEventMode";
334 | case MtpGetObjectPropsSupported: return "MtpGetObjectPropsSupported";
335 | case MtpGetObjectPropDesc: return "MtpGetObjectPropDesc";
336 | case MtpGetObjectPropValue: return "MtpGetObjectPropValue";
337 | case MtpSetObjectPropValue: return "MtpSetObjectPropValue";
338 | case MtpGetObjPropList: return "GetObjPropList";
339 | }
340 |
341 | return Container.getCodeString(code);
342 | }
343 | }
344 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/Container.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 | import java.io.PrintStream;
21 |
22 |
23 | /**
24 | * PTP Command, Data, Response, and Event blocks use a "Generic Container
25 | * Structure" as a packet header.
26 | *
27 | * Note that since the string values to which various codes map
28 | * have been interned, you may safely rely on "==" and "!=" when you
29 | * make comparisons against constant values.
30 | *
31 | * @version $Id: Container.java,v 1.8 2001/04/12 23:13:00 dbrownell Exp $
32 | * @author David Brownell
33 | */
34 | abstract public class Container extends Buffer
35 | {
36 | public static final int BLOCK_TYPE_COMMAND = 1;
37 | public static final int BLOCK_TYPE_DATA = 2;
38 | public static final int BLOCK_TYPE_RESPONSE = 3;
39 | public static final int BLOCK_TYPE_EVENT = 4;
40 |
41 | protected NameFactory factory;
42 |
43 | // get/put object handles (not 0, ~0) using session context
44 | // Session session;
45 |
46 | // fixed header layout, per annex D
47 | // NOTE: session id (9.3.2) is implicit: no multisession over USB
48 | // @ 0, u32 length
49 | // @ 4, u16 buffer type
50 | // @ 6, u16 code
51 | // @ 8, u32 xid
52 | // TOTAL: 12 bytes
53 | static final int HDR_LEN = 12;
54 |
55 | public Container (byte buf [], NameFactory f)
56 | { super (buf, buf.length); factory = f; }
57 |
58 | public Container (byte buf [], int len, NameFactory f)
59 | { super (buf, len); factory = f; }
60 |
61 | // package private
62 | public void putHeader (int len, int type, int code, int xid)
63 | {
64 | if (offset != 0)
65 | throw new IllegalStateException ();
66 | put32 (len);
67 | put16 (type);
68 | put16 (code);
69 | put32 (xid);
70 | }
71 |
72 |
73 | /**
74 | * Provides a printable representation of data from the block
75 | * header, including block type, code, and transaction ID.
76 | */
77 | public String toString ()
78 | {
79 | StringBuffer temp = new StringBuffer ();
80 | String type = getBlockTypeName (getBlockType ());
81 | int code = getCode ();
82 |
83 | temp.append ("{ ");
84 | temp.append (type);
85 | temp.append ("; len ");
86 | temp.append (Integer.toString (getLength ()));
87 | temp.append ("; ");
88 | temp.append (getCodeName (code));
89 | temp.append ("; xid ");
90 | temp.append (Integer.toString (getXID ()));
91 |
92 | // inelegant, but ...
93 | if (this instanceof ParamVector) {
94 | ParamVector vec = (ParamVector) this;
95 | int nparams = vec.getNumParams ();
96 |
97 | if (nparams > 0) {
98 | temp.append ("; ");
99 | for (int i = 0; i < nparams; i++) {
100 | if (i != 0)
101 | temp.append (" ");
102 | temp.append ("0x");
103 | temp.append (Integer.toHexString (vec.getParam (i)));
104 | }
105 | }
106 | }
107 |
108 | temp.append (" }");
109 | return temp.toString ();
110 | }
111 |
112 | void dump (PrintStream out)
113 | {
114 | out.println (toString ());
115 | }
116 |
117 |
118 | void parse ()
119 | {
120 | offset = HDR_LEN;
121 | }
122 |
123 | /** Returns the overall length of this data block, including header. */
124 | public int getLength ()
125 | { return /* unsigned */ getS32 (0); }
126 |
127 | /**
128 | * Returns the overall type of this data block as a coded integer.
129 | */
130 | public final int getBlockType ()
131 | { return getU16 (4); }
132 |
133 | /**
134 | * Returns an interned string, normally "command", "data", "response",
135 | * or "event", corresponding to the coded type. Unrecognized or
136 | * undefined values are returned as interned Integer.toHexString values.
137 | */
138 | public static final String getBlockTypeName (int type)
139 | {
140 | switch (type) {
141 | case 1: return "command";
142 | case 2: return "data";
143 | case 3: return "response";
144 | case 4: return "event";
145 | default: return Integer.toHexString (type).intern ();
146 | }
147 | }
148 |
149 | /**
150 | * Returns the operation, response, or event code of this block.
151 | */
152 | public final int getCode ()
153 | {
154 | return getU16 (6);
155 | }
156 |
157 | /**
158 | * Returns an interned string identifying the type of code field,
159 | * such as "OperationCode", "ResponseCode", "ObjectFormatCode",
160 | * "EventCode", or "DevicePropsCode". Unrecognized or undefined
161 | * values are returned as interned Integer.toHexString values.
162 | */
163 | public static final String getCodeType (int code)
164 | {
165 | switch (code >> 12) {
166 | case 1: return "OperationCode";
167 | case 2: return "ResponseCode";
168 | case 3: return "ObjectFormatCode";
169 | case 4: return "EventCode";
170 | case 5: return "DevicePropCode";
171 | case 8 + 1: return "Vendor-OpCode";
172 | case 8 + 2: return "Vendor-ResponseCode";
173 | case 8 + 3: return "Vendor-FormatCode";
174 | case 8 + 4: return "Vendor-EventCode";
175 | case 8 + 5: return "Vendor-PropCode";
176 | default: return Integer.toHexString (code >> 12).intern ();
177 | }
178 | }
179 |
180 | /**
181 | * Subclasses override this to map PTP codes to their names; the
182 | * results are always interned strings, so that they can be efficiently
183 | * compared ("=", "!=") against constants. Such per-instance methods
184 | * permit type-specific subclasses (and vendor extensions) to name their
185 | * code values, invoking superclass methods to name all other codes.
186 | */
187 | public String getCodeName (int code)
188 | {
189 | return getCodeString (code);
190 | }
191 |
192 | /**
193 | * Returns an interned string with name of this container's code.
194 | */
195 | public final String getCodeString ()
196 | {
197 | return getCodeName (getCode ()).intern ();
198 | }
199 |
200 | /**
201 | * Returns an interned string with the hexadecimal value of
202 | * the specified container code.
203 | */
204 | public static String getCodeString (int code)
205 | {
206 | return Integer.toHexString (code).intern ();
207 | }
208 |
209 | /**
210 | * Returns the ID of the transaction this block is associated with.
211 | */
212 | public final int getXID ()
213 | { return getS32 (8); }
214 | }
215 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/Data.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 |
21 | /**
22 | * The optional middle phase of a PTP transaction involves sending
23 | * data to or from the responder.
24 | *
25 | * @version $Id: Data.java,v 1.4 2001/04/12 23:13:00 dbrownell Exp $
26 | * @author David Brownell
27 | */
28 | public class Data extends Container
29 | {
30 | private boolean in;
31 |
32 | public Data (NameFactory f) { this (true, null, 0, f); }
33 |
34 | public Data (boolean isIn, byte buf [], NameFactory f)
35 | { super (buf, f); in = isIn; }
36 |
37 | public Data (boolean isIn, byte buf [], int len, NameFactory f)
38 | { super (buf, len, f); in = isIn; }
39 |
40 | boolean isIn ()
41 | { return in; }
42 |
43 | public String getCodeName (int code)
44 | {
45 | return factory.getOpcodeString (code);
46 | }
47 |
48 | public String toString ()
49 | {
50 | StringBuffer temp = new StringBuffer ();
51 | int code = getCode ();
52 |
53 | temp.append ("{ ");
54 | temp.append (getBlockTypeName (getBlockType ()));
55 | if (in)
56 | temp.append (" IN");
57 | else
58 | temp.append (" OUT");
59 | temp.append ("; len ");
60 | temp.append (Integer.toString (getLength ()));
61 | temp.append ("; ");
62 | temp.append (factory.getOpcodeString (code));
63 | temp.append ("; xid ");
64 | temp.append (Integer.toString (getXID ()));
65 | temp.append ("}");
66 | return temp.toString ();
67 | }
68 | }
69 |
70 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/DeviceInfo.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 | import java.io.PrintStream;
21 |
22 |
23 | /**
24 | * DeviceInfo describes device functionality such supported image formats,
25 | * operations, events, and device properties.
26 | *
27 | * @version $Id: DeviceInfo.java,v 1.8 2001/04/12 23:13:00 dbrownell Exp $
28 | * @author David Brownell
29 | */
30 | public class DeviceInfo extends Data
31 | {
32 | // need some transport-neutral interface; this is USB-specific
33 |
34 | int standardVersion;
35 | int vendorExtensionId;
36 | int vendorExtensionVersion;
37 | String vendorExtensionDesc;
38 |
39 | int functionalMode; // may change;
40 | int operationsSupported []; // 10.2
41 | int eventsSupported []; // 12.5
42 | int propertiesSupported []; // 13.3.5
43 |
44 | int captureFormats []; // 6
45 | int imageFormats []; // 6
46 | String manufacturer;
47 | String model;
48 |
49 | String deviceVersion;
50 | String serialNumber;
51 |
52 | // FIXME add formal vendor hooks, which we'd consult for string
53 | // mappings ... we don't have any here.
54 |
55 | // Command, Response, ObjectInfo, Event, and DevicePropDesc can
56 | // all be subclassed; but we won't have instances here. And
57 | // there's also the vendor extension stuff here.
58 |
59 |
60 | // input -- we can't know buffer size yet
61 | DeviceInfo (NameFactory f)
62 | { super (true, null, 0, f); }
63 |
64 |
65 | private boolean supports (int supported [], int code)
66 | {
67 | for (int i = 0; i < supported.length; i++) {
68 | if (code == supported [i])
69 | return true;
70 | }
71 | return false;
72 | }
73 |
74 |
75 | /** Returns true iff the device supports this operation */
76 | public boolean supportsOperation (int opCode)
77 | {
78 | return supports (operationsSupported, opCode);
79 | }
80 |
81 | /** Returns true iff the device supports this event */
82 | public boolean supportsEvent (int eventCode)
83 | {
84 | return supports (eventsSupported, eventCode);
85 | }
86 |
87 | /** Returns true iff the device supports this property */
88 | public boolean supportsProperty (int propCode)
89 | {
90 | return supports (propertiesSupported, propCode);
91 | }
92 |
93 | /** Returns true iff the device supports this capture format */
94 | public boolean supportsCaptureFormat (int formatCode)
95 | {
96 | return supports (captureFormats, formatCode);
97 | }
98 |
99 | /** Returns true iff the device supports this image format */
100 | public boolean supportsImageFormat (int formatCode)
101 | {
102 | return supports (imageFormats, formatCode);
103 | }
104 |
105 |
106 | // fit names to standard length lines
107 | private int addString (PrintStream out, int last, String s)
108 | {
109 | last += s.length ();
110 | last++;
111 | if (last < 80) {
112 | out.print (s);
113 | out.print (" ");
114 | } else {
115 | out.println ();
116 | out.print ("\t");
117 | out.print (s);
118 | out.print (" ");
119 | last = 8 + s.length () + 1;
120 | }
121 | return last;
122 | }
123 |
124 | void parse ()
125 | {
126 | super.parse ();
127 |
128 | standardVersion = nextU16 ();
129 | vendorExtensionId = /* unsigned */ nextS32 ();
130 | vendorExtensionVersion = nextU16 ();
131 | vendorExtensionDesc = nextString ();
132 |
133 | functionalMode = nextU16 ();
134 | operationsSupported = nextU16Array ();
135 | eventsSupported = nextU16Array ();
136 | propertiesSupported = nextU16Array ();
137 |
138 | captureFormats = nextU16Array ();
139 | imageFormats = nextU16Array ();
140 | manufacturer = nextString ();
141 | model = nextString ();
142 |
143 | deviceVersion = nextString ();
144 | serialNumber = nextString ();
145 | }
146 |
147 | void lines (PrintStream out)
148 | {
149 | if (manufacturer != null)
150 | out.println ("Manufacturer: " + manufacturer);
151 | if (model != null)
152 | out.println ("Model: " + model);
153 | if (deviceVersion != null)
154 | out.println ("Device Version: " + deviceVersion);
155 | if (serialNumber != null)
156 | out.println ("Serial Number: " + serialNumber);
157 |
158 | if (functionalMode != 0) {
159 | out.print ("Functional Mode: ");
160 | out.println (funcMode (functionalMode));
161 | }
162 |
163 | if (vendorExtensionId != 0) {
164 | out.print ("Extensions (");
165 | out.print (Integer.toString (vendorExtensionId));
166 | out.print (")");
167 | if (vendorExtensionDesc != null) {
168 | out.print (": ");
169 | out.print (vendorExtensionDesc);
170 | }
171 | out.println ();
172 |
173 | // summarize extension: ops, props, events
174 | }
175 | }
176 |
177 | public String toString ()
178 | {
179 |
180 | if (operationsSupported == null) {
181 | // System.err.println ("... device info uninitted");
182 | return "... device info uninitted";
183 | }
184 | String result = "DeviceInfo:\n";
185 | result += ("PTP Version: "
186 | + (standardVersion / 100)
187 | + "."
188 | + (standardVersion % 100));
189 |
190 | // per chapter 10
191 | result += ("\n\nOperations Supported:");
192 | for (int i = 0; i < operationsSupported.length; i++) {
193 | result += "\n\t" +factory.getOpcodeString (operationsSupported [i]);
194 | }
195 |
196 | // per chapter 11
197 | result += ("\n\nEvents Supported:");
198 | for (int i = 0; i < eventsSupported.length; i++) {
199 | result += "\n\t" +factory.getEventString (eventsSupported [i]);
200 | }
201 |
202 | // per chapter 13
203 | result += ("\n\nDevice Properties Supported:\n");
204 | for (int i = 0; i < propertiesSupported.length; i++) {
205 | result += "\t" +factory.getPropertyName (propertiesSupported [i]);
206 | }
207 |
208 | // per 6.2
209 | result += ("\n\nCapture Formats Supported:\n");
210 | for (int i = 0; i < captureFormats.length; i++) {
211 | result += "\t" +factory.getFormatString (captureFormats [i]);
212 | }
213 |
214 | // per 6.2
215 | result += ("\n\nImage Formats Supported:\n");
216 | for (int i = 0; i < imageFormats.length; i++) {
217 | result += "\t" + factory.getFormatString (imageFormats [i]);
218 | }
219 |
220 | if (vendorExtensionId != 0) {
221 | result += ("\n\nVendor Extension, id ");
222 | result += (Integer.toString (vendorExtensionId));
223 | result += (", version ");
224 | result += (standardVersion / 100);
225 | result += (".");
226 | result += (standardVersion % 100);
227 |
228 | if (vendorExtensionDesc != null) {
229 | result += "\nDescription: " +vendorExtensionDesc;
230 | }
231 | }
232 | return result;
233 | }
234 |
235 | static String funcMode (int functionalMode)
236 | {
237 | switch (functionalMode) {
238 | case 0:
239 | return "standard";
240 | case 1:
241 | return "sleeping";
242 | default:
243 | // FIXME add vendor hook
244 | StringBuffer buf = new StringBuffer ();
245 |
246 | if ((functionalMode & 0x8000) == 0)
247 | buf.append ("reserved 0x");
248 | else
249 | buf.append ("vendor 0x");
250 | buf.append (Integer.toHexString (functionalMode & ~0x8000));
251 | return buf.toString ();
252 | }
253 | }
254 | }
255 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/DevicePropDesc.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 | //Copyright 2000 by David Brownell
21 | //
22 | // This program is free software; you can redistribute it and/or modify
23 | // it under the terms of the GNU General Public License as published by
24 | // the Free Software Foundation; either version 2 of the License, or
25 | // (at your option) any later version.
26 | //
27 | // This program is distributed in the hope that it will be useful,
28 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
29 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 | // GNU General Public License for more details.
31 | //
32 | // You should have received a copy of the GNU General Public License
33 | // along with this program; if not, write to the Free Software
34 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 | //
36 |
37 |
38 |
39 | import java.io.PrintStream;
40 | import java.util.Vector;
41 |
42 | import android.widget.TextView;
43 |
44 |
45 | /**
46 | * DeviceProperty descriptions provide metadata (code, type, factory
47 | * defaults, is-it-writable, and perhaps value ranges or domains) and
48 | * current values of device properties.
49 | *
50 | * The values exposed are typically java.lang.Integer
,
51 | * java.lang.Long
, "int" or "long" arrays,
52 | * or Strings, and must be cast to more specific types.
53 | * The 64 bit integral types are supported, but not the 128 bit ones;
54 | * unsigned 64 bit values may not print as intended.
55 | *
56 | * @version $Id: DevicePropDesc.java,v 1.7 2001/04/12 23:13:00 dbrownell Exp $
57 | * @author David Brownell
58 | */
59 | public class DevicePropDesc extends Data
60 | {
61 | int propertyCode;
62 | int dataType;
63 | boolean writable;
64 | Object factoryDefault;
65 | Object currentValue;
66 | int formType;
67 | Object constraints;
68 |
69 | public DevicePropDesc (NameFactory f) { super (f); }
70 |
71 | public void parse ()
72 | {
73 | super.parse ();
74 |
75 | // per 13.3.3, tables 23, 24, 25
76 | propertyCode = nextU16 ();
77 | dataType = nextU16 ();
78 | writable = nextU8 () != 0;
79 |
80 | // FIXME use factories, as vendor hooks
81 | factoryDefault = DevicePropValue.get (dataType, this);
82 | currentValue = DevicePropValue.get (dataType, this);
83 |
84 | formType = nextU8 ();
85 | switch (formType) {
86 | case 0: // no more
87 | break;
88 | case 1: // range: min, max, step
89 | constraints = new Range (dataType, this);
90 | break;
91 | case 2: // enumeration: n, value1, ... valueN
92 | constraints = parseEnumeration ();
93 | break;
94 | default:
95 | System.err.println ("ILLEGAL prop desc form, " + formType);
96 | formType = 0;
97 | break;
98 | }
99 | }
100 | public void showInTextView (TextView tv)
101 | {
102 |
103 | tv.setText(factory.getPropertyName (propertyCode));
104 | tv.append (" = ");
105 | tv.append (""+currentValue);
106 | if (!writable)
107 | tv.append (", read-only");
108 | tv.append (", ");
109 | tv.append (DevicePropValue.getTypeName (dataType));
110 | switch (formType) {
111 | case 0:
112 | break;
113 | case 1: {
114 | Range r = (Range) constraints;
115 | tv.append (" from ");
116 | tv.append (""+r.getMinimum ());
117 | tv.append (" to ");
118 | tv.append (""+r.getMaximum ());
119 | tv.append (" by ");
120 | tv.append (""+r.getIncrement ());
121 | };
122 | break;
123 | case 2: {
124 | Vector v = (Vector) constraints;
125 | tv.append (" { ");
126 | for (int i = 0; i < v.size (); i++) {
127 | if (i != 0)
128 | tv.append (", ");
129 | tv.append (""+v.elementAt (i));
130 | }
131 | tv.append (" }");
132 | }
133 | break;
134 | default:
135 | tv.append (" form ");
136 | tv.append (""+formType);
137 | tv.append (" (error)");
138 | }
139 |
140 | tv.append (", default ");
141 | tv.append ("\n");
142 | tv.append ("Factory Default:"+factoryDefault);
143 | }
144 |
145 |
146 | void dump (PrintStream out)
147 | {
148 | super.dump (out);
149 |
150 | out.print (factory.getPropertyName (propertyCode));
151 | out.print (" = ");
152 | out.print (currentValue);
153 | if (!writable)
154 | out.print (", read-only");
155 | out.print (", ");
156 | out.print (DevicePropValue.getTypeName (dataType));
157 | switch (formType) {
158 | case 0:
159 | break;
160 | case 1: {
161 | Range r = (Range) constraints;
162 | out.print (" from ");
163 | out.print (r.getMinimum ());
164 | out.print (" to ");
165 | out.print (r.getMaximum ());
166 | out.print (" by ");
167 | out.print (r.getIncrement ());
168 | };
169 | break;
170 | case 2: {
171 | Vector v = (Vector) constraints;
172 | out.print (" { ");
173 | for (int i = 0; i < v.size (); i++) {
174 | if (i != 0)
175 | out.print (", ");
176 | out.print (v.elementAt (i));
177 | }
178 | out.print (" }");
179 | }
180 | break;
181 | default:
182 | out.print (" form ");
183 | out.print (formType);
184 | out.print (" (error)");
185 | }
186 |
187 | out.print (", default ");
188 | out.println (factoryDefault);
189 | }
190 |
191 | /** Returns true if the property is writable */
192 | public boolean isWritable ()
193 | { return writable; }
194 |
195 | /** Returns the current value (treat as immutable!) */
196 | public Object getValue ()
197 | { return currentValue; }
198 |
199 | /** Returns the factory default value (treat as immutable!) */
200 | public Object getDefault ()
201 | { return factoryDefault; }
202 |
203 |
204 | // code values, per 13.3.5 table 26
205 |
206 | public static final int BatteryLevel = 0x5001;
207 | public static final int FunctionalMode = 0x5002;
208 | public static final int ImageSize = 0x5003;
209 |
210 | public static final int CompressionSetting = 0x5004;
211 | public static final int WhiteBalance = 0x5005;
212 | public static final int RGBGain = 0x5006;
213 | public static final int FStop = 0x5007;
214 |
215 | public static final int FocalLength = 0x5008;
216 | public static final int FocusDistance = 0x5009;
217 | public static final int FocusMode = 0x500a;
218 | public static final int ExposureMeteringMode = 0x500b;
219 |
220 | public static final int FlashMode = 0x500c;
221 | public static final int ExposureTime = 0x500d;
222 | public static final int ExposureProgramMode = 0x500e;
223 | public static final int ExposureIndex = 0x500f;
224 |
225 | public static final int ExposureBiasCompensation = 0x5010;
226 | public static final int DateTime = 0x5011;
227 | public static final int CaptureDelay = 0x5012;
228 | public static final int StillCaptureMode = 0x5013;
229 |
230 | public static final int Contrast = 0x5014;
231 | public static final int Sharpness = 0x5015;
232 | public static final int DigitalZoom = 0x5016;
233 | public static final int EffectMode = 0x5017;
234 |
235 | public static final int BurstNumber = 0x5018;
236 | public static final int BurstInterval = 0x5019;
237 | public static final int TimelapseNumber = 0x501a;
238 | public static final int TimelapseInterval = 0x501b;
239 |
240 | public static final int FocusMeteringMode = 0x501c;
241 | public static final int UploadURL = 0x501d;
242 | public static final int Artist = 0x501e;
243 | public static final int CopyrightInfo = 0x501f;
244 |
245 |
246 | public String getCodeName (int code)
247 | {
248 | return factory.getPropertyName (code);
249 | }
250 |
251 | static class NameMap {
252 | int value;
253 | String name;
254 | NameMap (int v, String n) { value = v; name = n; }
255 | }
256 |
257 | static NameMap names [] = {
258 | new NameMap (BatteryLevel, "BatteryLevel"),
259 | new NameMap (FunctionalMode, "FunctionalMode"),
260 | new NameMap (ImageSize, "ImageSize"),
261 | new NameMap (CompressionSetting, "CompressionSetting"),
262 | new NameMap (WhiteBalance, "WhiteBalance"),
263 | new NameMap (RGBGain, "RGBGain"),
264 | new NameMap (FStop, "FStop"),
265 | new NameMap (FocalLength, "FocalLength"),
266 | new NameMap (FocusDistance, "FocusDistance"),
267 | new NameMap (FocusMode, "FocusMode"),
268 | new NameMap (ExposureMeteringMode, "ExposureMeteringMode"),
269 | new NameMap (FlashMode, "FlashMode"),
270 | new NameMap (ExposureTime, "ExposureTime"),
271 | new NameMap (ExposureProgramMode, "ExposureProgramMode"),
272 | new NameMap (ExposureIndex, "ExposureIndex"),
273 | new NameMap (ExposureBiasCompensation, "ExposureBiasCompensation"),
274 | new NameMap (DateTime, "DateTime"),
275 | new NameMap (CaptureDelay, "CaptureDelay"),
276 | new NameMap (StillCaptureMode, "StillCaptureMode"),
277 | new NameMap (Contrast, "Contrast"),
278 | new NameMap (Sharpness, "Sharpness"),
279 | new NameMap (DigitalZoom, "DigitalZoom"),
280 | new NameMap (EffectMode, "EffectMode"),
281 | new NameMap (BurstNumber, "BurstNumber"),
282 | new NameMap (BurstInterval, "BurstInterval"),
283 | new NameMap (TimelapseNumber, "TimelapseNumber"),
284 | new NameMap (TimelapseInterval, "TimelapseInterval"),
285 | new NameMap (FocusMeteringMode, "FocusMeteringMode"),
286 | new NameMap (UploadURL, "UploadURL"),
287 | new NameMap (Artist, "Artist"),
288 | new NameMap (CopyrightInfo, "CopyrightInfo"),
289 | };
290 |
291 | static String _getPropertyName (int code)
292 | {
293 | for (int i = 0; i < names.length; i++)
294 | if (names [i].value == code)
295 | return names [i].name;
296 | return Container.getCodeString (code);
297 | }
298 |
299 | /**
300 | * Maps standard property names to property codes.
301 | * Case is ignored in these comparisons.
302 | * @param name string identifying that property.
303 | * @return device property code, or -1
304 | */
305 | public static int getPropertyCode (String name)
306 | {
307 | for (int i = 0; i < names.length; i++)
308 | if (names [i].name.equalsIgnoreCase (name))
309 | return names [i].value;
310 |
311 | // FIXME: delegate to superclass
312 | return Integer.parseInt (name, 16);
313 | }
314 |
315 |
316 | /**
317 | * This class describes value ranges by minima, maxima,
318 | * and permissible increments.
319 | */
320 | public static final class Range
321 | {
322 | private Object min, max, step;
323 |
324 | Range (int dataType, DevicePropDesc desc)
325 | {
326 | min = DevicePropValue.get (dataType, desc);
327 | max = DevicePropValue.get (dataType, desc);
328 | step = DevicePropValue.get (dataType, desc);
329 | }
330 |
331 | /** Returns the maximum value of this range */
332 | public Object getMaximum () { return max; }
333 |
334 | /** Returns the minimum value of this range */
335 | public Object getMinimum () { return min; }
336 |
337 | /** Returns the increment of values in this range */
338 | public Object getIncrement () { return step; }
339 | }
340 |
341 | /** Returns any range constraints for this property's value, or null */
342 | public Range getRange ()
343 | {
344 | if (formType == 1)
345 | return (Range) constraints;
346 | return null;
347 | }
348 |
349 |
350 | private Vector parseEnumeration ()
351 | {
352 | int len = nextU16 ();
353 | Vector retval = new Vector (len);
354 |
355 | while (len-- > 0)
356 | retval.addElement (DevicePropValue.get (dataType, this));
357 | return retval;
358 | }
359 |
360 |
361 | /** Returns any enumerated options for this property's value, or null */
362 | public Vector getEnumeration ()
363 | {
364 | if (formType == 2)
365 | return (Vector) constraints;
366 | return null;
367 | }
368 | }
369 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/DevicePropValue.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 | import java.io.PrintStream;
21 |
22 | import android.widget.TextView;
23 |
24 |
25 | /**
26 | * DeviceProperty values wrap various types of integers and
27 | * arrays of integers, and strings. It's sort of like a
28 | * CORBA "Any", pairing a typecode and value, except that
29 | * the typecode is known in advance so it's never marshaled.
30 | *
31 | * @see DevicePropDesc
32 | *
33 | * @version $Id: DevicePropValue.java,v 1.4 2001/04/12 23:13:00 dbrownell Exp $
34 | * @author David Brownell
35 | */
36 | public class DevicePropValue extends Data
37 | {
38 | int typecode;
39 | Object value;
40 |
41 | DevicePropValue (int tc, NameFactory f)
42 | { super (f); typecode = tc; }
43 |
44 | private DevicePropValue (int tc, Object obj, NameFactory f)
45 | {
46 | super (f);
47 | typecode = tc;
48 | value = obj;
49 |
50 | // FIXME: marshal value into the buffer.
51 | }
52 |
53 | public Object getValue ()
54 | { return value; }
55 |
56 | public int getTypeCode ()
57 | { return typecode; }
58 |
59 | void parse ()
60 | {
61 | value = get (typecode, this);
62 | }
63 |
64 | void dump (PrintStream out)
65 | {
66 | out.print ("Type: ");
67 | out.print (getTypeName (typecode));
68 | out.print (", Value: ");
69 | out.println (value.toString ());
70 | }
71 |
72 | void showInTextView (TextView tv)
73 | {
74 | tv.setText ("Type: ");
75 | tv.append (getTypeName (typecode));
76 | tv.append (", Value: ");
77 | tv.append ("\n");
78 | tv.append (value.toString ());
79 | }
80 |
81 | public String getCodeName (int code)
82 | {
83 | return getTypeName (code);
84 | }
85 |
86 | static Object get (int code, Buffer buf)
87 | {
88 | Object value;
89 |
90 | switch (code) {
91 | case s8:
92 | return new Integer (buf.nextS8 ());
93 | case u8:
94 | return new Integer (buf.nextU8 ());
95 | case s16:
96 | return new Integer (buf.nextS16 ());
97 | case u16:
98 | return new Integer (buf.nextU16 ());
99 | case s32:
100 | return new Integer (buf.nextS32 ());
101 | case u32:
102 | return new Long (0x0ffFFffFFL & buf.nextS32 ());
103 | case s64:
104 | return new Long (buf.nextS64 ());
105 | case u64:
106 | // FIXME: unsigned masquerading as signed ...
107 | return new Long (buf.nextS64 ());
108 |
109 | // case s128: case u128:
110 |
111 | case s8array:
112 | return buf.nextS8Array ();
113 | case u8array:
114 | return buf.nextU8Array ();
115 | case s16array:
116 | return buf.nextS16Array ();
117 | case u16array:
118 | return buf.nextU16Array ();
119 | case u32array:
120 | // FIXME: unsigned masquerading as signed ...
121 | case s32array:
122 | return buf.nextS32Array ();
123 | case u64array:
124 | // FIXME: unsigned masquerading as signed ...
125 | case s64array:
126 | return buf.nextS64Array ();
127 | // case s128array: case u128array:
128 |
129 | case string:
130 | return buf.nextString ();
131 | }
132 | throw new IllegalArgumentException ();
133 | }
134 |
135 | // code values, per 5.3 table 3
136 |
137 | public static final int s8 = 0x0001;
138 | /** Unsigned eight bit integer */
139 | public static final int u8 = 0x0002;
140 | public static final int s16 = 0x0003;
141 | /** Unsigned sixteen bit integer */
142 | public static final int u16 = 0x0004;
143 | public static final int s32 = 0x0005;
144 | /** Unsigned thirty two bit integer */
145 | public static final int u32 = 0x0006;
146 | public static final int s64 = 0x0007;
147 | /** Unsigned sixty four bit integer */
148 | public static final int u64 = 0x0008;
149 | public static final int s128 = 0x0009;
150 | /** Unsigned one hundred twenty eight bit integer */
151 | public static final int u128 = 0x000a;
152 | public static final int s8array = 0x4001;
153 | /** Array of unsigned eight bit integers */
154 | public static final int u8array = 0x4002;
155 | public static final int s16array = 0x4003;
156 | /** Array of unsigned sixteen bit integers */
157 | public static final int u16array = 0x4004;
158 | public static final int s32array = 0x4005;
159 | /** Array of unsigned thirty two bit integers */
160 | public static final int u32array = 0x4006;
161 | public static final int s64array = 0x4007;
162 | /** Array of unsigned sixty four bit integers */
163 | public static final int u64array = 0x4008;
164 | public static final int s128array = 0x4009;
165 | /** Array of unsigned one hundred twenty eight bit integers */
166 | public static final int u128array = 0x400a;
167 | /** Unicode string */
168 | public static final int string = 0xffff;
169 |
170 | /**
171 | * Maps datatype codes to string names.
172 | * @param code datatype code
173 | * @return interned string identifying that datatype.
174 | */
175 | public static String getTypeName (int code)
176 | {
177 | switch (code) {
178 | case s8: return "s8";
179 | case u8: return "u8";
180 | case s16: return "s16";
181 | case u16: return "u16";
182 | case s32: return "s32";
183 | case u32: return "u32";
184 | case s64: return "s64";
185 | case u64: return "u64";
186 | case s128: return "s128";
187 | case u128: return "u128";
188 | case s8array: return "s8array";
189 | case u8array: return "u8array";
190 | case s16array: return "s16array";
191 | case u16array: return "u16array";
192 | case s32array: return "s32array";
193 | case u32array: return "u32array";
194 | case s64array: return "s64array";
195 | case u64array: return "u64array";
196 | case s128array: return "s128array";
197 | case u128array: return "u128array";
198 | case string: return "string";
199 | }
200 | return Container.getCodeString (code);
201 | }
202 | }
203 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/Event.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | // Copyright 2010 by Stefano Fornari
3 | //
4 | // This program is free software; you can redistribute it and/or modify
5 | // it under the terms of the GNU General Public License as published by
6 | // the Free Software Foundation; either version 2 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU General Public License
15 | // along with this program; if not, write to the Free Software
16 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 | //
18 | package com.ptplib.usbcamera;
19 |
20 | /**
21 | * Events are sent spontaneously from responders to initiators.
22 | * Event codes, described in chapter 12 of the PTP specification,
23 | * identify what happened. Some events have a parameter, and
24 | * additional data (for vendor extensions) may be available
25 | * using the class control request "Get Extended Event Data".
26 | *
27 | * @author David Brownell
28 | * @author Stefano Fonari
29 | */
30 | public class Event extends ParamVector {
31 |
32 | public Event(byte buf[], NameFactory f) {
33 | super(buf, buf.length, f);
34 | }
35 | /** EventCode: */
36 | public static final int Undefined = 0x4000;
37 | /** EventCode: */
38 | public static final int CancelTransaction = 0x4001;
39 | /** EventCode: */
40 | public static final int ObjectAdded = 0x4002;
41 | /** EventCode: */
42 | public static final int ObjectRemoved = 0x4003;
43 | /** EventCode: */
44 | public static final int StoreAdded = 0x4004;
45 | /** EventCode: */
46 | public static final int StoreRemoved = 0x4005;
47 | /** EventCode: */
48 | public static final int DevicePropChanged = 0x4006;
49 | /** EventCode: */
50 | public static final int ObjectInfoChanged = 0x4007;
51 | /** EventCode: */
52 | public static final int DeviceInfoChanged = 0x4008;
53 | /** EventCode: */
54 | public static final int RequestObjectTransfer = 0x4009;
55 | /** EventCode: */
56 | public static final int StoreFull = 0x400a;
57 | /** EventCode: */
58 | public static final int DeviceReset = 0x400b;
59 | /** EventCode: */
60 | public static final int StorageInfoChanged = 0x400c;
61 | /** EventCode: */
62 | public static final int CaptureComplete = 0x400d;
63 | /** EventCode: a status event was dropped (missed an interrupt) */
64 | public static final int UnreportedStatus = 0x400e;
65 |
66 | public String getCodeName(int code) {
67 | return factory.getEventString(code);
68 | }
69 |
70 | static public String _getEventString(int code) {
71 | switch (code) {
72 | case Undefined:
73 | return "Undefined";
74 | case CancelTransaction:
75 | return "CancelTransaction";
76 | case ObjectAdded:
77 | return "ObjectAdded";
78 | case ObjectRemoved:
79 | return "ObjectRemoved";
80 |
81 | case StoreAdded:
82 | return "StoreAdded";
83 | case StoreRemoved:
84 | return "StoreRemoved";
85 | case DevicePropChanged:
86 | return "DevicePropChanged";
87 | case ObjectInfoChanged:
88 | return "ObjectInfoChanged";
89 |
90 | case DeviceInfoChanged:
91 | return "DeviceInfoChanged";
92 | case RequestObjectTransfer:
93 | return "RequestObjectTransfer";
94 | case StoreFull:
95 | return "StoreFull";
96 | case DeviceReset:
97 | return "DeviceReset";
98 |
99 | case StorageInfoChanged:
100 | return "StorageInfoChanged";
101 | case CaptureComplete:
102 | return "CaptureComplete";
103 | case UnreportedStatus:
104 | return "UnreportedStatus";
105 |
106 |
107 | }
108 | return getCodeString(code);
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/FileSendData.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 | import java.io.InputStream;
21 | import java.io.IOException;
22 | import java.net.URLConnection;
23 |
24 |
25 | /**
26 | * Used with {@link BaselineInitiator#sendObject sendObject}, this can read
27 | * objects from files using a relatively small amount of in-memory buffering.
28 | * That reduces system resource requirements for working with large files
29 | * such as uncompressed TIF images supported by higher end imaging devices.
30 | *
31 | * @see BaselineInitiator#sendObject
32 | *
33 | * @version $Id: FileSendData.java,v 1.3 2001/04/12 23:13:00 dbrownell Exp $
34 | * @author David Brownell
35 | */
36 | public class FileSendData extends Data
37 | {
38 | private InputStream in;
39 | private int filesize;
40 |
41 | // FIXME: shouldn't be "File" streams
42 |
43 | /**
44 | * Constructs a data object which fills the given underlying file.
45 | */
46 | public FileSendData (URLConnection data, NameFactory f)
47 | throws IOException
48 | {
49 | super (false, new byte [128 * 1024], f);
50 | in = data.getInputStream ();
51 | filesize = data.getContentLength ();
52 | }
53 |
54 | public int getLength ()
55 | {
56 | return HDR_LEN + filesize;
57 | }
58 |
59 | /**
60 | * Reads object data from the underlying file.
61 | */
62 | public int read (byte buf [], int off, int len)
63 | throws IOException
64 | {
65 | return in.read (buf, off, len);
66 | }
67 |
68 | /**
69 | * Closes the underlying file.
70 | */
71 | public void close ()
72 | throws IOException
73 | {
74 | in.close ();
75 | }
76 | }
77 |
78 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/KodakExtension.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 | import java.net.URLConnection;
21 |
22 | /**
23 | * This class packages the vendor extension published by
24 | * Eastman Kodak Corporation, which has promised to openly
25 | * publish the complete specification needed to use these.
26 | *
27 | * @version $Id: KodakExtension.java,v 1.1 2001/04/12 23:13:00 dbrownell Exp $
28 | */
29 | class KodakExtension extends NameFactory
30 | {
31 | // FIXME: this should eventually host APIs for the
32 | // specialized commands, so it'll need to subclass
33 | // at least BaselineInitiator (so it can do I/O).
34 |
35 | KodakExtension () { }
36 |
37 |
38 | /*-------------------------------------------------------------*/
39 |
40 | /**
41 | * This is like SendObjectInfo. However, things like
42 | * the association ("MUSIC") need to be filled in;
43 | * there are no optional parameters.
44 | */
45 | public static final int SendFileObjectInfo = 0x9005;
46 |
47 | /**
48 | * This is SendObject, except that it was preceded
49 | * by SendFileObjectInfo
50 | */
51 | public static final int SendFileObject = 0x9006;
52 |
53 |
54 | public String getOpcodeString (int code)
55 | {
56 | switch (code) {
57 | case SendFileObjectInfo:
58 | return "Kodak_SendFileObjectInfo";
59 | case SendFileObject:
60 | return "Kodak_SendFileObject";
61 | }
62 | return Command._getOpcodeString (code);
63 | }
64 |
65 | /*-------------------------------------------------------------*/
66 |
67 | /** ResponseCode: */
68 | public static final int FilenameRequired = 0xa001;
69 |
70 | /** ResponseCode: */
71 | public static final int FilenameConflicts = 0xa002;
72 |
73 | /** ResponseCode: */
74 | public static final int FilenameInvalid = 0xa003;
75 |
76 | public String getResponseString (int code)
77 | {
78 | switch (code) {
79 | case FilenameRequired:
80 | return "Kodak_FilenameRequired";
81 | case FilenameConflicts:
82 | return "Kodak_FilenameConflicts";
83 | case FilenameInvalid:
84 | return "Kodak_FilenameInvalid";
85 | }
86 | return Response._getResponseString (code);
87 | }
88 |
89 | /*-------------------------------------------------------------*/
90 |
91 | /** ObjectFormatCode: ".fw" file for device firmware. */
92 | public static final int Firmware = 0xb001;
93 |
94 | /** ObjectFormatCode: ".m3u" style MP3 playlist. */
95 | public static final int M3U = 0xb002;
96 |
97 |
98 | public String getFormatString (int code)
99 | {
100 | switch (code) {
101 | case Firmware:
102 | return "Kodak_Firmware";
103 | case M3U:
104 | return "Kodak_M3U";
105 | }
106 | return ObjectInfo._getFormatString (code);
107 | }
108 |
109 | /*-------------------------------------------------------------*/
110 |
111 | /** Property code: */
112 | public static final int prop1 = 0xd001;
113 |
114 | /** Property code: */
115 | public static final int prop2 = 0xd002;
116 |
117 | /** Property code: */
118 | public static final int prop3 = 0xd003;
119 |
120 | /** Property code: */
121 | public static final int prop4 = 0xd004;
122 |
123 | /** Property code: */
124 | public static final int prop5 = 0xd005;
125 |
126 | /** Property code: */
127 | public static final int prop6 = 0xd006;
128 |
129 | public String getPropertyName (int code)
130 | {
131 | switch (code) {
132 | case prop1:
133 | return "Kodak_prop1";
134 | case prop2:
135 | return "Kodak_prop2";
136 | case prop3:
137 | return "Kodak_prop3";
138 | case prop4:
139 | return "Kodak_prop4";
140 | case prop5:
141 | return "Kodak_prop5";
142 | case prop6:
143 | return "Kodak_prop6";
144 | }
145 | return DevicePropDesc._getPropertyName (code);
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/NameFactory.java:
--------------------------------------------------------------------------------
1 | // Copyright 2001 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 | /**
21 | * Supports use of objects using vendor extension codes.
22 | * The base class produces names only for standard PTP
23 | * operations, responses, properties, events, and formats.
24 | *
25 | * @version $Id: NameFactory.java,v 1.1 2001/04/12 23:13:00 dbrownell Exp $
26 | */
27 | public class NameFactory
28 | {
29 | // package private
30 | protected NameFactory () { }
31 |
32 | // package private
33 | protected NameFactory updateFactory (int vendorExtensionId)
34 | {
35 | switch (vendorExtensionId) {
36 | case 0: return this;
37 | case 1: return new KodakExtension ();
38 | }
39 | if (BaselineInitiator.DEBUG)
40 | System.err.println ("Don't know extension " + vendorExtensionId);
41 | return this;
42 | }
43 |
44 | /*
45 | static String vendorToString (int vendorExtensionId)
46 | {
47 | switch (vendorExtensionId) {
48 | // from PIMA website
49 | case 1: return "Eastman Kodak Company";
50 | case 2: return "Seiko Epson";
51 | case 3: return "Agilent Technologies, Inc.";
52 | case 4: return "Polaroid Corporation";
53 | case 5: return "Agfa-Gevaert";
54 | case 6: return "Microsoft Corporation";
55 | default:
56 | return "0x" + Integer.toHexString (vendorExtensionId);
57 | }
58 | }
59 | */
60 |
61 | /**
62 | * Maps command codes to string names.
63 | * @param code device command code
64 | * @return interned string identifying that command.
65 | */
66 | // bits 14:12 = 001
67 | public String getOpcodeString (int code)
68 | { return Command._getOpcodeString (code); }
69 |
70 | /**
71 | * Maps response codes to string names.
72 | * @param code response code
73 | * @return interned string identifying that response.
74 | */
75 | // bits 14:12 = 010
76 | public String getResponseString (int code)
77 | { return Response._getResponseString (code); }
78 |
79 | /**
80 | * Maps object format codes to string names.
81 | * @param code device format code
82 | * @return interned string identifying that format.
83 | */
84 | // bits 14:12 = 011
85 | public String getFormatString (int code)
86 | { return ObjectInfo._getFormatString (code); }
87 |
88 | /**
89 | * Maps event codes to string names.
90 | * @param code device event code
91 | * @return interned string identifying that event.
92 | */
93 | // bits 14:12 = 100
94 | public String getEventString (int code)
95 | { return Event._getEventString (code); }
96 |
97 | /**
98 | * Maps property codes to string names.
99 | * @param code device property code
100 | * @return interned string identifying that property.
101 | */
102 | // bits 14:12 = 101
103 | public String getPropertyName (int code)
104 | { return DevicePropDesc._getPropertyName (code); }
105 |
106 |
107 | // FIXME: hooks for vendor-specific filesystem types.
108 | }
109 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/OutputStreamData.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2010 by Stefano Fornari
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | */
17 | package com.ptplib.usbcamera;
18 |
19 | import java.io.FileOutputStream;
20 | import java.io.IOException;
21 | import java.io.OutputStream;
22 |
23 | /**
24 | * Used with {@link BaselineInitiator#fillObject fillObject}, this writes
25 | * objects to a give output stream.
26 | *
27 | * @see BaselineInitiator#fillObject
28 | *
29 | * @author ste
30 | */
31 | public class OutputStreamData extends Data {
32 |
33 | private OutputStream out;
34 |
35 | /**
36 | * Constructs a data object which fills the given underlying file.
37 | */
38 | public OutputStreamData(OutputStream o, NameFactory f) {
39 | super(f);
40 | out = o;
41 | }
42 |
43 | /**
44 | * Writes object data to the underlying output stream
45 | */
46 | public void write(byte buf[], int off, int len) throws IOException {
47 | out.write(buf, off, len);
48 | }
49 |
50 | /**
51 | * Closes the underlying output stream.
52 | */
53 | public void close() throws IOException {
54 | out.close();
55 | }
56 |
57 | @Override
58 | final void parse() {
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/PTPBusyException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * cameracontrol
3 | * Copyright (C) 2010 Stefano Fornari
4 | *
5 | * This program is free software; you can redistribute it and/or modify it under
6 | * the terms of the GNU Affero General Public License version 3 as published by
7 | * the Free Software Foundation with the addition of the following permission
8 | * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
9 | * WORK IN WHICH THE COPYRIGHT IS OWNED BY Stefano Fornari, Stefano Fornari
10 | * DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11 | *
12 | * This program is distributed in the hope that it will be useful, but WITHOUT
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 | * details.
16 | *
17 | * You should have received a copy of the GNU Affero General Public License
18 | * along with this program; if not, see http://www.gnu.org/licenses or write to
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 | * MA 02110-1301 USA.
21 | */
22 |
23 | package com.ptplib.usbcamera;
24 |
25 | /**
26 | *
27 | * @author ste
28 | */
29 | public class PTPBusyException extends PTPException {
30 |
31 | /**
32 | * Creates a new instance of PTPBusyException
without detail message.
33 | */
34 | public PTPBusyException() {
35 | super("Device is busy");
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/PTPException.java:
--------------------------------------------------------------------------------
1 | // Copyright 2010 by Stefano Fornari
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 | package com.ptplib.usbcamera;
18 |
19 | public class PTPException extends Exception {
20 |
21 | private int errorCode;
22 |
23 | public PTPException() {
24 | this("");
25 | }
26 |
27 | public PTPException(int errorCode) {
28 | this("", null, errorCode);
29 | }
30 |
31 | public PTPException(String string) {
32 | this(string, null);
33 | }
34 |
35 | public PTPException(String string, int errorCode) {
36 | this(string, null, errorCode);
37 | }
38 |
39 | public PTPException(String string, Throwable t) {
40 | this(string, t, Response.Undefined);
41 | }
42 |
43 | public PTPException(String string, Throwable t, int errorCode) {
44 | super(string, t);
45 | this.errorCode = errorCode;
46 | }
47 |
48 | public int getErrorCode() {
49 | return errorCode;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/PTPUnsupportedException.java:
--------------------------------------------------------------------------------
1 | // Copyright 2010 by Stefano Fornari
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 | package com.ptplib.usbcamera;
18 |
19 | public class PTPUnsupportedException extends PTPException {
20 |
21 | public PTPUnsupportedException(String string) {
22 | super(string);
23 | }
24 |
25 | public PTPUnsupportedException(String string, Throwable t) {
26 | super(string, t);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/ParamVector.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 | import java.io.PrintStream;
21 |
22 |
23 | /**
24 | * This class is used for PTP messages consisting of only a set of
25 | * thirty-two bit parameters, such as commands, responses, and events.
26 | *
27 | * @version $Id: ParamVector.java,v 1.4 2001/04/12 23:13:00 dbrownell Exp $
28 | * @author David Brownell
29 | */
30 | public class ParamVector extends Container
31 | {
32 | ParamVector (byte buf [], NameFactory f)
33 | { super (buf, f); }
34 |
35 | ParamVector (byte buf [], int len, NameFactory f)
36 | { super (buf, len, f); }
37 |
38 | /** Returns the first positional parameter. */
39 | public final int getParam1 ()
40 | { return getS32 (12); }
41 |
42 | /** Returns the second positional parameter. */
43 | public final int getParam2 ()
44 | { return getS32 (16); }
45 |
46 | /** Returns the third positional parameter. */
47 | public final int getParam3 ()
48 | { return getS32 (20); }
49 |
50 | /** Returns the number of parameters in this data block */
51 | public final int getNumParams ()
52 | { return (length - MIN_LEN) / 4; }
53 |
54 |
55 | // no params
56 | static final int MIN_LEN = HDR_LEN;
57 |
58 | // allegedly some responses could have five params
59 | static final int MAX_LEN = 32;
60 |
61 |
62 | // NOTE: params in the spec are numbered from one, not zero
63 | int getParam (int i)
64 | { return getS32 (12 + (4 * i)); }
65 |
66 | void dump (PrintStream out)
67 | {
68 | out.print (this.toString ());
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/Response.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 |
21 | /**
22 | * The final phase of a PTP transaction sends a command's response from
23 | * the responder to the initiator. These include response codes, and are
24 | * described in chapter 11 of the PTP specification.
25 | *
26 | * @version $Id: Response.java,v 1.2 2001/04/12 23:13:00 dbrownell Exp $
27 | * @author David Brownell
28 | */
29 | public class Response extends ParamVector
30 | {
31 | Response (byte buf [], NameFactory f)
32 | { super (buf, f); }
33 |
34 | public Response (byte buf [], int len, NameFactory f)
35 | { super (buf, len, f); }
36 |
37 |
38 | /** ResponseCode: */
39 | public static final int Undefined = 0x2000;
40 | /** ResponseCode: */
41 | public static final int OK = 0x2001;
42 | /** ResponseCode: */
43 | public static final int GeneralError = 0x2002;
44 | /** ResponseCode: */
45 | public static final int SessionNotOpen = 0x2003;
46 |
47 | /** ResponseCode: */
48 | public static final int InvalidTransactionID = 0x2004;
49 | /** ResponseCode: */
50 | public static final int OperationNotSupported = 0x2005;
51 | /** ResponseCode: */
52 | public static final int ParameterNotSupported = 0x2006;
53 | /** ResponseCode: */
54 | public static final int IncompleteTransfer = 0x2007;
55 |
56 | /** ResponseCode: */
57 | public static final int InvalidStorageID = 0x2008;
58 | /** ResponseCode: */
59 | public static final int InvalidObjectHandle = 0x2009;
60 | /** ResponseCode: */
61 | public static final int DevicePropNotSupported = 0x200a;
62 | /** ResponseCode: */
63 | public static final int InvalidObjectFormatCode = 0x200b;
64 |
65 | /** ResponseCode: */
66 | public static final int StoreFull = 0x200c;
67 | /** ResponseCode: */
68 | public static final int ObjectWriteProtected = 0x200d;
69 | /** ResponseCode: */
70 | public static final int StoreReadOnly = 0x200e;
71 | /** ResponseCode: */
72 | public static final int AccessDenied = 0x200f;
73 |
74 |
75 | /** ResponseCode: */
76 | public static final int NoThumbnailPresent = 0x2010;
77 | /** ResponseCode: */
78 | public static final int SelfTestFailed = 0x2011;
79 | /** ResponseCode: */
80 | public static final int PartialDeletion = 0x2012;
81 | /** ResponseCode: */
82 | public static final int StoreNotAvailable = 0x2013;
83 |
84 | /** ResponseCode: */
85 | public static final int SpecificationByFormatUnsupported = 0x2014;
86 | /** ResponseCode: */
87 | public static final int NoValidObjectInfo = 0x2015;
88 | /** ResponseCode: */
89 | public static final int InvalidCodeFormat = 0x2016;
90 | /** ResponseCode: */
91 | public static final int UnknownVendorCode = 0x2017;
92 |
93 | /** ResponseCode: */
94 | public static final int CaptureAlreadyTerminated = 0x2018;
95 | /** ResponseCode: */
96 | public static final int DeviceBusy = 0x2019;
97 | /** ResponseCode: */
98 | public static final int InvalidParentObject = 0x201a;
99 | /** ResponseCode: */
100 | public static final int InvalidDevicePropFormat = 0x201b;
101 |
102 | /** ResponseCode: */
103 | public static final int InvalidDevicePropValue = 0x201c;
104 | /** ResponseCode: */
105 | public static final int InvalidParameter = 0x201d;
106 | /** ResponseCode: */
107 | public static final int SessionAlreadyOpen = 0x201e;
108 | /** ResponseCode: */
109 | public static final int TransactionCanceled = 0x201f;
110 |
111 | /** ResponseCode: */
112 | public static final int SpecificationOfDestinationUnsupported = 0x2020;
113 |
114 |
115 | public String getCodeName (int code)
116 | {
117 | return factory.getResponseString (code);
118 | }
119 |
120 | public static String _getResponseString (int code)
121 | {
122 | switch (code) {
123 | case Undefined: return "Undefined";
124 | case OK: return "OK";
125 | case GeneralError: return "GeneralError";
126 | case SessionNotOpen: return "SessionNotOpen";
127 |
128 | case InvalidTransactionID: return "InvalidTransactionID";
129 | case OperationNotSupported: return "OperationNotSupported";
130 | case ParameterNotSupported: return "ParameterNotSupported";
131 | case IncompleteTransfer: return "IncompleteTransfer";
132 |
133 | case InvalidStorageID: return "InvalidStorageID";
134 | case InvalidObjectHandle: return "InvalidObjectHandle";
135 | case DevicePropNotSupported: return "DevicePropNotSupported";
136 | case InvalidObjectFormatCode: return "InvalidObjectFormatCode";
137 |
138 | case StoreFull: return "StoreFull";
139 | case ObjectWriteProtected: return "ObjectWriteProtected";
140 | case StoreReadOnly: return "StoreReadOnly";
141 | case AccessDenied: return "AccessDenied";
142 |
143 | case NoThumbnailPresent: return "NoThumbnailPresent";
144 | case SelfTestFailed: return "SelfTestFailed";
145 | case PartialDeletion: return "PartialDeletion";
146 | case StoreNotAvailable: return "StoreNotAvailable";
147 |
148 | case SpecificationByFormatUnsupported:
149 | return "SpecificationByFormatUnsupported";
150 | case NoValidObjectInfo: return "NoValidObjectInfo";
151 | case InvalidCodeFormat: return "InvalidCodeFormat";
152 | case UnknownVendorCode: return "UnknownVendorCode";
153 |
154 | case CaptureAlreadyTerminated: return "CaptureAlreadyTerminated";
155 | case DeviceBusy: return "DeviceBusy";
156 | case InvalidParentObject: return "InvalidParentObject";
157 | case InvalidDevicePropFormat: return "InvalidDevicePropFormat";
158 |
159 | case InvalidDevicePropValue: return "InvalidDevicePropValue";
160 | case InvalidParameter: return "InvalidParameter";
161 | case SessionAlreadyOpen: return "SessionAlreadyOpen";
162 | case TransactionCanceled: return "TransactionCanceled";
163 |
164 | case SpecificationOfDestinationUnsupported:
165 | return "SpecificationOfDestinationUnsupported";
166 | }
167 | return ("0x" + Integer.toHexString (code)).intern ();
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/Session.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 |
21 | /**
22 | * Encapsulates the session between a PTP initiator and responder.
23 | *
24 | * @version $Id: Session.java,v 1.3 2001/04/12 23:13:00 dbrownell Exp $
25 | * @author David Brownell
26 | */
27 | class Session
28 | {
29 | private int sessionId;
30 | private int xid;
31 | private boolean active;
32 | private NameFactory factory;
33 |
34 | Session () { }
35 |
36 | void setFactory (NameFactory f) { factory = f; }
37 |
38 | NameFactory getFactory () { return factory; }
39 |
40 | int getNextXID ()
41 | { return (active ? xid++ : 0); }
42 |
43 | int getNextSessionID ()
44 | {
45 | if (!active)
46 | return ++sessionId;
47 | throw new IllegalStateException ("already active");
48 | }
49 |
50 | boolean isActive ()
51 | { return active; }
52 |
53 | void open ()
54 | { xid = 1; active = true; }
55 |
56 | void close ()
57 | { active = false; }
58 |
59 | int getSessionId ()
60 | { return sessionId; }
61 |
62 | // track objects and their info by handles;
63 | // hookup to marshaling system and event framework
64 | }
65 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/StorageInfo.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 |
18 | package com.ptplib.usbcamera;
19 |
20 | import java.io.PrintStream;
21 |
22 | import android.widget.TextView;
23 |
24 | /**
25 | * StorageInfo provides information such as the type and capacity of
26 | * storage media, whether it's removable, and more.
27 | *
28 | * @version $Id: StorageInfo.java,v 1.5 2001/04/12 23:13:00 dbrownell Exp $
29 | * @author David Brownell
30 | */
31 | public class StorageInfo extends Data
32 | {
33 | int storageType;
34 | int filesystemType;
35 | int accessCapability;
36 | long maxCapacity;
37 |
38 | long freeSpaceInBytes;
39 | int freeSpaceInImages;
40 | String storageDescription;
41 | String volumeLabel;
42 |
43 | StorageInfo (NameFactory f) { super (f); }
44 |
45 | void parse ()
46 | {
47 | super.parse ();
48 |
49 | storageType = nextU16 ();
50 | filesystemType = nextU16 ();
51 | accessCapability = nextU16 ();
52 | maxCapacity = /* unsigned */ nextS64 ();
53 | freeSpaceInBytes = /* unsigned */ nextS64 ();
54 | freeSpaceInImages = /* unsigned */ nextS32 ();
55 | storageDescription = nextString ();
56 | volumeLabel = nextString ();
57 | }
58 |
59 | void line (PrintStream out)
60 | {
61 | String temp;
62 |
63 | switch (storageType) {
64 | case 0: temp = "undefined"; break;
65 | case 1: temp = "Fixed ROM"; break;
66 | case 2: temp = "Removable ROM"; break;
67 | case 3: temp = "Fixed RAM"; break;
68 | case 4: temp = "Removable RAM"; break;
69 | default:
70 | temp = "Reserved-0x" + Integer.toHexString (storageType);
71 | }
72 | out.println ("Storage Type: " + temp);
73 | }
74 |
75 | void line (TextView tv)
76 | {
77 | String temp;
78 |
79 | switch (storageType) {
80 | case 0: temp = "undefined"; break;
81 | case 1: temp = "Fixed ROM"; break;
82 | case 2: temp = "Removable ROM"; break;
83 | case 3: temp = "Fixed RAM"; break;
84 | case 4: temp = "Removable RAM"; break;
85 | default:
86 | temp = "Reserved-0x" + Integer.toHexString (storageType);
87 | }
88 | tv.append ("Storage Type: " + temp +" \n");
89 | }
90 |
91 | void dump (PrintStream out)
92 | {
93 | String temp;
94 |
95 | super.dump (out);
96 | out.println ("StorageInfo:");
97 | line (out);
98 |
99 | switch (filesystemType) {
100 | case 0: temp = "undefined"; break;
101 | case 1: temp = "flat"; break;
102 | case 2: temp = "hierarchical"; break;
103 | case 3: temp = "dcf"; break;
104 | default:
105 | if ((filesystemType & 0x8000) != 0)
106 | temp = "Reserved-0x";
107 | else
108 | temp = "Vendor-0x";
109 | temp += Integer.toHexString (filesystemType);
110 | }
111 | out.println ("Filesystem Type: " + temp);
112 |
113 | // access: rw, ro, or ro "with object deletion"
114 |
115 | // CF card sizes are "marketing megabytes", not real ones
116 | if (maxCapacity != ~0)
117 | out.println ("Capacity: "
118 | + maxCapacity + " bytes ("
119 | + ((maxCapacity + 500000)/1000000) + " MB)"
120 | );
121 | if (freeSpaceInBytes != ~0)
122 | out.println ("Free space: "
123 | + freeSpaceInBytes + " bytes ("
124 | + ((freeSpaceInBytes + 500000)/1000000) + " MB)"
125 | );
126 | if (freeSpaceInImages != ~0)
127 | out.println ("Free space in Images: " + freeSpaceInImages);
128 |
129 | if (storageDescription != null)
130 | out.println ("Description: " + storageDescription);
131 | if (volumeLabel != null)
132 | out.println ("Volume Label: " + volumeLabel);
133 | }
134 |
135 |
136 | void showInTextView (TextView tv)
137 | {
138 | String temp;
139 |
140 |
141 | tv.setText ("StorageInfo:");
142 | tv.append ("\n");
143 | line (tv);
144 |
145 | switch (filesystemType) {
146 | case 0: temp = "undefined"; break;
147 | case 1: temp = "flat"; break;
148 | case 2: temp = "hierarchical"; break;
149 | case 3: temp = "dcf"; break;
150 | default:
151 | if ((filesystemType & 0x8000) != 0)
152 | temp = "Reserved-0x";
153 | else
154 | temp = "Vendor-0x";
155 | temp += Integer.toHexString (filesystemType);
156 | }
157 | tv.append ("\n");
158 | tv.append ("Filesystem Type: " + temp);
159 |
160 | // access: rw, ro, or ro "with object deletion"
161 |
162 | // CF card sizes are "marketing megabytes", not real ones
163 | if (maxCapacity != ~0)
164 | {
165 | tv.append ("\n");
166 | tv.append ("Capacity: "
167 | + maxCapacity + " bytes ("
168 | + ((maxCapacity + 500000)/1000000) + " MB)"
169 | );
170 | }
171 | if (freeSpaceInBytes != ~0)
172 | {
173 | tv.append ("\n");
174 | tv.append ("Free space: "
175 | + freeSpaceInBytes + " bytes ("
176 | + ((freeSpaceInBytes + 500000)/1000000) + " MB)"
177 | );
178 | }
179 | if (freeSpaceInImages != ~0)
180 | {
181 | tv.append ("\n");
182 | tv.append ("Free space in Images: " + freeSpaceInImages);
183 | }
184 | if (storageDescription != null)
185 | {
186 | tv.append ("\n");
187 | tv.append ("Description: " + storageDescription);
188 | }
189 | if (volumeLabel != null)
190 | {
191 | tv.append ("\n");
192 | tv.append ("Volume Label: " + volumeLabel);
193 | }
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/eos/EosEvent.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2010 by Stefano Fornari
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | */
17 |
18 | package com.ptplib.usbcamera.eos;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 |
24 |
25 | /**
26 | *
27 | * @author ste
28 | */
29 | public class EosEvent implements EosEventConstants {
30 |
31 | /**
32 | * Event code
33 | */
34 | private int code;
35 |
36 | /**
37 | * Params
38 | */
39 | private List params;
40 |
41 | /**
42 | * Creates a new parser with the given data
43 | *
44 | * @param data the events data - NOT NULL
45 | */
46 | public EosEvent() {
47 | params = new ArrayList();
48 | }
49 |
50 | public void setCode(int code) {
51 | this.code = code;
52 | }
53 |
54 | public int getCode() {
55 | return code;
56 | }
57 |
58 | /**
59 | * @param i the parameter index
60 | * @param param the param to set
61 | */
62 | public void setParam(int i, Object value) {
63 | if (i<0) {
64 | throw new IllegalArgumentException("param index cannot be < 0");
65 | }
66 | if (params.size() <= i) {
67 | ArrayList newParams = new ArrayList(i);
68 | newParams.addAll(params);
69 | params = newParams;
70 | for (int j=params.size(); j getParamCount())) {
83 | throw new IllegalArgumentException(
84 | "index " + i + " out of range (0-" + getParamCount() + ")"
85 | );
86 | }
87 | return params.get(i-1);
88 | }
89 |
90 | public int getIntParam(int i) {
91 | return ((Integer)getParam(i)).intValue();
92 | }
93 |
94 | public String getStringParam(int i) {
95 | return (String)getParam(i);
96 | }
97 |
98 | /**
99 | *
100 | * @return the number of parameters in this event
101 | */
102 | public int getParamCount() {
103 | return params.size();
104 | }
105 |
106 | public static String getEventName (int code){
107 | switch (code) {
108 | case EosEventRequestGetEvent : return "EosEventRequestGetEvent";
109 | case EosEventObjectAddedEx : return "EosEventObjectAddedEx";
110 | case EosEventObjectRemoved : return "EosEventObjectRemoved";
111 | case EosEventRequestGetObjectInfoEx : return "EosEventRequestGetObjectInfoEx";
112 | case EosEventStorageStatusChanged : return "EosEventStorageStatusChanged";
113 | case EosEventStorageInfoChanged : return "EosEventStorageInfoChanged";
114 | case EosEventRequestObjectTransfer : return "EosEventRequestObjectTransfer";
115 | case EosEventObjectInfoChangedEx : return "EosEventObjectInfoChangedEx";
116 | case EosEventObjectContentChanged : return "EosEventObjectContentChanged";
117 | case EosEventPropValueChanged : return "EosEventPropValueChanged";
118 | case EosEventAvailListChanged : return "EosEventAvailListChanged";
119 | case EosEventCameraStatusChanged : return "EosEventCameraStatusChanged";
120 | case EosEventWillSoonShutdown : return "EosEventWillSoonShutdown";
121 | case EosEventShutdownTimerUpdated : return "EosEventShutdownTimerUpdated";
122 | case EosEventRequestCancelTransfer : return "EosEventRequestCancelTransfer";
123 | case EosEventRequestObjectTransferDT : return "EosEventRequestObjectTransferDT";
124 | case EosEventRequestCancelTransferDT : return "EosEventRequestCancelTransferDT";
125 | case EosEventStoreAdded : return "EosEventStoreAdded";
126 | case EosEventStoreRemoved : return "EosEventStoreRemoved";
127 | case EosEventBulbExposureTime : return "EosEventBulbExposureTime";
128 | case EosEventRecordingTime : return "EosEventRecordingTime";
129 | case EosEventAfResult : return "EosEventRequestObjectTransferTS";
130 | case EosEventRequestObjectTransferTS : return "EosEventAfResult";
131 | }
132 | return "0x" +Integer.toHexString(code);
133 | }
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/eos/EosEventFormat.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2010 by Stefano Fornari
2 | *
3 | * This program is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation; either version 2 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program; if not, write to the Free Software
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | */
17 | package com.ptplib.usbcamera.eos;
18 |
19 | import java.lang.reflect.Field;
20 |
21 | /**
22 | * This class formats an EosEvent to a string
23 | *
24 | * @author stefano fornari
25 | */
26 | public class EosEventFormat implements EosEventConstants {
27 | public static String format(EosEvent e) {
28 | StringBuilder sb = new StringBuilder();
29 |
30 | int eventCode = e.getCode();
31 |
32 | sb.append(getEventName(eventCode));
33 | sb.append(" [ ");
34 | if (eventCode == EosEventPropValueChanged) {
35 | int propCode = e.getIntParam(1);
36 | sb.append(getPropertyName(propCode))
37 | .append(": ");
38 |
39 | if ((propCode >= EosPropPictureStyleStandard) &&
40 | (propCode <= EosPropPictureStyleUserSet3)) {
41 | sb.append("(Sharpness: ")
42 | .append(e.getIntParam(4))
43 | .append(", Contrast: ")
44 | .append(e.getIntParam(3));
45 | if (((Boolean)e.getParam(2)).booleanValue()) {
46 | sb.append(", Filter effect: ")
47 | .append(getFilterEffect(e.getIntParam(5)))
48 | .append(", Toning effect: ")
49 | .append(getToningEffect(e.getIntParam(6)));
50 | } else {
51 | sb.append(", Saturation: ")
52 | .append(e.getIntParam(5))
53 | .append(", Color tone: ")
54 | .append(e.getIntParam(6));
55 | }
56 | sb.append(")");
57 | } else {
58 | if (e.getParamCount()>1) {
59 | sb.append(e.getIntParam(2));
60 | }
61 | }
62 | } else if (eventCode == EosEventObjectAddedEx) {
63 | sb.append(formatEosEventObjectAddedEx(e));
64 | }
65 | sb.append(" ]");
66 |
67 | return sb.toString();
68 | }
69 |
70 | /**
71 | * Returns the printable name of the given event
72 | *
73 | * @param code event code
74 | *
75 | * @return the printable name of the given event
76 | */
77 | public static String getEventName(int code) {
78 | Field[] fields = EosEventConstants.class.getDeclaredFields();
79 |
80 | for (Field f: fields) {
81 | String name = f.getName();
82 | if (name.startsWith("EosEvent")) {
83 | try {
84 | if (f.getInt(null) == code) {
85 | return name;
86 | }
87 | } catch (Exception e) {
88 | //
89 | // Nothing to do
90 | //
91 | }
92 | }
93 | }
94 | return "Unknown";
95 | }
96 |
97 | /**
98 | * Returns the printable name of the given property
99 | *
100 | * @param code property code
101 | *
102 | * @return the printable name of the given property
103 | */
104 | public static String getPropertyName(int code) {
105 | return getCodeName("EosProp", code);
106 | }
107 |
108 | /**
109 | * Returns the printable name of the given image format
110 | *
111 | * @param code image format code
112 | *
113 | * @return the printable name of the given image format
114 | */
115 | public static String getImageFormatName(int code) {
116 | return getCodeName("ImageFormat", code);
117 | }
118 |
119 | /**
120 | * Returns the filter effect name given the code. Names are:
121 | * 0:None, 1:Yellow, 2:Orange, 3:Red, 4:Green
122 | *
123 | * @param code the filter effect code (0-4)
124 | *
125 | * @return the filter effect name
126 | */
127 | public static String getFilterEffect(int code) {
128 | if ((code < 0) || (code > 4)) {
129 | throw new IllegalArgumentException("code must be in he range 0-4");
130 | }
131 |
132 | switch (code) {
133 | case 0: return "None";
134 | case 1: return "Yellow";
135 | case 2: return "Orange";
136 | case 3: return "Red";
137 | case 4: return "Green";
138 | }
139 |
140 | //
141 | // We should never get here
142 | //
143 | return "Unknown";
144 | }
145 |
146 | /**
147 | * Returns the toning effect name given the code. Names are:
148 | * 0:None, 1:Sepia, 2:Blue, 3:Purple, 4:Green
149 | *
150 | * @param code the toning effect code (0-4)
151 | *
152 | * @return the toning effect name
153 | */
154 | public static String getToningEffect(int code) {
155 | if ((code < 0) || (code > 4)) {
156 | throw new IllegalArgumentException("code must be in he range 0-4");
157 | }
158 |
159 | switch (code) {
160 | case 0: return "None";
161 | case 1: return "Sepia";
162 | case 2: return "Blue";
163 | case 3: return "Purple";
164 | case 4: return "Green";
165 | }
166 |
167 | //
168 | // We should never get here
169 | //
170 | return "Unknown";
171 | }
172 |
173 | // --------------------------------------------------------- Private methods
174 |
175 | private static String formatEosEventObjectAddedEx(EosEvent event) {
176 | return String.format(
177 | "Filename: %s, Size(bytes): %d, ObjectID: 0x%08X, StorageID: 0x%08X, ParentID: 0x%08X, Format: %s",
178 | event.getStringParam(6),
179 | event.getIntParam(5),
180 | event.getIntParam(1),
181 | event.getIntParam(2),
182 | event.getIntParam(3),
183 | getImageFormatName(event.getIntParam(4))
184 | );
185 | }
186 |
187 | /**
188 | * Looks up and returns the name of the code give if there is a constant
189 | * field in EosEventConstants which starts with the given prefix
190 | *
191 | * @param prefix the field name prefix
192 | * @param code image format code
193 | *
194 | * @return the printable name of the given code
195 | */
196 | private static String getCodeName(String prefix, int code) {
197 | Field[] fields = EosEventConstants.class.getDeclaredFields();
198 |
199 | for (Field f: fields) {
200 | String name = f.getName();
201 | if (name.startsWith(prefix)) {
202 | try {
203 | if (f.getInt(null) == code) {
204 | return name.substring(prefix.length());
205 | }
206 | } catch (Exception e) {
207 | //
208 | // Nothing to do
209 | //
210 | }
211 | }
212 | }
213 | return "Unknown";
214 | }
215 |
216 | }
217 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/eos/EosEventParser.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2010 by Stefano Fornari
2 | *
3 | * This program is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation; either version 2 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program; if not, write to the Free Software
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | */
17 |
18 | package com.ptplib.usbcamera.eos;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 |
23 | import android.util.Log;
24 |
25 | import com.ptplib.usbcamera.PTPException;
26 | import com.ptplib.usbcamera.PTPUnsupportedException;
27 |
28 | /**
29 | * This class parses a stream of bytes as a sequence of events accordingly
30 | * to how Canon EOS returns events.
31 | *
32 | * The event information is returned in a standard PTP data packet as a number
33 | * of records followed by an empty record at the end of the packet. Each record
34 | * consists of multiple four-byte fields and always starts with record length
35 | * field. Further structure of the record depends on the device property code
36 | * which always goes in the third field. The empty record consists of the size
37 | * field and four byte empty field, which is always zero.
38 | *
39 | * @author stefano fornari
40 | */
41 | public class EosEventParser implements EosEventConstants {
42 |
43 | /**
44 | * The stream data are read from
45 | */
46 | private InputStream is;
47 |
48 | /**
49 | * Creates a new parser to parse the given input stream
50 | *
51 | * @param is
52 | */
53 | public EosEventParser(InputStream is) {
54 | if (is == null) {
55 | throw new IllegalArgumentException("The input stream cannot be null");
56 | }
57 |
58 | this.is = is;
59 | }
60 |
61 | /**
62 | * Returns true is there are events in the stream (and the stream is still
63 | * open), false otherwise.
64 | *
65 | * @return true is there are events in the stream (and the stream is still
66 | * open), false otherwise.
67 | */
68 | public boolean hasEvents() {
69 | try {
70 | // Log.d("EventParser", " available: " +is.available());
71 | if (is.available() <= 0) {
72 | return false;
73 | }
74 | } catch (IOException e) {
75 | return false;
76 | }
77 |
78 | return true;
79 | }
80 |
81 | /**
82 | * Returns the next event in the stream.
83 | *
84 | * @return the next event in the stream.
85 | *
86 | * @throws PTPException in case of errors
87 | */
88 | public EosEvent getNextEvent() throws PTPException {
89 | EosEvent event = new EosEvent();
90 |
91 | try {
92 | int len = getNextS32(); // len
93 | // Log.d("EventParser", " Len: " +len);
94 | if (len < 0x8) {
95 | throw new PTPUnsupportedException("Unsupported event (size<8 ???)");
96 | }
97 | int code = getNextS32();
98 | event.setCode(code);
99 | Log.d("EventParser", " Event len: " +len +", Code: 0x" +String.format("%04x", code) +" " +EosEvent.getEventName(code));
100 | parseParameters(event, len-8);
101 | // Log.d("EventParser", " Event: params " +event.getParamCount());
102 | for (int i = 1; i<= event.getParamCount(); i++)
103 | Log.d("EventParser", " params " +i +": " +String.format("0x%04x %d",event.getParam(i), event.getParam(i)));
104 | } catch (IOException e) {
105 | Log.d ("EventParser", " Error reading event stream");
106 | throw new PTPException("Error reading event stream", e);
107 | }
108 |
109 | return event;
110 | }
111 |
112 |
113 | // --------------------------------------------------------- Private methods
114 |
115 | private void parseParameters(EosEvent event, int len)
116 | throws PTPException, IOException {
117 | int code = event.getCode();
118 |
119 | if (code == EosEventPropValueChanged) {
120 | parsePropValueChangedParameters(event);
121 | } else if (code == EosEventShutdownTimerUpdated) {
122 | //
123 | // No parameters
124 | //
125 | } else if (code == EosEventCameraStatusChanged) {
126 | event.setParam(1, getNextS32());
127 | } else if (code == EosEventObjectAddedEx) {
128 | parseEosEventObjectAddedEx(event);
129 | } else{
130 | is.skip(len);
131 | throw new PTPUnsupportedException("Unsupported event");
132 | }
133 | }
134 |
135 | private void parsePropValueChangedParameters(EosEvent event)
136 | throws IOException {
137 | int property = getNextS32();
138 | event.setParam(1, property); // property changed
139 |
140 | if ((property >= EosPropPictureStyleStandard) &&
141 | (property <= EosPropPictureStyleUserSet3)) {
142 | boolean monochrome = (property == EosPropPictureStyleMonochrome);
143 | int size = getNextS32();
144 | if (size > 0x1C) {
145 | //
146 | // It is a EosPropPictureStyleUserXXX, let's read the type (then
147 | // we do not use it)
148 | //
149 | monochrome = (getNextS32() == EosPropPictureStyleUserTypeMonochrome);
150 | }
151 | event.setParam(2, (monochrome) ? Boolean.TRUE : Boolean.FALSE);
152 | event.setParam(3, getNextS32()); // contrast
153 | event.setParam(4, getNextS32()); // sharpness
154 | if (monochrome) {
155 | getNextS32();
156 | getNextS32();
157 | event.setParam(5, getNextS32()); // filter effect
158 | event.setParam(6, getNextS32()); // toning effect
159 | } else {
160 | event.setParam(5, getNextS32()); // saturation
161 | event.setParam(6, getNextS32()); // color tone
162 | getNextS32();
163 | getNextS32();
164 | }
165 | } else {
166 | //
167 | // default
168 | //
169 | event.setParam(2, getNextS32());
170 | }
171 |
172 | }
173 |
174 | private void parseEosEventObjectAddedEx(EosEvent event)
175 | throws IOException {
176 | event.setParam(1, getNextS32() ); // object id
177 | event.setParam(2, getNextS32() ); // storage id
178 | event.setParam(4, getNextS16() ); // format
179 | is.skip(10);
180 | event.setParam(5, getNextS32() ); // size
181 | event.setParam(3, getNextS32() ); // parent object id
182 | is.skip(4); // unknown
183 | event.setParam(6, getNextString()); // file name
184 | is.skip(4);
185 | }
186 |
187 | /**
188 | * Reads and return the next signed 32 bit integer read from the input
189 | * stream.
190 | *
191 | * @return the next signed 32 bit integer in the stream
192 | *
193 | * @throws IOException in case of IO errors
194 | */
195 | private final int getNextS32() throws IOException {
196 | int retval;
197 |
198 | retval = (0xff & is.read()) ;
199 | retval |= (0xff & is.read()) << 8;
200 | retval |= (0xff & is.read()) << 16;
201 | retval |= is.read() << 24;
202 |
203 | return retval;
204 | }
205 |
206 | /**
207 | * Reads and return the next signed 16 bit integer read from the input
208 | * stream.
209 | *
210 | * @return the next signed 16 bit integer in the stream
211 | *
212 | * @throws IOException in case of IO errors
213 | */
214 | private final int getNextS16() throws IOException {
215 | int retval;
216 |
217 | retval = (0xff & is.read()) ;
218 | retval |= (0xff & is.read()) << 8;
219 |
220 | return retval;
221 | }
222 |
223 | /**
224 | * Reads and return the next string read from the input stream. Strings are
225 | * zero (32 bit) terminated string
226 | *
227 | * @return the next string in the stream
228 | *
229 | * @throws IOException in case of IO errors
230 | */
231 | private final String getNextString() throws IOException {
232 | StringBuilder retval = new StringBuilder();
233 |
234 | char c = 0;
235 | while ((c = (char)is.read()) != 0) {
236 | retval.append(c);
237 | }
238 |
239 | //
240 | // At this point we read the string and one zero. We need to read the
241 | // remaining 3 zeros
242 | //
243 | is.skip(3);
244 |
245 | return retval.toString();
246 | }
247 |
248 | }
249 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/eos/EosInitiator.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 | package com.ptplib.usbcamera.eos;
18 |
19 | import java.io.ByteArrayInputStream;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | ////import ch.ntb.usb.*;
24 | import android.graphics.Bitmap;
25 | import android.graphics.BitmapFactory;
26 | import android.hardware.usb.UsbConstants;
27 | import android.hardware.usb.UsbDevice;
28 | import android.hardware.usb.UsbDeviceConnection;
29 | import android.hardware.usb.UsbEndpoint;
30 | import android.hardware.usb.UsbInterface;
31 | import android.hardware.usb.UsbManager;
32 | import android.hardware.usb.UsbRequest;
33 | import android.util.Log;
34 | import android.widget.ImageView;
35 |
36 |
37 | import com.ptplib.usbcamera.BaselineInitiator;
38 | import com.ptplib.usbcamera.Command;
39 | import com.ptplib.usbcamera.Container;
40 | import com.ptplib.usbcamera.Data;
41 | import com.ptplib.usbcamera.DevicePropDesc;
42 | import com.ptplib.usbcamera.PTPException;
43 | import com.ptplib.usbcamera.PTPUnsupportedException;
44 | import com.ptplib.usbcamera.Response;
45 |
46 | /**
47 | * This supports all standardized PTP-over-USB operations, including
48 | * operations (and modes) that are optional for all responders.
49 | * Filtering operations invoked on this class may be done on the device,
50 | * or may be emulated on the client side.
51 | * At this time, not all standardized operations are supported.
52 | *
53 | * @version $Id: EosInitiator.java,v 1.9 2001/04/12 23:13:00 dbrownell Exp $
54 | * @author David Brownell
55 | */
56 | public class EosInitiator extends BaselineInitiator {
57 |
58 | public static final int CANON_VID = 1193;
59 |
60 | public static boolean eventListenerRunning = false;
61 | /**
62 | * This is essentially a class driver, following Annex D of
63 | * the PTP specification.
64 | */
65 | public EosInitiator(UsbDevice dev, UsbDeviceConnection connection) throws PTPException {
66 | super(dev, connection);
67 | }
68 |
69 | /**
70 | * Fills out the provided device property description.
71 | *
72 | * @param propcode code identifying the property of interest
73 | * @param desc description to be filled; it may be a subtype
74 | * associated with with domain-specific methods
75 | * @return response code
76 | */
77 | public int getDevicePropDesc(int propcode, DevicePropDesc desc)
78 | throws PTPException {
79 | return transact1(Command.GetDevicePropDesc, desc, propcode).getCode();
80 | }
81 |
82 | /**
83 | * Checks if there is any event available. If there is any, an ArrayList
84 | * of Event object is returned.
85 | *
86 | * @return the list of available events
87 | *
88 | * @throws PTPException in case of errors
89 | */
90 | public List checkEvents()
91 | throws PTPException {
92 | int ret;
93 | // ret = transact1(Command.EosSetEventMode, null, 1).getCode(); // Prevents Releasing shutter
94 | // showResponseCode (" EosSetEventMode 1 ", ret);
95 | // if (ret != Response.OK) {
96 | // throw new PTPException("Error reading events", ret);
97 | // }
98 |
99 | Data data = new Data(this);
100 | Response res = transact0(Command.EosGetEvent, data);
101 | showResponseCode (" GetEvent: data length: " +data.getLength() +" resLength: " +res.getLength() +" EosGetEvent ", res.getCode());
102 |
103 | if (res.getCode() != Response.OK) {
104 | // throw new PTPException(String.format("Failed getting events from the camera (%1$04X)", res.getCode()));
105 | }
106 |
107 | // System.out.println("Event data:");
108 | // data.dump();
109 |
110 | //
111 | // We need to discard the initial 12 USB header bytes
112 | //
113 | byte[] buf = new byte[data.getLength() - 12];
114 | System.arraycopy(data.getData(), 12, buf, 0, buf.length);
115 |
116 | EosEventParser parser = new EosEventParser(new ByteArrayInputStream(buf));
117 |
118 | ArrayList events = new ArrayList();
119 | while (parser.hasEvents()) {
120 | try {
121 | EosEvent event = parser.getNextEvent();
122 | events.add(event);
123 | // events.add(parser.getNextEvent());
124 | } catch (PTPUnsupportedException e) {
125 | //
126 | // TODO: log this information?
127 | //
128 | //System.err.println("Skipping unsupported event");
129 | }
130 | }
131 |
132 | return events;
133 | }
134 |
135 | /**
136 | * Starts the capture of one (or more) new
137 | * data objects, according to current device properties.
138 | * The capture will complete without issuing further commands.
139 | *
140 | * @see #initiateOpenCapture
141 | *
142 | * @param storageId Where to store the object(s), or zero to
143 | * let the device choose.
144 | * @param formatCode Type of object(s) to capture, or zero to
145 | * use the device default.
146 | *
147 | * @return status code indicating whether capture started;
148 | * CaptureComplete events provide capture status, and
149 | * ObjectAdded events provide per-object status.
150 | */
151 | public Response initiateCapture(int storageId, int formatCode)
152 | throws PTPException {
153 |
154 | Response resp = null;
155 | //
156 | // Special initialization for EOS cameras
157 | //
158 | if (!info.supportsOperation(Command.EosRemoteRelease)) {
159 | Log.d(TAG, "The camera does not support EOS capture");
160 | throw new PTPException("The camera does not support EOS capture");
161 | }
162 |
163 | int ret;
164 | ret = transact1(Command.EosSetRemoteMode, null, 1).getCode();
165 | showResponseCode (" EosSetRemoteMode 1: ", ret);
166 | if (ret != Response.OK) {
167 | throw new PTPException("Unable to set remote mode", ret);
168 | }
169 |
170 | //
171 | // TODO: cover the case where initialization has already been done
172 | //
173 | // ret = transact1(Command.EosSetRemoteMode, null, 0).getCode();
174 | // showResponseCode (" EosSetRemoteMode 0 :", ret);
175 | // if (ret != Response.OK) {
176 | // throw new PTPException("Unable to set remote mode", ret);
177 | // }
178 |
179 | try { Thread.sleep(100); } catch (InterruptedException e) {e.printStackTrace();}
180 | checkEvents(); // Prevents EosRemoteRelease!
181 | try { Thread.sleep(100); } catch (InterruptedException e) {e.printStackTrace();}
182 | checkEvents(); // Prevents EosRemoteRelease!
183 | try { Thread.sleep(100); } catch (InterruptedException e) {e.printStackTrace();}
184 | checkEvents(); // Prevents EosRemoteRelease!
185 |
186 | resp = transact0(Command.EosRemoteRelease, null);
187 | ret = resp.getCode();
188 | Log.d(TAG, " EosRemoteRelease Response code: 0x" +Integer.toHexString(ret) +" OK: " +(ret == Response.OK));
189 | if (ret != Response.OK) {
190 | String msg = "Canon EOS Capture failed to release: Unknown error "
191 | + ret
192 | + " , please report.";
193 | if (ret == 1) {
194 | msg = "Canon EOS Capture failed to release: Perhaps no focus?";
195 | } else if (ret == 7) {
196 | msg = "Canon EOS Capture failed to release: Perhaps no more memory on card?";
197 | }
198 | Log.d(TAG, msg);
199 | throw new PTPException(msg, ret);
200 | }
201 | ret = transact1(Command.EosSetRemoteMode, null, 0).getCode();
202 | showResponseCode (" EosSetRemoteMode 0: ", ret);
203 | if (ret != Response.OK) {
204 | throw new PTPException("Unable to set remote mode", ret);
205 | }
206 | try { Thread.sleep(100); } catch (InterruptedException e) {e.printStackTrace();}
207 | checkEvents(); // Prevents EosRemoteRelease!
208 | try { Thread.sleep(100); } catch (InterruptedException e) {e.printStackTrace();}
209 | checkEvents(); // Prevents EosRemoteRelease!
210 | try { Thread.sleep(100); } catch (InterruptedException e) {e.printStackTrace();}
211 | checkEvents(); // Prevents EosRemoteRelease!
212 |
213 | return resp;
214 | }
215 |
216 | /**
217 | * Retrieves a chunk of the object identified by the given object id.
218 | *
219 | * @param oid object id
220 | * @param offset the offset to start from
221 | * @param size the number of bytes to transfer
222 | * @param data the Data object receiving the object
223 | *
224 | * @throws PTPException in case of errors
225 | */
226 | public void getPartialObject(int oid, int offset, int size, Data data)
227 | throws PTPException {
228 | Response ret =
229 | transact3(Command.EosGetPartialObject, data, oid, offset, size);
230 |
231 | if (ret.getCode() != Response.OK) {
232 | throw new PTPException("Error reading new object", ret.getCode());
233 | }
234 | }
235 |
236 | public void transferComplete(int oid)
237 | throws PTPException {
238 | Response ret =
239 | transact1(Command.EosTransferComplete, null, oid);
240 |
241 | if (ret.getCode() != Response.OK) {
242 | throw new PTPException("Error reading new object", ret.getCode());
243 | }
244 | }
245 |
246 | public Response setDevicePropValueEx (int property, int value) throws PTPException{
247 | byte [] buff = new byte [0x18];
248 | Data data = new Data (false, buff, buff.length, this);
249 | data.offset = 0;
250 | data.putHeader(buff.length, Container.BLOCK_TYPE_DATA, Command.EosSetDevicePropValueEx, 0 /*XID, dummy, will be overwritten*/);
251 | data.put32 (0x0c); // Length: 12 bytes
252 | data.put32 (property);
253 | data.put32 (value);
254 | return transact0(Command.EosSetDevicePropValueEx, data);
255 | }
256 |
257 | public Response getDevicePropValueEx (int property) throws PTPException{
258 | byte [] buff = new byte [0x10];
259 | Data data = new Data (false, buff, buff.length, this);
260 | data.offset = 0;
261 | data.putHeader(buff.length, Container.BLOCK_TYPE_DATA, Command.EosRequestDevicePropValue, 0 /*XID, dummy, will be overwritten*/);
262 | data.put32 (property);
263 | return transact0(Command.EosRequestDevicePropValue, data);
264 | }
265 |
266 | /*
267 | *
268 | //Doesn't work
269 | public Response setDeviceProp (int property, int value) throws PTPException{
270 | return transact3(Command.EosSetDevicePropValueEx,null,0x0c,property,value);
271 |
272 | }
273 | */
274 |
275 | public Response getShutterSpeed () throws PTPException{
276 | return getDevicePropValueEx (Command.EOS_DPC_ShutterSpeed);
277 |
278 | }
279 | public Response setShutterSpeed (int speed) throws PTPException{
280 | return setDevicePropValueEx (Command.EOS_DPC_ShutterSpeed, speed);
281 |
282 | }
283 |
284 | public Response setLiveView (boolean on) throws PTPException{
285 | if(on)
286 | {
287 | //turn on
288 | setDevicePropValueEx (Command.EOS_DPC_LiveView, 2);
289 | return setDevicePropValueEx(0xD1B3, 2);
290 | }
291 | else
292 | {
293 | //turn off
294 | return setDevicePropValueEx (Command.EOS_DPC_LiveView, 0);
295 | }
296 |
297 |
298 | }
299 |
300 | public Response startBulbs () throws PTPException{
301 |
302 | setDevicePropValueEx (Command.EOS_DPC_ShutterSpeed, EosEventConstants.SHUTTER_SPEED_BULB);
303 |
304 | // transact3(Command.EosPCHDDCapacity, null,0xfffffff8,0x00001000,0x00000000);
305 | // transact0(Command.EosSetUILock,null);
306 |
307 | return transact0(Command.EosBulbStart,null);
308 | }
309 |
310 | public Response stopBulbs () throws PTPException{
311 |
312 |
313 | // transact3(Command.EosPCHDDCapacity, null,0xffffffff,0x00001000,0x00000000);
314 | // transact3(Command.EosPCHDDCapacity, null,0xfffffffc,0x00001000,0x00000000);
315 | return transact0(Command.EosBulbEnd,null);
316 | // return transact0(Command.EosResetUILock,null);
317 | }
318 |
319 | public void GetDevicePropInfo()
320 | {
321 | int command = 0x1014;
322 | //GetDevicePropInfo PtpValues.StandardOperations.GET_DEVICE_PROP_DESC, self.sessionid, self.NewTransaction(), (propertyId,))
323 | }
324 |
325 | public Response MoveFocus(int step) throws PTPException{
326 |
327 | return transact1(Command.EosDriveLens,null,step);
328 |
329 | }
330 |
331 | public Response setExposure(int exposure) throws PTPException{
332 |
333 | return setDevicePropValueEx (Command.EOS_DPC_ExposureCompensation, exposure);
334 |
335 | }
336 |
337 | public Response setISO(int value) throws PTPException{
338 |
339 | return setDevicePropValueEx(Command.EOS_DPC_Iso ,value);
340 | }
341 |
342 | public Response setAperture(int value) throws PTPException{
343 |
344 | return setDevicePropValueEx(Command.EOS_DPC_Aperture ,value);
345 | }
346 |
347 |
348 | public Response setPictureStyle(int value) throws PTPException{
349 |
350 | return setDevicePropValueEx(Command.EOS_DPC_PictureStyle,value);
351 | }
352 |
353 | public Response setWhiteBalance(int value) throws PTPException{
354 |
355 | return setDevicePropValueEx(Command.EOS_DPC_WhiteBalance,value);
356 | }
357 |
358 | public Response setDriveMode(int value) throws PTPException{
359 |
360 | return setDevicePropValueEx(Command.EOS_DPC_DriveMode, value);
361 | }
362 |
363 | public Response setMetering(int value) throws PTPException{
364 |
365 | return setDevicePropValueEx(Command.EOS_DPC_ExpMeterringMode, value);
366 | }
367 |
368 | public Response setImageQuality(int value) throws PTPException{
369 |
370 | return setDevicePropValueEx(Command.EOS_DPC_ExpMeterringMode, value);
371 | }
372 |
373 | public void setupLiveview() throws PTPException
374 | {
375 |
376 | Command command = new Command(Command.EOS_OC_SetPCConnectMode, session, 1);
377 | write(command.data, command.length, DEFAULT_TIMEOUT);
378 | byte buf[] = read(DEFAULT_TIMEOUT);
379 |
380 | Response response = new Response (buf, inMaxPS, this);
381 |
382 | setDevicePropValueEx(Command.EOS_DPC_LiveView,2);
383 | setDevicePropValueEx(Command.EOS_DPC_LiveView,1);
384 |
385 |
386 | }
387 |
388 | public void getLiveView(final ImageView imageView)
389 | {
390 | Command command = new Command(Command.EOS_OC_GetLiveViewPicture, session,0x00100000);
391 | write(command.data, command.length, DEFAULT_TIMEOUT);
392 | byte buf[] = read(DEFAULT_TIMEOUT);
393 | Data item = new Data(true, buf, this);
394 |
395 | int totalLength = item.getLength();
396 | int left = totalLength - buf.length;
397 |
398 | int needToRead = (left/inMaxPS);
399 |
400 | if((left%inMaxPS) != 0)
401 | needToRead++;
402 |
403 | byte imageBuf[] = new byte[inMaxPS*(needToRead+1)];
404 |
405 | System.arraycopy(buf,0,imageBuf,0,512);
406 |
407 | for (int i=0; i<(needToRead); i++)
408 | {
409 |
410 | buf = read(DEFAULT_TIMEOUT);
411 | System.arraycopy(buf,0,imageBuf,512*(i+1),512);
412 |
413 |
414 | }
415 | Data completedData = new Data(true, imageBuf, this);
416 |
417 | final Bitmap bMap = BitmapFactory.decodeByteArray(completedData.data, 20, completedData.getLength()-20);
418 | Bitmap scaled = Bitmap.createScaledBitmap(bMap, bMap.getWidth()/10, bMap.getHeight()/10, false);
419 |
420 | imageView.post(new Runnable(){
421 |
422 | @Override
423 | public void run() {
424 | imageView.setImageBitmap(bMap);
425 | imageView.invalidate();
426 |
427 | }
428 |
429 | });
430 | /*
431 | tv6.setText(" Height:"+bMap.getHeight());
432 | tv6.append(" Width:"+bMap.getWidth());
433 | */
434 | byte buf1[] = read(DEFAULT_TIMEOUT);
435 |
436 | Response response = new Response (buf1, inMaxPS, this);
437 | //tv6.append(response.toString());
438 |
439 |
440 | }
441 | /////////////////////////
442 | public void setFocusPos(int x, int y)
443 | {
444 |
445 | Command command = new Command(EosEventConstants.PTP_OC_CANON_EOS_ZoomPosition,session,x,y);
446 |
447 | write(command.data, command.length, DEFAULT_TIMEOUT);
448 |
449 | byte buf[] = read(DEFAULT_TIMEOUT);
450 |
451 | //tv3.setText("Received:");
452 | Response response = new Response (buf, inMaxPS, this);
453 | //tv3.append(response.toString());
454 |
455 | }
456 |
457 | public void setZoom(int zoomLevel)
458 | {
459 | //zoomLevel = 5 or 10 or 1
460 |
461 |
462 | Command command = new Command(EosEventConstants.PTP_OC_CANON_EOS_Zoom,session,zoomLevel);
463 |
464 | write(command.data, command.length, DEFAULT_TIMEOUT);
465 |
466 | byte buf[] = read(DEFAULT_TIMEOUT);
467 |
468 | //tv3.setText("Received:");
469 | Response response = new Response (buf, inMaxPS, this);
470 | //tv3.append(response.toString());
471 |
472 | }
473 |
474 | public void doAutoFocus()
475 | {
476 |
477 | Command command = new Command(EosEventConstants.PTP_OC_CANON_EOS_DoAf, session);
478 | write(command.data, command.length, DEFAULT_TIMEOUT);
479 | byte buf[] = read(DEFAULT_TIMEOUT);
480 | //tv3.setText("Received:");
481 | Response response = new Response (buf, inMaxPS, this);
482 | //tv3.append(response.toString());
483 |
484 | }
485 |
486 | }
487 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/nikon/NikonEvent.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2010 by Stefano Fornari
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | */
17 |
18 | package com.ptplib.usbcamera.nikon;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 |
24 |
25 | /**
26 | *
27 | * @author ste
28 | */
29 | public class NikonEvent implements NikonEventConstants {
30 |
31 | /**
32 | * Event code
33 | */
34 | private int code;
35 |
36 | /**
37 | * Params
38 | */
39 | private List params;
40 |
41 | /**
42 | * Creates a new parser with the given data
43 | *
44 | * @param data the events data - NOT NULL
45 | */
46 | public NikonEvent() {
47 | params = new ArrayList();
48 | }
49 |
50 | public void setCode(int code) {
51 | this.code = code;
52 | }
53 |
54 | public int getCode() {
55 | return code;
56 | }
57 |
58 | /**
59 | * @param i the parameter index
60 | * @param param the param to set
61 | */
62 | public void setParam(int i, Object value) {
63 | if (i<0) {
64 | throw new IllegalArgumentException("param index cannot be < 0");
65 | }
66 | if (params.size() <= i) {
67 | ArrayList newParams = new ArrayList(i);
68 | newParams.addAll(params);
69 | params = newParams;
70 | for (int j=params.size(); j getParamCount())) {
83 | throw new IllegalArgumentException(
84 | "index " + i + " out of range (0-" + getParamCount() + ")"
85 | );
86 | }
87 | return params.get(i-1);
88 | }
89 |
90 | public int getIntParam(int i) {
91 | return ((Integer)getParam(i)).intValue();
92 | }
93 |
94 | public String getStringParam(int i) {
95 | return (String)getParam(i);
96 | }
97 |
98 | /**
99 | *
100 | * @return the number of parameters in this event
101 | */
102 | public int getParamCount() {
103 | return params.size();
104 | }
105 |
106 | public static String getEventName (int code){
107 | switch (code) {
108 | case EosEventRequestGetEvent : return "EosEventRequestGetEvent";
109 | case EosEventObjectAddedEx : return "EosEventObjectAddedEx";
110 | case EosEventObjectRemoved : return "EosEventObjectRemoved";
111 | case EosEventRequestGetObjectInfoEx : return "EosEventRequestGetObjectInfoEx";
112 | case EosEventStorageStatusChanged : return "EosEventStorageStatusChanged";
113 | case EosEventStorageInfoChanged : return "EosEventStorageInfoChanged";
114 | case EosEventRequestObjectTransfer : return "EosEventRequestObjectTransfer";
115 | case EosEventObjectInfoChangedEx : return "EosEventObjectInfoChangedEx";
116 | case EosEventObjectContentChanged : return "EosEventObjectContentChanged";
117 | case EosEventPropValueChanged : return "EosEventPropValueChanged";
118 | case EosEventAvailListChanged : return "EosEventAvailListChanged";
119 | case EosEventCameraStatusChanged : return "EosEventCameraStatusChanged";
120 | case EosEventWillSoonShutdown : return "EosEventWillSoonShutdown";
121 | case EosEventShutdownTimerUpdated : return "EosEventShutdownTimerUpdated";
122 | case EosEventRequestCancelTransfer : return "EosEventRequestCancelTransfer";
123 | case EosEventRequestObjectTransferDT : return "EosEventRequestObjectTransferDT";
124 | case EosEventRequestCancelTransferDT : return "EosEventRequestCancelTransferDT";
125 | case EosEventStoreAdded : return "EosEventStoreAdded";
126 | case EosEventStoreRemoved : return "EosEventStoreRemoved";
127 | case EosEventBulbExposureTime : return "EosEventBulbExposureTime";
128 | case EosEventRecordingTime : return "EosEventRecordingTime";
129 | case EosEventAfResult : return "EosEventRequestObjectTransferTS";
130 | case EosEventRequestObjectTransferTS : return "EosEventAfResult";
131 | }
132 | return "0x" +Integer.toHexString(code);
133 | }
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/nikon/NikonEventFormat.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2010 by Stefano Fornari
2 | *
3 | * This program is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation; either version 2 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program; if not, write to the Free Software
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | */
17 | package com.ptplib.usbcamera.nikon;
18 |
19 | import java.lang.reflect.Field;
20 |
21 | /**
22 | * This class formats an EosEvent to a string
23 | *
24 | * @author stefano fornari
25 | */
26 | public class NikonEventFormat implements NikonEventConstants {
27 | public static String format(NikonEvent e) {
28 | StringBuilder sb = new StringBuilder();
29 |
30 | int eventCode = e.getCode();
31 |
32 | sb.append(getEventName(eventCode));
33 | sb.append(" [ ");
34 | if (eventCode == EosEventPropValueChanged) {
35 | int propCode = e.getIntParam(1);
36 | sb.append(getPropertyName(propCode))
37 | .append(": ");
38 |
39 | if ((propCode >= EosPropPictureStyleStandard) &&
40 | (propCode <= EosPropPictureStyleUserSet3)) {
41 | sb.append("(Sharpness: ")
42 | .append(e.getIntParam(4))
43 | .append(", Contrast: ")
44 | .append(e.getIntParam(3));
45 | if (((Boolean)e.getParam(2)).booleanValue()) {
46 | sb.append(", Filter effect: ")
47 | .append(getFilterEffect(e.getIntParam(5)))
48 | .append(", Toning effect: ")
49 | .append(getToningEffect(e.getIntParam(6)));
50 | } else {
51 | sb.append(", Saturation: ")
52 | .append(e.getIntParam(5))
53 | .append(", Color tone: ")
54 | .append(e.getIntParam(6));
55 | }
56 | sb.append(")");
57 | } else {
58 | if (e.getParamCount()>1) {
59 | sb.append(e.getIntParam(2));
60 | }
61 | }
62 | } else if (eventCode == EosEventObjectAddedEx) {
63 | sb.append(formatEosEventObjectAddedEx(e));
64 | }
65 | sb.append(" ]");
66 |
67 | return sb.toString();
68 | }
69 |
70 | /**
71 | * Returns the printable name of the given event
72 | *
73 | * @param code event code
74 | *
75 | * @return the printable name of the given event
76 | */
77 | public static String getEventName(int code) {
78 | Field[] fields = NikonEventConstants.class.getDeclaredFields();
79 |
80 | for (Field f: fields) {
81 | String name = f.getName();
82 | if (name.startsWith("EosEvent")) {
83 | try {
84 | if (f.getInt(null) == code) {
85 | return name;
86 | }
87 | } catch (Exception e) {
88 | //
89 | // Nothing to do
90 | //
91 | }
92 | }
93 | }
94 | return "Unknown";
95 | }
96 |
97 | /**
98 | * Returns the printable name of the given property
99 | *
100 | * @param code property code
101 | *
102 | * @return the printable name of the given property
103 | */
104 | public static String getPropertyName(int code) {
105 | return getCodeName("EosProp", code);
106 | }
107 |
108 | /**
109 | * Returns the printable name of the given image format
110 | *
111 | * @param code image format code
112 | *
113 | * @return the printable name of the given image format
114 | */
115 | public static String getImageFormatName(int code) {
116 | return getCodeName("ImageFormat", code);
117 | }
118 |
119 | /**
120 | * Returns the filter effect name given the code. Names are:
121 | * 0:None, 1:Yellow, 2:Orange, 3:Red, 4:Green
122 | *
123 | * @param code the filter effect code (0-4)
124 | *
125 | * @return the filter effect name
126 | */
127 | public static String getFilterEffect(int code) {
128 | if ((code < 0) || (code > 4)) {
129 | throw new IllegalArgumentException("code must be in he range 0-4");
130 | }
131 |
132 | switch (code) {
133 | case 0: return "None";
134 | case 1: return "Yellow";
135 | case 2: return "Orange";
136 | case 3: return "Red";
137 | case 4: return "Green";
138 | }
139 |
140 | //
141 | // We should never get here
142 | //
143 | return "Unknown";
144 | }
145 |
146 | /**
147 | * Returns the toning effect name given the code. Names are:
148 | * 0:None, 1:Sepia, 2:Blue, 3:Purple, 4:Green
149 | *
150 | * @param code the toning effect code (0-4)
151 | *
152 | * @return the toning effect name
153 | */
154 | public static String getToningEffect(int code) {
155 | if ((code < 0) || (code > 4)) {
156 | throw new IllegalArgumentException("code must be in he range 0-4");
157 | }
158 |
159 | switch (code) {
160 | case 0: return "None";
161 | case 1: return "Sepia";
162 | case 2: return "Blue";
163 | case 3: return "Purple";
164 | case 4: return "Green";
165 | }
166 |
167 | //
168 | // We should never get here
169 | //
170 | return "Unknown";
171 | }
172 |
173 | // --------------------------------------------------------- Private methods
174 |
175 | private static String formatEosEventObjectAddedEx(NikonEvent event) {
176 | return String.format(
177 | "Filename: %s, Size(bytes): %d, ObjectID: 0x%08X, StorageID: 0x%08X, ParentID: 0x%08X, Format: %s",
178 | event.getStringParam(6),
179 | event.getIntParam(5),
180 | event.getIntParam(1),
181 | event.getIntParam(2),
182 | event.getIntParam(3),
183 | getImageFormatName(event.getIntParam(4))
184 | );
185 | }
186 |
187 | /**
188 | * Looks up and returns the name of the code give if there is a constant
189 | * field in EosEventConstants which starts with the given prefix
190 | *
191 | * @param prefix the field name prefix
192 | * @param code image format code
193 | *
194 | * @return the printable name of the given code
195 | */
196 | private static String getCodeName(String prefix, int code) {
197 | Field[] fields = NikonEventConstants.class.getDeclaredFields();
198 |
199 | for (Field f: fields) {
200 | String name = f.getName();
201 | if (name.startsWith(prefix)) {
202 | try {
203 | if (f.getInt(null) == code) {
204 | return name.substring(prefix.length());
205 | }
206 | } catch (Exception e) {
207 | //
208 | // Nothing to do
209 | //
210 | }
211 | }
212 | }
213 | return "Unknown";
214 | }
215 |
216 | }
217 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/nikon/NikonEventParser.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2010 by Stefano Fornari
2 | *
3 | * This program is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation; either version 2 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program; if not, write to the Free Software
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | */
17 |
18 | package com.ptplib.usbcamera.nikon;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 |
23 | import android.util.Log;
24 |
25 | import com.ptplib.usbcamera.PTPException;
26 | import com.ptplib.usbcamera.PTPUnsupportedException;
27 |
28 | /**
29 | * This class parses a stream of bytes as a sequence of events accordingly
30 | * to how Canon EOS returns events.
31 | *
32 | * The event information is returned in a standard PTP data packet as a number
33 | * of records followed by an empty record at the end of the packet. Each record
34 | * consists of multiple four-byte fields and always starts with record length
35 | * field. Further structure of the record depends on the device property code
36 | * which always goes in the third field. The empty record consists of the size
37 | * field and four byte empty field, which is always zero.
38 | *
39 | * @author stefano fornari
40 | */
41 | public class NikonEventParser implements NikonEventConstants {
42 |
43 | /**
44 | * The stream data are read from
45 | */
46 | private InputStream is;
47 |
48 | /**
49 | * Creates a new parser to parse the given input stream
50 | *
51 | * @param is
52 | */
53 | public NikonEventParser(InputStream is) {
54 | if (is == null) {
55 | throw new IllegalArgumentException("The input stream cannot be null");
56 | }
57 |
58 | this.is = is;
59 | }
60 |
61 | /**
62 | * Returns true is there are events in the stream (and the stream is still
63 | * open), false otherwise.
64 | *
65 | * @return true is there are events in the stream (and the stream is still
66 | * open), false otherwise.
67 | */
68 | public boolean hasEvents() {
69 | try {
70 | // Log.d("EventParser", " available: " +is.available());
71 | if (is.available() <= 0) {
72 | return false;
73 | }
74 | } catch (IOException e) {
75 | return false;
76 | }
77 |
78 | return true;
79 | }
80 |
81 | /**
82 | * Returns the next event in the stream.
83 | *
84 | * @return the next event in the stream.
85 | *
86 | * @throws PTPException in case of errors
87 | */
88 | public NikonEvent getNextEvent() throws PTPException {
89 | NikonEvent event = new NikonEvent();
90 |
91 | try {
92 | int len = getNextS32(); // len
93 | // Log.d("EventParser", " Len: " +len);
94 | if (len < 0x8) {
95 | throw new PTPUnsupportedException("Unsupported event (size<8 ???)");
96 | }
97 | int code = getNextS32();
98 | event.setCode(code);
99 | Log.d("EventParser", " Event len: " +len +", Code: 0x" +String.format("%04x", code) +" " +NikonEvent.getEventName(code));
100 | parseParameters(event, len-8);
101 | // Log.d("EventParser", " Event: params " +event.getParamCount());
102 | for (int i = 1; i<= event.getParamCount(); i++)
103 | Log.d("EventParser", " params " +i +": " +String.format("0x%04x %d",event.getParam(i), event.getParam(i)));
104 | } catch (IOException e) {
105 | Log.d ("EventParser", " Error reading event stream");
106 | throw new PTPException("Error reading event stream", e);
107 | }
108 |
109 | return event;
110 | }
111 |
112 |
113 | // --------------------------------------------------------- Private methods
114 |
115 | private void parseParameters(NikonEvent event, int len)
116 | throws PTPException, IOException {
117 | int code = event.getCode();
118 |
119 | if (code == EosEventPropValueChanged) {
120 | parsePropValueChangedParameters(event);
121 | } else if (code == EosEventShutdownTimerUpdated) {
122 | //
123 | // No parameters
124 | //
125 | } else if (code == EosEventCameraStatusChanged) {
126 | event.setParam(1, getNextS32());
127 | } else if (code == EosEventObjectAddedEx) {
128 | parseEosEventObjectAddedEx(event);
129 | } else{
130 | is.skip(len);
131 | throw new PTPUnsupportedException("Unsupported event");
132 | }
133 | }
134 |
135 | private void parsePropValueChangedParameters(NikonEvent event)
136 | throws IOException {
137 | int property = getNextS32();
138 | event.setParam(1, property); // property changed
139 |
140 | if ((property >= EosPropPictureStyleStandard) &&
141 | (property <= EosPropPictureStyleUserSet3)) {
142 | boolean monochrome = (property == EosPropPictureStyleMonochrome);
143 | int size = getNextS32();
144 | if (size > 0x1C) {
145 | //
146 | // It is a EosPropPictureStyleUserXXX, let's read the type (then
147 | // we do not use it)
148 | //
149 | monochrome = (getNextS32() == EosPropPictureStyleUserTypeMonochrome);
150 | }
151 | event.setParam(2, (monochrome) ? Boolean.TRUE : Boolean.FALSE);
152 | event.setParam(3, getNextS32()); // contrast
153 | event.setParam(4, getNextS32()); // sharpness
154 | if (monochrome) {
155 | getNextS32();
156 | getNextS32();
157 | event.setParam(5, getNextS32()); // filter effect
158 | event.setParam(6, getNextS32()); // toning effect
159 | } else {
160 | event.setParam(5, getNextS32()); // saturation
161 | event.setParam(6, getNextS32()); // color tone
162 | getNextS32();
163 | getNextS32();
164 | }
165 | } else {
166 | //
167 | // default
168 | //
169 | event.setParam(2, getNextS32());
170 | }
171 |
172 | }
173 |
174 | private void parseEosEventObjectAddedEx(NikonEvent event)
175 | throws IOException {
176 | event.setParam(1, getNextS32() ); // object id
177 | event.setParam(2, getNextS32() ); // storage id
178 | event.setParam(4, getNextS16() ); // format
179 | is.skip(10);
180 | event.setParam(5, getNextS32() ); // size
181 | event.setParam(3, getNextS32() ); // parent object id
182 | is.skip(4); // unknown
183 | event.setParam(6, getNextString()); // file name
184 | is.skip(4);
185 | }
186 |
187 | /**
188 | * Reads and return the next signed 32 bit integer read from the input
189 | * stream.
190 | *
191 | * @return the next signed 32 bit integer in the stream
192 | *
193 | * @throws IOException in case of IO errors
194 | */
195 | private final int getNextS32() throws IOException {
196 | int retval;
197 |
198 | retval = (0xff & is.read()) ;
199 | retval |= (0xff & is.read()) << 8;
200 | retval |= (0xff & is.read()) << 16;
201 | retval |= is.read() << 24;
202 |
203 | return retval;
204 | }
205 |
206 | /**
207 | * Reads and return the next signed 16 bit integer read from the input
208 | * stream.
209 | *
210 | * @return the next signed 16 bit integer in the stream
211 | *
212 | * @throws IOException in case of IO errors
213 | */
214 | private final int getNextS16() throws IOException {
215 | int retval;
216 |
217 | retval = (0xff & is.read()) ;
218 | retval |= (0xff & is.read()) << 8;
219 |
220 | return retval;
221 | }
222 |
223 | /**
224 | * Reads and return the next string read from the input stream. Strings are
225 | * zero (32 bit) terminated string
226 | *
227 | * @return the next string in the stream
228 | *
229 | * @throws IOException in case of IO errors
230 | */
231 | private final String getNextString() throws IOException {
232 | StringBuilder retval = new StringBuilder();
233 |
234 | char c = 0;
235 | while ((c = (char)is.read()) != 0) {
236 | retval.append(c);
237 | }
238 |
239 | //
240 | // At this point we read the string and one zero. We need to read the
241 | // remaining 3 zeros
242 | //
243 | is.skip(3);
244 |
245 | return retval.toString();
246 | }
247 |
248 | }
249 |
--------------------------------------------------------------------------------
/USBCamera/src/com/ptplib/usbcamera/nikon/NikonInitiator.java:
--------------------------------------------------------------------------------
1 | // Copyright 2000 by David Brownell
2 | //
3 | // This program is free software; you can redistribute it and/or modify
4 | // it under the terms of the GNU General Public License as published by
5 | // the Free Software Foundation; either version 2 of the License, or
6 | // (at your option) any later version.
7 | //
8 | // This program is distributed in the hope that it will be useful,
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | // GNU General Public License for more details.
12 | //
13 | // You should have received a copy of the GNU General Public License
14 | // along with this program; if not, write to the Free Software
15 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 | //
17 | package com.ptplib.usbcamera.nikon;
18 |
19 | import java.io.ByteArrayInputStream;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | ////import ch.ntb.usb.*;
24 | import android.hardware.usb.UsbConstants;
25 | import android.hardware.usb.UsbDevice;
26 | import android.hardware.usb.UsbDeviceConnection;
27 | import android.hardware.usb.UsbEndpoint;
28 | import android.hardware.usb.UsbInterface;
29 | import android.hardware.usb.UsbManager;
30 | import android.hardware.usb.UsbRequest;
31 | import android.util.Log;
32 | import android.widget.TextView;
33 |
34 |
35 | import com.ptplib.usbcamera.BaselineInitiator;
36 | import com.ptplib.usbcamera.Command;
37 | import com.ptplib.usbcamera.Container;
38 | import com.ptplib.usbcamera.Data;
39 | import com.ptplib.usbcamera.DevicePropDesc;
40 | import com.ptplib.usbcamera.NameFactory;
41 | import com.ptplib.usbcamera.PTPException;
42 | import com.ptplib.usbcamera.PTPUnsupportedException;
43 | import com.ptplib.usbcamera.Response;
44 |
45 | /**
46 | * This supports all standardized PTP-over-USB operations, including
47 | * operations (and modes) that are optional for all responders.
48 | * Filtering operations invoked on this class may be done on the device,
49 | * or may be emulated on the client side.
50 | * At this time, not all standardized operations are supported.
51 | *
52 | * @version $Id: EosInitiator.java,v 1.9 2001/04/12 23:13:00 dbrownell Exp $
53 | * @author David Brownell
54 | */
55 | public class NikonInitiator extends BaselineInitiator {
56 |
57 | public static final int NIKON_VID = 1200;
58 |
59 | public static boolean eventListenerRunning = false;
60 | /**
61 | * This is essentially a class driver, following Annex D of
62 | * the PTP specification.
63 | */
64 | public NikonInitiator(UsbDevice dev, UsbDeviceConnection connection) throws PTPException {
65 | super(dev, connection);
66 | /*
67 | if (thread != null) eventListenerRunning = false;
68 | thread = new Thread (this);
69 | thread.start();
70 | */
71 | }
72 |
73 | /**
74 | * Fills out the provided device property description.
75 | *
76 | * @param propcode code identifying the property of interest
77 | * @param desc description to be filled; it may be a subtype
78 | * associated with with domain-specific methods
79 | * @return response code
80 | */
81 | public int getDevicePropDesc(int propcode, DevicePropDesc desc)
82 | throws PTPException {
83 | return transact1(Command.GetDevicePropDesc, desc, propcode).getCode();
84 | }
85 |
86 |
87 |
88 |
89 | /**
90 | * Starts the capture of one (or more) new
91 | * data objects, according to current device properties.
92 | * The capture will complete without issuing further commands.
93 | *
94 | * @see #initiateOpenCapture
95 | *
96 | * @param storageId Where to store the object(s), or zero to
97 | * let the device choose.
98 | * @param formatCode Type of object(s) to capture, or zero to
99 | * use the device default.
100 | *
101 | * @return status code indicating whether capture started;
102 | * CaptureComplete events provide capture status, and
103 | * ObjectAdded events provide per-object status.
104 | */
105 | public Response initiateCapture(int storageId, int formatCode)
106 | throws PTPException {
107 | Response resp = null;
108 | //
109 | // Special initialization for EOS cameras
110 | //
111 | if (!info.supportsOperation(Command.InitiateCapture)) {
112 | Log.d(TAG, "The camera does not support Nikibon capture");
113 | throw new PTPException("The camera does not support Nikon capture");
114 | }
115 |
116 | int ret;
117 |
118 |
119 | try { Thread.sleep(100); } catch (InterruptedException e) {e.printStackTrace();}
120 | try { Thread.sleep(100); } catch (InterruptedException e) {e.printStackTrace();}
121 |
122 | resp = transact0(Command.InitiateCapture, null);
123 | ret = resp.getCode();
124 | Log.d(TAG, " NK_OC_Capture Response code: 0x" +Integer.toHexString(ret) +" OK: " +(ret == Response.OK));
125 | if (ret != Response.OK) {
126 | String msg = "NK_OC_Capture Capture failed to release: Unknown error "
127 | + ret
128 | + " , please report.";
129 | Log.d(TAG, msg);
130 | throw new PTPException(msg, ret);
131 | }
132 |
133 | try { Thread.sleep(100); } catch (InterruptedException e) {e.printStackTrace();}
134 |
135 |
136 | return resp;
137 | }
138 |
139 | /**
140 | * Retrieves a chunk of the object identified by the given object id.
141 | *
142 | * @param oid object id
143 | * @param offset the offset to start from
144 | * @param size the number of bytes to transfer
145 | * @param data the Data object receiving the object
146 | *
147 | * @throws PTPException in case of errors
148 | */
149 | public void getPartialObject(int oid, int offset, int size, Data data)
150 | throws PTPException {
151 | Response ret =
152 | transact3(Command.EosGetPartialObject, data, oid, offset, size);
153 |
154 | if (ret.getCode() != Response.OK) {
155 | throw new PTPException("Error reading new object", ret.getCode());
156 | }
157 | }
158 |
159 | public void transferComplete(int oid)
160 | throws PTPException {
161 | Response ret =
162 | transact1(Command.EosTransferComplete, null, oid);
163 |
164 | if (ret.getCode() != Response.OK) {
165 | throw new PTPException("Error reading new object", ret.getCode());
166 | }
167 | }
168 | //Methods below Added, getDevicePropDesc should work too
169 | public Response setDevicePropValueNikon (int property, int value) throws PTPException{
170 |
171 | byte [] buff = new byte [0x14];
172 | Data data = new Data (false, buff, buff.length, this);
173 | data.offset = 0;
174 | data.putHeader(buff.length, Container.BLOCK_TYPE_DATA, Command.SetDevicePropValue, 0 );
175 | data.put32 (value);
176 | Command command = new Command(Command.SetDevicePropValue, session, property);
177 | writeExtraData(command, data, DEFAULT_TIMEOUT);
178 |
179 |
180 | byte buf[] = new byte[inMaxPS];
181 | int len = mConnection.bulkTransfer(epIn, buf ,inMaxPS , DEFAULT_TIMEOUT);
182 | Response response = new Response(buf, len, this);
183 | return response;
184 | }
185 |
186 | public int getDevicePropValue(int propcode, DevicePropDesc desc)
187 | throws PTPException {
188 | return transact1(Command.GetDevicePropValue, desc, propcode).getCode();
189 | }
190 |
191 |
192 |
193 |
194 |
195 | //To do 22 Aug Ashraf
196 | public DevicePropDesc getPropValue (int value) throws PTPException
197 | {
198 |
199 | Command command = new Command(Command.GetDevicePropDesc, session, value);
200 | mConnection.bulkTransfer(epOut, command.data , command.length , DEFAULT_TIMEOUT);
201 |
202 | byte buf[] = new byte[inMaxPS];
203 | int lengthOfBytes = mConnection.bulkTransfer(epIn, buf , inMaxPS , DEFAULT_TIMEOUT);
204 |
205 | DevicePropDesc info = new DevicePropDesc (this);
206 | info.data = buf;
207 | info.length = info.getLength();
208 | info.parse();
209 |
210 | Response response1 = new Response (buf, inMaxPS, this);
211 |
212 | buf = new byte[inMaxPS];
213 | lengthOfBytes = mConnection.bulkTransfer(epIn, buf , inMaxPS , DEFAULT_TIMEOUT);
214 |
215 | Response response2 = new Response (buf, inMaxPS, this);
216 |
217 |
218 | return info;
219 |
220 | }
221 |
222 |
223 | public Response MoveFocus(int step) throws PTPException{
224 |
225 | return null;//transact1(Command.EosDriveLens,null,step);
226 |
227 | }
228 |
229 | public Response setExposure(int exposure) throws PTPException{
230 |
231 | return setDevicePropValueNikon(NikonEventConstants.PTP_DPC_ExposureBiasCompensation, exposure);
232 |
233 | }
234 |
235 | public Response setISO(int value) throws PTPException{
236 | //return null;
237 | return setDevicePropValueNikon(NikonEventConstants.PTP_DPC_ExposureIndex ,value);
238 | }
239 |
240 | public Response setAperture(int value) throws PTPException{
241 |
242 | return setDevicePropValueNikon(NikonEventConstants.PTP_DPC_FNumber ,value);
243 | }
244 |
245 |
246 | public Response setPictureStyle(int value) throws PTPException{
247 |
248 | return null; //return setDevicePropValueNikon(Command.EOS_DPC_PictureStyle,value);
249 | }
250 |
251 | public Response setWhiteBalance(int value) throws PTPException{
252 |
253 | return setDevicePropValueNikon(NikonEventConstants.PTP_DPC_WhiteBalance,value);
254 | }
255 |
256 | public Response setDriveMode(int value) throws PTPException{
257 |
258 | return null;//return setDevicePropValueNikon(Command.EOS_DPC_DriveMode, value);
259 | }
260 |
261 | public Response setMetering(int value) throws PTPException{
262 |
263 | return null;//setDevicePropValueNikon(NikonEventConstants.PTP_DPC_FocusMeteringMode, value);
264 | }
265 |
266 | public Response setImageQuality(int value) throws PTPException{
267 |
268 | return null;//setDevicePropValueNikon(Command.EOS_DPC_ExpMeterringMode, value);
269 | }
270 |
271 | public Response setShutterSpeed (int speed) throws PTPException{
272 | return setDevicePropValueNikon (NikonEventConstants.PTP_DPC_ExposureTime, speed);
273 |
274 | }
275 |
276 | public Response setPropValue(int property,String value)
277 | {
278 | int lengthString = value.length()+1;
279 | byte [] buff = new byte [0x12 +lengthString+lengthString+1];
280 | Data data = new Data (false, buff, buff.length, this);
281 | data.offset = 0;
282 | data.putHeader(buff.length, Container.BLOCK_TYPE_DATA,
283 | Command.SetDevicePropValue, 0 );
284 |
285 | data.putString(value);
286 | Command command = new Command(Command.SetDevicePropValue, session,
287 | property);
288 | writeExtraData(command, data, DEFAULT_TIMEOUT);
289 |
290 | // read response
291 | byte buf[] = new byte[inMaxPS];
292 | int len = mConnection.bulkTransfer(epIn, buf ,inMaxPS ,
293 | DEFAULT_TIMEOUT);
294 | Response response = new Response(buf, len, this);
295 | return response;
296 |
297 |
298 | }
299 |
300 | }
301 |
--------------------------------------------------------------------------------