nikon f mount protocol sniffer

Dependencies:   mbed

Committer:
muraguchi
Date:
Wed Dec 05 16:58:35 2018 +0000
Revision:
0:bc8e9dd8b17f
initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
muraguchi 0:bc8e9dd8b17f 1 #include "mbed.h"
muraguchi 0:bc8e9dd8b17f 2
muraguchi 0:bc8e9dd8b17f 3 Serial pc(USBTX, USBRX);
muraguchi 0:bc8e9dd8b17f 4
muraguchi 0:bc8e9dd8b17f 5 Ticker event_timer;
muraguchi 0:bc8e9dd8b17f 6
muraguchi 0:bc8e9dd8b17f 7 #define ARY_SIZE 1000
muraguchi 0:bc8e9dd8b17f 8
muraguchi 0:bc8e9dd8b17f 9 SPISlave spi_slave(p5,p6,p7,p8);
muraguchi 0:bc8e9dd8b17f 10 // p5 mosi
muraguchi 0:bc8e9dd8b17f 11 // p6 nc
muraguchi 0:bc8e9dd8b17f 12 // p7 sclk
muraguchi 0:bc8e9dd8b17f 13 // p8 hs
muraguchi 0:bc8e9dd8b17f 14
muraguchi 0:bc8e9dd8b17f 15 //DigitalIn sclk(p7);
muraguchi 0:bc8e9dd8b17f 16 //DigitalIn data(p5);
muraguchi 0:bc8e9dd8b17f 17 //DigitalIn hs(p8);
muraguchi 0:bc8e9dd8b17f 18
muraguchi 0:bc8e9dd8b17f 19 int event_timer_time=0;
muraguchi 0:bc8e9dd8b17f 20
muraguchi 0:bc8e9dd8b17f 21 void event_timer_progress()
muraguchi 0:bc8e9dd8b17f 22 {
muraguchi 0:bc8e9dd8b17f 23 event_timer_time++;
muraguchi 0:bc8e9dd8b17f 24 }
muraguchi 0:bc8e9dd8b17f 25
muraguchi 0:bc8e9dd8b17f 26 int reverse_byte(int byte)
muraguchi 0:bc8e9dd8b17f 27 {
muraguchi 0:bc8e9dd8b17f 28 return ((byte&0x80)>>7)|((byte&0x40)>>5) | ((byte&0x20)>>3) | ((byte&0x10)>>1) | ((byte&0x08)<<1) | ((byte&0x04)<<3) | ((byte&0x02)<<5) | ((byte&0x01)<<7);
muraguchi 0:bc8e9dd8b17f 29 }
muraguchi 0:bc8e9dd8b17f 30
muraguchi 0:bc8e9dd8b17f 31
muraguchi 0:bc8e9dd8b17f 32 int main()
muraguchi 0:bc8e9dd8b17f 33 {
muraguchi 0:bc8e9dd8b17f 34 int com_seq=0;
muraguchi 0:bc8e9dd8b17f 35 int com_ary[ARY_SIZE];
muraguchi 0:bc8e9dd8b17f 36 int time_ary[ARY_SIZE];
muraguchi 0:bc8e9dd8b17f 37
muraguchi 0:bc8e9dd8b17f 38 // 100us ticker
muraguchi 0:bc8e9dd8b17f 39 event_timer.attach(&event_timer_progress, 0.0001);
muraguchi 0:bc8e9dd8b17f 40
muraguchi 0:bc8e9dd8b17f 41 spi_slave.format(8, 3);
muraguchi 0:bc8e9dd8b17f 42
muraguchi 0:bc8e9dd8b17f 43 pc.baud(115200);
muraguchi 0:bc8e9dd8b17f 44 pc.printf("Nikon lens serial interface sniffer.\n");
muraguchi 0:bc8e9dd8b17f 45 while(com_seq<ARY_SIZE)
muraguchi 0:bc8e9dd8b17f 46 {
muraguchi 0:bc8e9dd8b17f 47 if(spi_slave.receive())
muraguchi 0:bc8e9dd8b17f 48 {
muraguchi 0:bc8e9dd8b17f 49 com_ary[com_seq]=spi_slave.read();
muraguchi 0:bc8e9dd8b17f 50 time_ary[com_seq]= event_timer_time;
muraguchi 0:bc8e9dd8b17f 51 com_seq++;
muraguchi 0:bc8e9dd8b17f 52 }
muraguchi 0:bc8e9dd8b17f 53 }
muraguchi 0:bc8e9dd8b17f 54
muraguchi 0:bc8e9dd8b17f 55 for(int l=0;l<ARY_SIZE;l++)
muraguchi 0:bc8e9dd8b17f 56 {
muraguchi 0:bc8e9dd8b17f 57 int rv_dat=reverse_byte(com_ary[l]);
muraguchi 0:bc8e9dd8b17f 58 if(rv_dat>=0x20 && rv_dat<=0x7e)
muraguchi 0:bc8e9dd8b17f 59 pc.printf("%08.01fms %02X '%c'\n",time_ary[l]/10.0,rv_dat,rv_dat);
muraguchi 0:bc8e9dd8b17f 60 else
muraguchi 0:bc8e9dd8b17f 61 pc.printf("%08.01fms %02X '-'\n",time_ary[l]/10.0,rv_dat);
muraguchi 0:bc8e9dd8b17f 62 }
muraguchi 0:bc8e9dd8b17f 63 }