Takanobu Muraguchi
/
Nikon_lens_sniffer
nikon f mount protocol sniffer
Revision 0:bc8e9dd8b17f, committed 2018-12-05
- Comitter:
- muraguchi
- Date:
- Wed Dec 05 16:58:35 2018 +0000
- Commit message:
- initial release
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r bc8e9dd8b17f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Dec 05 16:58:35 2018 +0000 @@ -0,0 +1,63 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); + +Ticker event_timer; + +#define ARY_SIZE 1000 + +SPISlave spi_slave(p5,p6,p7,p8); +// p5 mosi +// p6 nc +// p7 sclk +// p8 hs + +//DigitalIn sclk(p7); +//DigitalIn data(p5); +//DigitalIn hs(p8); + +int event_timer_time=0; + +void event_timer_progress() +{ + event_timer_time++; +} + +int reverse_byte(int byte) +{ + 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); +} + + +int main() +{ + int com_seq=0; + int com_ary[ARY_SIZE]; + int time_ary[ARY_SIZE]; + + // 100us ticker + event_timer.attach(&event_timer_progress, 0.0001); + + spi_slave.format(8, 3); + + pc.baud(115200); + pc.printf("Nikon lens serial interface sniffer.\n"); + while(com_seq<ARY_SIZE) + { + if(spi_slave.receive()) + { + com_ary[com_seq]=spi_slave.read(); + time_ary[com_seq]= event_timer_time; + com_seq++; + } + } + + for(int l=0;l<ARY_SIZE;l++) + { + int rv_dat=reverse_byte(com_ary[l]); + if(rv_dat>=0x20 && rv_dat<=0x7e) + pc.printf("%08.01fms %02X '%c'\n",time_ary[l]/10.0,rv_dat,rv_dat); + else + pc.printf("%08.01fms %02X '-'\n",time_ary[l]/10.0,rv_dat); + } +} \ No newline at end of file
diff -r 000000000000 -r bc8e9dd8b17f mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Dec 05 16:58:35 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187 \ No newline at end of file