Skip to content

Commit

Permalink
Move lua stuff to src/lua, move dec tool to camlib CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Sep 28, 2024
1 parent 035c95b commit 5b85206
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 43 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ jobs:
run: sudo apt install libusb-1.0-0-dev clang-tools

- name: Clone latest vcam
run: |
curl https://raw.githubusercontent.com/petabyt/vcam/master/install.sh | bash
run: curl https://raw.githubusercontent.com/petabyt/vcam/master/install.sh | bash

- name: Build
run: |
scan-build make libcamlib.so
make dec
run: scan-build make libcamlib.so

- name: Run main unit test
run: make test
Expand All @@ -36,5 +33,4 @@ jobs:
run: brew install libusb --force

- name: Build
run: |
make TARGET=m libcamlib.dylib
run: make TARGET=m libcamlib.dylib
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ test-ci
libusb-fake-ptp
*.so
*.d
dec
ptpdec
camlib
*.a
29 changes: 14 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CFLAGS := -Isrc/ -g -fpic -Wall -Wshadow -Wcast-qual -Wpedantic -Werror=incompatible-pointer-types -Werror=deprecated-declarations
CFLAGS += -D CAMLIB_NO_COMPAT -D VERBOSE

# Camlib needs to be compiled with these, with some exceptions:
# Camlib needs to be compiled with these files, with some exceptions:
# - log.c can be replaced with a custom logging mechanism
# - ip.c can be replaced with no_ip.c
# - libwpd.c or libusb.c can be replaced with no_usb.c
Expand All @@ -20,21 +20,24 @@ UNIX_LDFLAGS = $(shell pkg-config --libs libusb-1.0)
UNIX_LIB_FILES := $(CAMLIB_CORE) $(EXTRAS) src/libusb.o
WIN_LIB_FILES := $(CAMLIB_CORE) $(EXTRAS) src/libwpd.o

all: $(SO)

TARGET ?= l
ifeq ($(TARGET),m)
all: libcamlib.dylib
SO = libcamlib.dylib
CFLAGS += $(UNIX_CFLAGS)
libcamlib.dylib: $(UNIX_LIB_FILES)
$(CC) -shared $(UNIX_LIB_FILES) -L/usr/local/lib $(UNIX_CFLAGS) $(UNIX_LDFLAGS) -o libcamlib.dylib
endif
ifeq ($(TARGET),l)
all: libcamlib.so
SO = libcamlib.a
CFLAGS += $(UNIX_CFLAGS)
libcamlib.so: $(UNIX_LIB_FILES)
$(CC) -shared $(UNIX_LIB_FILES) -o libcamlib.so
libcamlib.a: $(UNIX_LIB_FILES)
ar rcs libcamlib.a $(UNIX_LIB_FILES)
LDFLAGS := $(UNIX_LDFLAGS)
endif
ifeq ($(TARGET),w)
all: libcamlib.dll
SO = libcamlib.dll
MINGW := x86_64-w64-mingw32
CC := $(MINGW)-gcc
CPP := $(MINGW)-c++
Expand All @@ -47,22 +50,18 @@ endif
%.o: %.c
$(CC) -MMD -c $(CFLAGS) $< -o $@

-include src/*.d lua/*.d lua/lua-cjson/*.d

DEC_FILES := src/dec/main.o src/enums.o src/enum_dump.o src/packet.o src/conv.o src/log.o
dec: $(DEC_FILES)
$(CC) $(DEC_FILES) $(CFLAGS) -o $@
-include src/*.d src/lua/*.d src/lua/lua-cjson/*.d

camlib: src/cli.o $(WIN_LIB_FILES)
$(CC) src/cli.o $(WIN_LIB_FILES) $(CFLAGS) $(LDFLAGS) -o $@
camlib: src/cli.o src/dec/main.o $(SO)
$(CC) src/cli.o src/dec/main.o $(CFLAGS) $(SO) $(LDFLAGS) -o $@

# Run this thing frequently
stringify:
python3 stringify.py

clean:
rm -rf *.o src/*.o src/dec/*.o *.out test-ci test/*.o examples/*.o examples/*.d *.exe dec *.dll *.so DUMP \
lua/*.o lua/lua-cjson/*.o src/*.d examples/*.d lua/*.d lua/lua-cjson/*.d
rm -rf *.o src/*.o src/dec/*.o *.out test-ci test/*.o examples/*.o examples/*.d *.exe camlib *.dll *.so DUMP \
src/lua/*.o src/lua/lua-cjson/*.o src/*.d examples/*.d src/lua/*.d src/lua/lua-cjson/*.d
cd examples && make clean

install: libcamlib.so
Expand Down
8 changes: 6 additions & 2 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
#include <stdlib.h>
#include <camlib.h>

int ptp_decode_output(const char *input, const char *output);

struct Options {
int do_open_sessions;
};

static int usage() {
printf(
"camlib\n"
" --dec <input_file> <output_file> Decode any PTP/USB packet dump into a readable text file\n"
" --help\n"
" --run <operation> <args>\n"
" --dont-open-session (A session is opened/closed by default)\n"
" --run ptp_hello_world 1 2 3 \"Hello, World\"\n"
);
printf("Compile date: " __DATE__ "\n");
return 0;
}

Expand Down Expand Up @@ -138,10 +142,10 @@ int main(int argc, char **argv) {
int rc = test();
printf("Return code: %d\n", rc);
return rc;
} else if (!strcmp(argv[i], "--dec")) {
return ptp_decode_output(argv[i + 1], argv[i + 2]);
}
}

return test();

return usage();
}
20 changes: 6 additions & 14 deletions src/dec/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,8 @@ int decode_eos_evproc(FILE *f, int length, uint8_t *data) {
return 0;
}

int main(int argc, char *argv[]) {
if (argc < 3) {
printf(
"Camlib PTP decoder utility - Compiled " __DATE__ "\n"
"Usage:\n"
"ptpd <dump_file> <output_file>\n");
return 0;
}

FILE *f = fopen(argv[1], "rb");
int ptp_decode_output(const char *input, const char *output) {
FILE *f = fopen(input, "rb");
if (f == NULL) {
puts("error opening file");
return 1;
Expand All @@ -64,7 +56,7 @@ int main(int argc, char *argv[]) {
fread(buffer, 1, size, f);
fclose(f);

f = fopen(argv[2], "w");
f = fopen(output, "w");
if (f == NULL) {
puts("error creating file");
return 1;
Expand All @@ -76,7 +68,7 @@ int main(int argc, char *argv[]) {
int vendor = PTP_DEV_EOS;

fprintf(f, "Generated by CamLib PTP Decoder\n");
fprintf(f, "Parsing file %s\n", argv[2]);
fprintf(f, "Parsing file %s\n", input);

long addr = 0;
while (addr < size) {
Expand Down Expand Up @@ -147,7 +139,7 @@ int main(int argc, char *argv[]) {
fprintf(f, "No params");
}
fprintf(f, "\n");
}else if (c->type == PTP_PACKET_TYPE_DATA) {
} else if (c->type == PTP_PACKET_TYPE_DATA) {
fprintf(f, "Data:\t");
int pl = c->length - 12;
for (int i = 0; i < pl; i++) {
Expand Down Expand Up @@ -179,6 +171,6 @@ int main(int argc, char *argv[]) {

fclose(f);
free(buffer);
printf("Wrote to %s\n", argv[2]);
printf("Wrote to %s\n", output);
return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int ptp_object_service_step(struct PtpRuntime *r, struct ObjectCache *oc) {
if (oc->curr >= oc->status_length) abort();
if (oc->curr == oc->status_length - 1) {
ptp_mutex_unlock(r);
return 0; // response code DONE
return 0;
}

int curr = oc->curr;
Expand Down Expand Up @@ -78,13 +78,15 @@ int ptp_object_service_step(struct PtpRuntime *r, struct ObjectCache *oc) {
oc->status[curr]->is_downloaded = 1;
oc->num_downloaded++;

oc->callback(r, &oc->status[curr]->info, oc->arg);
if (oc->callback) {
oc->callback(r, &oc->status[curr]->info, oc->arg);
}

oc->curr++;

ptp_mutex_unlock(r);

return 0;
return 1; // downloaded 1 object
}

int ptp_object_service_length(struct PtpRuntime *r, struct ObjectCache *oc) {
Expand Down

0 comments on commit 5b85206

Please sign in to comment.