summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/CMakeLists.txt11
-rw-r--r--views/enum.c47
-rw-r--r--views/enum.h23
-rw-r--r--views/transform.c71
-rw-r--r--views/transform.h17
5 files changed, 169 insertions, 0 deletions
diff --git a/views/CMakeLists.txt b/views/CMakeLists.txt
new file mode 100644
index 0000000..fa50abf
--- /dev/null
+++ b/views/CMakeLists.txt
@@ -0,0 +1,11 @@
+include_directories(
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/pcilib
+ ${CMAKE_BINARY_DIR}/pcilib
+ ${LIBXML2_INCLUDE_DIRS}
+)
+
+set(HEADERS ${HEADERS} enum.h transform.h)
+
+add_library(views STATIC enum.c transform.c)
diff --git a/views/enum.c b/views/enum.c
new file mode 100644
index 0000000..a222971
--- /dev/null
+++ b/views/enum.c
@@ -0,0 +1,47 @@
+#define _PCILIB_VIEW_ENUM_C
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "version.h"
+#include "model.h"
+#include "enum.h"
+
+static void pcilib_enum_view_free(pcilib_t *ctx, pcilib_view_context_t *view) {
+}
+
+static int pcilib_enum_view_read(pcilib_t *ctx, pcilib_view_context_t *view, const pcilib_register_value_t *regval, pcilib_data_type_t viewval_type, size_t viewval_size, void *viewval) {
+/* for(j=0; ((pcilib_enum_t*)(params))[j].name; j++) {
+ if (*regval<=((pcilib_enum_t*)(params))[j].max && *regval>=((pcilib_enum_t*)(params))[j].min) {
+ if(viewval_size<strlen(((pcilib_enum_t*)(params))[j].name)) {
+ pcilib_error("the string to contain the enum command is too tight");
+ return PCILIB_ERROR_MEMORY;
+ }
+ strncpy((char*)viewval,((pcilib_enum_t*)(params))[j].name, strlen(((pcilib_enum_t*)(params))[j].name));
+ k=strlen(((pcilib_enum_t*)(params))[j].name);
+ ((char*)viewval)[k]='\0';
+ return 0;
+ }
+ }
+ }
+ return PCILIB_ERROR_INVALID_REQUEST;*/
+}
+
+static int pcilib_enum_view_write(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t *regval, pcilib_data_type_t viewval_type, size_t viewval_size, const void *viewval) {
+/* int j,k;
+
+ if(view2reg==1) {
+ for(j=0; ((pcilib_enum_t*)(params))[j].name; j++) {
+ if(!(strcasecmp(((pcilib_enum_t*)(params))[j].name,(char*)viewval))) {
+ *regval=((pcilib_enum_t*)(params))[j].value;
+ return 0;
+ }
+ }*/
+}
+
+const pcilib_view_api_description_t pcilib_enum_view_static_api =
+ { PCILIB_VERSION, sizeof(pcilib_enum_view_description_t), NULL, NULL, pcilib_enum_view_read, pcilib_enum_view_write };
+const pcilib_view_api_description_t pcilib_enum_view_xml_api =
+ { PCILIB_VERSION, sizeof(pcilib_enum_view_description_t), NULL, pcilib_enum_view_free, pcilib_enum_view_read, pcilib_enum_view_write };
diff --git a/views/enum.h b/views/enum.h
new file mode 100644
index 0000000..eb90810
--- /dev/null
+++ b/views/enum.h
@@ -0,0 +1,23 @@
+#ifndef _PCILIB_VIEW_ENUM_H
+#define _PCILIB_VIEW_ENUM_H
+
+#include <pcilib.h>
+#include <pcilib/view.h>
+
+typedef struct {
+ pcilib_register_value_t value, min, max; /**< the value or value-range for which the name is defined, while wrtiting the name the value will be used even if range is specified */
+ const char *name; /**< corresponding string to value */
+} pcilib_value_name_t;
+
+typedef struct {
+ pcilib_view_description_t base;
+ pcilib_value_name_t *names;
+} pcilib_enum_view_description_t;
+
+
+#ifndef _PCILIB_VIEW_ENUM_C
+extern const pcilib_view_api_description_t pcilib_enum_view_static_api;
+extern const pcilib_view_api_description_t pcilib_enum_view_xml_api;
+#endif /* _PCILIB_VIEW_ENUM_C */
+
+#endif /* _PCILIB_VIEW_ENUM_H */
diff --git a/views/transform.c b/views/transform.c
new file mode 100644
index 0000000..54ae2c1
--- /dev/null
+++ b/views/transform.c
@@ -0,0 +1,71 @@
+#define _PCILIB_VIEW_TRANSFORM_C
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "version.h"
+#include "model.h"
+#include "transform.h"
+
+
+static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view, const pcilib_register_value_t *regval, pcilib_data_type_t viewval_type, size_t viewval_size, void *viewval) {
+/* int j=0;
+ pcilib_register_value_t value=0;
+ char* formula=NULL;
+
+ if(view2reg==0) {
+ if(!(strcasecmp(unit,((pcilib_view_t*)viewval)->base_unit.name))) {
+ formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->read_formula));
+ if(!(formula)) {
+ pcilib_error("can't allocate memory for the formula");
+ return PCILIB_ERROR_MEMORY;
+ }
+ strncpy(formula,((pcilib_formula_t*)params)->read_formula,strlen(((pcilib_formula_t*)params)->read_formula));
+ pcilib_view_apply_formula(ctx,formula,regval);
+ return 0;
+ }
+
+ for(j=0; ((pcilib_view_t*)viewval)->base_unit.transforms[j].name; j++) {
+ if(!(strcasecmp(((pcilib_view_t*)viewval)->base_unit.transforms[j].name,unit))) {
+ // when we have found the correct view of type formula, we apply the formula, that get the good value for return
+ formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->read_formula));
+ if(!(formula)) {
+ pcilib_error("can't allocate memory for the formula");
+ return PCILIB_ERROR_MEMORY;
+ }
+ strncpy(formula,((pcilib_formula_t*)params)->read_formula,strlen(((pcilib_formula_t*)params)->read_formula));
+ pcilib_view_apply_formula(ctx,formula, regval);
+ // pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.transforms[j],unit,regval);
+ return 0;
+ }
+ }*/
+}
+
+static int pcilib_transform_view_write(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t *regval, pcilib_data_type_t viewval_type, size_t viewval_size, const void *viewval) {
+/* if(!(strcasecmp(unit, ((pcilib_view_t*)viewval)->base_unit.name))) {
+ formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->write_formula));
+ strncpy(formula,((pcilib_formula_t*)params)->write_formula,strlen(((pcilib_formula_t*)params)->write_formula));
+ pcilib_view_apply_formula(ctx,formula,regval);
+ return 0;
+ }
+
+ for(j=0; ((pcilib_view_t*)viewval)->base_unit.transforms[j].name; j++) {
+ if(!(strcasecmp(((pcilib_view_t*)viewval)->base_unit.transforms[j].name,unit))) {
+ // when we have found the correct view of type formula, we apply the formula, that get the good value for return
+ formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->write_formula));
+ strncpy(formula,((pcilib_formula_t*)params)->write_formula,strlen((( pcilib_formula_t*)params)->write_formula));
+ //pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.transforms[j],unit,regval);
+ pcilib_view_apply_formula(ctx,formula,regval);
+ // we maybe need some error checking there , like temp_value >min and <max
+ return 0;
+ }
+ }
+ free(formula);
+ return PCILIB_ERROR_INVALID_REQUEST;*/
+}
+
+
+const pcilib_view_api_description_t pcilib_transform_view_api =
+ { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), NULL, NULL, pcilib_transform_view_read, pcilib_transform_view_write };
diff --git a/views/transform.h b/views/transform.h
new file mode 100644
index 0000000..f474552
--- /dev/null
+++ b/views/transform.h
@@ -0,0 +1,17 @@
+#ifndef _PCILIB_VIEW_TRANSFORM_H
+#define _PCILIB_VIEW_TRANSFORM_H
+
+#include <pcilib.h>
+#include <pcilib/view.h>
+
+typedef struct {
+ pcilib_view_description_t base;
+ const char *read_from_reg; /**< Formula explaining how to convert the register value to the view value */
+ const char *write_to_reg; /**< Formula explaining how to convert from the view value to the register value */
+} pcilib_transform_view_description_t;
+
+#ifndef _PCILIB_VIEW_TRANSFORM_C
+const pcilib_view_api_description_t pcilib_transform_view_api;
+#endif /* _PCILIB_VIEW_TRANSFORM_C */
+
+#endif /* _PCILIB_VIEW_TRANSFORM_H */