├── README.md ├── capture_emount.sh ├── decode_emount.sh ├── emount_plotdata.py └── multidecode.mk /README.md: -------------------------------------------------------------------------------- 1 | Miscellaneous tools and scripts for reverse engineering Sony's E-mount lens protocol 2 | 3 | I'll organize/document this better later - but take a look at my libsigrokdecode repo along with my sigrok_dumps repo 4 | -------------------------------------------------------------------------------- /capture_emount.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | sigrok-cli -d fx2lafw -c samplerate=6M --continuous -C D0=BODY_VD_LENS,D1=VCC,D2=LENS_CS_BODY,D3=RXD,D4=TXD,D5=BODY_CS_LENS -t VCC=1 -w -O srzip -o $1 3 | -------------------------------------------------------------------------------- /decode_emount.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | sigrok-cli -i $1 -P sony_emount:rx_cs=LENS_CS_BODY:rx=RXD:tx=TXD:tx_cs=BODY_CS_LENS 3 | -------------------------------------------------------------------------------- /emount_plotdata.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import argparse 4 | import binascii 5 | import struct 6 | import matplotlib.pyplot as plt 7 | import numpy as np 8 | 9 | parser = argparse.ArgumentParser(description='Process emount data') 10 | parser.add_argument('--infile', dest='infile', help='input file') 11 | 12 | args = parser.parse_args() 13 | 14 | infile=open(args.infile,'r') 15 | 16 | def apertureval(fstop): 17 | return hex(int((16.0+2*log(fstop,2))*256.0)) 18 | 19 | def valtoaperture(val): 20 | return 2**(val/512.0-8.0) 21 | 22 | #The following is based on info obtained from Leegong's firmware reverse engineering 23 | #Last entry in each of these arrays appears to be unused 24 | #Length of each subgroup in lens status message group 5 25 | group5_lens = [8, 1, 8, 3, 0x0A, 0x1C, 2, 6, 1, 2, 8, 6, 6, 6, 1] 26 | #Length of each subgroup in lens status message group 6 27 | group6_lens = [2, 0x0B, 9, 4, 6, 7] 28 | 29 | seen_lens = [] 30 | 31 | timespos = [] 32 | mpos1 = [] 33 | mpos2 = [] 34 | speeds_p = [] 35 | speeds_s = [] 36 | #times32 = [] 37 | #mpos32_1 = [] 38 | #mpos32_2 = [] 39 | #times34 = [] 40 | #mpos34 = [] 41 | 42 | times1D = [] 43 | pos1D = [] 44 | 45 | times1C = [] 46 | pos1C = [] 47 | 48 | times1F = [] 49 | pos1F = [] 50 | 51 | times22 = [] 52 | pos22 = [] 53 | 54 | times3C = [] 55 | pos3C = [] 56 | 57 | aperturetimes = [] 58 | apertures1 = [] 59 | apertures2 = [] 60 | 61 | aperturestattimes = [] 62 | aperturestats1 = [] 63 | aperturestats2 = [] 64 | 65 | times_cslot1 = [] 66 | types_cslot1 = [] 67 | cslot1_lens = [0x1D, 0x20] 68 | 69 | times_cslot2 = [] 70 | types_cslot2 = [] 71 | cslot2_lens = [0x16, 0x17, 0x1a, 0x1b, 0x1e, 0x24, 0x27] 72 | 73 | lasttime = None 74 | lastpos_p = None 75 | lastpos_s = None 76 | speedp = None 77 | speeds = None 78 | 79 | min_pos = 99999999999999 80 | max_pos = 0 81 | 82 | for line in infile: 83 | [sigrok_parser, data] = line.split(':',1) 84 | [pktts,data] = data.split(',',1) 85 | pktts = float(pktts) 86 | [lenstr,data] = data.split(',',1) 87 | pktlen = int(lenstr.split(':',1)[1],16) 88 | payloadlen = pktlen - 8 89 | [ftype,snum,speed,rxtx,data] = data.split(',',4) 90 | rxtx = int(rxtx.split(':',1)[1]) 91 | if hex(pktlen) not in seen_lens: 92 | seen_lens.append(hex(pktlen)) 93 | pktdata = bytearray.fromhex(data.split('\"',2)[1]) 94 | if(rxtx == 0): 95 | bytesproc = 0 96 | while(bytesproc < payloadlen): 97 | cmdid = pktdata[bytesproc] 98 | if(cmdid == 0x6): 99 | timespos.append(pktts) 100 | string6 = str(pktts) + ": Group 6:" 101 | sum6 = 1 102 | # print str(pktts) + ": Group 6" 103 | for j in range(len(group6_lens)): 104 | #print "\tSubgroup " + str(j) + ": " + binascii.hexlify(pktdata[bytesproc+sum6:bytesproc+sum6+group6_lens[j]]) 105 | if((j == 12) | (j == 13)): 106 | string6 += " Sg " + str(j) + ": " + binascii.hexlify(pktdata[bytesproc+sum6:bytesproc+sum6+group6_lens[j]]) 107 | sum6 += group6_lens[j] 108 | motorpos1 = struct.unpack(' max_pos): 125 | max_pos = motorpos1 126 | if(motorpos1 < min_pos): 127 | min_pos = motorpos1 128 | motorpos2 = struct.unpack(' max_pos): 290 | # max_pos = motorpos1 291 | # if(motorpos1 < min_pos): 292 | # min_pos = motorpos1 293 | # 294 | # motorpos2 = struct.unpack(' $@ 3 | 4 | all: $(subst .sr,.txt,$(wildcard *.sr)) 5 | --------------------------------------------------------------------------------