Skip to content

Commit

Permalink
Tweaks and fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Oct 19, 2024
1 parent 656e63f commit 01c11ce
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
22 changes: 6 additions & 16 deletions src/camlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ enum PtpLiveViewType {
/// @brief Unique camera types - each type should have similar opcodes and behavior
enum PtpVendors {
PTP_DEV_EMPTY = 0,
PTP_DEV_EOS = 1,
PTP_DEV_CANON = 2,
PTP_DEV_EOS = 1, // EOS DSLR/Mirrorless systems
PTP_DEV_CANON = 2, // Older powershot cameras
PTP_DEV_NIKON = 3,
PTP_DEV_SONY = 4,
PTP_DEV_FUJI = 5,
Expand All @@ -94,11 +94,12 @@ enum ImageFormats {
};

/// @brief Tells lib what backend and packet style to use
/// @note This is a bitmask so that it can be passed to ptp_new with other options.
enum PtpConnType {
// why this this a bitmask??
PTP_IP = (1 << 0),
PTP_IP_USB = (1 << 1), // TCP-based, but using USB-style packets (Fujifilm)
PTP_USB = (1 << 2),
PTP_BLE = (1 << 3), // I can only dream...
};

/// @brief Linked list to handle currently possible values for a property
Expand All @@ -111,7 +112,7 @@ struct PtpPropAvail {
void *data;
};

/// @brief Holds all camlib instance info
/// @brief Represents a single device connection
/// @struct PtpRuntime
struct PtpRuntime {
/// @brief Set to 1 to kill all IO operations. By default, this is 1. When a valid connection
Expand All @@ -137,7 +138,7 @@ struct PtpRuntime {
int max_packet_size;

/// @brief Info about current connection, used to detect camera type, supported opodes, etc
/// @note Set by ptp_parse_device_info.
/// @note Set by ptp_parse_device_info. This should be NULL when this struct is created.
struct PtpDeviceInfo *di;
int device_type;

Expand Down Expand Up @@ -338,15 +339,4 @@ int ptp_dump(struct PtpRuntime *r);
#define ptp_generic_send_data(...) ptp_send_data(__VA_ARGS__)
#endif

typedef void ptp_object_found_callback(struct PtpRuntime *r, struct PtpObjectInfo *oi, void *arg);

// Object service api (object.c) - optional
// Not documented yet
struct ObjectCache *ptp_create_object_service(int *handles, int length, ptp_object_found_callback *callback, void *arg);
struct PtpObjectInfo *ptp_object_service_get(struct PtpRuntime *r, struct ObjectCache *oc, int handle);
struct PtpObjectInfo *ptp_object_service_get_index(struct PtpRuntime *r, struct ObjectCache *oc, int req_i);
int ptp_object_service_length(struct PtpRuntime *r, struct ObjectCache *oc);
int ptp_object_service_step(struct PtpRuntime *r, struct ObjectCache *oc);
void ptp_object_service_add_priority(struct PtpRuntime *r, struct ObjectCache *oc, int handle);

#endif
10 changes: 5 additions & 5 deletions src/cl_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,21 @@ struct PtpDeviceEntry *ptpusb_device_list(struct PtpRuntime *r);
/// @memberof PTP/USB
void ptpusb_free_device_list(struct PtpDeviceEntry *e);
/// @brief Open and connect to a device from the PtpDeviceEntry structure
/// @note Sets kill switch to 0
/// @memberof PTP/USB
int ptp_device_open(struct PtpRuntime *r, struct PtpDeviceEntry *entry);

/// @brief Runs ptp_comm_init and connect to the first device available
int ptp_device_init(struct PtpRuntime *r);

// Temporary :)
//#define ptp_send_bulk_packet DEPRECATED_USE_ptp_cmd_write_INSTEAD
//#define ptp_receive_bulk_packet DEPRECATED_USE_ptp_cmd_read_INSTEAD

/// @brief Send data over the raw command endpoint
/// @memberof PTP/USB
int ptp_cmd_write(struct PtpRuntime *r, void *to, int length);
/// @brief Receive raw data over the command endpoint
/// @memberof PTP/USB
int ptp_cmd_read(struct PtpRuntime *r, void *to, int length);

/// @brief Reset the USB device or endpoint if there is communication issues
/// @brief Reset the USB endpoints if possible
/// @memberof PTP/USB
int ptp_device_reset(struct PtpRuntime *r);

Expand All @@ -69,6 +66,7 @@ int ptp_read_int(struct PtpRuntime *r, void *to, int length);
int ptp_device_close(struct PtpRuntime *r);

/// @brief Connect to a TCP port on the default network adapter
/// @note Sets kill switch to 0
/// @memberof PTP/IP
int ptpip_connect(struct PtpRuntime *r, const char *addr, int port, int extra_tmout);
/// @memberof PTP/IP
Expand All @@ -86,4 +84,6 @@ int ptpip_event_read(struct PtpRuntime *r, void *data, int size);
/// @memberof PTP/IP
int ptpip_close(struct PtpRuntime *r);

void ptpusb_free_device_list_entry(void *);

#endif
6 changes: 5 additions & 1 deletion src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
#include <ptp.h>

void ptp_reset(struct PtpRuntime *r) {
if (r == NULL) abort();
r->io_kill_switch = 1;
r->transaction = 0;
r->session = 0;
r->connection_type = PTP_USB;
r->response_wait_default = 1;
r->wait_for_response = 1;
r->comm_backend = NULL;
}

void ptp_init(struct PtpRuntime *r) {
if (r == NULL) abort();
memset(r, 0, sizeof(struct PtpRuntime));
ptp_reset(r);

Expand Down Expand Up @@ -100,6 +103,7 @@ void ptpusb_free_device_list(struct PtpDeviceEntry *e) {
struct PtpDeviceEntry *next;
while (e != NULL) {
next = e->next;
ptpusb_free_device_list_entry(e->device_handle_ptr);
free(e);
e = next;
}
Expand Down Expand Up @@ -190,7 +194,7 @@ int ptp_send(struct PtpRuntime *r, struct PtpCommand *cmd) {
return PTP_IO_ERR;
}
} else if (rc) {
ptp_mutex_unlock_thread(r);
ptp_mutex_unlock(r);
return PTP_IO_ERR;
}

Expand Down
6 changes: 5 additions & 1 deletion src/libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct LibUSBBackend {
};

// TODO: If this is accidentally called in the middle of a connection, it will cause a huge fault
int ptp_comm_init(struct PtpRuntime *r) {
static int ptp_comm_init(struct PtpRuntime *r) {
ptp_reset(r);

// libusb 1.0 has no specificed limit for reads/writes
Expand Down Expand Up @@ -243,6 +243,10 @@ int ptp_device_open(struct PtpRuntime *r, struct PtpDeviceEntry *entry) {
return 0;
}

void ptpusb_free_device_list_entry(void *ptr) {
// TODO: free libusb_device
}

int ptp_device_init(struct PtpRuntime *r) {
ptp_comm_init(r);
struct LibUSBBackend *backend = (struct LibUSBBackend *)r->comm_backend;
Expand Down
6 changes: 3 additions & 3 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ int ptpip_bulk_packet(struct PtpRuntime *r, struct PtpCommand *cmd, int type, in

int ptpip_data_start_packet(struct PtpRuntime *r, int data_length) {
struct PtpIpStartDataPacket *pkt = (struct PtpIpStartDataPacket *)(r->data);
pkt->length = 0x20;
pkt->length = 20; // fixme: This was 0x20, changed it (?????)
pkt->type = PTPIP_DATA_PACKET_START;
pkt->transaction = r->transaction;
pkt->data_phase_length = (uint64_t)data_length;
pkt->payload_length = (uint64_t)data_length;

return pkt->length;
}
Expand Down Expand Up @@ -318,7 +318,7 @@ int ptp_get_payload_length(struct PtpRuntime *r) {
ptp_panic("ptp_get_payload_length(): non data start packet");
}

return (int)ds->data_phase_length;
return (int)ds->payload_length;
} else {
struct PtpBulkContainer *bulk = (struct PtpBulkContainer*)(r->data);
return bulk->length - 12;
Expand Down
4 changes: 2 additions & 2 deletions src/ptp.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct PtpIpStartDataPacket {
uint32_t length;
uint32_t type;
uint32_t transaction;
uint64_t data_phase_length;
uint64_t payload_length;
};

struct PtpIpEndDataPacket {
Expand Down Expand Up @@ -293,7 +293,7 @@ struct PtpIpInitPacket {
#define PTP_OF_AVI 0x300A
#define PTP_OF_MPEG 0x300B
#define PTP_OF_ASF 0x300C
#define PTP_OF_MOV 0x300D // guessing
#define PTP_OF_MOV 0x300D
#define PTP_OF_JPEG 0x3801
#define PTP_OF_TIFF_EP 0x3802
#define PTP_OF_FlashPix 0x3803
Expand Down

0 comments on commit 01c11ce

Please sign in to comment.