summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--data.c10
-rw-r--r--private.h34
-rw-r--r--reader.c36
3 files changed, 39 insertions, 41 deletions
diff --git a/data.c b/data.c
index d1b890c..50d431a 100644
--- a/data.c
+++ b/data.c
@@ -61,15 +61,7 @@ inline static int ipecamera_decode_frame(ipecamera_t *ctx, pcilib_event_id_t eve
printf("%lu\n", ctx->raw_size);*/
res = ufo_decoder_decode_frame(ctx->ipedec, ctx->buffer + buf_ptr * ctx->padded_size, ctx->frame[buf_ptr].event.raw_size, pixels, &ctx->frame[buf_ptr].event.meta);
if (!res) {
-#ifdef IPECAMERA_DEBUG_BROKEN_FRAMES
- char name[128];
- sprintf(name, "%s/broken.%4lu", IPECAMERA_DEBUG_BROKEN_FRAMES, ctx->event_id);
- FILE *f = fopen(name, "w");
- if (f) {
- fwrite(ctx->buffer + buf_ptr * ctx->padded_size, ctx->raw_size, 1, f);
- fclose(f);
- }
-#endif /* IPECAMERA_DEBUG_BROKEN_FRAMES */
+ ipecamera_debug_buffer(BROKEN_FRAMES, ctx->frame[buf_ptr].event.raw_size, ctx->buffer + buf_ptr * ctx->padded_size, PCILIB_DEBUG_BUFFER_MKDIR, "broken_frame.%4lu", ctx->event_id);
err = PCILIB_ERROR_FAILED;
ctx->frame[buf_ptr].event.image_broken = err;
goto ready;
diff --git a/private.h b/private.h
index 4258410..2d3fa86 100644
--- a/private.h
+++ b/private.h
@@ -3,17 +3,22 @@
#include <pthread.h>
#include <pcilib/model.h>
+#include <pcilib/debug.h>
#include "ipecamera.h"
//#define IPECAMERA_BUG_MISSING_PAYLOAD //**< CMOSIS fails to provide a first payload for each frame, therefore the frame is 32 bit shorter */
#define IPECAMERA_BUG_MULTIFRAME_PACKETS //**< This is by design, start of packet comes directly after the end of last one in streaming mode */
//#define IPECAMERA_BUG_INCOMPLETE_PACKETS //**< Support incomplete packets, i.e. check for frame magic even if full frame size is not reached yet (slow) */
#define IPECAMERA_BUG_POSTPONED_READ
-#define IPECAMERA_DEBUG_BROKEN_FRAMES "/mnt/frames"
-//#define IPECAMERA_DEBUG_RAW_PACKETS "/mnt/frames"
-
//#define IPECAMERA_ANNOUNCE_READY //**< announce new event only after the reconstruction is done */
+#define IPECAMERA_DEBUG
+
+#ifdef IPECAMERA_DEBUG
+# define IPECAMERA_DEBUG_BROKEN_FRAMES
+# define IPECAMERA_DEBUG_RAW_PACKETS
+#endif /* IPECAMERA_DEBUG */
+
#define IPECAMERA_REGISTER_TIMEOUT 10000 //**< us */
#define IPECAMERA_DMA_TIMEOUT 50000 //**< us */
@@ -50,6 +55,29 @@
#define IPECAMERA_MODE_11_BIT_ADC 1
#define IPECAMERA_MODE_10_BIT_ADC 0
+#ifdef IPECAMERA_DEBUG_BROKEN_FRAMES
+# define IPECAMERA_DEBUG_BROKEN_FRAMES_MESSAGE(function, ...) pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__)
+# define IPECAMERA_DEBUG_BROKEN_FRAMES_BUFFER(function, ...) pcilib_debug_data_buffer (#function, __VA_ARGS__)
+#else /* IPECAMERA_DEBUG_BROKEN_FRAMES */
+# define IPECAMERA_DEBUG_BROKEN_FRAMES_MESSAGE(function, ...)
+# define IPECAMERA_DEBUG_BROKEN_FRAMES_BUFFER(function, ...)
+#endif /* IPECAMERA_DEBUG_BROKEN_FRAMES */
+
+#ifdef IPECAMERA_IPECAMERA_DEBUG_RAW_PACKETS
+# define IPECAMERA_DEBUG_RAW_PACKETS_MESSAGE(function, ...) pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__)
+# define IPECAMERA_DEBUG_RAW_PACKETS_BUFFER(function, ...) pcilib_debug_data_buffer (#function, __VA_ARGS__)
+#else /* IPECAMERA_IPECAMERA_DEBUG_RAW_PACKETS */
+# define IPECAMERA_DEBUG_RAW_PACKETS_MESSAGE(function, ...)
+# define IPECAMERA_DEBUG_RAW_PACKETS_BUFFER(function, ...)
+#endif /* IPECAMERA_IPECAMERA_DEBUG_RAW_PACKETS */
+
+#define ipecamera_debug(function, ...) \
+ IPECAMERA_DEBUG_##function##_MESSAGE(IPECAMERA_DEBUG_##function, __VA_ARGS__)
+
+#define ipecamera_debug_buffer(function, ...) \
+ IPECAMERA_DEBUG_##function##_BUFFER(IPECAMERA_DEBUG_##function, __VA_ARGS__)
+
+
typedef uint32_t ipecamera_payload_t;
typedef struct {
diff --git a/reader.c b/reader.c
index e9eda95..533a5a2 100644
--- a/reader.c
+++ b/reader.c
@@ -82,6 +82,8 @@ static uint32_t frame_magic[5] = { 0x51111111, 0x52222222, 0x53333333, 0x5444444
static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t bufsize, void *buf) {
int res;
int eof = 0;
+
+ static unsigned long packet_id = 0;
#ifdef IPECAMERA_BUG_MULTIFRAME_PACKETS
size_t real_size;
@@ -94,22 +96,9 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
static pcilib_event_id_t invalid_frame_id = (pcilib_event_id_t)-1;
#endif
-#ifdef IPECAMERA_DEBUG_RAW_PACKETS
- char fname[128];
- {
- static unsigned long packet_id = 0;
- sprintf(fname,"%s/frame%4lu", IPECAMERA_DEBUG_RAW_PACKETS, ctx->event_id);
- mkdir(fname, 0755);
- sprintf(fname,"%s/frame%4lu/frame%9lu", IPECAMERA_DEBUG_RAW_PACKETS, ctx->event_id, packet_id);
- FILE *f = fopen(fname, "w");
- if (f) {
- fwrite(buf, 1, bufsize, f);
- fclose(f);
- }
- sprintf(fname,"%s/frame%4lu/frame%9lu.invalid", IPECAMERA_DEBUG_RAW_PACKETS, ctx->event_id, packet_id++);
- }
-#endif /* IPECAMERA_DEBUG_RAW_PACKETS */
-
+ packet_id++;
+ ipecamera_debug_buffer(RAW_PACKETS, bufsize, buf, PCILIB_DEBUG_BUFFER_MKDIR, "frame%4lu/frame%9lu", ctx->event_id, packet_id);
+
if (!ctx->cur_size) {
#if defined(IPECAMERA_BUG_INCOMPLETE_PACKETS)||defined(IPECAMERA_BUG_MULTIFRAME_PACKETS)
size_t startpos;
@@ -118,10 +107,7 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
}
if ((startpos + sizeof(frame_magic)) > bufsize) {
-#ifdef IPECAMERA_DEBUG_RAW_PACKETS
- FILE *f = fopen(fname, "w");
- if (f) fclose(f);
-#endif /* IPECAMERA_DEBUG_RAW_PACKETS */
+ ipecamera_debug_buffer(RAW_PACKETS, bufsize, NULL, 0, "frame%4lu/frame%9lu.invalid", ctx->event_id, packet_id);
if (invalid_frame_id != ctx->event_id) {
// pcilib_warning("No frame magic in DMA packet of %u bytes, current event %lu", bufsize, ctx->event_id);
@@ -179,15 +165,7 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
// just rip of padding
bufsize = ctx->roi_raw_size - ctx->cur_size;
-
-#ifdef IPECAMERA_DEBUG_RAW_PACKETS
- sprintf(fname + strlen(fname) - 8, ".partial");
- FILE *f = fopen(fname, "w");
- if (f) {
- fwrite(buf, 1, bufsize, f);
- fclose(f);
- }
-#endif /* IPECAMERA_DEBUG_RAW_PACKETS */
+ ipecamera_debug_buffer(RAW_PACKETS, bufsize, buf, 0, "frame%4lu/frame%9lu.partial", ctx->event_id, packet_id);
}
#endif /* IPECAMERA_BUG_MULTIFRAME_PACKETS */