summaryrefslogtreecommitdiff
path: root/camlibs/pentax/pslr_scsi.h
blob: f3b66081536196221fe9838ed3c21b688bc6dab4 (plain)
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
/*
    pkTriggerCord
    Copyright (C) 2011-2019 Andras Salamon <andras.salamon@melda.info>
    Remote control of Pentax DSLR cameras.

    based on:

    PK-Remote
    Remote control of Pentax DSLR cameras.
    Copyright (C) 2008 Pontus Lidman <pontus@lysator.liu.se>

    This program 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 3 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 Lesser General Public License for more details.

    You should have received a copy of the GNU General Public License
    and GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef CAMLIBS_PENTAX_PSLR_SCSI_H
#define CAMLIBS_PENTAX_PSLR_SCSI_H

#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>

extern bool debug;
extern void write_debug( const char* message, ... );

#ifdef ANDROID
#include <android/log.h>
#define DPRINT(...) __android_log_print(ANDROID_LOG_DEBUG, "PkTriggerCord", __VA_ARGS__)
#else
#ifdef LIBGPHOTO2
#include <gphoto2/gphoto2-library.h>
#define DPRINT(x...) gp_log (GP_LOG_DEBUG, "pentax", x)
#else
#define DPRINT(x...) write_debug(x)
#endif
#endif

#define CHECK(x) do {							\
	int __r;							\
	__r = (x);							\
	if (__r != PSLR_OK) {						\
		fprintf(stderr, "%s:%d:%s failed: %d\n", __FILE__, __LINE__, #x, __r); \
		return __r;						\
	}								\
} while (0)

typedef enum {
    PSLR_OK = 0,
    PSLR_DEVICE_ERROR,
    PSLR_SCSI_ERROR,
    PSLR_COMMAND_ERROR,
    PSLR_READ_ERROR,
    PSLR_NO_MEMORY,
    PSLR_PARAM,                 /* Invalid parameters to API */
    PSLR_ERROR_MAX
} pslr_result;

/* This also could be used to specify FDTYPE HANDLE for Win32, but this seems tricky with includes */
#ifdef LIBGPHOTO2
#define FDTYPE GPPort*
#define PRIFDTYPE "p"
#else
/* classic UNIX style handle */
#define FDTYPE int
#define PRIFDTYPE "d"
#endif

int scsi_read(FDTYPE sg_fd, uint8_t *cmd, uint32_t cmdLen,
              uint8_t *buf, uint32_t bufLen);

int scsi_write(FDTYPE sg_fd, uint8_t *cmd, uint32_t cmdLen,
               uint8_t *buf, uint32_t bufLen);

char **get_drives(int *drive_num);

pslr_result get_drive_info(char* drive_name, FDTYPE* device,
                           char* vendor_id, int vendor_id_size_max,
                           char* product_id, int product_id_size_max);

void close_drive(FDTYPE *device);

#endif /* !defined(CAMLIBS_PENTAX_PSLR_SCSI_H) */