Skip to content

Commit a33dcaf

Browse files
committed
chunkparser: allow to set string and integer features
On some devices, chunk access requires a change of a local feature value. For example: ``` <Enumeration NameSpace="Standard" Name="ChunkComponentSelector"> <Visibility>Expert</Visibility> <EnumEntry NameSpace="Standard" Name="Range"> <Value>0</Value> </EnumEntry> <EnumEntry NameSpace="Standard" Name="Normal"> <Value>1</Value> </EnumEntry> <EnumEntry NameSpace="Standard" Name="Texture"> <Value>2</Value> </EnumEntry> <Value>0</Value> </Enumeration> <Float NameSpace="Standard" Name="ChunkScan3dCoordinateOffset"> <Visibility>Expert</Visibility> <ImposedAccessMode>RO</ImposedAccessMode> <pValue>ChunkScan3dCoordinateOffsetRegister</pValue> <Min>-3.40282e+38</Min> <Max>3.40282e+38</Max> <Inc>1e-6</Inc> <DisplayPrecision>6</DisplayPrecision> </Float> <FloatReg NameSpace="Custom" Name="ChunkScan3dCoordinateOffsetRegister"> <Visibility>Expert</Visibility> <Address>0x8</Address> <pIndex Offset="16">ChunkComponentSelector</pIndex> <Length>8</Length> <AccessMode>RW</AccessMode> <pPort>Chunk</pPort> <pInvalidator>ChunkScan3dCoordinateSelector</pInvalidator> <pInvalidator>ChunkComponentSelector</pInvalidator> <Endianess>LittleEndian</Endianess> </FloatReg> ``` 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); ```
1 parent 58d69bd commit a33dcaf

2 files changed

Lines changed: 95 additions & 1 deletion

File tree

src/arvchunkparser.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,92 @@ arv_chunk_parser_get_float_value (ArvChunkParser *parser, ArvBuffer *buffer, con
228228
return value;
229229
}
230230

231+
static ArvGcNode *
232+
arv_chunk_parser_get_feature (ArvChunkParser *parser, const char *feature)
233+
{
234+
g_return_val_if_fail (ARV_IS_CHUNK_PARSER(parser), NULL);
235+
g_return_val_if_fail (parser->priv->genicam, NULL);
236+
237+
return arv_gc_get_node (parser->priv->genicam, feature);
238+
}
239+
240+
static void *
241+
_get_feature (ArvChunkParser *parser, GType node_type, const char *feature, GError **error)
242+
{
243+
void *node;
244+
245+
g_return_val_if_fail (ARV_IS_CHUNK_PARSER (parser), NULL);
246+
g_return_val_if_fail (feature != NULL, NULL);
247+
248+
node = arv_chunk_parser_get_feature (parser, feature);
249+
250+
if (node == NULL) {
251+
g_set_error (error, ARV_CHUNK_PARSER_ERROR, ARV_CHUNK_PARSER_ERROR_FEATURE_NOT_FOUND,
252+
"[%s] Not found", feature);
253+
return NULL;
254+
}
255+
256+
if (!(G_TYPE_CHECK_INSTANCE_TYPE ((node), node_type))) {
257+
g_set_error (error, ARV_CHUNK_PARSER_ERROR, ARV_CHUNK_PARSER_ERROR_INVALID_FEATURE_TYPE,
258+
"[%s:%s] Not a %s", feature, G_OBJECT_TYPE_NAME (node), g_type_name (node_type));
259+
return NULL;
260+
}
261+
262+
return node;
263+
}
264+
265+
/**
266+
* arv_chunk_parser_set_string_feature_value:
267+
* @parser: a #ArvChunkParser
268+
* @feature: feature name
269+
* @value: feature value
270+
* @error: a #GError placeholder, %NULL to ignore
271+
*
272+
* Set a feature value using a string. The main use for this function is to set a Selector feature, in order to access
273+
* the corresponding chunk value. As the Genicam data owned by the parser is not shared with the device, this function
274+
* is limited to features that don't trigger device access.
275+
*
276+
* Since: 0.8.35
277+
*/
278+
279+
void
280+
arv_chunk_parser_set_string_feature_value (ArvChunkParser *parser,
281+
const char *feature, const char *value,
282+
GError **error)
283+
{
284+
ArvGcNode *node;
285+
286+
node = _get_feature (parser, ARV_TYPE_GC_STRING, feature, error);
287+
if (node != NULL)
288+
arv_gc_string_set_value (ARV_GC_STRING (node), value, error);
289+
}
290+
291+
/**
292+
* arv_chunk_parser_set_integer_feature_value:
293+
* @parser: a #ArvChunkParser
294+
* @feature: feature name
295+
* @value: feature value
296+
* @error: a #GError placeholder, %NULL to ignore
297+
*
298+
* Set a feature value using a 64 bit value. The main use for this function is to set a Selector feature, in order to
299+
* access the corresponding chunk value. As the Genicam data owned by the parser is not shared with the device, this
300+
* function is limited to features that don't trigger device access.
301+
*
302+
* Since: 0.8.35
303+
*/
304+
305+
void
306+
arv_chunk_parser_set_integer_feature_value (ArvChunkParser *parser,
307+
const char *feature, gint64 value,
308+
GError **error)
309+
{
310+
ArvGcNode *node;
311+
312+
node = _get_feature (parser, ARV_TYPE_GC_INTEGER, feature, error);
313+
if (node != NULL)
314+
arv_gc_integer_set_value (ARV_GC_INTEGER (node), value, error);
315+
}
316+
231317
/**
232318
* arv_chunk_parser_new:
233319
* @xml: XML genicam data

src/arvchunkparser.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ ARV_API GQuark arv_chunk_parser_error_quark (void);
4747
typedef enum {
4848
ARV_CHUNK_PARSER_ERROR_INVALID_FEATURE_TYPE,
4949
ARV_CHUNK_PARSER_ERROR_BUFFER_NOT_FOUND,
50-
ARV_CHUNK_PARSER_ERROR_CHUNK_NOT_FOUND
50+
ARV_CHUNK_PARSER_ERROR_CHUNK_NOT_FOUND,
51+
ARV_CHUNK_PARSER_ERROR_FEATURE_NOT_FOUND
5152
} ArvChunkParserError;
5253

5354
#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
6364
ARV_API double arv_chunk_parser_get_float_value (ArvChunkParser *parser, ArvBuffer *buffer,
6465
const char *chunk, GError **error);
6566

67+
ARV_API void arv_chunk_parser_set_string_feature_value (ArvChunkParser *parser,
68+
const char *feature, const char *value,
69+
GError **error);
70+
ARV_API void arv_chunk_parser_set_integer_feature_value (ArvChunkParser *parser,
71+
const char *feature, gint64 value,
72+
GError **error);
73+
6674
G_END_DECLS
6775

6876
#endif

0 commit comments

Comments
 (0)