1
#define _PCILIB_VIEW_TRANSFORM_C
10
#include "transform.h"
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) {
15
pcilib_register_value_t value=0;
19
if(!(strcasecmp(unit,((pcilib_view_t*)viewval)->base_unit.name))) {
20
formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->read_formula));
22
pcilib_error("can't allocate memory for the formula");
23
return PCILIB_ERROR_MEMORY;
25
strncpy(formula,((pcilib_formula_t*)params)->read_formula,strlen(((pcilib_formula_t*)params)->read_formula));
26
pcilib_view_apply_formula(ctx,formula,regval);
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));
35
pcilib_error("can't allocate memory for the formula");
36
return PCILIB_ERROR_MEMORY;
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);
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);
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
66
return PCILIB_ERROR_INVALID_REQUEST;*/
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 };