<commit_before>/* pdc640.c
 *
 * Copyright  2001 <NAME> <<EMAIL>>
 * Copyright  2002 <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 <string.h>

#include <gphoto2-library.h>
#include <gphoto2-port-log.h>
#include <bayer.h>

#include "jd350e.h"

#define GP_MODULE "pdc640"

#define PDC640_PING  "\x01"
#define PDC640_SPEED "\x69\x0b"

#define PDC640_MAXTRIES 3

#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}

#ifdef ENABLE_NLS
#  include <libintl.h>
#  undef _
#  define _(String) dgettext (GETTEXT_PACKAGE, String)
#  ifdef gettext_noop
#    define N_(String) gettext_noop (String)
#  else
#    define N_(String) (String)
#  endif
#else
#  define textdomain(String) (String)
#  define gettext(String) (String)
#  define dgettext(Domain,Message) (Message)
#  define dcgettext(Domain,Message,Type) (Message)
#  define bindtextdomain(Domain,Directory) (Domain)
#  define _(String) (String)
#  define N_(String) (String)
#endif


typedef enum{
	pdc640,
	jd350e
} Model;

typedef int postproc_func(int,int,unsigned char*);

struct _CameraPrivateLibrary{
	Model			model;
	BayerTile		bayer_tile;
	postproc_func*	postprocessor;
	char*			filespec;
};

static int rotate180(int width, int height, unsigned char* rgb);

static struct {
	const char*				model;
	int vendor,product;
	struct _CameraPrivateLibrary	pl;
} models[] = {
	{"Polaroid:Fun Flash 640", 0, 0, {
		 	pdc640,
			BAYER_TILE_RGGB,
			NULL, // add postprocessor here!
			"pdc640%04i.ppm"
		}
	},
	{"Jenoptik:JD350 entrance", 0x5da, 0x1006, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350e%04i.ppm"
		}
	},
	{"Jenoptik:JD350 video", 0xd96, 0x0000, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"ScanHex:SX-35", 0x797, 0x8901, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"ScanHex:SX-35", 0x797, 0x8909, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"ScanHex:SX-35", 0x797, 0x8911, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"ScanHex:SX-35", 0x84d, 0x1001, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"Typhoon:StyloCam", 0x797, 0x801a, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&rotate180,
			"stylo%04i.ppm"
		}
	},
	{"Trust:PowerC@m 350FS", 0x6d6, 0x002e, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&rotate180,
			"stylo%04i.ppm"
		}
	},
	{NULL,}
};

static int
pdc640_read_packet (GPPort *port, char *buf, int buf_size)
{
	int i;
	char checksum, c;

	/* Calculate the checksum */
	for (i = 0, checksum = 0; i < buf_size; i++)
		buf[i] = 0;

	/* Read the packet */
	CHECK_RESULT (gp_port_read (port, buf, buf_size));

	/* Calculate the checksum */
	for (i = 0, checksum = 0; i < buf_size; i++)
		checksum += buf[i];

	/* Read the checksum */
	CHECK_RESULT (gp_port_read (port, &c, 1));
	GP_DEBUG ("Checksum: %d calculated, %d received", checksum, c);
	if (checksum != c)
		return (GP_ERROR_CORRUPTED_DATA);

	return (GP_OK);
}<commit_msg>	* added Meade ScopeCam (also uses gt89x)<commit_after>/* pdc640.c
 *
 * Copyright  2001 <NAME> <<EMAIL>>
 * Copyright  2002 <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 <string.h>

#include <gphoto2-library.h>
#include <gphoto2-port-log.h>
#include <bayer.h>

#include "jd350e.h"

#define GP_MODULE "pdc640"

#define PDC640_PING  "\x01"
#define PDC640_SPEED "\x69\x0b"

#define PDC640_MAXTRIES 3

#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}

#ifdef ENABLE_NLS
#  include <libintl.h>
#  undef _
#  define _(String) dgettext (GETTEXT_PACKAGE, String)
#  ifdef gettext_noop
#    define N_(String) gettext_noop (String)
#  else
#    define N_(String) (String)
#  endif
#else
#  define textdomain(String) (String)
#  define gettext(String) (String)
#  define dgettext(Domain,Message) (Message)
#  define dcgettext(Domain,Message,Type) (Message)
#  define bindtextdomain(Domain,Directory) (Domain)
#  define _(String) (String)
#  define N_(String) (String)
#endif


typedef enum{
	pdc640,
	jd350e
} Model;

typedef int postproc_func(int,int,unsigned char*);

struct _CameraPrivateLibrary{
	Model			model;
	BayerTile		bayer_tile;
	postproc_func*	postprocessor;
	char*			filespec;
};

static int rotate180(int width, int height, unsigned char* rgb);

static struct {
	const char*				model;
	int vendor,product;
	struct _CameraPrivateLibrary	pl;
} models[] = {
	{"Polaroid:Fun Flash 640", 0, 0, {
		 	pdc640,
			BAYER_TILE_RGGB,
			NULL, // add postprocessor here!
			"pdc640%04i.ppm"
		}
	},
	{"Jenoptik:JD350 entrance", 0x5da, 0x1006, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350e%04i.ppm"
		}
	},
	{"Jenoptik:JD350 video", 0xd96, 0x0000, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"ScanHex:SX-35", 0x797, 0x8901, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"ScanHex:SX-35", 0x797, 0x8909, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"ScanHex:SX-35", 0x797, 0x8911, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"ScanHex:SX-35", 0x84d, 0x1001, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&jd350e_postprocessing,
			"jd350v%04i.ppm"
		}
	},
	{"Typhoon:StyloCam", 0x797, 0x801a, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&rotate180,
			"stylo%04i.ppm"
		}
	},
	{"Trust:PowerC@m 350FS", 0x6d6, 0x002e, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&rotate180,
			"trust%04i.ppm"
		}
	},
	/* http://www.meade.com/sportsoptics/catalog/captureview/index.html */
	{"GrandTek:ScopeCam", 0x797, 0x801c, {
		 	jd350e,
			BAYER_TILE_BGGR,
			&rotate180,
			"scope%04i.ppm"
		}
	},
	{NULL,}
};

static int
pdc640_read_packet (GPPort *port, char *buf, int buf_size)
{
	int i;
	char checksum, c;

	/* Calculate the checksum */
	for (i = 0, checksum = 0; i < buf_size; i++)
		buf[i] = 0;

	/* Read the packet */
	CHECK_RESULT (gp_port_read (port, buf, buf_size));

	/* Calculate the checksum */
	for (i = 0, checksum = 0; i < buf_size; i++)
		checksum += buf[i];

	/* Read the checksum */
	CHECK_RESULT (gp_port_read (port, &c, 1));
	GP_DEBUG ("Checksum: %d calculated, %d received", checksum, c);
	if (checksum != c)
		return (GP_ERROR_CORRUPTED_DATA);

	return (GP_OK);
}
{'fraction_non_alphanumeric': 0.1310065756196257, 'fraction_numerical': 0.06423874557410217, 'mean_word_length': 3.879086983343615, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '5737582', 'n_tokens_mistral': 3792, 'n_tokens_neox': 3161, 'n_words': 794}