int mdc800_delete_image (int pn) { printFnkCall ("(mdc800_delete_image) called for Image %i.\n",pn); if (!mdc800_initialize ()) { return 0; } printAPINote ("Delete Image %i \n", pn); if (!mdc800_setTarget (1)) // Image { printAPIError ("(mdc800_delete_image) can't set Target\n"); mdc800_close (); return 0; } if (!mdc800_io_sendCommand (COMMAND_DELETE_IMAGE,pn/100,(pn%100)/10,pn%10,0,0)) { printAPIError ("(mdc800_delete_image ) deleting Image %i fails !.\n",pn); mdc800_close (); return 0; } return 1; }
/* * Force camera to make a picture in the current quality */ int mdc800_take_picture () { unsigned char answer [2]; printFnkCall ("(mdc800_take_picture) called.\n"); if (!mdc800_initialize ()) { return 0; } if (!mdc800_setMode (0)) // Camera Mode { printAPIError ("(mdc800_take_picture) can't set Camera Mode!\n"); mdc800_close (); return 0; } if (!mdc800_setTarget (1)) // Image { printAPIError ("(mdc800_take_pictures) can't set Target\n"); mdc800_close (); return 0; } if (!mdc800_io_sendCommand (COMMAND_TAKE_PICTURE,0,0,0,0,0)) { printAPIError ("(mdc800_take_picture) take picture fails.\n"); mdc800_close (); return 0; } if (!mdc800_setTarget (1)) // Image { printAPIError ("(mdc800_take_pictures) can't set Target\n"); mdc800_close (); return 0; } // Assume taken picture is the last one ! if (!mdc800_io_sendCommand (COMMAND_GET_NUM_IMAGES,0,0,0,(char*)answer,2)) { printAPIError ("(mdc800_take_picture) request Number of taken Pictures fails.\n"); mdc800_close (); return 0; } return (int)answer[0]*256+answer [1]; }
int mdc800_number_of_pictures () { unsigned char answer [2]; printFnkCall ("(mdc800_number_of_pictures) called.\n"); if (!mdc800_initialize ()) { return 0; } if (!mdc800_setTarget (1)) // Image { printAPIError ("(mdc800_number_of_pictures) can't set Target\n"); mdc800_close (); return 0; } /* if (!mdc800_setMode (1)) { printError ("(mdc800_number_of_pictures) can't set Mode\n"); mdc800_close (); return 0; } */ if (!mdc800_io_sendCommand (COMMAND_GET_NUM_IMAGES,0,0,0,(char*)answer,2)) { printAPIError ("(mdc800_getNumberOfImages) request Number of Pictures fails.\n"); mdc800_close (); return 0; } return (int)answer[0]*256+answer [1]; }
struct Image* mdc800_get_picture (int picture_number,int thumbnail) { struct Image* bild=0; printFnkCall ("(mdc800_get_picture) called \n"); if (!mdc800_initialize ()) { return 0; } if (thumbnail) bild=mdc800_getThumbnail (picture_number); else bild=mdc800_getImage (picture_number); if (bild == 0) { mdc800_close (); } return bild; }
/* * sends a command and receives the answer to this * buffer: Strores the answer * length: length of answer or null */ int mdc800_rs232_sendCommand (char* command, char* buffer, int length) { char answer; int fault=0; struct timeval timeout; int i; if (mdc800_io_device_handle == 0) { printCError ("(mdc800_rs232_sendCommand) Camera is not open !\n"); return 0; } printFnkCall ("(mdc800_rs232_sendCommand) id:%i (%i,%i,%i),answer:%i\n",command[1],command[2],command[3],command[4],length); timeout.tv_usec = MDC800_DEFAULT_COMMAND_DELAY*1000; timeout.tv_sec = 0; select (1 , NULL, NULL, NULL, &timeout); gpio_set_timeout (mdc800_io_device_handle, MDC800_DEFAULT_TIMEOUT ); // Send command for (i=0; i<6; i++) { if (gpio_write (mdc800_io_device_handle, &command[i] ,1) != GPIO_OK) { printCError ("(mdc800_rs232_sendCommand) sending Byte %i fails!\n",i); fault=1; } if (gpio_read (mdc800_io_device_handle,&answer,1) != GPIO_OK) { printCError ("(mdc800_rs232_sendCommand) receiving resend of Byte %i fails.\n",i); fault=1; } if (command [i] != answer) { printCError ("(mdc800_rs232_sendCommand) Byte %i differs : send %i, received %i \n",i,command[i],answer); fault=1; } } if (fault) return 0; // Receive answer if (length) { // Some Commands needs a download. switch (command[1]) { case COMMAND_GET_IMAGE: case COMMAND_GET_THUMBNAIL: if (!mdc800_rs232_download (buffer,length)) { printCError ("(mdc800_rs232_sendCommand) download of %i Bytes fails.\n",length); fault=1; } break; default: if (!mdc800_rs232_receive (buffer,length)) { printCError ("(mdc800_rs232_sendCommand) receiving %i Bytes fails.\n",length); fault=1; } } } if (fault) return 0; // commit if (!(command[1] == COMMAND_CHANGE_RS232_BAUD_RATE)) if (!mdc800_rs232_waitForCommit (command[1])) { printCError ("(mdc800_rs232_sendCommand) receiving commit fails.\n"); fault=1; } if (fault) return 0; // all right return 1; }
/* * sends a command and receives the answer to this * buffer: Strores the answer * length: length of answer or null */ int mdc800_rs232_sendCommand(GPPort *port,unsigned char* command, unsigned char* buffer, int length) { char answer; int fault=0,ret; int i; printFnkCall ("(mdc800_rs232_sendCommand) id:%i (%i,%i,%i),answer:%i\n",command[1],command[2],command[3],command[4],length); usleep(MDC800_DEFAULT_COMMAND_DELAY*1000); gp_port_set_timeout (port, MDC800_DEFAULT_TIMEOUT ); /* Send command */ for (i=0; i<6; i++) { if (gp_port_write (port, (char*)&command[i] ,1) < GP_OK) { printCError ("(mdc800_rs232_sendCommand) sending Byte %i fails!\n",i); fault=1; } ret = gp_port_read (port,&answer,1); if ( ret != 1) { printCError ("(mdc800_rs232_sendCommand) receiving resend of Byte %i fails.\n",i); fault=1; } if (command [i] != answer) { printCError ("(mdc800_rs232_sendCommand) Byte %i differs : send %i, received %i \n",i,command[i],answer); fault=1; } } if (fault) return GP_ERROR_IO; /* Receive answer */ if (length) { /* Some Commands needs a download. */ switch (command[1]) { case COMMAND_GET_IMAGE: case COMMAND_GET_THUMBNAIL: if (!mdc800_rs232_download(port,buffer,length)) { printCError ("(mdc800_rs232_sendCommand) download of %i Bytes fails.\n",length); fault=1; } break; default: if (!mdc800_rs232_receive(port,buffer,length)) { printCError ("(mdc800_rs232_sendCommand) receiving %i Bytes fails.\n",length); fault=1; } } } if (fault) return GP_ERROR_IO; /* commit */ if (!(command[1] == COMMAND_CHANGE_RS232_BAUD_RATE)) { if (!mdc800_rs232_waitForCommit(port,command[1])) { printCError ("(mdc800_rs232_sendCommand) receiving commit fails.\n"); fault=1; } } if (fault) return GP_ERROR_IO; return GP_OK; }