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; }
static int delete_file_func (CameraFilesystem *fs, const char *folder, const char *filename, void *data, GPContext *context) { Camera *camera = data; int ret,nr ; nr = gp_filesystem_number(fs, folder, filename, context); if (nr < 0) return nr; ret = mdc800_setTarget (camera,1); if (ret!=GP_OK) { printAPIError ("(mdc800_delete_image) can't set Target\n"); return ret; } ret = mdc800_io_sendCommand(camera->port, COMMAND_DELETE_IMAGE,nr/100,(nr%100)/10,nr%10,0,0); if (ret != GP_OK) { printAPIError ("(mdc800_delete_image ) deleting Image %i fails !.\n",nr); return ret; } return GP_OK; }
/* * Get a preview from the Camera. * * Function return null, if no picture was taken, otherwise * the picture .. */ struct Image* mdc800_get_preview () { /* struct Image* image=null; char buffer [320*1024]; int i; int pic_size=32*1024; if (!mdc800_io_sendUSBCommand (0x3f, 1,0, 0,1,0,0, 0, 0)) { printError ("can't set camera to VCAM Mode \n"); return 0; } if (!mdc800_io_sendUSBCommand (0x3e,pic_size/256,pic_size%256,0,0,0,0,buffer,pic_size)) { printError ("can't take picture \n"); return 0; } image = (struct Image *) malloc (sizeof(struct Image)); image->image_size=pic_size; image->image=(unsigned char *) malloc (pic_size); for (i=0; i<pic_size; i++) image->image[i]=buffer [i]; strcpy(image->image_type,"jpg"); image->image_info_size = 0; correctImageData (image->image,0,0,1); return image; */ struct Image* pic=null; int num=mdc800_take_picture (); if (num == 0) { printAPIError ("(mdc800_get_preview) taking picture fails.\n"); mdc800_close (); return null; } pic=mdc800_get_picture (num,1); // Thumbnail if (pic == null) { printAPIError ("(mdc800_get_preview) there's no picture ??\n"); mdc800_close (); return 0; } if (!mdc800_delete_image (num)) { mdc800_close (); printAPIError ("(mdc800_get_preview) can't delete taken picture (%i)\n",num); return 0; } return (pic); }
/* * 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]; }
/* * Init this library. * usb: 0: rs232 1:usb */ int mdc800_initialize () { int h,s,e; if (mdc800_camera_open) return 1; printAPINote ("-Init---------------------------------------------------------------------------\n"); printAPINote ("Serial Port is \"%s\" \n",serial_port); if (!mdc800_openCamera (serial_port)) { printAPIError ("(mdc800_initialize) open camera fails.\n"); return 0; } printAPINote ("\n"); mdc800_camera_open=1; printAPINote ( mdc800_summary () ); printAPINote ("\n"); if (mdc800_getRemainFreeImageCount (&h,&s,&e)) printAPINote ("\nFree Memory for H%i S%i E%i\n",h,s,e); printAPINote ("-ok-----------------------------------------------------------------------------\n"); return 1; }
//------------------------------------------------------------------------------ //! bool resolveHost( const char* hostname, Vector<Socket::Endpoint>& dst ) { #if BASE_SOCKET_USE_BSD || BASE_SOCKET_USE_WINSOCK // Prepare request. addrinfo request; memset( &request, 0, sizeof(request) ); request.ai_family = AF_UNSPEC; // Retrieve candidates. addrinfo* candidates; int err = getaddrinfo( hostname, NULL, &request, &candidates ); if( err != 0 ) { printAPIError( "ERROR - resolveHost() - getaddrinfo() failed" ); return false; } for( addrinfo* cur = candidates; cur != NULL; cur = cur->ai_next ) { dst.pushBack( Socket::Endpoint() ); memcpy( &(dst.back().impl()->_stor), cur->ai_addr, cur->ai_addrlen ); } freeaddrinfo( candidates ); return true; #else return false; #endif }
//------------------------------------------------------------------------------ //! bool resolveHost( const char* hostname, Socket::Endpoint& ep ) { #if BASE_SOCKET_USE_BSD || BASE_SOCKET_USE_WINSOCK // Prepare request. addrinfo request; memset( &request, 0, sizeof(request) ); request.ai_family = AF_UNSPEC; // Retrieve candidates. addrinfo* candidates; int err = getaddrinfo( hostname, NULL, &request, &candidates ); if( err != 0 ) { printAPIError( "ERROR - resolveHost() - getaddrinfo() failed" ); return false; } addrinfo* cur = candidates; // Search for some criterion here (for now, take the last one). while( cur->ai_next != NULL ) { cur = cur->ai_next; } memcpy( &(ep.impl()->_stor), cur->ai_addr, cur->ai_addrlen ); freeaddrinfo( candidates ); return true; #else return true; #endif }
//------------------------------------------------------------------------------ //! RCP<ConnectedSocketDevice> Socket::accept() { #if BASE_SOCKET_USE_BSD || BASE_SOCKET_USE_WINSOCK sockaddr_storage stor; socklen_t slen = getSize(_localEndpoint.impl()->_stor); SocketDescriptor sock = ::accept( _impl->_sock, (sockaddr*)&stor, &slen ); if( sock == sInvalidSocket ) { printAPIError( "ERROR - Socket::accept() - accept failed" ); return NULL; } //fprintf(stderr,"... accept() suceeded\n"); RCP<Socket> socket = new Socket( this ); //fprintf(stderr,"... Socket created\n"); socket->_impl->_sock = sock; //fprintf(stderr,"... _sock assigned %p\n", socket->_impl); //socket->_localEndpoint = ; // Not setting the source endpoint for now. RCP<ConnectedSocketDevice> device = new ConnectedSocketDevice( socket.ptr() ); //fprintf(stderr,"... device created\n"); device->_remoteEndpoint.impl()->_stor = stor; //fprintf(stderr,"... _stor assigned\n"); socket->state( STATE_CONNECTED ); return device; #else return NULL; #endif }
//------------------------------------------------------------------------------ //! bool Socket::listen( uint16_t port ) { #if BASE_SOCKET_USE_BSD || BASE_SOCKET_USE_WINSOCK if( !bind( *this, port, this->_localEndpoint ) ) { return false; } // Update state. state( STATE_BOUND ); if( type() == TYPE_DATAGRAM || protocol() == PROTOCOL_UDP ) { // Datagram sockets don't need to listen; a simple bind is enough. return true; } // Start listening. int err = ::listen( _impl->_sock, DefaultBacklogSize ); if( err != 0 ) { printAPIError( "ERROR - Socket::listen() - listen failed" ); return false; } state( STATE_LISTENING ); return true; #else return false; #endif }
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]; }
/* * Gives Information about the current camera status. */ char* mdc800_summary() { char line[50]; if (!mdc800_camera_open) { printAPIError ("(mdc800_summary) camera is not open !\n"); return 0; } strcpy (mdc800_summary_output,"Summary for Mustek MDC800:\n"); if (!mdc800_getSystemStatus ()) { strcat (mdc800_summary_output,"no status reported."); mdc800_close (); return mdc800_summary_output; } if (mdc800_isCFCardPresent ()) sprintf (line,"Compact Flash Card detected\n"); else sprintf (line,"no Compact Flash Card detected\n"); strcat (mdc800_summary_output,line); if (mdc800_getMode () == 0) sprintf (line, "Current Mode: Camera Mode\n"); else sprintf (line, "Current Mode: Playback Mode\n"); strcat (mdc800_summary_output,line); sprintf (line,mdc800_getFlashLightString (mdc800_getFlashLightStatus ())); strcat (line,"\n"); strcat (mdc800_summary_output,line); if (mdc800_isBatteryOk ()) sprintf (line, "Batteries are ok."); else sprintf (line, "Batteries are low."); strcat (mdc800_summary_output,line); return mdc800_summary_output; }
//------------------------------------------------------------------------------ //! Socket::Socket( Family f, Type t, Protocol p ): _family( f ), _type( t ), _protocol( p ), _state( STATE_UNCONNECTED ) { _impl = new Socket::Impl(); #if BASE_SOCKET_USE_BSD || BASE_SOCKET_USE_WINSOCK _impl->_sock = socket( toAPI(family()), toAPI(type()), toAPI(protocol()) ); if( _impl->_sock == sInvalidSocket ) { printAPIError( "ERROR - Socket::Socket(Family, Type, Protocol) - socket() failed" ); CHECK( false ); } #else #endif }
//------------------------------------------------------------------------------ //! RCP<ConnectedSocketDevice> Socket::connect( const Endpoint& ep ) { #if BASE_SOCKET_USE_BSD || BASE_SOCKET_USE_WINSOCK state( STATE_CONNECTING ); addrinfo* candidates = getAddrInfo( *this, ep.hostname().cstr(), ep.port() ); if( candidates == NULL ) { return NULL; } Family family = fromAPI_family ( candidates->ai_family ); Type type = fromAPI_type ( candidates->ai_socktype ); Protocol protocol = fromAPI_protocol( candidates->ai_protocol ); RCP<Socket> socket = new Socket( family, type, protocol ); int err = ::connect( socket->_impl->_sock, candidates->ai_addr, SocketSSizeT(candidates->ai_addrlen) ); if( err != 0 ) { printAPIError( "ERROR - Socket::connect() - connect failed" ); freeaddrinfo( candidates ); return NULL; } RCP<ConnectedSocketDevice> device = new ConnectedSocketDevice( socket.ptr() ); device->_remoteEndpoint = ep; freeaddrinfo( candidates ); state( STATE_CONNECTED ); return device; #else return NULL; #endif }