From 5edb8d14272ea2ecd9784a26e150a45954d67e2e Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Wed, 5 Aug 2015 19:27:19 +0200 Subject: Introduce API debugging --- base.c | 8 ++++++++ data.c | 4 ++++ env.h | 1 + events.c | 14 ++++++++++++-- private.h | 9 +++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/base.c b/base.c index 00f38d1..53ebe4d 100644 --- a/base.c +++ b/base.c @@ -288,6 +288,8 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev return PCILIB_ERROR_INVALID_REQUEST; } + ipecamera_debug(API, "ipecamera: starting"); + ctx->event_id = 0; ctx->preproc_id = 0; ctx->reported_id = 0; @@ -503,6 +505,8 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev pthread_attr_destroy(&attr); + ipecamera_debug(API, "ipecamera: started"); + return err; } @@ -523,6 +527,8 @@ int ipecamera_stop(pcilib_context_t *vctx, pcilib_event_flags_t flags) { return 0; } + ipecamera_debug(API, "ipecamera: stopping"); + if (ctx->started) { ctx->run_reader = 0; err = pthread_join(ctx->rthread, &retcode); @@ -597,6 +603,8 @@ int ipecamera_stop(pcilib_context_t *vctx, pcilib_event_flags_t flags) { ctx->buffer_pos = 0; ctx->started = 0; + ipecamera_debug(API, "ipecamera: stopped"); + return 0; } diff --git a/data.c b/data.c index dc61234..d636097 100644 --- a/data.c +++ b/data.c @@ -189,6 +189,8 @@ int ipecamera_get(pcilib_context_t *vctx, pcilib_event_id_t event_id, pcilib_eve return PCILIB_ERROR_NOTINITIALIZED; } + ipecamera_debug(API, "ipecamera: get (data)"); + buf_ptr = ipecamera_resolve_event_id(ctx, event_id); if (buf_ptr < 0) return PCILIB_ERROR_OVERWRITTEN; @@ -272,5 +274,7 @@ int ipecamera_return(pcilib_context_t *vctx, pcilib_event_id_t event_id, pcilib_ pthread_rwlock_unlock(&ctx->frame[buf_ptr].mutex); } + ipecamera_debug(API, "ipecamera: return (data)"); + return 0; } diff --git a/env.h b/env.h index 46e4459..ca8dbf7 100644 --- a/env.h +++ b/env.h @@ -7,6 +7,7 @@ typedef enum { IPECAMERA_DEBUG_RAW_PACKETS_ENV, IPECAMERA_DEBUG_HARDWARE_ENV, IPECAMERA_DEBUG_FRAME_HEADERS_ENV, + IPECAMERA_DEBUG_API_ENV, IPECAMERA_MAX_ENV } ipecamera_env_t; diff --git a/events.c b/events.c index f942f0d..d286c73 100644 --- a/events.c +++ b/events.c @@ -32,6 +32,8 @@ int ipecamera_stream(pcilib_context_t *vctx, pcilib_event_callback_t callback, v return PCILIB_ERROR_NOTINITIALIZED; } + ipecamera_debug(API, "ipecamera: start streaming"); + ctx->streaming = 1; ctx->run_streamer = 1; @@ -77,10 +79,11 @@ int ipecamera_stream(pcilib_context_t *vctx, pcilib_event_callback_t callback, v ctx->streaming = 0; + ipecamera_debug(API, "ipecamera: streaming finished"); + if (do_stop) { ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT); } - return err; } @@ -104,6 +107,8 @@ int ipecamera_next_event(pcilib_context_t *vctx, pcilib_timeout_t timeout, pcili return PCILIB_ERROR_INVALID_REQUEST; } + ipecamera_debug(API, "ipecamera: next_event"); + #ifdef IPECAMERA_ANNOUNCE_READY if (((!ctx->preproc)&&(ctx->reported_id == ctx->event_id))||((ctx->preproc)&&(ctx->reported_id == ctx->preproc_id))) { #else /* IPECAMERA_ANNOUNCE_READY */ @@ -133,6 +138,7 @@ int ipecamera_next_event(pcilib_context_t *vctx, pcilib_timeout_t timeout, pcili } if (ctx->reported_id == ctx->event_id) { + ipecamera_debug(API, "ipecamera: next_event timed out"); return PCILIB_ERROR_TIMEOUT; } @@ -149,12 +155,16 @@ retry: memcpy(info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(ipecamera_event_info_t)); else if (info_size >= sizeof(pcilib_event_info_t)) memcpy(info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(pcilib_event_info_t)); - else + else { + ipecamera_debug(API, "ipecamera: next_event returned a error"); return PCILIB_ERROR_INVALID_ARGUMENT; + } } if ((ctx->event_id - ctx->reported_id) >= ctx->buffer_size) goto retry; + ipecamera_debug(API, "ipecamera: next_event returned"); + return 0; } diff --git a/private.h b/private.h index 4bbd937..9557ad4 100644 --- a/private.h +++ b/private.h @@ -14,6 +14,7 @@ # define IPECAMERA_DEBUG_RAW_PACKETS //**< Store all raw packets read from DMA grouped in frames */ # define IPECAMERA_DEBUG_HARDWARE //**< Produce various debugging information about ipecamera operation */ # define IPECAMERA_DEBUG_FRAME_HEADERS //**< Print frame headers & footers */ +# define IPECAMERA_DEBUG_API //**< Debug IPECamera API calls */ #endif /* IPECAMERA_DEBUG */ #define IPECAMERA_BUG_MISSING_PAYLOAD //**< CMOSIS fails to provide a first payload for each frame, therefore the frame is 32 bit shorter */ @@ -108,6 +109,14 @@ # define IPECAMERA_DEBUG_FRAME_HEADERS_BUFFER(function, ...) #endif /* IPECAMERA_DEBUG_RAW_FRAMES */ +#ifdef IPECAMERA_DEBUG_API +# define IPECAMERA_DEBUG_API_MESSAGE(function, ...) if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); } +# define IPECAMERA_DEBUG_API_BUFFER(function, ...) if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); } +#else /* IPECAMERA_DEBUG_API */ +# define IPECAMERA_DEBUG_API_MESSAGE(function, ...) +# define IPECAMERA_DEBUG_API_BUFFER(function, ...) +#endif /* IPECAMERA_DEBUG_API */ + #define ipecamera_debug(function, ...) \ IPECAMERA_DEBUG_##function##_MESSAGE(IPECAMERA_DEBUG_##function, PCILIB_LOG_DEFAULT, __VA_ARGS__) -- cgit v1.2.3