summaryrefslogtreecommitdiff
path: root/apps/examples/can
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-20 21:52:35 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-20 21:52:35 +0000
commit1a0b77740ae6317e7a9a512489bc74cecb4a5fdf (patch)
tree82926d6798d4193b9d1c0421d0b496acced412ae /apps/examples/can
parent49c358953f0d1462456a666cdf141346884d655d (diff)
downloadpx4-nuttx-1a0b77740ae6317e7a9a512489bc74cecb4a5fdf.tar.gz
px4-nuttx-1a0b77740ae6317e7a9a512489bc74cecb4a5fdf.tar.bz2
px4-nuttx-1a0b77740ae6317e7a9a512489bc74cecb4a5fdf.zip
Add support for extended (29-bit) CAN IDs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4319 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/examples/can')
-rw-r--r--apps/examples/can/can_main.c34
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;
}