From: Antonio Ospite Date: Sat, 9 Jan 2016 18:20:11 +0000 (+0100) Subject: visomat-data-downloader: add some debug facilities X-Git-Url: https://git.ao2.it/visomat-utils.git/commitdiff_plain/49d57f3f34f76b24d5bba6adae90d04c8e8ed406?ds=sidebyside visomat-data-downloader: add some debug facilities --- diff --git a/src/Makefile b/src/Makefile index c39f955..4ac4019 100644 --- a/src/Makefile +++ b/src/Makefile @@ -32,6 +32,10 @@ ifneq ($(CC),clang) CFLAGS += -Wunsafe-loop-optimizations -Wunused-but-set-variable endif +ifeq ($(DEBUG),1) + CFLAGS += -DDEBUG +endif + CFLAGS += $(shell pkg-config --cflags libusb-1.0) LDLIBS := $(shell pkg-config --libs libusb-1.0) diff --git a/src/visomat-data-downloader.c b/src/visomat-data-downloader.c index a53f72c..69f62d6 100644 --- a/src/visomat-data-downloader.c +++ b/src/visomat-data-downloader.c @@ -26,6 +26,31 @@ #include #include +#ifdef DEBUG +#define debug(...) fprintf(stderr, __VA_ARGS__) +static void debug_dump_buffer(const char *filename, uint8_t *buffer, unsigned int len) +{ + FILE *dump_file; + + dump_file = fopen(filename, "wb"); + if (dump_file == NULL) { + fprintf(stderr, "Failed to open %s: %s\n", filename, strerror(errno)); + return; + } + + fwrite(buffer, 1, len, dump_file); + fclose(dump_file); +} +#else +#define debug(...) do {} while(0) +static void debug_dump_buffer(const char *filename, uint8_t *buffer, unsigned int len) +{ + (void)filename; + (void)buffer; + (void)len; +} +#endif + #define VISOMAT_DEVICE_VID 0x1247 #define VISOMAT_DEVICE_PID 0x00f8 #define VISOMAT_CONFIGURATION 1 @@ -300,6 +325,9 @@ static int visomat_dump_eeprom(visomat_device *dev, unsigned int user_mask) if (ret < 0) return ret; + debug("buffer len: %d\n", ret); + debug_dump_buffer("eeprom.bin", buffer, sizeof(buffer)); + ret = decode_eeprom(buffer, ret, user_mask); if (ret < 0) return ret;