summaryrefslogtreecommitdiff
path: root/cethcan
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2013-05-31 23:50:05 +0000
committerroot <root@beaglebone.(none)>2013-05-31 23:50:33 +0000
commitb7e8785f3c304423bf8b766c378252d59541d581 (patch)
tree4c4e218ad603da6eaac55816b7e9031a5656a4e8 /cethcan
parent6a8219d0c4c3d1458673bcf28af359bbcb519454 (diff)
cethcan/socketcan: TX support
Diffstat (limited to 'cethcan')
-rw-r--r--cethcan/socketcan.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/cethcan/socketcan.c b/cethcan/socketcan.c
index d73ed45..5aeaa2b 100644
--- a/cethcan/socketcan.c
+++ b/cethcan/socketcan.c
@@ -21,7 +21,22 @@ struct socan {
static void socan_handler(void *arg, struct can_message *msg)
{
struct socan *sc = arg;
- lprintf("%s: TX not implemented", sc->u->name);
+ struct can_frame frame;
+ memset(&frame, 0, sizeof(frame));
+
+ if (msg->daddr & 0x00080000)
+ frame.can_id = CAN_EFF_FLAG
+ | (msg->daddr & 0x0003ffff)
+ | ((msg->daddr & 0xffe00000) >> 3);
+ else
+ frame.can_id = msg->daddr >> 21;
+
+ frame.can_dlc = msg->dlc;
+ memcpy(frame.data, msg->bytes, msg->dlc > CANFD_MAX_DLEN ?
+ CANFD_MAX_DLEN : msg->dlc);
+
+ if (write(sc->sock, &frame, sizeof(frame)) != sizeof(frame))
+ lprintf("%s: send failed: %s", sc->u->name, strerror(errno));
}
static void socan_event(int sock, short event, void *arg)