gint64 arv_gc_property_node_get_int64 (ArvGcPropertyNode *node, GError **error) { ArvDomNode *pvalue_node; g_return_val_if_fail (ARV_IS_GC_PROPERTY_NODE (node), 0); g_return_val_if_fail (error == NULL || *error == NULL, 0); pvalue_node = _get_pvalue_node (node); if (pvalue_node == NULL) return g_ascii_strtoll (_get_value_data (node), NULL, 0); if (ARV_IS_GC_INTEGER (pvalue_node)) { GError *local_error = NULL; gint64 value; value = arv_gc_integer_get_value (ARV_GC_INTEGER (pvalue_node), &local_error); if (local_error != NULL) g_propagate_error (error, local_error); return value; } arv_warning_genicam ("[GcPropertyNode::get_int64] Invalid node '%s'", arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (pvalue_node))); return 0; }
static const char * arv_gc_struct_entry_node_get_value_as_string (ArvGcFeatureNode *node) { ArvGcStructEntryNode *gc_struct_entry_node = ARV_GC_STRUCT_ENTRY_NODE (node); g_snprintf (gc_struct_entry_node->v_string, G_ASCII_DTOSTR_BUF_SIZE, "0x%08" G_GINT64_MODIFIER "x", arv_gc_integer_get_value (ARV_GC_INTEGER (node))); return gc_struct_entry_node->v_string; }
static void _update_variables (ArvGcSwissKnife *gc_swiss_knife, GError **error) { ArvGcNode *node; GError *local_error = NULL; GSList *iter; const char *expression; if (gc_swiss_knife->formula_node != NULL) expression = arv_gc_property_node_get_string (gc_swiss_knife->formula_node, &local_error); else expression = ""; if (local_error != NULL) { g_propagate_error (error, local_error); return; } arv_evaluator_set_expression (gc_swiss_knife->formula, expression); for (iter = gc_swiss_knife->variables; iter != NULL; iter = iter->next) { ArvGcVariableNode *variable_node = iter->data; node = arv_gc_property_node_get_linked_node (ARV_GC_PROPERTY_NODE (variable_node)); if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_INT64) { gint64 value; value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return; } arv_evaluator_set_int64_variable (gc_swiss_knife->formula, arv_gc_variable_node_get_name (variable_node), value); } else if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_DOUBLE) { double value; value = arv_gc_float_get_value (ARV_GC_FLOAT (node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return; } arv_evaluator_set_double_variable (gc_swiss_knife->formula, arv_gc_variable_node_get_name (variable_node), value); } } }
static guint64 _get_address (ArvGcRegisterNode *gc_register_node, GError **error) { ArvGc *genicam; GError *local_error = NULL; GSList *iter; guint64 value = 0; genicam = arv_gc_node_get_genicam (ARV_GC_NODE (gc_register_node)); g_return_val_if_fail (ARV_IS_GC (genicam), 0); for (iter = gc_register_node->addresses; iter != NULL; iter = iter->next) { value += arv_gc_property_node_get_int64 (iter->data, &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return 0; } } for (iter = gc_register_node->swiss_knives; iter != NULL; iter = iter->next) { value += arv_gc_integer_get_value (iter->data, &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return 0; } } if (gc_register_node->index != NULL) { gint64 length; length = _get_length (gc_register_node, &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return 0; } value += arv_gc_index_node_get_index (ARV_GC_INDEX_NODE (gc_register_node->index), length, &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return 0; } } return value; }
static const char * arv_gc_register_node_get_value_as_string (ArvGcFeatureNode *node, GError **error) { ArvGcRegisterNode *gc_register_node = ARV_GC_REGISTER_NODE (node); GError *local_error = NULL; const char *string; switch (gc_register_node->value_type) { case G_TYPE_INT64: g_snprintf (gc_register_node->v_string, G_ASCII_DTOSTR_BUF_SIZE, "0x%08" G_GINT64_MODIFIER "x", arv_gc_integer_get_value (ARV_GC_INTEGER (node), &local_error)); if (local_error != NULL) { g_propagate_error (error, local_error); return NULL; } return gc_register_node->v_string; case G_TYPE_DOUBLE: g_ascii_dtostr (gc_register_node->v_string, G_ASCII_DTOSTR_BUF_SIZE, arv_gc_float_get_value (ARV_GC_FLOAT (node), &local_error)); if (local_error != NULL) { g_propagate_error (error, local_error); return NULL; } return gc_register_node->v_string; case G_TYPE_STRING: string = arv_gc_string_get_value (ARV_GC_STRING (node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return NULL; } return string; default: break; } arv_warning_genicam ("[GcRegisterNode::get_value_as_string] Invalid value type"); return NULL; }
//! Serialize the tree, used by QArvCamera stream operators. void QArvCamera::QArvFeatureTree::recursiveSerialization( QTextStream& out, QArvCamera* camera, QArvCamera::QArvFeatureTree* tree) { auto node = arv_gc_get_node(camera->genicam, tree->feature()); if (tree->children().count() != 0) { if (QString("Root") != tree->feature()) out << "Category: " << tree->feature() << endl; foreach (auto child, tree->children()) { recursiveSerialization(out, camera, child); } return; } if (ARV_IS_GC_COMMAND(node)) return; out << "\t" << tree->feature() << "\t"; if (ARV_IS_GC_REGISTER_NODE(node) && QString(arv_dom_node_get_node_name(ARV_DOM_NODE(node))) == "IntReg") { QArvRegister r; r.length = arv_gc_register_get_length(ARV_GC_REGISTER(node), NULL); r.value = QByteArray(r.length, 0); arv_gc_register_get(ARV_GC_REGISTER(node), r.value.data(), r.length, NULL); out << "Register\t" << QString::number(r.length) << "\t" << QString("0x") + r.value.toHex() << endl; } else if (ARV_IS_GC_ENUMERATION(node)) { out << "Enumeration\t" << arv_gc_enumeration_get_string_value(ARV_GC_ENUMERATION(node), NULL) << endl; } else if (ARV_IS_GC_STRING(node)) { out << "String\t" << arv_gc_string_get_value(ARV_GC_STRING(node), NULL) << endl; } else if (ARV_IS_GC_FLOAT(node)) { out << "Float\t" << arv_gc_float_get_value(ARV_GC_FLOAT(node), NULL) << "\t" << arv_gc_float_get_unit(ARV_GC_FLOAT(node), NULL) << endl; } else if (ARV_IS_GC_BOOLEAN(node)) { out << "Boolean\t" << arv_gc_boolean_get_value(ARV_GC_BOOLEAN(node), NULL) << endl; } else if (ARV_IS_GC_INTEGER(node)) { out << "Integer\t" << arv_gc_integer_get_value(ARV_GC_INTEGER(node), NULL) << endl; } }
static const char * arv_gc_struct_entry_node_get_value_as_string (ArvGcFeatureNode *node, GError **error) { ArvGcStructEntryNode *gc_struct_entry_node = ARV_GC_STRUCT_ENTRY_NODE (node); GError *local_error = NULL; gint64 value; value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return NULL; } g_snprintf (gc_struct_entry_node->v_string, G_ASCII_DTOSTR_BUF_SIZE, "0x%08" G_GINT64_MODIFIER "x", value); return gc_struct_entry_node->v_string; }
gint64 arv_chunk_parser_get_integer_value (ArvChunkParser *parser, ArvBuffer *buffer, const char *chunk) { ArvGcNode *node; gint64 value = 0; g_return_val_if_fail (ARV_IS_CHUNK_PARSER (parser), 0.0); g_return_val_if_fail (ARV_IS_BUFFER (buffer), 0.0); node = arv_gc_get_node (parser->priv->genicam, chunk); arv_gc_set_buffer (parser->priv->genicam, buffer); if (ARV_IS_GC_INTEGER (node)) value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL); else arv_warning_device ("[ArvChunkParser::get_integer_value] Node '%s' is not an integer", chunk); return value; }
gint64 arv_gc_index_node_get_index (ArvGcIndexNode *index_node, gint64 default_offset, GError **error) { gint64 offset; gint64 node_value; GError *local_error = NULL; g_return_val_if_fail (ARV_IS_GC_INDEX_NODE (index_node), 0); g_return_val_if_fail (error == NULL || *error == NULL, 0); if (index_node->offset == NULL) offset = default_offset; else { if (index_node->is_p_offset) { ArvGcNode *node; ArvGc *genicam; genicam = arv_gc_node_get_genicam (ARV_GC_NODE (index_node)); node = arv_gc_get_node (genicam, index_node->offset); offset = arv_gc_integer_get_value (ARV_GC_INTEGER (node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return 0; } } else offset = g_ascii_strtoll (index_node->offset, NULL, 0); } node_value = arv_gc_property_node_get_int64 (ARV_GC_PROPERTY_NODE (index_node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return 0; } return offset * node_value; }
int main (int argc, char **argv) { ArvGc *genicam; char *xml; size_t size; GOptionContext *context; GError *error = NULL; int i; arv_g_type_init (); context = g_option_context_new (NULL); g_option_context_add_main_entries (context, arv_option_entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_option_context_free (context); g_print ("Option parsing failed: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } g_option_context_free (context); arv_debug_enable (arv_option_debug_domains); if (arv_option_filenames == NULL) { g_print ("Missing input filename.\n"); return EXIT_FAILURE; } for (i = 0; arv_option_filenames[i] != NULL; i++) { g_file_get_contents (arv_option_filenames[i], &xml, &size, NULL); if (xml != NULL) { ArvGcNode *node; g_print ("Loading '%s'.\n", arv_option_filenames[i]); genicam = arv_gc_new (NULL, xml, size); node = arv_gc_get_node (genicam, "RegAcquisitionCommand"); if (node != NULL) { g_print ("RegAcquisitionCommand address = 0x%Lx - length = 0x%Lx\n", (unsigned long long) arv_gc_register_get_address (ARV_GC_REGISTER (node), NULL), (unsigned long long) arv_gc_register_get_length (ARV_GC_REGISTER (node), NULL)); } node = arv_gc_get_node (genicam, "IntWidthIncrement"); if (node != NULL) { g_print ("IntWidthIncrement value = %Ld\n", (long long) arv_gc_integer_get_value (ARV_GC_INTEGER (node), NULL)); } node = arv_gc_get_node (genicam, "WhitebalValueMin"); if (node != NULL) { g_print ("WhitebalValueMin value = %g\n", arv_gc_float_get_value (ARV_GC_FLOAT (node), NULL)); } g_free (xml); g_object_unref (genicam); } else g_print ("File '%s' not found.\n", arv_option_filenames[i]); } return EXIT_SUCCESS; }
static void _update_to_variables (ArvGcConverter *gc_converter, GError **error) { ArvGcNode *node; GError *local_error = NULL; GSList *iter; const char *expression; if (gc_converter->formula_to_node != NULL) expression = arv_gc_property_node_get_string (gc_converter->formula_to_node, &local_error); else expression = ""; if (local_error != NULL) { g_propagate_error (error, local_error); return; } arv_evaluator_set_expression (gc_converter->formula_to, expression); for (iter = gc_converter->expressions; iter != NULL; iter = iter->next) { const char *expression; const char *name; expression = arv_gc_property_node_get_string (ARV_GC_PROPERTY_NODE (iter->data), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return; } name = arv_gc_property_node_get_name (iter->data); arv_evaluator_set_sub_expression (gc_converter->formula_to, name, expression); } for (iter = gc_converter->constants; iter != NULL; iter = iter->next) { const char *constant; const char *name; constant = arv_gc_property_node_get_string (ARV_GC_PROPERTY_NODE (iter->data), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return; } name = arv_gc_property_node_get_name (iter->data); arv_evaluator_set_constant (gc_converter->formula_to, name, constant); } for (iter = gc_converter->variables; iter != NULL; iter = iter->next) { ArvGcPropertyNode *variable_node = iter->data; node = arv_gc_property_node_get_linked_node (ARV_GC_PROPERTY_NODE (variable_node)); if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_INT64) { gint64 value; value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return; } arv_evaluator_set_int64_variable (gc_converter->formula_to, arv_gc_property_node_get_name (variable_node), value); } else if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_DOUBLE) { double value; value = arv_gc_float_get_value (ARV_GC_FLOAT (node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return; } arv_evaluator_set_double_variable (gc_converter->formula_to, arv_gc_property_node_get_name (variable_node), value); } } if (gc_converter->value != NULL) { node = arv_gc_property_node_get_linked_node (gc_converter->value); if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_INT64) { arv_gc_integer_set_value (ARV_GC_INTEGER (node), arv_evaluator_evaluate_as_double (gc_converter->formula_to, NULL), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return; } } else if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_DOUBLE) { arv_gc_float_set_value (ARV_GC_FLOAT (node), arv_evaluator_evaluate_as_double (gc_converter->formula_to, NULL), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return; } } else arv_warning_genicam ("[GcConverter::set_value] Invalid pValue node '%s'", gc_converter->value); } }
static gboolean _update_from_variables (ArvGcConverter *gc_converter, ArvGcConverterNodeType node_type, GError **error) { ArvGcNode *node = NULL; GError *local_error = NULL; GSList *iter; const char *expression; if (gc_converter->formula_from_node != NULL) expression = arv_gc_property_node_get_string (gc_converter->formula_from_node, &local_error); else expression = ""; if (local_error != NULL) { g_propagate_error (error, local_error); return FALSE; } arv_evaluator_set_expression (gc_converter->formula_from, expression); for (iter = gc_converter->expressions; iter != NULL; iter = iter->next) { const char *expression; const char *name; expression = arv_gc_property_node_get_string (ARV_GC_PROPERTY_NODE (iter->data), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return FALSE; } name = arv_gc_property_node_get_name (iter->data); arv_evaluator_set_sub_expression (gc_converter->formula_from, name, expression); } for (iter = gc_converter->constants; iter != NULL; iter = iter->next) { const char *constant; const char *name; constant = arv_gc_property_node_get_string (ARV_GC_PROPERTY_NODE (iter->data), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return FALSE; } name = arv_gc_property_node_get_name (iter->data); arv_evaluator_set_constant (gc_converter->formula_from, name, constant); } for (iter = gc_converter->variables; iter != NULL; iter = iter->next) { ArvGcPropertyNode *variable_node = iter->data; node = arv_gc_property_node_get_linked_node (ARV_GC_PROPERTY_NODE (variable_node)); if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_INT64) { gint64 value; value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return FALSE; } arv_evaluator_set_int64_variable (gc_converter->formula_from, arv_gc_property_node_get_name (variable_node), value); } else if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_DOUBLE) { double value; value = arv_gc_float_get_value (ARV_GC_FLOAT (node), &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); return FALSE; } arv_evaluator_set_double_variable (gc_converter->formula_from, arv_gc_property_node_get_name (variable_node), value); } } if (gc_converter->value != NULL) { node = arv_gc_property_node_get_linked_node (gc_converter->value); if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_INT64) { gint64 value; switch (node_type) { case ARV_GC_CONVERTER_NODE_TYPE_MIN: value = arv_gc_integer_get_min (ARV_GC_INTEGER (node), &local_error); break; case ARV_GC_CONVERTER_NODE_TYPE_MAX: value = arv_gc_integer_get_max (ARV_GC_INTEGER (node), &local_error); break; default: value = arv_gc_integer_get_value (ARV_GC_INTEGER (node), &local_error); break; } if (local_error != NULL) { g_propagate_error (error, local_error); return FALSE; } arv_evaluator_set_int64_variable (gc_converter->formula_from, "TO", value); } else if (arv_gc_feature_node_get_value_type (ARV_GC_FEATURE_NODE (node)) == G_TYPE_DOUBLE) { double value; switch (node_type) { case ARV_GC_CONVERTER_NODE_TYPE_MIN: value = arv_gc_float_get_min (ARV_GC_FLOAT (node), &local_error); break; case ARV_GC_CONVERTER_NODE_TYPE_MAX: value = arv_gc_float_get_max (ARV_GC_FLOAT (node), &local_error); break; default: value = arv_gc_float_get_value (ARV_GC_FLOAT (node), &local_error); break; } if (local_error != NULL) { g_propagate_error (error, local_error); return FALSE; } arv_evaluator_set_double_variable (gc_converter->formula_from, "TO", value); } else { arv_warning_genicam ("[GcConverter::set_value] Invalid pValue node '%s'", gc_converter->value); g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_INVALID_PVALUE, "pValue node '%s' of '%s' is invalid", arv_gc_property_node_get_string (gc_converter->value, NULL), arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_converter))); return FALSE; } } else { g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PVALUE_NOT_DEFINED, "pValue node of '%s' converter is not defined", arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_converter))); return FALSE; } return TRUE; }