From 450a67a8ee5d4ebd5da38e765aaafc25d54a5d9f Mon Sep 17 00:00:00 2001 From: Philippe Marzouk Date: Tue, 22 Aug 2000 20:30:48 +0000 Subject: [PATCH] added serial uploading git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@943 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/canon/Changelog | 5 +++- camlibs/canon/TODO | 1 + camlibs/canon/canon.c | 18 +++++++++----- camlibs/canon/psa50.c | 55 +++++++++++++++++++++++++++-------------- camlibs/canon/serial.c | 8 +++--- 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/camlibs/canon/Changelog b/camlibs/canon/Changelog index cf37c6487..9e9415742 100644 --- a/camlibs/canon/Changelog +++ b/camlibs/canon/Changelog @@ -1,5 +1,8 @@ 2000-08-22 - phil changed serial.c to the latest libusb from CVS (thanks Scott) + philm changed serial.c to the latest libusb from CVS (thanks Scott) + Got serial upload working. it should work at 115200 for S10 + and S20 but only 57600 for everyone else :-(. It is *very* + slow. 2000-08-21 philm deleted unused functions from canon.c (old configure box and related functions). diff --git a/camlibs/canon/TODO b/camlibs/canon/TODO index 03f629186..f60185795 100644 --- a/camlibs/canon/TODO +++ b/camlibs/canon/TODO @@ -8,6 +8,7 @@ - Uploading : I'm working on it but there are problems. I will soon include the preliminary support I got for people with S10 and S20 to test as it seems easier to get them working (s10sh does it). + (08/22/2000 - done for serial but slow) - The configuration dialog has to be made with the new toolkit independent functions provided by gphoto2. It should use gp_config_get and gp_config_set to retrieve and store its configuration information. diff --git a/camlibs/canon/canon.c b/camlibs/canon/canon.c index 1d26a757b..e91eb74b0 100644 --- a/camlibs/canon/canon.c +++ b/camlibs/canon/canon.c @@ -940,11 +940,20 @@ int camera_file_delete(Camera *camera, char *folder, char *filename) int camera_file_put(Camera *camera, CameraFile *file, char *folder) { + struct canon_info *cs = (struct canon_info*)camera->camlib_data; char destpath[300], destname[300]; int j; + if (cs->speed>57600 && + (strcmp(camera->model,"Canon PowerShot A50") == 0 + || strcmp(camera->model, "Canon PowerShot Pro70") == 0)) { + gp_camera_message(camera, + "Speeds greater than 57600 are not supported for uploading to this camera"); + return GP_ERROR; + } + if (!check_readiness(camera)) { - return 0; + return GP_ERROR; } strcpy(destname,file->name); @@ -954,17 +963,14 @@ int camera_file_put(Camera *camera, CameraFile *file, char *folder) return GP_ERROR; } - /* FIXME: Just a hack for testing purposes then we will have to - find the suitable directory to create or to store in*/ - sprintf(destpath,"D:\\DCIM\\CANONMSC\\"); - sprintf(destname,"PLAY_00.MRK"); - /* end of FIXME */ + sprintf(destpath,"D:\\DCIM\\100CANON\\"); j = strrchr(destpath,'\\') - destpath; destpath[j] = '\0'; if(!psa50_directory_operations(camera,destpath, DIR_CREATE)) return GP_ERROR; + psa50_delete_file(camera,destname,destpath); destpath[j] = '\\'; diff --git a/camlibs/canon/psa50.c b/camlibs/canon/psa50.c index 02aae3ecd..c6ddbb8c8 100644 --- a/camlibs/canon/psa50.c +++ b/camlibs/canon/psa50.c @@ -75,7 +75,8 @@ int psa50_send_frame(Camera *camera, const unsigned char *pkt,int len) } } *p++ = CANON_FEND; - return !canon_serial_send(camera, buffer,p-buffer,USLEEP2); + + return !canon_serial_send(camera, buffer,p-buffer,USLEEP2); } @@ -339,7 +340,7 @@ static int psa50_send_msg(Camera *camera,unsigned char mtype, total = pos-pkt; - if (mtype == 0x3 && dir == 0x11) { + if (mtype == 0x3 && dir == 0x11) { // uploading pkt[MSG_LEN_LSB] = total & 0xff; pkt[MSG_LEN_MSB] = total >> 8; @@ -1711,7 +1712,7 @@ int psa50_put_file_usb(Camera *camera, CameraFile *file, char *destname, char *d */ #define HDR_FIXED_LEN 30 -#define DATA_BLOCK 512 +#define DATA_BLOCK 900 int psa50_put_file_serial(Camera *camera, CameraFile *file, char *destname, char *destpath) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; @@ -1722,6 +1723,7 @@ int psa50_put_file_serial(Camera *camera, CameraFile *file, char *destname, char char offset2[4]; int block_len; char block_len2[4]; + int sent=0; int i,j=0,len, hdr_len; // int okay, good_ack; @@ -1730,24 +1732,39 @@ int psa50_put_file_serial(Camera *camera, CameraFile *file, char *destname, char filename[i]='\0'; hdr_len = HDR_FIXED_LEN + strlen(file->name) + strlen(destpath); - - block_len = 118; - for(i=0;i<4;i++) { - offset2[i] = (offset >> (8*i)) & 0xff; - block_len2[i] = (block_len >> (8*i)) & 0xff; - } + while(sentsize) { + + if(file->size < DATA_BLOCK) + block_len = file->size; + else if ((file->size - sent < DATA_BLOCK)) + block_len = file->size - sent; + else + block_len = DATA_BLOCK; + + offset = sent; + fprintf(stderr,"offset: %i, sent: %i\n",offset,sent); + + for(i=0;i<4;i++) { + offset2[i] = (offset >> (8*i)) & 0xff; + block_len2[i] = (block_len >> (8*i)) & 0xff; + } - for(i=0; idata[j]; - j++; - } - - msg = psa50_serial_dialogue(camera,0x3,0x11,&len,"\x02\x00\x00\x00",4, - offset2,4,block_len2,4, - destpath,strlen(destpath),destname,strlen(destname)+1, - "
\r\nCIFF_VERSION=1.00\r\n\r\n\r\n",118,
+		for(i=0; idata[j];
+			j++;
+		}
+	
+		msg = psa50_serial_dialogue(camera,0x3,0x11,&len,"\x02\x00\x00\x00",4,
+				offset2,4,block_len2,4,
+			    destpath,strlen(destpath),destname,strlen(destname)+1,
+				buf,block_len,
 				NULL);
+		
+		sent += block_len;
+		
+		fprintf(stderr,"Message sent!\n");
+	}
 	
 /* 
     for(i=0; i0 && cs->model == CANON_PS_A50) {
+    if (sleep>0 && cs->model == CANON_PS_A50 && cs->speed>57600) {
 		for(i=0;igdev,buf,1);
+			gpio_write(cs->gdev,(char*)buf,1);
 			buf++;
 			usleep(sleep);
 		}
     } else {
-		gpio_write(cs->gdev,buf,len);
+		gpio_write(cs->gdev,(char*)buf,len);
     }
 	
     return 0;