Skip to content

Commit

Permalink
Delete old writing routines
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Mar 10, 2024
1 parent 9755171 commit 75a51c0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 54 deletions.
12 changes: 6 additions & 6 deletions src/camlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,17 @@ uint32_t ptp_read_uint32(void *dat);
void ptp_write_uint8(void *dat, uint8_t b);
int ptp_write_uint32(void *dat, uint32_t b);

void ptp_read_string(void *dat, char *string, int max);
int ptp_read_uint16_array(void *dat, uint16_t *buf, int max);
int ptp_write_string(void *dat, char *string);
//void ptp_read_string(void *dat, char *string, int max);
//int ptp_read_uint16_array(void *dat, uint16_t *buf, int max);
//int ptp_write_string(void *dat, char *string);
int ptp_write_unicode_string(char *dat, char *string);
int ptp_read_unicode_string(char *buffer, char *dat, int max);
int ptp_read_utf8_string(void *dat, char *string, int max);

int ptp_read_string2(uint8_t *dat, char *string, int max);
int ptp_write_string2(uint8_t *dat, char *string);
int ptp_read_string(uint8_t *dat, char *string, int max);
int ptp_write_string(uint8_t *dat, char *string);
int ptp_write_utf8_string(void *dat, char *string);
int ptp_read_uint16_array2(uint8_t *dat, uint16_t *buf, int max, int *length);
int ptp_read_uint16_array(uint8_t *dat, uint16_t *buf, int max, int *length);

inline static int ptp_write_u8 (void *buf, uint8_t out) { ((uint8_t *)buf)[0] = out; return 1; }
inline static int ptp_write_u16(void *buf, uint16_t out) { ((uint16_t *)buf)[0] = out; return 2; }
Expand Down
38 changes: 19 additions & 19 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ int ptp_parse_object_info(struct PtpRuntime *r, struct PtpObjectInfo *oi) {
uint8_t *d = ptp_get_payload(r);
memcpy(oi, d, PTP_OBJ_INFO_VAR_START);
d += PTP_OBJ_INFO_VAR_START;
d += ptp_read_string2(d, oi->filename, sizeof(oi->filename));
d += ptp_read_string2(d, oi->date_created, sizeof(oi->date_created));
d += ptp_read_string2(d, oi->date_modified, sizeof(oi->date_modified));
d += ptp_read_string2(d, oi->keywords, sizeof(oi->keywords));
d += ptp_read_string(d, oi->filename, sizeof(oi->filename));
d += ptp_read_string(d, oi->date_created, sizeof(oi->date_created));
d += ptp_read_string(d, oi->date_modified, sizeof(oi->date_modified));
d += ptp_read_string(d, oi->keywords, sizeof(oi->keywords));

return 0;
}
Expand All @@ -119,13 +119,13 @@ int ptp_pack_object_info(struct PtpRuntime *r, struct PtpObjectInfo *oi, uint8_t
// If the string is empty, don't add it to the packet
int of = PTP_OBJ_INFO_VAR_START;
if (oi->filename[0] != '\0')
of += ptp_write_string2(buf + of, oi->filename);
of += ptp_write_string(buf + of, oi->filename);
if (oi->date_created[0] != '\0')
of += ptp_write_string2(buf + of, oi->date_created);
of += ptp_write_string(buf + of, oi->date_created);
if (oi->date_modified[0] != '\0')
of += ptp_write_string2(buf + of, oi->date_modified);
of += ptp_write_string(buf + of, oi->date_modified);
if (oi->keywords[0] != '\0')
of += ptp_write_string2(buf + of, oi->keywords);
of += ptp_write_string(buf + of, oi->keywords);

// Return pointer length added
return of;
Expand Down Expand Up @@ -163,21 +163,21 @@ int ptp_parse_device_info(struct PtpRuntime *r, struct PtpDeviceInfo *di) {
e += ptp_read_u32(e, &di->vendor_ext_id);
e += ptp_read_u16(e, &di->version);

e += ptp_read_string2(e, di->extensions, sizeof(di->extensions));
e += ptp_read_string(e, di->extensions, sizeof(di->extensions));

e += ptp_read_u16(e, &di->functional_mode);

e += ptp_read_uint16_array2(e, di->ops_supported, sizeof(di->ops_supported) / 2, &di->ops_supported_length);
e += ptp_read_uint16_array2(e, di->events_supported, sizeof(di->events_supported) / 2, &di->events_supported_length);
e += ptp_read_uint16_array2(e, di->props_supported, sizeof(di->props_supported) / 2, &di->props_supported_length);
e += ptp_read_uint16_array2(e, di->capture_formats, sizeof(di->capture_formats) / 2, &di->capture_formats_length);
e += ptp_read_uint16_array2(e, di->playback_formats, sizeof(di->playback_formats) / 2, &di->playback_formats_length);
e += ptp_read_uint16_array(e, di->ops_supported, sizeof(di->ops_supported) / 2, &di->ops_supported_length);
e += ptp_read_uint16_array(e, di->events_supported, sizeof(di->events_supported) / 2, &di->events_supported_length);
e += ptp_read_uint16_array(e, di->props_supported, sizeof(di->props_supported) / 2, &di->props_supported_length);
e += ptp_read_uint16_array(e, di->capture_formats, sizeof(di->capture_formats) / 2, &di->capture_formats_length);
e += ptp_read_uint16_array(e, di->playback_formats, sizeof(di->playback_formats) / 2, &di->playback_formats_length);

e += ptp_read_string2(e, di->manufacturer, sizeof(di->manufacturer));
e += ptp_read_string2(e, di->model, sizeof(di->model));
e += ptp_read_string(e, di->manufacturer, sizeof(di->manufacturer));
e += ptp_read_string(e, di->model, sizeof(di->model));

e += ptp_read_string2(e, di->device_version, sizeof(di->device_version));
e += ptp_read_string2(e, di->serial_number, sizeof(di->serial_number));
e += ptp_read_string(e, di->device_version, sizeof(di->device_version));
e += ptp_read_string(e, di->serial_number, sizeof(di->serial_number));

r->di = di; // set last parsed di

Expand Down Expand Up @@ -517,7 +517,7 @@ int ptp_fuji_parse_object_info(struct PtpRuntime *r, struct PtpFujiObjectInfo *o
uint8_t *d = ptp_get_payload(r);
memcpy(oi, d, PTP_FUJI_OBJ_INFO_VAR_START);
d += PTP_FUJI_OBJ_INFO_VAR_START;
d += ptp_read_string2(d, oi->filename, sizeof(oi->filename));
d += ptp_read_string(d, oi->filename, sizeof(oi->filename));

/* TODO: Figure out payload later:
0D 44 00 53 00 43 00 46 00 35 00 30 00 38 00 37 00 2E 00 4A 00 50 00 47 00
Expand Down
8 changes: 4 additions & 4 deletions src/dec/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <camlib.h>

int decode_eos_evproc(FILE *f, int length, uint8_t *data) {
int of = 0;
char buffer[64];

void *d = data;
of += ptp_read_utf8_string(d + of, buffer, sizeof(buffer));

ptp_read_utf8_string(&d, buffer, sizeof(buffer));

uint32_t len = ptp_read_uint32(&d);
uint32_t len;
of += ptp_read_u32(data + of, &len);

fprintf(f, "- Command name: %s\n", buffer);
fprintf(f, "- Parameters: %u\n", len);
Expand Down
33 changes: 9 additions & 24 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int ptp_write_uint32(void *dat, uint32_t b) {
}

// Read standard UTF16 string
void ptp_read_string(void *dat, char *string, int max) {
void ptp_read_string_(void *dat, char *string, int max) {
int length = (int)ptp_read_uint8(dat);

int y = 0;
Expand All @@ -62,13 +62,13 @@ void ptp_read_string(void *dat, char *string, int max) {
}

// Read standard UTF16 string
int ptp_read_string2(uint8_t *dat, char *string, int max) {
int ptp_read_string(uint8_t *dat, char *string, int max) {
uint8_t *two = dat;
ptp_read_string(&two, string, max);
ptp_read_string_(&two, string, max);
return two - dat;
}

int ptp_read_uint16_array(void *dat, uint16_t *buf, int max) {
int ptp_read_uint16_array_(void *dat, uint16_t *buf, int max) {
int n = ptp_read_uint32(dat);

for (int i = 0; i < n; i++) {
Expand All @@ -82,13 +82,13 @@ int ptp_read_uint16_array(void *dat, uint16_t *buf, int max) {
return n;
}

int ptp_read_uint16_array2(uint8_t *dat, uint16_t *buf, int max, int *length) {
int ptp_read_uint16_array(uint8_t *dat, uint16_t *buf, int max, int *length) {
uint8_t *two = dat;
(*length) = ptp_read_uint16_array(&two, buf, max);
(*length) = ptp_read_uint16_array_(&two, buf, max);
return two - dat;
}

int ptp_write_string(void *dat, char *string) {
int ptp_write_string_(void *dat, char *string) {
int length = strlen(string);
ptp_write_uint8(dat, length);

Expand All @@ -102,8 +102,8 @@ int ptp_write_string(void *dat, char *string) {
return (length * 2) + 2;
}

int ptp_write_string2(uint8_t *dat, char *string) {
return ptp_write_string(&dat, string);
int ptp_write_string(uint8_t *dat, char *string) {
return ptp_write_string_(&dat, string);
}

int ptp_write_utf8_string(void *dat, char *string) {
Expand Down Expand Up @@ -160,21 +160,6 @@ int ptp_read_utf8_string(void *dat, char *string, int max) {
return x;
}

int ptp_read_utf8_string2(void *dat, char *string, int max) {
char *d = (char *)dat;
int x = 0;
while (d[x] != '\0') {
string[x] = d[x];
x++;
if (x > max - 1) break;
}

string[x] = '\0';
x++;

return x;
}

// PTP/IP-specific packet
int ptpip_bulk_packet(struct PtpRuntime *r, struct PtpCommand *cmd, int type) {
struct PtpIpBulkContainer bulk;
Expand Down
2 changes: 2 additions & 0 deletions test/ci.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
set -e
set -o pipefail

cp test/ci-config.mak config.mak
cd ..
Expand Down
2 changes: 2 additions & 0 deletions test/myci.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
set -e
set -o pipefail

cp test/myci-config.mak config.mak
cd ../vcam/
Expand Down
2 changes: 1 addition & 1 deletion test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int ptp_vcam_magic() {
if (rc) return rc;
}

//rc = ptp_eos_evproc_run(&r, "EnableBootDisk %d 'aasd'", 10);
rc = ptp_eos_evproc_run(&r, "EnableBootDisk %d 'aasd'", 10);

ptp_close(&r);
return 0;
Expand Down

0 comments on commit 75a51c0

Please sign in to comment.