+----------------------------------------------------------------------------------+
| Information about Lens data protocol you wanted to know but nobody ever told you |
+----------------------------------------------------------------------------------+

Note: All info in this document is based on public sources!

Please don't redistribute this document, for personal use only!!!
I don't want to see it in the internet!!!

But you may use the info for making useful programs.

-------------------------------------------------------------------------------
-------------------------------------------------------------------------------


Following US Patents by Nikon are very useful:
---------------------------------------------------------------------
[1] US 4,758,854 - Camera System - lens connection, physical protocol, lens data info tables (good!)
[2] US 4,766,453 - Bayonet mount - the F bayonet for AF, lens contacts
[2] US 4,772,909 - lens AF  ...  - af information
[3] US 4,812,868 - AF detect...  - af correction
[4] US 4,814,802 - Camera System - data codes
[5] US 4,896,181 - Camera System - zoom lenses, protocol, lens data (good!)
[6] US 4,951,082 - 3D metering.. - 3D matrix metering, additional lens info
[6] US 5,347,340 - camera.lens.. - lens coefficents
[7] US 5,382,994 - info transmi. - teleconverter, af-i lenses
[8] US 5,727,241 - Photog.lens.. - physical protocol, new lens commands


Following documents are also very useful:
---------------------------------------------------------------------
Copyright (c) 1997 Ken Hancock <kenh@kagi.com>
This document resides at http://members.aol.com/khancock/pilot/nbuddy/
---------------------------------------------------------------------
file: NikonStringTables.c.txt
---------------------------------------------------------------------
file: N90s-memory-map.txt
0xFE2D            Focus distance cm = 10^(x/40)
0xFE2E            Zoom Position (SEE TABLES)
0xFE2F            Lens Focal Length Range(Lo) (SEE kFocalTable)
0xFE30            Lens Focal Length Range(Hi) (SEE kFocalTable)
0xFE31            Lens Apperature Range(Lo) (SEE kCameraApertureTable)
0xFE32            Lens Apperature Range(Hi) (SEE kCameraApertureTable)
0xFE33            Lens ID
                  0x22 = 70-210 4.5-5.6D (71-214mm)
                  0x25 = 60mm Macro
                  0x3A = 35-70 2.8D (36-71mm)
                  0x4F = 24-120 3.5-5.6D
---------------------------------------------------------------------


-------------------------------------------------------------------------------
-------------------------------------------------------------------------------

Now we can look at the data of the 50/1.8 lens and find some similarities.
The first four bytes from the "AF Lens Data" TAG 0x0098 are a version number as ASCII
0100 is from D100 and contains less data
0101 is from D2H and D70
0201 is from D2X, D2Hs and D50 and is encrypted the same way as white balance

I look only on version 0101.


Nikkor 50mm F/1.8 D
-------------------

original lens data @ oo (infinity)
25 13 47 00 47 F8 0F 08 03 08 01 12 00 85 00 00 50 14 76 58 50 50 14 14 7A 14 00 FF 00 01 FF F7 17 42 33 43 00 01 00 EE 00 00 51 06
25 13                08 03    01       85       50    76 58 50 50 14 14 7A 14                   17 42 33 43                      06 00 00 00 00 00 02 02
from makernote


original lens data @ near
20 18 48 00 70 F8 14 16 09 08 11 12 00 42 00 00 50 14 76 58 50 50 14 14 7A 14 00 FF 00 01 0C F6 15 45 2B 49 00 01 00 F2 00 00 51 11
20 18                16 09    11       42       50    76 58 50 50 14 14 7A 14                   15 45 2B 49                      11 00 00 00 00 00 02 02
from makernote


-------------------------------

Some guesses about the data:

00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C
original lens data @ oo (infinity)
25 13 47 00 47 F8 0F 08 03 08 01 12 00 85 00 00 50 14 76 58 50 50 14 14 7A 14 00 FF 00 01 FF F7 17 42 33 43 00 01 00 EE 00 00 51 06
25 13                08 03    01       85       50    76 58 50 50 14 14 7A 14                   17 42 33 43                      06 00 00 00 00 00 02 02
    |                       |  |     |  |        |     |  |  |  |  |  |  |  |
    |                       |  |     |  |        |     |  |  |  |  |  |  |  +------------ EffectiveApp:	  -> 1.8 ( varies with mikros, varzooms and TC's)
    |                       |  |     |  |        |     |  |  |  |  |  |  +--------------- MCU_Version:	see Nikon patents
    |                       |  |     |  |        |     |  |  |  |  |  +------------------ MaxAppLong:	  -> 1.8
    |                       |  |     |  |        |     |  |  |  |  +--------------------- MaxAppShort:	  -> 1.8
    |                       |  |     |  |        |     |  |  |  +------------------------ FocLengthLong:  -> 50	mm
    |                       |  |     |  |        |     |  |  +--------------------------- FocLengthShort: -> 50	mm
    |                       |  |     |  |        |     |  +------------------------------ AppStops:	  -> 7 1/3
    |                       |  |     |  |        |     +--------------------------------- LensID:	  -> 118
    |                       |  |     |  |        +--------------------------------------- ActFocLength:	  -> 50mm (changes with zooming or TC's)
    |                       |  |     |  +------------------------------------------------ Distance (only D lenses): see N90s-memory-map.txt
    |                       |  |     +--------------------------------------------------- LensControl: 0x40 = M/A, 0x60 = M, 0x20 = A, 0x00 = A
    |                       |  +--------------------------------------------------------- LensPos: if < 0x10 lens is @ infinity (only D)
    |                       +------------------------------------------------------------ LensType: 0x08=D, 0x88=G, 0x89=AFs
    +------------------------------------------------------------------------------------ Aperture for AF elektronics


I think that some of the info in this TAG is used by Nikon Capture, but I can't verify that.
The vignetting info (see patents) may be in the lens data, but where?

-------------------------------

The values from position 0x12 to 0x18 (LensID to MCU_Version) seem to be constant. They could be used to exactly identify a lens.
A unique ID is very helful for a lens correction database, since there are 3rd party lenses with same focallength and aperture
values.

One could only use the lens ID with Nikkor lenses, but there are some 3rd party lenses that use the Nikon ID for a different lens.
Some examples:           pos:  12 13 14 15 16 17 18

3rd party macro: 90mm F/2.5 :  1E 5D 64 64 20 20 13
Nikon Nikkor:    60mm F/2.8 :  1E 54 56 56 24 24 13

Tokina:       12-24mm F/4 G :  00 3C 1F 37 30 30 00
Nikon Nikkor: 12-24mm F/4 G :  7A 3C 1F 37 30 30 7E


I suggest following byteorder for the ID: 14-15-16-17-13-12-18. Stored as ASCII-HEX with '-' between the bytes
So the IDs would be:
3rd party macro: 90mm F/2.5 :    64-64-20-20-5D-1E-13 : ??? Makro 90/2.5
Nikon Nikkor:    60mm F/2.8 :    56-56-24-24-54-1E-13 : Nikon Mikro Nikkor AF 60/2.8
Tokina:       12-24mm F/4 G :    1F-37-30-30-3C-00-00 : Tokina AT-X pro 12-24/4D DX
Nikon Nikkor: 12-24mm F/4 G :    1F-37-30-30-3C-7A-7E : Nikon Nikkor 12-24DX

Adding an exact lens name string would be nice. Best to get the name from tghe official press release (I didn't with the example).

-------------------------------------------------------------------------------
-------------------------------------------------------------------------------

Conclusion
----------

Part of the lensdata is useful for generating an unique lens id.

With 'D' lenses also:
- Subject distance can be displayed
- The distance information can be used for vignette and distrotion correction.
- With exact lens info and distance we can calculate the reproduction ratio of a macro lens.

From the focal Length Infos the use and factor of an TC can be calculated.

Happy hacking ;)
