Skip to content

Commit

Permalink
Minor tweaks, add nonstandard goodbye code 0xffff
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Nov 1, 2024
1 parent 9b960bb commit 1c8f3c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/camlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct PtpRuntime {
/// @note: Optional
struct PtpPropAvail *avail;

struct ObjectCache *oc;
void *oc;
};

/// @brief Generic event / property change
Expand Down
12 changes: 8 additions & 4 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ void ptp_init(struct PtpRuntime *r) {
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);

if (pthread_mutex_init(r->mutex, &attr)) {
ptp_verbose_log("Failed to init mutex\n");
free(r->mutex);
r->mutex = NULL;
ptp_panic("Failed to init mutex\n");
}
#endif
}
Expand Down Expand Up @@ -155,7 +153,13 @@ void ptp_mutex_unlock_thread(struct PtpRuntime *r) {
}

static int ptp_check_rc(struct PtpRuntime *r) {
if (ptp_get_return_code(r) != PTP_RC_OK) {
int code = ptp_get_return_code(r);
// This is returned on Fuji cameras
if (code == 0xffff) {
ptp_verbose_log("Nonstandard goodbye return code 0xffff");
return PTP_IO_ERR;
}
if (code != PTP_RC_OK) {
ptp_verbose_log("Invalid return code: %X\n", ptp_get_return_code(r));
return PTP_CHECK_CODE;
}
Expand Down
12 changes: 4 additions & 8 deletions src/transport.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Packet transport interface for PTPUSB, PTPIP, and PTPUSBIP - uses OS IO functions
// Don't include this file with Windows/LibWPD builds. LibWPD replaces this file.

// For Windows MTP, this calls functions in libwpd.c
// Copyright 2024 by Daniel C (https://github.com/petabyt/camlib)

#include <stdio.h>
Expand Down Expand Up @@ -170,21 +169,18 @@ int ptpip_write_packet(struct PtpRuntime *r, int of) {
return rc;
}

// Quirk of LibUSB/LibWPD - we can allowed read 512 bytes over and over again
// until we don't, then packet is over. This makes the code simpler and gives a reduces
// calls to the backend, which increases performance. This isn't possible with sockets -
// the read will time out in most cases.
// MTP clients must support 512 byte bulk transactions, so this makes transmission simpler. And a little faster.
int ptpusb_read_all_packets(struct PtpRuntime *r) {
int read = 0;

// Try and get the first 512 bytes
int rc = 0;
while (rc <= 0 && r->wait_for_response) {
while (r->wait_for_response) {
rc = ptp_cmd_read(r, r->data + read, r->max_packet_size);

r->wait_for_response--;

if (rc < 0) break;
if (rc > 0) break;

if (r->wait_for_response) {
ptp_verbose_log("Trying again...\n");
Expand Down

0 comments on commit 1c8f3c3

Please sign in to comment.