/* send bug reports and comments to Joerg.Schulenburg@physik.(NO)uni-magdeburg.(SPAM)de 20.07.1997: compile: TurboC 2.0 huge model (-mh) if you set transfer rate, don't forget to set it back to 9600 at the end :) you should switch off any disk caches !? -> RAM use inline? (asm) code! or debug pg via system/script HALT useful? harddisk cash? load into RAM? 21.05.1998: linux: gcc -O2 whether chmod o+rw /dev/ttyS1 or give the executable root rights -------------------------------------snip-------------------------------- #!sh # DC25 communication via /dev/ttyS1 9600 bps + even parity + 1 stop stty sane < /dev/ttyS1 stty 9600 cs8 parenb -parodd raw min 0 time 10 < /dev/ttyS1 # reset ? #printf "\x7e\x00\x00\x00\x00\x00\x00\x1a" >/dev/ttyS1 #dd if=/dev/ttyS1 of=o bs=1 count=1 # status dd if=/dev/ttyS1 of=o bs=1 count=259 & # timing problems !!! printf "\x7f\x00\x00\x00\x00\x00\x00\x1a" >/dev/ttyS1 printf "\xd2" >/dev/ttyS1 sleep 10 s ------------------------------------snip---------------------------------- -------------------------------------------------------------------------- */ #include #include #include int ec=0,vvv=0; /* buffer, ErrorCode, Verbosemode */ /* ------------------- system specific routines (RS232) -------------- */ #if defined(__MSDOS__) && defined(__TURBOC__) #pragma options -j5 -g5 -G -O -Z -a -mh /* maxnum errors, huge model */ /* unsigned char _Cdecl inportb(int portid); void _Cdecl outportb(int portid, unsigned char value); void _Cdecl disable (void); void _Cdecl enable (void); int _Cdecl peek (unsigned segment, unsigned offset); char _Cdecl peekb (unsigned segment, unsigned offset); */ #include #define Port 0x2f8 /* COM1=0x3f8 COM2=0x2f8 */ /* hmm wann wird Port+5 rueckgesetzt? bei lesen Port ! */ /* #defines/inlines are much faster */ #define rdy() inportb(Port+5) /* stat & 1 */ #define getb() inportb(Port) #define putb(b) outportb(Port,b) #define clk() peek(0,0x46c) /* 55ms */ static int clk2(){ int i;outportb(0x70,0);i=(int)inportb(0x71);return(10*(i>>4)+(i&15));} /* CMOS+0 OUT 70,+0;IN 71;allows __cli__ etc. */ /* time() = CMOS */ void sendb(int b){ /* when ready to send */ while(!(inportb(Port+5) & 0x20)); outportb(Port,b); } long ini_serial(long bps){ int old; outportb(Port+4,0x00); /* modem controls: 0x10=loopback 0=default */ outportb(Port+2,0x00); /* no interrupts */ outportb(Port+3,0x80); /* line controls: baudrate = 115k/divisor */ old=inp(Port+0)+((long)inp(Port+1))<<8;if(old)old=115200l/old; outportb(Port+0,(115200l/bps) % 256); /* divisor */ outportb(Port+1,(115200l/bps) / 256); /* highbyte */ outportb(Port+3,0x03+0x18); /* 03=8,n,1 +08=parity +10=even */ outportb(Port+1,0x00); /* no int */ inportb(Port); /* flags ruecksetzen */ getb(); /* clear receiver */ return old; } int open_s(){}; int close_s(){}; /* ------------------------------------------------------------------- */ #elif defined(__linux__) /* or other unix ???, report to me! */ #define DEVICE "/dev/ttyS1" // #define DEVICE "/dev/cua1" long ini_serial(long bps){ int i;char s[100]; /* need root rights */ static long new_old=1200l; long old; old=new_old;new_old=bps; /* --- DC25 /dev/ttyS1=/dev/cua1 9600 bps + even parity + 1 stop bit */ /* --- stty gnu-1.12 works well --- */ i=system("stty sane <" DEVICE ); if(i){ fprintf(stderr,"stty sane < " DEVICE "\n"); exit(1); } if(vvv){ printf("ok ini1 ");fflush(stdout); } /* --- min 0 = return after 0 inputs, time 10 = wait max 1s --- */ sprintf(s,"stty %ld cs8 parenb -parodd raw -echo min 0 time 50 < " DEVICE , bps); i=system(s); if(i){ fprintf(stderr,"stty failed, no root?\n"); exit(1); } if(vvv)printf("ok ini2\n"); return old; } FILE *f1; /* serial device (char) */ int open_s(){ f1=fopen(DEVICE,"w+b"); if(!f1){ fprintf(stderr,"error: open " DEVICE "\n"); exit(1); } } int close_s(){ fclose(f1); // system("stty -a < " DEVICE ); } /* not to less and not to much! try it out! AMD486DX100=10 ? */ int delay(int ms){ int i,j;for(i=0;i1026) */ #define D1 ((char)0xd1) char buf[BL],k25[0x0400]={ 0x4D,0x4D, 0,0x2A, 0, 0, 0,0x08, 0,0x28, 0,0xFE, 0,0x04, 0, 0, /* 0100 MM.*............ */ 0,0x01, 0, 0, 0,0x01,0x01, 0, 0,0x03, 0, 0, 0,0x01, 0,0x50, /* 0110 ...............P */ 0, 0,0x01,0x01, 0,0x03, 0, 0, 0,0x01, 0,0x3C, 0, 0,0x01,0x02, /* 0120 ...........<.... */ 0,0x03, 0, 0, 0,0x03, 0, 0,0x01,0x5E,0x01,0x03, 0,0x03, 0, 0, /* 0130 .........^...... */ 0,0x01, 0,0x01, 0, 0,0x01,0x06, 0,0x03, 0, 0, 0,0x01, 0,0x02, /* 0140 ................ */ 0, 0,0x01,0x0E, 0,0x02, 0, 0, 0,0x08, 0, 0,0x01,0x64,0x01,0x0F, /* 0150 .............d.. */ 0,0x02, 0, 0, 0,0x16, 0, 0,0x01,0x6C,0x01,0x10, 0,0x02, 0, 0, /* 0160 .........l...... */ 0,0x1A, 0, 0,0x01,0x82,0x01,0x11, 0,0x04, 0, 0, 0,0x01, 0, 0, /* 0170 ................ */ 0x04, 0,0x01,0x12, 0,0x03, 0, 0, 0,0x01, 0,0x01, 0, 0,0x01,0x15, /* 0180 ................ */ 0,0x03, 0, 0, 0,0x01, 0,0x03, 0, 0,0x01,0x16, 0,0x03, 0, 0, /* 0190 ................ */ 0,0x01, 0,0x3C, 0, 0,0x01,0x17, 0,0x04, 0, 0, 0,0x01, 0, 0, /* 01A0 ...<............ */ 0x38,0x40,0x01,0x1A, 0,0x05, 0, 0, 0,0x01, 0, 0,0x01,0x9C,0x01,0x1B, /* 01B0 8@.............. */ 0,0x05, 0, 0, 0,0x01, 0, 0,0x01,0xA4,0x01,0x1C, 0,0x03, 0, 0, /* 01C0 ................ */ 0,0x01, 0,0x01, 0, 0,0x01,0x28, 0,0x03, 0, 0, 0,0x01, 0,0x02, /* 01D0 .......(........ */ 0, 0,0x01,0x31, 0,0x02, 0, 0, 0,0x11, 0, 0,0x01,0xAC,0x01,0x32, /* 01E0 ...1...........2 */ 0,0x02, 0, 0, 0,0x14, 0, 0,0x01,0xBE,0x01,0x4A, 0,0x04, 0, 0, /* 01F0 ...........J.... */ 0,0x01, 0, 0,0x02,0x10,0x82,0x98, 0,0x02, 0, 0, 0,0x21, 0, 0, /* 0200 .............!.. */ 0x01,0xD2,0x82,0x9D, 0,0x05, 0, 0, 0,0x01, 0, 0,0x01,0xF4,0x90,0x03, /* 0210 ................ */ 0,0x02, 0, 0, 0,0x14, 0, 0,0x01,0xFC,0x92,0x09, 0,0x03, 0, 0, /* 0220 ................ */ 0,0x01, 0,0x10, 0, 0,0x92,0x11, 0,0x03, 0, 0, 0,0x01, 0,0x01, /* 0230 ................ */ 0, 0,0x92,0x16, 0,0x01, 0, 0, 0,0x04,0x01, 0, 0, 0,0x92,0x17, /* 0240 ................ */ 0,0x03, 0, 0, 0,0x01, 0,0x02, 0, 0, 0, 0, 0, 0, 0,0x08, /* 0250 ................ */ 0,0x08, 0,0x08,0x44,0x43,0x30,0x30,0x30,0x31,0x48, 0,0x45,0x61,0x73,0x74, /* 0260 ....DC0001H.East */ 0x6D,0x61,0x6E,0x20,0x4B,0x6F,0x64,0x61,0x6B,0x20,0x43,0x6F,0x6D,0x70,0x61,0x6E, /* 0270 man Kodak Compan */ 0x79, 0,0x4B,0x4F,0x44,0x41,0x4B,0x20,0x44,0x43,0x32,0x35,0x20,0x44,0x49,0x47, /* 0280 y.KODAK DC25 DIG */ 0x49,0x54,0x41,0x4C,0x20,0x43,0x41,0x4D,0x45,0x52,0x41, 0, 0, 0, 0,0x48, /* 0290 ITAL CAMERA....H */ 0, 0, 0,0x01, 0, 0, 0,0x48, 0, 0, 0,0x01,0x44,0x43,0x32,0x35, /* 02A0 .......H....DC25 */ 0x20,0x43,0x61,0x6D,0x65,0x72,0x61,0x20,0x56,0x31,0x2E,0x30, 0, 0,0x30,0x30, /* 02B0 Camera V1.0..00 */ 0x30,0x30,0x3A,0x30,0x30,0x3A,0x30,0x30,0x20,0x30,0x30,0x3A,0x30,0x30,0x3A,0x30, /* 02C0 00:00:00 00:00:0 */ 0x30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 02D0 0............... */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 02E0 ................ */ 0, 0, 0, 0, 0, 0, 0,0x28, 0, 0, 0,0x0A,0x30,0x30,0x30,0x30, /* 02F0 .......(....0000 */ 0x3A,0x30,0x30,0x3A,0x30,0x30,0x20,0x30,0x30,0x3A,0x30,0x30,0x3A,0x30,0x30, 0, /* 0300 :00:00 00:00:00. */ 0,0x11, 0,0xFE, 0,0x04, 0, 0, 0,0x01, 0, 0, 0, 0,0x01, 0, /* 0310 ................ */ 0,0x03, 0, 0, 0,0x01,0x01,0xED, 0, 0,0x01,0x01, 0,0x03, 0, 0, /* 0320 ................ */ 0,0x01,0x01,0x75, 0, 0,0x01,0x02, 0,0x03, 0, 0, 0,0x01, 0,0x08, /* 0330 ...u............ */ 0, 0,0x01,0x03, 0,0x03, 0, 0, 0,0x01, 0,0x01, 0, 0,0x01,0x06, /* 0340 ................ */ 0,0x03, 0, 0, 0,0x01,0x80,0x23, 0, 0,0x01,0x11, 0,0x04, 0, 0, /* 0350 .......#........ */ 0,0x01, 0, 0,0x3C,0x40,0x01,0x12, 0,0x03, 0, 0, 0,0x01, 0,0x01, /* 0360 ....<@.......... */ 0, 0,0x01,0x15, 0,0x03, 0, 0, 0,0x01, 0,0x01, 0, 0,0x01,0x16, /* 0370 ................ */ 0,0x03, 0, 0, 0,0x01,0x01,0x75, 0, 0,0x01,0x17, 0,0x04, 0, 0, /* 0380 .......u........ */ 0,0x01, 0,0x02,0x24,0x40,0x01,0x1A, 0,0x05, 0, 0, 0,0x01, 0, 0, /* 0390 ....$@.......... */ 0x02,0xE2,0x01,0x1B, 0,0x05, 0, 0, 0,0x01, 0, 0,0x02,0xE2,0x01,0x1C, /* 03A0 ................ */ 0,0x03, 0, 0, 0,0x01, 0,0x01, 0, 0,0x01,0x28, 0,0x03, 0, 0, /* 03B0 ...........(.... */ 0,0x01, 0,0x02, 0, 0,0x82,0x8D, 0,0x03, 0, 0, 0,0x02, 0,0x02, /* 03C0 ................ */ 0,0x04,0x82,0x8E, 0,0x01, 0, 0, 0,0x08, 0, 0,0x02,0xF2, 0, 0, /* 03D0 ................ */ 0, 0, 0, 0, 0,0x48, 0, 0, 0,0x01, 0, 0, 0,0x48, 0, 0, /* 03E0 .....H.......H.. */ 0,0x01,0x01,0x04,0x05,0x03,0x04,0x01,0x03,0x05, 0, 0, 0, 0, 0, 0, /* 03F0 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0400 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0410 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0420 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0430 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0440 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0450 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0460 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0470 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0480 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0490 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 04A0 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 04B0 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 04C0 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 04D0 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 04E0 ................ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 04F0 ................ */ }; char c8[]={0xE1,0,0,0,0,0,0,0x1a}; char cmd[][10]={ /* len - timeout/s - command#8 */ {8, 1,0x41,0,0x96, 0,0,0,0,0x1a}, /* 0 A bps= 9600 (default) */ {8, 1,0x41,0,0x19,0x20,0,0,0,0x1a}, /* 1 A bps= 19200 */ {8, 1,0x41,0,0x38,0x40,0,0,0,0x1a}, /* 2 A bps= 38400 */ {8, 1,0x41,0,0x57,0x60,0,0,0,0x1a}, /* 3 A bps= 57600 */ {8, 1,0x41,0,0x11,0x52,0,0,0,0x1a}, /* 4 A bps=115200 */ {8, 2,0x7f,0, 0, 0,0,0,0,0x1a}, /* 5  get status */ {1, 1,0xd2,0, 0, 0,0,0,0, 0}, /* 6 ² ready for next data */ {1, 5,0xe1,0, 0, 0,0,0,0, 0}, /* 7 é PC error */ {8, 5,0x71,0, 0, 0,0,0,0,0x1a}, /* 8 q #2=resolution 0=high 1=low */ {8, 5,0x72,0, 0, 0,0,0,0,0x1a}, /* 9 r #2=flash 0=auto 1=on 2=off */ {8,10,0x77,0, 0, 0,0,0,0,0x1a}, /*10 w take a picture */ {8,30,0x7a,0, 0, 0,0,0,0,0x1a}, /*11 z erase all pictures #2??? */ {8, 2,0x56,0, 0, 0,0,0,0,0x1a}, /*12 V load 80x60 thumnail #3 */ {8, 2,0x51,0, 0, 0,0,0,0,0x1a}, /*13 Q load picture #3 */ {8, 2,0x55,0, 0, 0,0,0,0,0x1a}, /*14 U load info picture #3 ??? */ {8, 5,0x7e,0, 0, 0,0,0,0,0x1a}, /*15 ~ reset (click) ??? */ {0, 0, 0,0, 0, 0,0,0,0, 0}};/* empty */ /* 76 -> d1 */ void oute(int e){ if(!e) return; /* no error */ fprintf(stderr,"error %04x: ",e); switch(e){ case 2: fprintf(stderr,"wrong CRC");break; case 3: fprintf(stderr,"time out");break; case 4: fprintf(stderr,"0xD1 expected, but not received");break; case 5: fprintf(stderr,"0x00 expected, but not received");break; case 6: fprintf(stderr,"file operation");break; case 7: fprintf(stderr,"not enough memory");break; case 8: fprintf(stderr,"unknown camera");break; default: ; } fprintf(stderr,"\n"); /* if(e!=2) */ exit(e);} /* static inline */ int err(int b){ b&=0x1e00; if(b & 0x0200)fprintf(stderr,""); if(b & 0x0400)fprintf(stderr,""); if(b & 0x0800)fprintf(stderr,""); if(b & 0x1000)fprintf(stderr,""); return b;} void nl(){ printf("\n"); /* column=0; */ } void ob(char b){ printf(" %02x",255&(int)b); } long takt=300000l; /* 3000 * Takt/MHz besser: V24-INT und time() */ /* --- function: send command --- args: send_cmd,num_receive,receive_buff --- return: -1 if an error, 0 else */ /* ------------------- system specific routines (RS232) -------------- */ #if defined(__MSDOS__) && defined(__TURBOC__) int sendcmd(char *cmd,int rn,char *rbuf){ int i,j,t,sn; char cc=0,*p=rbuf;long t1,t3,t4; t1=0l; sn=cmd[0];if(sn>1)delay(70); /* timing problems: should be >50ms */ ec=0;t=clk()+18*cmd[1]; t=(clk2()+cmd[1]+1)%60; t3=takt; t4=t=cmd[1]; if(vvv){ printf("\nto send :"); for(i=2;i1)?1:0);j1)for(j=0;j1)delay(70); /* timing problems: should be >50ms */ ec=0;clearerr(f1); if(vvv){ printf("\nto send :"); for(i=2;i1 || ec!=0)for(j=0;j - set transfer rate (0..4: 9k6,19k2,38k4,57k6,115k2)\n" " b - set baud rate (0..4: 9k6,19k2,38k4,57k6,115k2)\n" " s - get camera status information\n" " r - set resolution 0=high 1=low\n" " f - set flash 0=auto 1=on 2=off\n" " d - delay about n ms p - take a picture\n" " e - erase all pictures 1 - 7e reset click ???\n" " a - load all pictures v - verbose mode\n" ,argv[0]); return -1; } ini_serial(9600l); /* 9600 bps, 8 bits, even parity, 1 stopbit */ open_s(); for(i=1;i9)?pi%16-10+'A':pi%16+'0'; k25[0x168]=(pi/16>9)?pi/16-10+'A':pi/16+'0'; /* set date ??? */ wr(k25,1024); printf("thumbnail - "); /* function 56 = thumb nail, offset 0400 14*1024l+64l */ cmd[12][5]=pi+1; sendcmd(cmd[12],1026,buf); wr(buf+1,1024); for(k=0;k<13;k++){ sendcmd(cmd[ 6],1025,buf); wr(buf ,1024); } /* last block */ sendcmd(cmd[ 6],1025,buf); wr(buf , 64); /* close */ sendcmd(cmd[ 6], 1,buf); printf("data 1+%3d blks - ",blks); /* function 51 = get CCD picture data 122/61 offset 3c40 */ cmd[13][5]=pi+1; sendcmd(cmd[13],1026,buf); wr(buf+1,1024); for(k=1;k