From 01c11ce74efe9a608725b5c70ca8d00a4aec1d2c Mon Sep 17 00:00:00 2001 From: Daniel C Date: Sat, 19 Oct 2024 01:10:09 -0400 Subject: [PATCH] Tweaks and fix typos --- src/camlib.h | 22 ++++++---------------- src/cl_backend.h | 10 +++++----- src/lib.c | 6 +++++- src/libusb.c | 6 +++++- src/packet.c | 6 +++--- src/ptp.h | 4 ++-- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/camlib.h b/src/camlib.h index b14cb0c..7a2ca09 100644 --- a/src/camlib.h +++ b/src/camlib.h @@ -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, @@ -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 @@ -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 @@ -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; @@ -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 diff --git a/src/cl_backend.h b/src/cl_backend.h index fe60031..8bbf0de 100644 --- a/src/cl_backend.h +++ b/src/cl_backend.h @@ -31,16 +31,13 @@ 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); @@ -48,7 +45,7 @@ int ptp_cmd_write(struct PtpRuntime *r, void *to, int length); /// @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); @@ -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 @@ -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 diff --git a/src/lib.c b/src/lib.c index 44338ee..2d6a434 100644 --- a/src/lib.c +++ b/src/lib.c @@ -9,15 +9,18 @@ #include 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); @@ -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; } @@ -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; } diff --git a/src/libusb.c b/src/libusb.c index 5d6d5f6..491c9e3 100644 --- a/src/libusb.c +++ b/src/libusb.c @@ -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 @@ -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; diff --git a/src/packet.c b/src/packet.c index 40b8edf..8662639 100644 --- a/src/packet.c +++ b/src/packet.c @@ -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; } @@ -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; diff --git a/src/ptp.h b/src/ptp.h index 1363d62..dadffd6 100644 --- a/src/ptp.h +++ b/src/ptp.h @@ -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 { @@ -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