Hi Matthias,

Thank you for the info.

I was wondering if you could post the patch you did to the Python
Modules/socketmodule.c/h files?

I'm interested in getting this going as well.

Paul

>> Matthias Fuchs-3 wrote:
>>
>>>
>>> Hi,
>>>
>>> it works. After some hacking on the python socket module
>>> (Modules/socketmodule.c, Modules/socketmodule.h) to make it know about
>>> the AF_CAN stuff, I can receive CAN data with the little script below:
>>>
>>> (29, '\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
>>>                 ^ ifindex
>>> 0000   00 00 00 00 08 00 00 00    ........
>>> 0008   00 00 00 00 00 00 00 01    ........
>>>
>>> (29, '\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
>>> 0000   00 00 00 00 08 00 00 00    ........
>>> 0008   00 00 00 01 00 00 00 01    ........
>>>
>>> There are a couple of open issue to make this clean (e.g. passing
>>> interface name instead of index to bind()). But it's cool stuff
>>> an extremely usefull when you need to script some test equipment
>>> over CAN.
>>> ...
>>>
>>> import struct
>>> import socket
>>>
>>> AF_CAN = 29
>>> PF_CAN = AF_CAN
>>> CAN_RAW = 1
>>> SOL_CAN_BASE = 100
>>> SOL_CAN_RAW = (SOL_CAN_BASE + CAN_RAW)
>>> CAN_RAW_FILTER = 1
>>>
>>>
>>> FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in
>>> range(256)])
>>>
>>> def dump(src, length=8):
>>>    result=[]
>>>    for i in xrange(0, len(src), length):
>>>       s = src[i:i+length]
>>>       hexa = ' '.join(["%02X"%ord(x) for x in s])
>>>       printable = s.translate(FILTER)
>>>       result.append("%04X   %-*s   %s\n" % (i, length*3, hexa,
>>> printable))
>>>    return ''.join(result)
>>>
>>>
>>> # create socket
>>> s = socket.socket(PF_CAN, socket.SOCK_RAW, CAN_RAW)
>>>
>>> # setup id filter
>>> id = 0
>>> mask = 0
>>> s.setsockopt(SOL_CAN_RAW, CAN_RAW_FILTER, struct.pack("II", id, mask))
>>>
>>> # bind to any I/F (ifindex, reserved/whatever)
>>> s.bind((0,))
>>>
>>> while 1:
>>>        data, addr = s.recvfrom(16)
>>>        print addr
>>>        print dump(data)
>>> _______________________________________________
>>> Socketcan-users mailing list
>>> [email protected]
>>> https://lists.berlios.de/mailman/listinfo/socketcan-users
>>>
>>>
>>>
>>
>>
>
>
_______________________________________________
Socketcan-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

Reply via email to