File: PROTOCOL

package info (click to toggle)
camediaplay 20010211-4
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 252 kB
  • ctags: 133
  • sloc: sh: 1,507; ansic: 1,458; tcl: 137; makefile: 83
file content (584 lines) | stat: -rw-r--r-- 19,704 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
Sanyo digital camera engine protocol
$Id: PROTOCOL,v 1.2 1998/01/18 01:41:02 itojun Exp $

NOTE1:	If the this text meets the actual practice, it is just a coincidence:-)
NOTE2:	All digits in protocol description are displayed in hexadecimal.
	(for example, "1B" means escape char, "41" means "A")
NOTE3:	Why we call it "Sanyo protocol?"  This is because the firmware
	and the CPU part of Olympus/Sanyo/Epson/Agfa digi-cams are
	implemented by Sanyo, reportedly.

There are several contributors to the list:
	Eugene Crosser <crosser@average.org>
	Leon Brooks <leonb@mon.ami.com.au>
	Tomio Narita <nrt@web.ad.jp>
	Thierry Bousch <bousch%linotte.uucp@topo.math.u-psud.fr>

Format can be devided into three categories:
	attention
	formatted - S commands
		    C commands

Attention commands
------------------
Get attention of camera (check if baudrate is ok or not)
	CPU: 00
	CAM:    xx

	xx: 15 if the baudrate is ok, FF if the baudrate is not good.

	NOTE: Agfa ePhoto307 returns 00 instead of 15, if the baudrate is ok.

	NOTE: we sometimes see FF alone sent from the camera.  The
		interpretation might be wrong.
	NOTE: some junk chars may be transmitted from the camera before
		15 or FF.  implementations may want to try skipping
		junk chars.

Formatted commands - in general
-------------------------------
General command format
    1. if camera has nothing to return to CPU
	CPU: 1B xx y1 y2 ....... z1 z2
	CAM:                           06

      CPU>CAM flow
	xx:	command type ('S' or 'C')
	y1 y2:	the length of the command body. (intel-endian: means y2*256+y1)
	.....:	command body. length is shown as y1 and y2.
	z1 z2:	simple checksum of command body. Just add the whole bytes
		of command body, take the least 16 bits, and place into
		z1 and z2 by intel-endian. (z2*256+z1)

      CAM>CPU flow
	06:	acknowledgement from the camera. (in ASCII character table,
		06 means ACK)
		I have never seen negative acknowledge, but I believe it must
		be 15 if there are. (15 means NAK)

    2. if camera has something to return to CPU (single sector reply)
	CPU: 1B xx y1 y2 ....... z1 z2                           06
	CAM:                           03 00 a1 a2 ....... b1 b2
	
      CPU>CAM flow
		Same as above.
      CAM>CPU flow
	03:	this is the last sector in this reply message. (ETX in ASCII
		table)
	00:	sector #.  this is sector 0.
	a1 a2:	the length of the reply body. (intel-endian: means a2*256+a1)
	.....:	reply body. length is shown as a1 and a2.
	b1 b2:	simple checksum of reply body. Just add the whole bytes
		of command body, take the least 16 bits, and place into
		b1 and b2 by intel-endian. (b2*256+b1)
      CPU>CAM flow
	06:	acknowledgement from the CPU. (in ASCII character table,
		06 means ACK)
		I have never seen negative acknowledge, but I believe it must
		be 15 if there are. (15 means NAK)

    3. if camera has something to return to CPU (multiple sector reply)
	3-a. command request:
		CPU: 1B xx y1 y2 ....... z1 z2
		CAM:

	      CPU>CAM flow
			Same as 1.  See "command with no reply" case.

	3-b. intermediate sectors:
		CPU:                           06
		CAM: 02 nn a1 a2 ....... b1 b2

	      CAM>CPU flow
		02:	this is one of the intermediate sectors in this reply
			message.  (STX in ASCII table)
		nn:	sector #.  starts from 0, and increased in normal order.
		a1 a2:	the length of the reply body. (intel-endian: means
			a2*256+a1)
		.....:	reply body. length is shown as a1 and a2.
		b1 b2:	simple checksum of reply body. Just add the whole
			bytes of command body, take the least 16 bits, and
			place into b1 and b2 by intel-endian. (b2*256+b1)

	      CPU>CAM flow
		06:	acknowledgement from the CPU. (in ASCII character
			table, 06 means ACK)
			I have never seen negative acknowledge, but I believe
			it must be 15 if there are. (15 means NAK)

	3-c. final sector:
		CPU:                           06
		CAM: 03 mm a1 a2 ....... b1 b2
	
	      CAM>CPU flow
		03:	this is the final sector in this reply message.
			(STX in ASCII table)
		mm:	final sector #.
		a1 a2:	the length of the reply body. (intel-endian: means
			a2*256+a1)
		.....:	reply body. length is shown as a1 and a2.
		b1 b2:	simple checksum of reply body. Just add the whole
			bytes of command body, take the least 16 bits, and
			place into b1 and b2 by intel-endian. (b2*256+b1)

	      CPU>CAM flow
		06:	acknowledgement from the CPU. (in ASCII character
			table, 06 means ACK)
			I have never seen negative acknowledge, but I believe
			it must be 15 if there are. (15 means NAK)

	As you have seen, case 2. (single sector reply) is a special
	case of 3. (multi sector reply)

    4. if you have long data to send to CPU (multiple sector command)
	4-a. command request:
		CPU: 1B xx y1 y2 ....... z1 z2
		CAM:                           06

	      CPU>CAM flow
			Same as 1.  See "command with no reply" case.

	      CAM>CPU flow
		06:	acknowledgement from the camera. (in ASCII character
			table, 06 means ACK)
			I have never seen negative acknowledge, but I believe
			it must be 15 if there are. (15 means NAK)

	4-b. intermediate sectors:
		CPU: 02 nn a1 a2 ....... b1 b2
		CAM:                           06

	      CPU>CAM flow
		02:	this is one of the intermediate sectors in this reply
			message.  (STX in ASCII table)
		nn:	sector #.  starts from 0, and increased in normal order.
		a1 a2:	the length of the extra command body.
			(intel-endian: means a2*256+a1)
		.....:	extra command body. length is shown as a1 and a2.
		b1 b2:	simple checksum of extra command body. Just add the
			whole bytes of command body, take the least 16 bits,
			and place into b1 and b2 by intel-endian. (b2*256+b1)

	      CAM>CPU flow
		06:	acknowledgement from the camera. (in ASCII character
			table, 06 means ACK)
			I have never seen negative acknowledge, but I believe
			it must be 15 if there are. (15 means NAK)

	4-c. final sector:
		CPU: 03 mm a1 a2 ....... b1 b2
		CAM:                           06
	
	      CPU>CAM flow
		03:	this is the final sector in this command.
			(STX in ASCII table)
		mm:	final sector #.
		a1 a2:	the length of the extra command body.
			(intel-endian: means a2*256+a1)
		.....:	extra command body. length is shown as a1 and a2.
		b1 b2:	simple checksum of extra command body. Just add the
			whole bytes of command body, take the least 16 bits,
			and place into b1 and b2 by intel-endian. (b2*256+b1)

	      CAM>CPU flow
		06:	acknowledgement from the camera. (in ASCII character
			table, 06 means ACK)
			I have never seen negative acknowledge, but I believe
			it must be 15 if there are. (15 means NAK)

	As you have seen, case 4. (multiple sector command) is similar
	to 3. (multi sector reply)


	In the following description, checksum bytes will be denoted by
	"CS CS", and length bytes will be shown as "LN LN".

Formatted commands - 'S' series
-------------------------------
	'S' commands requests the change of baudrate for the serial line.

	CPU: 1B 'S' 06 00 00 11 xx 00 00 00 CS CS
	CAM:                                      06

	This is command type 1. which needs no reply from camera.
	command body size is 6, hence command length field shows "06 00".

	xx:	baudrate to move to.
		00: default/initial(19200bps)
		01: 9600bps
		02: 19200bps
		03: 38400bps
		04: 57600bps
		05: 115200bps

	To switch the baudrate, you should:
		1. wait for acknowledge from the camera
		2. wait some time (from experience, 0.2sec would be fine)
		3. switch the baudrate

	NOTE: analysis incomplete.

Formatted commands - 'C' series
-------------------------------
	'C' commands has various meanings.  It will be determined by first
	byte of command body.

  00 ?? ?? ?? ?? ??: set various mode

	The command body has 6 bytes.  First is 00, second is mode name,
	and remaining 4 bytes seems to be 32 bit value (intel endian).

  00 01 xx 00 00 00: set picture quality mode
	CPU: 1B 'C' 06 00 00 01 xx 00 00 00 CS CS
	CAM:                                      06

	xx:	01 = normal mode
		02 = HQ

  00 02 xx xx xx xx: set current date
	CPU: 1B 'C' 06 00 00 02 xx xx xx xx CS CS
	CAM:                                      06

	date format: seconds from 1970/1/1 00:00:00, IN LOCAL TIME.
	(unix time always calcurate it in GMT)

  00 03 xx xx xx xx: set shutter speed
	CPU: 1B 'C' 06 00 00 03 xx xx xx xx CS CS
	CAM:                                      06

	described by Eugene Crosser, unconfirmed by itojun
	xx:	(in usec)

  00 04 xx 00 00 00: set the picture # to download
	CPU: 1B 'C' 06 00 00 04 xx 00 00 00 CS CS
	CAM:                                      06

	xx:	picture # (1-n)
		Don't know what happens if you specify out-of-range values.
		(should check before with series 'C' 01 0A)

  00 07 xx 00 00 00: set flash mode
	CPU: 1B 'C' 06 00 00 07 xx 00 00 00 CS CS
	CAM:                                      06

	xx:	00 = auto
		01 = force on
		02 = force off
		03 = on (redeye prevention)

  00 20 xx xx xx xx: set magic number for uploading to camera
	CPU: 1B 'C' 06 00 00 20 xx xx xx xx CS CS
	CAM:                                      06

	xx xx xx xx:	magic number. "0E 00 EC 0F" for Olympus C-410L.

	found by Thierry Bousch.
	NOTE: Camera will hang up if you upload images that does not
	conform to the camera's jpeg engine.  You will have to remove
	battery to recover from the hang up.

  00 21 xx 00 00 00: set lens mode
	CPU: 1B 'C' 06 00 00 21 xx 00 00 00 CS CS
	CAM:                                      06

	xx:	01 = macro mode
		02 = normal mode

  00 29 xx 00 00 00: set brightness of LCD screen(?)
	CPU: 1B 'C' 06 00 00 29 xx 00 00 00 CS CS
	CAM:                                      06


  01 ??: query various mode

	The command body has 2 bytes.  First is 01, second is mode name.
	The reply body has 4 bytes, and it seems to be 32 bit value
	(intel endian).

  01 01: query picture quality mode
	CPU: 1B 'C' 02 00 01 01 CS CS                               06
	CAM:                          03 00 04 00 xx 00 00 00 CS CS

	xx: picture quality mode (see command 00 01)

  01 02: query current date
	CPU: 1B 'C' 02 00 01 02 CS CS                               06
	CAM:                          03 00 04 00 xx xx xx xx CS CS

	date format: seconds from 1970/1/1 00:00:00, IN LOCAL TIME.
	(unix time always calcurate it in GMT)

  01 03: query shutter speed
	CPU: 1B 'C' 02 00 01 02 CS CS                               06
	CAM:                          03 00 04 00 xx xx xx xx CS CS

	described by Eugene Crosser, unconfirmed by itojun
	xx:	(in usec)

  01 07: query flash mode
	CPU: 1B 'C' 02 00 01 07 CS CS                               06
	CAM:                          03 00 04 00 xx 00 00 00 CS CS

	xx: flash mode (see command 00 07)

  01 0A: query number of picts the camera holds
	CPU: 1B 'C' 02 00 01 0A CS CS                               06
	CAM:                          03 00 04 00 xx 00 00 00 CS CS

	xx: number of picts camera holds (1-N)

  01 0B: query number of picts we can take
	CPU: 1B 'C' 02 00 01 0B CS CS                               06
	CAM:                          03 00 04 00 xx 00 00 00 CS CS

	xx: number of picts we can take in the current mode (1-N)

  01 0C: get the size of full-sized picture.
	CPU: 1B 'C' 02 00 01 0C CS CS                               06
	CAM:                          03 00 04 00 x1 x2 x3 x4 CS CS

	select picture# by series 'C' 00 04 before invoking it.
	x1 x2 x3 x4: size of full-sized picture (bytes).  intel endian.

  01 0D: get the size of thumbnail picture.
	CPU: 1B 'C' 02 00 01 0D CS CS                               06
	CAM:                          03 00 04 00 x1 x2 x3 x4 CS CS

	select picture# by series 'C' 00 04 before invoking it.
	x1 x2 x3 x4: size of thumbnail picture (bytes).  intel endian.

  01 10: battery capacity percentage.
	CPU: 1B 'C' 02 00 01 10 CS CS                               06
	CAM:                          03 00 04 00 xx 00 00 00 CS CS

	get battery capacity percentage.  used quite many times.

  01 17: query auto power-off time of ???
	CPU: 1B 'C' 02 00 01 17 CS CS                               06
	CAM:                          03 00 04 00 B4 00 00 00 CS CS

	autoshut on host timer (seconds) - Eugene Crosser

  01 18: query auto power-off time of ???
	CPU: 1B 'C' 02 00 01 18 CS CS                               06
	CAM:                          03 00 04 00 B4 00 00 00 CS CS

	autoshut in field timer (seconds) - Eugene Crosser

  01 21: query lens mode
	CPU: 1B 'C' 02 00 01 21 CS CS                               06
	CAM:                          03 00 04 00 xx 00 00 00 CS CS

	xx: lens mode (see command 00 21)

  01 24: unknown
	CPU: 1B 'C' 02 00 01 24 CS CS                               06
	CAM:                          03 00 04 00 05 00 00 00 CS CS

  01 26: query auto power-off time of ???
	CPU: 1B 'C' 02 00 01 26 CS CS                               06
	CAM:                          03 00 04 00 B4 00 00 00 CS CS

  01 27: unknown
	CPU: 1B 'C' 02 00 01 27 CS CS                               06
	CAM:                          03 00 04 00 00 00 00 00 00 00

	appears just after image transmission was done.

  01 29: query brightness of LCD screen(?)
	CPU: 1B 'C' 02 00 01 29 CS CS                               06
	CAM:                          03 00 04 00 02 00 00 00 CS CS


  02 ?? ??: details unknown

  02 01 00: erase all pictures
	CPU: 1B 'C' 03 00 02 01 00 CS CS
	CAM:                             06

  02 02 00: push shutter button
	CPU: 1B 'C' 03 00 02 02 00 CS CS
	CAM:                             06

	Don't know what happens if the command is issued while the memory
	is full.  (should check before with series 'C' 01 0B)

  02 07 00: erase single picture
	CPU: 1B 'C' 03 00 02 07 00 CS CS
	CAM:                             06

	select picture# by series 'C' 00 04 before invoking it.

  02 B0 00: save uploaded image into flashmemory
	CPU: 1B 'C' 03 00 02 B0 00 CS CS
	CAM:                             06

	Found by Thierry Bousch.
	NOTE: Camera will hang up if you upload images that does not
	conform to the camera's jpeg engine.  You will have to remove
	battery to recover from the hang up.

  03 xx ......: set various variable length value

	Set variable-length parameters to the camera.

  03 16 ......: set model id
	CPU: 1B 'C' LN LN 03 16 ..... CS CS
	CAM:                                06

	Command body has 0-terminated string that shows the model id of the
	camera.

  03 1D ......: upload data
	CPU: 1B 'C' LN LN 03 1D ..... CS CS	(first sector)
	CAM:                                06

	CPU: 02 xx LN LN ..... CS CS		(intermediate sectors)
	CAM:                         06

	CPU: 03 xx LN LN ..... CS CS		(last sector)
	CAM:                         06

	LN LN:	Usually, "00 08" is used for first/intermediate sectors,
		and arbitrary value for last sector.
	.....:	For the first sector, data part has to be (LN - 2) bytes
		because LN counts "03 1D" too.
	xx:	Sector number.  01 for the first intermediate sector
		(2nd sector in total), then monotonically increased.

	Found by Thierry Bousch.
	NOTE: Camera will hang up if you upload images that does not
	conform to the camera's jpeg engine.  You will have to remove
	battery to recover from the hang up.

  04 xx: get various variable length value

	Get variable-length values from the camera.

  04 0E: start downloading full-sized picture
	CPU: 1B 'C' 02 00 04 0E CS CS                          06
	CAM:                          ... multiple sectors ...

	select picture# by series 'C' 00 04 before invoking it.
	in C-400L, each sector has maximum size of 0x0800 (2048bytes).
	images that are bigger than 2048 bytes will be sent by multiple
	sectors.

  04 0F: start downloading thumbnail picture
	CPU: 1B 'C' 02 00 04 0F CS CS                          06
	CAM:                          ... multiple sectors ...

	select picture# by series 'C' 00 04 before invoking it.
	in C-400L, each sector has maximum size of 0x0800 (2048bytes).
	images that are bigger than 2048 bytes will be sent by multiple
	sectors.

  04 16: get model id
	CPU: 1B 'C' 02 00 04 16 CS                             06
	CAM:                          03 00 LN LN ...... CS CS

	Reply body has 0-terminated string that shows the model id of the
	camera.  For example, Olympus Camedia C-400L returns "OLYMPUS C-350L\0".

  04 19: get serial number
	CPU: 1B 'C' 02 00 04 19 CS CS                        06
	CAM:                          03 00 LN LN .... CS CS

	found by Eugene Crosser

  04 1A: get version
	CPU: 1B 'C' 02 00 04 1A CS CS                        06
	CAM:                          03 00 LN LN .... CS CS

	found by Eugene Crosser

  04 1B: get model type
	CPU: 1B 'C' 02 00 04 1B CS CS                        06
	CAM:                          03 00 LN LN .... CS CS

	Reply body has 0-terminated string that shows the model type of the
	camera.  For example, Olympus Camedia C-400L returns "SR25\0".

  04 2C: start downloading voice data (Sanyo DSC-V1 specific)
	CPU: 1B 'C' 02 00 04 2C CS CS                          06
	CAM:                          ... multiple sectors ...

	Specific to Sanyo DSC-V1.
	To download voice data, set picture# by 'C' series 00 04, then
	perform download by this command.  How to obtain the size of voice
	data is yet to be known.
	(submitted by Tomio Narita)

How to initialize the connection
--------------------------------
	1. attention
	2. set baudrate to default (0x00)
	3. attention
	4. set baudrate to specified one
	5. ????

How to download full-sized picture
----------------------------------
	see source code for more details.

	1. initialization.
	   set speed accordingly, ask user which picture to download,
	   and so forth.
	2. olympus tool sends 'C' series 01 10 command for battery capacity
	   check.
	3. set the picture# to get, by 'C' series 00 04.
	4. get size of the picture by 'C' series 01 0C, if needed.
	5. start transfer by 'C' series 04 0E.
	6. save all the reply body transferred from the camera into file.
	7. olympus tool sends 'C' series 01 27, by it is not necessery.

How to download thumbnail picture
---------------------------------
	see source code for more details.

	1. initialization.
	   set speed accordingly, ask user which picture to download,
	   and so forth.
	2. olympus tool sends 'C' series 01 10 command for battery capacity
	   check.
	3. set the picture# to get, by 'C' series 00 04.
	4. get size of the picture by 'C' series 01 0D, if needed.
	5. start transfer by 'C' series 04 0F.
	6. save all the reply body transferred from the camera into file.
	7. olympus tool sends 'C' series 01 27, by it is not necessery.

How to download voice data
--------------------------
(only for Sanyo DSC-V1)
	see source code for more details.

	1. initialization.
	   set speed accordingly, ask user which picture to download,
	   and so forth.
	2. olympus tool sends 'C' series 01 10 command for battery capacity
	   check.
	3. set the picture# to get, by 'C' series 00 04.
	4. (get size of the picture by 'C' series 01 xx - command unknown)
	5. start transfer by 'C' series 04 2C.
	6. save all the reply body transferred from the camera into file.
	7. olympus tool sends 'C' series 01 27, by it is not necessery.

	described by Tomio Narita.

How to upload picture
---------------------
	no source code available yet.  This is for Olympus C-410L.
	(not confirmed with other models)

	1. initialization.
	   set speed accordingly, ask user which picture to download,
	   and so forth.
	2. set the magic number, by 'C' series 00 20.
	3. start transfer by 'C' series 03 1D.
	4. send all the image data.
	5. save image data into flashmemory by 'C' series 02 B0.

	described by Thierry Bousch.
	NOTE: Camera will hang up if you upload images that does not
	conform to the camera's jpeg engine.  You will have to remove
	battery to recover from the hang up.