summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuotao Fu <l.fu@pengutronix.de>2009-11-25 16:04:57 +0100
committerLuotao Fu <l.fu@pengutronix.de>2009-11-25 16:18:54 +0100
commitd016207e320bf09ccd6ed2567583fed85bfcc38a (patch)
treec2b80e49062c089b7ea2aebd8a8d26a8902c36ea
parent199ba6c48eaa6fd16d95ad356e36e4df4329601f (diff)
downloadcanutils-d016207e320bf09ccd6ed2567583fed85bfcc38a.tar.gz
canutils-d016207e320bf09ccd6ed2567583fed85bfcc38a.tar.xz
[canconfig] add sample point to get/set bitrate
get/set bitrate now recognize sample_point configuration. also changed error handling while calling get_bitrate Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
-rw-r--r--src/canconfig.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/canconfig.c b/src/canconfig.c
index 5e648a7..1926628 100644
--- a/src/canconfig.c
+++ b/src/canconfig.c
@@ -89,18 +89,36 @@ static void do_show_bitrate(int argc, char* argv[])
{
struct can_bittiming bt;
- if (scan_get_bittiming(argv[1], &bt) < 0)
- fprintf(stdout, "%s: bitrate unknown\n", argv[1]);
- else
+ if (scan_get_bittiming(argv[1], &bt) < 0) {
+ fprintf(stderr, "%s: failed to get bitrate\n", argv[1]);
+ exit(EXIT_FAILURE);
+ } else
fprintf(stdout,
- "%s bitrate: %u\n", argv[1], bt.bitrate);
+ "%s bitrate: %u, sample point: %0.3f\n",
+ argv[1], bt.bitrate,
+ (float)((float)bt.sample_point / 1000));
}
-static void do_set_bitrate(int argc, char* argv[])
+static void do_set_bitrate(int argc, char *argv[])
{
- if (scan_set_bitrate(argv[1], (__u32)strtoul(argv[3], NULL, 10)) < 0) {
+ __u32 bitrate = 0;
+ __u32 sample_point = 0;
+ const char *name = argv[1];
+
+ while (argc > 0) {
+ if (!strcmp(*argv, "bitrate")) {
+ NEXT_ARG();
+ bitrate = (__u32)strtoul(*argv, NULL, 0);
+ } else if (!strcmp(*argv, "sample-point")) {
+ NEXT_ARG();
+ sample_point = (__u32)strtoul(*argv, NULL, 0);
+ }
+ argc--, argv++;
+ }
+
+ if (scan_set_bitrate(name, bitrate, sample_point) < 0) {
fprintf(stderr, "failed to set bitrate of %s to %lu\n",
- argv[1], strtoul(argv[3], NULL, 10));
+ argv[1], strtoul(name, NULL, 10));
exit(EXIT_FAILURE);
}
}