/******************************************************************* * I.MX6 Android can-utils 移植 * 说明: * 由于最近要用到CAN,于是先移植一下can-tuils来看一下情况。 * * 2016-8-1 深圳 南山平山村 曾剑锋 ******************************************************************/ 一、获取源码: https://github.com/linux-can/can-utils 二、错误现象: target thumb C: slcan_attach <= /home/myzr/myandroid/packages/apps/can-utils/slcan_attach.c /home/myzr/myandroid/packages/apps/can-utils/slcan_attach.c: In function 'main': /home/myzr/myandroid/packages/apps/can-utils/slcan_attach.c:81:14: error: 'N_SLCAN' undeclared (first use in this function) /home/myzr/myandroid/packages/apps/can-utils/slcan_attach.c:81:14: note: each undeclared identifier is reported only once for each function it appears in make: *** [out/target/product/sabresd_6dq/obj/EXECUTABLES/slcan_attach_intermediates/slcan_attach.o] Error 1 make: Leaving directory `/home/myzr/myandroid' 三、查看N_SLCAN情况: 1. 直接查看: myzr@myzr:~/myandroid/packages/apps/can-utils$ grep N_SLCAN * -R configure.ac:AC_CHECK_DECL(N_SLCAN,, configure.ac: [AC_DEFINE([N_SLCAN], [17], [N_SLCAN])] slcan_attach.c: int ldisc = N_SLCAN; slcand.c: int ldisc = N_SLCAN; 2. 执行autogen.sh再查看: myzr@myzr:~/myandroid/packages/apps/can-utils$ ./autogen.sh ---------- autoreconf ---------- Can't exec "libtoolize": No such file or directory at /usr/bin/autoreconf line 196. Use of uninitialized value in pattern match (m//) at /usr/bin/autoreconf line 196. configure.ac:9: installing `config/autoconf/config.guess' configure.ac:9: installing `config/autoconf/config.sub' configure.ac:22: installing `config/autoconf/install-sh' configure.ac:22: installing `config/autoconf/missing' GNUmakefile.am:25: Libtool library used but `LIBTOOL' is undefined GNUmakefile.am:25: The usual way to define `LIBTOOL' is to add `LT_INIT' GNUmakefile.am:25: to `configure.ac' and run `aclocal' and `autoconf' again. GNUmakefile.am:25: If `LT_INIT' is in `configure.ac', make sure GNUmakefile.am:25: its definition is in aclocal's search path. GNUmakefile.am: installing `config/autoconf/depcomp' autoreconf: automake failed with exit status: 1 myzr@myzr:~/myandroid/packages/apps/can-utils$ grep N_SLCAN * -R autom4te.cache/output.1:ac_fn_c_check_decl "$LINENO" "N_SLCAN" "ac_cv_have_decl_N_SLCAN" "$ac_includes_default" autom4te.cache/output.1:if test "x$ac_cv_have_decl_N_SLCAN" = xyes; then : autom4te.cache/output.1:$as_echo "@%:@define N_SLCAN 17" >>confdefs.h autom4te.cache/output.0:ac_fn_c_check_decl "$LINENO" "N_SLCAN" "ac_cv_have_decl_N_SLCAN" "$ac_includes_default" autom4te.cache/output.0:if test "x$ac_cv_have_decl_N_SLCAN" = xyes; then : autom4te.cache/output.0:$as_echo "@%:@define N_SLCAN 17" >>confdefs.h autom4te.cache/traces.0:m4trace:configure.ac:86: -1- m4_pattern_allow([^N_SLCAN$]) autom4te.cache/traces.1:m4trace:configure.ac:86: -1- AC_DEFINE_TRACE_LITERAL([N_SLCAN]) autom4te.cache/traces.1:m4trace:configure.ac:86: -1- m4_pattern_allow([^N_SLCAN$]) autom4te.cache/traces.1:m4trace:configure.ac:86: -1- AH_OUTPUT([N_SLCAN], [/* N_SLCAN */ autom4te.cache/traces.1:@%:@undef N_SLCAN]) configure:ac_fn_c_check_decl "$LINENO" "N_SLCAN" "ac_cv_have_decl_N_SLCAN" "$ac_includes_default" configure:if test "x$ac_cv_have_decl_N_SLCAN" = xyes; then : configure:$as_echo "#define N_SLCAN 17" >>confdefs.h configure.ac:AC_CHECK_DECL(N_SLCAN,, configure.ac: [AC_DEFINE([N_SLCAN], [17], [N_SLCAN])] slcan_attach.c: int ldisc = N_SLCAN; slcand.c: int ldisc = N_SLCAN; myzr@myzr:~/myandroid/packages/apps/can-utils$ 四、解决办法: slcan_attach.c slcand.c 中添加 #define N_SLCAN 17 宏定义。 五、测试命令: root@android:/data/local # ./cangen cangen: generate CAN frames Usage: cangen [options] <CAN interface> Options: -g <ms> (gap in milli seconds - default: 200 ms) -e (generate extended frame mode (EFF) CAN frames) -f (generate CAN FD CAN frames) -b (generate CAN FD CAN frames with bitrate switch (BRS)) -R (send RTR frame) -m (mix -e -f -b -R frames) -I <mode> (CAN ID generation mode - see below) -L <mode> (CAN data length code (dlc) generation mode - see below) -D <mode> (CAN data (payload) generation mode - see below) -p <timeout> (poll on -ENOBUFS to write frames with <timeout> ms) -n <count> (terminate after <count> CAN frames - default infinite) -i (ignore -ENOBUFS return values on write() syscalls) -x (disable local loopback of generated CAN frames) -v (increment verbose level for printing sent CAN frames) Generation modes: 'r' => random values (default) 'i' => increment values <hexvalue> => fix value using <hexvalue> When incrementing the CAN data the data length code minimum is set to 1. CAN IDs and data content are given and expected in hexadecimal values. Examples: cangen vcan0 -g 4 -I 42A -L 1 -D i -v -v (fixed CAN ID and length, inc. data) cangen vcan0 -e -L i -v -v -v (generate EFF frames, incr. length) cangen vcan0 -D 11223344DEADBEEF -L 8 (fixed CAN data payload and length) cangen vcan0 -g 0 -i -x (full load test ignoring -ENOBUFS) cangen vcan0 -g 0 -p 10 -x (full load test with polling, 10ms timeout) cangen vcan0 (my favourite default :) root@android:/data/local #