[Xenomai-git] Jorge Ramirez-Ortiz : utils/analogy: calibration - implement calibrated insn_read
Module: xenomai-3 Branch: master Commit: 54b8e8c46a1feb0b07cacbc255f63955868cd006 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=54b8e8c46a1feb0b07cacbc255f63955868cd006 Author: Jorge Ramirez-Ortiz j...@xenomai.org Date: Fri Oct 24 09:01:09 2014 -0400 utils/analogy: calibration - implement calibrated insn_read --- utils/analogy/insn_read.c | 85 +++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/utils/analogy/insn_read.c b/utils/analogy/insn_read.c index 842bddb..3592aac 100644 --- a/utils/analogy/insn_read.c +++ b/utils/analogy/insn_read.c @@ -39,6 +39,7 @@ static int idx_subd = -1; static int idx_chan; static int idx_rng = -1; static unsigned int scan_size = SCAN_CNT; +static char *calibration_file = NULL; struct option insn_read_opts[] = { {verbose, no_argument, NULL, 'v'}, @@ -47,6 +48,7 @@ struct option insn_read_opts[] = { {scan-count, required_argument, NULL, 'S'}, {channel, required_argument, NULL, 'c'}, {range, required_argument, NULL, 'R'}, + {cal, required_argument, NULL, 'y'}, {raw, no_argument, NULL, 'w'}, {help, no_argument, NULL, 'h'}, {0}, @@ -63,6 +65,7 @@ static void do_print_usage(void) fprintf(stdout, \t\t -c, --channel: channel to use\n); fprintf(stdout, \t\t -R, --range: range to use\n); fprintf(stdout, \t\t -w, --raw: dump data in raw format\n); + fprintf(stdout, \t\t -y, --cal: /path/to/calibration.bin \n); fprintf(stdout, \t\t -h, --help: print this help\n); } @@ -118,9 +121,8 @@ static int dump_text(a4l_desc_t *dsc, unsigned char *buf, int size) if (err 0) goto out; - for (i = 0; i tmp_cnt; i++) { + for (i = 0; i tmp_cnt; i++) fprintf(stdout, fmt, values[i]); - } tmp_size += tmp_cnt * width; } @@ -162,6 +164,7 @@ static int dump_converted(a4l_desc_t *dsc, unsigned char *buf, int size) goto out; } + fprintf(stdout, Non Calibrated values: \n); while (size - tmp_size 0) { double values[64]; int i, tmp_cnt = ((size - tmp_size) / width 64) ? @@ -182,6 +185,78 @@ out: return err; } +static int dump_calibrated(a4l_desc_t *dsc, unsigned char *buf, int size) +{ + struct a4l_calibration_data cal_info; + struct a4l_polynomial converter; + int err = 0, width, tmp_size = 0; + a4l_chinfo_t *chan; + a4l_rnginfo_t *rng; + + + /* Retrieve the channel info */ + err = a4l_get_chinfo(dsc, idx_subd, idx_chan, chan); + if (err 0) { + fprintf(stderr, + insn_read: info for channel %d + on subdevice %d not available (err=%d)\n, + idx_chan, idx_subd, err); + goto out; + } + + /* Retrieve the range info */ + err = a4l_get_rnginfo(dsc, idx_subd, idx_chan, idx_rng, rng); + if (err 0) { + fprintf(stderr, + insn_read: failed to recover range descriptor\n); + goto out; + } + + width = a4l_sizeof_chan(chan); + if (width 0) { + fprintf(stderr, + insn_read: incoherent info for channel %d\n, + idx_chan); + err = width; + goto out; + } + + err = a4l_read_calibration_file(calibration_file, cal_info); + if (err 0) { + fprintf(stderr, + insn_read: failed to read /tmp/calibration.txt \n); + goto out; + } + + err = a4l_get_softcal_converter(converter, idx_subd, idx_chan, idx_rng, + cal_info); + if (err 0) { + fprintf(stderr, + insn_read: failed to get the softcal converter \n); + goto out; + } + + fprintf(stdout, Calibrated values: \n); + while (size - tmp_size 0) { + double values[64]; + int i, tmp_cnt = ((size - tmp_size) / width 64) ? + 64 : ((size - tmp_size) / width); + + err = a4l_rawtodcal(chan, values, buf + tmp_size, tmp_cnt, + converter); + if (err 0) + goto out; + + for (i = 0; i tmp_cnt; i++) + fprintf(stdout, %F\n, values[i]); + + tmp_size += tmp_cnt * width; + } + +out: + return err; +} + int main(int argc, char *argv[]) { int err = 0; @@ -196,7 +271,7 @@ int main(int argc, char *argv[]) /* Compute arguments */ while ((err = getopt_long(argc, argv, - vrd:s:S:c:R:wh, insn_read_opts, +
[Xenomai-git] Jorge Ramirez-Ortiz : utils/analogy: calibration - implement calibrated insn_read
Module: xenomai-3 Branch: next Commit: 54b8e8c46a1feb0b07cacbc255f63955868cd006 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=54b8e8c46a1feb0b07cacbc255f63955868cd006 Author: Jorge Ramirez-Ortiz j...@xenomai.org Date: Fri Oct 24 09:01:09 2014 -0400 utils/analogy: calibration - implement calibrated insn_read --- utils/analogy/insn_read.c | 85 +++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/utils/analogy/insn_read.c b/utils/analogy/insn_read.c index 842bddb..3592aac 100644 --- a/utils/analogy/insn_read.c +++ b/utils/analogy/insn_read.c @@ -39,6 +39,7 @@ static int idx_subd = -1; static int idx_chan; static int idx_rng = -1; static unsigned int scan_size = SCAN_CNT; +static char *calibration_file = NULL; struct option insn_read_opts[] = { {verbose, no_argument, NULL, 'v'}, @@ -47,6 +48,7 @@ struct option insn_read_opts[] = { {scan-count, required_argument, NULL, 'S'}, {channel, required_argument, NULL, 'c'}, {range, required_argument, NULL, 'R'}, + {cal, required_argument, NULL, 'y'}, {raw, no_argument, NULL, 'w'}, {help, no_argument, NULL, 'h'}, {0}, @@ -63,6 +65,7 @@ static void do_print_usage(void) fprintf(stdout, \t\t -c, --channel: channel to use\n); fprintf(stdout, \t\t -R, --range: range to use\n); fprintf(stdout, \t\t -w, --raw: dump data in raw format\n); + fprintf(stdout, \t\t -y, --cal: /path/to/calibration.bin \n); fprintf(stdout, \t\t -h, --help: print this help\n); } @@ -118,9 +121,8 @@ static int dump_text(a4l_desc_t *dsc, unsigned char *buf, int size) if (err 0) goto out; - for (i = 0; i tmp_cnt; i++) { + for (i = 0; i tmp_cnt; i++) fprintf(stdout, fmt, values[i]); - } tmp_size += tmp_cnt * width; } @@ -162,6 +164,7 @@ static int dump_converted(a4l_desc_t *dsc, unsigned char *buf, int size) goto out; } + fprintf(stdout, Non Calibrated values: \n); while (size - tmp_size 0) { double values[64]; int i, tmp_cnt = ((size - tmp_size) / width 64) ? @@ -182,6 +185,78 @@ out: return err; } +static int dump_calibrated(a4l_desc_t *dsc, unsigned char *buf, int size) +{ + struct a4l_calibration_data cal_info; + struct a4l_polynomial converter; + int err = 0, width, tmp_size = 0; + a4l_chinfo_t *chan; + a4l_rnginfo_t *rng; + + + /* Retrieve the channel info */ + err = a4l_get_chinfo(dsc, idx_subd, idx_chan, chan); + if (err 0) { + fprintf(stderr, + insn_read: info for channel %d + on subdevice %d not available (err=%d)\n, + idx_chan, idx_subd, err); + goto out; + } + + /* Retrieve the range info */ + err = a4l_get_rnginfo(dsc, idx_subd, idx_chan, idx_rng, rng); + if (err 0) { + fprintf(stderr, + insn_read: failed to recover range descriptor\n); + goto out; + } + + width = a4l_sizeof_chan(chan); + if (width 0) { + fprintf(stderr, + insn_read: incoherent info for channel %d\n, + idx_chan); + err = width; + goto out; + } + + err = a4l_read_calibration_file(calibration_file, cal_info); + if (err 0) { + fprintf(stderr, + insn_read: failed to read /tmp/calibration.txt \n); + goto out; + } + + err = a4l_get_softcal_converter(converter, idx_subd, idx_chan, idx_rng, + cal_info); + if (err 0) { + fprintf(stderr, + insn_read: failed to get the softcal converter \n); + goto out; + } + + fprintf(stdout, Calibrated values: \n); + while (size - tmp_size 0) { + double values[64]; + int i, tmp_cnt = ((size - tmp_size) / width 64) ? + 64 : ((size - tmp_size) / width); + + err = a4l_rawtodcal(chan, values, buf + tmp_size, tmp_cnt, + converter); + if (err 0) + goto out; + + for (i = 0; i tmp_cnt; i++) + fprintf(stdout, %F\n, values[i]); + + tmp_size += tmp_cnt * width; + } + +out: + return err; +} + int main(int argc, char *argv[]) { int err = 0; @@ -196,7 +271,7 @@ int main(int argc, char *argv[]) /* Compute arguments */ while ((err = getopt_long(argc, argv, - vrd:s:S:c:R:wh, insn_read_opts, +
[Xenomai-git] Jorge Ramirez-Ortiz : utils/analogy: calibration - implement calibrated insn_read
Module: xenomai-3 Branch: next Commit: 7361c3ad2322727679d28bee48185560eec3a07f URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7361c3ad2322727679d28bee48185560eec3a07f Author: Jorge Ramirez-Ortiz j...@xenomai.org Date: Fri Oct 24 09:01:09 2014 -0400 utils/analogy: calibration - implement calibrated insn_read --- utils/analogy/insn_read.c | 85 +++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/utils/analogy/insn_read.c b/utils/analogy/insn_read.c index 842bddb..3592aac 100644 --- a/utils/analogy/insn_read.c +++ b/utils/analogy/insn_read.c @@ -39,6 +39,7 @@ static int idx_subd = -1; static int idx_chan; static int idx_rng = -1; static unsigned int scan_size = SCAN_CNT; +static char *calibration_file = NULL; struct option insn_read_opts[] = { {verbose, no_argument, NULL, 'v'}, @@ -47,6 +48,7 @@ struct option insn_read_opts[] = { {scan-count, required_argument, NULL, 'S'}, {channel, required_argument, NULL, 'c'}, {range, required_argument, NULL, 'R'}, + {cal, required_argument, NULL, 'y'}, {raw, no_argument, NULL, 'w'}, {help, no_argument, NULL, 'h'}, {0}, @@ -63,6 +65,7 @@ static void do_print_usage(void) fprintf(stdout, \t\t -c, --channel: channel to use\n); fprintf(stdout, \t\t -R, --range: range to use\n); fprintf(stdout, \t\t -w, --raw: dump data in raw format\n); + fprintf(stdout, \t\t -y, --cal: /path/to/calibration.bin \n); fprintf(stdout, \t\t -h, --help: print this help\n); } @@ -118,9 +121,8 @@ static int dump_text(a4l_desc_t *dsc, unsigned char *buf, int size) if (err 0) goto out; - for (i = 0; i tmp_cnt; i++) { + for (i = 0; i tmp_cnt; i++) fprintf(stdout, fmt, values[i]); - } tmp_size += tmp_cnt * width; } @@ -162,6 +164,7 @@ static int dump_converted(a4l_desc_t *dsc, unsigned char *buf, int size) goto out; } + fprintf(stdout, Non Calibrated values: \n); while (size - tmp_size 0) { double values[64]; int i, tmp_cnt = ((size - tmp_size) / width 64) ? @@ -182,6 +185,78 @@ out: return err; } +static int dump_calibrated(a4l_desc_t *dsc, unsigned char *buf, int size) +{ + struct a4l_calibration_data cal_info; + struct a4l_polynomial converter; + int err = 0, width, tmp_size = 0; + a4l_chinfo_t *chan; + a4l_rnginfo_t *rng; + + + /* Retrieve the channel info */ + err = a4l_get_chinfo(dsc, idx_subd, idx_chan, chan); + if (err 0) { + fprintf(stderr, + insn_read: info for channel %d + on subdevice %d not available (err=%d)\n, + idx_chan, idx_subd, err); + goto out; + } + + /* Retrieve the range info */ + err = a4l_get_rnginfo(dsc, idx_subd, idx_chan, idx_rng, rng); + if (err 0) { + fprintf(stderr, + insn_read: failed to recover range descriptor\n); + goto out; + } + + width = a4l_sizeof_chan(chan); + if (width 0) { + fprintf(stderr, + insn_read: incoherent info for channel %d\n, + idx_chan); + err = width; + goto out; + } + + err = a4l_read_calibration_file(calibration_file, cal_info); + if (err 0) { + fprintf(stderr, + insn_read: failed to read /tmp/calibration.txt \n); + goto out; + } + + err = a4l_get_softcal_converter(converter, idx_subd, idx_chan, idx_rng, + cal_info); + if (err 0) { + fprintf(stderr, + insn_read: failed to get the softcal converter \n); + goto out; + } + + fprintf(stdout, Calibrated values: \n); + while (size - tmp_size 0) { + double values[64]; + int i, tmp_cnt = ((size - tmp_size) / width 64) ? + 64 : ((size - tmp_size) / width); + + err = a4l_rawtodcal(chan, values, buf + tmp_size, tmp_cnt, + converter); + if (err 0) + goto out; + + for (i = 0; i tmp_cnt; i++) + fprintf(stdout, %F\n, values[i]); + + tmp_size += tmp_cnt * width; + } + +out: + return err; +} + int main(int argc, char *argv[]) { int err = 0; @@ -196,7 +271,7 @@ int main(int argc, char *argv[]) /* Compute arguments */ while ((err = getopt_long(argc, argv, - vrd:s:S:c:R:wh, insn_read_opts, +