cleanups.

imported command codes from windows driver.
generic crc handling.


git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@8165 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Marcus Meissner
2005-07-09 21:15:12 +00:00
parent 6b3e7131ed
commit cfa281f0a9
4 changed files with 194 additions and 224 deletions

View File

@@ -1,6 +1,9 @@
Sat Jul 9 17:39:28 CEST 2005 Marcus Meissner <marcus@jet.franken.de>
* *: Initial import of HP Photosmart 215 driver.
Can download images and previews, can delete single images
and all images.
* hp215.c:
Switch to generic CRC handling, generized the command blob generation.
Added all command codes from the windows driver.

View File

@@ -50,93 +50,4 @@ static unsigned short crctab[256] = {
* Omen Technology.
*/
#define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
/*
* Copyright © 1986 Gary S. Brown. You may use this program, or
* code or tables extracted from it, as desired without restriction.
*/
/* First, the polynomial itself and its table of feedback terms. The */
/* polynomial is */
/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
/* Note that we take it "backwards" and put the highest-order term in */
/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */
/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */
/* the MSB being 1. */
/* Note that the usual hardware shift register implementation, which */
/* is what we're using (we're merely optimizing it by doing eight-bit */
/* chunks at a time) shifts bits into the lowest-order term. In our */
/* implementation, that means shifting towards the right. Why do we */
/* do it this way? Because the calculated CRC must be transmitted in */
/* order from highest-order term to lowest-order term. UARTs transmit */
/* characters in order from LSB to MSB. By storing the CRC this way, */
/* we hand it to the UART in the order low-byte to high-byte; the UART */
/* sends each low-bit to hight-bit; and the result is transmission bit */
/* by bit from highest- to lowest-order term without requiring any bit */
/* shuffling on our part. Reception works similarly. */
/* The feedback terms table consists of 256, 32-bit entries. Notes: */
/* */
/* The table can be generated at runtime if desired; code to do so */
/* is shown later. It might not be obvious, but the feedback */
/* terms simply represent the results of eight shift/xor opera- */
/* tions for all combinations of data and CRC register values. */
/* */
/* The values must be right-shifted by eight bits by the "updcrc" */
/* logic; the shift must be unsigned (bring in zeroes). On some */
/* hardware you could probably optimize the shift in assembler by */
/* using byte-swap instructions. */
#if 0
static long cr3tab[] = { /* CRC polynomial 0xedb88320 */
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
#endif
#ifdef NFGM
long
UPDC32(b, c)
long c;
{
return (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF));
}
#else
#define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF))
#endif
/* End of crctab.c */
#define updcrc(cp, crc) ( crctab[cp ^ ((crc >> 8) & 255)] ^ (crc << 8))

View File

@@ -25,7 +25,7 @@
/*
Old Maintainer : Enno Bartels <ennobartels@t-online.de> in 2002/2003
Original author : Jason Surprise <thesurprises1@attbi.com> in 2002.
Checksum author: Roberto Ragusa <r.ragusa@libero.it> in 2002/2003.
Checksum author: Roberto Ragusa <r.ragusa@libero.it> in 2002/2003.
Ported to libgphoto2: Marcus Meissner <marcus@jet.franken.de> in 2005.
@@ -41,7 +41,7 @@
Single picture comands:
Allways 12 bytes long
| 0 1cmd 2 3 4 5 6 7 8 9 10 11
| 0 1cmd 2 3 4 5 6 7 8 9 10 11
-------------------------------+---------------------------------------------------------------
Request for a preview | 0x02 0xb3 0x84 0x80 ... 0x03
Request for a picture | 0x02 0xb4 0x84 0x80 ... 0x03
@@ -67,6 +67,8 @@
#include <gphoto2-library.h>
#include <gphoto2-result.h>
#include "crctab.h"
#ifdef ENABLE_NLS
# include <libintl.h>
# undef _
@@ -83,27 +85,76 @@
#include "hp215.h"
char monNameShort[12][30];
enum hp215_cmd {
SET_TIME = 0x86,
SET_TIME_AS_STR = 0x87,
SET_TIME_MODE = 0x88,
SET_TIME_PERIOD = 0x89,
SET_XFER_PROTOCOL = 0x8a,
SET_AUTO_SHUTDOWN_TIME = 0x8b,
SET_PHOTO_NO_DISPLAY_MODE = 0x8c,
DO_CALIBRATION = 0x8d,
GET_CALIBRATION_PARAM = 0x8e,
SET_SHOOT_AUTO = 0x90,
SET_FLASH = 0x91,
SET_EXPOSURE = 0x92,
SET_FOCUS = 0x93,
SET_SHUTTER = 0x94,
SET_RESOLUTION = 0x95,
SET_COMPRESSION = 0x96,
SET_TIMER = 0x97,
SET_EXT_FLASH = 0x98,
SET_PIC_FORMAT = 0x99,
RECORD_FUNC = 0xa2,
SET_SHOOTING_DEBUG_MODE = 0xa3,
GET_INTERNAL_SHOOT_AUTO_FUNC = 0xa4,
SET_INTERNAL_SHOOT_PARAM = 0xa6,
SET_SHOOT_PARAM = 0xa7,
SET_REVIEW_MODE = 0xa8,
SET_DISPLAY_PICTURE_NO = 0xa9,
SET_SHOOT_MODE_BY_INDEX = 0xaa,
GET_SHOOT_MODE_TABLE = 0xab,
SET_ACTIVE_SHOOTING_MODE = 0xac,
TAKE_PHOTO = 0xb0,
DELETE_PHOTO = 0xb1,
PROTECT_PHOTO = 0xb2,
DOWNLOAD_THUMBNAIL = 0xb3,
DOWNLOAD_PHOTO = 0xb4,
TAKE_PREVIEW = 0xb5,
SELF_TEST = 0xb6,
DISPLAY_PATTERN = 0xb7,
UPLOAD_PHOTO = 0xb8,
UPLOAD_FIRMWARE = 0xba,
UPDATE_FIRMWARE = 0xbb,
DOWNLOAD_FILE_BY_NAME = 0xbd,
__UPDATE_FIRMWARE = 0xbc,
DOWNLOAD_PHOTO_FROM_ALBUM = 0xbe,
GET_CAMERA_CAPS = 0xc0,
GET_CAMERA_CURINFO = 0xc1,
GET_PHOTO_INFO = 0xc5,
GET_ALBUM_INFO = 0xc6,
GET_CAMERA_READY = 0xce,
GET_INTERNAL_SHOOT_PARAM = 0xcf,
CREATE_ALBUM = 0xd0,
RENAME_ALBUM = 0xd2,
SET_ACTIVE_ALBUM = 0xd4,
};
/*****************************************************************************
* Function name : hp_gen_cmd *
*****************************************************************************/
/*
For picture/thumbnail and pic date/time request, the following
algorithm is used to generate the cmd to send to the camera for each
picture.
Thanks to Roberto Ragusa for figuring out the algorithm for this. I
would have never figured it out..
Every commands looks like:
02 AA BB .... CC CC CC CC 03
| b u f f e r
| 0 1cmd 2 3 4 5 6 7 8 9 10 11
-------------------------------+---------------------------------------------------------------
Request for a preview | 0x02 0xb3 0x84 0x80 ... 0x03
Request for a picture | 0x02 0xb4 0x84 0x80 ... 0x03
Request date/time for preview | 0x02 0xc5 0x84 0x80 ... 0x03
Request for deleting one pic | 0x02 0xb1 0x84 0x80 ... 0x03
02 - STX
AA - cmd byte
BB - 0x80 | argumentlength
... - argumentlength bytes
CC CC CC CC 16 bit CRC split into 4 bit pieces, | 0x80
03 - ETX
Request for a preview | 0xb3 16bit picnum
Request for a picture | 0xb4 16bit picnum
Request date/time for preview | 0xc5 16bit picnum
Request for deleting one pic | 0xb1 16bit picnum
Picture number:
----------------
@@ -111,120 +162,94 @@ char monNameShort[12][30];
buffer[5] = ((num&0xf0 )>>4) | 0x80;
buffer[6] = ((num&0xf ) ) | 0x80;
A generic CRC is done over the buffer, starting with the CMD byte (offset 1).
Rest:
-----
x4 = buffer[4] & 0xf;
x5 = buffer[5] & 0xf;
x6 = buffer[6] & 0xf;
Request for a preview : myx7=0xf myx8=0x2 myx9=0xe myx10=0x8
Request for a picture : myx7=0x3 myx8=0xa myx9=0xa myx10=0x9
Request date/time for preview: myx7=0x3 myx8=0xa myx9=0x9 myx10=0x5
Request for delete one pict. : myx7=0x7 myx8=0x9 myx9=0xa myx10=0x8
myx7 ^= x6 ^ ((x5<<1)&0xf) ^ x5 ^ ((x4<<1)&0xf) ^ x4 ^ x4>>2;
myx8 ^= (x6>>3) ^ ((x5<<1)&0xf) ^ (x5>>3) ^ x5 ^ ((x4<<2)&0xf) ^ ((x4<<1)&0xf) ^ x4;
myx9 ^= ((x6<<1)&0xf) ^ ((x5>>3<<1)&0xf) ^ ((x5<<1)&0xf) ^ x5 ^ ((x4<<1)&0xf) ^ x4;
myx10 ^= x6 ^ x5 ^ (x5>>3);
buffer[7] = myx7 | 0x80;
buffer[8] = myx8 | 0x80;
buffer[9] = myx9 | 0x80;
buffer[10] = myx10 | 0x80;
buffer[7] = ((crc>>12) & 0xf) | 0x80;
buffer[8] = ((crc>>8 ) & 0xf) | 0x80;
buffer[9] = ((crc>>4 ) & 0xf) | 0x80;
buffer[10] = ((crc ) & 0xf) | 0x80;
buffer[11] = 0x03;
*/
static int
hp_gen_cmd (int cmd, int num, unsigned char *buffer)
static int
hp_gen_cmd_blob (enum hp215_cmd cmd, int bytes, unsigned char *argdata, unsigned char *buffer)
{
int x4, x5, x6;
int myx7, myx8, myx9, myx10;
int i, crc = 0;
buffer[0] = 0x02;
/* store STX */
buffer[0] = STX;
/* store CMD */
buffer[1] = cmd;
buffer[2] = 0x84;
buffer[3] = 0x80;
buffer[4] = ((num&0xf00)>>8) | 0x80;
buffer[5] = ((num&0xf0 )>>4) | 0x80;
buffer[6] = ((num&0xf ) ) | 0x80;
if (bytes >= 0x7d) {
gp_log (GP_LOG_ERROR, "hp215", "Using too large argument buffer %d bytes\n", bytes);
return GP_ERROR_BAD_PARAMETERS;
}
/* store arglen */
buffer[2] = 0x80 | bytes;
x4 = buffer[4]&0xf;
x5 = buffer[5]&0xf;
x6 = buffer[6]&0xf;
/* Kind of command */
switch (cmd) {
case 0xb3: /* Request for a preview */
myx7=0xf,myx8=0x2,myx9=0xe,myx10=0x8;
break;
case 0xb4: /* Request for a picture */
myx7=0x3,myx8=0xa,myx9=0xa,myx10=0x9;
break;
case 0xc5: /* Request date/time for preview */
myx7=0x3,myx8=0xa,myx9=0x9,myx10=0x5;
break;
case 0xb1: /* Request delete a single pic */
myx7=0x7,myx8=0x9,myx9=0xa,myx10=0x8;
break;
default: /* unknown command */
gp_log (GP_LOG_ERROR, "hp215", "ERROR: Unknown command %x!\n", cmd);
return GP_ERROR;
if (bytes) {
/* store arguments */
memcpy (buffer+3, argdata, bytes);
}
/* What is happening here ? */
myx7 ^= x6^((x5<<1)&0xf)^x5^((x4<<1)&0xf)^x4^x4>>2;
myx8 ^= (x6>>3)^((x5<<1)&0xf)^(x5>>3)^x5^((x4<<2)&0xf)^((x4<<1)&0xf)^x4;
myx9 ^= ((x6<<1)&0xf)^((x5>>3<<1)&0xf)^((x5<<1)&0xf)^x5^((x4<<1)&0xf)^x4;
myx10 ^= x6^x5^(x5>>3);
buffer[7] = myx7 | 0x80;
buffer[8] = myx8 | 0x80;
buffer[9] = myx9 | 0x80;
buffer[10] = myx10 | 0x80;
buffer[11] = 0x03;
/* generate CRC over cmd, len, and arguments */
for (i=1;i<bytes + 3;i++)
crc = updcrc(buffer[i], crc);
/* store CRC */
buffer[bytes+3] = ((crc >> 12) & 0xf) | 0x80;
buffer[bytes+4] = ((crc >> 8) & 0xf) | 0x80;
buffer[bytes+5] = ((crc >> 4) & 0xf) | 0x80;
buffer[bytes+6] = ((crc >> 0) & 0xf) | 0x80;
/* store ETX */
buffer[bytes+7] = ETX;
return GP_OK;
}
static int
hp_send_ack (Camera *cam)
static int
hp_gen_cmd_1_16 (enum hp215_cmd cmd, unsigned short val, unsigned char *buffer)
{
unsigned char byte = ACK;
int ret;
unsigned char argbuf[4];
gp_log (GP_LOG_DEBUG, "hp215", "Sending ACK ... ");
ret = gp_port_write (cam->port, &byte, 1);
if (ret < GP_OK)
gp_log (GP_LOG_ERROR, "hp215", "ACK sending failed with %d\n", ret);
return ret;
argbuf[0] = ((val&0xf000)>>12) | 0x80;
argbuf[1] = ((val&0x0f00)>> 8) | 0x80;
argbuf[2] = ((val&0x00f0)>> 4) | 0x80;
argbuf[3] = ((val&0x000f) ) | 0x80;
return hp_gen_cmd_blob (cmd, 4, argbuf, buffer);
}
static int
static int
hp_send_ack (Camera *cam)
{
unsigned char byte = ACK;
int ret;
gp_log (GP_LOG_DEBUG, "hp215", "Sending ACK ... ");
ret = gp_port_write (cam->port, &byte, 1);
if (ret < GP_OK)
gp_log (GP_LOG_ERROR, "hp215", "ACK sending failed with %d\n", ret);
return ret;
}
static int
hp_rcv_ack (Camera *cam)
{
int ret;
unsigned char byte = '\0';
int ret;
unsigned char byte = '\0';
gp_log (GP_LOG_DEBUG, "hp215", "Receiving ACK ... ");
ret = gp_port_read (cam->port, &byte, 1);
if (ret < GP_OK)
return ret;
if (byte == ACK)
return GP_OK;
gp_log (GP_LOG_DEBUG, "hp215", "Expected ACK, but read %02x", byte);
return GP_ERROR_IO;
gp_log (GP_LOG_DEBUG, "hp215", "Receiving ACK ... ");
ret = gp_port_read (cam->port, &byte, 1);
if (ret < GP_OK)
return ret;
if (byte == ACK)
return GP_OK;
gp_log (GP_LOG_DEBUG, "hp215", "Expected ACK, but read %02x", byte);
return GP_ERROR_IO;
}
static int
@@ -232,9 +257,10 @@ hp_get_timeDate_cam (Camera *cam, char *txtbuffer, size_t txtbuffersize)
{
int i, ret;
unsigned char msg[0x6b];
unsigned char buffer[] = HP_CMD_DATETIME;
unsigned char buffer[8];
t_date date;
hp_gen_cmd_blob (GET_CAMERA_CURINFO, 0, NULL, buffer);
memset(msg, 0, sizeof(msg));
/* Sending date/time command */
@@ -280,7 +306,7 @@ hp_get_timeDate_cam (Camera *cam, char *txtbuffer, size_t txtbuffersize)
date.hour = (msg[14]-48)*10 + (msg[15]-48);
date.min = (msg[17]-48)*10 + (msg[18]-48);
snprintf (txtbuffer, txtbuffersize, _("Current camera time: %04d-%02d-%02d %02d:%02d\n"),
snprintf (txtbuffer, txtbuffersize, _("Current camera time: %04d-%02d-%02d %02d:%02d\n"),
date.year, date.month, date.day, date.hour, date.min
);
return GP_OK;
@@ -331,16 +357,16 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
memset(msg, 0, sizeof(msg));
switch (type) {
case GP_FILE_TYPE_NORMAL:
cmd = 0xb4;
cmd = DOWNLOAD_PHOTO;
break;
case GP_FILE_TYPE_PREVIEW:
cmd = 0xb3;
cmd = DOWNLOAD_THUMBNAIL;
break;
default:
return GP_ERROR_BAD_PARAMETERS;
}
hp_gen_cmd (cmd, image_no, buffer);
hp_gen_cmd_1_16 (cmd, image_no, buffer);
ret = gp_port_write (camera->port, buffer, 0x0c);
if (ret < GP_OK)
return ret;
@@ -408,7 +434,7 @@ delete_file_func (CameraFilesystem *fs, const char *folder,
image_no++;
memset(msg, 0, sizeof(msg));
hp_gen_cmd (0xb1, image_no, buffer);
hp_gen_cmd_1_16 (DELETE_PHOTO, image_no, buffer);
ret = gp_port_write (camera->port, buffer, 0x0c);
if (ret < GP_OK)
return ret;
@@ -428,12 +454,12 @@ delete_all_func (CameraFilesystem *fs, const char *folder, void *data,
GPContext *context)
{
Camera *camera = data;
unsigned char buffer[] = HP_CMD_DELETE_PICS;
unsigned char buffer[12];
unsigned char msg[10];
int ret;
memset (msg, 0, sizeof(msg));
hp_gen_cmd_1_16 (DELETE_PHOTO, 0xFFFF, buffer);
ret = gp_port_write (camera->port, buffer, 12);
if (ret < GP_OK)
return GP_ERROR_IO;
@@ -463,7 +489,7 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
image_no++;
memset (msg, 0, sizeof(msg));
hp_gen_cmd (0xc5, image_no, buffer);
hp_gen_cmd_1_16 (GET_PHOTO_INFO, image_no, buffer);
ret = gp_port_write (camera->port, buffer, 0x0c);
if (ret < GP_OK)
return ret;
@@ -489,7 +515,7 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
return GP_OK;
#if 0
/* Copy getten date into date placeholder */
strcpy ((camera->pic[cnt+1])->date_time, &msg[0x0d]);
strcpy ((camera->pic[cnt+1])->date_time, &msg[0x0d]);
/* Calculate day,month, year, hour and minute of the photo */
(camera->pic[cnt+1])->date.day = (msg[3+offset]-48)*10 + (msg[4+offset]-48);
@@ -506,16 +532,16 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
/*
000013 B> 00000000: 02c6 8880 8083 8438 2f30 3288 848e 8b03 .......8/02.....
000014 B< 00000000: 06 .
000015 B< 00000000: 02c6 aae0 e050 686f 746f 416c 6275 6d00 .....PhotoAlbum.
00000010: 3a32 3600 8080 0180 8182 8c81 8080 8080 :26.............
00000020: 8080 8080 e480 8080 8080 8080 8087 8084 ................
00000030: 8a03 ..
000016 B> 00000000: 06 .
The first cmd in the trace is sent to the camera. It appears to
@@ -526,7 +552,7 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
can use the above command as is regardless of the date/time and still
receive the PhotoAlbum correctly, so I've implemented it as a static
call.
From observation, the 43+44+45th lower words of the returned msg contains
the number of pictures in the camera.
*/
@@ -582,6 +608,37 @@ file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
return gp_list_populate(list, "image%i.jpg", count);
}
static int
camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *path,
GPContext *context)
{
unsigned char buffer[12];
unsigned char msg[10];
int ret;
hp_gen_cmd_1_16 (TAKE_PHOTO, 1, buffer);
ret = gp_port_write (camera->port, buffer, 12);
if (ret < GP_OK)
return ret;
if (hp_rcv_ack (camera))
return GP_ERROR_IO;
gp_log( GP_LOG_DEBUG, "hp215", "Expecting capture reply ... ");
/* FIXME: hangs here currently */
ret = gp_port_read (camera->port, msg, 10);
if (ret != 10) {
gp_log (GP_LOG_ERROR, "hp215", "ERROR: Init failed. %d bytes received instead of 10!\n", ret);
return GP_ERROR_IO;
}
ret = hp_send_ack (camera);
if (ret < GP_OK)
return ret;
/*
* tell libgphoto2 where to find it by filling out the path.
*/
return GP_OK;
}
int
camera_id (CameraText *id) {
strcpy(id->text, "hp215");
@@ -599,7 +656,7 @@ camera_abilities (CameraAbilitiesList *list) {
a.port = GP_PORT_USB;
a.usb_vendor = 0x3f0; /* HP */
a.usb_product = 0x6202; /* Photosmart 215 */
a.operations = GP_OPERATION_NONE;
a.operations = GP_OPERATION_CAPTURE_IMAGE;
a.file_operations = GP_FILE_OPERATION_DELETE | GP_FILE_OPERATION_PREVIEW;
a.folder_operations = GP_FOLDER_OPERATION_DELETE_ALL;
return gp_abilities_list_append(list, a);
@@ -607,15 +664,16 @@ camera_abilities (CameraAbilitiesList *list) {
int
camera_init (Camera *camera, GPContext *context)
camera_init (Camera *camera, GPContext *context)
{
int ret;
unsigned char msg[10];
unsigned char buffer[] = HP_CMD_INIT;
unsigned char buffer[8];
GPPortSettings settings;
camera->functions->summary = camera_summary;
camera->functions->about = camera_about;
camera->functions->capture = camera_capture;
gp_filesystem_set_list_funcs (camera->fs, file_list_func, NULL, camera);
gp_filesystem_set_info_funcs (camera->fs, get_info_func, NULL, camera);
@@ -641,6 +699,7 @@ camera_init (Camera *camera, GPContext *context)
gp_log (GP_LOG_DEBUG, "hp215", "Sending init sequence ... ");
hp_gen_cmd_blob (GET_CAMERA_READY, 0, NULL, buffer);
ret = gp_port_write (camera->port, buffer, 8);
if (ret < GP_OK)
return ret;

View File

@@ -22,14 +22,11 @@
* Suite 330, Boston, MA 02111-1307, USA. *
*****************************************************************************/
#define STX 0x02
#define ETX 0x03
#define ACK 0x06
#define HP_VENDOR_ID 0x3f0
#define HP215_ID 0x6202
/* General commands */
#define HP_CMD_INIT {0x02, 0xce, 0x80, 0x8a, 0x84, 0x8d, 0x83, 0x03}
#define HP_CMD_DATETIME {0x02, 0xc1, 0x80, 0x8b, 0x84, 0x8e, 0x8d, 0x03}
#define HP_CMD_GET_PHOTO_ALBUM {0x02, 0xc6, 0x88, 0x80, 0x80, 0x83, 0x84, 0x38, 0x2f, 0x30, 0x32, 0x88, 0x84, 0x8e, 0x8b, 0x03}
#define HP_CMD_DELETE_PICS {0x02, 0xb1, 0x84, 0x8f, 0x8f, 0x8f, 0x8f, 0x86, 0x80, 0x8a, 0x86, 0x03}