From 87c176b6d0c95fb274e1397da459406e3fc819bb Mon Sep 17 00:00:00 2001 From: Emmanuel Pacaud Date: Fri, 12 Jul 2024 07:14:16 +0200 Subject: [PATCH] chunkparser: allow to set string and integer features On some devices, chunk access requires a change of a local feature value. For example: ``` Expert 0 1 2 0 Expert RO ChunkScan3dCoordinateOffsetRegister -3.40282e+38 3.40282e+38 1e-6 6 Expert
0x8
ChunkComponentSelector 8 RW Chunk ChunkScan3dCoordinateSelector ChunkComponentSelector LittleEndian
``` As the Genicam tree is owned by the parser and not shared with the device, in order to access to chunk data without a device instance, we need to provide an API to set the selector feature. ``` arv_chunk_parser_set_string_feature_value (parser, "ChunkComponentSelector", "Normal", &error); normal_offset = arv_chunk_parser_get_float_value (parser, "ChunkScan3dCoordinateOffset", &error); ``` --- src/arvchunkparser.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ src/arvchunkparser.h | 10 +++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/arvchunkparser.c b/src/arvchunkparser.c index fd604af11..f63d929eb 100644 --- a/src/arvchunkparser.c +++ b/src/arvchunkparser.c @@ -228,6 +228,64 @@ arv_chunk_parser_get_float_value (ArvChunkParser *parser, ArvBuffer *buffer, con return value; } +static ArvGcNode * +arv_chunk_parser_get_feature (ArvChunkParser *parser, const char *feature) +{ + g_return_val_if_fail (ARV_IS_CHUNK_PARSER(parser), NULL); + g_return_val_if_fail (parser->priv->genicam, NULL); + + return arv_gc_get_node (parser->priv->genicam, feature); +} + +static void * +_get_feature (ArvChunkParser *parser, GType node_type, const char *feature, GError **error) +{ + void *node; + + g_return_val_if_fail (ARV_IS_CHUNK_PARSER (parser), NULL); + g_return_val_if_fail (feature != NULL, NULL); + + node = arv_chunk_parser_get_feature (parser, feature); + + if (node == NULL) { + g_set_error (error, ARV_CHUNK_PARSER_ERROR, ARV_CHUNK_PARSER_ERROR_FEATURE_NOT_FOUND, + "[%s] Not found", feature); + return NULL; + } + + if (!(G_TYPE_CHECK_INSTANCE_TYPE ((node), node_type))) { + g_set_error (error, ARV_CHUNK_PARSER_ERROR, ARV_CHUNK_PARSER_ERROR_INVALID_FEATURE_TYPE, + "[%s:%s] Not a %s", feature, G_OBJECT_TYPE_NAME (node), g_type_name (node_type)); + return NULL; + } + + return node; +} + +void +arv_chunk_parser_set_string_feature_value (ArvChunkParser *parser, + const char *feature, const char *value, + GError **error) +{ + ArvGcNode *node; + + node = _get_feature (parser, ARV_TYPE_GC_STRING, feature, error); + if (node != NULL) + arv_gc_string_set_value (ARV_GC_STRING (node), value, error); +} + +void +arv_chunk_parser_set_integer_feature_value (ArvChunkParser *parser, + const char *feature, gint64 value, + GError **error) +{ + ArvGcNode *node; + + node = _get_feature (parser, ARV_TYPE_GC_INTEGER, feature, error); + if (node != NULL) + arv_gc_integer_set_value (ARV_GC_INTEGER (node), value, error); +} + /** * arv_chunk_parser_new: * @xml: XML genicam data diff --git a/src/arvchunkparser.h b/src/arvchunkparser.h index d3ef90b03..98d492e8e 100644 --- a/src/arvchunkparser.h +++ b/src/arvchunkparser.h @@ -47,7 +47,8 @@ ARV_API GQuark arv_chunk_parser_error_quark (void); typedef enum { ARV_CHUNK_PARSER_ERROR_INVALID_FEATURE_TYPE, ARV_CHUNK_PARSER_ERROR_BUFFER_NOT_FOUND, - ARV_CHUNK_PARSER_ERROR_CHUNK_NOT_FOUND + ARV_CHUNK_PARSER_ERROR_CHUNK_NOT_FOUND, + ARV_CHUNK_PARSER_ERROR_FEATURE_NOT_FOUND } ArvChunkParserError; #define ARV_TYPE_CHUNK_PARSER (arv_chunk_parser_get_type ()) @@ -63,6 +64,13 @@ ARV_API gint64 arv_chunk_parser_get_integer_value (ArvChunkParser *parser, Arv ARV_API double arv_chunk_parser_get_float_value (ArvChunkParser *parser, ArvBuffer *buffer, const char *chunk, GError **error); +ARV_API void arv_chunk_parser_set_string_feature_value (ArvChunkParser *parser, + const char *feature, const char *value, + GError **error); +ARV_API void arv_chunk_parser_set_integer_feature_value (ArvChunkParser *parser, + const char *feature, gint64 value, + GError **error); + G_END_DECLS #endif