コード例 #1
0
ファイル: l859.c プロジェクト: mejedi/Gphoto2.framework
/*
 * l859_connect - try hand shake with camera and establish connection
 */
static int l859_connect(Camera *camera) {

	GPPortSettings settings;
	uint8_t	bps;
	int ret;

	GP_DEBUG ("Connecting to a camera.");

	ret = l859_sendcmd(camera, L859_CMD_CONNECT);
	if (ret < GP_OK)
		return ret;
	if (l859_retrcmd(camera) == GP_ERROR) {
		if (l859_sendcmd(camera, L859_CMD_RESET) != GP_OK)
			return GP_ERROR;
		if (l859_sendcmd(camera, L859_CMD_CONNECT)!= GP_OK)
			return GP_ERROR;
		if (l859_retrcmd(camera) == GP_ERROR)
			return GP_ERROR;
	}

	switch (camera->pl->speed) {
		case 19200:
			bps = L859_CMD_SPEED_19200;
			break;
		case 57600:
			bps = L859_CMD_SPEED_57600;
			break;
		case 115200:
			bps = L859_CMD_SPEED_115200;
			break;
		default:
			bps = L859_CMD_SPEED_DEFAULT;
			break;
	}

	if (bps != L859_CMD_SPEED_DEFAULT) {

		if (l859_sendcmd(camera, bps) != GP_OK)
			return GP_ERROR;

		gp_port_get_settings(camera->port, &settings);
		settings.serial.speed = camera->pl->speed;
		gp_port_set_settings(camera->port, settings);

		if (l859_retrcmd(camera) == GP_ERROR)
			return GP_ERROR;
	}

	if (l859_sendcmd(camera, L859_CMD_INIT) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;

	GP_DEBUG ("Camera connected successfully.");

	return GP_OK;
}
コード例 #2
0
ファイル: l859.c プロジェクト: CastorGemini/libgphoto2
/*
 * l859_selectimage_preview - select preview image to download,
 * return its size
 */
static int l859_selectimage_preview(Camera *camera, uint8_t index) {

	int			size = 0;
	uint8_t	byte1 = 0;
	uint8_t	byte2 = 0;
	uint8_t	byte3 = 0;
	int		value0;
	int		value1;
	int		value2;
	int		value3;

	GP_DEBUG ("Selected preview image: %i.", index);

	value0 = index;
	value1 = value0 % 10;
	value2 = (value0 - value1) % 100;
	value3 = (value0 - value1 - value2) / 100;
	value2 = value2 / 10;

	if (l859_sendcmd(camera, 0xa0 + value1) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, 0xb0 + value2) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, 0xc0 + value3) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, L859_CMD_PREVIEW) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;

	byte1 = camera->pl->buf[5];
	byte2 = camera->pl->buf[6];
	byte3 = camera->pl->buf[7];

	size = (byte1 * 256 * 256) + (byte2 * 256) + byte3;

	GP_DEBUG ("Selected preview image: %i, size: %i.", index, size);

	return size;
}
コード例 #3
0
ファイル: l859.c プロジェクト: CastorGemini/libgphoto2
static int delete_all_func (CameraFilesystem *fs, const char *folder,
			    void *data, GPContext *context) {

	Camera *camera = data;

	GP_DEBUG ("Delete all images");

	if (l859_sendcmd(camera, L859_CMD_DELETE_ALL) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, L859_CMD_DELETE_ACK) != GP_OK)
		return GP_ERROR;

	GP_DEBUG ("Delete all images done.");

	return GP_OK;
}
コード例 #4
0
ファイル: l859.c プロジェクト: CastorGemini/libgphoto2
/*
 * l859_readimageblock - read #block block (116 bytes) of an
 * image into buf
 */
static int l859_readimageblock(Camera *camera, int block, char *buffer) {

	int     index;

	GP_DEBUG ("Reading image block: %i.", block);

	if (l859_sendcmd(camera, L859_CMD_ACK) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;

	for (index = 3; index < 116; index++) {
		buffer[index - 3] = camera->pl->buf[index];
	}

	GP_DEBUG ("Block: %i read in.", block);

	return 112;

}
コード例 #5
0
ファイル: l859.c プロジェクト: CastorGemini/libgphoto2
/*
 *l859_delete - delete image #index from camera memory
 */
static int l859_delete(Camera *camera, uint8_t index) {

	int		value0;
	int		value1;
	int		value2;
	int		value3;

	GP_DEBUG ("Deleting image: %i.", index);

	value0 = index;
	value1 = value0 % 10;
	value2 = (value0 - value1) % 100;
	value3 = (value0 - value1 - value2) / 100;
	value2 = value2 / 10;

	if (l859_sendcmd(camera, L859_CMD_DELETE_1) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, 0xa0 + value1) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, 0xb0 + value2) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, 0xc0 + value3) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, L859_CMD_DELETE_2) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, L859_CMD_DELETE_3) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, L859_CMD_DELETE_ACK) != GP_OK)
		return GP_ERROR;

	GP_DEBUG ("Image %i deleted.", index);

	return GP_OK;
}
コード例 #6
0
ファイル: l859.c プロジェクト: CastorGemini/libgphoto2
static int get_file_func (CameraFilesystem *fs, const char *folder,
			  const char *filename, CameraFileType type,
			  CameraFile *file, void *data, GPContext *context) {

	Camera *camera = data;
	int		index;
	int		size;
	int		i;
	int		s;
	char	buffer[112];
	int		bufIndex;
	unsigned int id;

	GP_DEBUG ("Get File %s", filename);

	/* index is the 0-based image number on the camera */
	index = gp_filesystem_number (camera->fs, folder, filename, context);
	if (index < 0)
		return (index);

	switch (type) {
	case GP_FILE_TYPE_NORMAL:
		size = l859_selectimage(camera, index);
		break;
	case GP_FILE_TYPE_PREVIEW:
		size = l859_selectimage_preview(camera, index);
	default:
		return (GP_ERROR_NOT_SUPPORTED);
	}
	if (size < 0)
		return (size);

	id = gp_context_progress_start (context, size,
		_("Downloading '%s'..."), filename);
	for (i = 0, s = 0; s < size; i++) {

		if (l859_sendcmd(camera, L859_CMD_ACK) != GP_OK)
			return GP_ERROR;
		if (l859_retrcmd(camera) == GP_ERROR)
			return GP_ERROR;

		for (bufIndex = 3; bufIndex < 115 && s < size; bufIndex++) {
			buffer[bufIndex - 3] = camera->pl->buf[bufIndex];
			s += 1;
		}
		GP_DEBUG ("Packet Size: %i Data Size: %i", bufIndex - 3, s);

		/* Append data to the file */
		gp_file_append (file, buffer, bufIndex - 3);

		/* Check for cancellation */
		gp_context_progress_update (context, id, s);
		if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) {
			l859_disconnect (camera);
			l859_connect    (camera);
			return (GP_ERROR_CANCEL);
		}
	}

	gp_file_set_mime_type (file, GP_MIME_JPEG); 
	GP_DEBUG ("Camera Get File Done");
	return (GP_OK);
}
コード例 #7
0
ファイル: l859.c プロジェクト: CastorGemini/libgphoto2
static int file_list_func (CameraFilesystem *fs, const char *folder,
			   CameraList *list, void *data, GPContext *context) {

	Camera *camera = data;
	int	num = 0;
	int	width;
	int	year;
	int	size;
	uint8_t	month;
	uint8_t	day;
	uint8_t	hour;
	uint8_t	minute;
	uint8_t	byte1;
	uint8_t	byte2;
	uint8_t	byte3;
	char	*filename;

	GP_DEBUG ("Camera List Files");

	if (l859_sendcmd(camera, 0xa0) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, 0xb0) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, 0xc0) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, L859_CMD_PREVIEW) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;

	while (camera->pl->buf[13] == num) {

		byte1 = camera->pl->buf[8];
		byte2 = camera->pl->buf[9];
		width = (byte1 * 256) + byte2;
		byte1 = camera->pl->buf[22];
		year = byte1 + 1900;
		month = camera->pl->buf[23];
		day = camera->pl->buf[24];
		hour = camera->pl->buf[25];
		minute = camera->pl->buf[26];

		byte1 = camera->pl->buf[5];
		byte2 = camera->pl->buf[6];
		byte3 = camera->pl->buf[7];
		size = (byte1 * 256 * 256) + (byte2 * 256) + byte3;

		/* Check for no images */
		if (size == 0)
			return GP_OK;

		if (!(filename = (char*)malloc(30))) {
			GP_DEBUG ("Unable to allocate memory for filename.");
			return GP_ERROR_NO_MEMORY;
		}

		sprintf(filename, "%.4i%s%i-%i-%i(%i-%i).jpg", num + 1,
			width == 640 ? "F" : "N", year, month, day, hour, minute);
		GP_DEBUG ("Filename: %s.", filename);

		gp_list_append (list, filename, NULL);
/*		GP_DEBUG ("Num %i Filename %s", num, filename); */
		free (filename);
		num = num + 1;
		if (l859_sendcmd(camera, L859_CMD_PREVIEW_NEXT) != GP_OK)
			return GP_ERROR;
		if (l859_retrcmd(camera) == GP_ERROR)
			return GP_ERROR;
	}
	GP_DEBUG ("Camera List Files Done");
	return GP_OK;
}