How to use socketcan in android application layer

2,300 views
Skip to first unread message

Peter Chen

unread,
Dec 18, 2013, 4:16:27 AM12/18/13
to linux...@googlegroups.com
hey, guys.
I'v finished sunxi CAN drive in the socketcan mode.And I write a C program proved it works.I can send and receive packet correctlly.
Since I'm not an android app developer, I wonder how can I write a demo app by using the socketcan method.Can anyone give me some suggestions.Thaks.

Olliver Schinagl

unread,
Dec 18, 2013, 1:32:19 AM12/18/13
to linux...@googlegroups.com
On 18-12-13 10:16, Peter Chen wrote:
> hey, guys.
> I'v finished sunxi CAN drive in the socketcan mode.And I write a C
> program proved it works.I can send and receive packet correctlly.
that's amazing! great work and exciting too!

> Since I'm not an android app developer, I wonder how can I write a demo
> app by using the socketcan method.Can anyone give me some suggestions.Thaks.
Not sure if there's many android devs on this list ... :(

>
> --
> You received this message because you are subscribed to the Google
> Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to linux-sunxi...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Carlo Caione

unread,
Dec 18, 2013, 4:27:59 AM12/18/13
to linux...@googlegroups.com
On Wed, Dec 18, 2013 at 10:16 AM, Peter Chen <xingk...@gmail.com> wrote:
> hey, guys.
> I'v finished sunxi CAN drive in the socketcan mode.And I write a C program
> proved it works.I can send and receive packet correctlly.

Glad you were able to get the documentation for CAN

> Since I'm not an android app developer, I wonder how can I write a demo app
> by using the socketcan method.Can anyone give me some suggestions.Thaks.

I'm not sure I understood what you mean (if you tested the driver
probably you have already written a demo :)
With socketcan you see the CAN bus as a network interface (canX), so
you can use the socket interface. The fact that you are working with
the CAN bus is totally transparent.
(https://www.kernel.org/doc/Documentation/networking/can.txt)

BTW, if willing, please post the source code for review :)

--
Carlo Caione

Peter Chen

unread,
Dec 18, 2013, 6:11:53 AM12/18/13
to linux...@googlegroups.com, olive...@schinagl.nl
Thanks anyway

在 2013年12月18日星期三UTC+8下午2时32分19秒,Olliver Schinagl写道:

Peter Chen

unread,
Dec 18, 2013, 6:26:42 AM12/18/13
to linux...@googlegroups.com
Sorry for my poor english.I mean I want to write an APP to send/receive CAN message.Since I use socketcan, so I wonder how to write the APP in a proper way.Do I need to write the HAL, JNI and service?Or I can just use the network programming way.

And for the source code, I put it on my github. Anyone interested can visit via:https://github.com/ryangithub/sunxi-can-driver

在 2013年12月18日星期三UTC+8下午5时27分59秒,Carlo Caione写道:

Carlo Caione

unread,
Dec 18, 2013, 6:46:47 AM12/18/13
to linux...@googlegroups.com
On Wed, Dec 18, 2013 at 12:26 PM, Peter Chen <xingk...@gmail.com> wrote:
> Sorry for my poor english.I mean I want to write an APP to send/receive CAN
> message.Since I use socketcan, so I wonder how to write the APP in a proper
> way.Do I need to write the HAL, JNI and service?Or I can just use the
> network programming way.

Please, do not top-post.
I'm not an Android programmer but at low level with socketcan you have
to use classical socket APIs.
No idea for upper layers HAL / JNI / ...

I'm not sure if you are interested in mainlining the code, it requires
a bit more work in cleaning but IMO it is definitely doable.
If you are interested, please submit the patches for review.

BTW, if you have the documentation for CAN, please let us have it so
Oliver can add it to the wiki.

--
Carlo Caione

DrOctavius1

unread,
Dec 20, 2013, 12:00:52 PM12/20/13
to linux...@googlegroups.com
Peter,

Thanks for your socketcan driver!!! please, would be great to have the CAN controller documentation, so everybody can help to improve your work.

There is an Android image for other processor (I.mx6) that has CANBUS (using socketcan) and other I/O support, with some small application examples:

Android Jellybean 4.2.2 for EDM1-CF-IMX6 (Now with .apk utilities for GPIO/CANbus/Serial)


Regards,

Leandro

Peter Chen

unread,
Dec 20, 2013, 11:55:47 PM12/20/13
to linux...@googlegroups.com


在 2013年12月21日星期六UTC+8上午1时00分52秒,DrOctavius1写道:
Peter,

Thanks for your socketcan driver!!! please, would be great to have the CAN controller documentation, so everybody can help to improve your work.

There is an Android image for other processor (I.mx6) that has CANBUS (using socketcan) and other I/O support, with some small application examples:

Android Jellybean 4.2.2 for EDM1-CF-IMX6 (Now with .apk utilities for GPIO/CANbus/Serial)


Regards,

Leandro

Leandro,
Thanks for you reply.The link should helps me a lot.Here is the CAN controller document, hope it help those CAN driver deps.
CAN Bus1.pdf

Kaspter Ju

unread,
Jan 5, 2014, 12:09:38 PM1/5/14
to linux...@googlegroups.com, Peter Chen
On 12/21/2013 12:55 PM, Peter Chen wrote:
>
> Thanks for you reply.The link should helps me a lot.Here is the CAN
> controller document, hope it help those CAN driver deps.
>

Thanks for your documentation!
AFAIK, there is Flexcan implement in android framework,
https://github.com/zhangjie201412/Flexcan.git
hope this helps.

Regards,

Kaspter

tha...@gmail.com

unread,
Jan 14, 2014, 1:16:40 PM1/14/14
to linux...@googlegroups.com


Hi Peter

Thank you for the work on the can driver. Have you moved your sunxi-can-driver git repo?

I cant access it.

thanx

unread,
Jan 14, 2014, 4:12:28 PM1/14/14
to linux...@googlegroups.com
Peter Chen <xingkongcp@...> writes:

>
>
> Sorry for my poor english.I mean I want to write an APP to send/receive
CAN message.Since I use socketcan, so I wonder how to write the APP in a
proper way.Do I need to write the HAL, JNI and service?Or I can just use the
network programming way.
> And for the source code, I put it on my github. Anyone interested can
visit via:https://github.com/ryangithub/sunxi-can-driver

Hi Peter

Good work on the CAN driver. I am unable to access your git repo. Is your
git repo still available?





Mihail Tommonen

unread,
Jan 15, 2014, 12:19:53 PM1/15/14
to linux...@googlegroups.com, tha...@gmail.com

Hi

Here's what I got from googlecache, in case Peter doesn't show up.

https://drive.google.com/file/d/0B-fu0gscaM_heGdxc3BuUkxMczJUTkFXcU1kdmZZNEFiamxF/edit?usp=sharing

tha...@gmail.com

unread,
Jan 15, 2014, 12:30:08 PM1/15/14
to linux...@googlegroups.com, tha...@gmail.com

Hi Mihail

Thank you for your help exactly what I was looking for.

Regards

thanx

mr.vija...@gmail.com

unread,
Mar 21, 2016, 4:42:35 AM3/21/16
to linux-sunxi
Hi Peter,
Can you elaborate please how you have implemented SocketCan in Android.
if possible then please share source code over blog.
I am finding a way to implement SocketCan in android but I could not bale to find any sufficient document.

Thanks.
Reply all
Reply to author
Forward
0 new messages