diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2011-03-24 09:55:33 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2011-03-24 09:55:33 +0100 |
commit | 0e684b35d4707042bba028ce47b53d0336f662e0 (patch) | |
tree | a542c0b60b5de7b4b5ff6cf1f246183e30435208 | |
parent | 146ac46ab25b3510e34b6fdeb680d4810b48a91a (diff) | |
download | libuca-0e684b35d4707042bba028ce47b53d0336f662e0.tar.gz libuca-0e684b35d4707042bba028ce47b53d0336f662e0.tar.bz2 libuca-0e684b35d4707042bba028ce47b53d0336f662e0.tar.xz libuca-0e684b35d4707042bba028ce47b53d0336f662e0.zip |
Expose synchronicity property, add boolean unit and document the error code
format
-rw-r--r-- | src/cameras/pco.c | 2 | ||||
-rw-r--r-- | src/cameras/pf.c | 7 | ||||
-rw-r--r-- | src/grabbers/me4.c | 39 | ||||
-rw-r--r-- | src/uca-grabber.h | 2 | ||||
-rw-r--r-- | src/uca.c | 2 | ||||
-rw-r--r-- | src/uca.h | 33 | ||||
-rw-r--r-- | test/grab.c | 3 |
7 files changed, 66 insertions, 22 deletions
diff --git a/src/cameras/pco.c b/src/cameras/pco.c index 4acbf17..bd8714c 100644 --- a/src/cameras/pco.c +++ b/src/cameras/pco.c @@ -252,7 +252,7 @@ uint32_t uca_pco_init(struct uca_camera **cam, struct uca_grabber *grabber) struct uca_camera *uca = uca_cam_new(); uca->user = pco; uca->grabber = grabber; - uca->grabber->asynchronous = true; + uca->grabber->synchronous = false; /* Camera found, set function pointers... */ uca->destroy = &uca_pco_destroy; diff --git a/src/cameras/pf.c b/src/cameras/pf.c index 5c35b70..86fe5e6 100644 --- a/src/cameras/pf.c +++ b/src/cameras/pf.c @@ -57,7 +57,10 @@ static uint32_t uca_pf_set_property(struct uca_camera *cam, enum uca_property_id int err = UCA_NO_ERROR; /* We try to set the property on the grabber. If it returns "invalid", we - * also try it via the PF SDK. Else, there was a more serious error. */ + * also try it via the PF SDK. Else, there was a more serious error. + * + * FIXME: This is actually not that good for cases where only the grabber + * should set a certain property and the camera itself is not able to do so. */ err = grabber->set_property(grabber, property, data); if (((err & UCA_ERR_MASK_CODE) == UCA_ERR_INVALID) || (err == UCA_NO_ERROR)) err = UCA_ERR_CAMERA | UCA_ERR_PROP; @@ -208,7 +211,7 @@ uint32_t uca_pf_init(struct uca_camera **cam, struct uca_grabber *grabber) struct uca_camera *uca = uca_cam_new(); uca->grabber = grabber; - uca->grabber->asynchronous = true; + uca->grabber->synchronous = false; /* Camera found, set function pointers... */ uca->destroy = &uca_pf_destroy; diff --git a/src/grabbers/me4.c b/src/grabbers/me4.c index d1667ff..ba2c881 100644 --- a/src/grabbers/me4.c +++ b/src/grabbers/me4.c @@ -73,20 +73,27 @@ static struct uca_sisofg_map_t *uca_me4_find_property(enum uca_grabber_constants uint32_t uca_me4_set_property(struct uca_grabber *grabber, int32_t property, void *data) { - uint32_t err = UCA_ERR_GRABBER | UCA_ERR_PROP; - struct uca_sisofg_map_t *fg_prop = uca_me4_find_property(property); - if (fg_prop == NULL) - return err | UCA_ERR_INVALID; - + /* Handle all properties not related specifically to the me4 */ + union uca_value *v = (union uca_value *) data; switch (property) { case UCA_PROP_GRAB_TIMEOUT: - ((struct fg_apc_data *) grabber->user)->timeout = *((uint32_t *) data); + ((struct fg_apc_data *) grabber->user)->timeout = v->u32; break; + case UCA_PROP_GRAB_SYNCHRONOUS: + grabber->synchronous = v->u32 != 0; + return UCA_NO_ERROR; + default: break; } + /* Try to find a matching me4 property */ + uint32_t err = UCA_ERR_GRABBER | UCA_ERR_PROP; + struct uca_sisofg_map_t *fg_prop = uca_me4_find_property(property); + if (fg_prop == NULL) + return err | UCA_ERR_INVALID; + if (fg_prop->interpret_data) { /* Data is not a value but a SiSo specific constant that we need to * translate to Silicon Software speak. Therefore, we try to find it in @@ -102,8 +109,17 @@ uint32_t uca_me4_set_property(struct uca_grabber *grabber, int32_t property, voi UCA_NO_ERROR : err | UCA_ERR_INVALID; } -uint32_t uca_me4_get_property(struct uca_grabber *grabber, enum uca_grabber_constants property, void *data) +uint32_t uca_me4_get_property(struct uca_grabber *grabber, int32_t property, void *data) { + switch (property) { + case UCA_PROP_GRAB_SYNCHRONOUS: + *((uint32_t *) data) = grabber->synchronous ? 1 : 0; + return UCA_NO_ERROR; + + default: + break; + } + uint32_t err = UCA_ERR_GRABBER | UCA_ERR_PROP; struct uca_sisofg_map_t *fg_prop = uca_me4_find_property(property); if (fg_prop == NULL) @@ -139,9 +155,8 @@ uint32_t uca_me4_acquire(struct uca_grabber *grabber, int32_t n_frames) if (GET_MEM(grabber) == NULL) return UCA_ERR_GRABBER | UCA_ERR_NO_MEMORY; - int flag = grabber->asynchronous ? ACQ_STANDARD : ACQ_BLOCK; n_frames = n_frames < 0 ? GRAB_INFINITE : n_frames; - if (Fg_AcquireEx(GET_FG(grabber), 0, n_frames, flag, GET_MEM(grabber)) == FG_OK) + if (Fg_AcquireEx(GET_FG(grabber), 0, n_frames, ACQ_STANDARD, GET_MEM(grabber)) == FG_OK) return UCA_NO_ERROR; return UCA_ERR_GRABBER | UCA_ERR_ACQUIRE; @@ -160,10 +175,10 @@ uint32_t uca_me4_grab(struct uca_grabber *grabber, void **buffer, uint64_t *fram static frameindex_t last_frame = 0; struct fg_apc_data *me4 = (struct fg_apc_data *) grabber->user; - if (grabber->asynchronous) - last_frame = Fg_getLastPicNumberEx(me4->fg, PORT_A, me4->mem); - else + if (grabber->synchronous) last_frame = Fg_getLastPicNumberBlockingEx(me4->fg, last_frame+1, PORT_A, me4->timeout, me4->mem); + else + last_frame = Fg_getLastPicNumberEx(me4->fg, PORT_A, me4->mem); if (last_frame <= 0) return UCA_ERR_GRABBER | UCA_ERR_FRAME_TRANSFER; diff --git a/src/uca-grabber.h b/src/uca-grabber.h index 7b3185b..f754a81 100644 --- a/src/uca-grabber.h +++ b/src/uca-grabber.h @@ -131,7 +131,7 @@ typedef struct uca_grabber { /* Private */ uca_cam_grab_callback callback; - bool asynchronous; + bool synchronous; void *user; } uca_grabber_t; @@ -40,6 +40,7 @@ const char *uca_unit_map[] = { "rows", "fps", "°C", + "[0/1]", "" }; @@ -78,6 +79,7 @@ static struct uca_property property_map[UCA_PROP_LAST+1] = { { "Gain.ADC.Max", uca_na, uca_uint32t, uca_read }, { "Gain.ADC.Step", uca_na, uca_uint32t, uca_read }, { "Grabber.Timeout", uca_s, uca_uint32t, uca_readwrite }, + { "Grabber.Synchronous", uca_bool, uca_uint32t, uca_readwrite }, { "Mode.Timestamp", uca_na, uca_uint32t, uca_readwrite }, { "Mode.Scan", uca_na, uca_uint32t, uca_readwrite }, { "Interlace.Samplerate", uca_na, uca_uint32t, uca_readwrite }, @@ -1,6 +1,8 @@ #ifndef __UNIFIED_CAMERA_ACCESS_H #define __UNIFIED_CAMERA_ACCESS_H +#include <stdint.h> + #ifdef __cplusplus extern "C" { #endif @@ -103,6 +105,7 @@ enum uca_property_ids { /* grabber specific */ UCA_PROP_GRAB_TIMEOUT, + UCA_PROP_GRAB_SYNCHRONOUS, /* pco.edge specific */ UCA_PROP_TIMESTAMP_MODE, @@ -170,6 +173,7 @@ typedef struct uca_property { uca_rows, /**< number of rows */ uca_fps, /**< frames per second */ uca_dc, /**< degree celsius */ + uca_bool, /**< 1 or 0 for true and false */ uca_na /**< no unit available (for example modes) */ } unit; @@ -197,15 +201,32 @@ typedef struct uca_property { } access; } uca_property_t; +union uca_value { + uint32_t u32; + uint8_t u8; + char *string; +}; + extern const char *uca_unit_map[]; /**< maps unit numbers to corresponding strings */ -/* - * 16 bits error code - * 4 bits error source - * 4 bits error class - * 4 bits reserved - * 4 bits error level +/** + * An error code is a 32 bit integer with the following format (x:y means x bits + * for purpose y): + * + * [ 31 (MSB) ... ... 0 (LSB) ] + * [ 4:lvl | 4:rsv | 4:class | 4:source | 16:code ] + * + * where + * + * - lvl describes severity such as warning or failure, + * - rsv is reserved, + * - class describes the general class of the error, + * - source describes where the error occured and + * - code is the actual error condition + * + * UCA_ERR_MASK_*s can be used to mask the desired field of the error code. + * */ #define UCA_NO_ERROR 0x00000000 diff --git a/test/grab.c b/test/grab.c index 8c5e78c..c8a6153 100644 --- a/test/grab.c +++ b/test/grab.c @@ -24,6 +24,9 @@ int main(int argc, char *argv[]) val = 0; handle_error(cam->set_property(cam, UCA_PROP_DELAY, &val)); + val = 1; + handle_error(cam->set_property(cam, UCA_PROP_GRAB_SYNCHRONOUS, &val)); + uint32_t width, height, bits; handle_error(cam->get_property(cam, UCA_PROP_WIDTH, &width, 0)); handle_error(cam->get_property(cam, UCA_PROP_HEIGHT, &height, 0)); |