Skip to content

Commit

Permalink
Fix bug in transport.c for PTP/USB, add stuff to stuff.c
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Dec 18, 2024
1 parent 0c12784 commit 5d30fac
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,9 @@ int ptp_parse_prop_value(struct PtpRuntime *r) {
type = PTP_TC_UINT16; break;
case 4:
type = PTP_TC_UINT32; break;
case 0:
return -1;
default:
ptp_panic("ptp_parse_prop_value: unknown data type size %d", ptp_get_payload_length(r));
ptp_verbose_log("%s: unknown data type size %d - returning -1\n", __func__, ptp_get_payload_length(r));
return -1;
}

int out;
Expand Down
39 changes: 38 additions & 1 deletion src/stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,42 @@ int ptp_list_devices(void) {
printf("Model friendly name: '%s'\n", list->name);
}

ptp_close(r);

return 0;
}

static struct PtpRuntime *ptp_connect_id(int id) {
struct PtpRuntime *r = ptp_new(PTP_USB);
struct PtpDeviceEntry *list = ptpusb_device_list(r);

if (list == NULL) {
printf("No devices found\n");
return 0;
}

int i = 0;
for (; list != NULL; list = list->next) {
if (i == id) {
int rc = ptp_device_open(r, list);
if (rc) return NULL;
return r;
}
i++;
}

ptp_close(r);
return NULL;
}

int ptp_dump_device(void) {
struct PtpRuntime *r = ptp_connect_id(0);

struct PtpDeviceInfo di;
char buffer[4096];
ptp_get_device_info(r, &di);
ptp_device_info_json(&di, buffer, sizeof(buffer));
printf("%s\n", (char*)buffer);

return 0;
}
}
10 changes: 8 additions & 2 deletions src/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ int ptp_send_packet(struct PtpRuntime *r, int length) {
int sent = 0;
while (1) {
int max = length - sent;
if (r->max_packet_size != 512) ptp_panic("max packet size is not 512, %d", r->max_packet_size);
if (max > r->max_packet_size) max = r->max_packet_size;
int rc = ptp_cmd_write(r, r->data + sent, max);
int rc;
if (r->connection_type == PTP_USB) {
rc = ptp_cmd_write(r, r->data + sent, max);
} else if (r->connection_type == PTP_IP_USB) {
rc = ptpip_cmd_write(r, r->data + sent, max);
} else {
ptp_panic("illegal connection_type");
}

if (rc < 0) {
ptp_verbose_log("%s: %d\n", __func__, rc);
Expand Down

0 comments on commit 5d30fac

Please sign in to comment.