/* * waits for the Commit value * The function expexts the commandid auf the corresponding command * to determiante, wether a long timeout is needed or not. (Take Photo) */ int mdc800_rs232_waitForCommit (char commandid) { char ch[1]; if (mdc800_io_device_handle == 0) { printCError ("(mdc800_rs232_waitForCommit) Camera is not open !\n"); return 0; } gpio_set_timeout (mdc800_io_device_handle, mdc800_io_getCommandTimeout (commandid) ); if (gpio_read (mdc800_io_device_handle,ch,1) != GPIO_OK) { printCError ("(mdc800_rs232_waitForCommit) Error receiving commit !\n"); return 0; } if (ch[0] != ANSWER_COMMIT ) { printCError ("(mdc800_rs232_waitForCommit) Byte \"%i\" was not the commit !\n",ch[0]); return 0; } return (1); }
/* * waits for the Commit value * The function expects the commandid of the corresponding command * to determine whether a long timeout is needed or not. (Take Photo) */ int mdc800_rs232_waitForCommit (GPPort *port,char commandid) { unsigned char ch[1]; int ret; gp_port_set_timeout(port,mdc800_io_getCommandTimeout(commandid)); ret = gp_port_read(port,ch,1); if (ret!=1) { printCError ("(mdc800_rs232_waitForCommit) Error receiving commit !\n"); return GP_ERROR_IO; } if (ch[0] != ANSWER_COMMIT ) { printCError ("(mdc800_rs232_waitForCommit) Byte \"%i\" was not the commit !\n",ch[0]); return GP_ERROR_IO; } return GP_OK; }
int mdc800_usb_sendCommand(GPPort*port,unsigned char*command,unsigned char*buffer,int length) { unsigned char tmp_buffer [16]; GPPortSettings settings; int ret; printf ("(mdc800_usb_sendCommand) id:%i (%i,%i,%i,%i,%i,%i),answer:%i\n",command[1],command[2],command[3],command[4],command[5],command[6],command[7],length); /* Send the Command */ gp_port_set_timeout(port,MDC800_DEFAULT_TIMEOUT); gp_port_get_settings(port,&settings); settings.usb.outep = MDC800_USB_ENDPOINT_COMMAND; gp_port_set_settings(port,settings); ret = mdc800_usb_readFromIrq(port,0,tmp_buffer,MDC800_DEFAULT_TIMEOUT); if (ret != GP_OK) { fprintf(stderr,"Camera did not get ready before mdc800_usb_sendCommand!\n"); } if ((ret=gp_port_write(port,(char*)command,8)) != 8) { printCError ("(mdc800_usb_sendCommand) sending Command fails (%d)!\n",ret); return ret; } /* receive the answer */ switch (command [1]) { case COMMAND_GET_THUMBNAIL: case COMMAND_GET_IMAGE: gp_port_set_timeout (port, 2000); if (gp_port_read (port,(char*)buffer,64) != 64) { printCError ("(mdc800_usb_sendCommand) requesting 64Byte dummy data fails.\n"); return GP_ERROR_IO; } fprintf(stderr,"got 64 byte\n"); { /* Download loop */ int readen=0; while (readen < length) { if (gp_port_read(port,(char*)(buffer+readen),64) != 64) { printCError ("(mdc800_usb_sendCommand) reading image data fails.\n"); return 0; } fprintf(stderr,"got 64 byte\n"); readen+=64; } } break; default : if (length > 0) { ret = mdc800_usb_readFromIrq (port,1,tmp_buffer, mdc800_io_getCommandTimeout(command[1])); if (ret != GP_OK) { /* Reading fails */ printCError ("(mdc800_usb_sendCommand) receiving answer fails (%d).\n",ret); return ret; } memcpy(buffer,tmp_buffer,length); } } #if 1 /* Waiting for camera to get ready */ ret = mdc800_usb_readFromIrq(port,0,tmp_buffer,mdc800_io_getCommandTimeout (command[1])); if (ret!=GP_OK) { /* Reading fails */ printCError ("(mdc800_usb_sendCommand) camera didn't get ready in the defined intervall ?!\n"); return ret; } #endif return GP_OK; }