Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added get/set register node value #833

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/arvcamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <arvgcfloat.h>
#include <arvgcenumeration.h>
#include <arvgcenumentry.h>
#include <arvgcregister.h>
#include <arvgcstring.h>
#include <arvbuffer.h>
#include <arvgc.h>
Expand Down Expand Up @@ -2816,6 +2817,69 @@ arv_camera_get_float_increment (ArvCamera *camera, const char *feature, GError *
return arv_device_get_float_feature_increment (priv->device, feature, error);
}

/**
* arv_camera_set_register:
* @camera: a #ArvCamera
* @feature: feature name
* @value: new feature value
* @error: a #GError placeholder, %NULL to ignore
*
* Set a register feature value.
*
* Since:
*/

void
arv_camera_set_register (ArvCamera *camera, const char *feature, guint64 length, void* value, GError **error)
{
ArvCameraPrivate *priv = arv_camera_get_instance_private (camera);

g_return_if_fail (ARV_IS_CAMERA (camera));

arv_device_set_register_feature_value (priv->device, feature, length, value, error);
}

/**
* arv_camera_get_register:
* @camera: a #ArvCamera
* @feature: feature name
* @value: (out): the register feature value
* @error: a #GError placeholder, %NULL to ignore
*
* Since:
*/

void
arv_camera_get_register (ArvCamera *camera, const char *feature,guint64 length, void* value, GError **error)
{
ArvCameraPrivate *priv = arv_camera_get_instance_private (camera);

g_return_if_fail (ARV_IS_CAMERA (camera));

arv_device_get_register_feature_value (priv->device, feature, length, value, error);
}

/**
* arv_camera_get_register_length:
* @camera: a #ArvCamera
* @feature: feature name
* @error: a #GError placeholder
*
* Returns: the length of register value, 0 if not available
*
* Since:
*/

guint64
arv_camera_get_register_length (ArvCamera *camera, const char *feature, GError **error)
{
ArvCameraPrivate *priv = arv_camera_get_instance_private (camera);

g_return_val_if_fail (ARV_IS_CAMERA (camera), 0);

return arv_device_get_register_feature_length (priv->device, feature, error);
}

Comment on lines +2853 to +2882
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simplify the API here, and make get_register allocate a buffer and return the buffer length, and suppress get_register_length.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And rename get_register to dup_register, which makes clear the data must be freed after use.

/**
* arv_camera_dup_available_enumerations:
* @camera: a #ArvCamera
Expand Down
4 changes: 4 additions & 0 deletions src/arvcamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ ARV_API double arv_camera_get_float (ArvCamera *camera, const char *feature,
ARV_API void arv_camera_get_float_bounds (ArvCamera *camera, const char *feature, double *min, double *max, GError **error);
ARV_API double arv_camera_get_float_increment (ArvCamera *camera, const char *feature, GError **error);

ARV_API void arv_camera_set_register (ArvCamera *camera, const char *feature, guint64 length, void* value, GError **error);
ARV_API void arv_camera_get_register (ArvCamera *camera, const char *feature, guint64 length, void* value, GError **error);
ARV_API guint64 arv_camera_get_register_length (ArvCamera *camera, const char *feature, GError **error);

ARV_API gint64 * arv_camera_dup_available_enumerations (ArvCamera *camera, const char *feature,
guint *n_values, GError **error);
ARV_API const char ** arv_camera_dup_available_enumerations_as_strings (ArvCamera *camera, const char *feature,
Expand Down
1 change: 1 addition & 0 deletions src/arvchunkparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <arvbuffer.h>
#include <arvgcinteger.h>
#include <arvgcfloat.h>
#include <arvgcregister.h>
#include <arvgcstring.h>
#include <arvgcboolean.h>
#include <arvdebugprivate.h>
Expand Down
67 changes: 67 additions & 0 deletions src/arvdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <arvgcfeaturenode.h>
#include <arvgcboolean.h>
#include <arvgcenumeration.h>
#include <arvgcregister.h>
#include <arvgcstring.h>
#include <arvstream.h>
#include <arvdebug.h>
Expand Down Expand Up @@ -798,6 +799,72 @@ arv_device_get_float_feature_increment (ArvDevice *device, const char *feature,
return G_MINDOUBLE;
}

/**
* arv_device_set_register_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @value: new feature value
* @error: a #GError placeholder
*
* Set the register feature value.
*
* Since:
*/

void
arv_device_set_register_feature_value (ArvDevice *device, const char *feature, guint64 length, void* value, GError **error)
{
ArvGcNode *node;

node = _get_feature (device, ARV_TYPE_GC_REGISTER, feature, error);
if (node != NULL)
arv_gc_register_set (ARV_GC_REGISTER (node), value, length, error);
}

/**
* arv_device_get_register_feature_value:
* @device: a #ArvDevice
* @feature: feature name
* @value: (out): the register feature value
* @error: a #GError placeholder
*
* Retrive the register feature value.
*
* Since:
*/

void
arv_device_get_register_feature_value (ArvDevice *device, const char *feature, guint64 length, void* value, GError **error)
{
ArvGcNode *node;

node = _get_feature (device, ARV_TYPE_GC_REGISTER, feature, error);
if (node != NULL)
arv_gc_register_get (ARV_GC_REGISTER (node), value, length, error);
}

/**
* arv_device_get_register_feature_length:
* @device: a #ArvDevice
* @feature: feature name
* @error: a #GError placeholder
*
* Returns: the length of register value, 0 if not available
*
* Since:
*/

guint64
arv_device_get_register_feature_length (ArvDevice *device, const char *feature, GError **error)
{
ArvGcNode *node;
node = _get_feature (device, ARV_TYPE_GC_REGISTER, feature, error);
if (node != NULL)
return arv_gc_register_get_length(ARV_GC_REGISTER (node), error);

return 0;
}

Comment on lines +836 to +867
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark here about the API simplification. In arvDevice, the get_register function should take care to check the buffer length value is lower than the maximum size (2^16), and return an error otherwise.

/**
* arv_device_dup_available_enumeration_feature_values:
* @device: an #ArvDevice
Expand Down
4 changes: 4 additions & 0 deletions src/arvdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ ARV_API void arv_device_set_float_feature_value (ArvDevice *device, const char
ARV_API double arv_device_get_float_feature_value (ArvDevice *device, const char *feature, GError **error);
ARV_API void arv_device_get_float_feature_bounds (ArvDevice *device, const char *feature, double *min, double *max, GError **error);
ARV_API double arv_device_get_float_feature_increment (ArvDevice *device, const char *feature, GError **error);

ARV_API void arv_device_set_register_feature_value (ArvDevice *device, const char *feature, guint64 length, void* value, GError **error);
ARV_API void arv_device_get_register_feature_value (ArvDevice *device, const char *feature, guint64 length, void* value, GError **error);
ARV_API guint64 arv_device_get_register_feature_length (ArvDevice *device, const char *feature, GError **error);

ARV_API gint64 * arv_device_dup_available_enumeration_feature_values (ArvDevice *device, const char *feature,
guint *n_values, GError **error);
Expand Down
1 change: 1 addition & 0 deletions src/arvgcenumeration.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <arvgcenumentry.h>
#include <arvgcinteger.h>
#include <arvgcselector.h>
#include <arvgcregister.h>
#include <arvgcstring.h>
#include <arvgcfeaturenodeprivate.h>
#include <arvgc.h>
Expand Down
1 change: 1 addition & 0 deletions src/arvgcfeaturenode.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <arvgcboolean.h>
#include <arvgcinteger.h>
#include <arvgcfloat.h>
#include <arvgcregister.h>
#include <arvgcstring.h>
#include <arvgcenumeration.h>
#include <arvgcenums.h>
Expand Down
1 change: 1 addition & 0 deletions src/arvgcpropertynode.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <arvgcinteger.h>
#include <arvgcfloat.h>
#include <arvgcboolean.h>
#include <arvgcregister.h>
#include <arvgcstring.h>
#include <arvgc.h>
#include <arvdomtext.h>
Expand Down
1 change: 1 addition & 0 deletions src/arvgcstringnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/

#include <arvgcstringnode.h>
#include <arvgcregister.h>
#include <arvgcstring.h>
#include <arvgcinteger.h>
#include <arvgcvalueindexednode.h>
Expand Down
29 changes: 28 additions & 1 deletion src/arvtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ arv_tool_show_feature (ArvGcFeatureNode *node, ArvToolListMode list_mode, int le
value = g_strdup_printf ("%s",
arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node),
&error) ? "true" : "false");
} else if (ARV_IS_GC_REGISTER (node)) {
void* buffer;
guint64 length = arv_gc_register_get_length(ARV_GC_REGISTER (node), &error);
arv_gc_register_get (ARV_GC_REGISTER (node), buffer, length, &error);

value = g_strdup_printf ("%" G_GUINT64_FORMAT, (char *)buffer ? length : 0);
}
}

Expand Down Expand Up @@ -364,7 +370,28 @@ arv_tool_control (int argc, char **argv, ArvDevice *device)

if (error == NULL)
printf ("%s = %s\n", tokens[0], value ? "true" : "false");
} else {
} else if (ARV_IS_GC_REGISTER (feature)) {
unsigned char* buffer;

guint64 length = arv_gc_register_get_length(ARV_GC_REGISTER (feature), &error);
if (error == NULL)
printf ("Length of %s = %"G_GUINT64_FORMAT"\n", tokens[0], length);

buffer = (unsigned char*) malloc(length);
arv_gc_register_get (ARV_GC_REGISTER (feature), (void*)buffer, length, &error);

if (error == NULL){
printf("Content of %s =", tokens[0]);
for( int i = 0; i < length; i++){
if ( i%8 == 0){
printf("\n\t");
}
printf("0x%02x ", *((buffer)+i));
Comment on lines +383 to +389
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use arv_g_string_append_hex_dump here.

Please format the output as:

GenDCDescriptor = 128 bytes@0x0900
01e0 c8 b7 89 b0 45 fa 3d 9d 8c e9 a7 33 46 85 1f 2c  ....E.=....3F..,
...

}
}
printf("\n");
free(buffer);
}else {
const char *value = arv_gc_feature_node_get_value_as_string
(ARV_GC_FEATURE_NODE (feature), &error);

Expand Down