Module: xenomai-3
Branch: master
Commit: 07b4608034dc1deff8231a3f51ec211609739764
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=07b4608034dc1deff8231a3f51ec211609739764

Author: Jorge Ramirez-Ortiz <j...@xenomai.org>
Date:   Wed Sep 17 09:30:13 2014 -0700

utils/analogy: calibration - parse the calibration file

---

 lib/boilerplate/iniparser/iniparser.c |    6 +-
 utils/analogy/analogy_calibrate.c     |   42 ++------
 utils/analogy/analogy_calibrate.h     |  123 +++++++++++++++++++---
 utils/analogy/calibration_ni_m.c      |  184 ++++++++++++++++++++-------------
 utils/analogy/calibration_ni_m.h      |    9 +-
 5 files changed, 241 insertions(+), 123 deletions(-)

diff --git a/lib/boilerplate/iniparser/iniparser.c 
b/lib/boilerplate/iniparser/iniparser.c
index 0e1621d..5b2094a 100644
--- a/lib/boilerplate/iniparser/iniparser.c
+++ b/lib/boilerplate/iniparser/iniparser.c
@@ -619,11 +619,13 @@ dictionary * iniparser_load(const char * ininame)
 
        case LINE_ERROR:
 #if 0
-            warning(anon_scope, "iniparser: syntax error in %s (%d):\n",
+            printf("iniparser: syntax error in %s (%d):\n",
                     ininame,
                     lineno);
-            warning(anon_scope, "-> %s\n", line);
+            printf( "-> %s\n", line);
+
 #endif
+
            ret = EINVAL;
             errs++ ;
             break;
diff --git a/utils/analogy/analogy_calibrate.c 
b/utils/analogy/analogy_calibrate.c
index b2ac286..8404811 100644
--- a/utils/analogy/analogy_calibrate.c
+++ b/utils/analogy/analogy_calibrate.c
@@ -87,22 +87,22 @@ apply_calibration_set_globals(char *info)
        params.name = strtok(info, ":");
        p = strtok(NULL, ",");
        if (!p)
-               error(EXIT, 0, "missing --apply parameter \n");
+               error(EXIT, 0, "missing --apply parameter subd \n");
        params.subd = strtol(p, NULL, 0);
 
        p = strtok(NULL, ",");
        if (!p)
-               error(EXIT, 0, "missing --apply parameter \n");
+               error(EXIT, 0, "missing --apply parameter channel \n");
        params.channel = strtol(p, NULL, 0);
 
        p = strtok(NULL, ",");
        if (!p)
-               error(EXIT, 0, "missing --apply parameter \n");
+               error(EXIT, 0, "missing --apply parameter range \n");
        params.range = strtol(p, NULL, 0);
 
        p = strtok(NULL, "");
        if (!p)
-               error(EXIT, 0, "missing --apply parameter \n");
+               error(EXIT, 0, "missing --apply parameter aref \n");
        params.aref = strtol(p, NULL, 0);
 
        return 0;
@@ -114,10 +114,8 @@ static void __attribute__ ((constructor)) 
__analogy_calibrate_init(void)
 }
 int main(int argc, char *argv[])
 {
-       struct sched_param param = {.sched_priority = 99};
        char *device = NULL, *file = NULL, *apply_info = NULL;
        int v, i, fd, err = 0;
-       struct rlimit rl;
 
        __debug("version: git commit %s, revision %s \n", GIT_STAMP, revision);
 
@@ -152,26 +150,6 @@ int main(int argc, char *argv[])
        if (apply_info)
                apply_calibration_set_globals(apply_info);
 
-       err = getrlimit(RLIMIT_STACK, &rl);
-       if (!err) {
-               if (rl.rlim_cur < rl.rlim_max) {
-                       rl.rlim_cur = rl.rlim_max;
-                       err = setrlimit(RLIMIT_STACK, &rl);
-                       if (err)
-                               __debug("setrlimit errno (%d) \n", errno);
-                       else
-                               __debug("Program Stack Size: %ld MB \n\n", 
rl.rlim_cur/(1024*1024));
-               }
-       }
-
-       err = mlockall(MCL_CURRENT | MCL_FUTURE);
-       if (err < 0)
-               error(EXIT, errno, "mlockall error");
-
-       err = pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
-       if (err)
-               error(EXIT, 0, "pthread_setschedparam failed (0x%x)", err);
-
        fd = a4l_open(&descriptor, device);
        if (fd < 0)
                error(EXIT, 0, "open %s failed (%d)", device, fd);
@@ -184,17 +162,19 @@ int main(int argc, char *argv[])
        /*
         * TODO: modify the meaning of board/driver in the proc
         */
-       push_to_cal_file("[platform] \n");
-       push_to_cal_file("driver_name: %s \n", descriptor.board_name);
-       push_to_cal_file("board_name: %s \n", descriptor.driver_name);
+       push_to_cal_file("[%s] \n",PLATFORM_STR);
+       push_to_cal_file(DRIVER_STR" = %s;\n", descriptor.board_name);
+       push_to_cal_file(BOARD_STR" = %s;\n", descriptor.driver_name);
 
        err = ni_m_software_calibrate();
        if (err)
                error(CONT, 0, "software calibration failed (%d)", err);
 
+       err = ni_m_apply_calibration();
+       if (err)
+               error(CONT, 0, "applying calibration failed (%d)", err);
+
        a4l_close(&descriptor);
-       if (cal)
-               fclose(cal);
 
        return err;
 }
diff --git a/utils/analogy/analogy_calibrate.h 
b/utils/analogy/analogy_calibrate.h
index c2b539a..4a30997 100644
--- a/utils/analogy/analogy_calibrate.h
+++ b/utils/analogy/analogy_calibrate.h
@@ -31,6 +31,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 
+#include "iniparser/iniparser.h"
 #include "git-stamp.h"
 #include "error.h"
 
@@ -132,6 +133,7 @@ static inline void __push_to_file(FILE *file, char *fmt, 
...)
 
        va_start(ap, fmt);
        vfprintf(file, fmt, ap);
+       fflush(file);
        va_end(ap);
 }
 
@@ -152,22 +154,6 @@ static inline int __array_search(char *elem, const char 
*array[], int len)
                         __push_to_file(cal, fmt, ##__VA_ARGS__);               
\
        } while(0)
 
-
-static inline void debug_cmd(a4l_cmd_t *cmd)
-{
-       __debug(" cmd.start_src         :0x%x \n",cmd->start_src);
-       __debug(" cmd.scan_begin_src    :0x%x \n",cmd->scan_begin_src);
-       __debug(" cmd.scan_begin_arg    :0x%x \n",cmd->scan_begin_arg);
-       __debug(" cmd.convert_src       :0x%x \n",cmd->convert_src);
-       __debug(" cmd.convert_arg       :0x%x \n",cmd->convert_arg);
-       __debug(" cmd.scan_end_src      :0x%x \n",cmd->scan_end_src);
-       __debug(" cmd.scan_end_arg      :0x%x \n",cmd->scan_end_arg);
-       __debug(" cmd.stop_src          :0x%x \n",cmd->stop_src);
-       __debug(" cmd.stop_arg          :0x%x \n",cmd->stop_arg);
-       __debug(" cmd.chan_descs        :0x%x \n",cmd->chan_descs);
-       __debug(" cmd.nb_chan           :0x%x \n",cmd->nb_chan);
-}
-
 static inline double rng_max(a4l_rnginfo_t *range)
 {
        double a, b;
@@ -188,4 +174,109 @@ static inline double rng_min(a4l_rnginfo_t *range)
        return a;
 }
 
+struct subd_data {
+       int index;
+       int channel;
+       int range;
+       int expansion;
+       int nb_coeff;
+       double *coeff;
+};
+
+struct calibration_data {
+       char *driver_name;
+       char *board_name;
+       int nb_ai;
+       struct subd_data *ai;
+       int nb_ao;
+       struct subd_data *ao;
+};
+
+#define ELEMENT_FIELD_FMT      "%s_%d:%s"
+#define ELEMENT_FMT            "%s:%s"
+#define COEFF_FMT              ELEMENT_FIELD_FMT"_%d"
+
+#define PLATFORM_STR           "platform"
+#define CALIBRATION_SUBD_STR   "calibration"
+#define MEMORY_SUBD_STR                "memory"
+#define AI_SUBD_STR            "analog_input"
+#define AO_SUBD_STR            "analog_output"
+
+#define INDEX_STR      "index"
+#define ELEMENTS_STR   "elements"
+#define CHANNEL_STR    "channel"
+#define RANGE_STR      "range"
+#define EXPANSION_STR  "expansion_origin"
+#define NBCOEFF_STR    "nbcoeff"
+#define COEFF_STR      "coeff"
+#define BOARD_STR      "board_name"
+#define DRIVER_STR     "driver_name"
+
+static inline int
+read_calfile_str(char ** val, struct _dictionary_ *f, const char *subd, char 
*type)
+{
+       char *not_found = NULL;
+       char *str;
+       int err;
+
+       err = asprintf(&str, ELEMENT_FMT, subd, type);
+       if (err < 0)
+               error(EXIT, 0, "asprintf \n");
+       *val = (char *) iniparser_getstring(f, str, not_found);
+       __debug("%s = %s \n", str, *val);
+       free(str);
+       if (*val == not_found)
+               error(EXIT, 0, "calibration file: str element not found \n");
+
+       return 0;
+}
+
+
+static inline int
+read_calfile_integer(int *val, struct _dictionary_ *f,
+                   const char *subd, int subd_idx, char *type)
+{
+       int not_found = 0xFFFF;
+       char *str;
+       int err;
+
+       if (subd_idx < 0)
+               err = asprintf(&str, ELEMENT_FMT, subd, type);
+       else
+               err = asprintf(&str, ELEMENT_FIELD_FMT, subd, subd_idx, type);
+       if (err < 0)
+               error(EXIT, 0, "asprintf \n");
+       *val = iniparser_getint(f, str, not_found);
+       __debug("%s = %d \n", str, *val);
+       free(str);
+       if (*val == not_found)
+               error(EXIT, 0, "calibration file: int element not found \n");
+
+       return 0;
+}
+
+static inline int
+read_calfile_double(double *d, struct _dictionary_ *f,
+                   const char *subd, int subd_idx, char *type, int type_idx)
+{
+       const double not_found = -255.0;
+       char *str;
+       int err;
+
+       if (strncmp(type, COEFF_STR, strlen(COEFF_STR) != 0))
+               error(EXIT, 0, "only contains doubles as coefficients \n");
+       err = asprintf(&str, COEFF_FMT, subd, subd_idx, type, type_idx);
+       if (err < 0)
+               error(EXIT, 0, "asprintf \n");
+       *d = iniparser_getdouble(f, str, not_found);
+       __debug("%s = %g \n", str, *d);
+       free(str);
+       if (*d == not_found)
+               error(EXIT, 0, "calbration file: double element not found \n");
+
+       return 0;
+}
+
+
+
 #endif
diff --git a/utils/analogy/calibration_ni_m.c b/utils/analogy/calibration_ni_m.c
index fa5b4e6..358c395 100644
--- a/utils/analogy/calibration_ni_m.c
+++ b/utils/analogy/calibration_ni_m.c
@@ -30,7 +30,6 @@
 #include <math.h>
 
 #include "calibration_ni_m.h"
-#include "iniparser/iniparser.h"
 
 extern char *apply_name;
 
@@ -46,19 +45,18 @@ static struct subdev_ops ops;
 static struct eeprom eeprom;
 static struct gnumath math;
 
-
 static int
-apply_calibration(void)
+parse_calibration_file(char *name, struct calibration_data *data)
 {
+       const char *subdevice[2] = { AI_SUBD_STR, AO_SUBD_STR };
+       int i, j, k, index, nb_elements;
+       struct subd_data *p = NULL;
+       struct _dictionary_ *d;
        const char *filename;
-       dictionary *d;
        wordexp_t exp;
        int ret = 0;
 
-       if (params.name == NULL)
-               return 0;
-
-       ret = wordexp(params.name, &exp, WRDE_NOCMD|WRDE_UNDEF);
+       ret = wordexp(name, &exp, WRDE_NOCMD|WRDE_UNDEF);
        if (ret) {
                ret = ret == WRDE_NOSPACE ? -ENOMEM : -EINVAL;
                error(EXIT, 0, "cant apply calibration (%d) \n", ret);
@@ -71,13 +69,68 @@ apply_calibration(void)
        if (access(filename, R_OK))
                error(EXIT, 0, "cant access %s for reading \n", params.name);
 
+       __debug("using calibration file: %s \n", params.name);
+
        d = iniparser_load(filename);
+       if (d == NULL)
+               error(EXIT, 0, "iniparser loading error for %s (%d)\n", 
params.name, errno);
+
+       read_calfile_str(&data->driver_name, d, PLATFORM_STR, DRIVER_STR);
+       read_calfile_str(&data->board_name, d, PLATFORM_STR, BOARD_STR);
+       for (k = 0; k < ARRAY_LEN(subdevice); k++) {
+               read_calfile_integer(&nb_elements, d, subdevice[k], -1,
+                                    ELEMENTS_STR);
+               read_calfile_integer(&index, d, subdevice[k], -1,
+                                    INDEX_STR);
+
+               if (strncmp(subdevice[k], AI_SUBD_STR, strlen(AI_SUBD_STR)) == 
0) {
+                       data->ai = malloc(nb_elements * sizeof(struct 
subd_data));
+                       data->nb_ai = nb_elements;
+                       p  = data->ai;
+               }
+               if (strncmp(subdevice[k], AO_SUBD_STR, strlen(AO_SUBD_STR)) == 
0) {
+                       data->ao = malloc(nb_elements * sizeof(struct 
subd_data));
+                       data->nb_ao = nb_elements;
+                       p = data->ao;
+               }
+               for (i = 0; i < nb_elements; i++) {
+                       read_calfile_integer(&p->expansion, d, subdevice[k], i,
+                                            EXPANSION_STR);
+                       read_calfile_integer(&p->nb_coeff, d, subdevice[k], i,
+                                            NBCOEFF_STR);
+                       read_calfile_integer(&p->channel, d, subdevice[k], i,
+                                            CHANNEL_STR);
+                       read_calfile_integer(&p->range, d, subdevice[k], i,
+                                            RANGE_STR);
+                       p->coeff = malloc(p->nb_coeff * sizeof(double));
+                       for (j = 0; j < p->nb_coeff; j++) {
+                               read_calfile_double(&p->coeff[j], d, 
subdevice[k],
+                                                   i, COEFF_STR, j);
+                       }
+                       p->index = index;
+                       p++;
+               }
+       }
        wordfree(&exp);
 
-       if (d == NULL)
-               error(EXIT, 0, "iniparser loading error for %s \n", 
params.name);
+       return 0;
+}
+
+
+int
+ni_m_apply_calibration(void)
+{
+       struct calibration_data cal_data;
+
+       if (params.name == NULL)
+               return 0;
 
-       return ret;
+       parse_calibration_file(params.name, &cal_data);
+       /*
+        * TODO: apply the calibration file.
+        */
+
+       return 0;
 }
 
 /*
@@ -93,31 +146,26 @@ write_calibration(struct list *calibration_list, struct 
subdevice *subd)
                return;
 
        push_to_cal_file("\n[%s] \n", subd->name);
-       push_to_cal_file("index: %d \n", subd->idx);
-       list_for_each_entry_safe(e, t, calibration_list, node)
-       j++;
-       push_to_cal_file("elements: %d \n", j);
+       push_to_cal_file(INDEX_STR" = %d;\n", subd->idx);
+       list_for_each_entry_safe(e, t, calibration_list, node) {
+               j++;
+       }
+       push_to_cal_file(ELEMENTS_STR" = %d;\n", j);
 
        j = 0;
        list_for_each_entry_safe(e, t, calibration_list, node) {
                push_to_cal_file("[%s_%d] \n", subd->name, j);
-               push_to_cal_file("channel: %d \n", e->channel);
-               push_to_cal_file("range: %d \n", e->range);
-               push_to_cal_file("expansion_origin: %g \n",
+               push_to_cal_file(CHANNEL_STR" = %d;\n", e->channel);
+               push_to_cal_file(RANGE_STR" = %d;\n", e->range);
+               push_to_cal_file(EXPANSION_STR" = %g;\n",
                                 e->polynomial->expansion_origin);
-               push_to_cal_file("nbcoeff: %d \n",
+               push_to_cal_file(NBCOEFF_STR"= %d;\n",
                                 e->polynomial->nb_coefficients);
-               push_to_cal_file("coefficients: ");
-
-               for (i = 0;;) {
-                       push_to_cal_file("%g", e->polynomial->coefficients[i]);
-                       i++;
-                       if (i == e->polynomial->nb_coefficients) {
-                               push_to_cal_file(" \n");
-                               break;
-                       }
-                       push_to_cal_file(", ");
-               }
+
+               for (i = 0; i < e->polynomial->nb_coefficients; i++)
+                       push_to_cal_file(COEFF_STR"_%d = %g;\n",
+                                        i,
+                                        e->polynomial->coefficients[i]);
                j++;
        }
 
@@ -208,8 +256,7 @@ eeprom_read_reference_voltage(float *val)
  * subdevice operations
  */
 static int
-data_read_hint(struct subdevice *s, int channel, int range, int aref,
-              unsigned int delay)
+data_read_hint(struct subdevice *s, int channel, int range, int aref)
 {
        sampl_t dummy_data;
        a4l_insn_t insn;
@@ -434,7 +481,7 @@ polynomial_linearize(double *dst, struct polynomial *p, 
double val)
 static int
 reference_get_min_sampling_period(int *val)
 {
-       unsigned int chan_descs[] = { 0 };
+       unsigned int chan_descs[] = { 0};
        a4l_cmd_t cmd;
        int err;
 
@@ -466,7 +513,7 @@ reference_get_min_sampling_period(int *val)
 static int
 reference_set_bits(unsigned int bits)
 {
-       unsigned int data[2] = { A4L_INSN_CONFIG_ALT_SOURCE, bits };
+       unsigned int data[2] = { A4L_INSN_CONFIG_ALT_SOURCE, bits};
        a4l_insn_t insn;
        int err;
 
@@ -515,7 +562,7 @@ reference_set_pwm(struct subdevice *s, unsigned int h, 
unsigned int d,
 
 static int
 reference_read_doubles(double dst[], unsigned int nb_samples,
-                      int speriod, int irange, unsigned int settle_time)
+                      int speriod, int irange)
 {
        int i, err = 0;
        sampl_t *p;
@@ -524,8 +571,7 @@ reference_read_doubles(double dst[], unsigned int 
nb_samples,
        if (!p)
                error(EXIT, 0, "malloc");
 
-       err = references.read_samples(p, nb_samples, speriod, irange,
-                                     settle_time);
+       err = references.read_samples(p, nb_samples, speriod, irange);
        if (err) {
                free(p);
                error(EXIT, 0, "read_samples");
@@ -540,19 +586,15 @@ reference_read_doubles(double dst[], unsigned int 
nb_samples,
 }
 
 static int
-reference_read_samples(void *dst, unsigned int nb_samples, int speriod,
-                      int irange, unsigned int settle_time)
+reference_read_samples(void *dst, unsigned int nb_samples, int speriod, int 
irange)
 {
        int err;
 
-       if (settle_time > 1000000000)
-               error(EXIT, 0, "invalid argument (%d)", settle_time);
-
        if (!nb_samples)
                error(EXIT, 0, "invalid nb samples (%d)", nb_samples);
 
        err = ops.data.read_hint(&ai_subd, CR_ALT_SOURCE|CR_ALT_FILTER,
-                                irange, AREF_DIFF, settle_time);
+                                irange, AREF_DIFF);
        if (err)
                error(EXIT, 0, "read_hint (%d)", err);
 
@@ -672,8 +714,7 @@ characterize_pwm(struct pwm_info *dst, int pref, unsigned 
range)
                if (err)
                        error(EXIT, 0, "get_min_speriod");
 
-               err = references.read_doubles(p, len/sizeof(*p), speriod, range,
-                                             NI_M_SETTLE_TIME);
+               err = references.read_doubles(p, len/sizeof(*p), speriod, 
range);
                if (err)
                        error(EXIT, 0, "read_doubles");
 
@@ -765,8 +806,7 @@ calibrate_ai_gain_and_offset(struct polynomial *dst, struct 
polynomial *src,
        err = references.get_min_speriod(&speriod);
        if (err)
                error(EXIT, 0, "get_min_speriod");
-       err = references.read_doubles(p, len/sizeof(*p), speriod, range,
-                                     NI_M_SETTLE_TIME);
+       err = references.read_doubles(p, len/sizeof(*p), speriod, range);
        if (err)
                error(EXIT, 0, "read_doubles");
        math.stats.mean(&measured_ground_code, p, len/sizeof(*p));
@@ -778,8 +818,7 @@ calibrate_ai_gain_and_offset(struct polynomial *dst, struct 
polynomial *src,
        err = references.get_min_speriod(&speriod);
        if (err)
                error(EXIT, 0, "get_min_speriod");
-       err = references.read_doubles(p, len/sizeof(*p), speriod, range,
-                                     NI_M_SETTLE_TIME);
+       err = references.read_doubles(p, len/sizeof(*p), speriod, range);
        if (err)
                error(EXIT, 0, "read_doubles");
        math.stats.mean(&measured_reference_code, p, len/sizeof(*p));
@@ -847,11 +886,9 @@ get_calibration_node(struct list *l, unsigned channel, 
unsigned range) {
                return NULL;
 
        list_for_each_entry_safe(e, t, l, node) {
-               if (e->channel == channel ||
-                   e->channel == ALL_CHANNELS ||
+               if (e->channel == channel || e->channel == ALL_CHANNELS ||
                    channel == ALL_CHANNELS) {
-                       if (e->range == range ||
-                           e->range == ALL_RANGES ||
+                       if (e->range == range || e->range == ALL_RANGES ||
                            range == ALL_RANGES) {
                                return e;
                        }
@@ -1086,6 +1123,7 @@ ni_m_calibrate_ai(void)
                        .range = -1,
                },
 
+
        };
 
        list_init(&ai_calibration_list);
@@ -1142,7 +1180,6 @@ ni_m_calibrate_ai(void)
         * calibrate low, medium and high gain ranges
         */
        for (i = 0; i < ARRAY_LEN(calibration_info); i++) {
-
                __debug("Calibrating AI: %s \n", calibration_info[i]);
 
                if (calibration_info[i].range >= 0)
@@ -1153,7 +1190,8 @@ ni_m_calibrate_ai(void)
                if (!calibrated.ranges[calibration_info[i].range])
                        error(EXIT, 0, "not calibrated yet \n" );
 
-               err = characterize_pwm(&pwm_info, calibration_info[i].ref_pos,
+               err = characterize_pwm(&pwm_info,
+                                      calibration_info[i].ref_pos,
                                       calibration_info[i].range);
                if (err)
                        error(EXIT, 0, "characterize_pwm \n");
@@ -1176,7 +1214,6 @@ calibrate:
                                                       
calibration_info[i].threshold);
                if (err)
                        error(EXIT, 0, "calibrate_ranges_above_threshold \n");
-
        }
 
        return 0;
@@ -1277,23 +1314,31 @@ calibrate_ao_channel_and_range(unsigned ai_rng, 
unsigned ao_channel, unsigned ao
 
        /* low nominals */
        data.codes[0].nominal = low_code;
+
        ops.data.write(&low_code, &ao_subd, ao_channel, ao_rng, AREF_GROUND);
        references.get_min_speriod(&speriod);
-       references.read_doubles(readings, NI_M_NR_SAMPLES, speriod, ai_rng,
-                               NI_M_SETTLE_TIME);
+       references.read_doubles(readings,
+                               NI_M_NR_SAMPLES,
+                               speriod,
+                               ai_rng);
        math.stats.mean(&measured_low_code, readings, NI_M_NR_SAMPLES);
-       math.polynomial.linearize(&data.codes[0].measured, node->polynomial,
+       math.polynomial.linearize(&data.codes[0].measured,
+                                 node->polynomial,
                                  measured_low_code);
 
        /* high nominals */
        high_code = get_high_code(ai_rng, ao_rng);
        data.codes[1].nominal = (1.0) * (double) high_code;
+
        ops.data.write(&high_code, &ao_subd, ao_channel, ao_rng, AREF_GROUND);
        references.get_min_speriod(&speriod);
-       references.read_doubles(readings, NI_M_NR_SAMPLES, speriod, ai_rng,
-                               NI_M_SETTLE_TIME);
+       references.read_doubles(readings,
+                               NI_M_NR_SAMPLES,
+                               speriod,
+                               ai_rng);
        math.stats.mean(&measured_high_code, readings, NI_M_NR_SAMPLES);
-       math.polynomial.linearize(&data.codes[1].measured, node->polynomial,
+       math.polynomial.linearize(&data.codes[1].measured,
+                                 node->polynomial,
                                  measured_high_code);
 
        poly.expansion_origin = 0.0;
@@ -1301,7 +1346,8 @@ calibrate_ao_channel_and_range(unsigned ai_rng, unsigned 
ao_channel, unsigned ao
        __debug("AO calibration for channel %d, range %d \n", ao_channel, 
ao_rng);
 
        for (i = 0; i < data.nb_codes ; i++)
-               __debug("set ao to %g, measured %g \n", data.codes[i].nominal,
+               __debug("set ao to %g, measured %g \n",
+                       data.codes[i].nominal,
                        data.codes[i].measured);
 
        /*----------------------------------------------------------------------
@@ -1317,7 +1363,6 @@ calibrate_ao_channel_and_range(unsigned ai_rng, unsigned 
ao_channel, unsigned ao
        math.polynomial.fit(&poly, &data);
 
        append_calibration_node(&ao_calibration_list, &poly, ao_channel, 
ao_rng);
-
        print_polynomial(&poly);
        free(data.codes);
 
@@ -1392,16 +1437,16 @@ int ni_m_software_calibrate(void)
 
                switch (sbinfo->flags & A4L_SUBD_TYPES) {
                case A4L_SUBD_CALIB:
-                       SET_SUBD(cal, i, sbinfo, "calibration");
+                       SET_SUBD(cal, i, sbinfo, CALIBRATION_SUBD_STR);
                        break;
                case A4L_SUBD_AI:
-                       SET_SUBD(ai, i, sbinfo, "analog_input");
+                       SET_SUBD(ai, i, sbinfo, AI_SUBD_STR);
                        break;
                case A4L_SUBD_AO:
-                       SET_SUBD(ao, i, sbinfo, "analog_output");
+                       SET_SUBD(ao, i, sbinfo, AO_SUBD_STR);
                        break;
                case A4L_SUBD_MEMORY:
-                       SET_SUBD(mem, i, sbinfo, "memory");
+                       SET_SUBD(mem, i, sbinfo, MEMORY_SUBD_STR);
                        break;
                }
        }
@@ -1427,8 +1472,6 @@ int ni_m_software_calibrate(void)
 
        write_calibration(&ao_calibration_list, &ao_subd);
 
-       apply_calibration();
-
        return 0;
 }
 
@@ -1444,3 +1487,4 @@ static void __attribute__ ((constructor)) 
__ni_m_calibrate_init(void)
        init_interface(ai_subd, SUBD);
 }
 
+
diff --git a/utils/analogy/calibration_ni_m.h b/utils/analogy/calibration_ni_m.h
index c9805bb..a0cb836 100644
--- a/utils/analogy/calibration_ni_m.h
+++ b/utils/analogy/calibration_ni_m.h
@@ -31,7 +31,9 @@ extern const char *ni_m_boards[];
 extern const int nr_ni_m_boards;
 
 #define ni_m_board_supported(id) __array_search(id, ni_m_boards, 
nr_ni_m_boards)
+
 int ni_m_software_calibrate(void);
+int ni_m_apply_calibration(void);
 
 #define init_interface(a, b)  a = ((typeof(a)) INIT_##b);
 
@@ -115,7 +117,7 @@ struct eeprom {
 }
 
 typedef int (*data_read_async_function)(void *, struct subdevice *, unsigned , 
int , int);
-typedef int (*data_read_hint_function)(struct subdevice *s, int, int, int, 
unsigned);
+typedef int (*data_read_hint_function)(struct subdevice *s, int, int, int);
 typedef int (*data_read_function)(unsigned *, struct subdevice *, int, int, 
int);
 typedef int (*data_write_function)(long int *, struct subdevice *s, int, int, 
int);
 
@@ -219,8 +221,8 @@ struct gnumath {
 }
 
 typedef int (*reference_set_pwm_function)(struct subdevice *s, unsigned, 
unsigned, unsigned *, unsigned *);
-typedef int (*reference_read_reference_doubles_function)(double [], unsigned, 
int, int, unsigned);
-typedef int (*reference_read_reference_samples_function)(void *, unsigned, 
int, int, unsigned);
+typedef int (*reference_read_reference_doubles_function)(double [], unsigned, 
int, int);
+typedef int (*reference_read_reference_samples_function)(void *, unsigned, 
int, int);
 typedef int (*reference_get_min_sampling_period_function)(int *);
 typedef int (*reference_set_reference_channel_function)(void);
 typedef int (*reference_set_reference_src_function)(void);
@@ -257,7 +259,6 @@ struct pwm_info {
 #define NI_M_TARGET_PWM_PERIOD_TICKS   ( 20 * NI_M_MIN_PWM_PULSE_TICKS )
 #define NI_M_NR_SAMPLES                        ( 15000 )
 #define NI_M_BASE_RANGE                        ( 0 )
-#define NI_M_SETTLE_TIME               ( 1000000 )
 
 
 struct subdevice_calibration_node {


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to