<commit_before>/* jl2005c.c
 *
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>

#include <gphoto2/gphoto2.h>
#include <gphoto2/gphoto2-port.h>
#include "gphoto2-endian.h"

#include "jl2005c.h"

#define GP_MODULE "jl2005c" 

int 
jl2005c_init (Camera *camera, GPPort *port, CameraPrivateLibrary *priv) 
{
	unsigned char command[2];
	char response;
	unsigned char info[0xe000];
	int info_block_size = 0;
	memset(info,0, sizeof(info)); 
	memset(command,0,sizeof(command));
	GP_DEBUG("Running jl2005c_init\n");


	gp_port_write (port, "\x08\x00", 2); 

	usleep (10000);
	gp_port_write (port, "\x95\x60", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x95\x61", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x95\x62", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port,"\x95\x63" , 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x95\x64", 2); 
	usleep (10000);	
	gp_port_read (port, &response, 1);

	usleep (10000);	
	gp_port_write (port, "\x95\x65", 2);
	usleep (10000);
	gp_port_read (port, &response, 1); /* Number of pix returned here */
	priv->nb_entries = (unsigned)response;
	GP_DEBUG("%d entries in the camera\n", response);
	GP_DEBUG("%d entries in the camera\n", priv->nb_entries);
	info_block_size = ((unsigned)response * 0x10) + 2;
	if (info_block_size%0x200) 
		info_block_size += 0x200 - (info_block_size%0x200);
	usleep (10000);

	gp_port_write (port, "\x95\x66", 2); 	
	usleep (10000);
	gp_port_read (port, &response, 1); 
	usleep (10000);

	gp_port_write (port, "\x95\x67", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x68", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x69", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x6a", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x6b", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x6c", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	priv->data_to_read = (response &0xff)*0x100;

	gp_port_write (port, "\x95\x6d", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	priv->data_to_read += (response&0xff);
	priv->data_to_read *= 0x200;
	priv->total_data_in_camera = priv->data_to_read;
	GP_DEBUG ("data_to_read = 0x%lx = %lu\n", priv->data_to_read, 
							priv->data_to_read);
	GP_DEBUG ("total_data_in_camera = 0x%lx = %lu\n", priv->data_to_read, 
							priv->data_to_read);

	gp_port_write (port, "\x95\x6e", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x95\x6f", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x0a\x00", 2); 	

	usleep (10000);
	/* Switch the inep over to 0x82. It stays there ever after. */ 
	set_usb_in_endpoint	(camera, 0x82); 
	usleep (10000);
	gp_port_read(port, (char *)info, info_block_size);
	usleep (10000);
	gp_port_write (port, "\x0b\x00",2);	
	usleep (10000);
	memmove(priv->info, info, info_block_size);
	GP_DEBUG("Leaving jl2005c_init\n");
        return GP_OK;
}


int
jl2005c_get_pic_data_size (Info *info, int n)
{
	int size;
	GP_DEBUG("info[48+16*n+7] = %02X\n", info[48+16*n+7]);
	GP_DEBUG("info[48+16*n+8] = %02X\n", info[48+16*n+8]);
	size = (info[48+16*n+7]*0x200 + info[48+16*n+8]*0x2);
	GP_DEBUG("size = 0x%x = %d\n", size, size);
	return (size);
}

unsigned long
jl2005c_get_start_of_photo(Info *info, unsigned int n)
{
	int j = 0;
	unsigned long start = 0;
	if (!n) 
		return 0;
	while (j < n) {
		start += jl2005c_get_pic_data_size(info,j);
		j++;
	}
	return start;
}		


int 
set_usb_in_endpoint	(Camera *camera, int inep) 
{
	GPPortSettings settings;
	gp_port_get_settings ( camera ->port, &settings);
	settings.usb.inep = inep;
	GP_DEBUG("inep reset to %02X\n", inep);
	return gp_port_set_settings ( camera ->port, settings);
}	


int <commit_msg>camlibs/jl2005c: minor changes to computation of data size and start point for photos<commit_after>/* jl2005c.c
 *
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>

#include <gphoto2/gphoto2.h>
#include <gphoto2/gphoto2-port.h>
#include "gphoto2-endian.h"

#include "jl2005c.h"

#define GP_MODULE "jl2005c" 

int 
jl2005c_init (Camera *camera, GPPort *port, CameraPrivateLibrary *priv) 
{
	unsigned char command[2];
	char response;
	unsigned char info[0xe000];
	int info_block_size = 0;
	memset(info,0, sizeof(info)); 
	memset(command,0,sizeof(command));
	GP_DEBUG("Running jl2005c_init\n");


	gp_port_write (port, "\x08\x00", 2); 

	usleep (10000);
	gp_port_write (port, "\x95\x60", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x95\x61", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x95\x62", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port,"\x95\x63" , 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x95\x64", 2); 
	usleep (10000);	
	gp_port_read (port, &response, 1);

	usleep (10000);	
	gp_port_write (port, "\x95\x65", 2);
	usleep (10000);
	gp_port_read (port, &response, 1); /* Number of pix returned here */
	priv->nb_entries = (unsigned)response;
	GP_DEBUG("%d entries in the camera\n", response);
	GP_DEBUG("%d entries in the camera\n", priv->nb_entries);
	info_block_size = ((unsigned)response * 0x10) + 2;
	if (info_block_size%0x200) 
		info_block_size += 0x200 - (info_block_size%0x200);
	usleep (10000);

	gp_port_write (port, "\x95\x66", 2); 	
	usleep (10000);
	gp_port_read (port, &response, 1); 
	usleep (10000);

	gp_port_write (port, "\x95\x67", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x68", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x69", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x6a", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x6b", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	gp_port_write (port, "\x95\x6c", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	priv->data_to_read = (response &0xff)*0x100;

	gp_port_write (port, "\x95\x6d", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);
	usleep (10000);

	priv->data_to_read += (response&0xff);
	priv->data_to_read *= 0x200;
	priv->total_data_in_camera = priv->data_to_read;
	GP_DEBUG ("data_to_read = 0x%lx = %lu\n", priv->data_to_read, 
							priv->data_to_read);
	GP_DEBUG ("total_data_in_camera = 0x%lx = %lu\n", priv->data_to_read, 
							priv->data_to_read);

	gp_port_write (port, "\x95\x6e", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x95\x6f", 2); 
	usleep (10000);
	gp_port_read (port, &response, 1);

	usleep (10000);
	gp_port_write (port, "\x0a\x00", 2); 	

	usleep (10000);
	/* Switch the inep over to 0x82. It stays there ever after. */ 
	set_usb_in_endpoint	(camera, 0x82); 
	usleep (10000);
	gp_port_read(port, (char *)info, info_block_size);
	usleep (10000);
	gp_port_write (port, "\x0b\x00",2);	
	usleep (10000);
	memmove(priv->info, info, info_block_size);
	GP_DEBUG("Leaving jl2005c_init\n");
        return GP_OK;
}


int
jl2005c_get_pic_data_size (Info *info, int n)
{
	int size;
	GP_DEBUG("info[48+16*n+7] = %02X\n", info[48+16*n+7]);
	size = (info[48+16*n+7]*0x200);
	GP_DEBUG("size = 0x%x = %d\n", size, size);
	return (size);
}

unsigned long
jl2005c_get_start_of_photo(Info *info, unsigned int n)
{
	unsigned long start = 0;
	start = (info[48+16*n+12]&0xff)*0x100;
	start -= 0x400;
	start += info[48+16*n+13]&0xff;
	start *= 0x200;

	return start;
}		


int 
set_usb_in_endpoint	(Camera *camera, int inep) 
{
	GPPortSettings settings;
	gp_port_get_settings ( camera ->port, &settings);
	settings.usb.inep = inep;
	GP_DEBUG("inep reset to %02X\n", inep);
	return gp_port_set_settings ( camera ->port, settings);
}	


int 
{'fraction_non_alphanumeric': 0.15481707918351248, 'fraction_numerical': 0.08549452716694605, 'mean_word_length': 4.497018970189702, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7025683', 'n_tokens_mistral': 4789, 'n_tokens_neox': 4040, 'n_words': 1065}