transform.c 3.4 KB

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