/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to views/transform.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-09-24 02:28:45 UTC
  • mfrom: (305.1.19 views)
  • Revision ID: csa@suren.me-20150924022845-p7hc8lh8v0q48g0r
Finalyze XML support and provide initial support for views (only descriptions so far)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define _PCILIB_VIEW_TRANSFORM_C
 
2
 
 
3
#include <stdio.h>
 
4
#include <unistd.h>
 
5
#include <stdlib.h>
 
6
#include <string.h>
 
7
 
 
8
#include "version.h"
 
9
#include "model.h"
 
10
#include "transform.h"
 
11
 
 
12
 
 
13
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) {
 
14
/*    int j=0;
 
15
    pcilib_register_value_t value=0;
 
16
    char* formula=NULL;
 
17
 
 
18
    if(view2reg==0) {
 
19
        if(!(strcasecmp(unit,((pcilib_view_t*)viewval)->base_unit.name))) {
 
20
            formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->read_formula));
 
21
            if(!(formula)) {
 
22
                pcilib_error("can't allocate memory for the formula");
 
23
                return PCILIB_ERROR_MEMORY;
 
24
            }
 
25
            strncpy(formula,((pcilib_formula_t*)params)->read_formula,strlen(((pcilib_formula_t*)params)->read_formula));
 
26
            pcilib_view_apply_formula(ctx,formula,regval);
 
27
            return 0;
 
28
        }
 
29
 
 
30
        for(j=0; ((pcilib_view_t*)viewval)->base_unit.transforms[j].name; j++) {
 
31
            if(!(strcasecmp(((pcilib_view_t*)viewval)->base_unit.transforms[j].name,unit))) {
 
32
                // when we have found the correct view of type formula, we apply the formula, that get the good value for return
 
33
                formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->read_formula));
 
34
                if(!(formula)) {
 
35
                    pcilib_error("can't allocate memory for the formula");
 
36
                    return PCILIB_ERROR_MEMORY;
 
37
                }
 
38
                strncpy(formula,((pcilib_formula_t*)params)->read_formula,strlen(((pcilib_formula_t*)params)->read_formula));
 
39
                pcilib_view_apply_formula(ctx,formula, regval);
 
40
                //        pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.transforms[j],unit,regval);
 
41
                return 0;
 
42
            }
 
43
        }*/
 
44
}
 
45
 
 
46
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) {
 
47
/*        if(!(strcasecmp(unit, ((pcilib_view_t*)viewval)->base_unit.name))) {
 
48
            formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->write_formula));
 
49
            strncpy(formula,((pcilib_formula_t*)params)->write_formula,strlen(((pcilib_formula_t*)params)->write_formula));
 
50
            pcilib_view_apply_formula(ctx,formula,regval);
 
51
            return 0;
 
52
        }
 
53
 
 
54
        for(j=0; ((pcilib_view_t*)viewval)->base_unit.transforms[j].name; j++) {
 
55
            if(!(strcasecmp(((pcilib_view_t*)viewval)->base_unit.transforms[j].name,unit))) {
 
56
                // when we have found the correct view of type formula, we apply the formula, that get the good value for return
 
57
                formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->write_formula));
 
58
                strncpy(formula,((pcilib_formula_t*)params)->write_formula,strlen((( pcilib_formula_t*)params)->write_formula));
 
59
                //pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.transforms[j],unit,regval);
 
60
                pcilib_view_apply_formula(ctx,formula,regval);
 
61
                // we maybe need some error checking there , like temp_value >min and <max
 
62
                return 0;
 
63
            }
 
64
        }
 
65
    free(formula);
 
66
    return PCILIB_ERROR_INVALID_REQUEST;*/
 
67
}
 
68
 
 
69
 
 
70
const pcilib_view_api_description_t pcilib_transform_view_api =
 
71
  { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), NULL, NULL,  pcilib_transform_view_read,  pcilib_transform_view_write };