diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-01-20 21:52:35 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-01-20 21:52:35 +0000 |
commit | b179df901ec15a71cbef5ae7af92c6ee61a29529 (patch) | |
tree | 82926d6798d4193b9d1c0421d0b496acced412ae /apps | |
parent | e5a26ed98c6959bee193b046f300daee7c3dcf80 (diff) | |
download | px4-firmware-b179df901ec15a71cbef5ae7af92c6ee61a29529.tar.gz px4-firmware-b179df901ec15a71cbef5ae7af92c6ee61a29529.tar.bz2 px4-firmware-b179df901ec15a71cbef5ae7af92c6ee61a29529.zip |
Add support for extended (29-bit) CAN IDs
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4319 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'apps')
-rw-r--r-- | apps/examples/can/can_main.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/apps/examples/can/can_main.c b/apps/examples/can/can_main.c index 4e12fcd08..27e19b156 100644 --- a/apps/examples/can/can_main.c +++ b/apps/examples/can/can_main.c @@ -57,6 +57,12 @@ * Pre-processor Definitions ****************************************************************************/ +#ifdef CONFIG_CAN_EXTID +# define MAX_ID (1 << 29) +#else +# define MAX_ID (1 << 11) +#endif + #ifdef CONFIG_NSH_BUILTIN_APPS # define MAIN_NAME can_main # define MAIN_STRING "can_main: " @@ -99,12 +105,16 @@ int MAIN_NAME(int argc, char *argv[]) struct can_msg_s rxmsg; size_t msgsize; ssize_t nbytes; +#ifdef CONFIG_CAN_EXTID + uint32_t msgid; +#else + uint16_t msgid; +#endif uint8_t msgdata; #if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_CAN_NMSGS) long nmsgs; #endif int msgdlc; - int msgid; int fd; int errval = 0; int ret; @@ -174,7 +184,13 @@ int MAIN_NAME(int argc, char *argv[]) /* Construct the next TX message */ - txmsg.cm_hdr = CAN_HDR(msgid, 0, msgdlc); + txmsg.cm_hdr.ch_id = msgid; + txmsg.cm_hdr.ch_rtr = false; + txmsg.cm_hdr.ch_dlc = msgdlc; +#ifdef CONFIG_CAN_EXTID + txmsg.cm_hdr.ch_extid = true; +#endif + for (i = 0; i < msgdlc; i++) { txmsg.cm_data[i] = msgdata + i; @@ -182,7 +198,7 @@ int MAIN_NAME(int argc, char *argv[]) /* Send the TX message */ - msgsize = CAN_MSGLEN(txmsg.cm_hdr); + msgsize = CAN_MSGLEN(msgdlc); nbytes = write(fd, &txmsg, msgsize); if (nbytes != msgsize) { @@ -204,16 +220,20 @@ int MAIN_NAME(int argc, char *argv[]) /* Verify that the received messages are the same */ - if (txmsg.cm_hdr != rxmsg.cm_hdr) + if (memcmp(&txmsg.cm_hdr, &rxmsg.cm_hdr, sizeof(struct can_hdr_s)) != 0) { - message("ERROR: Sent header %04x; received header %04x\n", txmsg.cm_hdr, rxmsg.cm_hdr); + message("ERROR: Sent header does not match received header:\n"); + lib_dumpbuffer("Sent header", (FAR const uint8_t*)&txmsg.cm_hdr, + sizeof(struct can_hdr_s)); + lib_dumpbuffer("Received header", (FAR const uint8_t*)&rxmsg.cm_hdr, + sizeof(struct can_hdr_s)); errval = 4; goto errout_with_dev; } if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0) { - message("ERROR: Data does not match. DLC=%d\n", msgdlc); + message("ERROR: Data does not match. DLC=%d\n", msgdlc); for (i = 0; i < msgdlc; i++) { message(" %d: TX %02x RX %02x\n", i, txmsg.cm_data[i], rxmsg.cm_data[i]); @@ -230,7 +250,7 @@ int MAIN_NAME(int argc, char *argv[]) msgdata += msgdlc; - if (++msgid >= 2048) + if (++msgid >= MAX_ID) { msgid = 1; } |