1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* Copyright © 1999/2000 by Henning Zabel <henning@uni-paderborn.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program 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 General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* gphoto driver for the Mustek MDC800 Digital Camera. The driver
* supports rs232 and USB. It automatically detects which Kernelnode
* is used.
*/
/*
* Implements cummunication-core :
*
* Sending commands and receiving data
*/
#include <gphoto2/gphoto2-library.h>
#include <gphoto2/gphoto2-result.h>
#include "io.h"
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include "print.h"
#include "rs232.h"
#include "usb.h"
#include "mdc800_spec.h"
/*
* Send a Command to the Camera. It is unimportent wether this
* is a USB or a RS232 Command. The Function implements an automatic
* retry of a failed command.
*
* The Function will only be used in this Layer, execpt on probing
* the Baudrate of Rs232.
* if quiet is true, the function won't print notes
*/
int mdc800_io_sendCommand_with_retry (GPPort *port,unsigned char* command, unsigned char* buffer, int length, int maxtries,int quiet)
{
int try=0;
int ret=GP_OK;
while (try < maxtries)
{
usleep(MDC800_DEFAULT_COMMAND_RETRY_DELAY*1000);
if (port->type == GP_PORT_USB)
ret=mdc800_usb_sendCommand(port,command, buffer, length );
else
ret=mdc800_rs232_sendCommand(port, command, buffer, length);
if (ret==GP_OK)
return GP_OK;
try++;
}
if (!quiet)
{
printCoreNote ("\nCamera is not responding (Maybe off?)\n");
printCoreNote ("giving it up after %i times.\n\n", try);
}
return GP_ERROR_IO;
}
/*
* sends a command and receives the answer to this
* buffer: Strores the answer
* length: length of answer or null
*/
int mdc800_io_sendCommand (GPPort*port,unsigned char commandid,unsigned char par1,unsigned char par2,unsigned char par3, unsigned char* buffer, int length)
{
unsigned char command [8];
command[0]=COMMAND_BEGIN;
command[1]=commandid;
command[2]=par1;
command[3]=par2;
command[4]=par3;
command[5]=COMMAND_END;
command[6]=0;
command[7]=0;
return mdc800_io_sendCommand_with_retry (port,command,buffer,length, MDC800_DEFAULT_COMMAND_RETRY,0);
}
/*
* Helper function for rs232 and usb
* It returns a timeout for the specified command
*/
int mdc800_io_getCommandTimeout (unsigned char command)
{
switch (command)
{
case COMMAND_SET_STORAGE_SOURCE:
case COMMAND_SET_TARGET:
case COMMAND_SET_CAMERA_MODE:
case COMMAND_DELETE_IMAGE:
return MDC800_LONG_TIMEOUT;
case COMMAND_TAKE_PICTURE:
case COMMAND_PLAYBACK_IMAGE:
case COMMAND_SET_PLAYBACK_MODE:
return MDC800_TAKE_PICTURE_TIMEOUT;
}
return MDC800_DEFAULT_TIMEOUT;
}
|