summaryrefslogtreecommitdiff
path: root/camlibs/jd11
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2001-12-29 21:20:21 +0000
committerMarcus Meissner <marcus@jet.franken.de>2001-12-29 21:20:21 +0000
commit0ebe7c373d3d3944fb46ae9695000a937b5166d5 (patch)
treeb932b80a1cbb11c7519ed4e67e100bec10663913 /camlibs/jd11
parentde95eb7243261d331b6dad99011b80183410d635 (diff)
downloadlibgphoto2-0ebe7c373d3d3944fb46ae9695000a937b5166d5.tar.gz
* serial.c: Made serial comm much more robust.
Use gp_file_progress properly. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@3617 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'camlibs/jd11')
-rw-r--r--camlibs/jd11/ChangeLog4
-rw-r--r--camlibs/jd11/serial.c95
2 files changed, 76 insertions, 23 deletions
diff --git a/camlibs/jd11/ChangeLog b/camlibs/jd11/ChangeLog
index 178414c7c..b810a0247 100644
--- a/camlibs/jd11/ChangeLog
+++ b/camlibs/jd11/ChangeLog
@@ -3,6 +3,10 @@
* serial.[ch], jd11.c: Use new gp_file_progress.
* jd11.c: Initialize CameraAbilities struct with zeroes.
+ * serial.c: Made serial transfers much more robust, with retries
+ and draining of old data.
+ Also use gp_file_progress correctly (hopefully).
+
2001-12-05 Lutz Müller <urc8@rz.uni-karlsruhe.de>
* serial.c: Include <bayer.h>, not "libgphoto2/bayer.h"
diff --git a/camlibs/jd11/serial.c b/camlibs/jd11/serial.c
index 1d2374df3..ec456c03a 100644
--- a/camlibs/jd11/serial.c
+++ b/camlibs/jd11/serial.c
@@ -73,18 +73,23 @@ static int _send_cmd(GPPort *port,unsigned short cmd) {
return WRITE(port,buf,2);
}
-static void _read_cmd(GPPort *port,unsigned short *xcmd) {
+static int _read_cmd(GPPort *port,unsigned short *xcmd) {
unsigned char buf[2];
- int i = 0;
+ int i = 0,ret;
*xcmd = 0x4242;
do {
- if (2==READ(port,buf,2)) {
- if (buf[0]==0xff)
- break;
- continue;
+ if (1==(ret=READ(port,buf,1))) {
+ if (buf[0]==0xff) {
+ if (1==READ(port,buf+1,1)) {
+ *xcmd = (buf[0] << 8)| buf[1];
+ return GP_OK;
+ }
+ }
+ } else {
+ return ret;
}
} while (i++<10);
- *xcmd = (buf[0]<<8)|buf[1];
+ return GP_ERROR_IO;
}
#if 0
@@ -97,20 +102,46 @@ static void _dump_buf(unsigned char *buf,int size) {
}
#endif
+
+static int _send_cmd_2(GPPort *port,unsigned short cmd, unsigned short *xcmd) {
+ unsigned char buf[2];
+ int ret, tries = 3;
+ *xcmd = 0x4242;
+ while (tries--) {
+ int i = 0;
+ buf[0] = cmd>>8;
+ buf[1] = cmd&0xff;
+ ret = WRITE(port,buf,2);
+ do {
+ if (1==(ret=READ(port,buf,1))) {
+ if (buf[0]==0xff) {
+ if (1==READ(port,buf+1,1)) {
+ *xcmd = (buf[0] << 8)| buf[1];
+ return GP_OK;
+ }
+ }
+ } else {
+ return ret;
+ }
+ } while (i++<3);
+ }
+ return GP_ERROR_IO;
+}
+
int jd11_ping(GPPort *port) {
unsigned short xcmd;
char buf[1];
- int ret;
-
- while (1==READ(port,buf,1))
- /* drain input queue before PING */;
- ret=_send_cmd(port,0xff08);
- if (ret!=GP_OK)
- return ret;
- _read_cmd(port,&xcmd);
- if (xcmd==0xfff1)
- return GP_OK;
- return GP_ERROR_IO;
+ int ret,tries = 3;
+
+ while (tries--) {
+ ret = GP_ERROR_IO;
+ while (1==READ(port,buf,1))
+ /* drain input queue before PING */;
+ ret=_send_cmd_2(port,0xff08,&xcmd);
+ if ((ret==GP_OK) && (xcmd==0xfff1))
+ return GP_OK;
+ }
+ return ret;
}
int
@@ -160,9 +191,11 @@ jd11_set_rgb(GPPort *port,float red, float green, float blue) {
int
jd11_select_index(GPPort *port) { /* select index */
unsigned short xcmd;
+ int ret;
- _send_cmd(port,0xffa4);
- _read_cmd(port,&xcmd);
+ ret = _send_cmd_2(port,0xffa4,&xcmd);
+ if (ret!=GP_OK)
+ return ret;
if (xcmd!=0xff01)
return GP_ERROR_IO;
return GP_OK;
@@ -172,7 +205,8 @@ int
jd11_select_image(GPPort *port,int nr) { /* select image <nr> */
unsigned short xcmd;
- _send_cmd(port,0xffa1);_send_cmd(port,0xff00|nr);
+ _send_cmd(port,0xffa1);
+ _send_cmd(port,0xff00|nr);
_read_cmd(port,&xcmd);
if (xcmd != 0xff01)
return GP_ERROR_IO;
@@ -302,7 +336,9 @@ jd11_get_image_preview(Camera *camera,CameraFile*file,int nr, char **data, int *
char header[200];
GPPort *port = camera->port;
+
if (nr < 0) return GP_ERROR_BAD_PARAMETERS;
+
ret = jd11_select_index(port);
if (ret != GP_OK)
return ret;
@@ -321,10 +357,15 @@ jd11_get_image_preview(Camera *camera,CameraFile*file,int nr, char **data, int *
ret=getpacket(port,indexbuf+curread,readsize);
if (ret==0)
break;
- gp_file_progress(file,(1.0*curread)/xsize);
curread+=ret;
if (ret<200)
break;
+ ret = gp_file_progress(file,(1.0*curread)/xsize);
+ if (ret < 0) { /* cancelled */
+ /* What to do...Just free the stuff we allocated for now.*/
+ free(indexbuf);
+ return ret;
+ }
_send_cmd(port,0xfff1);
}
strcpy(header,"P5\n# gPhoto2 JD11 thumbnail image\n64 48 255\n");
@@ -392,10 +433,18 @@ serial_image_reader(Camera *camera,CameraFile *file,int nr,unsigned char ***imag
ret=getpacket(port,(*imagebufs)[picnum]+curread,readsize);
if (ret==0)
break;
- gp_file_progress(file,1.0*picnum/3.0+(curread*1.0)/sizes[picnum]/3.0);
curread+=ret;
if (ret<200)
break;
+ ret = gp_file_progress(file,1.0*picnum/3.0+(curread*1.0)/sizes[picnum]/3.0);
+ if (ret < 0) { /* cancelled */
+ int j;
+ /* What to do ... Just free the stuff we allocated for now. */
+ for (j=0;j<picnum;j++)
+ free((*imagebufs)[picnum]);
+ free(*imagebufs);
+ return ret;
+ }
_send_cmd(port,0xfff1);
}
}