Skip to content

Commit

Permalink
Make all uint packet functions static
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Mar 24, 2024
1 parent d576994 commit f93b7a0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/camlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ int ptp_buffer_resize(struct PtpRuntime *r, size_t size);
// Packet builder/unpacker helper functions. These accept a pointer-to-pointer
// and will advance the dereferenced pointer by amount read. Mostly for internal use.
// These functions accept (void *), but really wants (void **), but (void **) would require casting in every call
uint8_t ptp_read_uint8(void *dat);
uint16_t ptp_read_uint16(void *dat);
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);
//uint8_t ptp_read_uint8(void *dat);
//uint16_t ptp_read_uint16(void *dat);
//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);

int ptp_write_unicode_string(char *dat, char *string);
int ptp_read_unicode_string(char *buffer, char *dat, int max);
Expand Down
2 changes: 1 addition & 1 deletion src/cl_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ int ptp_eos_get_shutter(int data, int dir);
int ptp_eos_get_iso(int data, int dir);
int ptp_eos_get_aperture(int data, int dir);
int ptp_eos_get_white_balance(int data, int dir);
int ptp_eos_get_imgformat_value(int data[5]);
int ptp_eos_get_imgformat_value(uint32_t data[5]);

void *ptp_pack_chdk_upload_file(struct PtpRuntime *r, char *in, char *out, int *length);

Expand Down
4 changes: 2 additions & 2 deletions src/conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ int ptp_eos_get_aperture(int data, int dir) {
// Converts to camlib wrapper types (enum ImageFormats)
struct CanonImageFormats {
int value;
int data[9];
uint32_t data[9];
}canon_imgformats[] = {
{IMG_FORMAT_RAW, {1, 16, 6, 0, 4}}, // RAW
{IMG_FORMAT_STD, {1, 16, 1, 0, 2}}, // STD
{IMG_FORMAT_HIGH, {1, 16, 1, 0, 3}}, // HIGH
{IMG_FORMAT_RAW_JPEG, {2, 16, 6, 0, 4, 16, 1, 0, 3}}, // RAW + HIGH JPG
};

int ptp_eos_get_imgformat_value(int data[5]) {
int ptp_eos_get_imgformat_value(uint32_t data[5]) {
for (int i = 0; i < (int)(sizeof(canon_imgformats) / sizeof(struct CanonImageFormats)); i++) {
if (!memcmp(canon_imgformats[i].data, data, sizeof(int) * 5)) {
return canon_imgformats[i].value;
Expand Down
18 changes: 9 additions & 9 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ void *ptp_pack_chdk_upload_file(struct PtpRuntime *r, char *in, char *out, int *

int size_all = 4 + strlen(out) + 1 + file_size;
*length = size_all;
char *data = malloc(size_all);
uint8_t *data = malloc(size_all);
if (data == NULL) return NULL;

void *d_ptr = (void *)data;
ptp_write_uint32(&d_ptr, strlen(out) + 1);
ptp_write_utf8_string(&d_ptr, out);
int of = 0;
of += ptp_write_u32(data + of, strlen(out) + 1);
of += ptp_write_utf8_string(data + of, out);

fread(d_ptr, 1, file_size, f);
fread(data + of, 1, file_size, f);

return data;
}
Expand Down Expand Up @@ -388,7 +388,7 @@ int ptp_storage_info_json(struct PtpStorageInfo *so, char *buffer, int max) {
return len;
}

int ptp_eos_prop_next(void *d, struct PtpGenericEvent *p) {
int ptp_eos_prop_next(uint8_t *d, struct PtpGenericEvent *p) {
uint32_t code, value, tmp;

int of = 0;
Expand Down Expand Up @@ -417,7 +417,7 @@ int ptp_eos_prop_next(void *d, struct PtpGenericEvent *p) {
name = "battery";
break;
case PTP_PC_EOS_ImageFormat: {
int data[5] = {value};
uint32_t data[5] = {value};
of += ptp_read_u32(d + of, &data[1]);
of += ptp_read_u32(d + of, &data[2]);
of += ptp_read_u32(d + of, &data[3]);
Expand Down Expand Up @@ -519,7 +519,7 @@ int ptp_eos_events(struct PtpRuntime *r, struct PtpGenericEvent **p) {
struct PtpGenericEvent *cur = &p_base[i];
memset(cur, 0, sizeof(struct PtpGenericEvent));

void *d = dp;
uint8_t *d = dp;

uint32_t size, type;
d += ptp_read_u32(d, &size);
Expand Down Expand Up @@ -616,7 +616,7 @@ int ptp_fuji_get_init_info(struct PtpRuntime *r, struct PtpFujiInitResp *resp) {
d += ptp_read_u32(d, &resp->x3);
d += ptp_read_u32(d, &resp->x4);

ptp_read_unicode_string(resp->cam_name, (char *)(dat), sizeof(resp->cam_name));
ptp_read_unicode_string(resp->cam_name, (char *)d, sizeof(resp->cam_name));

return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@
#include <ptp.h>
#include <camlib.h>

uint8_t ptp_read_uint8(void *dat) {
static uint8_t ptp_read_uint8(void *dat) {
uint8_t **p = (uint8_t **)dat;
uint8_t x = (**p);
(*p)++;
return x;
}

uint16_t ptp_read_uint16(void *dat) {
static uint16_t ptp_read_uint16(void *dat) {
uint16_t **p = (uint16_t **)dat;
uint16_t x = (**p);
(*p)++;
return x;
}

uint32_t ptp_read_uint32(void *dat) {
static uint32_t ptp_read_uint32(void *dat) {
uint32_t **p = (uint32_t **)dat;
uint32_t x = (**p);
(*p)++;
return x;
}

void ptp_write_uint8(void *dat, uint8_t b) {
static void ptp_write_uint8(void *dat, uint8_t b) {
uint8_t **ptr = (uint8_t **)dat;
(**ptr) = b;
(*ptr)++;
}

int ptp_write_uint32(void *dat, uint32_t b) {
static int ptp_write_uint32(void *dat, uint32_t b) {
uint32_t **ptr = (uint32_t **)dat;
(**ptr) = b;
(*ptr)++;
Expand Down

0 comments on commit f93b7a0

Please sign in to comment.