Exemplo n.º 1
0
/* This function gets the current system time, sets the contents of the current
   dimagev->data struct appropriately, and then sends the data.
*/
int dimagev_set_date(dimagev_t *dimagev) {
	struct tm *this_time;
	time_t now;

	if ( dimagev == NULL ) {
		return GP_ERROR_BAD_PARAMETERS;
	}

	if ( ( now = time(NULL) ) < 0 ) {
		GP_DEBUG( "dimagev_set_date::unable to get system time");
		return GP_ERROR;
	}

	if ( ( this_time = localtime(&now) ) == NULL ) {
		GP_DEBUG( "dimagev_set_date::unable to convert system time to local time");
		return GP_ERROR;
	}

	GP_DEBUG( "Setting clock to %02d/%02d/%02d %02d:%02d:%02d", this_time->tm_year % 100, ( this_time->tm_mon + 1 ), this_time->tm_mday, this_time->tm_hour, this_time->tm_min, this_time->tm_sec);

	dimagev->data->date_valid = (unsigned char) 1;
	dimagev->data->year = (unsigned char) ( this_time->tm_year % 100 );
	dimagev->data->month = (unsigned char) ( this_time->tm_mon + 1 );
	dimagev->data->day = (unsigned char) this_time->tm_mday;
	dimagev->data->hour = (unsigned char) this_time->tm_hour;
	dimagev->data->minute = (unsigned char) this_time->tm_min;
	dimagev->data->second = (unsigned char) this_time->tm_sec;

	if ( dimagev_send_data(dimagev) < GP_OK ) {
		GP_DEBUG( "dimagev_set_date::unable to set time");
		return GP_ERROR_IO;
	}

	/* So we don't set this date again later by mistake. */
	dimagev->data->date_valid = (unsigned char) 0;

	if ( dimagev_send_data(dimagev) < GP_OK ) {
		GP_DEBUG( "dimagev_set_date::unable to set time");
		return GP_ERROR_IO;
	}

	return GP_OK;
}
Exemplo n.º 2
0
int dimagev_get_picture(dimagev_t *dimagev, int file_number, CameraFile *file) {
	int total_packets, i;
	unsigned long size = 0;
	dimagev_packet *p, *r;
	unsigned char char_buffer, command_buffer[3];
	char *data;

	if ( dimagev->data->host_mode != (unsigned char) 1 ) {

		dimagev->data->host_mode = (unsigned char) 1;

		if ( dimagev_send_data(dimagev) < GP_OK ) {
			GP_DEBUG( "dimagev_get_picture::unable to set host mode");
			return GP_ERROR_IO;
		}
	}

	GP_DEBUG( "dimagev_get_picture::file_number is %d", file_number);

	/* Maybe check if it exists? Check the file type? */
	
	/* First make the command packet. */
	command_buffer[0] = 0x04;
	command_buffer[1] = (unsigned char)( file_number / 256 );
	command_buffer[2] = (unsigned char)( file_number % 256 );
	if ( ( p = dimagev_make_packet(command_buffer, 3, 0) ) == NULL ) {
		GP_DEBUG( "dimagev_get_picture::unable to allocate command packet");
		return GP_ERROR_NO_MEMORY;
	}

	if ( gp_port_write(dimagev->dev, (char *)p->buffer, p->length) < GP_OK ) {
		GP_DEBUG( "dimagev_get_picture::unable to send set_data packet");
		free(p);
		return GP_ERROR_IO;
	} else if ( gp_port_read(dimagev->dev, (char *)&char_buffer, 1) < GP_OK ) {
		GP_DEBUG( "dimagev_get_picture::no response from camera");
		free(p);
		return GP_ERROR_IO;
	}
		
	free(p);

	switch ( char_buffer ) {
		case DIMAGEV_ACK:
			break;
		case DIMAGEV_NAK:
			GP_DEBUG( "dimagev_get_picture::camera did not acknowledge transmission");
			return dimagev_get_picture(dimagev, file_number, file);
/*			return GP_ERROR_IO;*/
		case DIMAGEV_CAN:
			GP_DEBUG( "dimagev_get_picture::camera cancels transmission");
			return GP_ERROR_IO;
		default:
			GP_DEBUG( "dimagev_get_picture::camera responded with unknown value %x", char_buffer);
			return GP_ERROR_IO;
	}

	if ( ( p = dimagev_read_packet(dimagev) ) == NULL ) {
		GP_DEBUG( "dimagev_get_picture::unable to read packet");
		return GP_ERROR_IO;
	}

	if ( ( r = dimagev_strip_packet(p) ) == NULL ) {
		GP_DEBUG( "dimagev_get_picture::unable to strip packet");
		free(p);
		return GP_ERROR_NO_MEMORY;
	}
		
	free(p);

	total_packets = (int) r->buffer[0];

	/* Allocate an extra byte just in case. */
	if ( ( data = malloc((size_t)((993 * total_packets) + 1)) ) == NULL ) {
		GP_DEBUG( "dimagev_get_picture::unable to allocate buffer for file");
		free(r);
		return GP_ERROR_NO_MEMORY;
	}

	memcpy(data, &(r->buffer[1]), (size_t) r->length );
	size += ( r->length - 2 );

	free(r);

	for ( i = 0 ; i < ( total_packets -1 ) ; i++ ) {
		char_buffer=DIMAGEV_ACK;
		if ( gp_port_write(dimagev->dev, (char *)&char_buffer, 1) < GP_OK ) {
			GP_DEBUG( "dimagev_get_picture::unable to send ACK");
			free(data);
			return GP_ERROR_IO;
		}
	
		if ( ( p = dimagev_read_packet(dimagev) ) == NULL ) {
			/*
			GP_DEBUG( "dimagev_get_picture::unable to read packet");
			return GP_ERROR_IO;
			*/

			GP_DEBUG( "dimagev_get_picture::sending NAK to get retry");
			char_buffer=DIMAGEV_NAK;
			if ( gp_port_write(dimagev->dev, (char *)&char_buffer, 1) < GP_OK ) {
				GP_DEBUG( "dimagev_get_picture::unable to send NAK");
				free(data);
				return GP_ERROR_IO;
			}

			if ( ( p = dimagev_read_packet(dimagev) ) == NULL ) {
				GP_DEBUG( "dimagev_get_picture::unable to read packet");
				free(data);
				return GP_ERROR_IO;
			}
		}

		if ( ( r = dimagev_strip_packet(p) ) == NULL ) {
			GP_DEBUG( "dimagev_get_picture::unable to strip packet");
			free(data);
			free(p);
			return GP_ERROR_NO_MEMORY;
		}
		
		free(p);

		memcpy(&( data[ ( size + 1) ] ), r->buffer, (size_t) r->length );
		size += r->length;

		free(r);
	}

	size++;

	char_buffer=DIMAGEV_EOT;
	if ( gp_port_write(dimagev->dev, (char *)&char_buffer, 1) < GP_OK ) {
		GP_DEBUG( "dimagev_get_picture::unable to send ACK");
		free(data);
		return GP_ERROR_IO;
	}

	if ( gp_port_read(dimagev->dev, (char *)&char_buffer, 1) < GP_OK ) {
		GP_DEBUG( "dimagev_get_picture::no response from camera");
		free(data);
		return GP_ERROR_IO;
	}
		
	switch ( char_buffer ) {
		case DIMAGEV_ACK:
			break;
		case DIMAGEV_NAK:
			GP_DEBUG( "dimagev_get_picture::camera did not acknowledge transmission");
			free(data);
			return GP_ERROR_IO;
		case DIMAGEV_CAN:
			GP_DEBUG( "dimagev_get_picture::camera cancels transmission");
			free(data);
			return GP_ERROR_IO;
		default:
			GP_DEBUG( "dimagev_get_picture::camera responded with unknown value %x", char_buffer);
			free(data);
			return GP_ERROR_IO;
	}

	gp_file_set_data_and_size (file, data, size);

	return GP_OK;
}
Exemplo n.º 3
0
int dimagev_delete_picture(dimagev_t *dimagev, int file_number) {
    dimagev_packet *p, *raw;
    unsigned char command_buffer[3];
    char char_buffer = 0;

    if ( dimagev == NULL ) {
        GP_DEBUG( "dimagev_delete_picture::unable to use NULL dimagev_t");
        return GP_ERROR_BAD_PARAMETERS;
    }

    dimagev_dump_camera_status(dimagev->status);
    /* An image can only be deleted if the card is normal or full. */
    if ( dimagev->status->card_status > (unsigned char) 1 ) {
        GP_DEBUG( "dimagev_delete_picture::memory card does not permit deletion");
        return GP_ERROR;
    }

    if ( dimagev->data->host_mode != (unsigned char) 1 ) {

        dimagev->data->host_mode = (unsigned char) 1;

        if ( dimagev_send_data(dimagev) < GP_OK ) {
            GP_DEBUG( "dimagev_delete_picture::unable to set host mode");
            return GP_ERROR_IO;
        }
    }


    /* First make the command packet. */
    command_buffer[0] = 0x05;
    command_buffer[1] = (unsigned char)( file_number / 256 );
    command_buffer[2] = (unsigned char)( file_number % 256 );
    if ( ( p = dimagev_make_packet(command_buffer, 3, 0) ) == NULL ) {
        GP_DEBUG( "dimagev_delete_picture::unable to allocate command packet");
        return GP_ERROR_NO_MEMORY;
    }

    if ( gp_port_write(dimagev->dev, (char *)p->buffer, p->length) < GP_OK ) {
        GP_DEBUG( "dimagev_delete_picture::unable to send set_data packet");
        free(p);
        return GP_ERROR_IO;
    } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) < GP_OK ) {
        GP_DEBUG( "dimagev_delete_picture::no response from camera");
        free(p);
        return GP_ERROR_IO;
    }

    free(p);

    switch ( char_buffer ) {
    case DIMAGEV_ACK:
        break;
    case DIMAGEV_NAK:
        GP_DEBUG( "dimagev_delete_picture::camera did not acknowledge transmission");
        return GP_ERROR_IO;
    case DIMAGEV_CAN:
        GP_DEBUG( "dimagev_delete_picture::camera cancels transmission");
        return GP_ERROR_IO;
    default:
        GP_DEBUG( "dimagev_delete_picture::camera responded with unknown value %x", char_buffer);
        return GP_ERROR_IO;
    }


    if ( ( p = dimagev_read_packet(dimagev) ) == NULL ) {
        GP_DEBUG( "dimagev_delete_picture::unable to read packet");
        return GP_ERROR_IO;
    }

    if ( ( raw = dimagev_strip_packet(p) ) == NULL ) {
        GP_DEBUG( "dimagev_delete_picture::unable to strip packet");
        free(p);
        return GP_ERROR;
    }

    free(p);

    if ( raw->buffer[0] != (unsigned char) 0 ) {
        GP_DEBUG( "dimagev_delete_picture::delete returned error code");
        free(raw);
        return GP_ERROR_NO_MEMORY;
    }
    free(raw);

    char_buffer=DIMAGEV_EOT;
    if ( gp_port_write(dimagev->dev, &char_buffer, 1) < GP_OK ) {
        GP_DEBUG( "dimagev_delete_picture::unable to send ACK");
        return GP_ERROR_IO;
    }

    if ( gp_port_read(dimagev->dev, &char_buffer, 1) < GP_OK ) {
        GP_DEBUG( "dimagev_delete_picture::no response from camera");
        return GP_ERROR_IO;
    }

    switch ( char_buffer ) {
    case DIMAGEV_ACK:
        break;
    case DIMAGEV_NAK:
        GP_DEBUG( "dimagev_delete_picture::camera did not acknowledge transmission");
        return GP_ERROR_IO;
    case DIMAGEV_CAN:
        GP_DEBUG( "dimagev_delete_picture::camera cancels transmission");
        return GP_ERROR_IO;
    default:
        GP_DEBUG( "dimagev_delete_picture::camera responded with unknown value %x", char_buffer);
        return GP_ERROR_IO;
    }

    return GP_OK;
}
Exemplo n.º 4
0
int dimagev_get_thumbnail(dimagev_t *dimagev, int file_number, CameraFile *file) {
	dimagev_packet *p, *r;
	unsigned char char_buffer, command_buffer[3], *ycrcb_data;
	char *data;
	long int size = 0;

	if ( dimagev->data->host_mode != (unsigned char) 1 ) {

		dimagev->data->host_mode = (unsigned char) 1;

		if ( dimagev_send_data(dimagev) < GP_OK ) {
			GP_DEBUG( "dimagev_get_thumbnail::unable to set host mode");
			return GP_ERROR_IO;
		}
	}

	/* First make the command packet. */
	command_buffer[0] = 0x0d;
	command_buffer[1] = (unsigned char)( file_number / 256 );
	command_buffer[2] = (unsigned char)( file_number % 256 );
	if ( ( p = dimagev_make_packet(command_buffer, 3, 0) ) == NULL ) {
		GP_DEBUG( "dimagev_get_thumbnail::unable to allocate command packet");
		return GP_ERROR_NO_MEMORY;
	}

	if ( gp_port_write(dimagev->dev, (char *)p->buffer, p->length) < GP_OK ) {
		GP_DEBUG( "dimagev_get_thumbnail::unable to send set_data packet");
		free(p);
		return GP_ERROR_IO;
	} else if ( gp_port_read(dimagev->dev, (char *)&char_buffer, 1) < GP_OK ) {
		GP_DEBUG( "dimagev_get_thumbnail::no response from camera");
		free(p);
		return GP_ERROR_IO;
	}
		
	free(p);

	switch ( char_buffer ) {
		case DIMAGEV_ACK:
			break;
		case DIMAGEV_NAK:
			GP_DEBUG( "dimagev_get_thumbnail::camera did not acknowledge transmission");
			return dimagev_get_thumbnail(dimagev, file_number, file);
/*			return GP_ERROR_IO;*/
		case DIMAGEV_CAN:
			GP_DEBUG( "dimagev_get_thumbnail::camera cancels transmission");
			return GP_ERROR_IO;
		default:
			GP_DEBUG( "dimagev_get_thumbnail::camera responded with unknown value %x", char_buffer);
			return GP_ERROR_IO;
	}

	if ( ( p = dimagev_read_packet(dimagev) ) == NULL ) {
		GP_DEBUG( "dimagev_get_thumbnail::unable to read packet");
		return GP_ERROR_IO;
	}

	if ( ( r = dimagev_strip_packet(p) ) == NULL ) {
		GP_DEBUG( "dimagev_get_thumbnail::unable to strip packet");
		free(p);
		return GP_ERROR_NO_MEMORY;
	}
		
	free(p);

	/* Unlike normal images, we are guaranteed 9600 bytes *exactly*. */

	/* Allocate an extra byte just in case. */
	if ( ( ycrcb_data = malloc(9600) ) == NULL ) {
		GP_DEBUG( "dimagev_get_thumbnail::unable to allocate buffer for file");
		free(r);
		return GP_ERROR_NO_MEMORY;
	}

	memcpy(ycrcb_data, r->buffer, (size_t) r->length );
	size +=  r->length - 1 ;

	free(r);

	while ( size < 9599 ) {

		char_buffer=DIMAGEV_ACK;
		if ( gp_port_write(dimagev->dev, (char *)&char_buffer, 1) < GP_OK ) {
			GP_DEBUG( "dimagev_get_thumbnail::unable to send ACK");
			free(ycrcb_data);
			return GP_ERROR_IO;
		}
	
		if ( ( p = dimagev_read_packet(dimagev) ) == NULL ) {
			GP_DEBUG( "dimagev_get_thumbnail::unable to read packet");
			free(ycrcb_data);
			return GP_ERROR_IO;
		}

		if ( ( r = dimagev_strip_packet(p) ) == NULL ) {
			GP_DEBUG( "dimagev_get_thumbnail::unable to strip packet");
			free(p);
			free(ycrcb_data);
			return GP_ERROR_NO_MEMORY;
		}
		
		free(p);

		memcpy(&( ycrcb_data[ ( size + 1) ] ), r->buffer, (size_t) r->length );
		size += r->length;

		free(r);

		GP_DEBUG( "dimagev_get_thumbnail::current file size is %ld", size);
	}

	size++;

	char_buffer=DIMAGEV_EOT;
	if ( gp_port_write(dimagev->dev, (char *)&char_buffer, 1) < GP_OK ) {
		GP_DEBUG( "dimagev_get_thumbnail::unable to send ACK");
		free(ycrcb_data);
		return GP_ERROR_IO;
	}

	if ( gp_port_read(dimagev->dev, (char *)&char_buffer, 1) < GP_OK ) {
		GP_DEBUG( "dimagev_get_thumbnail::no response from camera");
		free(ycrcb_data);
		return GP_ERROR_IO;
	}
		
	switch ( char_buffer ) {
		case DIMAGEV_ACK:
			break;
		case DIMAGEV_NAK:
			GP_DEBUG( "dimagev_get_thumbnail::camera did not acknowledge transmission");
			free(ycrcb_data);
			return GP_ERROR_IO;
		case DIMAGEV_CAN:
			GP_DEBUG( "dimagev_get_thumbnail::camera cancels transmission");
			free(ycrcb_data);
			return GP_ERROR_IO;
		default:
			GP_DEBUG( "dimagev_get_thumbnail::camera responded with unknown value %x", char_buffer);
			free(ycrcb_data);
			return GP_ERROR_IO;
	}

	data = (char *)dimagev_ycbcr_to_ppm(ycrcb_data);
	size = 14413;

	gp_file_set_data_and_size (file, data, size);

	return GP_OK;
}