Skip to content

Commit

Permalink
Add no_ip.c since ip.c is POSIX-only, also add new USB api from libus…
Browse files Browse the repository at this point in the history
…b.c to libwpd.c
  • Loading branch information
petabyt committed Oct 11, 2023
1 parent 490a139 commit 225f7b0
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/backend.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Common IO backend code - only applies to platforms that have generic
// USB packet IO access (Not Windows)
// Packet stream read/write logic - uses bare I/O operations
// Windows doesn't have that, so it can't be used here.

// Copyright 2022 by Daniel C (https://github.com/petabyt/camlib)

Expand Down
2 changes: 0 additions & 2 deletions src/canon.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ int ptp_eos_get_viewfinder_data(struct PtpRuntime *r) {
cmd.param_length = 1;

cmd.params[0] = 0x200000;
cmd.params[1] = 0x0;
cmd.params[2] = 0x0;

return ptp_generic_send(r, &cmd);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ip.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// PTP/IP implementation -
// POSIX PTP/IP implementation
// Copyright 2023 by Daniel C (https://github.com/petabyt/camlib)

#include <stdio.h>
Expand Down
21 changes: 19 additions & 2 deletions src/libwpd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Windows USB I/O frontend for libwpd (https://github.com/petabyt/libwpd)
// Copyright 2022 by Daniel C (https://github.com/petabyt/camlib)
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
Expand All @@ -9,9 +11,16 @@

struct WpdStruct backend_wpd;

int ptp_device_init(struct PtpRuntime *r) {
int ptp_comm_init(struct PtpRuntime *r) {
ptp_generic_reset(r);
wpd_init(1, L"Camlib WPD");

return 0;
}

int ptp_device_init(struct PtpRuntime *r) {
ptp_comm_init();

int length = 0;
wchar_t **devices = wpd_get_devices(&backend_wpd, &length);

Expand All @@ -37,6 +46,14 @@ int ptp_device_init(struct PtpRuntime *r) {
return PTP_NO_DEVICE;
}

struct PtpDeviceEntry *ptpusb_device_list(struct PtpRuntime *r) {
return NULL;
}

int ptp_device_open(struct PtpRuntime *r, struct PtpDeviceEntry *entry) {
return PTP_IO_ERR;
}

int ptp_send_bulk_packets(struct PtpRuntime *r, int length) {
struct PtpCommand cmd;
struct PtpBulkContainer *bulk = (struct PtpBulkContainer*)(r->data);
Expand Down Expand Up @@ -121,7 +138,7 @@ int ptp_receive_bulk_packets(struct PtpRuntime *r) {
return 0;
}

int ptp_receive_int(void *to, int length) {
int ptp_read_int(void *to, int length) {
return 0;
}

Expand Down
36 changes: 36 additions & 0 deletions src/no_ip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Include this if you wish to never use TCP/IP
// Copyright 2022 by Daniel C (https://github.com/petabyt/camlib)
#include <camlib.h>
#include <ptp.h>

int ptpip_new_timeout_socket(char *addr, int port) {
return -1;
}

int ptpip_connect(struct PtpRuntime *r, char *addr, int port) {
return -1;
}

int ptpip_connect_events(struct PtpRuntime *r, char *addr, int port) {
return -1;
}

int ptpip_close(struct PtpRuntime *r) {
return -1;
}

int ptpip_cmd_write(struct PtpRuntime *r, void *data, int size) {
return -1;
}

int ptpip_cmd_read(struct PtpRuntime *r, void *data, int size) {
return -1;
}

int ptpip_event_send(struct PtpRuntime *r, void *data, int size) {
return -1;
}

int ptpip_event_read(struct PtpRuntime *r, void *data, int size) {
return -1;
}
9 changes: 9 additions & 0 deletions src/pack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <camlib.h>

int ptp_pack_fuji_object_info(struct PtpRuntime *r, struct PtpObjectInfo *oi, void *buffer, int max) {
void **ptr = (void **)(&buffer);

memcpy(*ptr, oi, PTP_FUJI_OBJ_INFO_VAR_START);
(*ptr) += PTP_FUJI_OBJ_INFO_VAR_START;

}
2 changes: 2 additions & 0 deletions src/ptp.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ struct PtpIpEndDataPacket {
// See https://en.wikipedia.org/wiki/USB#Device_classes
#define PTP_CLASS_ID 6

#define USB_VENDOR_CANON 0x4A9

// ISO number for PTP/IP, seems to be standard (?)
#define PTP_IP_PORT 15740

Expand Down
5 changes: 2 additions & 3 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int ptp_generic_send_data(struct PtpRuntime *r, struct PtpCommand *cmd, void *da
} else {
// Single data packet
plength = ptp_new_data_packet(r, cmd, data, length);
if (ptp_send_bulk_packets(r, plength) != plength) {
if (ptp_send_bulk_packets(r, plength) != plength + length) {
ptp_mutex_unlock(r);
return PTP_IO_ERR;
}
Expand Down Expand Up @@ -157,8 +157,7 @@ struct UintArray *ptp_dup_uint_array(struct UintArray *arr) {
return arr2;
}

// May be slightly inneficient for every frame/action
// TODO: maybe 'cache' dev type for speed
// TODO: maybe 'cache' dev type
int ptp_device_type(struct PtpRuntime *r) {
struct PtpDeviceInfo *di = r->di;
if (di == NULL) return PTP_DEV_EMPTY;
Expand Down

0 comments on commit 225f7b0

Please sign in to comment.